1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3  * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4  * SPDX-License-Identifier: GPL-3.0-or-later
5  ***************************************************************************/
6 #ifndef SKGSCHEDULEDPLUGIN_H
7 #define SKGSCHEDULEDPLUGIN_H
8 /** @file
9  * A skrooge plugin to manage scheduled operations.
10 *
11 * @author Stephane MANKOWSKI
12  */
13 #include "skginterfaceplugin.h"
14 #include "skgoperationobject.h"
15 #include "ui_skgscheduledpluginwidget_pref.h"
16 
17 class SKGDocumentBank;
18 
19 /**
20  * A skrooge plugin to manage scheduled operations
21  */
22 class SKGScheduledPlugin : public SKGInterfacePlugin
23 {
24     Q_OBJECT
25     Q_INTERFACES(SKGInterfacePlugin)
26 
27 public:
28     /**
29      * Default Constructor
30      */
31     explicit SKGScheduledPlugin(QWidget* iWidget, QObject* iParent, const QVariantList& iArg);
32 
33     /**
34      * Default Destructor
35      */
36     ~SKGScheduledPlugin() override;
37 
38     /**
39      * Called to initialise the plugin
40      * @param iDocument the main document
41      * @return true if the plugin is compatible with the document
42      */
43     bool setupActions(SKGDocument* iDocument) override;
44 
45     /**
46      * The number of dashboard widgets of the plugin.
47      * @return The number of dashboard widgets of the plugin
48      */
49     int getNbDashboardWidgets() override;
50 
51     /**
52      * Get a dashboard widget title of the plugin.
53      * @param iIndex the index of the widget
54      * @return The title
55      */
56     QString getDashboardWidgetTitle(int iIndex) override;
57 
58     /**
59      * Get a dashboard widget of the plugin.
60      * @param iIndex the index of the widget
61      * @return The dashboard widget of the plugin
62      */
63     SKGBoardWidget* getDashboardWidget(int iIndex) override;
64 
65     /**
66      * Must be modified to refresh widgets after a modification.
67      */
68     void refresh() override;
69 
70     /**
71     * The preference widget of the plugin.
72     * @return The preference widget of the plugin
73      */
74     QWidget* getPreferenceWidget() override;
75 
76     /**
77      * The preference skeleton of the plugin.
78      * @return The preference skeleton of the plugin
79      */
80     KConfigSkeleton* getPreferenceSkeleton() override;
81 
82     /**
83      * This function is called when preferences have been modified. Must be used to save some parameters into the document.
84      * A transaction is already opened
85      * @return an object managing the error.
86      *   @see SKGError
87      */
88     SKGError savePreferences() const override;
89 
90     /**
91      * The page widget of the plugin.
92      * @return The page widget of the plugin
93      */
94     SKGTabPage* getWidget() override;
95 
96     /**
97      * The title of the plugin.
98      * @return The title of the plugin
99      */
100     QString title() const override;
101 
102     /**
103      * The icon of the plugin.
104      * @return The icon of the plugin
105      */
106     QString icon() const override;
107 
108     /**
109      * The toolTip of the plugin.
110      * @return The toolTip of the plugin
111      */
112     QString toolTip() const override;
113 
114     /**
115      * The tips list of the plugin.
116      * @return The tips list of the plugin
117      */
118     QStringList tips() const override;
119 
120     /**
121      * Must be implemented to set the position of the plugin.
122      * @return integer value between 0 and 999 (default = 999)
123      */
124     int getOrder() const override;
125 
126     /**
127      * Must be implemented to know if a plugin must be display in pages chooser.
128      * @return true of false (default = false)
129      */
130     bool isInPagesChooser() const override;
131 
132     /**
133      * The advice list of the plugin.
134      * @return The advice list of the plugin
135      */
136     SKGAdviceList advice(const QStringList& iIgnoredAdvice) override;
137 
138     /**
139      * Must be implemented to execute the automatic correction for the advice.
140      * @param iAdviceIdentifier the identifier of the advice
141      * @param iSolution the identifier of the possible solution
142      * @return an object managing the error. MUST return ERR_NOTIMPL if iAdviceIdentifier is not known
143      *   @see SKGError
144      */
145     SKGError executeAdviceCorrection(const QString& iAdviceIdentifier, int iSolution) override;
146 
147 private Q_SLOTS:
148     void onScheduleOperation();
149     void onSkipScheduledOperations();
150 
151 private:
152     Q_DISABLE_COPY(SKGScheduledPlugin)
153 
154     SKGError scheduleOperation(const SKGOperationObject& iOperation, SKGRecurrentOperationObject& oRecurrent) const;
155 
156     SKGDocumentBank* m_currentBankDocument;
157     QString m_docUniqueIdentifier;
158 
159     Ui::skgscheduledplugin_pref ui{};
160 
161     int m_counterAdvice;
162 };
163 
164 #endif  // SKGSCHEDULEDPLUGIN_H
165