Skip to content

Commit 7a8c61f

Browse files
authored
Merge branch 'master' into preserve-selected-account-between-runs
Signed-off-by: dsyzov <[email protected]>
2 parents 70be1f0 + 68f1b0b commit 7a8c61f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1475
-2486
lines changed

src/common/checksums.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ ComputeChecksum::ComputeChecksum(QObject *parent)
175175
{
176176
}
177177

178-
ComputeChecksum::~ComputeChecksum() = default;
178+
ComputeChecksum::~ComputeChecksum()
179+
{
180+
_checksumCalculator.reset();
181+
}
179182

180183
void ComputeChecksum::setChecksumType(const QByteArray &type)
181184
{
@@ -201,6 +204,11 @@ void ComputeChecksum::startImpl(const QString &filePath)
201204

202205
_checksumCalculator.reset(new ChecksumCalculator(filePath, _checksumType));
203206
_watcher.setFuture(QtConcurrent::run([this]() {
207+
if (!_checksumCalculator) {
208+
qCDebug(lcChecksums) << "checksumCalculator instance was destroyed before calculation started, returning empty checksum";
209+
return QByteArray();
210+
}
211+
204212
return _checksumCalculator->calculate();
205213
}));
206214
}

src/gui/accountmanager.cpp

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ bool AccountManager::restoreFromLegacySettings()
276276
selectedAccountIds = childGroups;
277277
}
278278

279+
const auto legacyVersion = oCSettings->value(ConfigFile::clientVersionC, {}).toString();
280+
ConfigFile().setClientPreviousVersionString(legacyVersion);
281+
qCInfo(lcAccountManager) << "Migrating from" << legacyVersion;
279282
qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", ");
280283
settings = std::move(oCSettings);
281-
282284
ConfigFile::setDiscoveredLegacyConfigPath(configFileInfo.canonicalPath());
283285
break;
284286
} else {
@@ -288,21 +290,47 @@ bool AccountManager::restoreFromLegacySettings()
288290
}
289291

