File indexing completed on 2024-04-28 05:06:07
0001 /* 0002 SPDX-FileCopyrightText: 2000-2001 Michael Edwardes <mte@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2017, 2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0004 SPDX-FileCopyrightText: 2021 Dawid Wróbel <me@dawidwrobel.com> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef KMYMONEY_H 0008 #define KMYMONEY_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 #include <QList> 0014 #include <QByteArray> 0015 #include <QFileDialog> 0016 #include <QUrl> 0017 0018 // ---------------------------------------------------------------------------- 0019 // KDE Includes 0020 0021 #include <KXmlGuiWindow> 0022 0023 // ---------------------------------------------------------------------------- 0024 // Project Includes 0025 0026 #include <imymoneyprocessingcalendar.h> 0027 0028 #include "kmymoneyutils.h" 0029 0030 #include "mymoneyaccount.h" 0031 #include "mymoney/onlinejob.h" 0032 #include "onlinejobtyped.h" 0033 #include "mymoneykeyvaluecontainer.h" 0034 #include "mymoneymoney.h" 0035 #include "mymoneysplit.h" 0036 #include "mymoneytransaction.h" 0037 #include "mymoneyenums.h" 0038 #include "viewenums.h" 0039 0040 class QResizeEvent; 0041 class MyMoneyObject; 0042 class MyMoneyInstitution; 0043 class MyMoneyAccount; 0044 class MyMoneySecurity; 0045 class MyMoneyPayee; 0046 class MyMoneyPrice; 0047 class MyMoneyTag; 0048 class MyMoneySplit; 0049 class MyMoneyTransaction; 0050 class WebConnect; 0051 class creditTransfer; 0052 class IMyMoneyOperationsFormat; 0053 class SelectedObjects; 0054 0055 template <class T> class onlineJobTyped; 0056 typedef void (*KMyMoneyAppCallback)(int, int, const QString &); 0057 0058 namespace eKMyMoney { 0059 enum class FileAction; 0060 } 0061 namespace eDialogs { 0062 enum class ScheduleResultCode; 0063 } 0064 namespace eMenu { 0065 enum class Action; 0066 enum class Menu; 0067 } 0068 0069 /*! \mainpage KMyMoney Main Page for API documentation. 0070 * 0071 * \section intro Introduction 0072 * 0073 * This is the API documentation for KMyMoney. It should be used as a reference 0074 * for KMyMoney developers and users who wish to see how KMyMoney works. This 0075 * documentation will be kept up-to-date as development progresses and should be 0076 * read for new features that have been developed in KMyMoney. 0077 */ 0078 0079 /** 0080 * The base class for KMyMoney application windows. It sets up the main 0081 * window and reads the config file as well as providing a menubar, toolbar 0082 * and statusbar. 0083 * 0084 * @see KMyMoneyView 0085 * 0086 * @author Michael Edwardes 2000-2001 0087 * @author Thomas Baumgart 2006-2008 0088 * 0089 * @short Main application class. 0090 */ 0091 class KMyMoneyApp : public KXmlGuiWindow, public IMyMoneyProcessingCalendar 0092 { 0093 Q_OBJECT 0094 0095 private Q_SLOTS: 0096 /** 0097 * Add a context menu to the list used by KMessageBox::informationList to display the consistency check results. 0098 */ 0099 void slotInstallConsistencyCheckContextMenu(); 0100 0101 /** 0102 * Handle the context menu of the list used by KMessageBox::informationList to display the consistency check results. 0103 */ 0104 void slotShowContextMenuForConsistencyCheck(const QPoint &); 0105 0106 void slotSelectionChanged(const SelectedObjects& selection); 0107 0108 void slotAddSharedAction(eMenu::Action action, QAction* defaultAction); 0109 0110 protected Q_SLOTS: 0111 /** 0112 * This slot is intended to be used as part of auto saving. This is used when the 0113 * QTimer emits the timeout signal and simply checks that the file is dirty (has 0114 * received modifications to its contents), and call the appropriate method to 0115 * save the file. Furthermore, re-starts the timer (possibly not needed). 0116 * @author mvillarino 2005 0117 * @see KMyMoneyApp::slotDataChanged() 0118 */ 0119 void slotAutoSave(); 0120 0121 /** 0122 * This slot re-enables all message for which the "Don't show again" 0123 * option had been selected. 0124 */ 0125 void slotEnableMessages(); 0126 0127 /** 0128 * This slot navigates to KMyMoney online community. 0129 */ 0130 void slotGetOnlineHelp(); 0131 0132 /** 0133 * This slot navigates to KMyMoney release news page. 0134 */ 0135 void slotWhatsNew(); 0136 0137 /** 0138 * This slot navigates to KMyMoney website. 0139 */ 0140 void slotVisitWebsite(); 0141 0142 /** 0143 * Called to run performance test. 0144 */ 0145 void slotPerformanceTest(); 0146 0147 /** 0148 * Called to generate the sql to create kmymoney database tables etc. 0149 */ 0150 void slotGenerateSql(); 0151 0152 #ifdef KMM_DEBUG 0153 /** 0154 * Called when the user asks for file information. 0155 */ 0156 void slotFileFileInfo(); 0157 0158 /** 0159 * Debugging only: turn on/off traces 0160 */ 0161 void slotToggleTraces(); 0162 #endif 0163 0164 /** 0165 * Debugging only: turn on/off timers 0166 */ 0167 void slotToggleTimers(); 0168 0169 /** 0170 * Called when the user asks for the personal information. 0171 */ 0172 void slotFileViewPersonal(); 0173 0174 void slotLoadAccountTemplates(); 0175 void slotSaveAccountTemplates(); 0176 0177 /** 0178 * Open up the application wide settings dialog. 0179 * 0180 * @see KSettingsDlg 0181 */ 0182 void slotSettings(); 0183 0184 /** 0185 * Called to show credits window. 0186 */ 0187 void slotShowCredits(); 0188 0189 /** 0190 * Called when the user wishes to backup the current file 0191 */ 0192 void slotBackupFile(); 0193 0194 /** 0195 * Perform mount operation before making a backup of the current file 0196 */ 0197 void slotBackupMount(); 0198 0199 /** 0200 * Perform the backup write operation 0201 */ 0202 bool slotBackupWriteFile(); 0203 0204 /** 0205 * Perform unmount operation after making a backup of the current file 0206 */ 0207 void slotBackupUnmount(); 0208 0209 /** 0210 * Finish backup of the current file 0211 */ 0212 void slotBackupFinish(); 0213 0214 /** 0215 * Handle events on making a backup of the current file 0216 */ 0217 void slotBackupHandleEvents(); 0218 0219 /** 0220 * Call this slot, if any configuration parameter has changed 0221 */ 0222 void slotUpdateConfiguration(const QString &dialogName); 0223 0224 /** 0225 * This slot is used to start new features during the development cycle 0226 */ 0227 void slotNewFeature(); 0228 0229 /** 0230 * This slot starts the tab order editor on the current widget 0231 * if it is supported. 0232 */ 0233 void slotEditTabOrder(); 0234 0235 /** 0236 * This slot triggers an update of all views and restarts 0237 * a single shot timer to call itself again at beginning of 0238 * the next day. 0239 */ 0240 void slotDateChanged(); 0241 0242 /** 0243 * This slot will be called when the engine data changed 0244 * and the application object needs to update its state. 0245 */ 0246 void slotDataChanged(); 0247 0248 /** 0249 * This slot collects information for a new scheduled transaction 0250 * based on transaction @a t and @a occurrence and saves it in the engine. 0251 */ 0252 void slotScheduleNew(const MyMoneyTransaction& t, eMyMoney::Schedule::Occurrence occurrence = eMyMoney::Schedule::Occurrence::Monthly); 0253 0254 void slotStatusProgressDone(); 0255 0256 void slotCheckSchedules(); 0257 0258 void slotDeleteTransactions(); 0259 void slotDuplicateTransactions(); 0260 void slotDisplayTransactionDetails(); 0261 void slotCopySplits(); 0262 void slotMarkTransactions(); 0263 void slotMoveTransactionTo(); 0264 void slotMoveToToday(); 0265 void slotMatchTransaction(); 0266 void slotAcceptTransaction(); 0267 void slotCreateScheduledTransaction(); 0268 void slotStartReconciliation(); 0269 void slotReportReconciliation(); 0270 void slotEnterOverdueSchedules(); 0271 void slotFindTransaction(); 0272 void slotCloseAccount(); 0273 void slotReopenAccount(); 0274 0275 void slotExecuteAction(); 0276 void slotExecuteActionWithData(); 0277 0278 public: 0279 /** 0280 * This method checks if there is at least one asset or liability account 0281 * in the current storage object. If not, it starts the new account wizard. 0282 */ 0283 void createInitialAccount(); 0284 0285 /** 0286 * This method returns the last URL used or an empty URL 0287 * depending on the option setting if the last file should 0288 * be opened during startup or the open file dialog should 0289 * be displayed. 0290 * 0291 * @return URL of last opened file or empty if the program 0292 * should start with the open file dialog 0293 */ 0294 QUrl lastOpenedURL(); 0295 0296 /** 0297 * constructor of KMyMoneyApp, calls all init functions to create the application. 0298 */ 0299 explicit KMyMoneyApp(QWidget* parent = 0); 0300 0301 /** 0302 * Destructor 0303 */ 0304 ~KMyMoneyApp(); 0305 0306 static void progressCallback(int current, int total, const QString&); 0307 0308 void writeLastUsedDir(const QString& directory); 0309 QString readLastUsedDir() const; 0310 void writeLastUsedFile(const QString& fileName); 0311 QString readLastUsedFile() const; 0312 0313 /** 0314 * Returns whether there is an importer available that can handle this file 0315 */ 0316 bool isImportableFile(const QUrl &url); 0317 0318 /** 0319 * This method returns a list of all 'other' dcop registered kmymoney processes. 0320 * It's a subset of the return of DCOPclient()->registeredApplications(). 0321 * 0322 * @retval QStringList of process ids 0323 */ 0324 QList<QString> instanceList() const; 0325 0326 #ifdef KMM_DEBUG 0327 /** 0328 * Dump a list of the names of all defined KActions to stdout. 0329 */ 0330 void dumpActions() const; 0331 #endif 0332 0333 void createAccount(MyMoneyAccount& newAccount, MyMoneyAccount& parentAccount, MyMoneyAccount& brokerageAccount, MyMoneyMoney openingBal); 0334 0335 QString filename() const; 0336 QUrl filenameURL() const; 0337 void writeFilenameURL(const QUrl &url); 0338 0339 void addToRecentFiles(const QUrl &url); 0340 QTimer* autosaveTimer(); 0341 0342 /** 0343 * Checks if the file with the @a url already exists. If so, 0344 * the user is asked if he/she wants to override the file. 0345 * If the user's answer is negative, @p false will be returned. 0346 * @p true will be returned in all other cases. 0347 */ 0348 bool okToWriteFile(const QUrl &url); 0349 0350 /** 0351 * Return pointer to the WebConnect object 0352 */ 0353 WebConnect* webConnect() const; 0354 0355 /** 0356 * Call this to find out if the currently open file is a sql database 0357 * 0358 * @retval true file is database 0359 * @retval false file is serial 0360 */ 0361 bool isDatabase(); 0362 0363 /** 0364 * Call this to find out if the currently open file is native KMM 0365 * 0366 * @retval true file is native 0367 * @retval false file is foreign 0368 */ 0369 bool isNativeFile(); 0370 0371 bool fileOpen() const; 0372 0373 KMyMoneyAppCallback progressCallback(); 0374 0375 void consistencyCheck(bool alwaysDisplayResult); 0376 0377 protected: 0378 /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration 0379 * file 0380 */ 0381 void saveOptions(); 0382 0383 /** 0384 * Creates the interfaces necessary for the plugins to work. Therefore, 0385 * this method must be called prior to loadPlugins(). 0386 */ 0387 void createInterfaces(); 0388 0389 /** 0390 * read general options again and initialize all variables like the recent file list 0391 */ 0392 void readOptions(); 0393 0394 /** 0395 * Gets pointers for menus preset by KXMLGUIFactory 0396 * @return pointers for menus 0397 */ 0398 QHash<eMenu::Menu, QMenu *> initMenus(); 0399 0400 /** 0401 * Initializes QActions (names, object names, icons, some connections, shortcuts) 0402 * @return pointers for actions 0403 */ 0404 QHash<eMenu::Action, QAction *> initActions(); 0405 0406 /** initializes the dynamic menus (account selectors) */ 0407 void initDynamicMenus(); 0408 0409 /** 0410 * sets up the statusbar for the main window by initializing a statuslabel. 0411 */ 0412 void initStatusBar(); 0413 0414 /** sets up the application icons */ 0415 void initIcons(); 0416 0417 /** queryClose is called by KMainWindow on each closeEvent of a window. Against the 0418 * default implementation (only returns true), this calls saveModified() on the document object to ask if the document shall 0419 * be saved if Modified; on cancel the closeEvent is rejected. 0420 * The settings are saved using saveOptions() if we are about to close. 0421 * @see KMainWindow#queryClose 0422 * @see QWidget#closeEvent 0423 */ 0424 bool queryClose() final override; 0425 0426 #ifdef KMM_DEBUG 0427 void resizeEvent(QResizeEvent*) final override; 0428 #endif 0429 0430 /** 0431 * This method preloads the holidays for the duration of the default forecast period 0432 */ 0433 void preloadHolidays(); 0434 0435 bool event(QEvent * event) override; 0436 0437 public Q_SLOTS: 0438 0439 void slotFileInfoDialog(); 0440 0441 bool isFileOpenedInAnotherInstance(const QUrl &url); 0442 0443 void slotFileConsistencyCheck(); 0444 0445 /** 0446 * fires up the price table editor 0447 */ 0448 void slotPriceDialog(); 0449 0450 /** 0451 * fires up the currency table editor 0452 */ 0453 void slotCurrencyDialog(); 0454 0455 /** 0456 * dummy method needed just for initialization 0457 */ 0458 void slotShowTransactionDetail(); 0459 0460 /** 0461 * Toggles the hide reconciled transactions setting 0462 */ 0463 void slotHideReconciledTransactions(); 0464 0465 /** 0466 * Toggles the hide unused categories setting 0467 */ 0468 void slotHideUnusedCategories(); 0469 0470 /** 0471 * Toggles the show all accounts setting 0472 */ 0473 void slotShowAllAccounts(); 0474 0475 0476 /** 0477 * changes the statusbar contents for the standard label permanently, 0478 * used to indicate current actions. Returns the previous value for 0479 * 'stacked' usage. 0480 * 0481 * @param text the text that is displayed in the statusbar 0482 */ 0483 QString slotStatusMsg(const QString &text); 0484 0485 /** 0486 * This method changes the progress bar in the status line according 0487 * to the parameters @p current and @p total. The following special 0488 * cases exist: 0489 * 0490 * - current = -1 and total = -1 will reset the progress bar 0491 * - current = ?? and total != 0 will setup the 100% mark to @p total 0492 * - current = xx and total == 0 will set the percentage 0493 * 0494 * @param current the current value with respect to the initialised 0495 * 100% mark 0496 * @param total the total value (100%) 0497 */ 0498 void slotStatusProgressBar(int current, int total = 0); 0499 0500 /** 0501 * Called to update stock and currency prices from the user menu 0502 */ 0503 void slotEquityPriceUpdate(); 0504 0505 /** 0506 * Create a new investment in a given @p parent investment account 0507 */ 0508 void slotInvestmentNew(MyMoneyAccount& account, const MyMoneyAccount& parent); 0509 0510 /** 0511 * Brings up the new category editor and saves the information. 0512 * The dialog will be preset with the name and parent account. 0513 * 0514 * @param account reference of category to be created. The @p name member 0515 * should be filled by the caller. The object will be filled 0516 * with additional information during the creation process 0517 * esp. the @p id member. 0518 * @param parent reference to parent account (defaults to none) 0519 */ 0520 void slotCategoryNew(MyMoneyAccount& account, const MyMoneyAccount& parent); 0521 void slotCategoryNew(MyMoneyAccount& account); 0522 0523 /** 0524 */ 0525 void slotPayeeNew(const QString& newnameBase, QString& id); 0526 0527 /** 0528 * This slot fires up the KCalc application 0529 */ 0530 void slotToolsStartKCalc(); 0531 0532 /** 0533 * Brings up the new account wizard and saves the information. 0534 */ 0535 void slotAccountNew(MyMoneyAccount&); 0536 0537 void webConnect(const QString& sourceUrl, const QByteArray &asn_id); 0538 void webConnectUrl(const QUrl url); 0539 0540 private: 0541 /** 0542 * This method sets the holidayRegion for use by the processing calendar. 0543 */ 0544 void setHolidayRegion(const QString& holidayRegion); 0545 0546 /** 0547 * Load the status bar with the 'ready' message. This is hold in a single 0548 * place, so that is consistent with isReady(). 0549 */ 0550 void ready(); 0551 0552 /** 0553 * Check if the status bar contains the 'ready' message. The return 0554 * value is used e.g. to detect if a quit operation is allowed or not. 0555 * 0556 * @retval true application is idle 0557 * @retval false application is active working on a longer operation 0558 */ 0559 bool isReady(); 0560 0561 /** 0562 * Re-implemented from IMyMoneyProcessingCalendar 0563 */ 0564 bool isProcessingDate(const QDate& date) const final override; 0565 0566 Q_SIGNALS: 0567 /** 0568 * This signal is emitted when a new file is loaded. In the case file 0569 * is closed, this signal is also emitted with an empty url. 0570 */ 0571 void fileLoaded(const QUrl &url); 0572 0573 /** 0574 * This signal is emitted if a specific transaction with @a transactionId in account 0575 * @a accountId is selected 0576 */ 0577 void transactionSelected(const QString accountId, const QString& transactionId); 0578 0579 /** 0580 * This signal is sent out, when the user presses Ctrl+A or activates 0581 * the Select all transactions action. 0582 */ 0583 void selectAllTransactions(); 0584 0585 /** 0586 * This signal is emitted when a new institution has been selected by 0587 * the GUI. If no institution is selected or the selection is removed, 0588 * @a institution is identical to MyMoneyInstitution(). This signal is used 0589 * by plugins to get information about changes. 0590 */ 0591 void institutionSelected(const MyMoneyInstitution& institution); 0592 0593 /** 0594 * This signal is emitted when a new schedule has been selected by 0595 * the GUI. If no schedule is selected or the selection is removed, 0596 * @a schedule is identical to MyMoneySchedule(). This signal is used 0597 * by plugins to get information about changes. 0598 */ 0599 void scheduleSelected(const MyMoneySchedule& schedule); 0600 0601 void startMatchTransaction(const MyMoneyTransaction& t); 0602 void cancelMatchTransaction(); 0603 0604 void kmmFilePlugin(unsigned int); 0605 0606 public: 0607 0608 bool isActionToggled(const eMenu::Action _a); 0609 static const QHash<eMenu::Action, QString> s_Actions; 0610 0611 private: 0612 /// \internal d-pointer class. 0613 class Private; 0614 /* 0615 * Actually, one should write "Private * const d" but that confuses the KIDL 0616 * compiler in this context. It complains about the const keyword. So we leave 0617 * it out here 0618 */ 0619 /// \internal d-pointer instance. 0620 Private* d; 0621 0622 public Q_SLOTS: 0623 bool slotFileNew(); 0624 void slotFileOpen(); 0625 bool slotFileOpenRecent(const QUrl &url); 0626 bool slotFileSave(); 0627 bool slotFileSaveAs(); 0628 bool slotFileClose(); 0629 bool slotCloseViewOrFile(); 0630 /** 0631 * closes all open windows by calling close() on each memberList item 0632 * until the list is empty, then quits the application. 0633 * If queryClose() returns false because the user canceled the 0634 * saveModified() dialog, the closing breaks. 0635 */ 0636 void slotFileQuit(); 0637 }; 0638 0639 extern KMyMoneyApp *kmymoney; 0640 0641 class KMStatus 0642 { 0643 public: 0644 explicit KMStatus(const QString &text); 0645 ~KMStatus(); 0646 private: 0647 QString m_prevText; 0648 }; 0649 0650 #define KMSTATUS(msg) KMStatus _thisStatus(msg) 0651 0652 #endif // KMYMONEY_H