Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/sql/sqlstorage.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include <memory> | 20 | #include <memory> | ||
21 | #include <config-kmymoney.h> | 21 | #include <config-kmymoney.h> | ||
22 | 22 | | |||
23 | // ---------------------------------------------------------------------------- | 23 | // ---------------------------------------------------------------------------- | ||
24 | // QT Includes | 24 | // QT Includes | ||
25 | 25 | | |||
26 | #include <QUrlQuery> | 26 | #include <QUrlQuery> | ||
27 | #include <QSqlQuery> | ||||
27 | #include <QTimer> | 28 | #include <QTimer> | ||
29 | #include <QFile> | ||||
30 | #include <QSqlDriver> | ||||
28 | 31 | | |||
29 | // ---------------------------------------------------------------------------- | 32 | // ---------------------------------------------------------------------------- | ||
30 | // KDE Includes | 33 | // KDE Includes | ||
31 | 34 | | |||
32 | #include <KPluginFactory> | 35 | #include <KPluginFactory> | ||
33 | #include <KActionCollection> | 36 | #include <KActionCollection> | ||
34 | #include <KLocalizedString> | 37 | #include <KLocalizedString> | ||
35 | #include <KMessageBox> | 38 | #include <KMessageBox> | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 102 | if(!options.isEmpty()) { | |||
100 | options += QLatin1Char(','); | 103 | options += QLatin1Char(','); | ||
101 | } | 104 | } | ||
102 | options += QLatin1String("override"); | 105 | options += QLatin1String("override"); | ||
103 | query.removeQueryItem(QLatin1String("mode")); | 106 | query.removeQueryItem(QLatin1String("mode")); | ||
104 | query.removeQueryItem(optionKey); | 107 | query.removeQueryItem(optionKey); | ||
105 | query.addQueryItem(optionKey, options); | 108 | query.addQueryItem(optionKey, options); | ||
106 | dbURL.setQuery(query); | 109 | dbURL.setQuery(query); | ||
107 | } | 110 | } | ||
111 | break; | ||||
112 | case 2: // bad password | ||||
113 | case 3: // unsupported operation | ||||
114 | delete storage; | ||||
115 | return nullptr; | ||||
108 | } | 116 | } | ||
109 | } | 117 | } | ||
110 | // single user mode; read some of the data into memory | 118 | // single user mode; read some of the data into memory | ||
111 | // FIXME - readFile no longer relevant? | 119 | // FIXME - readFile no longer relevant? | ||
112 | // tried removing it but then got no indication that loading was complete | 120 | // tried removing it but then got no indication that loading was complete | ||
113 | // also, didn't show home page | 121 | // also, didn't show home page | ||
114 | // reader->setProgressCallback(&KMyMoneyView::progressCallback); | 122 | // reader->setProgressCallback(&KMyMoneyView::progressCallback); | ||
115 | if (!reader->readFile()) { | 123 | if (!reader->readFile()) { | ||
Show All 37 Lines | |||||
153 | { | 161 | { | ||
154 | auto rc = false; | 162 | auto rc = false; | ||
155 | QUrl oldUrl; | 163 | QUrl oldUrl; | ||
156 | // in event of it being a database, ensure that all data is read into storage for saveas | 164 | // in event of it being a database, ensure that all data is read into storage for saveas | ||
157 | if (appInterface()->isDatabase()) | 165 | if (appInterface()->isDatabase()) | ||
158 | oldUrl = appInterface()->filenameURL().isEmpty() ? appInterface()->lastOpenedURL() : appInterface()->filenameURL(); | 166 | oldUrl = appInterface()->filenameURL().isEmpty() ? appInterface()->lastOpenedURL() : appInterface()->filenameURL(); | ||
159 | 167 | | |||
160 | QPointer<KSelectDatabaseDlg> dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); | 168 | QPointer<KSelectDatabaseDlg> dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); | ||
161 | QUrl url = oldUrl; | 169 | QUrl url = oldUrl; | ||
tbaumgart: Why are you using a fixed name for the DB here? | |||||
wojnilowicz: That shouldn't be here. It was for testing purpose only. | |||||
162 | if (!dialog->checkDrivers()) { | 170 | if (!dialog->checkDrivers()) { | ||
163 | delete dialog; | 171 | delete dialog; | ||
164 | return rc; | 172 | return rc; | ||
165 | } | 173 | } | ||
166 | 174 | | |||
167 | while (oldUrl == url && dialog->exec() == QDialog::Accepted && dialog != 0) { | 175 | while (oldUrl == url && dialog->exec() == QDialog::Accepted && dialog != 0) { | ||
168 | url = dialog->selectedURL(); | 176 | url = dialog->selectedURL(); | ||
169 | // If the protocol is SQL for the old and new, and the hostname and database names match | 177 | // If the protocol is SQL for the old and new, and the hostname and database names match | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 229 | if (!dialog->checkDrivers()) { | |||
222 | delete dialog; | 230 | delete dialog; | ||
223 | return; | 231 | return; | ||
224 | } | 232 | } | ||
225 | 233 | | |||
226 | if (dialog->exec() == QDialog::Accepted && dialog != 0) { | 234 | if (dialog->exec() == QDialog::Accepted && dialog != 0) { | ||
227 | auto url = dialog->selectedURL(); | 235 | auto url = dialog->selectedURL(); | ||
228 | QUrl newurl = url; | 236 | QUrl newurl = url; | ||
229 | if ((newurl.scheme() == QLatin1String("sql"))) { | 237 | if ((newurl.scheme() == QLatin1String("sql"))) { | ||
230 | const QString key = QLatin1String("driver"); | 238 | const auto key = QLatin1String("driver"); | ||
231 | // take care and convert some old url to their new counterpart | 239 | // take care and convert some old url to their new counterpart | ||
232 | QUrlQuery query(newurl); | 240 | QUrlQuery query(newurl); | ||
233 | if (query.queryItemValue(key) == QLatin1String("QMYSQL3")) { // fix any old urls | 241 | if (query.queryItemValue(key) == QLatin1String("QMYSQL3")) { // fix any old urls | ||
234 | query.removeQueryItem(key); | 242 | query.removeQueryItem(key); | ||
235 | query.addQueryItem(key, QLatin1String("QMYSQL")); | 243 | query.addQueryItem(key, QLatin1String("QMYSQL")); | ||
236 | } | 244 | } else if (query.queryItemValue(key) == QLatin1String("QSQLITE3")) { | ||
237 | if (query.queryItemValue(key) == QLatin1String("QSQLITE3")) { | | |||
238 | query.removeQueryItem(key); | 245 | query.removeQueryItem(key); | ||
239 | query.addQueryItem(key, QLatin1String("QSQLITE")); | 246 | query.addQueryItem(key, QLatin1String("QSQLITE")); | ||
240 | } | 247 | } | ||
248 | #ifdef ENABLE_SQLCIPHER | ||||
249 | // Reading unencrypted database with QSQLITE | ||||
250 | // while QSQLCIPHER is available causes crash. | ||||
251 | // QSQLCIPHER can read QSQLITE | ||||
252 | if (query.queryItemValue(key) == QLatin1String("QSQLITE")) { | ||||
253 | query.removeQueryItem(key); | ||||
254 | query.addQueryItem(key, QLatin1String("QSQLCIPHER")); | ||||
255 | } | ||||
256 | #endif | ||||
257 | | ||||
241 | newurl.setQuery(query); | 258 | newurl.setQuery(query); | ||
242 | 259 | | |||
243 | // check if a password is needed. it may be if the URL came from the last/recent file list | 260 | // check if a password is needed. it may be if the URL came from the last/recent file list | ||
244 | dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite, newurl); | 261 | dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite, newurl); | ||
245 | if (!dialog->checkDrivers()) { | 262 | if (!dialog->checkDrivers()) { | ||
246 | delete dialog; | 263 | delete dialog; | ||
247 | return; | 264 | return; | ||
248 | } | 265 | } | ||
Show All 37 Lines | 302 | i18n("Database contains data which must be removed before using Save As.\n" | |||
286 | "Do you wish to continue?"), "Database not empty") == KMessageBox::Continue) { | 303 | "Do you wish to continue?"), "Database not empty") == KMessageBox::Continue) { | ||
287 | if (writer->open(url, QIODevice::WriteOnly, true) == 0) | 304 | if (writer->open(url, QIODevice::WriteOnly, true) == 0) | ||
288 | canWrite = true; | 305 | canWrite = true; | ||
289 | } else { | 306 | } else { | ||
290 | delete writer; | 307 | delete writer; | ||
291 | return false; | 308 | return false; | ||
292 | } | 309 | } | ||
293 | break; | 310 | break; | ||
311 | case 2: // bad password | ||||
312 | case 3: // unsupported operation | ||||
313 | delete writer; | ||||
314 | return false; | ||||
294 | } | 315 | } | ||
295 | if (canWrite) { | 316 | if (canWrite) { | ||
296 | delete writer; | 317 | delete writer; | ||
297 | save(url); | 318 | save(url); | ||
298 | return true; | 319 | return true; | ||
299 | } else { | 320 | } else { | ||
300 | KMessageBox::detailedError(nullptr, | 321 | KMessageBox::detailedError(nullptr, | ||
301 | i18n("Cannot open or create database %1.\n" | 322 | i18n("Cannot open or create database %1.\n" | ||
Show All 10 Lines |
Why are you using a fixed name for the DB here?