290292
ConfigFile configFile;
293+
// General settings
291294
configFile.setVfsEnabled(settings->value(ConfigFile::isVfsEnabledC, configFile.isVfsEnabled()).toBool());
292-
configFile.setLaunchOnSystemStartup(settings->value(ConfigFile::launchOnSystemStartupC, configFile.launchOnSystemStartup()).toBool());
293-
configFile.setOptionalServerNotifications(settings->value(ConfigFile::optionalServerNotificationsC, configFile.optionalServerNotifications()).toBool());
294-
configFile.setPromptDeleteFiles(settings->value(ConfigFile::promptDeleteC, configFile.promptDeleteFiles()).toBool());
295-
configFile.setShowCallNotifications(settings->value(ConfigFile::showCallNotificationsC, configFile.showCallNotifications()).toBool());
296-
configFile.setShowChatNotifications(settings->value(ConfigFile::showChatNotificationsC, configFile.showChatNotifications()).toBool());
297-
configFile.setShowQuotaWarningNotifications(settings->value(ConfigFile::showQuotaWarningNotificationsC, configFile.showQuotaWarningNotifications()).toBool());
298-
configFile.setShowInExplorerNavigationPane(settings->value(ConfigFile::showInExplorerNavigationPaneC, configFile.showInExplorerNavigationPane()).toBool());
295+
configFile.setLaunchOnSystemStartup(settings->value(ConfigFile::launchOnSystemStartupC,
296+
configFile.launchOnSystemStartup()).toBool());
297+
configFile.setOptionalServerNotifications(settings->value(ConfigFile::optionalServerNotificationsC,
298+
configFile.optionalServerNotifications()).toBool());
299+
configFile.setPromptDeleteFiles(settings->value(ConfigFile::promptDeleteC,
300+
configFile.promptDeleteFiles()).toBool());
301+
configFile.setShowCallNotifications(settings->value(ConfigFile::showCallNotificationsC,
302+
configFile.showCallNotifications()).toBool());
303+
configFile.setShowChatNotifications(settings->value(ConfigFile::showChatNotificationsC,
304+
configFile.showChatNotifications()).toBool());
305+
configFile.setShowQuotaWarningNotifications(settings->value(ConfigFile::showQuotaWarningNotificationsC,
306+
configFile.showQuotaWarningNotifications()).toBool());
307+
configFile.setShowInExplorerNavigationPane(settings->value(ConfigFile::showInExplorerNavigationPaneC,
308+
configFile.showInExplorerNavigationPane()).toBool());
309+
// Advanced
310+
const auto newBigFolderSizeLimit = settings->value(ConfigFile::newBigFolderSizeLimitC, configFile.newBigFolderSizeLimit().second).toLongLong();
311+
const auto useNewBigFolderSizeLimit = settings->value(ConfigFile::useNewBigFolderSizeLimitC, configFile.useNewBigFolderSizeLimit()).toBool();
312+
configFile.setNewBigFolderSizeLimit(useNewBigFolderSizeLimit, newBigFolderSizeLimit);
313+
configFile.setNotifyExistingFoldersOverLimit(settings->value(ConfigFile::notifyExistingFoldersOverLimitC,
314+
configFile.notifyExistingFoldersOverLimit()).toBool());
315+
configFile.setStopSyncingExistingFoldersOverLimit(settings->value(ConfigFile::stopSyncingExistingFoldersOverLimitC,
316+
configFile.stopSyncingExistingFoldersOverLimit()).toBool());
317+
configFile.setConfirmExternalStorage(settings->value(ConfigFile::confirmExternalStorageC, configFile.confirmExternalStorage()).toBool());
318+
configFile.setMoveToTrash(settings->value(ConfigFile::moveToTrashC, configFile.moveToTrash()).toBool());
319+
// Info
320+
configFile.setUpdateChannel(settings->value(ConfigFile::updateChannelC, configFile.currentUpdateChannel()).toString());
321+
auto previousAppName = settings->contains(ConfigFile::legacyAppName) ? ConfigFile::legacyAppName
322+
: ConfigFile::unbrandedAppName;
323+
const auto updaterGroupName = QString("%1/%2").arg(previousAppName, ConfigFile::autoUpdateCheckC);
324+
configFile.setAutoUpdateCheck(settings->value(updaterGroupName, configFile.autoUpdateCheck()).toBool(), {});
325+
// Network
299326
ClientProxy().saveProxyConfigurationFromSettings(*settings);
300327
configFile.setUseUploadLimit(settings->value(ConfigFile::useUploadLimitC, configFile.useUploadLimit()).toInt());
301328
configFile.setUploadLimit(settings->value(ConfigFile::uploadLimitC, configFile.uploadLimit()).toInt());
302329
configFile.setUseDownloadLimit(settings->value(ConfigFile::useDownloadLimitC, configFile.useDownloadLimit()).toInt());
303330
configFile.setDownloadLimit(settings->value(ConfigFile::downloadLimitC, configFile.downloadLimit()).toInt());
304331

