Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix update channels #7350

Merged
merged 10 commits into from
Oct 31, 2024
29 changes: 28 additions & 1 deletion src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);
settings.setValue(QLatin1String(serverColorC), acc->_serverColor);
settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor);
settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->capabilities().serverHasValidSubscription());
settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->serverHasValidSubscription());

if (!acc->_skipE2eeMetadataChecksumValidation) {
settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC));
Expand Down Expand Up @@ -611,10 +611,30 @@ void AccountManager::deleteAccount(OCC::AccountState *account)

account->account()->deleteAppToken();

// clean up config from subscriptions if the account removed was the only with valid subscription
if (account->account()->serverHasValidSubscription()) {
updateServerHasValidSubscriptionConfig();
}

emit accountSyncConnectionRemoved(account);
emit accountRemoved(account);
}

void AccountManager::updateServerHasValidSubscriptionConfig()
{
auto serverHasValidSubscription = false;
for (const auto &account : _accounts) {
if (!account->account()->serverHasValidSubscription()) {
continue;
}

serverHasValidSubscription = true;
break;
}

ConfigFile().setServerHasValidSubscription(serverHasValidSubscription);
}

AccountPtr AccountManager::createAccount()
{
const auto acc = Account::create();
Expand Down Expand Up @@ -670,10 +690,17 @@ void AccountManager::addAccountState(AccountState *const accountState)
Q_ASSERT(accountState->account());

QObject::connect(accountState->account().data(), &Account::wantsAccountSaved, this, &AccountManager::saveAccount);
QObject::connect(accountState->account().data(), &Account::capabilitiesChanged, this, &AccountManager::capabilitiesChanged);

AccountStatePtr ptr(accountState);
_accounts << ptr;
ptr->trySignIn();

// update config subscriptions if the account added is the only with valid subscription
if (accountState->account()->serverHasValidSubscription() && !ConfigFile().serverHasValidSubscription()) {
updateServerHasValidSubscriptionConfig();
}

emit accountAdded(accountState);
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "account.h"

Check failure on line 17 in src/gui/accountmanager.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountmanager.h:17:10 [clang-diagnostic-error]

'account.h' file not found
#include "accountstate.h"

namespace OCC {
Expand Down Expand Up @@ -114,6 +114,7 @@
void accountSyncConnectionRemoved(OCC::AccountState *account);
void removeAccountFolders(OCC::AccountState *account);
void forceLegacyImportChanged();
void capabilitiesChanged();

private:
// saving and loading Account to settings
Expand All @@ -128,6 +129,9 @@
// Adds an account to the tracked list, emitting accountAdded()
void addAccountState(AccountState *const accountState);

// update config serverHasValidSubscription when accounts list changes
void updateServerHasValidSubscriptionConfig();

AccountManager() = default;
QList<AccountStatePtr> _accounts;
/// Account ids from settings that weren't read
Expand Down
22 changes: 15 additions & 7 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/generalsettings.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/generalsettings.cpp

File src/gui/generalsettings.cpp does not conform to Custom style guidelines. (lines 294)
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -244,6 +244,10 @@
// accountAdded means the wizard was finished and the wizard might change some options.
connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings);

#if defined(BUILD_UPDATER)
loadUpdateChannelsList();
#endif

customizeStyle();
}

Expand Down Expand Up @@ -284,18 +288,22 @@
_ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit());
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
}

#if defined(BUILD_UPDATER)
void GeneralSettings::loadUpdateChannelsList() {
ConfigFile cfgFile;
const auto validUpdateChannels = cfgFile.validUpdateChannels();
_ui->updateChannel->clear();
_ui->updateChannel->addItems(validUpdateChannels);
const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel());
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0);
connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
#endif
if (_currentUpdateChannelList.isEmpty() || (_currentUpdateChannelList != validUpdateChannels && !cfgFile.serverHasValidSubscription())) {
_currentUpdateChannelList = validUpdateChannels;
_ui->updateChannel->clear();
_ui->updateChannel->addItems(_currentUpdateChannelList);
const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel());
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0);
connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
}
}

