File indexing completed on 2024-04-28 05:50:07
0001 /* 0002 * SPDX-License-Identifier: GPL-3.0-or-later 0003 * SPDX-FileCopyrightText: 2021 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> 0004 */ 0005 #ifndef APP_VMS_H 0006 #define APP_VMS_H 0007 0008 #include "../model/accounts.h" 0009 #include "../model/password.h" 0010 #include "../account/account.h" 0011 #include "keysmith.h" 0012 0013 namespace app 0014 { 0015 OverviewState * overviewStateOf(Keysmith *app); 0016 FlowState * flowStateOf(Keysmith *app); 0017 model::SimpleAccountListModel * accountListOf(Keysmith *app); 0018 0019 class AddAccountViewModel: public QObject 0020 { 0021 Q_OBJECT 0022 Q_PROPERTY(model::AccountInput * input READ input CONSTANT) 0023 Q_PROPERTY(model::SimpleAccountListModel * accounts READ accounts CONSTANT) 0024 Q_PROPERTY(bool validateAvailability READ validateAvailability CONSTANT) 0025 Q_PROPERTY(bool quitEnabled READ quitEnabled CONSTANT) 0026 public: 0027 explicit AddAccountViewModel(model::AccountInput *input, model::SimpleAccountListModel *accounts, 0028 bool quitEnabled, bool validateAvailability, 0029 QObject *parent = nullptr); 0030 model::AccountInput * input(void) const; 0031 model::SimpleAccountListModel * accounts(void) const; 0032 bool validateAvailability(void) const; 0033 bool quitEnabled(void) const; 0034 Q_SIGNALS: 0035 void cancelled(void); 0036 void accepted(void); 0037 private: 0038 model::AccountInput * const m_input; 0039 model::SimpleAccountListModel * const m_accounts; 0040 const bool m_quitEnabled; 0041 const bool m_validateAvailability; 0042 }; 0043 0044 class RenameAccountViewModel: public QObject 0045 { 0046 Q_OBJECT 0047 Q_PROPERTY(model::AccountInput * input READ input CONSTANT) 0048 Q_PROPERTY(model::SimpleAccountListModel * accounts READ accounts CONSTANT) 0049 public: 0050 explicit RenameAccountViewModel(model::AccountInput *input, model::SimpleAccountListModel *accounts, 0051 QObject *parent = nullptr); 0052 model::AccountInput * input(void) const; 0053 model::SimpleAccountListModel * accounts(void) const; 0054 Q_SIGNALS: 0055 void cancelled(void); 0056 void accepted(void); 0057 private: 0058 model::AccountInput * const m_input; 0059 model::SimpleAccountListModel * const m_accounts; 0060 }; 0061 0062 class ErrorViewModel: public QObject 0063 { 0064 Q_OBJECT 0065 Q_PROPERTY(QString errorText READ error CONSTANT) 0066 Q_PROPERTY(QString errorTitle READ title CONSTANT) 0067 Q_PROPERTY(bool quitEnabled READ quitEnabled CONSTANT) 0068 public: 0069 explicit ErrorViewModel(const QString &errorTitle, const QString &errorText, bool quitEnabled, 0070 QObject *parent = nullptr); 0071 bool quitEnabled(void) const; 0072 QString error(void) const; 0073 QString title(void) const; 0074 Q_SIGNALS: 0075 void dismissed(void); 0076 private: 0077 const QString m_title; 0078 const QString m_error; 0079 const bool m_quitEnabled; 0080 }; 0081 0082 class PasswordViewModel: public QObject 0083 { 0084 Q_OBJECT 0085 Q_PROPERTY(bool failed READ failed NOTIFY failedChanged) 0086 Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) 0087 public: 0088 explicit PasswordViewModel(model::PasswordRequest *request, QObject *parent = nullptr); 0089 virtual ~PasswordViewModel(); 0090 bool failed(void) const; 0091 bool busy(void) const; 0092 Q_SIGNALS: 0093 void failedChanged(void); 0094 void busyChanged(void); 0095 private Q_SLOTS: 0096 void rejected(void); 0097 protected: 0098 bool m_failed; 0099 model::PasswordRequest * const m_request; 0100 }; 0101 0102 class SetupPasswordViewModel: public PasswordViewModel 0103 { 0104 Q_OBJECT 0105 public: 0106 explicit SetupPasswordViewModel(model::PasswordRequest *request, QObject *parent = nullptr); 0107 public Q_SLOTS: 0108 void setup(const QString &password, const QString &confirmedPassword); 0109 }; 0110 0111 class UnlockAccountsViewModel: public PasswordViewModel 0112 { 0113 Q_OBJECT 0114 public: 0115 explicit UnlockAccountsViewModel(model::PasswordRequest *request, QObject *parent = nullptr); 0116 public Q_SLOTS: 0117 void unlock(const QString &password); 0118 }; 0119 0120 class AccountsOverviewViewModel: public QObject 0121 { 0122 Q_OBJECT 0123 Q_PROPERTY(model::SimpleAccountListModel * accounts READ accounts CONSTANT) 0124 Q_PROPERTY(bool actionsEnabled READ actionsEnabled NOTIFY actionsEnabledChanged) 0125 public: 0126 explicit AccountsOverviewViewModel(Keysmith *app); 0127 model::SimpleAccountListModel * accounts(void) const; 0128 bool actionsEnabled(void) const; 0129 public Q_SLOTS: 0130 void addNewAccount(void); 0131 Q_SIGNALS: 0132 void actionsEnabledChanged(void); 0133 private: 0134 Keysmith * const m_app; 0135 model::SimpleAccountListModel * const m_accounts; 0136 }; 0137 } 0138 0139 #endif