Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/views/kmymoneyview.cpp
Show All 39 Lines | |||||
40 | // KDE Includes | 40 | // KDE Includes | ||
41 | 41 | | |||
42 | #include <KMessageBox> | 42 | #include <KMessageBox> | ||
43 | #include <KTitleWidget> | 43 | #include <KTitleWidget> | ||
44 | #include <KCompressionDevice> | 44 | #include <KCompressionDevice> | ||
45 | #include <KSharedConfig> | 45 | #include <KSharedConfig> | ||
46 | #include <KBackup> | 46 | #include <KBackup> | ||
47 | #include <KActionCollection> | 47 | #include <KActionCollection> | ||
48 | #include <KIO/StoredTransferJob> | ||||
49 | #include <KJobWidgets> | ||||
48 | 50 | | |||
49 | #ifdef KF5Activities_FOUND | 51 | #ifdef KF5Activities_FOUND | ||
50 | #include <KActivities/ResourceInstance> | 52 | #include <KActivities/ResourceInstance> | ||
51 | #endif | 53 | #endif | ||
52 | 54 | | |||
53 | // ---------------------------------------------------------------------------- | 55 | // ---------------------------------------------------------------------------- | ||
54 | // Project Includes | 56 | // Project Includes | ||
55 | 57 | | |||
▲ Show 20 Lines • Show All 739 Lines • ▼ Show 20 Line(s) | 795 | { | |||
795 | while (len--) { | 797 | while (len--) { | ||
796 | qfile->ungetChar(*buf--); | 798 | qfile->ungetChar(*buf--); | ||
797 | } | 799 | } | ||
798 | } | 800 | } | ||
799 | 801 | | |||
800 | bool KMyMoneyView::readFile(const QUrl &url, IMyMoneyStorageFormat* pExtReader) | 802 | bool KMyMoneyView::readFile(const QUrl &url, IMyMoneyStorageFormat* pExtReader) | ||
801 | { | 803 | { | ||
802 | QString filename; | 804 | QString filename; | ||
803 | 805 | bool downloadedFile = false; | |||
804 | m_fileOpen = false; | 806 | m_fileOpen = false; | ||
805 | bool isEncrypted = false; | 807 | bool isEncrypted = false; | ||
806 | 808 | | |||
807 | IMyMoneyStorageFormat* pReader = 0; | 809 | IMyMoneyStorageFormat* pReader = 0; | ||
808 | 810 | | |||
809 | if (!url.isValid()) { | 811 | if (!url.isValid()) { | ||
810 | qDebug("Invalid URL '%s'", qPrintable(url.url())); | 812 | qDebug("Invalid URL '%s'", qPrintable(url.url())); | ||
811 | return false; | 813 | return false; | ||
Show All 12 Lines | 819 | if (url.scheme() == QLatin1String("sql")) { // handle reading of database | |||
824 | return (openDatabase(newUrl)); // on error, any message will have been displayed | 826 | return (openDatabase(newUrl)); // on error, any message will have been displayed | ||
825 | } | 827 | } | ||
826 | 828 | | |||
827 | IMyMoneyStorage *storage = new MyMoneySeqAccessMgr; | 829 | IMyMoneyStorage *storage = new MyMoneySeqAccessMgr; | ||
828 | 830 | | |||
829 | if (url.isLocalFile()) { | 831 | if (url.isLocalFile()) { | ||
830 | filename = url.toLocalFile(); | 832 | filename = url.toLocalFile(); | ||
831 | } else { | 833 | } else { | ||
832 | // TODO: port to kf5 (NetAccess) | 834 | downloadedFile = true; | ||
833 | #if 0 | 835 | KIO::StoredTransferJob *transferjob = KIO::storedGet (url); | ||
834 | if (!KIO::NetAccess::download(url, filename, 0)) { | 836 | KJobWidgets::setWindow(transferjob, this); | ||
837 | if (! transferjob->exec()) { | ||||
835 | KMessageBox::detailedError(this, | 838 | KMessageBox::detailedError(this, | ||
836 | i18n("Error while loading file '%1'.", url.url()), | 839 | i18n("Error while loading file '%1'.", url.url()), | ||
837 | KIO::NetAccess::lastErrorString(), | 840 | transferjob->errorString(), | ||
838 | i18n("File access error")); | 841 | i18n("File access error")); | ||
839 | return false; | 842 | return false; | ||
840 | } | 843 | } | ||
841 | #endif | 844 | QTemporaryFile file; | ||
845 | file.setAutoRemove(false); | ||||
846 | file.open(); | ||||
847 | file.write(transferjob->data()); | ||||
848 | filename = file.fileName(); | ||||
849 | file.close(); | ||||
842 | } | 850 | } | ||
843 | 851 | | |||
844 | // let's glimps into the file to figure out, if it's one | 852 | // let's glimps into the file to figure out, if it's one | ||
845 | // of the old (uncompressed) or new (compressed) files. | 853 | // of the old (uncompressed) or new (compressed) files. | ||
846 | QFile file(filename); | 854 | QFile file(filename); | ||
847 | QFileInfo info(file); | 855 | QFileInfo info(file); | ||
848 | if (!info.isFile()) { | 856 | if (!info.isFile()) { | ||
849 | QString msg = i18n("<p><b>%1</b> is not a KMyMoney file.</p>", filename); | 857 | QString msg = i18n("<p><b>%1</b> is not a KMyMoney file.</p>", filename); | ||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | 1019 | try { | |||
1014 | checkAccountName(file->liability(), i18n("Liability")); | 1022 | checkAccountName(file->liability(), i18n("Liability")); | ||
1015 | checkAccountName(file->income(), i18n("Income")); | 1023 | checkAccountName(file->income(), i18n("Income")); | ||
1016 | checkAccountName(file->expense(), i18n("Expense")); | 1024 | checkAccountName(file->expense(), i18n("Expense")); | ||
1017 | checkAccountName(file->equity(), i18n("Equity")); | 1025 | checkAccountName(file->equity(), i18n("Equity")); | ||
1018 | ft.commit(); | 1026 | ft.commit(); | ||
1019 | } catch (const MyMoneyException &) { | 1027 | } catch (const MyMoneyException &) { | ||
1020 | } | 1028 | } | ||
1021 | 1029 | | |||
1022 | // if a temporary file was constructed by NetAccess::download, | 1030 | // if a temporary file was downloaded, then it will be removed | ||
1023 | // then it will be removed with the next call. Otherwise, it | 1031 | // with the next call. Otherwise, it stays untouched on the local | ||
1024 | // stays untouched on the local filesystem | 1032 | // filesystem. | ||
1025 | // TODO: port to KF5 (NetAccess) | 1033 | if (downloadedFile) { | ||
1026 | //KIO::NetAccess::removeTempFile(filename); | 1034 | QFile::remove(filename); | ||
1035 | } | ||||
1036 | | ||||
1027 | return initializeStorage(); | 1037 | return initializeStorage(); | ||
1028 | } | 1038 | } | ||
1029 | 1039 | | |||
1030 | void KMyMoneyView::checkAccountName(const MyMoneyAccount& _acc, const QString& name) const | 1040 | void KMyMoneyView::checkAccountName(const MyMoneyAccount& _acc, const QString& name) const | ||
1031 | { | 1041 | { | ||
1032 | auto file = MyMoneyFile::instance(); | 1042 | auto file = MyMoneyFile::instance(); | ||
1033 | if (_acc.name() != name) { | 1043 | if (_acc.name() != name) { | ||
1034 | MyMoneyAccount acc(_acc); | 1044 | MyMoneyAccount acc(_acc); | ||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Line(s) | 1325 | if (encryptFile == true) { | |||
1319 | } | 1329 | } | ||
1320 | } | 1330 | } | ||
1321 | } | 1331 | } | ||
1322 | } | 1332 | } | ||
1323 | 1333 | | |||
1324 | 1334 | | |||
1325 | // Create a temporary file if needed | 1335 | // Create a temporary file if needed | ||
1326 | QString writeFile = localFile; | 1336 | QString writeFile = localFile; | ||
1327 | QTemporaryFile tmpFile; | 1337 | QTemporaryFile tmpFile; | ||
christiand: Is this line intended? | |||||
1328 | if (QFile::exists(localFile)) { | 1338 | if (QFile::exists(localFile)) { | ||
1329 | tmpFile.open(); | 1339 | tmpFile.open(); | ||
1330 | writeFile = tmpFile.fileName(); | 1340 | writeFile = tmpFile.fileName(); | ||
1331 | tmpFile.close(); | 1341 | tmpFile.close(); | ||
1332 | } | 1342 | } | ||
1333 | 1343 | | |||
1334 | /** | 1344 | /** | ||
1335 | * @brief Automatically restore settings when scope is left | 1345 | * @brief Automatically restore settings when scope is left | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 1441 | if (url.isLocalFile()) { | |||
1439 | } catch (const MyMoneyException &) { | 1449 | } catch (const MyMoneyException &) { | ||
1440 | throw MYMONEYEXCEPTION(i18n("Unable to write changes to '%1'", filename)); | 1450 | throw MYMONEYEXCEPTION(i18n("Unable to write changes to '%1'", filename)); | ||
1441 | } | 1451 | } | ||
1442 | } else { | 1452 | } else { | ||
1443 | QTemporaryFile tmpfile; | 1453 | QTemporaryFile tmpfile; | ||
1444 | tmpfile.open(); // to obtain the name | 1454 | tmpfile.open(); // to obtain the name | ||
1445 | tmpfile.close(); | 1455 | tmpfile.close(); | ||
1446 | saveToLocalFile(tmpfile.fileName(), storageWriter.get(), plaintext, keyList); | 1456 | saveToLocalFile(tmpfile.fileName(), storageWriter.get(), plaintext, keyList); | ||
1447 | // TODO: port to kf5 | 1457 | | ||
1448 | //if (!KIO::NetAccess::upload(tmpfile.fileName(), url, 0)) | 1458 | Q_CONSTEXPR int permission = -1; | ||
tbaumgart: Q_CONSTEXPR int permission = -1; | |||||
1449 | // throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'", url.toDisplayString())); | 1459 | QFile file(tmpfile.fileName()); | ||
1460 | file.open(QIODevice::ReadOnly); | ||||
1461 | KIO::StoredTransferJob *putjob = KIO::storedPut(file.readAll(), url, permission, KIO::JobFlag::Overwrite); | ||||
1462 | if (!putjob->exec()) { | ||||
1463 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'.<br />%2", url.toDisplayString(), putjob->errorString())); | ||||
1464 | } | ||||
1465 | file.close(); | ||||
1450 | } | 1466 | } | ||
1451 | m_fileType = KmmXML; | 1467 | m_fileType = KmmXML; | ||
1452 | } catch (const MyMoneyException &e) { | 1468 | } catch (const MyMoneyException &e) { | ||
1453 | KMessageBox::error(this, e.what()); | 1469 | KMessageBox::error(this, e.what()); | ||
1454 | MyMoneyFile::instance()->setDirty(); | 1470 | MyMoneyFile::instance()->setDirty(); | ||
1455 | rc = false; | 1471 | rc = false; | ||
1456 | } | 1472 | } | ||
1457 | emit kmmFilePlugin(postSave); | 1473 | emit kmmFilePlugin(postSave); | ||
▲ Show 20 Lines • Show All 866 Lines • Show Last 20 Lines |
Is this line intended?