Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/kmymoney.cpp
Context not available. | |||||
970 | 970 | | |||
---|---|---|---|---|---|
971 | // actually, url should be the parameter to this function | 971 | // actually, url should be the parameter to this function | ||
972 | // but for now, this would involve too many changes | 972 | // but for now, this would involve too many changes | ||
973 | bool rc = true; | 973 | auto rc = true; | ||
christiand: From my point of view the `auto` reduces readability without adding a benefit. | |||||
I don't think it's really what counts in a review thing. I like to use auto and use it whenever I can. That's like not worth discussing. wojnilowicz: I don't think it's really what counts in a review thing. I like to use auto and use it whenever… | |||||
974 | try { | 974 | try { | ||
975 | if (! url.isValid()) { | 975 | if (! url.isValid()) { | ||
976 | throw MYMONEYEXCEPTION(i18n("Malformed URL '%1'", url.url())); | 976 | throw MYMONEYEXCEPTION(i18n("Malformed URL '%1'", url.url())); | ||
977 | } | 977 | } | ||
978 | 978 | | |||
979 | if (url.isLocalFile()) { | 979 | if (url.scheme() == QLatin1String("sql")) { | ||
980 | filename = url.toLocalFile(); | 980 | rc = false; | ||
981 | try { | 981 | auto pluginFound = false; | ||
christiand: Here, too. | |||||
982 | const unsigned int nbak = KMyMoneySettings::autoBackupCopies(); | 982 | for (const auto& plugin : m_plugins.storage) { | ||
983 | if (nbak) { | 983 | if (plugin->formatName().compare(QLatin1String("SQL")) == 0) { | ||
984 | KBackup::numberedBackupFile(filename, QString(), QStringLiteral("~"), nbak); | 984 | rc = plugin->save(url); | ||
985 | pluginFound = true; | ||||
986 | break; | ||||
987 | } | ||||
988 | } | ||||
989 | | ||||
990 | if(!pluginFound) | ||||
991 | throw MYMONEYEXCEPTION(i18n("Couldn't find suitable plugin to save your storage.")); | ||||
992 | | ||||
993 | } else if (url.isLocalFile()) { | ||||
994 | filename = url.toLocalFile(); | ||||
995 | try { | ||||
996 | const unsigned int nbak = KMyMoneySettings::autoBackupCopies(); | ||||
nbak should be a self-describing name. christiand: `nbak` should be a [[ https://community.kde. | |||||
wojnilowicz: I agree but that's not the code that I'm changing :) | |||||
997 | if (nbak) { | ||||
998 | KBackup::numberedBackupFile(filename, QString(), QStringLiteral("~"), nbak); | ||||
999 | } | ||||
1000 | saveToLocalFile(filename, storageWriter.get(), plaintext, keyList); | ||||
1001 | } catch (const MyMoneyException &) { | ||||
1002 | throw MYMONEYEXCEPTION(i18n("Unable to write changes to '%1'", filename)); | ||||
985 | } | 1003 | } | ||
986 | saveToLocalFile(filename, storageWriter.get(), plaintext, keyList); | 1004 | } else { | ||
987 | } catch (const MyMoneyException &) { | 1005 | | ||
988 | throw MYMONEYEXCEPTION(i18n("Unable to write changes to '%1'", filename)); | 1006 | QTemporaryFile tmpfile; | ||
989 | } | 1007 | tmpfile.open(); // to obtain the name | ||
990 | } else { | 1008 | tmpfile.close(); | ||
991 | QTemporaryFile tmpfile; | 1009 | saveToLocalFile(tmpfile.fileName(), storageWriter.get(), plaintext, keyList); | ||
992 | tmpfile.open(); // to obtain the name | 1010 | | ||
993 | tmpfile.close(); | 1011 | Q_CONSTEXPR int permission = -1; | ||
994 | saveToLocalFile(tmpfile.fileName(), storageWriter.get(), plaintext, keyList); | 1012 | QFile file(tmpfile.fileName()); | ||
995 | 1013 | file.open(QIODevice::ReadOnly); | |||
996 | Q_CONSTEXPR int permission = -1; | 1014 | KIO::StoredTransferJob *putjob = KIO::storedPut(file.readAll(), url, permission, KIO::JobFlag::Overwrite); | ||
997 | QFile file(tmpfile.fileName()); | 1015 | if (!putjob->exec()) { | ||
998 | file.open(QIODevice::ReadOnly); | 1016 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'.<br />%2", url.toDisplayString(), putjob->errorString())); | ||
999 | KIO::StoredTransferJob *putjob = KIO::storedPut(file.readAll(), url, permission, KIO::JobFlag::Overwrite); | 1017 | } | ||
1000 | if (!putjob->exec()) { | 1018 | file.close(); | ||
1001 | throw MYMONEYEXCEPTION(i18n("Unable to upload to '%1'.<br />%2", url.toDisplayString(), putjob->errorString())); | | |||
1002 | } | 1019 | } | ||
1003 | file.close(); | | |||
1004 | } | | |||
1005 | m_fileType = KMyMoneyApp::KmmXML; | 1020 | m_fileType = KMyMoneyApp::KmmXML; | ||
1006 | } catch (const MyMoneyException &e) { | 1021 | } catch (const MyMoneyException &e) { | ||
1007 | KMessageBox::error(q, e.what()); | 1022 | KMessageBox::error(q, e.what()); | ||
Context not available. |
From my point of view the auto reduces readability without adding a benefit.