Commit 0b5be818 authored by Andrius Štikonas's avatar Andrius Štikonas
Browse files

Port away from KIO::NetAccess.

REVIEW: 128449
parent e0f2e9ee
......@@ -38,6 +38,7 @@ find_package(KF5 5.23 REQUIRED
DBusAddons
I18n
IconThemes
JobWidgets
KIO
KDELibs4Support
Notifications
......@@ -241,6 +242,7 @@ target_link_libraries(kgpg
KF5::DBusAddons
KF5::I18n
KF5::IconThemes
KF5::JobWidgets
KF5::KDELibs4Support
KF5::KIOCore
KF5::KIOFileWidgets
......
......@@ -34,7 +34,9 @@
#include <KEncodingFileDialog>
#include <KFind>
#include <KFindDialog>
#include <KIO/Job>
#include <KIO/RenameDialog>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <KRecentFilesAction>
......@@ -51,12 +53,10 @@
#include <QPainter>
#include <QPrintDialog>
#include <QPrinter>
#include <QTemporaryFile>
#include <QTextCodec>
#include <QTextStream>
#include <QVBoxLayout>
#include <QWidget>
#include <kio/netaccess.h>
class KgpgView : public QWidget {
public:
......@@ -115,23 +115,19 @@ KgpgEditor::~KgpgEditor()
void KgpgEditor::openDocumentFile(const QUrl &url, const QString &encoding)
{
QString tempopenfile;
if(KIO::NetAccess::download(url, tempopenfile, this))
auto downloadJob = KIO::storedGet(url);
KJobWidgets::setWindow(downloadJob , this);
downloadJob->exec();
if(!downloadJob->error())
{
QFile qfile(tempopenfile);
if (qfile.open(QIODevice::ReadOnly))
{
QTextStream t(&qfile);
t.setCodec(encoding.toAscii());
m_editor->setPlainText(t.readAll());
qfile.close();
m_docname = url;
m_textchanged = false;
m_emptytext = false;
setCaption(url.fileName(), false);
m_recentfiles->addUrl(url);
}
KIO::NetAccess::removeTempFile(tempopenfile);
QTextStream t(downloadJob->data());
t.setCodec(encoding.toAscii());
m_editor->setPlainText(t.readAll());
m_docname = url;
m_textchanged = false;
m_emptytext = false;
setCaption(url.fileName(), false);
m_recentfiles->addUrl(url);
}
}
......@@ -317,13 +313,10 @@ bool KgpgEditor::slotFileSave()
}
else
{
QTemporaryFile tmpfile;
tmpfile.open();
QTextStream stream(&tmpfile);
stream.setCodec(cod);
stream << m_editor->toPlainText();
if(!KIO::NetAccess::upload(tmpfile.fileName(), m_docname, this))
auto uploadJob = KIO::storedPut(cod->fromUnicode(m_editor->toPlainText()), m_docname, -1);
KJobWidgets::setWindow(uploadJob , this);
uploadJob->exec();
if(uploadJob->error())
{
KMessageBox::sorry(this, i18n("The document could not be saved, please check your permissions and disk space."));
return false;
......@@ -357,11 +350,16 @@ bool KgpgEditor::slotFileSaveAs()
return false;
}
f.close();
} else if (KIO::NetAccess::exists(url, KIO::NetAccess::DestinationSide, this)) {
const QString message = i18n("Overwrite existing file %1?", url.fileName());
int result = KMessageBox::warningContinueCancel(this, message, QString(), KStandardGuiItem::overwrite());
if (result == KMessageBox::Cancel)
return false;
} else {
auto statJob = KIO::stat(url, KIO::StatJob::DestinationSide, 0);
KJobWidgets::setWindow(statJob, this);
statJob->exec();
if (!statJob->error()) {
const QString message = i18n("Overwrite existing file %1?", url.fileName());
int result = KMessageBox::warningContinueCancel(this, message, QString(), KStandardGuiItem::overwrite());
if (result == KMessageBox::Cancel)
return false;
}
}
m_docname = url;
......
......@@ -27,6 +27,8 @@
#include "transactions/kgpgsigntext.h"
#include "transactions/kgpgverify.h"
#include <KIO/Job>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <KUrlMimeData>
......@@ -35,9 +37,8 @@
#include <QDropEvent>
#include <QFile>
#include <QMimeData>
#include <QTemporaryFile>
#include <QTextStream>
#include <kio/netaccess.h>
#include <KConfigGroup>
#define SIGNEDMESSAGE_BEGIN QLatin1String( "-----BEGIN PGP SIGNED MESSAGE-----" )
#define SIGNEDMESSAGE_END QLatin1String( "-----END PGP SIGNATURE-----" )
......@@ -94,10 +95,17 @@ void KgpgTextEdit::openDroppedFile(const QUrl &url, const bool probe)
if (KMessageBox::warningContinueCancel(this, i18n("<qt><b>Remote file dropped</b>.<br />The remote file will now be copied to a temporary file to process requested operation. This temporary file will be deleted after operation.</qt>"), QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), QLatin1String( "RemoteFileWarning" )) != KMessageBox::Continue)
return;
if (!KIO::NetAccess::download(url, m_tempfile, this)) {
QTemporaryFile tmpFile;
tmpFile.open();
auto copyJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()));
KJobWidgets::setWindow(copyJob , this);
copyJob->exec();
if (copyJob->error()) {
KMessageBox::sorry(this, i18n("Could not download file."));
return;
}
tmpFile.setAutoRemove(false);
m_tempfile = tmpFile.fileName();
tmpurl = QUrl::fromLocalFile(m_tempfile);
}
......@@ -121,7 +129,8 @@ void KgpgTextEdit::openDroppedFile(const QUrl &url, const bool probe)
return;
}
// remove only here, as KGpgDecrypt will use and remove the file itself
KIO::NetAccess::removeTempFile(m_tempfile);
if(!m_tempfile.isEmpty())
QFile::remove( m_tempfile );
m_tempfile.clear();
QString tmpinfo;
......@@ -250,7 +259,8 @@ void KgpgTextEdit::slotDecryptDone(int result)
Q_ASSERT(decr != Q_NULLPTR);
if (!m_tempfile.isEmpty()) {
KIO::NetAccess::removeTempFile(m_tempfile);
if(!m_tempfile.isEmpty())
QFile::remove( m_tempfile );
m_tempfile.clear();
}
......
......@@ -16,8 +16,10 @@
#include "gpgproc.h"
#include <KDebug>
#include <KIO/NetAccess>
#include <KIO/Job>
#include <QRegExp>
#include <QTemporaryFile>
KGpgTextOrFileTransaction::KGpgTextOrFileTransaction(QObject *parent, const QString &text, const bool allowChaining)
: KGpgTransaction(parent, allowChaining)
......@@ -90,12 +92,16 @@ KGpgTextOrFileTransaction::preStart()
if (url.isLocalFile()) {
locfiles.append(url.toLocalFile());
} else {
QString tmpfile;
if (KIO::NetAccess::download(url, tmpfile, 0)) {
m_tempfiles.append(tmpfile);
QTemporaryFile tmpFile;
tmpFile.open();
auto copyJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()));
copyJob->exec();
if (!copyJob->error()) {
tmpFile.setAutoRemove(false);
m_tempfiles.append(tmpFile.fileName());
} else {
m_messages.append(KIO::NetAccess::lastErrorString());
m_messages.append(copyJob->errorString());
cleanUrls();
setSuccess(TS_KIO_FAILED);
return false;
......@@ -164,7 +170,7 @@ void
KGpgTextOrFileTransaction::cleanUrls()
{
foreach (const QString &u, m_tempfiles)
KIO::NetAccess::removeTempFile(u);
QFile::remove(u);
m_tempfiles.clear();
m_locfiles.clear();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment