File indexing completed on 2024-04-28 05:50:07

0001 /*
0002  * SPDX-License-Identifier: GPL-3.0-or-later
0003  * SPDX-FileCopyrightText: 2020-2021 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
0004  */
0005 #ifndef APP_KEYSMITH_H
0006 #define APP_KEYSMITH_H
0007 
0008 #include "../account/account.h"
0009 #include "../model/accounts.h"
0010 #include "../model/password.h"
0011 
0012 #include <QMetaEnum>
0013 #include <QObject>
0014 #include <QQmlEngine>
0015 #include <QSharedPointer>
0016 
0017 namespace app
0018 {
0019     class Navigation: public QObject
0020     {
0021         Q_OBJECT
0022     public:
0023         enum Page
0024         {
0025             Error,
0026             AddAccount,
0027             RenameAccount,
0028             AccountsOverview,
0029             SetupPassword,
0030             UnlockAccounts
0031         };
0032         Q_ENUM(Page)
0033     public:
0034         explicit Navigation(QQmlEngine * const engine);
0035         Q_INVOKABLE QString name(app::Navigation::Page page) const;
0036     public Q_SLOTS:
0037         void push(app::Navigation::Page page, QObject *modelToTransfer);
0038         void navigate(app::Navigation::Page page, QObject *modelToTransfer);
0039     Q_SIGNALS:
0040         void routed(app::Navigation::Page route, QObject *transferred);
0041         void pushed(app::Navigation::Page route, QObject *transferred);
0042     private:
0043         QQmlEngine * const m_engine;
0044     };
0045 
0046     class OverviewState;
0047     class FlowState;
0048 
0049     class Store
0050     {
0051     public:
0052         explicit Store(void);
0053         accounts::AccountStorage * accounts(void) const;
0054         model::SimpleAccountListModel * accountList(void) const;
0055         OverviewState * overview(void) const;
0056         FlowState * flows(void) const;
0057     private:
0058         QSharedPointer<FlowState> m_flows;
0059         QSharedPointer<OverviewState> m_overview;
0060         QSharedPointer<accounts::AccountStorage> m_accounts;
0061         QSharedPointer<model::SimpleAccountListModel> m_accountList;
0062     };
0063 
0064     class Keysmith: public QObject
0065     {
0066         Q_OBJECT
0067         Q_PROPERTY(app::Navigation * navigation READ navigation CONSTANT)
0068     public:
0069         explicit Keysmith(Navigation * const navigation, QObject *parent = nullptr);
0070         virtual ~Keysmith();
0071         const Store & store(void) const;
0072         Navigation * navigation(void) const;
0073         Q_INVOKABLE void copyToClipboard(const QString &text);
0074         Q_INVOKABLE model::SimpleAccountListModel * accountListModel(void);
0075         Q_INVOKABLE model::PasswordRequest * passwordRequest(void);
0076     private:
0077         accounts::AccountStorage * storage(void);
0078     private:
0079         Store m_store;
0080         Navigation * const m_navigation;
0081     };
0082 }
0083 
0084 Q_DECLARE_METATYPE(app::Navigation *);
0085 
0086 #endif