305332
// Try to load the single account.
333+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::SetupUsers);
306334
if (!settings->childKeys().isEmpty()) {
307335
settings->beginGroup(accountsC);
308336
const auto childGroups = selectedAccountIds.isEmpty() ? settings->childGroups() : selectedAccountIds;
@@ -582,13 +610,33 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
582610
}
583611
acc->_settingsMap.insert(key, settings.value(key));
584612
}
585-
586613
acc->setCredentials(CredentialsFactory::create(authType));
587-
acc->setProxyType(settings.value(networkProxyTypeC).value<QNetworkProxy::ProxyType>());
588-
acc->setProxyHostName(settings.value(networkProxyHostNameC).toString());
589-
acc->setProxyPort(settings.value(networkProxyPortC).toInt());
590-
acc->setProxyNeedsAuth(settings.value(networkProxyNeedsAuthC).toBool());
591-
acc->setProxyUser(settings.value(networkProxyUserC).toString());
614+
615+
{
616+
auto accountProxyType = settings.value(networkProxyTypeC).value<QNetworkProxy::ProxyType>();
617+
auto accountProxyHost = settings.value(networkProxyHostNameC).toString();
618+
auto accountProxyPort = settings.value(networkProxyPortC).toInt();
619+
auto accountProxyNeedsAuth = settings.value(networkProxyNeedsAuthC).toBool();
620+
auto accountProxyUser = settings.value(networkProxyUserC).toString();
621+
const auto globalProxyType = settings.value(ClientProxy::proxyTypeC).value<QNetworkProxy::ProxyType>();
622+
qCDebug(lcAccountManager) << "Account proxy type:" << accountProxyType;
623+
qCDebug(lcAccountManager) << "Global proxy type:" << globalProxyType;
624+
if (accountProxyType == QNetworkProxy::NoProxy && globalProxyType != QNetworkProxy::NoProxy) {
625+
accountProxyType = globalProxyType;
626+
accountProxyHost = settings.value(ClientProxy::proxyHostC).toString();
627+
accountProxyPort = settings.value(ClientProxy::proxyPortC).toInt();
628+
accountProxyNeedsAuth = settings.value(ClientProxy::proxyNeedsAuthC).toBool();
629+
accountProxyUser = settings.value(ClientProxy::proxyUserC).toString();
630+
qCInfo(lcAccountManager) << "Account has no proxy set, using global proxy instead.";
631+
}
632+
633+
acc->setProxyType(accountProxyType);
634+
acc->setProxyHostName(accountProxyHost);
635+
acc->setProxyPort(accountProxyPort);
636+
acc->setProxyNeedsAuth(accountProxyNeedsAuth);
637+
acc->setProxyUser(accountProxyUser);
638+
}
639+
592640
acc->setUploadLimitSetting(
593641
settings.value(
594642
networkUploadLimitSettingC,
@@ -599,7 +647,6 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
599647
networkDownloadLimitSettingC,
600648
QVariant::fromValue(Account::AccountNetworkTransferLimitSetting::NoLimit)
601649
).value<Account::AccountNetworkTransferLimitSetting>());
602-
603650
acc->setUploadLimit(settings.value(networkUploadLimitC).toInt());
604651
acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt());
605652

@@ -786,7 +833,7 @@ void AccountManager::addAccountState(AccountState *const accountState)
786833

787834
bool AccountManager::forceLegacyImport() const
788835
{
789-
return _forceLegacyImport;
836+
return _forceLegacyImport;
790837
}
791838

792839
void AccountManager::setForceLegacyImport(const bool forceLegacyImport)

src/gui/accountstate.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,12 @@ void AccountState::checkConnectivity()
296296
// make little sense, we might be missing client certs.
297297
if (!account()->credentials()->wasFetched()) {
298298
_waitingForNewCredentials = true;
299-
account()->credentials()->fetchFromKeychain();
299+
ConfigFile configFile;
300+
const auto shouldTryUnbrandedToBrandedMigration = configFile.shouldTryUnbrandedToBrandedMigration();
301+
qCDebug(lcAccountState) << "shouldTryUnbrandedToBrandedMigration?" << shouldTryUnbrandedToBrandedMigration;
302+
qCDebug(lcAccountState) << "migrationPhase?" << configFile.migrationPhase();
303+
const auto appName = shouldTryUnbrandedToBrandedMigration ? configFile.unbrandedAppName : "";
304+
account()->credentials()->fetchFromKeychain(appName);
300305
return;
301306
}
302307

@@ -492,6 +497,10 @@ void AccountState::slotCredentialsFetched(AbstractCredentials *)
492497
qCInfo(lcAccountState) << "Fetched credentials for" << _account->url().toString()
493498
<< "attempting to connect";
494499
_waitingForNewCredentials = false;
500+
ConfigFile configFile;
501+
if (configFile.isMigrationInProgress()) {
502+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::Done);
503+
}
495504
checkConnectivity();
496505
}
497506

