diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,9 @@ set(KMM_ADDRESSBOOK_FOUND true) endif() +CMAKE_DEPENDENT_OPTION(ENABLE_SQLSTORAGE "Enable SQL storage support." ON + "Qt5Sql_FOUND" OFF) + # check for optional QWebEngine option(ENABLE_WEBENGINE "Enable QWebEngine" OFF) if(ENABLE_WEBENGINE) diff --git a/kmymoney/dialogs/CMakeLists.txt b/kmymoney/dialogs/CMakeLists.txt --- a/kmymoney/dialogs/CMakeLists.txt +++ b/kmymoney/dialogs/CMakeLists.txt @@ -22,7 +22,6 @@ kequitypriceupdatedlg.cpp kequitypriceupdateconfdlg.cpp kfindtransactiondlg.cpp - kgeneratesqldlg.cpp kgpgkeyselectiondlg.cpp kloadtemplatedlg.cpp kmergetransactionsdlg.cpp @@ -38,7 +37,6 @@ kpayeereassigndlg.cpp ktagreassigndlg.cpp kreportconfigurationfilterdlg.cpp - kselectdatabasedlg.cpp kselecttransactionsdlg.cpp ksplittransactiondlg.cpp ktemplateexportdlg.cpp @@ -63,13 +61,13 @@ keditscheduledlg.ui kenterscheduledlg.ui kequitypriceupdatedlg.ui kequitypriceupdateconfdlg.ui - kfindtransactiondlg.ui kgeneratesqldlg.ui + kfindtransactiondlg.ui kloadtemplatedlg.ui kmymoneyfileinfodlg.ui kmymoneypricedlg.ui knewaccountdlg.ui knewbankdlg.ui knewbudgetdlg.ui knewequityentrydlg.ui editpersonaldatadlg.ui kpayeereassigndlg.ui ktagreassigndlg.ui - kselectdatabasedlg.ui kselecttransactionsdlg.ui + kselecttransactionsdlg.ui ksortoptiondlg.ui ksplitcorrectiondlg.ui ksplittransactiondlg.ui ktemplateexportdlg.ui kupdatestockpricedlg.ui diff --git a/kmymoney/kmymoney.h b/kmymoney/kmymoney.h --- a/kmymoney/kmymoney.h +++ b/kmymoney/kmymoney.h @@ -339,6 +339,10 @@ void createAccount(MyMoneyAccount& newAccount, MyMoneyAccount& parentAccount, MyMoneyAccount& brokerageAccount, MyMoneyMoney openingBal); QString filename() const; + QUrl filenameURL() const; + + void addToRecentFiles(const QUrl& url); + QTimer* autosaveTimer(); /** * Checks if the file with the @a url already exists. If so, @@ -420,6 +424,8 @@ /** open a file and load it into the document*/ void slotFileOpen(); + bool isFileOpenedInAnotherInstance(const QUrl &url); + /** opens a file from the recent files menu */ void slotFileOpenRecent(const QUrl &url); diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -91,15 +91,13 @@ #include "wizards/newinvestmentwizard/knewinvestmentwizard.h" #include "dialogs/knewaccountdlg.h" #include "dialogs/editpersonaldatadlg.h" -#include "dialogs/kselectdatabasedlg.h" #include "dialogs/kcurrencycalculator.h" #include "dialogs/keditscheduledlg.h" #include "wizards/newloanwizard/keditloanwizard.h" #include "dialogs/kpayeereassigndlg.h" #include "dialogs/kcategoryreassigndlg.h" #include "wizards/endingbalancedlg/kendingbalancedlg.h" #include "dialogs/kbalancechartdlg.h" -#include "dialogs/kgeneratesqldlg.h" #include "dialogs/kloadtemplatedlg.h" #include "dialogs/kgpgkeyselectiondlg.h" #include "dialogs/ktemplateexportdlg.h" @@ -138,6 +136,7 @@ #include "converter/mymoneystatementreader.h" #include "converter/mymoneytemplate.h" +#include "plugins/interfaces/kmmappinterface.h" #include "plugins/interfaces/kmmviewinterface.h" #include "plugins/interfaces/kmmstatementinterface.h" #include "plugins/interfaces/kmmimportinterface.h" @@ -152,7 +151,6 @@ #include "misc/webconnect.h" #include "storage/mymoneystoragemgr.h" -#include "storage/mymoneystoragesql.h" #include @@ -431,6 +429,7 @@ KMyMoneyPlugin::pluginHandling(KMyMoneyPlugin::Action::Load, d->m_plugins, this, guiFactory()); onlineJobAdministration::instance()->setOnlinePlugins(d->m_plugins.extended); d->m_myMoneyView->setOnlinePlugins(d->m_plugins.online); + d->m_myMoneyView->setStoragePlugins(d->m_plugins.storage); setCentralWidget(frame); @@ -617,8 +616,6 @@ // ************* // The File menu // ************* - {Action::FileOpenDatabase, QStringLiteral("open_database"), i18n("Open database..."), Icon::SVNUpdate}, - {Action::FileSaveAsDatabase, QStringLiteral("saveas_database"), i18n("Save as database..."), Icon::FileArchiver}, {Action::FileBackup, QStringLiteral("file_backup"), i18n("Backup..."), Icon::Empty}, {Action::FileImportStatement, QStringLiteral("file_import_statement"), i18n("Statement file..."), Icon::Empty}, {Action::FileImportTemplate, QStringLiteral("file_import_template"), i18n("Account Template..."), Icon::Empty}, @@ -678,7 +675,6 @@ {Action::ToolUpdatePrices, QStringLiteral("tools_update_prices"), i18n("Update Stock and Currency Prices..."), Icon::ToolUpdatePrices}, {Action::ToolConsistency, QStringLiteral("tools_consistency_check"), i18n("Consistency Check"), Icon::Empty}, {Action::ToolPerformance, QStringLiteral("tools_performancetest"), i18n("Performance-Test"), Icon::Fork}, - {Action::ToolSQL, QStringLiteral("tools_generate_sql"), i18n("Generate Database SQL"), Icon::Empty}, {Action::ToolCalculator, QStringLiteral("tools_kcalc"), i18n("Calculator..."), Icon::AccessoriesCalculator}, // ***************** // The settings menu @@ -765,8 +761,8 @@ // ************* // The File menu // ************* - {Action::FileOpenDatabase, &KMyMoneyApp::slotOpenDatabase}, - {Action::FileSaveAsDatabase, &KMyMoneyApp::slotSaveAsDatabase}, +// {Action::FileOpenDatabase, &KMyMoneyApp::slotOpenDatabase}, +// {Action::FileSaveAsDatabase, &KMyMoneyApp::slotSaveAsDatabase}, {Action::FileBackup, &KMyMoneyApp::slotBackupFile}, {Action::FileImportTemplate, &KMyMoneyApp::slotLoadAccountTemplates}, {Action::FileExportTemplate, &KMyMoneyApp::slotSaveAccountTemplates}, @@ -801,7 +797,7 @@ {Action::ToolUpdatePrices, &KMyMoneyApp::slotEquityPriceUpdate}, {Action::ToolConsistency, &KMyMoneyApp::slotFileConsistencyCheck}, {Action::ToolPerformance, &KMyMoneyApp::slotPerformanceTest}, - {Action::ToolSQL, &KMyMoneyApp::slotGenerateSql}, +// {Action::ToolSQL, &KMyMoneyApp::slotGenerateSql}, {Action::ToolCalculator, &KMyMoneyApp::slotToolsStartKCalc}, // ***************** // The settings menu @@ -1250,17 +1246,17 @@ void KMyMoneyApp::slotOpenDatabase() { - KMSTATUS(i18n("Open a file.")); - QPointer dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite); - if (!dialog->checkDrivers()) { - delete dialog; - return; - } +// KMSTATUS(i18n("Open a file.")); +// QPointer dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite); +// if (!dialog->checkDrivers()) { +// delete dialog; +// return; +// } - if (dialog->exec() == QDialog::Accepted && dialog != 0) { - slotFileOpenRecent(dialog->selectedURL()); - } - delete dialog; +// if (dialog->exec() == QDialog::Accepted && dialog != 0) { +// slotFileOpenRecent(dialog->selectedURL()); +// } +// delete dialog; } bool KMyMoneyApp::isImportableFile(const QUrl &url) @@ -1291,68 +1287,28 @@ return result; } - -void KMyMoneyApp::slotFileOpenRecent(const QUrl &url) +bool KMyMoneyApp::isFileOpenedInAnotherInstance(const QUrl &url) { - KMSTATUS(i18n("Loading file...")); - QUrl lastFile = d->m_fileName; - - // check if there are other instances which might have this file open - QList list = instanceList(); - QList::ConstIterator it; - bool duplicate = false; + const auto instances = instanceList(); #ifdef KMM_DBUS - for (it = list.constBegin(); duplicate == false && it != list.constEnd(); ++it) { - QDBusInterface remoteApp(*it, "/KMymoney", "org.kde.kmymoney"); + // check if there are other instances which might have this file open + for (const auto& instance : instances) { + QDBusInterface remoteApp(instance, "/KMymoney", "org.kde.kmymoney"); QDBusReply reply = remoteApp.call("filename"); - if (!reply.isValid()) { + if (!reply.isValid()) qDebug("D-Bus error while calling app->filename()"); - } else { - if (reply.value() == url.url()) { - duplicate = true; - } - } + else if (reply.value() == url.url()) + return true; } #endif - if (!duplicate) { - QUrl newurl = url; - if ((newurl.scheme() == QLatin1String("sql"))) { - const QString key = QLatin1String("driver"); - // take care and convert some old url to their new counterpart - QUrlQuery query(newurl); - if (query.queryItemValue(key) == QLatin1String("QMYSQL3")) { // fix any old urls - query.removeQueryItem(key); - query.addQueryItem(key, QLatin1String("QMYSQL")); - } - if (query.queryItemValue(key) == QLatin1String("QSQLITE3")) { - query.removeQueryItem(key); - query.addQueryItem(key, QLatin1String("QSQLITE")); - } - newurl.setQuery(query); - - if (query.queryItemValue(key) == QLatin1String("QSQLITE")) { - newurl.setUserInfo(QString()); - newurl.setHost(QString()); - } - // check if a password is needed. it may be if the URL came from the last/recent file list - QPointer dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite, newurl); - if (!dialog->checkDrivers()) { - delete dialog; - return; - } - // if we need to supply a password, then show the dialog - // otherwise it isn't needed - if ((query.queryItemValue("secure").toLower() == QLatin1String("yes")) && newurl.password().isEmpty()) { - if (dialog->exec() == QDialog::Accepted && dialog != nullptr) { - newurl = dialog->selectedURL(); - } else { - delete dialog; - return; - } - } - delete dialog; - } + return false; +} +void KMyMoneyApp::slotFileOpenRecent(const QUrl &url) +{ + KMSTATUS(i18n("Loading file...")); + if (!isFileOpenedInAnotherInstance(url)) { + QUrl newurl = url; if (newurl.scheme() == QLatin1String("sql") || KMyMoneyUtils::fileExists(newurl)) { slotFileClose(); if (!d->m_myMoneyView->fileOpen()) { @@ -1403,10 +1359,20 @@ d->consistencyCheck(false); setEnabled(false); - if (d->m_myMoneyView->isDatabase()) - rc = d->m_myMoneyView->saveDatabase(d->m_fileName); - else + if (d->m_myMoneyView->isDatabase()) { + auto pluginFound = false; + for (const auto& plugin : d->m_plugins.storage) { + if (plugin->formatName().compare(QLatin1String("SQL")) == 0) { + rc = plugin->save(d->m_fileName); + pluginFound = true; + break; + } + } + if(!pluginFound) + KMessageBox::error(this, i18n("Couldn't find suitable plugin to save your storage.")); + } else { rc = d->m_myMoneyView->saveFile(d->m_fileName, MyMoneyFile::instance()->value("kmm-encryption-key")); + } setEnabled(true); d->m_autoSaveTimer->stop(); @@ -1574,48 +1540,49 @@ bool KMyMoneyApp::saveAsDatabase() { - bool rc = false; - QUrl oldUrl; - // in event of it being a database, ensure that all data is read into storage for saveas - if (d->m_myMoneyView->isDatabase()) - oldUrl = d->m_fileName.isEmpty() ? lastOpenedURL() : d->m_fileName; - - KMSTATUS(i18n("Saving file to database...")); - QPointer dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); - QUrl url = oldUrl; - if (!dialog->checkDrivers()) { - delete dialog; - return (false); - } - - while (oldUrl == url && dialog->exec() == QDialog::Accepted && dialog != 0) { - url = dialog->selectedURL(); - // If the protocol is SQL for the old and new, and the hostname and database names match - // Let the user know that the current database cannot be saved on top of itself. - if (url.scheme() == "sql" && oldUrl.scheme() == "sql" - && oldUrl.host() == url.host() - && QUrlQuery(oldUrl).queryItemValue("driver") == QUrlQuery(url).queryItemValue("driver") - && oldUrl.path().right(oldUrl.path().length() - 1) == url.path().right(url.path().length() - 1)) { - KMessageBox::sorry(this, i18n("Cannot save to current database.")); - } else { - try { - rc = d->m_myMoneyView->saveAsDatabase(url); - } catch (const MyMoneyException &e) { - KMessageBox::sorry(this, i18n("Cannot save to current database: %1", e.what())); - } - } - } - delete dialog; - - if (rc) { - //KRecentFilesAction *p = dynamic_cast(action("file_open_recent")); - //if(p) - d->m_recentFiles->addUrl(url); - writeLastUsedFile(url.toDisplayString(QUrl::PreferLocalFile)); - } - d->m_autoSaveTimer->stop(); - updateCaption(); - return rc; +// bool rc = false; +// QUrl oldUrl; +// // in event of it being a database, ensure that all data is read into storage for saveas +// if (d->m_myMoneyView->isDatabase()) +// oldUrl = d->m_fileName.isEmpty() ? lastOpenedURL() : d->m_fileName; + +// KMSTATUS(i18n("Saving file to database...")); +// QPointer dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); +// QUrl url = oldUrl; +// if (!dialog->checkDrivers()) { +// delete dialog; +// return (false); +// } + +// while (oldUrl == url && dialog->exec() == QDialog::Accepted && dialog != 0) { +// url = dialog->selectedURL(); +// // If the protocol is SQL for the old and new, and the hostname and database names match +// // Let the user know that the current database cannot be saved on top of itself. +// if (url.scheme() == "sql" && oldUrl.scheme() == "sql" +// && oldUrl.host() == url.host() +// && QUrlQuery(oldUrl).queryItemValue("driver") == QUrlQuery(url).queryItemValue("driver") +// && oldUrl.path().right(oldUrl.path().length() - 1) == url.path().right(url.path().length() - 1)) { +// KMessageBox::sorry(this, i18n("Cannot save to current database.")); +// } else { +// try { +// rc = d->m_myMoneyView->saveAsDatabase(url); +// } catch (const MyMoneyException &e) { +// KMessageBox::sorry(this, i18n("Cannot save to current database: %1", e.what())); +// } +// } +// } +// delete dialog; + +// if (rc) { +// //KRecentFilesAction *p = dynamic_cast(action("file_open_recent")); +// //if(p) +// d->m_recentFiles->addUrl(url); +// writeLastUsedFile(url.toDisplayString(QUrl::PreferLocalFile)); +// } +// d->m_autoSaveTimer->stop(); +// updateCaption(); +// return rc; + return false; } void KMyMoneyApp::slotFileCloseWindow() @@ -1953,7 +1920,7 @@ d->m_myMoneyView->updateViewType(); // update the sql storage module settings - MyMoneyStorageSql::setStartDate(KMyMoneyGlobalSettings::startDate().date()); +// MyMoneyStorageSql::setStartDate(KMyMoneyGlobalSettings::startDate().date()); // update the report module settings MyMoneyReport::setLineWidth(KMyMoneyGlobalSettings::lineWidth()); @@ -2208,10 +2175,10 @@ void KMyMoneyApp::slotGenerateSql() { - QPointer editor = new KGenerateSqlDlg(this); - editor->setObjectName("Generate Database SQL"); - editor->exec(); - delete editor; +// QPointer editor = new KGenerateSqlDlg(this); +// editor->setObjectName("Generate Database SQL"); +// editor->exec(); +// delete editor; } void KMyMoneyApp::slotToolsStartKCalc() @@ -2616,8 +2583,8 @@ { QString tooltip = i18n("Create a new transaction"); const QVector> actionStates { - {qMakePair(Action::FileOpenDatabase, true)}, - {qMakePair(Action::FileSaveAsDatabase, fileOpen)}, +// {qMakePair(Action::FileOpenDatabase, true)}, +// {qMakePair(Action::FileSaveAsDatabase, fileOpen)}, {qMakePair(Action::FilePersonalData, fileOpen)}, {qMakePair(Action::FileBackup, (fileOpen && !d->m_myMoneyView->isDatabase()))}, {qMakePair(Action::FileInformation, fileOpen)}, @@ -2937,6 +2904,21 @@ return d->m_fileName.url(); } +QUrl KMyMoneyApp::filenameURL() const +{ + return d->m_fileName; +} + +void KMyMoneyApp::addToRecentFiles(const QUrl& url) +{ + d->m_recentFiles->addUrl(url); +} + +QTimer* KMyMoneyApp::autosaveTimer() +{ + return d->m_autoSaveTimer; +} + WebConnect* KMyMoneyApp::webConnect() const { return d->m_webConnect; @@ -3049,6 +3031,7 @@ void KMyMoneyApp::createInterfaces() { // Sets up the plugin interface + KMyMoneyPlugin::pluginInterfaces().appInterface = new KMyMoneyPlugin::KMMAppInterface(this, this); KMyMoneyPlugin::pluginInterfaces().importInterface = new KMyMoneyPlugin::KMMImportInterface(this); KMyMoneyPlugin::pluginInterfaces().statementInterface = new KMyMoneyPlugin::KMMStatementInterface(this); KMyMoneyPlugin::pluginInterfaces().viewInterface = new KMyMoneyPlugin::KMMViewInterface(d->m_myMoneyView, this); diff --git a/kmymoney/kmymoneyui.rc b/kmymoney/kmymoneyui.rc --- a/kmymoney/kmymoneyui.rc +++ b/kmymoney/kmymoneyui.rc @@ -1,9 +1,9 @@ - + - - + + &Import @@ -99,7 +99,7 @@ - + diff --git a/kmymoney/mymoney/storage/CMakeLists.txt b/kmymoney/mymoney/storage/CMakeLists.txt --- a/kmymoney/mymoney/storage/CMakeLists.txt +++ b/kmymoney/mymoney/storage/CMakeLists.txt @@ -14,9 +14,6 @@ mymoneystoragexml.cpp mymoneystoragemgr.cpp mymoneystorageanon.cpp - mymoneystoragesql.cpp - mymoneydbdef.cpp - mymoneydbdriver.cpp kmymoneystorageplugin.cpp mymoneystoragenames.cpp ) @@ -45,7 +42,3 @@ install(FILES ${storage_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/kmymoney COMPONENT Devel ) - -install(FILES kmymoney-sqlstorageplugin.desktop - DESTINATION ${SERVICETYPES_INSTALL_DIR} -) diff --git a/kmymoney/payeeidentifier/ibanandbic/CMakeLists.txt b/kmymoney/payeeidentifier/ibanandbic/CMakeLists.txt --- a/kmymoney/payeeidentifier/ibanandbic/CMakeLists.txt +++ b/kmymoney/payeeidentifier/ibanandbic/CMakeLists.txt @@ -31,39 +31,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/ibanbicdata.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) -# Storage plugin - -configure_file(kmymoney-ibanbic-storageplugin.desktop.in kmymoney-ibanbic-storageplugin.desktop) - -set ( IBAN_BIC_STORAGE_PLUGIN_SCRS - ibanbicstorageplugin.cpp -) - -add_library( payeeidentifier_ibanbic_storageplugin MODULE - ${IBAN_BIC_STORAGE_PLUGIN_SCRS} -) - -target_link_libraries( payeeidentifier_ibanbic_storageplugin - Qt5::Core - Qt5::Sql - kmm_mymoney -) -# The json files of payeeidentifier_iban_bic are currently required -add_dependencies(payeeidentifier_ibanbic_storageplugin payeeidentifier_iban_bic) - -kcoreaddons_desktop_to_json(payeeidentifier_ibanbic_storageplugin - "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-ibanbic-storageplugin.desktop" - SERVICE_TYPES "${KMyMoney_SOURCE_DIR}/kmymoney/mymoney/storage/kmymoney-sqlstorageplugin.desktop" - ) - -install(TARGETS payeeidentifier_ibanbic_storageplugin - DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") - -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-ibanbic-storageplugin.desktop" - DESTINATION ${SERVICES_INSTALL_DIR} - ) - if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/kmymoney/payeeidentifier/nationalaccount/CMakeLists.txt b/kmymoney/payeeidentifier/nationalaccount/CMakeLists.txt --- a/kmymoney/payeeidentifier/nationalaccount/CMakeLists.txt +++ b/kmymoney/payeeidentifier/nationalaccount/CMakeLists.txt @@ -27,34 +27,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kmymoney-nationalaccountnumberplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) -# Storage plugin - -set ( nationalAccount_STORAGE_PLUGIN_SCRS - nationalaccountstorageplugin.cpp -) - -add_library( payeeidentifier_nationalaccount_storageplugin MODULE - ${nationalAccount_STORAGE_PLUGIN_SCRS} -) - -target_link_libraries( payeeidentifier_nationalaccount_storageplugin - Qt5::Core - Qt5::Sql - kmm_mymoney -) - -configure_file(kmymoney-nationalaccount-storageplugin.desktop.in kmymoney-nationalaccount-storageplugin.desktop) -kcoreaddons_desktop_to_json(payeeidentifier_nationalaccount_storageplugin - "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-nationalaccount-storageplugin.desktop" - SERVICE_TYPES "${KMyMoney_SOURCE_DIR}/kmymoney/mymoney/storage/kmymoney-sqlstorageplugin.desktop" -) - -install(TARGETS payeeidentifier_nationalaccount_storageplugin - DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") - -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/kmymoney-nationalaccount-storageplugin.desktop - DESTINATION ${SERVICES_INSTALL_DIR} -) - add_subdirectory( ui ) diff --git a/kmymoney/pluginloader.h b/kmymoney/pluginloader.h --- a/kmymoney/pluginloader.h +++ b/kmymoney/pluginloader.h @@ -41,6 +41,7 @@ class OnlinePlugin; class OnlinePluginExtended; class ImporterPlugin; + class StoragePlugin; enum class eListing; @@ -70,6 +71,7 @@ QMap online; // casted standard plugin, if such interface is available QMap extended; // casted standard plugin, if such interface is available QMap importer; // casted standard plugin, if such interface is available + QMap storage; // casted standard plugin, if such interface is available }; Category pluginCategory(const KPluginMetaData& pluginInfo); diff --git a/kmymoney/pluginloader.cpp b/kmymoney/pluginloader.cpp --- a/kmymoney/pluginloader.cpp +++ b/kmymoney/pluginloader.cpp @@ -91,6 +91,7 @@ ctnPlugins.online.remove(it.key()); ctnPlugins.extended.remove(it.key()); ctnPlugins.importer.remove(it.key()); + ctnPlugins.storage.remove(it.key()); guiFactory->removeClient(it.value()); it.value()->unplug(); @@ -143,6 +144,10 @@ if (IImporter) ctnPlugins.importer.insert((*it).pluginId(), IImporter); + auto IStorage = qobject_cast(plugin); + if (IStorage) + ctnPlugins.storage.insert((*it).pluginId(), IStorage); + } } diff --git a/kmymoney/plugins/CMakeLists.txt b/kmymoney/plugins/CMakeLists.txt --- a/kmymoney/plugins/CMakeLists.txt +++ b/kmymoney/plugins/CMakeLists.txt @@ -9,6 +9,10 @@ add_subdirectory( reconciliationreport ) add_subdirectory( checkprinting ) +if(ENABLE_SQLSTORAGE) + add_subdirectory(sql) +endif() + if (KBANKING_FOUND) add_subdirectory( kbanking ) endif (KBANKING_FOUND) @@ -30,6 +34,7 @@ ########### next target ############### set(kmm_plugin_LIB_SRCS + appinterface.cpp importinterface.cpp kmymoneyplugin.cpp statementinterface.cpp @@ -39,6 +44,7 @@ ) set(plugins_HEADERS + appinterface.h importinterface.h kmymoneyplugin.h statementinterface.h diff --git a/kmymoney/dialogs/kgeneratesqldlg.h b/kmymoney/plugins/appinterface.h rename from kmymoney/dialogs/kgeneratesqldlg.h rename to kmymoney/plugins/appinterface.h --- a/kmymoney/dialogs/kgeneratesqldlg.h +++ b/kmymoney/plugins/appinterface.h @@ -1,10 +1,9 @@ /*************************************************************************** - kgeneratesql.h + appinterface.h ------------------- - copyright : (C) 2005 by Tony Bloomfield - (C) 2017 by Łukasz Wojniłowicz + copyright : (C) 2018 by Łukasz Wojniłowicz -***************************************************************************/ + ***************************************************************************/ /*************************************************************************** * * @@ -15,44 +14,43 @@ * * ***************************************************************************/ -#ifndef KGENERATESQLDLG_H -#define KGENERATESQLDLG_H +#ifndef APPINTERFACE_H +#define APPINTERFACE_H // ---------------------------------------------------------------------------- // QT Includes -#include +#include // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes -class KGenerateSqlDlgPrivate; -class KGenerateSqlDlg : public QDialog +#include + +class QTimer; + +namespace KMyMoneyPlugin { - Q_OBJECT - Q_DISABLE_COPY(KGenerateSqlDlg) - -public: - explicit KGenerateSqlDlg(QWidget *parent = nullptr); - ~KGenerateSqlDlg(); - /** - * execute the generation - */ - int exec() override; - -public Q_SLOTS: - void slotHelp(); - void slotdriverSelected(); - void slotcreateTables(); - void slotsaveSQL(); - -private: - KGenerateSqlDlgPrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGenerateSqlDlg) - -}; + class KMM_PLUGIN_EXPORT AppInterface : public QObject + { + Q_OBJECT + + public: + explicit AppInterface(QObject* parent, const char* name = 0); + virtual ~AppInterface(); + + virtual QUrl filenameURL() const = 0; + virtual QUrl lastOpenedURL() = 0; + virtual void writeLastUsedFile(const QString& fileName) = 0; + virtual void slotFileOpenRecent(const QUrl &url) = 0; + virtual void addToRecentFiles(const QUrl& url) = 0; + virtual void updateCaption(bool skipActions = false) = 0; + virtual QTimer* autosaveTimer() = 0; + }; + +} #endif diff --git a/kmymoney/dialogs/kgeneratesqldlg.h b/kmymoney/plugins/appinterface.cpp copy from kmymoney/dialogs/kgeneratesqldlg.h copy to kmymoney/plugins/appinterface.cpp --- a/kmymoney/dialogs/kgeneratesqldlg.h +++ b/kmymoney/plugins/appinterface.cpp @@ -1,10 +1,8 @@ /*************************************************************************** - kgeneratesql.h + appinterface.cpp ------------------- - copyright : (C) 2005 by Tony Bloomfield - (C) 2017 by Łukasz Wojniłowicz - -***************************************************************************/ + copyright : (C) 2018 by Łukasz Wojniłowicz + ***************************************************************************/ /*************************************************************************** * * @@ -15,44 +13,23 @@ * * ***************************************************************************/ -#ifndef KGENERATESQLDLG_H -#define KGENERATESQLDLG_H - // ---------------------------------------------------------------------------- // QT Includes -#include - // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes -class KGenerateSqlDlgPrivate; -class KGenerateSqlDlg : public QDialog -{ - Q_OBJECT - Q_DISABLE_COPY(KGenerateSqlDlg) - -public: - explicit KGenerateSqlDlg(QWidget *parent = nullptr); - ~KGenerateSqlDlg(); - /** - * execute the generation - */ - int exec() override; - -public Q_SLOTS: - void slotHelp(); - void slotdriverSelected(); - void slotcreateTables(); - void slotsaveSQL(); - -private: - KGenerateSqlDlgPrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGenerateSqlDlg) +#include "appinterface.h" -}; +KMyMoneyPlugin::AppInterface::AppInterface(QObject* parent, const char* name) : + QObject(parent) +{ + setObjectName(name); +} -#endif +KMyMoneyPlugin::AppInterface::~AppInterface() +{ +} diff --git a/kmymoney/plugins/interfaceloader.h b/kmymoney/plugins/interfaceloader.h --- a/kmymoney/plugins/interfaceloader.h +++ b/kmymoney/plugins/interfaceloader.h @@ -21,6 +21,7 @@ #include "kmm_plugin_export.h" +namespace KMyMoneyPlugin { class AppInterface; } namespace KMyMoneyPlugin { class ImportInterface; } namespace KMyMoneyPlugin { class StatementInterface; } namespace KMyMoneyPlugin { class ViewInterface; } @@ -45,6 +46,7 @@ * @{ * This class is owner of these objects. However, the parent is somebody else. They are deleted by destruction of the parent only. */ + KMyMoneyPlugin::AppInterface* appInterface; KMyMoneyPlugin::ViewInterface* viewInterface; KMyMoneyPlugin::StatementInterface* statementInterface; KMyMoneyPlugin::ImportInterface* importInterface; diff --git a/kmymoney/plugins/interfaces/CMakeLists.txt b/kmymoney/plugins/interfaces/CMakeLists.txt --- a/kmymoney/plugins/interfaces/CMakeLists.txt +++ b/kmymoney/plugins/interfaces/CMakeLists.txt @@ -1,5 +1,7 @@ set (libinterfaces_a_SOURCES - kmmimportinterface.cpp kmmstatementinterface.cpp + kmmappinterface.cpp + kmmimportinterface.cpp + kmmstatementinterface.cpp kmmviewinterface.cpp ) diff --git a/kmymoney/dialogs/kgeneratesqldlg.h b/kmymoney/plugins/interfaces/kmmappinterface.h copy from kmymoney/dialogs/kgeneratesqldlg.h copy to kmymoney/plugins/interfaces/kmmappinterface.h --- a/kmymoney/dialogs/kgeneratesqldlg.h +++ b/kmymoney/plugins/interfaces/kmmappinterface.h @@ -1,10 +1,11 @@ /*************************************************************************** - kgeneratesql.h + kmmappinterface.h ------------------- - copyright : (C) 2005 by Tony Bloomfield + begin : Mon Apr 14 2008 + copyright : (C) 2008 Thomas Baumgart + email : ipwizard@users.sourceforge.net (C) 2017 by Łukasz Wojniłowicz - -***************************************************************************/ + ***************************************************************************/ /*************************************************************************** * * @@ -15,44 +16,50 @@ * * ***************************************************************************/ -#ifndef KGENERATESQLDLG_H -#define KGENERATESQLDLG_H +#ifndef KMMAPPINTERFACE_H +#define KMMAPPINTERFACE_H // ---------------------------------------------------------------------------- // QT Includes -#include +#include // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes -class KGenerateSqlDlgPrivate; -class KGenerateSqlDlg : public QDialog -{ - Q_OBJECT - Q_DISABLE_COPY(KGenerateSqlDlg) +#include "appinterface.h" -public: - explicit KGenerateSqlDlg(QWidget *parent = nullptr); - ~KGenerateSqlDlg(); +class KMyMoneyApp; + +namespace KMyMoneyPlugin +{ /** - * execute the generation - */ - int exec() override; + * This class represents the implementation of the + * AppInterface. + */ + class KMMAppInterface : public AppInterface + { + Q_OBJECT + + public: + explicit KMMAppInterface(KMyMoneyApp* app, QObject* parent, const char* name = 0); + ~KMMAppInterface() override = default; -public Q_SLOTS: - void slotHelp(); - void slotdriverSelected(); - void slotcreateTables(); - void slotsaveSQL(); + QUrl filenameURL() const override; + QUrl lastOpenedURL() override; + void writeLastUsedFile(const QString& fileName) override; + void slotFileOpenRecent(const QUrl &url) override; + void addToRecentFiles(const QUrl& url) override; + void updateCaption(bool skipActions = false) override; + QTimer* autosaveTimer() override; -private: - KGenerateSqlDlgPrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGenerateSqlDlg) + private: + KMyMoneyApp* m_app; + }; -}; +} #endif diff --git a/kmymoney/plugins/interfaces/kmmappinterface.cpp b/kmymoney/plugins/interfaces/kmmappinterface.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/interfaces/kmmappinterface.cpp @@ -0,0 +1,71 @@ +/*************************************************************************** + kmmappinterface.cpp + ------------------- + begin : Mon Apr 14 2008 + copyright : (C) 2008 Thomas Baumgart + email : ipwizard@users.sourceforge.net + (C) 2017 by Łukasz Wojniłowicz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kmmappinterface.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoney.h" + +KMyMoneyPlugin::KMMAppInterface::KMMAppInterface(KMyMoneyApp* app, QObject* parent, const char* name) : + AppInterface(parent, name), + m_app(app) +{ +} + +QUrl KMyMoneyPlugin::KMMAppInterface::filenameURL() const +{ + return m_app->filenameURL(); +} + +QUrl KMyMoneyPlugin::KMMAppInterface::lastOpenedURL() +{ + return m_app->lastOpenedURL(); +} + +void KMyMoneyPlugin::KMMAppInterface::writeLastUsedFile(const QString& fileName) +{ + m_app->writeLastUsedFile(fileName); +} + +void KMyMoneyPlugin::KMMAppInterface::slotFileOpenRecent(const QUrl &url) +{ + m_app->slotFileOpenRecent(url); +} + +void KMyMoneyPlugin::KMMAppInterface::addToRecentFiles(const QUrl& url) +{ + m_app->addToRecentFiles(url); +} + +void KMyMoneyPlugin::KMMAppInterface::updateCaption(bool skipActions) +{ + m_app->updateCaption(skipActions); +} + +QTimer* KMyMoneyPlugin::KMMAppInterface::autosaveTimer() +{ + return m_app->autosaveTimer(); +} diff --git a/kmymoney/plugins/interfaces/kmmviewinterface.h b/kmymoney/plugins/interfaces/kmmviewinterface.h --- a/kmymoney/plugins/interfaces/kmmviewinterface.h +++ b/kmymoney/plugins/interfaces/kmmviewinterface.h @@ -86,6 +86,8 @@ */ bool fileOpen() override; + bool isDatabase() override; + /** * Brings up a dialog to change the list(s) settings and saves them into the * class KMyMoneySettings (a singleton). diff --git a/kmymoney/plugins/interfaces/kmmviewinterface.cpp b/kmymoney/plugins/interfaces/kmmviewinterface.cpp --- a/kmymoney/plugins/interfaces/kmmviewinterface.cpp +++ b/kmymoney/plugins/interfaces/kmmviewinterface.cpp @@ -62,6 +62,12 @@ return m_view->fileOpen(); } +bool KMyMoneyPlugin::KMMViewInterface::isDatabase() +{ + return m_view->isDatabase(); +} + + //KMyMoneyViewBase* KMyMoneyPlugin::KMMViewInterface::addPage(const QString& item, const QString& icon) //{ // return m_view->addBasePage(item, icon); diff --git a/kmymoney/plugins/kmymoneyplugin.h b/kmymoney/plugins/kmymoneyplugin.h --- a/kmymoney/plugins/kmymoneyplugin.h +++ b/kmymoney/plugins/kmymoneyplugin.h @@ -38,8 +38,11 @@ #include "mymoneykeyvaluecontainer.h" +class MyMoneyStorageMgr; class MyMoneyAccount; class KMyMoneySettings; + +namespace KMyMoneyPlugin { class AppInterface; } namespace KMyMoneyPlugin { class ImportInterface; } namespace KMyMoneyPlugin { class StatementInterface; } namespace KMyMoneyPlugin { class ViewInterface; } @@ -139,6 +142,8 @@ // named Xxx: // // XxxInterface* xxxInterface(); + + AppInterface* appInterface() const; ViewInterface* viewInterface() const; StatementInterface* statementInterface() const; ImportInterface* importInterface() const; @@ -273,10 +278,46 @@ }; +/** + * This class describes the interface between the KMyMoney + * application and it's STORAGE plugins. All storage plugins + * must provide this interface. + * + */ +class KMM_PLUGIN_EXPORT StoragePlugin +{ +public: + StoragePlugin() = default; + virtual ~StoragePlugin() = default; + + /** + * @brief Loads file into storage + * @param storage Storage manager for the file + * @param url URL of the file + * @return true if successfully opened + */ + virtual bool open(MyMoneyStorageMgr *storage, const QUrl &url) = 0; + + /** + * @brief Saves storage into file + * @param url URL of the file + * @return true if successfully saved + */ + virtual bool save(const QUrl &url) = 0; + + /** + * @brief Storage identifier + * @return Storage identifier + */ + virtual QString formatName() const = 0; +}; + + } // end of namespace Q_DECLARE_INTERFACE(KMyMoneyPlugin::OnlinePlugin, "org.kmymoney.plugin.onlineplugin") Q_DECLARE_INTERFACE(KMyMoneyPlugin::ImporterPlugin, "org.kmymoney.plugin.importerplugin") +Q_DECLARE_INTERFACE(KMyMoneyPlugin::StoragePlugin, "org.kmymoney.plugin.storageplugin") /** @} */ diff --git a/kmymoney/plugins/kmymoneyplugin.cpp b/kmymoney/plugins/kmymoneyplugin.cpp --- a/kmymoney/plugins/kmymoneyplugin.cpp +++ b/kmymoney/plugins/kmymoneyplugin.cpp @@ -77,6 +77,12 @@ { } +KMyMoneyPlugin::AppInterface* KMyMoneyPlugin::Plugin::appInterface() const +{ + Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().appInterface); + return KMyMoneyPlugin::pluginInterfaces().appInterface; +} + KMyMoneyPlugin::ViewInterface* KMyMoneyPlugin::Plugin::viewInterface() const { Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().viewInterface); diff --git a/kmymoney/plugins/sql/CMakeLists.txt b/kmymoney/plugins/sql/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/CMakeLists.txt @@ -0,0 +1,38 @@ +add_subdirectory(payeeidentifier) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sqlstorage.json.in ${CMAKE_CURRENT_BINARY_DIR}/sqlstorage.json @ONLY) + +set(sqlstorage_SOURCES + sqlstorage.cpp + mymoneystoragesql.cpp + mymoneydbdef.cpp + mymoneydbdriver.cpp + kselectdatabasedlg.cpp + kgeneratesqldlg.cpp + ) + +ki18n_wrap_ui(sqlstorage_SOURCES kselectdatabasedlg.ui kgeneratesqldlg.ui) + +add_library(sqlstorage MODULE ${sqlstorage_SOURCES} ) +kde_target_enable_exceptions(sqlstorage PUBLIC) + +target_link_libraries(sqlstorage + PUBLIC + kmm_plugin + kmm_widgets + kmm_utils_platformtools +) + +install(FILES sqlstorage.rc + DESTINATION "${KXMLGUI_INSTALL_DIR}/sqlstorage") + +install(TARGETS sqlstorage + DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") + +install(FILES kmymoney-sqlstorageplugin.desktop + DESTINATION ${SERVICETYPES_INSTALL_DIR} +) + +if(BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/kmymoney/dialogs/kgeneratesqldlg.h b/kmymoney/plugins/sql/kgeneratesqldlg.h rename from kmymoney/dialogs/kgeneratesqldlg.h rename to kmymoney/plugins/sql/kgeneratesqldlg.h diff --git a/kmymoney/dialogs/kgeneratesqldlg.cpp b/kmymoney/plugins/sql/kgeneratesqldlg.cpp rename from kmymoney/dialogs/kgeneratesqldlg.cpp rename to kmymoney/plugins/sql/kgeneratesqldlg.cpp diff --git a/kmymoney/dialogs/kgeneratesqldlg.ui b/kmymoney/plugins/sql/kgeneratesqldlg.ui rename from kmymoney/dialogs/kgeneratesqldlg.ui rename to kmymoney/plugins/sql/kgeneratesqldlg.ui diff --git a/kmymoney/mymoney/storage/kmymoney-sqlstorageplugin.desktop b/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop rename from kmymoney/mymoney/storage/kmymoney-sqlstorageplugin.desktop rename to kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop diff --git a/kmymoney/dialogs/kselectdatabasedlg.h b/kmymoney/plugins/sql/kselectdatabasedlg.h rename from kmymoney/dialogs/kselectdatabasedlg.h rename to kmymoney/plugins/sql/kselectdatabasedlg.h diff --git a/kmymoney/dialogs/kselectdatabasedlg.cpp b/kmymoney/plugins/sql/kselectdatabasedlg.cpp rename from kmymoney/dialogs/kselectdatabasedlg.cpp rename to kmymoney/plugins/sql/kselectdatabasedlg.cpp diff --git a/kmymoney/dialogs/kselectdatabasedlg.ui b/kmymoney/plugins/sql/kselectdatabasedlg.ui rename from kmymoney/dialogs/kselectdatabasedlg.ui rename to kmymoney/plugins/sql/kselectdatabasedlg.ui diff --git a/kmymoney/mymoney/storage/mymoneydbdef.h b/kmymoney/plugins/sql/mymoneydbdef.h rename from kmymoney/mymoney/storage/mymoneydbdef.h rename to kmymoney/plugins/sql/mymoneydbdef.h diff --git a/kmymoney/mymoney/storage/mymoneydbdef.cpp b/kmymoney/plugins/sql/mymoneydbdef.cpp rename from kmymoney/mymoney/storage/mymoneydbdef.cpp rename to kmymoney/plugins/sql/mymoneydbdef.cpp diff --git a/kmymoney/mymoney/storage/mymoneydbdriver.h b/kmymoney/plugins/sql/mymoneydbdriver.h rename from kmymoney/mymoney/storage/mymoneydbdriver.h rename to kmymoney/plugins/sql/mymoneydbdriver.h diff --git a/kmymoney/mymoney/storage/mymoneydbdriver.cpp b/kmymoney/plugins/sql/mymoneydbdriver.cpp rename from kmymoney/mymoney/storage/mymoneydbdriver.cpp rename to kmymoney/plugins/sql/mymoneydbdriver.cpp diff --git a/kmymoney/mymoney/storage/mymoneystoragesql.h b/kmymoney/plugins/sql/mymoneystoragesql.h rename from kmymoney/mymoney/storage/mymoneystoragesql.h rename to kmymoney/plugins/sql/mymoneystoragesql.h diff --git a/kmymoney/mymoney/storage/mymoneystoragesql.cpp b/kmymoney/plugins/sql/mymoneystoragesql.cpp rename from kmymoney/mymoney/storage/mymoneystoragesql.cpp rename to kmymoney/plugins/sql/mymoneystoragesql.cpp diff --git a/kmymoney/mymoney/storage/mymoneystoragesql_p.h b/kmymoney/plugins/sql/mymoneystoragesql_p.h rename from kmymoney/mymoney/storage/mymoneystoragesql_p.h rename to kmymoney/plugins/sql/mymoneystoragesql_p.h diff --git a/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory( ibanandbic ) +add_subdirectory( nationalaccount ) diff --git a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt @@ -0,0 +1,32 @@ +#Storage plugin + +configure_file(kmymoney-ibanbic-storageplugin.desktop.in kmymoney-ibanbic-storageplugin.desktop) + +set ( IBAN_BIC_STORAGE_PLUGIN_SCRS + ibanbicstorageplugin.cpp +) + +add_library( payeeidentifier_ibanbic_storageplugin MODULE + ${IBAN_BIC_STORAGE_PLUGIN_SCRS} +) + +target_link_libraries( payeeidentifier_ibanbic_storageplugin + Qt5::Core + Qt5::Sql + kmm_mymoney +) +# The json files of payeeidentifier_iban_bic are currently required +add_dependencies(payeeidentifier_ibanbic_storageplugin payeeidentifier_iban_bic) + +kcoreaddons_desktop_to_json(payeeidentifier_ibanbic_storageplugin + "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-ibanbic-storageplugin.desktop" + SERVICE_TYPES "${KMyMoney_SOURCE_DIR}/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop" + ) + +install(TARGETS payeeidentifier_ibanbic_storageplugin + DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-ibanbic-storageplugin.desktop" + DESTINATION ${SERVICES_INSTALL_DIR} + ) diff --git a/kmymoney/payeeidentifier/ibanandbic/ibanbicstorageplugin.h b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.h rename from kmymoney/payeeidentifier/ibanandbic/ibanbicstorageplugin.h rename to kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.h diff --git a/kmymoney/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp rename from kmymoney/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp rename to kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp diff --git a/kmymoney/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in rename from kmymoney/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in rename to kmymoney/plugins/sql/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in diff --git a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt @@ -0,0 +1,29 @@ +# Storage plugin + +set ( nationalAccount_STORAGE_PLUGIN_SCRS + nationalaccountstorageplugin.cpp +) + +add_library( payeeidentifier_nationalaccount_storageplugin MODULE + ${nationalAccount_STORAGE_PLUGIN_SCRS} +) + +target_link_libraries( payeeidentifier_nationalaccount_storageplugin + Qt5::Core + Qt5::Sql + kmm_mymoney +) + +configure_file(kmymoney-nationalaccount-storageplugin.desktop.in kmymoney-nationalaccount-storageplugin.desktop) +kcoreaddons_desktop_to_json(payeeidentifier_nationalaccount_storageplugin + "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-nationalaccount-storageplugin.desktop" + SERVICE_TYPES "${KMyMoney_SOURCE_DIR}/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop" +) + +install(TARGETS payeeidentifier_nationalaccount_storageplugin + DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/kmymoney-nationalaccount-storageplugin.desktop + DESTINATION ${SERVICES_INSTALL_DIR} +) diff --git a/kmymoney/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in rename from kmymoney/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in rename to kmymoney/plugins/sql/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in diff --git a/kmymoney/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h rename from kmymoney/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h rename to kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h diff --git a/kmymoney/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp rename from kmymoney/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp rename to kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp diff --git a/kmymoney/plugins/sql/sqlstorage.h b/kmymoney/plugins/sql/sqlstorage.h new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/sqlstorage.h @@ -0,0 +1,72 @@ +/*************************************************************************** + sqlstorage.h + ------------------- + copyright : (C) 2018 by Łukasz Wojniłowicz + email : lukasz.wojnilowicz@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef SQLSTORAGE_H +#define SQLSTORAGE_H + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// QT Includes + +// Project Includes + +#include "kmymoneyplugin.h" + +class MyMoneyStorageMgr; + +class SQLStorage : public KMyMoneyPlugin::Plugin, public KMyMoneyPlugin::StoragePlugin +{ + Q_OBJECT + Q_INTERFACES(KMyMoneyPlugin::StoragePlugin) + +public: + explicit SQLStorage(QObject *parent, const QVariantList &args); + ~SQLStorage() override; + + QAction *m_openDBaction; + QAction *m_saveAsDBaction; + QAction *m_generateDB; + + bool open(MyMoneyStorageMgr *storage, const QUrl &url) override; + bool save(const QUrl &url) override; + QString formatName() const override; + +protected: + void createActions(); + +private: + /** + * Saves the data into permanent storage on a new or empty SQL database. + * + * @param url The pseudo URL of the database + * + * @retval false save operation failed + * @retval true save operation was successful + */ + bool saveAsDatabase(const QUrl &url); + bool saveDatabase(const QUrl &url); + + void injectExternalSettings(KMyMoneySettings* p) override; + +private Q_SLOTS: + void slotOpenDatabase(); + void slotSaveAsDatabase(); + void slotGenerateSql(); +}; + +#endif diff --git a/kmymoney/plugins/sql/sqlstorage.cpp b/kmymoney/plugins/sql/sqlstorage.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/sqlstorage.cpp @@ -0,0 +1,317 @@ +/*************************************************************************** + sqlstorage.cpp + ------------------- + + copyright : (C) 2018 by Łukasz Wojniłowicz + email : lukasz.wojnilowicz@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "sqlstorage.h" + +#include +#include + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "appinterface.h" +#include "viewinterface.h" +#include "kselectdatabasedlg.h" +#include "kgeneratesqldlg.h" +#include "mymoneyfile.h" +#include "mymoneystoragesql.h" +#include "mymoneyexception.h" +//#include "mymoneystoragemgr.h" +#include "icons.h" +#include "kmymoneyglobalsettings.h" + +using namespace Icons; + +SQLStorage::SQLStorage(QObject *parent, const QVariantList &args) : + KMyMoneyPlugin::Plugin(parent, "sqlstorage"/*must be the same as X-KDE-PluginInfo-Name*/) +{ + Q_UNUSED(args) + setComponentName("sqlstorage", i18n("SQL storage")); + setXMLFile("sqlstorage.rc"); + createActions(); + // For information, announce that we have been loaded. + qDebug("Plugins: sqlstorage loaded"); +} + +SQLStorage::~SQLStorage() +{ + qDebug("Plugins: sqlstorage unloaded"); +} + +void SQLStorage::injectExternalSettings(KMyMoneySettings* p) +{ + KMyMoneyGlobalSettings::injectExternalSettings(p); +} + +bool SQLStorage::open(MyMoneyStorageMgr *storage, const QUrl &url) +{ + auto reader = std::make_unique(storage, url); + + QUrl dbURL(url); + bool retry = true; + while (retry) { + switch (reader->open(dbURL, QIODevice::ReadWrite)) { + case 0: // opened okay + retry = false; + break; + case 1: // permanent error + KMessageBox::detailedError(nullptr, + i18n("Cannot open database %1\n", dbURL.toDisplayString()), + reader->lastError()); + return false; + case -1: // retryable error + if (KMessageBox::warningYesNo(nullptr, reader->lastError(), PACKAGE) == KMessageBox::No) { + return false; + } else { + QUrlQuery query(dbURL); + const QString optionKey = QLatin1String("options"); + QString options = query.queryItemValue(optionKey); + if(!options.isEmpty()) { + options += QLatin1Char(','); + } + options += QLatin1String("override"); + query.removeQueryItem(QLatin1String("mode")); + query.removeQueryItem(optionKey); + query.addQueryItem(optionKey, options); + dbURL.setQuery(query); + } + } + } + // single user mode; read some of the data into memory + // FIXME - readFile no longer relevant? + // tried removing it but then got no indication that loading was complete + // also, didn't show home page +// reader->setProgressCallback(&KMyMoneyView::progressCallback); + if (!reader->readFile()) { + KMessageBox::detailedError(nullptr, + i18n("An unrecoverable error occurred while reading the database"), + reader->lastError().toLatin1(), + i18n("Database malfunction")); + return false; + } +// reader->setProgressCallback(0); + return true; +} + +bool SQLStorage::save(const QUrl &url) +{ + return saveDatabase(url); +} + +QString SQLStorage::formatName() const +{ + return QStringLiteral("SQL"); +} + +void SQLStorage::createActions() +{ + m_openDBaction = actionCollection()->addAction("open_database"); + m_openDBaction->setText(i18n("Open database...")); + m_openDBaction->setIcon(Icons::get(Icon::SVNUpdate)); + connect(m_openDBaction, &QAction::triggered, this, &SQLStorage::slotOpenDatabase); + + m_saveAsDBaction = actionCollection()->addAction("saveas_database"); + m_saveAsDBaction->setText(i18n("Save as database...")); + m_saveAsDBaction->setIcon(Icons::get(Icon::FileArchiver)); + connect(m_saveAsDBaction, &QAction::triggered, this, &SQLStorage::slotSaveAsDatabase); + + m_generateDB = actionCollection()->addAction("tools_generate_sql"); + m_generateDB->setText(i18n("Generate Database SQL")); + connect(m_generateDB, &QAction::triggered, this, &SQLStorage::slotGenerateSql); +} + +void SQLStorage::slotOpenDatabase() +{ + QPointer dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite); + if (!dialog->checkDrivers()) { + delete dialog; + return; + } + + if (dialog->exec() == QDialog::Accepted && dialog != 0) { + auto url = dialog->selectedURL(); + QUrl newurl = url; + if ((newurl.scheme() == QLatin1String("sql"))) { + const QString key = QLatin1String("driver"); + // take care and convert some old url to their new counterpart + QUrlQuery query(newurl); + if (query.queryItemValue(key) == QLatin1String("QMYSQL3")) { // fix any old urls + query.removeQueryItem(key); + query.addQueryItem(key, QLatin1String("QMYSQL")); + } + if (query.queryItemValue(key) == QLatin1String("QSQLITE3")) { + query.removeQueryItem(key); + query.addQueryItem(key, QLatin1String("QSQLITE")); + } + newurl.setQuery(query); + + if (query.queryItemValue(key) == QLatin1String("QSQLITE")) { + newurl.setUserInfo(QString()); + newurl.setHost(QString()); + } + // check if a password is needed. it may be if the URL came from the last/recent file list + QPointer dialog = new KSelectDatabaseDlg(QIODevice::ReadWrite, newurl); + if (!dialog->checkDrivers()) { + delete dialog; + return; + } + // if we need to supply a password, then show the dialog + // otherwise it isn't needed + if ((query.queryItemValue("secure").toLower() == QLatin1String("yes")) && newurl.password().isEmpty()) { + if (dialog->exec() == QDialog::Accepted && dialog != nullptr) { + newurl = dialog->selectedURL(); + } else { + delete dialog; + return; + } + } + delete dialog; + } + + appInterface()->slotFileOpenRecent(newurl); + } + delete dialog; +} + +void SQLStorage::slotSaveAsDatabase() +{ + bool rc = false; + QUrl oldUrl; + // in event of it being a database, ensure that all data is read into storage for saveas + if (viewInterface()->isDatabase()) + oldUrl = appInterface()->filenameURL().isEmpty() ? appInterface()->lastOpenedURL() : appInterface()->filenameURL(); + + QPointer dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); + QUrl url = oldUrl; + if (!dialog->checkDrivers()) { + delete dialog; + return; + } + + while (oldUrl == url && dialog->exec() == QDialog::Accepted && dialog != 0) { + url = dialog->selectedURL(); + // If the protocol is SQL for the old and new, and the hostname and database names match + // Let the user know that the current database cannot be saved on top of itself. + if (url.scheme() == "sql" && oldUrl.scheme() == "sql" + && oldUrl.host() == url.host() + && QUrlQuery(oldUrl).queryItemValue("driver") == QUrlQuery(url).queryItemValue("driver") + && oldUrl.path().right(oldUrl.path().length() - 1) == url.path().right(url.path().length() - 1)) { + KMessageBox::sorry(nullptr, i18n("Cannot save to current database.")); + } else { + try { + rc = saveAsDatabase(url); + } catch (const MyMoneyException &e) { + KMessageBox::sorry(nullptr, i18n("Cannot save to current database: %1", e.what())); + } + } + } + delete dialog; + + if (rc) { + //KRecentFilesAction *p = dynamic_cast(action("file_open_recent")); + //if(p) + appInterface()->addToRecentFiles(url); + appInterface()->writeLastUsedFile(url.toDisplayString(QUrl::PreferLocalFile)); + } + appInterface()->autosaveTimer()->stop(); + appInterface()->updateCaption(); + return; +} + +void SQLStorage::slotGenerateSql() +{ + QPointer editor = new KGenerateSqlDlg(nullptr); + editor->setObjectName("Generate Database SQL"); + editor->exec(); + delete editor; +} + +bool SQLStorage::saveAsDatabase(const QUrl &url) +{ + auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); + auto canWrite = false; + switch (writer->open(url, QIODevice::WriteOnly)) { + case 0: + canWrite = true; + break; + case -1: // dbase already has data, see if he wants to clear it out + if (KMessageBox::warningContinueCancel(nullptr, + i18n("Database contains data which must be removed before using Save As.\n" + "Do you wish to continue?"), "Database not empty") == KMessageBox::Continue) { + if (writer->open(url, QIODevice::WriteOnly, true) == 0) + canWrite = true; + } else { + delete writer; + return false; + } + break; + } + delete writer; + if (canWrite) { + saveDatabase(url); + return true; + } else { + KMessageBox::detailedError(nullptr, + i18n("Cannot open or create database %1.\n" + "Retry Save As Database and click Help" + " for further info.", url.toDisplayString()), writer->lastError()); + return false; + } +} + +bool SQLStorage::saveDatabase(const QUrl &url) +{ + auto rc = false; + if (!viewInterface()->fileOpen()) { + KMessageBox::error(nullptr, i18n("Tried to access a file when it has not been opened")); + return (rc); + } + auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); + writer->open(url, QIODevice::WriteOnly); +// writer->setProgressCallback(&KMyMoneyView::progressCallback); + if (!writer->writeFile()) { + KMessageBox::detailedError(nullptr, + i18n("An unrecoverable error occurred while writing to the database.\n" + "It may well be corrupt."), + writer->lastError().toLatin1(), + i18n("Database malfunction")); + rc = false; + } else { + rc = true; + } + writer->setProgressCallback(0); + delete writer; + return rc; +} + +K_PLUGIN_FACTORY_WITH_JSON(SQLStorageFactory, "sqlstorage.json", registerPlugin();) + +#include "sqlstorage.moc" diff --git a/kmymoney/plugins/sql/sqlstorage.json.in b/kmymoney/plugins/sql/sqlstorage.json.in new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/sqlstorage.json.in @@ -0,0 +1,21 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "tonybloom@users.sourceforge.net,lukasz.wojnilowicz@gmail.com", + "Name": "Tony Bloomfield,Łukasz Wojniłowicz" + } + ], + "Description": "Adds SQL storage support to KMyMoney", + "EnabledByDefault": true, + "Icon": "server-database", + "Id": "sqlstorage", + "License": "GPL", + "Name": "SQL Storage", + "ServiceTypes": [ + "KMyMoney/Plugin" + ], + "Version": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@", + "Website": "https://kmymoney.org/plugins.html" + } +} diff --git a/kmymoney/plugins/sql/sqlstorage.rc b/kmymoney/plugins/sql/sqlstorage.rc new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/sqlstorage.rc @@ -0,0 +1,13 @@ + + + + + + + + + T&ools + + + + diff --git a/kmymoney/plugins/sql/tests/CMakeLists.txt b/kmymoney/plugins/sql/tests/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/sql/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +include(ECMAddTests) + +set(sqlstoragestatic_SOURCES + ../mymoneystoragesql.cpp + ../mymoneydbdef.cpp + ../mymoneydbdriver.cpp + ) + +add_library(sqlstoragestatic STATIC ${sqlstoragestatic_SOURCES} ) +kde_target_enable_exceptions(sqlstoragestatic PUBLIC) +target_link_libraries(sqlstoragestatic +PUBLIC + kmm_plugin + kmm_widgets + kmm_utils_platformtools +) + +file(GLOB tests_sources "*-test.cpp") +ecm_add_tests(${tests_sources} + LINK_LIBRARIES + sqlstoragestatic + Qt5::Test + kmm_testutils + kmm_plugin + kmm_widgets + kmm_utils_platformtools + onlinetask_unavailabletask +) diff --git a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.h rename from kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h rename to kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.h --- a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h +++ b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.h @@ -26,9 +26,9 @@ #define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyStorageMgrTest; -#include "../mymoneyobject.h" +#include "mymoneyobject.h" #include "mymoneystoragemgr.h" -#include "mymoneystoragesql.h" +#include "../mymoneystoragesql.h" class MyMoneyStorageMgrTest : public QObject { diff --git a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp rename from kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp rename to kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp --- a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp +++ b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp @@ -20,7 +20,8 @@ #include #include "mymoneystoragemgr_p.h" -#include "mymoneystoragesql_p.h" +#include "../mymoneystoragesql.h" +#include "../mymoneystoragesql_p.h" #include "mymoneytestutils.h" #include "mymoneymoney.h" #include "mymoneyfile.h" @@ -36,7 +37,6 @@ #include "mymoneysplit_p.h" #include "mymoneytransaction.h" #include "mymoneybudget.h" -#include "mymoneystoragesql.h" #include "onlinetasks/dummy/tasks/dummytask.h" #include "misc/platformtools.h" diff --git a/kmymoney/plugins/viewinterface.h b/kmymoney/plugins/viewinterface.h --- a/kmymoney/plugins/viewinterface.h +++ b/kmymoney/plugins/viewinterface.h @@ -83,6 +83,7 @@ */ virtual bool fileOpen() = 0; + virtual bool isDatabase() = 0; /** * Brings up a dialog to change the list(s) settings and saves them into the * class KMyMoneySettings (a singleton). diff --git a/kmymoney/views/kmymoneyview.h b/kmymoney/views/kmymoneyview.h --- a/kmymoney/views/kmymoneyview.h +++ b/kmymoney/views/kmymoneyview.h @@ -44,6 +44,7 @@ namespace eAccountsModel { enum class Column; } namespace eMenu { enum class Action; } namespace KMyMoneyPlugin { class OnlinePlugin; } +namespace KMyMoneyPlugin { class StoragePlugin; } namespace eDialogs { enum class ScheduleResultCode; } class KMyMoneyApp; @@ -134,6 +135,8 @@ QFileDevice::Permissions m_fmode; int m_lastViewSelected; + QMap* m_storagePlugins; + // Keep a note of the file type typedef enum _fileTypeE { KmmBinary = 0, // native, binary @@ -247,25 +250,6 @@ * @retval true save operation was successful */ bool saveFile(const QUrl &url, const QString& keyList = QString()); - /** - * Saves the data into permanent storage on a new or empty SQL database. - * - * @param url The pseudo of tyhe database - * - * @retval false save operation failed - * @retval true save operation was successful - */ - //const bool saveDatabase(const QUrl &url); This no longer relevant - /** - * Saves the data into permanent storage on a new or empty SQL database. - * - * @param url The pseudo URL of the database - * - * @retval false save operation failed - * @retval true save operation was successful - */ - bool saveAsDatabase(const QUrl &url); - bool saveDatabase(const QUrl &url); /** * Call this to find out if the currently open file is native KMM @@ -342,6 +326,7 @@ void slotAccountTreeViewChanged(const eAccountsModel::Column column, const bool show); void setOnlinePlugins(QMap& plugins); + void setStoragePlugins(QMap& plugins); // TODO: remove that function /** diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -69,7 +69,6 @@ #include "mymoneystoragebin.h" #include "mymoneyexception.h" #include "mymoneystoragexml.h" -#include "mymoneystoragesql.h" #include "mymoneystorageanon.h" #include "khomeview.h" #include "kaccountsview.h" @@ -102,6 +101,7 @@ #include "mymoneyfile.h" #include "mymoneysecurity.h" #include "mymoneyreport.h" +#include "kmymoneyplugin.h" #include "mymoneyenums.h" using namespace Icons; @@ -118,7 +118,8 @@ m_inConstructor(true), m_fileOpen(false), m_fmode(QFileDevice::ReadUser | QFileDevice::WriteUser), - m_lastViewSelected(0) + m_lastViewSelected(0), + m_storagePlugins(nullptr) #ifdef KF5Activities_FOUND , m_activityResourceInstance(0) #endif @@ -477,6 +478,11 @@ m_onlineJobOutboxView->setOnlinePlugins(plugins); } +void KMyMoneyView::setStoragePlugins(QMap& plugins) +{ + m_storagePlugins = &plugins; +} + eDialogs::ScheduleResultCode KMyMoneyView::enterSchedule(MyMoneySchedule& schedule, bool autoEnter, bool extendedKeys) { return m_scheduledView->enterSchedule(schedule, autoEnter, extendedKeys); @@ -689,7 +695,10 @@ QUrlQuery query(url); query.removeQueryItem("mode"); newUrl.setQuery(query); - return (openDatabase(newUrl)); // on error, any message will have been displayed + auto rc = openDatabase(newUrl); // on error, any message will have been displayed + if (!rc) + MyMoneyFile::instance()->attachStorage(new MyMoneyStorageMgr); + return rc; } auto storage = new MyMoneyStorageMgr; @@ -922,54 +931,24 @@ if (!pStorage) pStorage = new MyMoneyStorageMgr; - auto reader = std::make_unique(pStorage, url); - - QUrl dbURL(url); - bool retry = true; - while (retry) { - switch (reader->open(dbURL, QIODevice::ReadWrite)) { - case 0: // opened okay - retry = false; + auto rc = false; + auto pluginFound = false; + if (m_storagePlugins) { + for (const auto& plugin : *m_storagePlugins) { + if (plugin->formatName().compare(QLatin1String("SQL")) == 0) { + rc = plugin->open(pStorage, url); + pluginFound = true; break; - case 1: // permanent error - KMessageBox::detailedError(this, i18n("Cannot open database %1\n", dbURL.toDisplayString()), reader->lastError()); - if (pStorage) { - removeStorage(); - delete pStorage; - } - return false; - case -1: // retryable error - if (KMessageBox::warningYesNo(this, reader->lastError(), PACKAGE) == KMessageBox::No) { - if (pStorage) { - removeStorage(); - delete pStorage; - } - return false; - } else { - QUrlQuery query(dbURL); - const QString optionKey = QLatin1String("options"); - QString options = query.queryItemValue(optionKey); - if(!options.isEmpty()) { - options += QLatin1Char(','); - } - options += QLatin1String("override"); - query.removeQueryItem(QLatin1String("mode")); - query.removeQueryItem(optionKey); - query.addQueryItem(optionKey, options); - dbURL.setQuery(query); - } + } } } - // single user mode; read some of the data into memory - // FIXME - readFile no longer relevant? - // tried removing it but then got no indication that loading was complete - // also, didn't show home page - reader->setProgressCallback(&KMyMoneyView::progressCallback); - if (!reader->readFile()) { - KMessageBox::detailedError(this, - i18n("An unrecoverable error occurred while reading the database"), - reader->lastError().toLatin1(), - i18n("Database malfunction")); + + if(!pluginFound) + KMessageBox::error(this, i18n("Couldn't find suitable plugin to read your storage.")); + + if(!rc) { + removeStorage(); + delete pStorage; return false; } @@ -979,7 +958,6 @@ } m_fileOpen = true; - reader->setProgressCallback(0); return initializeStorage(); } @@ -1341,64 +1319,6 @@ return rc; } -bool KMyMoneyView::saveAsDatabase(const QUrl &url) -{ - auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); - bool canWrite = false; - switch (writer->open(url, QIODevice::WriteOnly)) { - case 0: - canWrite = true; - break; - case -1: // dbase already has data, see if he wants to clear it out - if (KMessageBox::warningContinueCancel(this, - i18n("Database contains data which must be removed before using Save As.\n" - "Do you wish to continue?"), "Database not empty") == KMessageBox::Continue) { - if (writer->open(url, QIODevice::WriteOnly, true) == 0) - canWrite = true; - } else { - delete writer; - return false; - } - break; - } - delete writer; - if (canWrite) { - saveDatabase(url); - return true; - } else { - KMessageBox::detailedError(this, - i18n("Cannot open or create database %1.\n" - "Retry Save As Database and click Help" - " for further info.", url.toDisplayString()), writer->lastError()); - return false; - } -} - -bool KMyMoneyView::saveDatabase(const QUrl &url) -{ - auto rc = false; - if (!fileOpen()) { - KMessageBox::error(this, i18n("Tried to access a file when it has not been opened")); - return (rc); - } - auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); - writer->open(url, QIODevice::WriteOnly); - writer->setProgressCallback(&KMyMoneyView::progressCallback); - if (!writer->writeFile()) { - KMessageBox::detailedError(this, - i18n("An unrecoverable error occurred while writing to the database.\n" - "It may well be corrupt."), - writer->lastError().toLatin1(), - i18n("Database malfunction")); - rc = false; - } else { - rc = true; - } - writer->setProgressCallback(0); - delete writer; - return rc; -} - bool KMyMoneyView::dirty() { if (!fileOpen())