Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/converter/mymoneytemplate.cpp
Context not available. | |||||
33 | #include <KMessageBox> | 33 | #include <KMessageBox> | ||
---|---|---|---|---|---|
34 | #include <QTemporaryFile> | 34 | #include <QTemporaryFile> | ||
35 | #include <KXmlGuiWindow> | 35 | #include <KXmlGuiWindow> | ||
36 | #include <KIO/StoredTransferJob> | ||||
37 | #include <KJobWidgets> | ||||
36 | 38 | | |||
37 | // ---------------------------------------------------------------------------- | 39 | // ---------------------------------------------------------------------------- | ||
38 | // Project Includes | 40 | // Project Includes | ||
Context not available. | |||||
63 | bool MyMoneyTemplate::loadTemplate(const QUrl &url) | 65 | bool MyMoneyTemplate::loadTemplate(const QUrl &url) | ||
64 | { | 66 | { | ||
65 | QString filename; | 67 | QString filename; | ||
66 | 68 | bool downloadedFile = false; | |||
67 | if (!url.isValid()) { | 69 | if (!url.isValid()) { | ||
68 | qDebug("Invalid template URL '%s'", qPrintable(url.url())); | 70 | qDebug("Invalid template URL '%s'", qPrintable(url.url())); | ||
69 | return false; | 71 | return false; | ||
Context not available. | |||||
75 | 77 | | |||
76 | } else { | 78 | } else { | ||
77 | bool rc = false; | 79 | bool rc = false; | ||
78 | // TODO: port to kf5 | 80 | downloadedFile = true; | ||
79 | //rc = KIO::NetAccess::download(url, filename, KMyMoneyUtils::mainWindow()); | 81 | KIO::StoredTransferJob *transferjob = KIO::storedGet (url); | ||
80 | if (!rc) { | 82 | KJobWidgets::setWindow(transferjob, KMyMoneyUtils::mainWindow()); | ||
81 | KMessageBox::detailedError(KMyMoneyUtils::mainWindow(), | 83 | rc = transferjob->exec(); | ||
84 | if (! rc) { | ||||
85 | KMessageBox::detailedError(KMyMoneyUtils::mainWindow(), | ||||
82 | i18n("Error while loading file '%1'.", url.url()), | 86 | i18n("Error while loading file '%1'.", url.url()), | ||
83 | // TODO: port to kf5 | 87 | transferjob->errorString(), | ||
84 | QString(),//KIO::NetAccess::lastErrorString(), | | |||
85 | i18n("File access error")); | 88 | i18n("File access error")); | ||
86 | return false; | 89 | return false; | ||
87 | } | 90 | } | ||
91 | QTemporaryFile file; | ||||
92 | file.setAutoRemove(false); | ||||
93 | file.open(); | ||||
94 | file.write(transferjob->data()); | ||||
95 | filename = file.fileName(); | ||||
96 | file.close(); | ||||
88 | } | 97 | } | ||
89 | 98 | | |||
90 | bool rc = true; | 99 | bool rc = true; | ||
Context not available. | |||||
112 | rc = false; | 121 | rc = false; | ||
113 | } | 122 | } | ||
114 | 123 | | |||
115 | // if a temporary file was constructed by NetAccess::download, | 124 | // if a temporary file was downloaded, then it will be removed | ||
116 | // then it will be removed with the next call. Otherwise, it | 125 | // with the next call. Otherwise, it stays untouched on the local | ||
117 | // stays untouched on the local filesystem | 126 | // filesystem. | ||
118 | // TODO: port to kf5 | 127 | if (downloadedFile) { | ||
119 | //KIO::NetAccess::removeTempFile(filename); | 128 | QFile::remove(filename); | ||
129 | } | ||||
120 | return rc; | 130 | return rc; | ||
121 | } | 131 | } | ||
122 | 132 | | |||
Context not available. | |||||
466 | if (qfile.open(QIODevice::WriteOnly)) { | 476 | if (qfile.open(QIODevice::WriteOnly)) { | ||
467 | saveToLocalFile(&qfile); | 477 | saveToLocalFile(&qfile); | ||
468 | if (!qfile.commit()) { | 478 | if (!qfile.commit()) { | ||
469 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.url())); | 479 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.toDisplayString())); | ||
470 | } | 480 | } | ||
471 | } else { | 481 | } else { | ||
472 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.url())); | 482 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.toDisplayString())); | ||
483 | } | ||||
484 | int permission = -1; | ||||
485 | KIO::StoredTransferJob *putjob = KIO::storedPut(&tmpfile, url, permission); | ||||
486 | if (!putjob->exec()) { | ||||
487 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.toDisplayString())); | ||||
473 | } | 488 | } | ||
474 | // TODO: port to kf5 | | |||
475 | //if (!KIO::NetAccess::upload(tmpfile.fileName(), url, 0)) | | |||
476 | // throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.url())); | | |||
477 | } | 489 | } | ||
478 | return true; | 490 | return true; | ||
479 | } | 491 | } | ||
Context not available. |