2013-07-04 21:59:40 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-07-04 21:59:40 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderman.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "generalsettings.h"
|
|
|
|
#include "networksettings.h"
|
|
|
|
#include "accountsettings.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "progressdispatcher.h"
|
|
|
|
#include "owncloudgui.h"
|
2015-10-19 15:41:53 +03:00
|
|
|
#include "activitywidget.h"
|
2015-04-17 18:56:17 +03:00
|
|
|
#include "accountmanager.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QStandardItemModel>
|
2014-12-01 13:37:06 +03:00
|
|
|
#include <QStackedWidget>
|
2013-07-04 21:59:40 +04:00
|
|
|
#include <QPushButton>
|
2013-11-15 18:45:21 +04:00
|
|
|
#include <QSettings>
|
2014-12-01 13:37:06 +03:00
|
|
|
#include <QToolBar>
|
2015-08-10 11:50:57 +03:00
|
|
|
#include <QToolButton>
|
2014-12-01 13:37:06 +03:00
|
|
|
#include <QLayout>
|
2015-08-10 11:50:57 +03:00
|
|
|
#include <QVBoxLayout>
|
2015-08-11 18:56:02 +03:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QImage>
|
2015-08-11 22:45:27 +03:00
|
|
|
#include <QWidgetAction>
|
2017-01-23 23:36:18 +03:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPainterPath>
|
2014-12-01 13:37:06 +03:00
|
|
|
|
|
|
|
namespace {
|
2017-05-17 11:55:42 +03:00
|
|
|
const char TOOLBAR_CSS[] =
|
2018-07-11 14:34:17 +03:00
|
|
|
"QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 0 solid %2; spacing: 0; } "
|
|
|
|
"QToolBar QToolButton { background: %1; border: none; border-bottom: 0 solid %2; margin: 0; padding: 5px; } "
|
2015-10-27 15:42:25 +03:00
|
|
|
"QToolBar QToolBarExtension { padding:0; } "
|
2015-08-10 21:13:20 +03:00
|
|
|
"QToolBar QToolButton:checked { background: %3; color: %4; }";
|
2015-10-23 17:19:40 +03:00
|
|
|
|
2019-09-08 12:33:20 +03:00
|
|
|
static const float buttonSizeRatio = 1.618f; // golden ratio
|
2014-12-01 13:37:06 +03:00
|
|
|
}
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2015-10-23 17:19:40 +03:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2017-10-06 13:01:10 +03:00
|
|
|
#include "settingsdialogcommon.cpp"
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
, _ui(new Ui::SettingsDialog)
|
|
|
|
, _gui(gui)
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2016-03-18 18:23:21 +03:00
|
|
|
ConfigFile cfg;
|
|
|
|
|
2013-11-13 23:12:56 +04:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2013-07-04 21:59:40 +04:00
|
|
|
_ui->setupUi(this);
|
2015-08-11 12:30:58 +03:00
|
|
|
_toolBar = new QToolBar;
|
|
|
|
_toolBar->setIconSize(QSize(32, 32));
|
|
|
|
_toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
layout()->setMenuBar(_toolBar);
|
2014-09-02 15:58:55 +04:00
|
|
|
|
|
|
|
// People perceive this as a Window, so also make Ctrl+W work
|
|
|
|
QAction *closeWindowAction = new QAction(this);
|
|
|
|
closeWindowAction->setShortcut(QKeySequence("Ctrl+W"));
|
2017-09-20 12:48:13 +03:00
|
|
|
connect(closeWindowAction, &QAction::triggered, this, &SettingsDialog::accept);
|
2014-09-02 15:58:55 +04:00
|
|
|
addAction(closeWindowAction);
|
|
|
|
|
2013-07-22 14:28:43 +04:00
|
|
|
setObjectName("Settings"); // required as group for saveGeometry call
|
2014-12-01 13:37:06 +03:00
|
|
|
setWindowTitle(Theme::instance()->appNameGUI());
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2018-03-26 22:02:03 +03:00
|
|
|
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
|
|
|
this, &SettingsDialog::accountAdded);
|
|
|
|
connect(AccountManager::instance(), &AccountManager::accountRemoved,
|
|
|
|
this, &SettingsDialog::accountRemoved);
|
|
|
|
|
2018-11-09 14:12:25 +03:00
|
|
|
|
2015-08-11 12:30:58 +03:00
|
|
|
_actionGroup = new QActionGroup(this);
|
|
|
|
_actionGroup->setExclusive(true);
|
2018-05-12 01:18:38 +03:00
|
|
|
connect(_actionGroup, &QActionGroup::triggered, this, &SettingsDialog::slotSwitchPage);
|
|
|
|
|
2018-08-14 12:54:08 +03:00
|
|
|
_actionBefore = new QAction(this);
|
2018-05-12 01:18:38 +03:00
|
|
|
_toolBar->addAction(_actionBefore);
|
|
|
|
|
2018-07-07 18:16:03 +03:00
|
|
|
// Adds space between users + activities and general + network actions
|
2018-05-12 01:18:38 +03:00
|
|
|
QWidget* spacer = new QWidget();
|
2018-05-12 01:33:13 +03:00
|
|
|
spacer->setMinimumWidth(10);
|
2018-05-12 01:18:38 +03:00
|
|
|
spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
|
|
|
_toolBar->addWidget(spacer);
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
QAction *generalAction = createColorAwareAction(QLatin1String(":/client/resources/settings.png"), tr("General"));
|
|
|
|
_actionGroup->addAction(generalAction);
|
2015-10-23 17:19:40 +03:00
|
|
|
_toolBar->addAction(generalAction);
|
2013-07-04 21:59:40 +04:00
|
|
|
GeneralSettings *generalSettings = new GeneralSettings;
|
|
|
|
_ui->stack->addWidget(generalSettings);
|
|
|
|
|
2019-12-09 22:47:42 +03:00
|
|
|
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
|
|
|
|
connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged);
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
QAction *networkAction = createColorAwareAction(QLatin1String(":/client/resources/network.png"), tr("Network"));
|
|
|
|
_actionGroup->addAction(networkAction);
|
2015-10-23 17:19:40 +03:00
|
|
|
_toolBar->addAction(networkAction);
|
2013-07-24 21:53:05 +04:00
|
|
|
NetworkSettings *networkSettings = new NetworkSettings;
|
|
|
|
_ui->stack->addWidget(networkSettings);
|
|
|
|
|
2015-08-11 12:30:58 +03:00
|
|
|
_actionGroupWidgets.insert(generalAction, generalSettings);
|
|
|
|
_actionGroupWidgets.insert(networkAction, networkSettings);
|
2014-12-01 13:37:06 +03:00
|
|
|
|
2018-11-12 20:53:47 +03:00
|
|
|
foreach(auto ai, AccountManager::instance()->accounts()) {
|
|
|
|
accountAdded(ai.data());
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
QTimer::singleShot(1, this, &SettingsDialog::showFirstPage);
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-08-14 19:46:58 +04:00
|
|
|
QAction *showLogWindow = new QAction(this);
|
|
|
|
showLogWindow->setShortcut(QKeySequence("F12"));
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(showLogWindow, &QAction::triggered, gui, &ownCloudGui::slotToggleLogBrowser);
|
2013-08-14 19:46:58 +04:00
|
|
|
addAction(showLogWindow);
|
|
|
|
|
2019-12-21 05:04:31 +03:00
|
|
|
connect(this, &SettingsDialog::onActivate, gui, &ownCloudGui::slotSettingsDialogActivated);
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
customizeStyle();
|
|
|
|
|
2013-07-22 14:28:43 +04:00
|
|
|
cfg.restoreGeometry(this);
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:18:28 +04:00
|
|
|
// close event is not being called here
|
2017-05-17 11:55:42 +03:00
|
|
|
void SettingsDialog::reject()
|
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2013-09-20 16:18:28 +04:00
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void SettingsDialog::accept()
|
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2013-09-20 16:18:28 +04:00
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
void SettingsDialog::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::StyleChange:
|
|
|
|
case QEvent::PaletteChange:
|
|
|
|
case QEvent::ThemeChange:
|
|
|
|
customizeStyle();
|
2019-12-09 22:47:42 +03:00
|
|
|
|
|
|
|
// Notify the other widgets (Dark-/Light-Mode switching)
|
|
|
|
emit styleChanged();
|
2015-08-11 18:56:02 +03:00
|
|
|
break;
|
2019-12-21 05:04:31 +03:00
|
|
|
case QEvent::ActivationChange:
|
|
|
|
if(isActiveWindow())
|
|
|
|
emit onActivate();
|
2015-08-11 18:56:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::changeEvent(e);
|
|
|
|
}
|
|
|
|
|
2014-12-01 13:37:06 +03:00
|
|
|
void SettingsDialog::slotSwitchPage(QAction *action)
|
2014-08-15 17:01:01 +04:00
|
|
|
{
|
2015-08-11 12:30:58 +03:00
|
|
|
_ui->stack->setCurrentWidget(_actionGroupWidgets.value(action));
|
2014-08-15 17:01:01 +04:00
|
|
|
}
|
|
|
|
|
2015-08-19 16:51:48 +03:00
|
|
|
void SettingsDialog::showFirstPage()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
QList<QAction *> actions = _toolBar->actions();
|
2015-11-10 14:20:08 +03:00
|
|
|
if (!actions.empty()) {
|
|
|
|
actions.first()->trigger();
|
2015-08-19 16:51:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 14:18:59 +04:00
|
|
|
void SettingsDialog::showActivityPage()
|
|
|
|
{
|
2018-04-02 18:46:26 +03:00
|
|
|
if (auto account = qvariant_cast<AccountState*>(sender()->property("account"))) {
|
2018-03-26 22:02:03 +03:00
|
|
|
_activitySettings[account]->show();
|
2018-04-02 18:46:26 +03:00
|
|
|
_ui->stack->setCurrentWidget(_activitySettings[account]);
|
2014-12-01 15:08:49 +03:00
|
|
|
}
|
2013-11-29 14:18:59 +04:00
|
|
|
}
|
|
|
|
|
2018-11-09 14:12:25 +03:00
|
|
|
void SettingsDialog::showIssuesList(AccountState *account) {
|
|
|
|
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
|
|
|
|
if (it.value() == _activitySettings[account]) {
|
|
|
|
it.key()->activate(QAction::ActionEvent::Trigger);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 18:46:26 +03:00
|
|
|
void SettingsDialog::activityAdded(AccountState *s){
|
|
|
|
_ui->stack->addWidget(_activitySettings[s]);
|
|
|
|
connect(_activitySettings[s], &ActivitySettings::guiLog, _gui,
|
|
|
|
&ownCloudGui::slotShowOptionalTrayMessage);
|
|
|
|
|
|
|
|
ConfigFile cfg;
|
|
|
|
_activitySettings[s]->setNotificationRefreshInterval(cfg.notificationRefreshInterval());
|
|
|
|
|
|
|
|
// Note: all the actions have a '\n' because the account name is in two lines and
|
|
|
|
// all buttons must have the same size in order to keep a good layout
|
|
|
|
QAction *action = createColorAwareAction(QLatin1String(":/client/resources/activity.png"), tr("Activity"));
|
|
|
|
action->setProperty("account", QVariant::fromValue(s));
|
|
|
|
_toolBar->insertAction(_actionBefore, action);
|
|
|
|
_actionGroup->addAction(action);
|
|
|
|
_actionGroupWidgets.insert(action, _activitySettings[s]);
|
|
|
|
connect(action, &QAction::triggered, this, &SettingsDialog::showActivityPage);
|
|
|
|
}
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
void SettingsDialog::accountAdded(AccountState *s)
|
|
|
|
{
|
2015-08-30 16:20:35 +03:00
|
|
|
auto height = _toolBar->sizeHint().height();
|
2016-01-07 19:58:23 +03:00
|
|
|
bool brandingSingleAccount = !Theme::instance()->multiAccount();
|
|
|
|
|
2018-05-12 01:18:38 +03:00
|
|
|
_activitySettings[s] = new ActivitySettings(s, this);
|
2018-07-07 18:16:03 +03:00
|
|
|
|
2019-12-02 16:10:18 +03:00
|
|
|
|
|
|
|
|
2018-07-07 18:16:03 +03:00
|
|
|
// if this is not the first account, then before we continue to add more accounts we add a separator
|
2018-05-12 01:18:38 +03:00
|
|
|
if(AccountManager::instance()->accounts().first().data() != s &&
|
|
|
|
AccountManager::instance()->accounts().size() >= 1){
|
|
|
|
_actionGroupWidgets.insert(_toolBar->insertSeparator(_actionBefore), _activitySettings[s]);
|
|
|
|
}
|
|
|
|
|
2017-01-22 15:58:36 +03:00
|
|
|
QAction *accountAction;
|
2017-03-10 00:34:36 +03:00
|
|
|
QImage avatar = s->account()->avatar();
|
2017-01-22 15:58:36 +03:00
|
|
|
const QString actionText = brandingSingleAccount ? tr("Account") : s->account()->displayName();
|
2017-05-17 11:55:42 +03:00
|
|
|
if (avatar.isNull()) {
|
2017-01-22 15:58:36 +03:00
|
|
|
accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
|
2017-05-17 11:55:42 +03:00
|
|
|
actionText);
|
2017-01-22 15:58:36 +03:00
|
|
|
} else {
|
2017-11-21 12:18:15 +03:00
|
|
|
QIcon icon(QPixmap::fromImage(AvatarJob::makeCircularAvatar(avatar)));
|
2017-01-22 15:58:36 +03:00
|
|
|
accountAction = createActionWithIcon(icon, actionText);
|
|
|
|
}
|
|
|
|
|
2016-01-07 19:58:23 +03:00
|
|
|
if (!brandingSingleAccount) {
|
|
|
|
accountAction->setToolTip(s->account()->displayName());
|
2017-10-06 13:01:10 +03:00
|
|
|
accountAction->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio));
|
2016-01-07 19:58:23 +03:00
|
|
|
}
|
2018-04-02 18:46:26 +03:00
|
|
|
|
|
|
|
_toolBar->insertAction(_actionBefore, accountAction);
|
2015-04-17 18:56:17 +03:00
|
|
|
auto accountSettings = new AccountSettings(s, this);
|
2017-05-17 11:55:42 +03:00
|
|
|
_ui->stack->insertWidget(0, accountSettings);
|
2015-08-11 12:30:58 +03:00
|
|
|
_actionGroup->addAction(accountAction);
|
|
|
|
_actionGroupWidgets.insert(accountAction, accountSettings);
|
2017-01-22 15:58:36 +03:00
|
|
|
_actionForAccount.insert(s->account().data(), accountAction);
|
2018-06-18 14:07:51 +03:00
|
|
|
accountAction->trigger();
|
2015-04-17 18:56:17 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged);
|
|
|
|
connect(accountSettings, &AccountSettings::openFolderAlias,
|
|
|
|
_gui, &ownCloudGui::slotFolderOpenAction);
|
2018-11-09 14:12:25 +03:00
|
|
|
connect(accountSettings, &AccountSettings::showIssuesList, this, &SettingsDialog::showIssuesList);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(s->account().data(), &Account::accountChangedAvatar, this, &SettingsDialog::slotAccountAvatarChanged);
|
2017-10-05 22:08:38 +03:00
|
|
|
connect(s->account().data(), &Account::accountChangedDisplayName, this, &SettingsDialog::slotAccountDisplayNameChanged);
|
2015-11-02 00:29:37 +03:00
|
|
|
|
2018-07-10 18:07:54 +03:00
|
|
|
// Refresh immediatly when getting online
|
2018-07-05 18:55:37 +03:00
|
|
|
connect(s, &AccountState::isConnectedChanged, this, &SettingsDialog::slotRefreshActivityAccountStateSender);
|
2018-02-08 19:20:50 +03:00
|
|
|
|
2019-12-19 21:50:21 +03:00
|
|
|
// Connect styleChanged event, to adapt (Dark-/Light-Mode switching)
|
|
|
|
connect(this, &SettingsDialog::styleChanged, accountSettings, &AccountSettings::slotStyleChanged);
|
|
|
|
connect(this, &SettingsDialog::styleChanged, _activitySettings[s], &ActivitySettings::slotStyleChanged);
|
|
|
|
|
2018-04-02 18:46:26 +03:00
|
|
|
activityAdded(s);
|
|
|
|
slotRefreshActivity(s);
|
2015-04-17 18:56:17 +03:00
|
|
|
}
|
|
|
|
|
2017-01-22 15:58:36 +03:00
|
|
|
void SettingsDialog::slotAccountAvatarChanged()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
Account *account = static_cast<Account *>(sender());
|
|
|
|
if (account && _actionForAccount.contains(account)) {
|
2017-01-22 15:58:36 +03:00
|
|
|
QAction *action = _actionForAccount[account];
|
2017-05-17 11:55:42 +03:00
|
|
|
if (action) {
|
2017-03-10 00:34:36 +03:00
|
|
|
QImage pix = account->avatar();
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!pix.isNull()) {
|
2017-11-21 12:18:15 +03:00
|
|
|
action->setIcon(QPixmap::fromImage(AvatarJob::makeCircularAvatar(pix)));
|
2017-01-22 15:58:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 22:08:38 +03:00
|
|
|
void SettingsDialog::slotAccountDisplayNameChanged()
|
|
|
|
{
|
|
|
|
Account *account = static_cast<Account *>(sender());
|
|
|
|
if (account && _actionForAccount.contains(account)) {
|
|
|
|
QAction *action = _actionForAccount[account];
|
|
|
|
if (action) {
|
|
|
|
QString displayName = account->displayName();
|
|
|
|
action->setText(displayName);
|
|
|
|
auto height = _toolBar->sizeHint().height();
|
2017-10-06 13:01:10 +03:00
|
|
|
action->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(account, height * buttonSizeRatio));
|
2017-10-05 22:08:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
void SettingsDialog::accountRemoved(AccountState *s)
|
|
|
|
{
|
2015-08-11 12:30:58 +03:00
|
|
|
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
|
2015-04-17 18:56:17 +03:00
|
|
|
auto as = qobject_cast<AccountSettings *>(*it);
|
|
|
|
if (!as) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (as->accountsState() == s) {
|
2015-10-23 17:19:40 +03:00
|
|
|
_toolBar->removeAction(it.key());
|
2015-08-11 12:30:58 +03:00
|
|
|
|
2015-11-26 15:26:19 +03:00
|
|
|
if (_ui->stack->currentWidget() == it.value()) {
|
|
|
|
showFirstPage();
|
|
|
|
}
|
2016-03-31 09:56:26 +03:00
|
|
|
|
|
|
|
it.key()->deleteLater();
|
|
|
|
it.value()->deleteLater();
|
|
|
|
_actionGroupWidgets.erase(it);
|
2015-04-17 18:56:17 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 17:39:07 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (_actionForAccount.contains(s->account().data())) {
|
2017-01-22 15:58:36 +03:00
|
|
|
_actionForAccount.remove(s->account().data());
|
|
|
|
}
|
2018-04-05 11:59:50 +03:00
|
|
|
|
|
|
|
if(_activitySettings.contains(s)){
|
|
|
|
_activitySettings[s]->slotRemoveAccount();
|
|
|
|
_activitySettings[s]->hide();
|
2018-07-07 18:16:03 +03:00
|
|
|
|
2018-04-05 11:59:50 +03:00
|
|
|
// get the settings widget and the separator
|
|
|
|
foreach(QAction *action, _actionGroupWidgets.keys(_activitySettings[s])){
|
|
|
|
_actionGroupWidgets.remove(action);
|
|
|
|
_toolBar->removeAction(action);
|
|
|
|
}
|
2018-07-11 14:34:17 +03:00
|
|
|
_toolBar->widgetForAction(_actionBefore)->hide();
|
2018-04-05 11:59:50 +03:00
|
|
|
_activitySettings.remove(s);
|
|
|
|
}
|
2015-12-09 13:41:43 +03:00
|
|
|
|
|
|
|
// Hide when the last account is deleted. We want to enter the same
|
|
|
|
// state we'd be in the client was started up without an account
|
|
|
|
// configured.
|
|
|
|
if (AccountManager::instance()->accounts().isEmpty()) {
|
|
|
|
hide();
|
|
|
|
}
|
2015-04-17 18:56:17 +03:00
|
|
|
}
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
void SettingsDialog::customizeStyle()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
QString highlightColor(palette().highlight().color().name());
|
2019-12-01 22:33:10 +03:00
|
|
|
QString highlightTextColor(palette().highlightedText().color().name());
|
2015-08-11 18:56:02 +03:00
|
|
|
QString dark(palette().dark().color().name());
|
|
|
|
QString background(palette().base().color().name());
|
2019-12-01 22:33:10 +03:00
|
|
|
_toolBar->setStyleSheet(QString::fromLatin1(TOOLBAR_CSS).arg(background, dark, highlightColor, highlightTextColor));
|
2015-08-11 18:56:02 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
Q_FOREACH (QAction *a, _actionGroup->actions()) {
|
2019-12-09 22:34:27 +03:00
|
|
|
QIcon icon = Theme::createColorAwareIcon(a->property("iconPath").toString(), palette());
|
2015-08-11 18:56:02 +03:00
|
|
|
a->setIcon(icon);
|
2017-05-17 11:55:42 +03:00
|
|
|
QToolButton *btn = qobject_cast<QToolButton *>(_toolBar->widgetForAction(a));
|
2018-05-12 01:18:38 +03:00
|
|
|
if (btn)
|
2015-08-11 18:56:02 +03:00
|
|
|
btn->setIcon(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 17:19:40 +03:00
|
|
|
class ToolButtonAction : public QWidgetAction
|
|
|
|
{
|
|
|
|
public:
|
2017-05-17 11:55:42 +03:00
|
|
|
explicit ToolButtonAction(const QIcon &icon, const QString &text, QObject *parent)
|
|
|
|
: QWidgetAction(parent)
|
|
|
|
{
|
2015-10-23 17:19:40 +03:00
|
|
|
setText(text);
|
|
|
|
setIcon(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-11 13:09:29 +03:00
|
|
|
QWidget *createWidget(QWidget *parent) override
|
2017-05-17 11:55:42 +03:00
|
|
|
{
|
|
|
|
auto toolbar = qobject_cast<QToolBar *>(parent);
|
2015-10-23 17:19:40 +03:00
|
|
|
if (!toolbar) {
|
|
|
|
// this means we are in the extention menu, no special action here
|
2018-11-11 12:56:22 +03:00
|
|
|
return nullptr;
|
2015-10-23 17:19:40 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QToolButton *btn = new QToolButton(parent);
|
2015-10-23 17:19:40 +03:00
|
|
|
btn->setDefaultAction(this);
|
|
|
|
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QAction *SettingsDialog::createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath)
|
2017-01-22 15:58:36 +03:00
|
|
|
{
|
|
|
|
QAction *action = new ToolButtonAction(icon, text, this);
|
|
|
|
action->setCheckable(true);
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!iconPath.isEmpty()) {
|
2017-01-22 15:58:36 +03:00
|
|
|
action->setProperty("iconPath", iconPath);
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2015-08-11 18:56:02 +03:00
|
|
|
QAction *SettingsDialog::createColorAwareAction(const QString &iconPath, const QString &text)
|
|
|
|
{
|
|
|
|
// all buttons must have the same size in order to keep a good layout
|
2019-12-09 22:34:27 +03:00
|
|
|
QIcon coloredIcon = Theme::createColorAwareIcon(iconPath, palette());
|
2017-01-22 15:58:36 +03:00
|
|
|
return createActionWithIcon(coloredIcon, text, iconPath);
|
2015-08-11 18:56:02 +03:00
|
|
|
}
|
2015-04-17 18:56:17 +03:00
|
|
|
|
2018-02-08 19:20:50 +03:00
|
|
|
void SettingsDialog::slotRefreshActivityAccountStateSender()
|
|
|
|
{
|
|
|
|
slotRefreshActivity(qobject_cast<AccountState*>(sender()));
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void SettingsDialog::slotRefreshActivity(AccountState *accountState)
|
2015-11-04 18:40:22 +03:00
|
|
|
{
|
2018-07-06 12:14:41 +03:00
|
|
|
if (accountState->isConnected())
|
2018-04-02 18:46:26 +03:00
|
|
|
_activitySettings[accountState]->slotRefresh();
|
2015-11-04 18:40:22 +03:00
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|