diff --git a/kmymoney/plugins/sql/CMakeLists.txt b/kmymoney/plugins/sql/CMakeLists.txt --- a/kmymoney/plugins/sql/CMakeLists.txt +++ b/kmymoney/plugins/sql/CMakeLists.txt @@ -1,6 +1,3 @@ -add_subdirectory(payeeidentifier) -add_subdirectory(onlinetasks) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sqlstorage.json.in ${CMAKE_CURRENT_BINARY_DIR}/sqlstorage.json @ONLY) set(sqlstorage_SOURCES @@ -10,7 +7,6 @@ mymoneydbdriver.cpp kselectdatabasedlg.cpp kgeneratesqldlg.cpp - kmymoneystorageplugin.cpp ) ki18n_wrap_ui(sqlstorage_SOURCES kselectdatabasedlg.ui kgeneratesqldlg.ui) @@ -38,10 +34,6 @@ install(FILES sqlstorage.rc DESTINATION "${KXMLGUI_INSTALL_DIR}/sqlstorage") -install(FILES kmymoney-sqlstorageplugin.desktop - DESTINATION ${SERVICETYPES_INSTALL_DIR} -) - if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop b/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop deleted file mode 100644 --- a/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop +++ /dev/null @@ -1,27 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=KMyMoney/sqlStoragePlugin -Name=Enables plugins to store data in the sql database -Name[ca]=Activa els connectors per emmagatzemar dades en la base de dades SQL -Name[ca@valencia]=Activa els connectors per emmagatzemar dades en la base de dades SQL -Name[da]=Aktiverer plugins til at lagre data i sql-databasen -Name[de]=Aktiviert Module, um Daten in der SQL-Datenbank zu speichern -Name[en_GB]=Enables plugins to store data in the sql database -Name[es]=Activa los complementos para almacenar datos en la base de datos sql -Name[fi]=Sallii liitännäisten tallettaa tietoa SQL-tietokantaan -Name[fr]=Permet aux modules externes de stocker les données dans la base de données sql -Name[gl]=Activa complementos para gardar datos na base de datos SQL -Name[it]=Abilita le estensioni per archiviare i dati nella banca dati sql -Name[nl]=Schakelt plug-ins in om gegevens in de sql-database op te slaan -Name[pl]=Włącza wtyczki do przechowywania danych w bazach danych sql -Name[pt]=Permite aos 'plugins' guardarem dados na base de dados de SQL -Name[pt_BR]=Permite que os plugins armazenem dados no banco de dados SQL -Name[sk]=Umožní pluginom uložiť údaje v sql databáze -Name[sv]=Gör det möjligt för insticksprogram att lagra data i SQL-databasen -Name[tr]=Eklentilerin verileri sql veritabanında depolamasına izin verir -Name[uk]=Надає змогу додаткам зберігати дані у базі даних SQL -Name[x-test]=xxEnables plugins to store data in the sql databasexx - -[PropertyDef::X-KMyMoney-PluginIid] -Type=QStringList -# The unique identifier for the plugin diff --git a/kmymoney/plugins/sql/kmymoneystorageplugin.h b/kmymoney/plugins/sql/kmymoneystorageplugin.h deleted file mode 100644 --- a/kmymoney/plugins/sql/kmymoneystorageplugin.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2013-2015 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef KMYMONEYSTORAGEPLUGIN_H -#define KMYMONEYSTORAGEPLUGIN_H - -#include -#include - -class QSqlDatabase; -namespace KMyMoneyPlugin -{ - -/** - * @brief Interface for plugins which store data in an sql database - * - */ -class storagePlugin : public QObject -{ - Q_OBJECT - -public: - /** - * This is the constructor needed by KService - */ - explicit storagePlugin(QObject* parent = 0, const QVariantList& options = QVariantList()); - - /** - * @brief Setup database to make it usable by the plugins - * - * This method is also called on the first usage in a session. You must check if your changes - * were applied before. This also enables the plugin to upgrade the schema if needed. - * - * You must fill the kmmPluginInfo table with your plugins data. The version column is for your - * usage. A higher number means a more recent version. - * Use a transaction! - */ - virtual bool setupDatabase(QSqlDatabase connection) = 0; - - /** - * @brief Remove all data belonging to the plugin from the database - */ - virtual bool removePluginData(QSqlDatabase connection) = 0; - - virtual ~storagePlugin(); -}; - -} // end namespace KMyMoneyPlugin - -Q_DECLARE_INTERFACE(KMyMoneyPlugin::storagePlugin, "org.kmymoney.plugin.storageplugin") - -#endif // KMYMONEYPLUGIN_STORAGEPLUGIN_H diff --git a/kmymoney/plugins/sql/kmymoneystorageplugin.cpp b/kmymoney/plugins/sql/kmymoneystorageplugin.cpp deleted file mode 100644 --- a/kmymoney/plugins/sql/kmymoneystorageplugin.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2013-2015 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "kmymoneystorageplugin.h" - -KMyMoneyPlugin::storagePlugin::storagePlugin(QObject* parent, const QVariantList& options) - : QObject(parent) -{ - Q_UNUSED(options); -} - -KMyMoneyPlugin::storagePlugin::~storagePlugin() -{ - -} diff --git a/kmymoney/plugins/sql/mymoneystoragesql_p.h b/kmymoney/plugins/sql/mymoneystoragesql_p.h --- a/kmymoney/plugins/sql/mymoneystoragesql_p.h +++ b/kmymoney/plugins/sql/mymoneystoragesql_p.h @@ -50,13 +50,11 @@ // KDE Includes #include -#include // ---------------------------------------------------------------------------- // Project Includes #include "mymoneystoragemgr.h" -#include "kmymoneystorageplugin.h" #include "onlinejobadministration.h" #include "onlinetasks/interfaces/tasks/onlinetask.h" #include "mymoneycostcenter.h" @@ -2668,34 +2666,193 @@ return false; QString sqlIID; + MyMoneyDbTransaction t(*q, Q_FUNC_INFO); + auto rc = false; if (iid == payeeIdentifiers::ibanBic::staticPayeeIdentifierIid()) - sqlIID = QString::fromLatin1("org.kmymoney.payeeIdentifier.ibanbic.sqlStoragePlugin"); + rc = setupIBANBIC(*q); else if (iid == payeeIdentifiers::nationalAccount::staticPayeeIdentifierIid()) - sqlIID = QLatin1String("org.kmymoney.payeeIdentifier.nationalAccount.sqlStoragePlugin"); + rc = setupNationalAccount(*q); else if (iid == sepaOnlineTransferImpl::name()) - sqlIID = QLatin1String("org.kmymoney.creditTransfer.sepa.sqlStoragePlugin"); + rc = setupSepaOnlineTransfer(*q); else + rc = false; + return rc; + } + + bool setupIBANBIC(QSqlDatabase connection) + { + auto iid = QLatin1String("org.kmymoney.payeeIdentifier.ibanbic.sqlStoragePlugin"); + // Get current version + QSqlQuery query = QSqlQuery(connection); + query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); + query.bindValue(0, iid); + if (!query.exec()) { + qWarning("Could not execute query for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text())); return false; + } - QString errorMsg; - KMyMoneyPlugin::storagePlugin* plugin = KServiceTypeTrader::createInstanceFromQuery( - QLatin1String("KMyMoney/sqlStoragePlugin"), - QString("'%1' ~in [X-KMyMoney-PluginIid]").arg(sqlIID.replace(QLatin1Char('\''), QLatin1String("\\'"))), - 0, - QVariantList(), - &errorMsg - ); + int currentVersion = 0; + if (query.next()) + currentVersion = query.value(0).toInt(); - if (plugin == 0) - throw MYMONEYEXCEPTION(QString::fromLatin1("Could not load sqlStoragePlugin '%1', (error: %2)").arg(sqlIID, errorMsg)); + // Create database in it's most recent version if version is 0 + // (version 0 means the database was not installed) + if (currentVersion == 0) { + // If the database is recreated the table may be still there. So drop it if needed. No error handling needed + // as this step is not necessary - only the creation is important. + if (!query.exec("DROP TABLE IF EXISTS kmmIbanBic;")) + return false; - MyMoneyDbTransaction t(*q, Q_FUNC_INFO); - if (plugin->setupDatabase(*q)) { - m_loadedStoragePlugins.insert(sqlIID); - return true; + if (!query.exec( + "CREATE TABLE kmmIbanBic (" + " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmPayeeIdentifier( id ) ON DELETE CASCADE ON UPDATE CASCADE," + " iban varchar(32)," + " bic char(11) CHECK(length(bic) = 11 OR bic IS NULL)," + " name text" + " );" + )) { + qWarning("Could not create table for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text())); + return false; + } + + query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); + query.bindValue(0, iid); + query.bindValue(1, 1); + query.bindValue(2, 0); + query.bindValue(3, "DROP TABLE kmmIbanBic;"); + if (query.exec()) + return true; + qWarning("Could not save plugin info for ibanBicStoragePlugin (%s): %s", qPrintable(iid), qPrintable(query.lastError().text())); + return false; } - throw MYMONEYEXCEPTION(QString::fromLatin1("Could not install sqlStoragePlugin '%1' in database.").arg(sqlIID)); + // Check if version is valid with this plugin + switch (currentVersion) { + case 1: return true; + } + + return false; + } + + bool setupNationalAccount(QSqlDatabase connection) + { + auto iid = QLatin1String("org.kmymoney.payeeIdentifier.nationalAccount.sqlStoragePlugin"); + // Get current version + QSqlQuery query = QSqlQuery(connection); + query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); + query.bindValue(0, iid); + if (!query.exec()) { + qWarning("Could not execute query for nationalAccountStoragePlugin: %s", qPrintable(query.lastError().text())); + return false; + } + + int currentVersion = 0; + if (query.next()) + currentVersion = query.value(0).toInt(); + + // Create database in it's most recent version if version is 0 + // (version 0 means the database was not installed) + if (currentVersion == 0) { + // If the database is recreated the table may be still there. So drop it if needed. No error handling needed + // as this step is not necessary - only the creation is important. + if (!query.exec("DROP TABLE IF EXISTS kmmNationalAccountNumber;")) + return false; + + if (!query.exec( + "CREATE TABLE kmmNationalAccountNumber (" + " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmPayeeIdentifier( id ) ON DELETE CASCADE ON UPDATE CASCADE," + " countryCode varchar(3)," + " accountNumber TEXT," + " bankCode TEXT," + " name TEXT" + " );" + )) { + qWarning("Could not create table for nationalAccountStoragePlugin: %s", qPrintable(query.lastError().text())); + return false; + } + + query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); + query.bindValue(0, iid); + query.bindValue(1, 1); + query.bindValue(2, 0); + query.bindValue(3, "DROP TABLE kmmNationalAccountNumber;"); + if (query.exec()) + return true; + qWarning("Could not save plugin info for nationalAccountStoragePlugin (%s): %s", qPrintable(iid), qPrintable(query.lastError().text())); + return false; + } + + // Check if version is valid with this plugin + switch (currentVersion) { + case 1: return true; + } + + return false; + } + + bool setupSepaOnlineTransfer(QSqlDatabase connection) + { + auto iid = QLatin1String("org.kmymoney.creditTransfer.sepa.sqlStoragePlugin"); + // Get current version + QSqlQuery query = QSqlQuery(connection); + query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); + query.bindValue(0, iid); + if (!query.exec()) { + qWarning("Could not execute query for sepaStoragePlugin: %s", qPrintable(query.lastError().text())); + return false; + } + + int currentVersion = 0; + if (query.next()) + currentVersion = query.value(0).toInt(); + + // Create database in it's most recent version if version is 0 + // (version 0 means the database was not installed) + if (currentVersion <= 1) { + // If the database is recreated the table may be still there. So drop it if needed. No error handling needed + // as this step is not necessary - only the creation is important. + if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) + return false; + + if (!query.exec( + "CREATE TABLE kmmSepaOrders (" + " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id ) ON UPDATE CASCADE ON DELETE CASCADE," + " originAccount varchar(32) REFERENCES kmmAccounts( id ) ON UPDATE CASCADE ON DELETE SET NULL," + " value text DEFAULT '0'," + " purpose text," + " endToEndReference varchar(35)," + " beneficiaryName varchar(27)," + " beneficiaryIban varchar(32)," + " beneficiaryBic char(11)," + " textKey int," + " subTextKey int" + " );" + )) { + qWarning("Error while creating table kmmSepaOrders: %s", qPrintable(query.lastError().text())); + return false; + } + + query.prepare("DELETE FROM kmmPluginInfo WHERE iid = ?;"); + query.bindValue(0, iid); + query.exec(); + + query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); + query.bindValue(0, iid); + query.bindValue(1, 2); + query.bindValue(2, 0); + query.bindValue(3, "DROP TABLE kmmSepaOrders;"); + if (query.exec()) + return true; + qWarning("Error while inserting kmmPluginInfo for '%s': %s", qPrintable(iid), qPrintable(query.lastError().text())); + return false; + } + + // Check if version is valid with this plugin + switch (currentVersion) { + case 2: return true; + } + + return false; } bool actOnIBANBICObjectInSQL(SQLAction action, const payeeIdentifier &obj) diff --git a/kmymoney/plugins/sql/onlinetasks/CMakeLists.txt b/kmymoney/plugins/sql/onlinetasks/CMakeLists.txt deleted file mode 100644 --- a/kmymoney/plugins/sql/onlinetasks/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(sepa) diff --git a/kmymoney/plugins/sql/onlinetasks/sepa/CMakeLists.txt b/kmymoney/plugins/sql/onlinetasks/sepa/CMakeLists.txt deleted file mode 100644 --- a/kmymoney/plugins/sql/onlinetasks/sepa/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# Storage plugin - -set ( sepa_STORAGE_PLUGIN_SCRS - sepastorageplugin.cpp - ../../kmymoneystorageplugin.cpp -) - -add_library( credittransfer_sepa_storageplugin MODULE - ${sepa_STORAGE_PLUGIN_SCRS} -) - -target_link_libraries( credittransfer_sepa_storageplugin - Qt5::Core - Qt5::Sql - kmm_mymoney -) - -configure_file(kmymoney-sepa-storageplugin.desktop.in kmymoney-sepa-storageplugin.desktop) -kcoreaddons_desktop_to_json(credittransfer_sepa_storageplugin - "${CMAKE_CURRENT_BINARY_DIR}/kmymoney-sepa-storageplugin.desktop" - SERVICE_TYPES "${KMyMoney_SOURCE_DIR}/kmymoney/plugins/sql/kmymoney-sqlstorageplugin.desktop" -) - -install(TARGETS credittransfer_sepa_storageplugin - DESTINATION "${KDE_INSTALL_PLUGINDIR}/kmymoney") - -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/kmymoney-sepa-storageplugin.desktop - DESTINATION ${SERVICES_INSTALL_DIR} -) diff --git a/kmymoney/plugins/sql/onlinetasks/sepa/kmymoney-sepa-storageplugin.desktop.in b/kmymoney/plugins/sql/onlinetasks/sepa/kmymoney-sepa-storageplugin.desktop.in deleted file mode 100644 --- a/kmymoney/plugins/sql/onlinetasks/sepa/kmymoney-sepa-storageplugin.desktop.in +++ /dev/null @@ -1,14 +0,0 @@ -[Desktop Entry] -Type=Service -ServiceTypes=KMyMoney/sqlStoragePlugin - -X-KMyMoney-PluginIid=org.kmymoney.creditTransfer.sepa.sqlStoragePlugin - -Name=credittransfer_sepa_storageplugin -X-KDE-Library=kmymoney/credittransfer_sepa_storageplugin -X-KDE-PluginInfo-Author=Christian David -X-KDE-PluginInfo-Email=christian-david@web.de -X-KDE-PluginInfo-Version=${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX} -X-KDE-PluginInfo-Website=https://kmymoney.org -X-KDE-PluginInfo-License=GPLv2+ -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.h b/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.h deleted file mode 100644 --- a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2014 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SEPASTORAGEPLUGIN_H -#define SEPASTORAGEPLUGIN_H - -#include "sql/kmymoneystorageplugin.h" - -#include - -class sepaStoragePlugin : public KMyMoneyPlugin::storagePlugin -{ - Q_OBJECT - Q_INTERFACES(KMyMoneyPlugin::storagePlugin) - -public: - explicit sepaStoragePlugin(QObject* parent = 0, const QVariantList& options = QVariantList()); - bool removePluginData(QSqlDatabase connection) final override; - bool setupDatabase(QSqlDatabase connection) final override; - - static const QString iid; -}; - -#endif // SEPASTORAGEPLUGIN_H diff --git a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp b/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp deleted file mode 100644 --- a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2014 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "sepastorageplugin.h" - -#include - -#include -#include - -K_PLUGIN_FACTORY_WITH_JSON(sepaStoragePluginFactory, "kmymoney-sepa-storageplugin.json", registerPlugin();) - -const QString sepaStoragePlugin::iid = QLatin1String("org.kmymoney.creditTransfer.sepa.sqlStoragePlugin"); - -sepaStoragePlugin::sepaStoragePlugin(QObject* parent, const QVariantList& options) - : storagePlugin(parent) -{ - Q_UNUSED(options); -} - -/** @todo implement */ -bool sepaStoragePlugin::removePluginData(QSqlDatabase connection) -{ - Q_UNUSED(connection); - return false; -} - -bool sepaStoragePlugin::setupDatabase(QSqlDatabase connection) -{ - // Get current version - QSqlQuery query = QSqlQuery(connection); - query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); - query.bindValue(0, iid); - if (!query.exec()) { - qWarning("Could not execute query for sepaStoragePlugin: %s", qPrintable(query.lastError().text())); - return false; - } - - int currentVersion = 0; - if (query.next()) - currentVersion = query.value(0).toInt(); - - // Create database in it's most recent version if version is 0 - // (version 0 means the database was not installed) - if (currentVersion <= 1) { - // If the database is recreated the table may be still there. So drop it if needed. No error handling needed - // as this step is not necessary - only the creation is important. - if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) - return false; - - if (!query.exec( - "CREATE TABLE kmmSepaOrders (" - " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id ) ON UPDATE CASCADE ON DELETE CASCADE," - " originAccount varchar(32) REFERENCES kmmAccounts( id ) ON UPDATE CASCADE ON DELETE SET NULL," - " value text DEFAULT '0'," - " purpose text," - " endToEndReference varchar(35)," - " beneficiaryName varchar(27)," - " beneficiaryIban varchar(32)," - " beneficiaryBic char(11)," - " textKey int," - " subTextKey int" - " );" - )) { - qWarning("Error while creating table kmmSepaOrders: %s", qPrintable(query.lastError().text())); - return false; - } - - query.prepare("DELETE FROM kmmPluginInfo WHERE iid = ?;"); - query.bindValue(0, iid); - query.exec(); - - query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); - query.bindValue(0, iid); - query.bindValue(1, 2); - query.bindValue(2, 0); - query.bindValue(3, "DROP TABLE kmmSepaOrders;"); - if (query.exec()) - return true; - qWarning("Error while inserting kmmPluginInfo for '%s': %s", qPrintable(iid), qPrintable(query.lastError().text())); - return false; - } - - // Check if version is valid with this plugin - switch (currentVersion) { - case 2: return true; - } - - return false; -} - -#include "sepastorageplugin.moc" diff --git a/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory( ibanandbic ) -add_subdirectory( nationalaccount ) diff --git a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -#Storage plugin - -configure_file(kmymoney-ibanbic-storageplugin.desktop.in kmymoney-ibanbic-storageplugin.desktop) - -set ( IBAN_BIC_STORAGE_PLUGIN_SCRS - ibanbicstorageplugin.cpp - ../../kmymoneystorageplugin.cpp -) - -add_library( payeeidentifier_ibanbic_storageplugin MODULE - ${IBAN_BIC_STORAGE_PLUGIN_SCRS} -) - -target_link_libraries( payeeidentifier_ibanbic_storageplugin - Qt5::Core - Qt5::Sql - kmm_mymoney -) - -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/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.h b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.h deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2014 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef IBANBICSTORAGEPLUGIN_H -#define IBANBICSTORAGEPLUGIN_H - -#include "sql/kmymoneystorageplugin.h" - -class ibanBicStoragePlugin : public KMyMoneyPlugin::storagePlugin -{ - Q_OBJECT - Q_INTERFACES(KMyMoneyPlugin::storagePlugin) -// Q_PLUGIN_METADATA(IID "org.kmymoney.payeeIdentifier.ibanbic.sqlStoragePlugin") - -public: - explicit ibanBicStoragePlugin(QObject* parent = 0, const QVariantList& options = QVariantList()); - bool removePluginData(QSqlDatabase connection) final override; - bool setupDatabase(QSqlDatabase connection) final override; - static QString iid(); -}; - -#endif // IBANBICSTORAGEPLUGIN_H diff --git a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/ibanbicstorageplugin.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2014 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "ibanbicstorageplugin.h" - -#include - -#include -#include - -K_PLUGIN_FACTORY_WITH_JSON(ibanBicStoragePluginFactory, "kmymoney-ibanbic-storageplugin.json", registerPlugin();) - -QString ibanBicStoragePlugin::iid() -{ - return QLatin1String("org.kmymoney.payeeIdentifier.ibanbic.sqlStoragePlugin"); -} - -ibanBicStoragePlugin::ibanBicStoragePlugin(QObject* parent, const QVariantList& options) - : storagePlugin(parent, options) -{ - -} - -/** @todo to be implemented */ -bool ibanBicStoragePlugin::removePluginData(QSqlDatabase connection) -{ - Q_UNUSED(connection); - return false; -} - -bool ibanBicStoragePlugin::setupDatabase(QSqlDatabase connection) -{ - // Get current version - QSqlQuery query = QSqlQuery(connection); - query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); - query.bindValue(0, iid()); - if (!query.exec()) { - qWarning("Could not execute query for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text())); - return false; - } - - int currentVersion = 0; - if (query.next()) - currentVersion = query.value(0).toInt(); - - // Create database in it's most recent version if version is 0 - // (version 0 means the database was not installed) - if (currentVersion == 0) { - // If the database is recreated the table may be still there. So drop it if needed. No error handling needed - // as this step is not necessary - only the creation is important. - if (!query.exec("DROP TABLE IF EXISTS kmmIbanBic;")) - return false; - - if (!query.exec( - "CREATE TABLE kmmIbanBic (" - " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmPayeeIdentifier( id ) ON DELETE CASCADE ON UPDATE CASCADE," - " iban varchar(32)," - " bic char(11) CHECK(length(bic) = 11 OR bic IS NULL)," - " name text" - " );" - )) { - qWarning("Could not create table for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text())); - return false; - } - - query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); - query.bindValue(0, iid()); - query.bindValue(1, 1); - query.bindValue(2, 0); - query.bindValue(3, "DROP TABLE kmmIbanBic;"); - if (query.exec()) - return true; - qWarning("Could not save plugin info for ibanBicStoragePlugin (%s): %s", qPrintable(iid()), qPrintable(query.lastError().text())); - return false; - } - - // Check if version is valid with this plugin - switch (currentVersion) { - case 1: return true; - } - - return false; -} - -#include "ibanbicstorageplugin.moc" diff --git a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in b/kmymoney/plugins/sql/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/ibanandbic/kmymoney-ibanbic-storageplugin.desktop.in +++ /dev/null @@ -1,14 +0,0 @@ -[Desktop Entry] -Type=Service -ServiceTypes=KMyMoney/sqlStoragePlugin - -X-KMyMoney-PluginIid=org.kmymoney.payeeIdentifier.ibanbic.sqlStoragePlugin - -Name=payeeidentifier_ibanbic_storageplugin -X-KDE-Library=kmymoney/payeeidentifier_ibanbic_storageplugin -X-KDE-PluginInfo-Author=Christian David -X-KDE-PluginInfo-Email=christian-david@web.de -X-KDE-PluginInfo-Version=${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX} -X-KDE-PluginInfo-Website=https://kmymoney.org -X-KDE-PluginInfo-License=GPLv2+ -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# Storage plugin - -set ( nationalAccount_STORAGE_PLUGIN_SCRS - nationalaccountstorageplugin.cpp - ../../kmymoneystorageplugin.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/plugins/sql/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/kmymoney-nationalaccount-storageplugin.desktop.in +++ /dev/null @@ -1,14 +0,0 @@ -[Desktop Entry] -Type=Service -ServiceTypes=KMyMoney/sqlStoragePlugin - -X-KMyMoney-PluginIid=org.kmymoney.payeeIdentifier.nationalAccount.sqlStoragePlugin - -Name=payeeidentifier_nationalaccount_storageplugin -X-KDE-Library=kmymoney/payeeidentifier_nationalaccount_storageplugin -X-KDE-PluginInfo-Author=Christian David -X-KDE-PluginInfo-Email=christian-david@web.de -X-KDE-PluginInfo-Version=${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX} -X-KDE-PluginInfo-Website=https://kmymoney.org -X-KDE-PluginInfo-License=GPLv2+ -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2014 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NATIONALACCOUNTSTORAGEPLUGIN_H -#define NATIONALACCOUNTSTORAGEPLUGIN_H - -#include "sql/kmymoneystorageplugin.h" - -class nationalAccountStoragePlugin : public KMyMoneyPlugin::storagePlugin -{ - Q_OBJECT - Q_INTERFACES(KMyMoneyPlugin::storagePlugin) - -public: - explicit nationalAccountStoragePlugin(QObject* parent = 0, const QVariantList& options = QVariantList()); - bool removePluginData(QSqlDatabase connection) final override; - bool setupDatabase(QSqlDatabase connection) final override; - static QString iid(); -}; - -#endif // NATIONALACCOUNTSTORAGEPLUGIN_H diff --git a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp b/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp deleted file mode 100644 --- a/kmymoney/plugins/sql/payeeidentifier/nationalaccount/nationalaccountstorageplugin.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of KMyMoney, A Personal Finance Manager by KDE - * Copyright (C) 2015 Christian Dávid - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nationalaccountstorageplugin.h" - -#include -#include - -#include -#include - -#include "sql/kmymoneystorageplugin.h" - -K_PLUGIN_FACTORY_WITH_JSON(nationalAccountStoragePluginFactory, "kmymoney-nationalaccount-storageplugin.json", registerPlugin();) - -QString nationalAccountStoragePlugin::iid() -{ - return QLatin1String("org.kmymoney.payeeIdentifier.nationalAccount.sqlStoragePlugin"); -} - -nationalAccountStoragePlugin::nationalAccountStoragePlugin(QObject* parent, const QVariantList& options) - : storagePlugin(parent, options) -{ - -} - -/** @todo to be implemented */ -bool nationalAccountStoragePlugin::removePluginData(QSqlDatabase connection) -{ - Q_UNUSED(connection); - return false; -} - -bool nationalAccountStoragePlugin::setupDatabase(QSqlDatabase connection) -{ - // Get current version - QSqlQuery query = QSqlQuery(connection); - query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?"); - query.bindValue(0, iid()); - if (!query.exec()) { - qWarning("Could not execute query for nationalAccountStoragePlugin: %s", qPrintable(query.lastError().text())); - return false; - } - - int currentVersion = 0; - if (query.next()) - currentVersion = query.value(0).toInt(); - - // Create database in it's most recent version if version is 0 - // (version 0 means the database was not installed) - if (currentVersion == 0) { - // If the database is recreated the table may be still there. So drop it if needed. No error handling needed - // as this step is not necessary - only the creation is important. - if (!query.exec("DROP TABLE IF EXISTS kmmNationalAccountNumber;")) - return false; - - if (!query.exec( - "CREATE TABLE kmmNationalAccountNumber (" - " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmPayeeIdentifier( id ) ON DELETE CASCADE ON UPDATE CASCADE," - " countryCode varchar(3)," - " accountNumber TEXT," - " bankCode TEXT," - " name TEXT" - " );" - )) { - qWarning("Could not create table for nationalAccountStoragePlugin: %s", qPrintable(query.lastError().text())); - return false; - } - - query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); - query.bindValue(0, iid()); - query.bindValue(1, 1); - query.bindValue(2, 0); - query.bindValue(3, "DROP TABLE kmmNationalAccountNumber;"); - if (query.exec()) - return true; - qWarning("Could not save plugin info for nationalAccountStoragePlugin (%s): %s", qPrintable(iid()), qPrintable(query.lastError().text())); - return false; - } - - // Check if version is valid with this plugin - switch (currentVersion) { - case 1: return true; - } - - return false; -} - -#include "nationalaccountstorageplugin.moc" diff --git a/kmymoney/plugins/sql/tests/CMakeLists.txt b/kmymoney/plugins/sql/tests/CMakeLists.txt --- a/kmymoney/plugins/sql/tests/CMakeLists.txt +++ b/kmymoney/plugins/sql/tests/CMakeLists.txt @@ -4,7 +4,6 @@ ../mymoneystoragesql.cpp ../mymoneydbdef.cpp ../mymoneydbdriver.cpp - ../kmymoneystorageplugin.cpp ) add_library(sqlstoragestatic STATIC ${sqlstoragestatic_SOURCES} )