File indexing completed on 2024-05-12 16:43:49

0001 /*
0002     SPDX-FileCopyrightText: 2000-2001 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004 Thomas Baumgart <ipwizard@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2017, 2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMYMONEYVIEW_H
0009 #define KMYMONEYVIEW_H
0010 
0011 #include <config-kmymoney.h>
0012 
0013 // ----------------------------------------------------------------------------
0014 // QT Includes
0015 
0016 #include <QFileDevice>
0017 
0018 // ----------------------------------------------------------------------------
0019 // KDE Includes
0020 
0021 #include <KPageWidget>
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 #include "selectedtransactions.h"
0026 
0027 #ifdef ENABLE_ACTIVITIES
0028 namespace KActivities
0029 {
0030 class ResourceInstance;
0031 }
0032 #endif
0033 
0034 namespace eAccountsModel {
0035 enum class Column;
0036 }
0037 namespace eMenu {
0038 enum class Action;
0039 }
0040 namespace KMyMoneyPlugin {
0041 class OnlinePlugin;
0042 }
0043 namespace eDialogs {
0044 enum class ScheduleResultCode;
0045 }
0046 namespace eView {
0047 enum class Intent;
0048 }
0049 namespace eView {
0050 enum class Action;
0051 }
0052 namespace Icons {
0053 enum class Icon;
0054 }
0055 
0056 class KMyMoneyApp;
0057 class KHomeView;
0058 class KAccountsView;
0059 class KCategoriesView;
0060 class KInstitutionsView;
0061 class KPayeesView;
0062 class KTagsView;
0063 class KBudgetView;
0064 class KScheduledView;
0065 class KGlobalLedgerView;
0066 class IMyMoneyOperationsFormat;
0067 class MyMoneyTransaction;
0068 class KInvestmentView;
0069 class KReportsView;
0070 class SimpleLedgerView;
0071 class MyMoneySchedule;
0072 class MyMoneySecurity;
0073 class MyMoneyReport;
0074 class TransactionEditor;
0075 class KOnlineJobOutbox;
0076 class KMyMoneyTitleLabel;
0077 class MyMoneyAccount;
0078 class MyMoneyMoney;
0079 class MyMoneyObject;
0080 class QLabel;
0081 class KMyMoneyViewBase;
0082 
0083 /**
0084   * This class represents the view of the MyMoneyFile which contains
0085   * Banks/Accounts/Transactions, Recurring transactions (or Bills & Deposits)
0086   * and scripts (yet to be implemented).  Each different aspect of the file
0087   * is represented by a tab within the view.
0088   *
0089   * @author Michael Edwardes 2001 Copyright 2000-2001
0090   *
0091   * @short Handles the view of the MyMoneyFile.
0092   */
0093 enum class View;
0094 class KMyMoneyView : public KPageWidget
0095 {
0096     Q_OBJECT
0097 private:
0098 
0099     KPageWidgetModel* m_model;
0100 
0101     QHash<View, KPageWidgetItem*> viewFrames;
0102     QHash<View, KMyMoneyViewBase*> viewBases;
0103 
0104     KMyMoneyTitleLabel* m_header;
0105 
0106     void viewAccountList(const QString& selectAccount); // Show the accounts view
0107 
0108     void createSchedule(MyMoneySchedule s, MyMoneyAccount& a);
0109 
0110 public:
0111     /**
0112       * The constructor for KMyMoneyView. Just creates all the tabs for the
0113       * different aspects of the MyMoneyFile.
0114       */
0115     KMyMoneyView();
0116 
0117     /**
0118       * Destructor
0119       */
0120     ~KMyMoneyView();
0121 
0122     /**
0123       * This method enables the state of all views (except home view) according
0124       * to an open file.
0125       */
0126     void enableViewsIfFileOpen(bool fileOpen);
0127     void switchToHomeView();
0128 
0129     void addWidget(QWidget* w);
0130 
0131     void showPageAndFocus(View idView);
0132     void showPage(View idView);
0133 
0134     /**
0135       * check if the current view allows to print something
0136       *
0137       * @retval true Yes, view allows to print
0138       * @retval false No, view cannot print
0139       */
0140     bool canPrint();
0141 
0142     void finishReconciliation(const MyMoneyAccount& account);
0143 
0144     void showTitleBar(bool show);
0145 
0146     /**
0147       * This method changes the view type according to the settings.
0148       */
0149     void updateViewType();
0150 
0151     void slotAccountTreeViewChanged(const eAccountsModel::Column column, const bool show);
0152 
0153     void setOnlinePlugins(QMap<QString, KMyMoneyPlugin::OnlinePlugin*>& plugins);
0154 
0155     // TODO: remove that function
0156     /**
0157      * ugly proxy function
0158      */
0159     eDialogs::ScheduleResultCode enterSchedule(MyMoneySchedule& schedule, bool autoEnter, bool extendedKeys);
0160 
0161     void addView(KMyMoneyViewBase* view, const QString& name, View idView, Icons::Icon icon);
0162     void removeView(View idView);
0163 
0164     /**
0165      * @brief actionsToBeConnected are actions that need ActionCollection
0166      * which is available in KMyMoneyApp
0167      * @return QHash of action id and QAction itself
0168      */
0169     QHash<eMenu::Action, QAction *> actionsToBeConnected();
0170 
0171 protected:
0172     /**
0173       * Overwritten because KMyMoney has it's custom header.
0174       */
0175     bool showPageHeader() const final override;
0176 
0177 
0178 public Q_SLOTS:
0179     /**
0180       * This slot writes information about the page passed as argument @a current
0181       * in the kmymoney.rc file so that it can be selected automatically when
0182       * the application is started again.
0183       *
0184       * @param current QModelIndex of the current page item
0185       * @param previous QModelIndex of the previous page item
0186       */
0187     void slotCurrentPageChanged(const QModelIndex current, const QModelIndex previous);
0188 
0189     /**
0190       * Brings up a dialog to change the list(s) settings and saves them into the
0191       * class KMyMoneySettings (a singleton).
0192       *
0193       * @see KListSettingsDlg
0194       * Refreshes all views. Used e.g. after settings have been changed or
0195       * data has been loaded from external sources (QIF import).
0196       **/
0197     void slotRefreshViews();
0198 
0199     /**
0200       * Called, whenever the payees view should pop up and a specific
0201       * transaction in an account should be shown.
0202       *
0203       * @param payeeId The ID of the payee to be shown
0204       * @param accountId The ID of the account to be shown
0205       * @param transactionId The ID of the transaction to be selected
0206       */
0207     void slotPayeeSelected(const QString& payeeId, const QString& accountId, const QString& transactionId);
0208 
0209     /**
0210       * Called, whenever the tags view should pop up and a specific
0211       * transaction in an account should be shown.
0212       *
0213       * @param tagId The ID of the tag to be shown
0214       * @param accountId The ID of the account to be shown
0215       * @param transactionId The ID of the transaction to be selected
0216       */
0217     void slotTagSelected(const QString& tagId, const QString& accountId, const QString& transactionId);
0218 
0219     /**
0220       * This slot prints the current view.
0221       */
0222     void slotPrintView();
0223 
0224     /**
0225       * Called when the user changes the detail
0226       * setting of the transaction register
0227       *
0228       * @param detailed if true, the register is shown with all details
0229       */
0230     void slotShowTransactionDetail(bool detailed);
0231 
0232     /**
0233      * Informs respective views about selected object, so they can
0234      * update action states and current object.
0235      * @param obj Account, Category, Investment, Stock, Institution
0236      */
0237     void slotObjectSelected(const MyMoneyObject& obj);
0238 
0239     void slotSelectByObject(const MyMoneyObject& obj, eView::Intent intent);
0240     void slotSelectByVariant(const QVariantList& variant, eView::Intent intent);
0241     void slotCustomActionRequested(View view, eView::Action action);
0242 
0243     void slotFileOpened();
0244     void slotFileClosed();
0245 
0246 private Q_SLOTS:
0247     /**
0248       * This slots switches the view to the specific page
0249       */
0250     void slotShowHomePage();
0251     void slotShowInstitutionsPage();
0252     void slotShowAccountsPage();
0253     void slotShowSchedulesPage();
0254     void slotShowCategoriesPage();
0255     void slotShowTagsPage();
0256     void slotShowPayeesPage();
0257     void slotShowLedgersPage();
0258     void slotShowInvestmentsPage();
0259     void slotShowReportsPage();
0260     void slotShowBudgetPage();
0261     void slotShowForecastPage();
0262     void slotShowOutboxPage();
0263     void switchToDefaultView();
0264 
0265     /**
0266      * Opens object in ledgers or edits in case of institution
0267      * @param obj Account, Category, Investment, Stock, Institution
0268      */
0269     void slotOpenObjectRequested(const MyMoneyObject& obj);
0270 
0271     /**
0272      * Opens context menu based on objects's type
0273      * @param obj Account, Category, Investment, Stock, Institution
0274      */
0275     void slotContextMenuRequested(const MyMoneyObject& obj);
0276 
0277 private:
0278 
0279     /**
0280       * Internal method used by slotAccountNew() and slotAccountCategory().
0281       */
0282     void accountNew(const bool createCategory);
0283 
0284     void resetViewSelection();
0285 
0286 Q_SIGNALS:
0287     /**
0288      * This signal is emitted whenever a view is selected.
0289      * The parameter @p view is identified as one of KMyMoneyView::viewID.
0290      */
0291     void viewActivated(View view);
0292 
0293     void accountSelectedForContextMenu(const MyMoneyAccount& acc);
0294 
0295     void viewStateChanged(bool enabled);
0296     /**
0297       * This signal is emitted to inform the kmmFile plugin when various file actions
0298       * occur. The Action parameter distinguishes between them.
0299       */
0300     void kmmFilePlugin(unsigned int action);
0301 
0302     /**
0303      * @brief proxy signal
0304      */
0305     void statusMsg(const QString& txt);
0306 
0307     /**
0308      * @brief proxy signal
0309      */
0310     void statusProgress(int cnt, int base);
0311 
0312     void accountReconciled(const MyMoneyAccount& account, const QDate& date, const MyMoneyMoney& startingBalance, const MyMoneyMoney& endingBalance, const QList<QPair<MyMoneyTransaction, MyMoneySplit> >& transactionList);
0313 
0314     /**
0315       * This signal is emitted when a transaction/list of transactions has been selected by
0316       * the GUI. If no transaction is selected or the selection is removed,
0317       * @p transactions is identical to an empty QList. This signal is used
0318       * by plugins to get information about changes.
0319       */
0320     void transactionsSelected(const KMyMoneyRegister::SelectedTransactions& transactions);
0321 
0322     /**
0323       * This signal is emitted when a new account has been selected by
0324       * the GUI. If no account is selected or the selection is removed,
0325       * @a account is identical to MyMoneyAccount(). This signal is used
0326       * by plugins to get information about changes.
0327       */
0328     void accountSelected(const MyMoneyAccount& account);
0329 };
0330 
0331 #endif