Fix review comments from Claudio III.
authoralex-z <blackslayer4@gmail.com>
Fri, 30 Dec 2022 13:45:47 +0000 (14:45 +0100)
committerallexzander <allexzander@users.noreply.github.com>
Fri, 30 Dec 2022 13:46:06 +0000 (14:46 +0100)
Signed-off-by: alex-z <blackslayer4@gmail.com>
src/gui/accountsetupcommandlinemanager.cpp
src/gui/accountsetupcommandlinemanager.h
src/gui/application.cpp

index 39fe895cafec24944c474eac917626d0edca38ff..a604cb53bc1990e254c9de258efa84d0bbf03574 100644 (file)
@@ -19,6 +19,29 @@ namespace OCC
 {
 Q_LOGGING_CATEGORY(lcAccountSetupCommandLineManager, "nextcloud.gui.accountsetupcommandlinemanager", QtInfoMsg)
 
+AccountSetupCommandLineManager *AccountSetupCommandLineManager::_instance = nullptr;
+
+AccountSetupCommandLineManager::AccountSetupCommandLineManager(QObject *parent)
+    : QObject{parent}
+{
+}
+
+AccountSetupCommandLineManager *AccountSetupCommandLineManager::instance()
+{
+    if (!_instance) {
+        _instance = new AccountSetupCommandLineManager();
+    }
+    return _instance;
+}
+
+void AccountSetupCommandLineManager::destroy()
+{
+    if (_instance) {
+        _instance->deleteLater();
+        _instance = nullptr;
+    }
+}
+
 bool AccountSetupCommandLineManager::parseCommandlineOption(const QString &option, QStringListIterator &optionsIterator, QString &errorMessage)
 {
     if (option == QStringLiteral("--apppassword")) {
@@ -67,16 +90,16 @@ bool AccountSetupCommandLineManager::parseCommandlineOption(const QString &optio
     return false;
 }
 
-bool AccountSetupCommandLineManager::isCommandLineParsed()
+bool AccountSetupCommandLineManager::isCommandLineParsed() const
 {
     return !_appPassword.isEmpty() && !_userId.isEmpty() && _serverUrl.isValid();
 }
 
-void AccountSetupCommandLineManager::setupAccountFromCommandLine(QObject *parent)
+void AccountSetupCommandLineManager::setupAccountFromCommandLine()
 {
     if (isCommandLineParsed()) {
         qCInfo(lcAccountSetupCommandLineManager) << QStringLiteral("Command line has been parsed and account setup parameters have been found. Attempting setup a new account %1...").arg(_userId);
-        const auto accountSetupJob = new AccountSetupFromCommandLineJob(_appPassword, _userId, _serverUrl, _localDirPath, _isVfsEnabled, _remoteDirPath, parent);
+        const auto accountSetupJob = new AccountSetupFromCommandLineJob(_appPassword, _userId, _serverUrl, _localDirPath, _isVfsEnabled, _remoteDirPath, parent());
         accountSetupJob->handleAccountSetupFromCommandLine();
     } else {
         qCInfo(lcAccountSetupCommandLineManager) << QStringLiteral("No account setup parameters have been found, or they are invalid. Proceed with normal startup...");
@@ -88,11 +111,4 @@ void AccountSetupCommandLineManager::setupAccountFromCommandLine(QObject *parent
     _localDirPath.clear();
     _isVfsEnabled = true;
 }
-
-QString AccountSetupCommandLineManager::_appPassword;
-QString AccountSetupCommandLineManager::_userId;
-QUrl AccountSetupCommandLineManager::_serverUrl;
-QString AccountSetupCommandLineManager::_remoteDirPath;
-QString AccountSetupCommandLineManager::_localDirPath;
-bool AccountSetupCommandLineManager::_isVfsEnabled = true;
 }
index f9b1e9279603b8b41bfaf082572538287a7ba3ec..585627e85801a63d0828b2b52ff076f7c1b83d7d 100644 (file)
 #include <QUrl>
 
 namespace OCC {
-class AccountSetupCommandLineManager
+class AccountSetupCommandLineManager : public QObject
 {
+    Q_OBJECT
+
 public:
-    [[nodiscard]] static bool parseCommandlineOption(const QString &option, QStringListIterator &optionsIterator, QString &errorMessage);
+    [[nodiscard]] static AccountSetupCommandLineManager *instance();
+    static void destroy();
+
+    [[nodiscard]] bool parseCommandlineOption(const QString &option, QStringListIterator &optionsIterator, QString &errorMessage);
 
-    [[nodiscard]] static bool isCommandLineParsed();
+    [[nodiscard]] bool isCommandLineParsed() const;
 
-    static void setupAccountFromCommandLine(QObject *parent = nullptr);
+public slots:
+    void setupAccountFromCommandLine();
 
 private:
-    explicit AccountSetupCommandLineManager() = delete;
-
-    static QString _appPassword;
-    static QString _userId;
-    static QUrl _serverUrl;
-    static QString _remoteDirPath;
-    static QString _localDirPath;
-    static bool _isVfsEnabled;
+    explicit AccountSetupCommandLineManager(QObject *parent = nullptr);
+
+    static AccountSetupCommandLineManager *_instance;
+
+    QString _appPassword;
+    QString _userId;
+    QUrl _serverUrl;
+    QString _remoteDirPath;
+    QString _localDirPath;
+    bool _isVfsEnabled;
 };
 
 }
index eeaab85da7dc0173ef62d2273ce46c680efd4ac3..8af99a7dfc6afab85bbe2a4f6a3f9ef5f1fd37cc 100644 (file)
@@ -419,9 +419,10 @@ Application::Application(int &argc, char **argv)
 
     handleEditLocallyFromOptions();
 
-    if (AccountSetupCommandLineManager::isCommandLineParsed()) {
-        AccountSetupCommandLineManager::setupAccountFromCommandLine(this);
+    if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) {
+        AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine();
     }
+    AccountSetupCommandLineManager::destroy();
 }
 
 Application::~Application()
@@ -590,9 +591,10 @@ void Application::slotParseMessage(const QString &msg, QObject *)
 
         handleEditLocallyFromOptions();
 
-        if (AccountSetupCommandLineManager::isCommandLineParsed()) {
-            AccountSetupCommandLineManager::setupAccountFromCommandLine(this);
+        if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) {
+            AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine();
         }
+        AccountSetupCommandLineManager::destroy();
 
     } else if (msg.startsWith(QLatin1String("MSG_SHOWMAINDIALOG"))) {
         qCInfo(lcApplication) << "Running for" << _startedAt.elapsed() / 1000.0 << "sec";
@@ -681,7 +683,7 @@ void Application::parseOptions(const QStringList &options)
         }
         else {
             QString errorMessage;
-            if (!AccountSetupCommandLineManager::parseCommandlineOption(option, it, errorMessage)) {
+            if (!AccountSetupCommandLineManager::instance()->parseCommandlineOption(option, it, errorMessage)) {
                 if (!errorMessage.isEmpty()) {
                     showHint(errorMessage.toStdString());
                     return;