KMyMoney Plugin API

kmymoneyplugin.cpp
1 /*
2  SPDX-FileCopyrightText: 2005-2021 Thomas Baumgart <[email protected]>
3  SPDX-FileCopyrightText: 2015 Christian Dávid <[email protected]>
4  SPDX-FileCopyrightText: 2021 Dawid Wróbel <[email protected]>
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "kmymoneyplugin.h"
9 
10 // ----------------------------------------------------------------------------
11 // QT Includes
12 
13 #include <QMap>
14 #include <QMimeDatabase>
15 
16 // ----------------------------------------------------------------------------
17 // KDE Includes
18 
19 #include <KActionCollection>
20 #include <KPluginMetaData>
21 #include <KToggleAction>
22 
23 // ----------------------------------------------------------------------------
24 // Project Includes
25 #include "interfaceloader.h"
26 #if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 77, 0)
27 #include <mymoneyexception.h>
28 #endif
29 
31 
32 #if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 77, 0)
33 KMyMoneyPlugin::Plugin::Plugin(QObject* parent, const QVariantList& args)
34  : QObject()
35  , KXMLGUIClient()
36 {
37  Q_UNUSED(parent)
38 
39  if (args.isEmpty() || args.count() < 2)
40  throw MYMONEYEXCEPTION_CSTRING("Plugin not initialized properly!");
41  else {
42  setObjectName(args.at(0).toString());
43  m_componentDisplayName = args.at(1).toString();
44  setComponentName(args.at(0).toString(), m_componentDisplayName);
45  }
46 }
47 #else
48 KMyMoneyPlugin::Plugin::Plugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList& args)
49  : QObject()
50  , KXMLGUIClient()
51 {
52  Q_UNUSED(parent)
53  Q_UNUSED(args)
54 
55  setObjectName(metaData.pluginId());
56  m_componentDisplayName = metaData.name();
57  setComponentName(metaData.pluginId(), m_componentDisplayName);
58 }
59 #endif
60 
61 KMyMoneyPlugin::Plugin::~Plugin()
62 {
63 }
64 
65 QString KMyMoneyPlugin::Plugin::componentDisplayName() const
66 {
67  return m_componentDisplayName;
68 }
69 
71 {
72  Q_UNUSED(guiFactory)
73 }
74 
76 {
77 }
78 
79 void KMyMoneyPlugin::Plugin::updateActions(const SelectedObjects& selections)
80 {
81  Q_UNUSED(selections)
82 }
83 
85 {
86 }
87 
89 {
90  static KToggleAction dummyAction(QString("Dummy"), nullptr);
91 
92  KToggleAction* p = dynamic_cast<KToggleAction*>(actionCollection()->action(QString(actionName.toLatin1())));
93  if (!p) {
94  qWarning("Action '%s' is not of type KToggleAction", qPrintable(actionName));
95  p = &dummyAction;
96  }
97 
98  qWarning("Action with name '%s' not found!", qPrintable(actionName));
99  return p;
100 }
101 
102 KMyMoneyPlugin::OnlinePlugin::OnlinePlugin()
103 {
104 }
105 
106 KMyMoneyPlugin::OnlinePlugin::~OnlinePlugin()
107 {
108 }
109 
110 KMyMoneyPlugin::AppInterface* KMyMoneyPlugin::Plugin::appInterface() const
111 {
112  Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().appInterface);
113  return KMyMoneyPlugin::pluginInterfaces().appInterface;
114 }
115 
116 KMyMoneyPlugin::ViewInterface* KMyMoneyPlugin::Plugin::viewInterface() const
117 {
118  Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().viewInterface);
119  return KMyMoneyPlugin::pluginInterfaces().viewInterface;
120 }
121 
122 KMyMoneyPlugin::StatementInterface* KMyMoneyPlugin::Plugin::statementInterface() const
123 {
124  Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().statementInterface);
125  return KMyMoneyPlugin::pluginInterfaces().statementInterface;
126 }
127 
128 KMyMoneyPlugin::ImportInterface* KMyMoneyPlugin::Plugin::importInterface() const
129 {
130  Q_CHECK_PTR(KMyMoneyPlugin::pluginInterfaces().importInterface);
131  return KMyMoneyPlugin::pluginInterfaces().importInterface;
132 }
133 
134 KMyMoneyPlugin::ImporterPlugin::ImporterPlugin()
135 {
136 }
137 
139 {
140  QMimeDatabase db;
141  QMimeType mime = db.mimeTypeForFile(filename);
142 
143  if (!mime.isDefault())
144  for (const auto& mimeTypeName : formatMimeTypes())
145  if (mime.inherits(mimeTypeName))
146  return true;
147 
148  return false;
149 }
150 
151 KMyMoneyPlugin::ImporterPlugin::~ImporterPlugin()
152 {
153 }
virtual void plug(KXMLGUIFactory *guiFactory)
Called during plug in process.
virtual KActionCollection * actionCollection() const
QString name() const
virtual void unplug()
Called before unloading.
KMyMoneyPlugin::Container pPlugins
Structure of plugins objects by their interfaces.
KToggleAction * toggleAction(const QString &name) const
See KMyMoneyApp::toggleAction() for a description.
bool inherits(const QString &mimeTypeName) const const
This abstract class represents the ImportInterface to add new importers to KMyMoney.
This abstract class represents the ViewInterface to add new view pages to the JanusWidget of KMyMoney...
Definition: viewinterface.h:47
virtual void updateConfiguration()
This method is called by the application whenever the configuration changes.
QMimeType mimeTypeForFile(const QString &fileName, QMimeDatabase::MatchMode mode) const const
virtual void updateActions(const SelectedObjects &selections)
This method is called by the application whenever a selection changes.
virtual bool isMyFormat(const QString &filename) const
This method checks whether the file provided is of expected format.
The Container struct to hold all plugin interfaces.
QByteArray toLatin1() const const
QAction * action(int index) const
QString pluginId() const
This abstract class represents the interface to import statements into the KMyMoney application...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 19 2021 23:23:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.