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
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "protocolwidget.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>
|
|
|
|
#include <QDebug>
|
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>
|
2014-12-01 13:37:06 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char TOOLBAR_CSS[] =
|
2015-08-11 09:43:36 +03:00
|
|
|
"QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } "
|
|
|
|
"QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 0; } "
|
2015-08-10 21:13:20 +03:00
|
|
|
"QToolBar QToolButton:checked { background: %3; color: %4; }";
|
2015-08-10 11:50:57 +03:00
|
|
|
|
|
|
|
void addActionToToolBar(QAction *action, QToolBar *tb) {
|
|
|
|
QToolButton* btn = new QToolButton;
|
|
|
|
btn->setDefaultAction(action);
|
|
|
|
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
tb->addWidget(btn);
|
|
|
|
}
|
2014-12-01 13:37:06 +03:00
|
|
|
}
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2015-03-11 18:41:37 +03:00
|
|
|
//
|
|
|
|
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp !
|
|
|
|
//
|
2013-10-01 15:52:07 +04:00
|
|
|
SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
|
2014-12-01 15:08:49 +03:00
|
|
|
QDialog(parent)
|
2015-04-17 18:56:17 +03:00
|
|
|
, _ui(new Ui::SettingsDialog), _gui(gui)
|
2014-12-01 15:08:49 +03:00
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2013-11-13 23:12:56 +04:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2013-07-04 21:59:40 +04:00
|
|
|
_ui->setupUi(this);
|
2014-12-01 13:37:06 +03:00
|
|
|
QToolBar *toolBar = new QToolBar;
|
|
|
|
QString highlightColor(palette().highlight().color().name());
|
|
|
|
QString altBase(palette().alternateBase().color().name());
|
2015-02-06 10:30:20 +03:00
|
|
|
QString dark(palette().dark().color().name());
|
2015-08-10 21:13:20 +03:00
|
|
|
QString background(palette().base().color().name());
|
|
|
|
toolBar->setStyleSheet(QString::fromAscii(TOOLBAR_CSS).arg(background).arg(dark).arg(highlightColor).arg(altBase));
|
2015-08-10 11:50:57 +03:00
|
|
|
toolBar->setIconSize(QSize(32, 32));
|
2014-12-01 13:37:06 +03:00
|
|
|
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"));
|
|
|
|
connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept()));
|
|
|
|
addAction(closeWindowAction);
|
|
|
|
|
2015-08-10 11:50:57 +03:00
|
|
|
|
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
|
|
|
|
2015-07-03 12:04:03 +03:00
|
|
|
// Add a spacer so config buttonns are right aligned and account buttons will be left aligned
|
|
|
|
auto spacer = new QWidget();
|
|
|
|
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
toolBar->addWidget(spacer);
|
2015-08-10 11:50:57 +03:00
|
|
|
QActionGroup *group = new QActionGroup(this);
|
|
|
|
group->setExclusive(true);
|
2015-07-03 12:04:03 +03:00
|
|
|
|
2015-08-05 15:49:16 +03:00
|
|
|
// 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
|
2014-12-08 20:00:29 +03:00
|
|
|
QIcon protocolIcon(QLatin1String(":/client/resources/activity.png"));
|
2015-08-10 11:50:57 +03:00
|
|
|
_protocolAction = group->addAction(protocolIcon, tr("Activity"));
|
2014-12-01 13:37:06 +03:00
|
|
|
_protocolAction->setCheckable(true);
|
2015-08-10 11:50:57 +03:00
|
|
|
addActionToToolBar(_protocolAction, toolBar);
|
2014-12-01 13:37:06 +03:00
|
|
|
ProtocolWidget *protocolWidget = new ProtocolWidget;
|
|
|
|
_ui->stack->addWidget(protocolWidget);
|
2013-10-08 16:12:05 +04:00
|
|
|
|
2014-12-08 20:00:29 +03:00
|
|
|
QIcon generalIcon(QLatin1String(":/client/resources/settings.png"));
|
2015-08-10 11:50:57 +03:00
|
|
|
QAction *generalAction = group->addAction(generalIcon, tr("General"));
|
2014-12-01 13:37:06 +03:00
|
|
|
generalAction->setCheckable(true);
|
2015-08-10 11:50:57 +03:00
|
|
|
addActionToToolBar(generalAction, toolBar);
|
2013-07-04 21:59:40 +04:00
|
|
|
GeneralSettings *generalSettings = new GeneralSettings;
|
|
|
|
_ui->stack->addWidget(generalSettings);
|
|
|
|
|
2014-12-08 20:00:29 +03:00
|
|
|
QIcon networkIcon(QLatin1String(":/client/resources/network.png"));
|
2015-08-10 11:50:57 +03:00
|
|
|
QAction *networkAction = group->addAction(networkIcon, tr("Network"));
|
2014-12-01 13:37:06 +03:00
|
|
|
networkAction->setCheckable(true);
|
2015-08-10 11:50:57 +03:00
|
|
|
addActionToToolBar(networkAction, toolBar);
|
2013-07-24 21:53:05 +04:00
|
|
|
NetworkSettings *networkSettings = new NetworkSettings;
|
|
|
|
_ui->stack->addWidget(networkSettings);
|
|
|
|
|
2014-12-01 13:37:06 +03:00
|
|
|
_actions.insert(_protocolAction, protocolWidget);
|
|
|
|
_actions.insert(generalAction, generalSettings);
|
|
|
|
_actions.insert(networkAction, networkSettings);
|
|
|
|
|
|
|
|
connect(group, SIGNAL(triggered(QAction*)), SLOT(slotSwitchPage(QAction*)));
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
|
|
|
|
this, SLOT(accountAdded(AccountState*)));
|
|
|
|
connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
|
|
|
|
this, SLOT(accountRemoved(AccountState*)));
|
|
|
|
foreach (auto ai , AccountManager::instance()->accounts()) {
|
|
|
|
accountAdded(ai.data());
|
|
|
|
}
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2014-12-01 13:37:06 +03:00
|
|
|
// default to Account
|
2015-04-28 12:39:27 +03:00
|
|
|
toolBar->actions().at(0)->trigger();
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
|
2013-12-21 06:36:43 +04:00
|
|
|
connect(closeButton, SIGNAL(clicked()), SLOT(accept()));
|
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"));
|
2013-10-02 17:28:33 +04:00
|
|
|
connect(showLogWindow, SIGNAL(triggered()), gui, SLOT(slotToggleLogBrowser()));
|
2013-08-14 19:46:58 +04:00
|
|
|
addAction(showLogWindow);
|
|
|
|
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-12-01 13:37:06 +03:00
|
|
|
void SettingsDialog::slotSwitchPage(QAction *action)
|
2014-08-15 17:01:01 +04:00
|
|
|
{
|
2014-12-01 13:37:06 +03:00
|
|
|
_ui->stack->setCurrentWidget(_actions.value(action));
|
2014-08-15 17:01:01 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 14:18:59 +04:00
|
|
|
void SettingsDialog::showActivityPage()
|
|
|
|
{
|
2014-12-01 15:08:49 +03:00
|
|
|
if (_protocolAction) {
|
|
|
|
slotSwitchPage(_protocolAction);
|
|
|
|
}
|
2013-11-29 14:18:59 +04:00
|
|
|
}
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
void SettingsDialog::accountAdded(AccountState *s)
|
|
|
|
{
|
|
|
|
QIcon accountIcon(QLatin1String(":/client/resources/account.png"));
|
|
|
|
auto toolBar = qobject_cast<QToolBar*>(layout()->menuBar());
|
|
|
|
Q_ASSERT(toolBar);
|
2015-08-05 15:49:16 +03:00
|
|
|
auto accountAction = new QAction(accountIcon, s->shortDisplayNameForSettings(), this);
|
|
|
|
accountAction->setToolTip(s->account()->displayName());
|
2015-04-17 18:56:17 +03:00
|
|
|
accountAction->setCheckable(true);
|
2015-08-10 11:50:57 +03:00
|
|
|
|
|
|
|
QToolButton* accountButton = new QToolButton;
|
|
|
|
accountButton->setDefaultAction(accountAction);
|
|
|
|
accountButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
toolBar->insertWidget(toolBar->actions().at(0), accountButton);
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
auto accountSettings = new AccountSettings(s, this);
|
|
|
|
_ui->stack->insertWidget(0 , accountSettings);
|
|
|
|
_actions.insert(accountAction, accountSettings);
|
|
|
|
|
2015-06-02 20:57:41 +03:00
|
|
|
auto group = findChild<QActionGroup*>(
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
QString() , Qt::FindDirectChildrenOnly
|
|
|
|
#endif
|
|
|
|
);
|
2015-04-17 18:56:17 +03:00
|
|
|
Q_ASSERT(group);
|
|
|
|
group->addAction(accountAction);
|
|
|
|
|
|
|
|
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged()));
|
|
|
|
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)),
|
|
|
|
_gui, SLOT(slotFolderOpenAction(QString)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::accountRemoved(AccountState *s)
|
|
|
|
{
|
|
|
|
for (auto it = _actions.begin(); it != _actions.end(); ++it) {
|
|
|
|
auto as = qobject_cast<AccountSettings *>(*it);
|
|
|
|
if (!as) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (as->accountsState() == s) {
|
|
|
|
delete it.key();
|
|
|
|
delete it.value();
|
|
|
|
_actions.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 14:18:59 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|