src/gui/application.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,22 @@ namespace {
119119

120120
bool Application::configVersionMigration()
121121
{
122+
ConfigFile configFile;
123+
const auto shouldTryToMigrate = configFile.shouldTryToMigrate();
124+
if (!shouldTryToMigrate) {
125+
qCInfo(lcApplication) << "This is not an upgrade/downgrade/migration. Proceed to read current application config file.";
126+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::Done);
127+
return false;
128+
}
129+
130+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::SetupConfigFile);
122131
QStringList deleteKeys, ignoreKeys;
123132
AccountManager::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
124133
FolderMan::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
125-
126-
ConfigFile configFile;
127-
128-
// Did the client version change?
129-
// (The client version is adjusted further down)
130-
const auto currentVersion = QVersionNumber::fromString(MIRALL_VERSION_STRING);
131-
const auto previousVersion = QVersionNumber::fromString(configFile.clientVersionString());
132-
const auto versionChanged = previousVersion != currentVersion;
133-
const auto downgrading = previousVersion > currentVersion;
134-
134+
configFile.setClientPreviousVersionString(configFile.clientVersionString());
135+
136+
qCDebug(lcApplication) << "Migration is in progress:" << configFile.isMigrationInProgress();
137+
const auto versionChanged = configFile.isUpgrade() || configFile.isDowngrade();
135138
if (versionChanged) {
136139
qCInfo(lcApplication) << "Version changed. Removing updater settings from config.";
137140
configFile.cleanUpdaterConfiguration();
@@ -177,7 +180,7 @@ bool Application::configVersionMigration()
177180
"Continuing will mean <b>%2 these settings</b>.<br>"
178181
"<br>"
179182
"The current configuration file was already backed up to <i>%3</i>.")
180-
.arg((downgrading ? tr("newer", "newer software version") : tr("older", "older software version")),
183+
.arg((configFile.isDowngrade() ? tr("newer", "newer software version") : tr("older", "older software version")),
181184
deleteKeys.isEmpty()? tr("ignoring") : tr("deleting"),
182185
backupFilesList.join("<br>")));
183186
box.addButton(tr("Quit"), QMessageBox::AcceptRole);
@@ -484,7 +487,8 @@ Application::~Application()
484487
void Application::setupAccountsAndFolders()
485488
{
486489
_folderManager.reset(new FolderMan);
487-
490+
ConfigFile configFile;
491+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::SetupUsers);
488492
const auto accountsRestoreResult = restoreLegacyAccount();
489493
const auto accounts = AccountManager::instance()->accounts();
490494
if (accountsRestoreResult != AccountManager::AccountsRestoreSuccessFromLegacyVersion
@@ -496,6 +500,7 @@ void Application::setupAccountsAndFolders()
496500
return;
497501
}
498502

503+
configFile.setMigrationPhase(ConfigFile::MigrationPhase::SetupFolders);
499504
const auto foldersListSize = FolderMan::instance()->setupFolders();
500505
FolderMan::instance()->setSyncEnabled(true);
501506

src/gui/connectionvalidator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ void ConnectionValidator::slotUserFetched(UserInfo *userInfo)
329329

330330
#ifndef TOKEN_AUTH_ONLY
331331
connect(_account->e2e(), &ClientSideEncryption::initializationFinished, this, &ConnectionValidator::reportConnected);
332-
_account->e2e()->setAccount(_account);
333332
_account->e2e()->initialize(nullptr);
334333
#else
335334
reportResult(Connected);

src/gui/creds/webflowcredentials.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ bool WebFlowCredentials::ready() const {
132132
return _ready;
133133
}
134134

