forked from nextcloud/desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccountsetupcommandlinemanager.cpp
More file actions
110 lines (100 loc) · 4.07 KB
/
Copy pathaccountsetupcommandlinemanager.cpp
File metadata and controls
110 lines (100 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "accountsetupcommandlinemanager.h"
#include "accountsetupfromcommandlinejob.h"
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")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_appPassword = optionsIterator.next();
return true;
} else {
errorMessage = QStringLiteral("apppassword not specified");
}
} else if (option == QStringLiteral("--localdirpath")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_localDirPath = optionsIterator.next();
return true;
} else {
errorMessage = QStringLiteral("basedir not specified");
}
} else if (option == QStringLiteral("--remotedirpath")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_remoteDirPath = optionsIterator.next();
return true;
} else {
errorMessage = QStringLiteral("remotedir not specified");
}
} else if (option == QStringLiteral("--serverurl")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_serverUrl = optionsIterator.next();
return true;
} else {
errorMessage = QStringLiteral("serverurl not specified");
}
} else if (option == QStringLiteral("--userid")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_userId = optionsIterator.next();
return true;
} else {
errorMessage = QStringLiteral("userid not specified");
}
} else if (option == QLatin1String("--isvfsenabled")) {
if (optionsIterator.hasNext() && !optionsIterator.peekNext().startsWith(QLatin1String("--"))) {
_isVfsEnabled = optionsIterator.next().toInt() != 0;
return true;
} else {
errorMessage = QStringLiteral("isvfsenabled not specified");
}
}
return false;
}
bool AccountSetupCommandLineManager::isCommandLineParsed() const
{
return !_appPassword.isEmpty() && !_userId.isEmpty() && _serverUrl.isValid();
}
bool AccountSetupCommandLineManager::isVfsEnabled() const
{
return _isVfsEnabled;
}
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());
accountSetupJob->handleAccountSetupFromCommandLine();
} else {
qCInfo(lcAccountSetupCommandLineManager) << QStringLiteral("No account setup parameters have been found, or they are invalid. Proceed with normal startup...");
}
_appPassword.clear();
_userId.clear();
_serverUrl.clear();
_remoteDirPath.clear();
_localDirPath.clear();
_isVfsEnabled = false;
}
}