File indexing completed on 2024-05-05 17:19:01

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGINTERFACEPLUGIN_H
0007 #define SKGINTERFACEPLUGIN_H
0008 /** @file
0009 * This file is a plugin interface definition.
0010 *
0011 * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 #include <kparts/readonlypart.h>
0014 
0015 #include <qstringlist.h>
0016 
0017 #include "skgadvice.h"
0018 #include "skgbasegui_export.h"
0019 #include "skgdocument.h"
0020 #include "skgerror.h"
0021 #include "skgtabpage.h"
0022 class SKGBoardWidget;
0023 class QAction;
0024 class KConfigSkeleton;
0025 class QDockWidget;
0026 
0027 /**
0028  * This file is a plugin interface definition.
0029  */
0030 class SKGBASEGUI_EXPORT SKGInterfacePlugin : public KParts::ReadOnlyPart
0031 {
0032     Q_OBJECT
0033 public:
0034     /**
0035      * Default constructor
0036      * @param iParent the parent of the plugin
0037      */
0038     explicit SKGInterfacePlugin(QObject* iParent = nullptr);
0039 
0040     /**
0041      * Default destructor
0042      */
0043     ~SKGInterfacePlugin() override;
0044 
0045     /**
0046      * Called to initialise the plugin
0047      * @param iDocument the main document
0048      * @return true if the plugin is compatible with the document
0049      */
0050     virtual bool setupActions(SKGDocument* iDocument) = 0;
0051 
0052     /**
0053      * Register a global action
0054      * @param iIdentifier identifier of the action
0055      * @param iAction action pointer
0056      * @param iListOfTable list of table where this action must be enabled (empty list means all)
0057      *                 You can also add only one item like this to set the list dynamically:
0058      *                 query:the sql condition on sqlite_master
0059      * @param iMinSelection the minimum number of selected item to enable the action
0060      *                  0 : no need selection but need a page opened containing a table
0061      *                 -1 : no need selection and need a page opened (not containing a table)
0062      *                 -2 : no need selection and no need a page opened
0063      * @param iMaxSelection the maximum number of selected item to enable the action (-1 = infinite)
0064      * @param iRanking the ranking to sort actions in contextual menus
0065      *                  -1: automatic by creation order
0066      *                   0: not in contextual menu
0067      * @param iSelectionMustHaveFocus the action will be activated only if the widget containing the selection has the focus
0068      *
0069      *                   Actions can be set in differents groups by changing hundred:
0070      *                      0 to  99 is a group
0071      *                    100 to 200 is an other group
0072      */
0073     virtual void registerGlobalAction(const QString& iIdentifier, QAction* iAction,
0074                                       const QStringList& iListOfTable = QStringList(),
0075                                       int iMinSelection = -2,
0076                                       int iMaxSelection = -1,
0077                                       int iRanking = -1,
0078                                       bool iSelectionMustHaveFocus = false);
0079 
0080     /**
0081      * This function is called when the application is launched again with new arguments
0082      * @param iArgument the arguments
0083      * @return the rest of arguments to treat
0084      */
0085     virtual QStringList processArguments(const QStringList& iArgument);
0086 
0087     /**
0088      * Must be modified to close properly the plugin.
0089      */
0090     virtual void close();
0091 
0092     /**
0093      * Must be modified to refresh widgets after a modification.
0094      */
0095     virtual void refresh();
0096 
0097     /**
0098      * The page widget of the plugin.
0099      * @return The page widget of the plugin
0100      */
0101     virtual SKGTabPage* getWidget();
0102 
0103     /**
0104      * The number of dashboard widgets of the plugin.
0105      * @return The number of dashboard widgets of the plugin
0106      */
0107     virtual int getNbDashboardWidgets();
0108 
0109     /**
0110      * Get a dashboard widget title of the plugin.
0111      * @param iIndex the index of the widget
0112      * @return The title
0113      */
0114     virtual QString getDashboardWidgetTitle(int iIndex);
0115 
0116     /**
0117      * Get a dashboard widget of the plugin.
0118      * @param iIndex the index of the widget
0119      * @return The dashboard widget of the plugin
0120      */
0121     virtual SKGBoardWidget* getDashboardWidget(int iIndex);
0122 
0123     /**
0124      * The dock widget of the plugin.
0125      * @return The dock widget of the plugin
0126      */
0127     virtual QDockWidget* getDockWidget();
0128 
0129     /**
0130      * Initialize the preferences. This is use full for settings stored in the document
0131      */
0132     virtual void initPreferences();
0133 
0134     /**
0135      * The preference widget of the plugin.
0136      * @return The preference widget of the plugin
0137      */
0138     virtual QWidget* getPreferenceWidget();
0139 
0140     /**
0141      * The preference skeleton of the plugin.
0142      * @return The preference skeleton of the plugin
0143      */
0144     virtual KConfigSkeleton* getPreferenceSkeleton();
0145 
0146     /**
0147      * This function is called when preferences have been modified. Must be used to save some parameters into the document.
0148      * A transaction is already opened
0149      * @return an object managing the error.
0150      *   @see SKGError
0151      */
0152     virtual SKGError savePreferences() const;
0153 
0154     /**
0155      * The title of the plugin.
0156      * @return The title of the plugin
0157      */
0158     virtual QString title() const = 0;
0159 
0160     /**
0161      * The icon of the plugin.
0162      * @return The icon of the plugin
0163      */
0164     virtual QString icon() const;
0165 
0166     /**
0167      * The statusTip of the plugin.
0168      * @return The toolTip of the plugin
0169      */
0170     virtual QString statusTip() const;
0171 
0172     /**
0173      * The toolTip of the plugin.
0174      * @return The toolTip of the plugin
0175      */
0176     virtual QString toolTip() const;
0177 
0178     /**
0179      * The tips list of the plugin.
0180      * @return The tips list of the plugin
0181      */
0182     virtual QStringList tips() const;
0183 
0184     /**
0185      * The sub plugins services types list of the plugin.
0186      * This will be used to display authors in the "About" of the application
0187      * @return The sub plugins list of the plugin
0188      */
0189     virtual QStringList subPlugins() const;
0190 
0191     /**
0192      * Must be implemented to set the position of the plugin.
0193      * @return integer value between 0 and 999 (default = 999)
0194      */
0195     virtual int getOrder() const;
0196 
0197     /**
0198      * Must be implemented to know if a plugin must be display in pages chooser.
0199      * @return true of false (default = false)
0200      */
0201     virtual bool isInPagesChooser() const;
0202 
0203     /**
0204      * Must be implemented to know if this plugin is enabled
0205      * @return true of false (default = true)
0206      */
0207     virtual bool isEnabled() const;
0208 
0209     /**
0210      * The advice list of the plugin.
0211      * @return The advice list of the plugin
0212      */
0213     virtual SKGAdviceList advice(const QStringList& iIgnoredAdvice);
0214 
0215     /**
0216      * Must be implemented to execute the automatic correction for the advice.
0217      * @param iAdviceIdentifier the identifier of the advice
0218      * @param iSolution the identifier of the possible solution
0219      * @return an object managing the error. MUST return ERR_NOTIMPL if iAdviceIdentifier is not known
0220      *   @see SKGError
0221      */
0222     virtual SKGError executeAdviceCorrection(const QString& iAdviceIdentifier, int iSolution);
0223 
0224 private:
0225     Q_DISABLE_COPY(SKGInterfacePlugin)
0226 };
0227 
0228 /**
0229  * This plugin interface definition.
0230  */
0231 Q_DECLARE_INTERFACE(SKGInterfacePlugin, "skrooge.com.SKGInterfacePlugin/1.0")
0232 
0233 #endif  // SKGINTERFACEPLUGIN_H