135-
void WebFlowCredentials::fetchFromKeychain() {
135+
void WebFlowCredentials::fetchFromKeychain(const QString &appName) {
136136
_wasFetched = true;
137+
_appName = appName;
137138

138139
// Make sure we get the user from the config file
139140
fetchUser();
@@ -223,7 +224,6 @@ void WebFlowCredentials::persist() {
223224
}
224225

225226
_account->setCredentialSetting(userC, _user);
226-
emit _account->wantsAccountSaved(_account->sharedFromThis());
227227

228228
// write cert if there is one
229229
if (!_clientSslCertificate.isNull()) {
@@ -361,7 +361,7 @@ void WebFlowCredentials::forgetSensitiveData() {
361361

362362
_account->deleteAppPassword();
363363

364-
const auto kck = keychainKey(_account->url().toString(), _user, _account->id());
364+
const auto kck = keychainKey(_account->url().toString(), _user, _account->id(), _appName);
365365
if (kck.isEmpty()) {
366366
qCWarning(lcWebFlowCredentials()) << "InvalidateToken: User is empty, bailing out!";
367367
return;
@@ -424,6 +424,7 @@ void WebFlowCredentials::fetchFromKeychainHelper() {
424424
_user + clientCertificatePEMC,
425425
_keychainMigration,
426426
this);
427+
job->setAppName(_appName);
427428
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientCertPEMJobDone);
428429
job->start();
429430
}
@@ -443,6 +444,7 @@ void WebFlowCredentials::slotReadClientCertPEMJobDone(KeychainChunk::ReadJob *re
443444
_user + clientKeyPEMC,
444445
_keychainMigration,
445446
this);
447+
job->setAppName(_appName);
446448
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientKeyPEMJobDone);
447449
job->start();
448450
}
@@ -483,6 +485,7 @@ void WebFlowCredentials::readSingleClientCaCertPEM()
483485
_user + clientCaCertificatePEMC + QString::number(_clientSslCaCertificates.count()),
484486
_keychainMigration,
485487
this);
488+
job->setAppName(_appName);
486489
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientCaCertsPEMJobDone);
487490
job->start();
488491
} else {
@@ -516,7 +519,8 @@ void WebFlowCredentials::slotReadClientCaCertsPEMJobDone(KeychainChunk::ReadJob
516519
const QString kck = keychainKey(
517520
_account->url().toString(),
518521
_user,
519-
_keychainMigration ? QString() : _account->id());
522+
_keychainMigration ? QString() : _account->id(),
523+
_appName);
520524

521525
auto job = new ReadPasswordJob(Theme::instance()->appName(), this);
522526
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
@@ -547,6 +551,7 @@ void WebFlowCredentials::slotReadPasswordJobDone(Job *incomingJob) {
547551
_password = job->textData();
548552
_ready = true;
549553
_credentialsValid = true;
554+
persist();
550555
} else {
551556
_ready = false;
552557
}

src/gui/creds/webflowcredentials.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class WebFlowCredentials : public AbstractCredentials
5555

5656
[[nodiscard]] bool ready() const override;
5757

58-
void fetchFromKeychain() override;
58+
void fetchFromKeychain(const QString &appName = {}) override;
5959
void askFromUser() override;
6060

6161
bool stillValid(QNetworkReply *reply) override;
@@ -127,6 +127,7 @@ private slots:
127127
bool _ready = false;
128128
bool _credentialsValid = false;
129129
bool _keychainMigration = false;
130+
QString _appName;
130131

131132
WebFlowCredentialsDialog *_askDialog = nullptr;
132133
};

src/gui/folderman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ShareTestHelper;
2727
class EndToEndTestHelper;
2828
class TestSyncConflictsModel;
2929
class TestRemoteWipe;
30+
class FolderManTestHelper;
3031

3132
namespace OCC {
3233

@@ -415,6 +416,7 @@ private slots:
415416
friend class ::EndToEndTestHelper;
416417
friend class ::TestFolderStatusModel;
417418
friend class ::TestRemoteWipe;
419+
friend class ::FolderManTestHelper;
418420
};
419421

420422
} // namespace OCC

src/gui/generalsettings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ void GeneralSettings::slotToggleOptionalServerNotifications(bool enable)
610610
cfgFile.setOptionalServerNotifications(enable);
611611
_ui->chatNotificationsCheckBox->setEnabled(enable);
612612
_ui->callNotificationsCheckBox->setEnabled(enable);
613+
_ui->quotaWarningNotificationsCheckBox->setEnabled(enable);
613614
}
614615

615616
void GeneralSettings::slotToggleChatNotifications(bool enable)

src/gui/openfilemanager.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,7 @@ void showInFileManager(const QString &localPath)
107107
p.waitForFinished(5000);
108108
}
109109
} else if (Utility::isMac()) {
110-
QStringList scriptArgs;
111-
scriptArgs << QLatin1String("-e")
112-
<< QString::fromLatin1(R"(tell application "Finder" to reveal POSIX file "%1")")
113-
.arg(localPath);
114-
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
115-
scriptArgs.clear();
116-
scriptArgs << QLatin1String("-e")
117-
<< QLatin1String("tell application \"Finder\" to activate");
118-
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
110+
QProcess::startDetached("/usr/bin/open", {"-R", localPath});
119111
} else {
120112
QString app;
121113
QStringList args;

0 commit comments

Comments
 (0)