New plugins loading system
ClosedPublic

Authored by wojnilowicz on Dec 30 2017, 1:58 PM.

Details

Summary

Current plugins loading system crashes KMyMoney very often after quit and doesn't allow unpluging plugins. This patch aims to improve on those two deficiencies.

Changes:

  1. use of KPluginLoader instead of QPluginLoader

KCM modules of plugins cannot use QPluginLoader, so load all plugins with single type of plugin loader.
Loading with QPluginLoader directly causes some strange valgrind errors(invalid read size), which are untrackable. However, it doesn't occur with KPluginLoader.

  1. create new KSettingsPlugins page

The page has changing Apply button depending on selection. The page allows unloading/loading plugins. The page causes plugin system to update after changes.

  1. no method for plugins handling in KMyMoneyApp, because all is encapsulated in pluginloader.h
  2. don't store KPluginSelector because it's needed only during configuration
  3. use plugin diagnostics in console that looks like "Plugins: xxxplugin (un)loaded" which allows debugging,
  4. use kcmshell5 instead of kcmshell4,
  5. use of qobject_cast instead of dynamic_cast to test plugin's interfaces, which is faster,
  6. remove "kmm_" prefix from KMM plugins as they're private and not public, so no name clash shouldn't occur,
  7. rename classes from something like KMMXXXImporterPlugin to something like XXXImporter, which is shorter,
  8. allow enabling Weboob and using printcheck plugins,
  9. new m_plugins member to store all plugin interfaces.
Test Plan

Tested loading and unloading of every plugin.
SEPA orders is still unavailable and would require more work.

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wojnilowicz requested review of this revision.Dec 30 2017, 1:58 PM
wojnilowicz created this revision.

Fixed some problems with tests.

tbaumgart requested changes to this revision.Dec 30 2017, 5:11 PM

Compiles here without warnings after applying the following patch (just a couple overrides are missing)

diff --git a/kmymoney/plugins/csv/import/csvimporter.h b/kmymoney/plugins/csv/import/csvimporter.h
index 9e98beff..8493960e 100644
--- a/kmymoney/plugins/csv/import/csvimporter.h
+++ b/kmymoney/plugins/csv/import/csvimporter.h
@@ -53,7 +53,7 @@ public:
     *
     * @return QString Name of the format
     */
-  virtual QString formatName() const;
+  virtual QString formatName() const override;
 
   /**
     * This method returns the filename filter suitable for passing to
@@ -62,7 +62,7 @@ public:
     *
     * @return QString Filename filter string
     */
-  virtual QString formatFilenameFilter() const;
+  virtual QString formatFilenameFilter() const override;
 
   /**
     * This method returns whether this plugin is able to import
@@ -72,7 +72,7 @@ public:
     *
     * @return bool Whether the indicated file is importable by this plugin
     */
-  virtual bool isMyFormat(const QString& filename) const;
+  virtual bool isMyFormat(const QString& filename) const override;
 
   /**
     * Import a file
@@ -81,7 +81,7 @@ public:
     *
     * @return bool Whether the import was successful.
     */
-  virtual bool import(const QString& filename);
+  virtual bool import(const QString& filename) override;
 
   /**
     * Returns the error result of the last import
@@ -90,7 +90,7 @@ public:
     *  last import, or QString() if it was successful.
     *
     */
-  virtual QString lastError() const;
+  virtual QString lastError() const override;
 
 private:
   bool              m_silent;

I have tested a WebConnect CSV download and import. That worked well.
The only problem I see is that the "Update all accounts" action is not enabled after application start and I have not figured out how to make it available as a user. Also, the "Account/Update account..." is not enabled after I have selected an account that is mapped to an online account.

Here's the stderr log:

WebConnect: Try to connect to WebConnect server
WebConnect: Connect to server failed
WebConnect: Running in server mode
Plugins: csvexporter loaded
Plugins: csvimporter loaded
Plugins: gncimporter loaded
Plugins: icalendarexporter loaded
Plugins: kbanking loaded
Plugins: kbanking pluged
Plugins: ofximporter loaded
Plugins: printcheck loaded
QIODevice::read (QFile, "/usr/share/kmm_printcheck/check_template.html"): device not open
Plugins: qifexporter loaded
Plugins: qifimporter loaded
Plugins: reconciliation report loaded
Plugins: weboob loaded
Cost center model created with items 0
Payees model created with items 0
reading file
start parsing file
startDocument
reading securities
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
onlineTask available "org.kmymoney.creditTransfer.sepa"
endDocument
Start loading splits
Loaded 17494 elements
Loaded 33 elements
Loaded 17528 elements
<<< playing around with the app and quitting >>>
Plugins: csvexporter unloaded
Plugins: csvimporter unloaded
Plugins: gncimporter unloaded
Plugins: icalendarexporter unloaded
Plugins: kbanking unpluged
Plugins: kbanking unloaded
Plugins: ofximporter unloaded
Plugins: printcheck unloaded
Plugins: qifexporter unloaded
Plugins: qifimporter unloaded
Plugins: reconciliation report unloaded
Plugins: weboob unloaded

Another minor problem seems to be the location of the check template (see above that it was not found). It is installed as follows:

thb@thb-nb:~/devel/kmymoney/build (arcpatch-D9566 *)$ grep check_template install_manifest.txt 
/usr/share/printcheck/check_template.html
/usr/share/printcheck/check_template_green_linen.html
This revision now requires changes to proceed.Dec 30 2017, 5:11 PM

Fix problems with providers.

tbaumgart accepted this revision.Dec 30 2017, 6:37 PM

Looks good to me. The template file for the printcheck plugin has a new location. We need to mention that in the Release Notes

This revision is now accepted and ready to land.Dec 30 2017, 6:37 PM
This revision was automatically updated to reflect the committed changes.