#if defined(BUILD_UPDATER)
void GeneralSettings::slotUpdateInfo()
{
ConfigFile config;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef MIRALL_GENERALSETTINGS_H
#define MIRALL_GENERALSETTINGS_H

#include "config.h"

Check failure on line 18 in src/gui/generalsettings.h

View workflow job for this annotation

GitHub Actions / build

src/gui/generalsettings.h:18:10 [clang-diagnostic-error]

'config.h' file not found

#include <QWidget>
#include <QPointer>
Expand All @@ -23,6 +23,7 @@
namespace OCC {
class IgnoreListEditor;
class SyncLogDialog;
class AccountState;

namespace Ui {
class GeneralSettings;
Expand All @@ -43,6 +44,9 @@

public slots:
void slotStyleChanged();
#if defined(BUILD_UPDATER)
void loadUpdateChannelsList();
#endif
camilasan marked this conversation as resolved.
Show resolved Hide resolved

private slots:
void saveMiscSettings();
Expand All @@ -67,6 +71,7 @@
Ui::GeneralSettings *_ui;
QPointer<IgnoreListEditor> _ignoreEditor;
bool _currentlyLoading = false;
QStringList _currentUpdateChannelList;
};


Expand Down
11 changes: 9 additions & 2 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged);

#if defined(BUILD_UPDATER)
connect(AccountManager::instance(), &AccountManager::accountAdded, generalSettings, &GeneralSettings::loadUpdateChannelsList);
connect(AccountManager::instance(), &AccountManager::accountRemoved, generalSettings, &GeneralSettings::loadUpdateChannelsList);
connect(AccountManager::instance(), &AccountManager::capabilitiesChanged, generalSettings, &GeneralSettings::loadUpdateChannelsList);
#endif

QAction *networkAction = createColorAwareAction(QLatin1String(":/client/theme/network.svg"), tr("Network"));

Check warning on line 137 in src/gui/settingsdialog.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/settingsdialog.cpp:137:14 [cppcoreguidelines-init-variables]

variable 'networkAction' is not initialized
_actionGroup->addAction(networkAction);
_toolBar->addAction(networkAction);
auto *networkSettings = new NetworkSettings;
Expand All @@ -137,8 +143,9 @@
_actionGroupWidgets.insert(generalAction, generalSettings);
_actionGroupWidgets.insert(networkAction, networkSettings);

foreach(auto ai, AccountManager::instance()->accounts()) {
accountAdded(ai.data());
const auto accountsList = AccountManager::instance()->accounts();
for (const auto &account : accountsList) {
accountAdded(account.data());
}

QTimer::singleShot(1, this, &SettingsDialog::showFirstPage);
Expand Down
19 changes: 16 additions & 3 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,13 +1076,26 @@ void Account::setAskUserForMnemonic(const bool ask)
emit askUserForMnemonicChanged();
}

bool Account::serverHasValidSubscription() const
{
return _serverHasValidSubscription;
}

void Account::setServerHasValidSubscription(bool valid)
{
_serverHasValidSubscription = valid;
}

void Account::updateServerSubcription()
{
ConfigFile currentConfig;
if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription();
serverHasValidSubscription != currentConfig.serverHasValidSubscription()) {
currentConfig.setServerHasValidSubscription(serverHasValidSubscription);
const auto capabilityValidSubscription = _capabilities.serverHasValidSubscription();
const auto configValidSubscription = currentConfig.serverHasValidSubscription();
if (capabilityValidSubscription != configValidSubscription && !configValidSubscription) {
currentConfig.setServerHasValidSubscription(capabilityValidSubscription);
}

setServerHasValidSubscription(capabilityValidSubscription);
}

void Account::updateDesktopEnterpriseChannel()
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
[[nodiscard]] unsigned int downloadLimit() const;
void setDownloadLimit(unsigned int kbytes);

[[nodiscard]] bool serverHasValidSubscription() const;
void setServerHasValidSubscription(bool valid);

public slots:
/// Used when forgetting credentials
void clearQNAMCache();
Expand Down Expand Up @@ -553,6 +556,8 @@ private slots:
unsigned int _uploadLimit = 0;
unsigned int _downloadLimit = 0;

bool _serverHasValidSubscription = false;

/* IMPORTANT - remove later - FIXME MS@2019-12-07 -->
* TODO: For "Log out" & "Remove account": Remove client CA certs and KEY!
*
Expand Down
15 changes: 4 additions & 11 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/configfile.cpp

File src/libsync/configfile.cpp does not conform to Custom style guidelines. (lines 710)
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -12,7 +12,7 @@
* for more details.
*/

#include "config.h"

Check failure on line 15 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:15:10 [clang-diagnostic-error]

'config.h' file not found

#include "configfile.h"
#include "theme.h"
Expand Down Expand Up @@ -707,32 +707,25 @@
if (serverHasValidSubscription() && !isBranded) {
if (const auto serverChannel = desktopEnterpriseChannel();
validUpdateChannels().contains(serverChannel)) {
qCWarning(lcConfigFile()) << "Enforcing update channel" << serverChannel << "because that is the desktop enterprise channel returned by the server.";
qCWarning(lcConfigFile()) << "Default update channel is" << serverChannel << "because that is the desktop enterprise channel returned by the server.";
return serverChannel;
}
}

if (const auto currentVersionSuffix = Theme::instance()->versionSuffix();
validUpdateChannels().contains(currentVersionSuffix) && !isBranded) {
qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client.";
qCWarning(lcConfigFile()) << "Default update channel is" << currentVersionSuffix << "because of the version suffix of the current client.";
return currentVersionSuffix;
}

qCWarning(lcConfigFile()) << "Enforcing default update channel" << defaultUpdateChannelName;
qCWarning(lcConfigFile()) << "Default update channel is" << defaultUpdateChannelName;
return defaultUpdateChannelName;
}

QString ConfigFile::currentUpdateChannel() const
{
auto updateChannel = defaultUpdateChannel();
QSettings settings(configFile(), QSettings::IniFormat);
if (const auto configUpdateChannel = settings.value(QLatin1String(updateChannelC), updateChannel).toString();
validUpdateChannels().contains(configUpdateChannel)) {
qCWarning(lcConfigFile()) << "Config file has a valid update channel:" << configUpdateChannel;
updateChannel = configUpdateChannel;
}

return updateChannel;
return settings.value(QLatin1String(updateChannelC), defaultUpdateChannel()).toString();
}

void ConfigFile::setUpdateChannel(const QString &channel)
Expand Down
Loading