Warning, file /office/skrooge/skgbasegui/skgmainpanel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 SKGMAINPANEL_H 0007 #define SKGMAINPANEL_H 0008 /** @file 0009 * This file defines a main panel. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 #include <kxmlguiwindow.h> 0014 0015 #include <qsystemtrayicon.h> 0016 #include <qurl.h> 0017 0018 #include "skgbasegui_export.h" 0019 #include "skgbasegui_settings.h" 0020 #include "skginterfaceplugin.h" 0021 #include "skgobjectbase.h" 0022 #include "skgtabpage.h" 0023 #include "skgtabwidget.h" 0024 0025 #include "ui_skgmainpanel_base.h" 0026 #include "ui_skgmainpanel_pref.h" 0027 0028 0029 class SKGDocument; 0030 class SKGMainPanelPrivate; 0031 0032 class QSplashScreen; 0033 class KMessageWidget; 0034 0035 class QListWidgetItem; 0036 0037 /** 0038 * This class serves as the main window. It handles the 0039 * menus, toolbars, and status bars. 0040 */ 0041 class SKGBASEGUI_EXPORT SKGMainPanel : public KXmlGuiWindow 0042 { 0043 Q_OBJECT 0044 public: 0045 /** 0046 * Default Constructor 0047 * @param iSplashScreen the splash screen 0048 * @param iDocument the document to manage data 0049 */ 0050 explicit SKGMainPanel(QSplashScreen* iSplashScreen, SKGDocument* iDocument); 0051 0052 /** 0053 * Default Destructor 0054 */ 0055 ~SKGMainPanel() override; 0056 0057 /** 0058 * Return the document of the main panel 0059 * @return document of the main panel 0060 */ 0061 SKGDocument* getDocument() const; 0062 0063 /** 0064 * Creates a modal file dialog and returns the selected filename or an empty string if none was chosen. 0065 * A confirmation message is displayed if needed 0066 * @param iStartDir this can either be 0067 * @li the URL of the directory to start in. 0068 * @li a QUrl) to start in the current working directory, or the last directory where a file has been selected. 0069 * @li an URL starting with 'kfiledialog:///\<keyword\>' to start in the directory last used by a filedialog in the same application that specified the same keyword. 0070 * @li an URL starting with 'kfiledialog:///\<keyword\>?global' to start in the directory last used by a filedialog in any application that specified the same keyword. 0071 * @param iFilter a shell glob or a mime-type-filter that specifies which files to display. The preferred option is to set a list of mimetype names, see setMimeFilter() for details. Otherwise you can set the text to be displayed for the each glob, and provide multiple globs, see setFilter() for details. 0072 * @param iParent the widget the dialog will be centered on initially. 0073 * @param iCodec a valid QString to get the codec or nullptr. 0074 * @return the file name 0075 */ 0076 static QString getSaveFileName(const QString& iStartDir, const QString& iFilter, QWidget* iParent, QString* iCodec = nullptr); 0077 0078 /** 0079 * Display an error message 0080 * @param iError the error 0081 * @param iNotifyIfNoError to launch a notification even if there is no error 0082 * @return the message widget 0083 */ 0084 static KMessageWidget* displayErrorMessage(const SKGError& iError, bool iNotifyIfNoError = false); 0085 0086 /** 0087 * Display an error message 0088 * @param iError the error 0089 * @param iAction the additional action to add 0090 * @param iNotifyIfNoError to launch a notification even if there is no error 0091 * @return the message widget 0092 */ 0093 static KMessageWidget* displayErrorMessage(const SKGError& iError, QAction* iAction, bool iNotifyIfNoError = false); 0094 0095 /** 0096 * Fill a widget with distinct values 0097 * @param iWidgets the widgets 0098 * @param iDoc document 0099 * @param iTable table 0100 * @param iAttribut attribute 0101 * @param iWhereClause where clause 0102 * @param iAddoperators to add operators (=upper, =lower to the list) 0103 */ 0104 static void fillWithDistinctValue( 0105 const QList<QWidget*>& iWidgets, 0106 SKGDocument* iDoc, 0107 const QString& iTable, 0108 const QString& iAttribut, 0109 const QString& iWhereClause, 0110 bool iAddoperators = false); 0111 0112 /** 0113 * Return main panel 0114 */ 0115 static SKGMainPanel* getMainPanel(); 0116 0117 /** 0118 * Get main config groupe 0119 * @return main config groupe 0120 */ 0121 static KConfigGroup getMainConfigGroup(); 0122 0123 /** 0124 * Convert a QDate into a QString based on application settings. 0125 * @param iDate the date 0126 * @return the converted QString 0127 */ 0128 // cppcheck-suppress passedByValue 0129 static QString dateToString(QDate iDate); 0130 0131 /** 0132 * Get the first selected object 0133 * @return first selected object 0134 */ 0135 SKGObjectBase getFirstSelectedObject() const; 0136 0137 /** 0138 * Get the current selection 0139 * @return selected objects 0140 */ 0141 SKGObjectBase::SKGListSKGObjectBase getSelectedObjects() const; 0142 0143 /** 0144 * Get the number of selected object 0145 * @return number of selected objects 0146 */ 0147 int getNbSelectedObjects() const; 0148 0149 /** 0150 * To know if the widget having the selection has the focus 0151 * Default implementation is based on mainWidget 0152 * @return true of false 0153 */ 0154 bool hasSelectionWithFocus(); 0155 0156 /** 0157 * To know if the closure of the application is authorized 0158 * @return true if close is authorized else false 0159 */ 0160 bool queryClose() override; 0161 0162 /** 0163 * To know if the closure of the file is authorized 0164 * @return true if close is authorized else false 0165 */ 0166 bool queryFileClose(); 0167 0168 /** 0169 * Return the plugin number by index 0170 * @param iIndex the index of the plugin 0171 * @return the plugin pointer. Can be nullptr. Mustn't be deleted 0172 */ 0173 SKGInterfacePlugin* getPluginByIndex(int iIndex); 0174 0175 /** 0176 * Return the plugin number by name 0177 * @param iName the name of the plugin 0178 * @return the plugin pointer. Can be nullptr. Mustn't be deleted 0179 */ 0180 SKGInterfacePlugin* getPluginByName(const QString& iName); 0181 0182 /** 0183 * Get the label for normal message in status bar 0184 * @return the label 0185 */ 0186 QLabel* statusNormalMessage() const; 0187 0188 /** 0189 * Get the current splash screen. nullptr if the splash screen is closed. 0190 * @return the splash screen 0191 */ 0192 QSplashScreen* splashScreen() const; 0193 0194 /** 0195 * Set the main widget 0196 * @param iWidget the widget to display when all pages are closed 0197 */ 0198 void setMainWidget(QWidget* iWidget); 0199 0200 /** 0201 * Get the tab widget. 0202 * @return the tab widget 0203 */ 0204 SKGTabWidget* getTabWidget() const; 0205 0206 /** 0207 * Get the history item of the current page 0208 * @return the history item 0209 */ 0210 SKGTabPage::SKGPageHistoryItem currentPageHistoryItem() const; 0211 0212 /** 0213 * Get the index of the current page 0214 * @return index of the current page 0215 */ 0216 int currentPageIndex() const; 0217 0218 /** 0219 * Get the current page 0220 * @return the current page 0221 */ 0222 SKGTabPage* currentPage() const; 0223 0224 /** 0225 * Get a index of a page 0226 * @param iPage the page 0227 * @return the index (-1 if not found) 0228 */ 0229 int pageIndex(SKGTabPage* iPage) const; 0230 0231 /** 0232 * Get a page 0233 * @param iIndex an index 0234 * @return the page 0235 */ 0236 SKGTabPage* page(int iIndex) const; 0237 0238 /** 0239 * Get then number of pages 0240 * @return the number of pages 0241 */ 0242 int countPages() const; 0243 0244 /** 0245 * Register a global action 0246 * @param iIdentifier identifier of the action 0247 * @param iAction action pointer 0248 * @param iAddInCollection to add or not the action in the main panel collection 0249 * @param iListOfTable list of table where this action must be enabled (empty list means all) 0250 * You can also add only one item like this to set the list dynamically: 0251 * query:the sql condition on sqlite_master 0252 * @param iMinSelection the minimum number of selected item to enable the action 0253 * 0 : no need selection but need a page opened containing a table 0254 * -1 : no need selection and need a page opened (not containing a table) 0255 * -2 : no need selection and no need a page opened 0256 * @param iMaxSelection the maximum number of selected item to enable the action (-1 = infinite) 0257 * @param iRanking the ranking to sort actions in contextual menus 0258 * @param iRanking the ranking to sort actions in contextual menus 0259 * -1: automatic by creation order 0260 * 0: not in contextual menu 0261 * @param iSelectionMustHaveFocus the action will be activated only if the widget containing the selection has the focus 0262 * 0263 * Actions can be set in differents groups by changing hundred: 0264 * 0 to 99 is a group 0265 * 100 to 200 is another group 0266 */ 0267 void registerGlobalAction(const QString& iIdentifier, QAction* iAction, 0268 bool iAddInCollection = true, 0269 const QStringList& iListOfTable = QStringList(), 0270 int iMinSelection = -2, 0271 int iMaxSelection = -1, 0272 int iRanking = -1, 0273 bool iSelectionMustHaveFocus = false); 0274 0275 /** 0276 * Get a registered global action 0277 * @param iIdentifier identifier of the action 0278 * @param iWarnIfNotExist warn if the action does not exist 0279 * @return action pointer 0280 */ 0281 QPointer<QAction> getGlobalAction(const QString& iIdentifier, bool iWarnIfNotExist = true); 0282 0283 /** 0284 * Get a list of actions enable for a contextual menu 0285 * @param iTable the table 0286 * @return the list of actions 0287 */ 0288 QList<QPointer<QAction> > getActionsForContextualMenu(const QString& iTable); 0289 0290 /** 0291 * Get all registered global actions 0292 * @return actions 0293 */ 0294 QMap<QString, QPointer<QAction> > getGlobalActions() const; 0295 0296 /** 0297 * Get the tips of days 0298 * @return the tips of days 0299 */ 0300 QStringList getTipsOfDay() const; 0301 0302 /** 0303 * Get the tip of days 0304 * @return the tip of days 0305 */ 0306 QString getTipOfDay() const; 0307 0308 /** 0309 * Define if the document must be saved when closed 0310 * @param iSaveOnClose the save on close mode 0311 */ 0312 void setSaveOnClose(bool iSaveOnClose); 0313 0314 /** 0315 * Get all advice 0316 * @return the list of advice 0317 */ 0318 SKGAdviceList getAdvice() const; 0319 0320 public Q_SLOTS: 0321 /** 0322 * Display a message 0323 * @param iMessage the message 0324 * @param iType the type 0325 * @param iAction the associated action 0326 * @return the message widget 0327 */ 0328 KMessageWidget* displayMessage(const QString& iMessage, SKGDocument::MessageType iType = SKGDocument::Information, const QString& iAction = QString()); 0329 0330 /** 0331 * Display an error message 0332 * @param iMessage the error message. If the message is "", the data of the sender will be used 0333 * @return the message widget 0334 */ 0335 KMessageWidget* displayErrorMessage(const QString& iMessage = QString()); 0336 0337 /** 0338 * This function is called when the application is launched again with new arguments 0339 * @param iArgument the arguments 0340 * @return the rest of arguments to treat 0341 */ 0342 QStringList processArguments(const QStringList& iArgument); 0343 0344 /** 0345 * Set the current page 0346 * @param iIndex the current page 0347 */ 0348 void setCurrentPage(int iIndex); 0349 0350 /** 0351 * Set the context item visibility 0352 * @param iPage index of the page in the pages chooser 0353 * @param iVisibility the visibility 0354 */ 0355 void setContextVisibility(int iPage, bool iVisibility); 0356 0357 /** 0358 * Set the context item visibility 0359 * @param iItem item in the pages chooser 0360 * @param iVisibility the visibility 0361 */ 0362 void setContextVisibility(QListWidgetItem* iItem, bool iVisibility); 0363 0364 /** 0365 * Open a plugin in a page described in sender()->data() 0366 * @return true if the url has been opened 0367 */ 0368 bool openPage(); 0369 0370 /** 0371 * Open a plugin in a page 0372 * @param iUrl the url like this "skg://plugin_name/?param1=value1¶m2=value2&…" to open a special page 0373 * or "skg://action" to trigger an action 0374 * or "https://…" to open a web page 0375 * @param iNewPage to open a new page or not 0376 * @return true if the url has been opened 0377 */ 0378 bool openPage(const QUrl& iUrl, bool iNewPage = true); 0379 0380 /** 0381 * Open a plugin in a page 0382 * @param iUrl the url like this "skg://plugin_name/?param1=value1¶m2=value2&…" to open a special page 0383 * or "skg://action/?param1=value1¶m2=value2&…" to trigger an action, parameters can be found as property on the sender QAction 0384 * or "https://…" to open a web page 0385 * if empty then url will be get from sender()->data() 0386 * @param iNewPage to open a new page or not 0387 * @return true if the url has been opened 0388 */ 0389 bool openPage(const QString& iUrl, bool iNewPage = true); 0390 0391 /** 0392 * Open a plugin in a page 0393 * @param iPage index of the page in the pages chooser 0394 * @param iNewPage to open a new page or not 0395 * @return the opened tab 0396 */ 0397 SKGTabPage* openPage(int iPage, bool iNewPage = true); 0398 0399 /** 0400 * Open a plugin in a page 0401 * @param plugin the plugin 0402 * @param index index of the tab to replace or -1 to add a new one 0403 * @param parameters parameters of the plugin 0404 * @param title title of the page 0405 * @param iID id of the new page 0406 * @param iSetCurrent to set the new page as the current one 0407 * @return the opened tab 0408 */ 0409 SKGTabPage* openPage(SKGInterfacePlugin* plugin, int index = -1, const QString& parameters = QString(), const QString& title = QString(), const QString& iID = QString(), bool iSetCurrent = true); 0410 0411 /** 0412 * Switch the pin state of the page 0413 * @param iWidget the page to remove (nullptr means current one) 0414 */ 0415 void switchPinPage(QWidget* iWidget); 0416 0417 /** 0418 * Close a page 0419 * @param iIndex the page to remove (-1 means current one) 0420 */ 0421 void closePageByIndex(int iIndex = -1); 0422 0423 /** 0424 * Close a page 0425 * @param iWidget the page to remove (nullptr means current one) 0426 * @param iForce to close pinned pages too 0427 */ 0428 void closePage(QWidget* iWidget, bool iForce = false); 0429 0430 /** 0431 * Close the current page 0432 */ 0433 void closeCurrentPage(); 0434 0435 /** 0436 * Close all other pages 0437 * @param iWidget the page to keep (nullptr means current one) 0438 */ 0439 void closeAllOtherPages(QWidget* iWidget); 0440 0441 /** 0442 * Close all pages 0443 * @param iForce to close pinned pages too 0444 */ 0445 void closeAllPages(bool iForce = false); 0446 0447 /** 0448 * Force the refresh of the object. 0449 */ 0450 void refresh(); 0451 0452 /** 0453 * Send notifications corresponding to the transaction. 0454 * @param iTransaction the transaction identifier 0455 */ 0456 void notify(int iTransaction = 0); 0457 0458 /** 0459 * Open settings panel on dedicated page. 0460 * @param iPluginName the name of the plugin (pluginInterface->objectName()) 0461 */ 0462 void optionsPreferences(const QString& iPluginName = QString()); 0463 0464 /** 0465 * Unregister a global action 0466 * @param iAction action pointer 0467 */ 0468 void unRegisterGlobalAction(QObject* iAction); 0469 0470 Q_SIGNALS: 0471 /** 0472 * This signal is sent when a new page is opened. 0473 */ 0474 void pageOpened(); 0475 0476 /** 0477 * This signal is sent when a new page is opened. 0478 */ 0479 void pageClosed(); 0480 0481 /** 0482 * This signal is sent when the current page changes. 0483 */ 0484 void currentPageChanged(); 0485 0486 /** 0487 * This signal is sent when settings changes. 0488 */ 0489 void settingsChanged(); 0490 0491 /** 0492 * This signal is sent when selection changes. 0493 */ 0494 void selectionChanged(); 0495 0496 protected: 0497 /** 0498 * event 0499 * @param e event 0500 */ 0501 void changeEvent(QEvent* e) override; 0502 /** 0503 * Event filtering 0504 * @param iObject object 0505 * @param iEvent event 0506 * @return In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false. 0507 */ 0508 bool eventFilter(QObject* iObject, QEvent* iEvent) override; 0509 0510 private Q_SLOTS: 0511 KMessageWidget* getMessageWidget(const QString& iMessage, SKGDocument::MessageType iType, const QString& iAction, bool iAutoKillOnClick); 0512 void showMenu(QPoint iPos); 0513 0514 void onSettingsChanged(); 0515 void onCancelCurrentAction(); 0516 void onQuitAction(); 0517 void addTab(); 0518 void onBeforeOpenContext(); 0519 void onOpenContext(); 0520 void saveDefaultState(); 0521 void resetDefaultState(); 0522 void overwriteBookmarkState(); 0523 void enableEditor(); 0524 void onPrevious(); 0525 void onNext(); 0526 void onReopenLastClosed(); 0527 void onFullScreen(); 0528 void onShowPreviousMenu(); 0529 void onShowNextMenu(); 0530 void onZoomChanged(); 0531 void onShowMenuBar(); 0532 void onShowButtonMenu(); 0533 void onHideContextItem(); 0534 void onShowAllContextItems(); 0535 void onLockDocks(); 0536 void onUnlockDocks(); 0537 void onConfigureNotifications(); 0538 void onClearMessages(); 0539 void onMigrateToSQLCipher(); 0540 private: 0541 Q_DISABLE_COPY(SKGMainPanel) 0542 void setupActions(); 0543 0544 SKGMainPanelPrivate* const d; 0545 }; 0546 0547 #endif // SKGMAINPANEL_H