File indexing completed on 2024-05-19 05:06:54
0001 /* 0002 SPDX-FileCopyrightText: 2005-2021 Thomas Baumgart <ipwizard@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2015 Christian Dávid <christian-david@web.de> 0004 SPDX-FileCopyrightText: 2021 Dawid Wróbel <me@dawidwrobel.com> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KMYMONEYPLUGIN_H 0009 #define KMYMONEYPLUGIN_H 0010 0011 #include <kmm_plugin_export.h> 0012 0013 // ---------------------------------------------------------------------------- 0014 // QT Includes 0015 0016 #include <QMap> 0017 #include <QObject> 0018 0019 // ---------------------------------------------------------------------------- 0020 // KDE Includes 0021 0022 #include <KXMLGUIClient> 0023 0024 #include "kcoreaddons_version.h" 0025 0026 class KToggleAction; 0027 class KPluginMetaData; 0028 0029 // ---------------------------------------------------------------------------- 0030 // Project Includes 0031 0032 #include "mymoneykeyvaluecontainer.h" 0033 0034 class MyMoneyStorageMgr; 0035 class MyMoneyAccount; 0036 class KMyMoneySettings; 0037 class IMyMoneyOperationsFormat; 0038 class SelectedObjects; 0039 0040 namespace KMyMoneyPlugin { 0041 class AppInterface; 0042 class ImportInterface; 0043 class StatementInterface; 0044 class ViewInterface; 0045 } 0046 0047 namespace eKMyMoney { 0048 enum class StorageType; 0049 } 0050 0051 /** 0052 * @defgroup KMyMoneyPlugin 0053 * 0054 * KMyMoney knows several types of plugins. The most common and generic one is KMyMoneyPlugin::Plugin. 0055 * 0056 * Another group of plugins are just loaded on demand and offer special functions with a tight integration into KMyMoney. Whenever possible you should use this 0057 * kind of plugins. At the moment this are the onlineTask and payeeIdentifierData. 0058 * 0059 * @{ 0060 */ 0061 0062 namespace KMyMoneyPlugin { 0063 0064 /** 0065 * This class describes the interface between KMyMoney and it's plugins. 0066 * 0067 * The plugins are based on Qt 5's plugin system. So you must compile json information into the plugin. 0068 * KMyMoney looks into the folder "${PLUGIN_INSTALL_DIR}/kmymoney/" and loads all plugins found there (if the user did not deactivate the plugin). 0069 * 0070 * The json header of the plugin must comply with the requirements of KCoreAddon's KPluginMetaData class. 0071 * To load the plugin at start up the service type "KMyMoney/Plugin" must be set. 0072 * 0073 * @warning The plugin system for KMyMoney 5 is still in development. Especially the loading of the on-demand plugins (mainly undocumented :( ) will change. 0074 * 0075 * A basic json header is shown below. 0076 * @code{.json} 0077 { 0078 "KPlugin": { 0079 "Authors": [ 0080 { 0081 "Name": "Author's Names, Second Author", 0082 "Email": "E-Mail 1, E-Mail 2" 0083 } 0084 ], 0085 "Description": "Short description for plugin list (translateable)", 0086 "EnabledByDefault": true, 0087 "Icon": "icon to be shown in plugin list", 0088 "Id": "a unique identifier", 0089 "License": "see KPluginMetaData for list of predefined licenses (translateable)", 0090 "Name": "Name of the plugin (translateable)", 0091 "Version": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@", 0092 } 0093 } 0094 * @endcode 0095 * 0096 * This example assumes you are using 0097 * @code{.cmake} 0098 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/... ${CMAKE_CURRENT_BINARY_DIR}/... @ONLY) 0099 @endcode 0100 * to replace the version variables using cmake. 0101 * 0102 * @see https://doc.qt.io/qt-5/plugins-howto.html 0103 * @see https://api.kde.org/frameworks/kcoreaddons/html/classKPluginMetaData.html 0104 * 0105 */ 0106 class KMM_PLUGIN_EXPORT Plugin : public QObject, public KXMLGUIClient 0107 { 0108 Q_OBJECT 0109 public: 0110 explicit Plugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList& args); 0111 virtual ~Plugin(); 0112 0113 QString componentDisplayName() const; 0114 0115 public Q_SLOTS: 0116 /** 0117 * @brief Called during plug in process 0118 */ 0119 virtual void plug(KXMLGUIFactory* guiFactory); 0120 0121 /** 0122 * @brief Called before unloading 0123 */ 0124 virtual void unplug(); 0125 0126 /** 0127 * This method is called by the application whenever a 0128 * selection changes. The default implementation does nothing. 0129 */ 0130 virtual void updateActions(const SelectedObjects& selections); 0131 0132 /** 0133 * This method is called by the application whenever the 0134 * configuration changes. The default implementation does nothing. 0135 */ 0136 virtual void updateConfiguration(); 0137 0138 protected: 0139 /** See KMyMoneyApp::toggleAction() for a description */ 0140 KToggleAction* toggleAction(const QString& name) const; 0141 0142 // define interface classes here. The interface classes provide a mechanism 0143 // for the plugin to interact with KMyMoney 0144 // they are defined in the following form for an interface 0145 // named Xxx: 0146 // 0147 // XxxInterface* xxxInterface(); 0148 0149 AppInterface* appInterface() const; 0150 ViewInterface* viewInterface() const; 0151 StatementInterface* statementInterface() const; 0152 ImportInterface* importInterface() const; 0153 0154 private: 0155 QString m_componentDisplayName; 0156 }; 0157 0158 /** 0159 * This class describes the interface between the KMyMoney 0160 * application and it's ONLINE-BANKING plugins. All online banking plugins 0161 * must provide this interface. 0162 * 0163 * A good tutorial on how to design and develop a plugin 0164 * structure for a KDE application (e.g. KMyMoney) can be found at 0165 * http://web.archive.org/web/20100305214125/http://developer.kde.org/documentation/tutorials/developing-a-plugin-structure/index.html 0166 * 0167 */ 0168 class KMM_PLUGIN_EXPORT OnlinePlugin 0169 { 0170 public: 0171 OnlinePlugin(); 0172 virtual ~OnlinePlugin(); 0173 0174 virtual void protocols(QStringList& protocolList) const = 0; 0175 0176 /** 0177 * This method returns a pointer to a widget representing an additional 0178 * tab that will be added to the KNewAccountDlg. The string referenced 0179 * with @a tabName will be filled with the text that should be placed 0180 * on the tab. It should return 0 if no additional tab is needed. 0181 * 0182 * Information about the account can be taken out of @a account. 0183 * 0184 * Once the pointer to the widget is returned to KMyMoney, it takes care 0185 * of destruction of all included widgets when the dialog is closed. The plugin 0186 * can access the widgets created after the call to storeConfigParameters() 0187 * happened. 0188 */ 0189 virtual QWidget* accountConfigTab(const MyMoneyAccount& account, QString& tabName) = 0; 0190 0191 /** 0192 * This method is called by the framework whenever it is time to store 0193 * the configuration data maintained by the plugin. The plugin should use 0194 * the widgets created in accountConfigTab() to extract the current values. 0195 * 0196 * @param current The @a current container contains the current settings 0197 */ 0198 virtual MyMoneyKeyValueContainer onlineBankingSettings(const MyMoneyKeyValueContainer& current) = 0; 0199 0200 /** 0201 * This method is called by the framework when the user wants to map 0202 * a KMyMoney account onto an online account. The KMyMoney account is identified 0203 * by @a acc and the online provider should store its data in @a onlineBankingSettings 0204 * upon success. 0205 * 0206 * @retval true if account is mapped 0207 * @retval false if account is not mapped 0208 */ 0209 virtual bool mapAccount(const MyMoneyAccount& acc, MyMoneyKeyValueContainer& onlineBankingSettings) = 0; 0210 0211 /** 0212 * This method is called by the framework when the user wants to update 0213 * a KMyMoney account with data from an online account. The KMyMoney account is identified 0214 * by @a acc. The online provider should read its data from acc.onlineBankingSettings(). 0215 * @a true is returned upon success. The plugin might consider to stack the requests 0216 * in case @a moreAccounts is @p true. @a moreAccounts defaults to @p false. 0217 * 0218 * @retval true if account is updated 0219 * @retval false if account is not updated 0220 */ 0221 virtual bool updateAccount(const MyMoneyAccount& acc, bool moreAccounts = false) = 0; 0222 }; 0223 0224 /** 0225 * This class describes the interface between the KMyMoney 0226 * application and it's IMPORTER plugins. All importer plugins 0227 * must provide this interface. 0228 * 0229 * A good tutorial on how to design and develop a plugin 0230 * structure for a KDE application (e.g. KMyMoney) can be found at 0231 * http://web.archive.org/web/20100305214125/http://developer.kde.org/documentation/tutorials/developing-a-plugin-structure/index.html 0232 * 0233 */ 0234 class KMM_PLUGIN_EXPORT ImporterPlugin 0235 { 0236 public: 0237 ImporterPlugin(); 0238 virtual ~ImporterPlugin(); 0239 0240 /** 0241 * This method returns the list of the MIME types that this plugin handles, 0242 * e.g. {"application/x-ofx", "application/x-qfx"}. Be specific: don't use generic 0243 * types, like "text/plain", which many other types inherit from, and which 0244 * would result in @ref isMyFormat() returning false positives. 0245 * 0246 * @return QStringList List of MIME types 0247 */ 0248 virtual QStringList formatMimeTypes() const = 0; 0249 0250 /** 0251 * This method checks whether the file provided is of expected format. 0252 * The default implementation checks whether the file's MIME type inherits any 0253 * of the types provided by @ref formatMimeTypes(). 0254 * 0255 * @param filename Fully-qualified pathname to a file 0256 * 0257 * @return bool Whether the indicated file is importable by this plugin 0258 */ 0259 virtual bool isMyFormat(const QString& filename) const; 0260 0261 /** 0262 * Import a file 0263 * 0264 * @param filename File to import 0265 * 0266 * @return bool Whether the import was successful. 0267 */ 0268 virtual bool import(const QString& filename) = 0; 0269 0270 /** 0271 * Returns the error result of the last import 0272 * 0273 * @return QString English-language name of the error encountered in the 0274 * last import, or QString() if it was successful. 0275 * 0276 */ 0277 virtual QString lastError() const = 0; 0278 }; 0279 0280 /** 0281 * This class describes the interface between the KMyMoney 0282 * application and it's STORAGE plugins. All storage plugins 0283 * must provide this interface. 0284 * 0285 */ 0286 class KMM_PLUGIN_EXPORT StoragePlugin 0287 { 0288 public: 0289 StoragePlugin() = default; 0290 virtual ~StoragePlugin() = default; 0291 0292 /** 0293 * @brief Loads file into storage 0294 * @param url URL of the file 0295 * @return true if successfully opened 0296 */ 0297 virtual bool open(const QUrl& url) = 0; 0298 0299 /** 0300 * @brief Saves storage into file 0301 * @param url URL of the file 0302 * @return true if successfully saved 0303 */ 0304 virtual bool save(const QUrl& url) = 0; 0305 0306 /** 0307 * @brief Saves storage into file 0308 * @param url URL of the file 0309 * @return true if successfully saved 0310 */ 0311 virtual bool saveAs() = 0; 0312 0313 /** 0314 * @brief Storage identifier 0315 * @return Storage identifier 0316 */ 0317 virtual eKMyMoney::StorageType storageType() const = 0; 0318 0319 virtual QString fileExtension() const = 0; 0320 0321 /** 0322 * @brief returns the full URL used to open the database (incl. password) 0323 * @return QUrl to re-open the database 0324 */ 0325 virtual QUrl openUrl() const = 0; 0326 }; 0327 0328 /** 0329 * This class describes the interface between the KMyMoney 0330 * application and its data plugins. All data plugins 0331 * must provide this interface. 0332 * 0333 */ 0334 class KMM_PLUGIN_EXPORT DataPlugin 0335 { 0336 public: 0337 DataPlugin() = default; 0338 virtual ~DataPlugin() = default; 0339 0340 /** 0341 * @brief Gets data from data service 0342 * @param arg Item name to retrieve data for 0343 * @param type Data type to retrieve for item 0344 * @return a data like int or QString 0345 */ 0346 virtual QVariant requestData(const QString& arg, uint type) = 0; 0347 }; 0348 0349 class OnlinePluginExtended; 0350 0351 /** 0352 * @brief The Container struct to hold all plugin interfaces 0353 */ 0354 struct Container { 0355 QMap<QString, Plugin*> standard; // this should contain all loaded plugins because every plugin should inherit Plugin class 0356 QMap<QString, OnlinePlugin*> online; // casted standard plugin, if such interface is available 0357 QMap<QString, OnlinePluginExtended*> extended; // casted standard plugin, if such interface is available 0358 QMap<QString, ImporterPlugin*> importer; // casted standard plugin, if such interface is available 0359 QMap<QString, StoragePlugin*> storage; // casted standard plugin, if such interface is available 0360 QMap<QString, DataPlugin*> data; // casted standard plugin, if such interface is available 0361 }; 0362 0363 } // end of namespace 0364 0365 /** 0366 * @brief Structure of plugins objects by their interfaces 0367 */ 0368 KMM_PLUGIN_EXPORT extern KMyMoneyPlugin::Container pPlugins; 0369 0370 Q_DECLARE_INTERFACE(KMyMoneyPlugin::OnlinePlugin, "org.kmymoney.plugin.onlineplugin") 0371 Q_DECLARE_INTERFACE(KMyMoneyPlugin::ImporterPlugin, "org.kmymoney.plugin.importerplugin") 0372 Q_DECLARE_INTERFACE(KMyMoneyPlugin::StoragePlugin, "org.kmymoney.plugin.storageplugin") 0373 Q_DECLARE_INTERFACE(KMyMoneyPlugin::DataPlugin, "org.kmymoney.plugin.dataplugin") 0374 0375 /** @} */ 0376 0377 #endif