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_COMMAND_LINE_H
0006 #define APP_COMMAND_LINE_H
0007 
0008 #include "keysmith.h"
0009 #include "../model/input.h"
0010 
0011 #include "../keysmith-features.h"
0012 
0013 #include <QCommandLineParser>
0014 #include <QGuiApplication>
0015 #include <QObject>
0016 #include <QString>
0017 #include <QStringList>
0018 
0019 namespace app
0020 {
0021 
0022     class CommandLineAccountJob: public QObject
0023     {
0024         Q_OBJECT
0025     public:
0026         explicit CommandLineAccountJob(model::AccountInput *recipient);
0027         void run(const QString &uri);
0028     Q_SIGNALS:
0029         void newAccountInvalid(void);
0030         void newAccountProcessed(void);
0031     private:
0032         static void processNewAccount(CommandLineAccountJob *target, const QString &uri);
0033     private Q_SLOTS:
0034         void expired(void);
0035     private:
0036         bool m_alive;
0037         model::AccountInput * const m_recipient;
0038     };
0039 
0040     class CommandLineOptions: public QObject
0041     {
0042         Q_OBJECT
0043         Q_PROPERTY(bool optionsOk READ optionsOk CONSTANT)
0044         Q_PROPERTY(QString errorText READ errorText CONSTANT)
0045         Q_PROPERTY(bool newAccountRequested READ newAccountRequested CONSTANT)
0046     public:
0047         static void addOptions(QCommandLineParser &parser);
0048         explicit CommandLineOptions(QCommandLineParser &parser, bool parseOk, QObject *parent = nullptr);
0049         QString errorText(void) const;
0050         bool optionsOk(void) const;
0051         bool newAccountRequested(void) const;
0052     public Q_SLOTS:
0053         void handleNewAccount(model::AccountInput *recipient);
0054     Q_SIGNALS:
0055         void newAccountInvalid(void);
0056         void newAccountProcessed(void);
0057     private:
0058         static void processNewAccount(CommandLineOptions *target, model::AccountInput *recipient);
0059     private:
0060         const bool m_parseOk;
0061         const QString m_errorText;
0062         QCommandLineParser &m_parser;
0063     };
0064 
0065     class Proxy: public QObject
0066     {
0067         Q_OBJECT
0068     public:
0069         static bool parseCommandLine(QCommandLineParser &parser, const QStringList &argv);
0070         static void addOptions(QCommandLineParser &parser);
0071     public:
0072         explicit Proxy(QGuiApplication *app, QObject *parent = nullptr);
0073         bool enable(Keysmith *keysmith);
0074         bool proxy(const QCommandLineParser &parser, bool parsedOk);
0075 #ifdef ENABLE_DBUS_INTERFACE
0076     public Q_SLOTS:
0077         void handleDBusActivation(const QStringList &arguments, const QString &workingDirectory);
0078 #endif
0079     private Q_SLOTS:
0080         void disable(void);
0081     private:
0082         Keysmith * m_keysmith;
0083         QGuiApplication *m_app;
0084     };
0085 };
0086 
0087 #endif