2014-10-29 15:27:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Denis Dzyubenko
|
|
|
|
*
|
|
|
|
* 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.
|
2014-10-29 15:27:26 +03: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.
|
|
|
|
*/
|
|
|
|
|
2014-02-14 06:02:59 +04:00
|
|
|
#include "settingsdialogmac.h"
|
|
|
|
|
|
|
|
#include "macstandardicon.h"
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderman.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "generalsettings.h"
|
|
|
|
#include "networksettings.h"
|
|
|
|
#include "accountsettings.h"
|
2015-07-31 15:56:14 +03:00
|
|
|
#include "creds/abstractcredentials.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-11-17 13:53:49 +03:00
|
|
|
#include "activitywidget.h"
|
2015-05-26 18:36:15 +03:00
|
|
|
#include "accountmanager.h"
|
2014-02-14 06:02:59 +04:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSettings>
|
2017-04-12 18:55:28 +03:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPainterPath>
|
2014-02-14 06:02:59 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2014-02-14 06:02:59 +04:00
|
|
|
|
2017-10-06 13:01:10 +03:00
|
|
|
#include "settingsdialogcommon.cpp"
|
|
|
|
|
|
|
|
|
2017-04-12 18:55:28 +03:00
|
|
|
// Duplicate in settingsdialog.cpp
|
2017-05-17 11:55:42 +03:00
|
|
|
static QIcon circleMask(const QImage &avatar)
|
2017-04-12 18:55:28 +03:00
|
|
|
{
|
|
|
|
int dim = avatar.width();
|
|
|
|
|
|
|
|
QPixmap fixedImage(dim, dim);
|
|
|
|
fixedImage.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter imgPainter(&fixedImage);
|
|
|
|
QPainterPath clip;
|
|
|
|
clip.addEllipse(0, 0, dim, dim);
|
|
|
|
imgPainter.setClipPath(clip);
|
|
|
|
imgPainter.drawImage(0, 0, avatar);
|
|
|
|
imgPainter.end();
|
|
|
|
|
|
|
|
return QIcon(fixedImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-11 18:41:37 +03:00
|
|
|
//
|
|
|
|
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp !
|
|
|
|
//
|
2014-02-14 06:02:59 +04:00
|
|
|
SettingsDialogMac::SettingsDialogMac(ownCloudGui *gui, QWidget *parent)
|
2017-05-17 11:55:42 +03:00
|
|
|
: MacPreferencesWindow(parent)
|
|
|
|
, _gui(gui)
|
2014-02-14 06:02:59 +04:00
|
|
|
{
|
2015-10-05 07:21:19 +03:00
|
|
|
// do not show minimize button. There is no use, and restoring the
|
2014-06-20 18:27:43 +04:00
|
|
|
// dialog from minimize is broken in MacPreferencesWindow
|
2017-05-17 11:55:42 +03:00
|
|
|
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
|
2014-06-20 18:27:43 +04:00
|
|
|
|
2014-06-20 18:37:07 +04:00
|
|
|
|
|
|
|
// Emulate dialog behavior: Escape means close
|
2014-09-02 15:58:55 +04:00
|
|
|
QAction *closeDialogAction = new QAction(this);
|
|
|
|
closeDialogAction->setShortcut(QKeySequence(Qt::Key_Escape));
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(closeDialogAction, &QAction::triggered, this, &SettingsDialogMac::close);
|
2014-09-02 15:58:55 +04:00
|
|
|
addAction(closeDialogAction);
|
|
|
|
// People perceive this as a Window, so also make Ctrl+W work
|
2014-06-20 18:37:07 +04:00
|
|
|
QAction *closeWindowAction = new QAction(this);
|
2014-09-02 15:58:55 +04:00
|
|
|
closeWindowAction->setShortcut(QKeySequence("Ctrl+W"));
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(closeWindowAction, &QAction::triggered, this, &SettingsDialogMac::close);
|
2014-06-20 18:37:07 +04:00
|
|
|
addAction(closeWindowAction);
|
2014-09-30 17:21:55 +04:00
|
|
|
// People perceive this as a Window, so also make Ctrl+H work
|
|
|
|
QAction *hideWindowAction = new QAction(this);
|
|
|
|
hideWindowAction->setShortcut(QKeySequence("Ctrl+H"));
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(hideWindowAction, &QAction::triggered, this, &SettingsDialogMac::hide);
|
2014-09-30 17:21:55 +04:00
|
|
|
addAction(hideWindowAction);
|
2014-06-20 18:37:07 +04:00
|
|
|
|
2014-02-14 06:02:59 +04:00
|
|
|
setObjectName("SettingsMac"); // required as group for saveGeometry call
|
|
|
|
|
|
|
|
setWindowTitle(tr("%1").arg(Theme::instance()->appNameGUI()));
|
|
|
|
|
2015-11-17 13:53:49 +03:00
|
|
|
QIcon activityIcon(QLatin1String(":/client/resources/activity.png"));
|
|
|
|
_activitySettings = new ActivitySettings;
|
|
|
|
addPreferencesPanel(activityIcon, tr("Activity"), _activitySettings);
|
2017-05-17 11:55:42 +03:00
|
|
|
connect(_activitySettings, SIGNAL(guiLog(QString, QString)), _gui,
|
|
|
|
SLOT(slotShowOptionalTrayMessage(QString, QString)));
|
2015-11-17 13:53:49 +03:00
|
|
|
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
2017-05-17 11:55:42 +03:00
|
|
|
this, &SettingsDialogMac::accountAdded);
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(AccountManager::instance(), &AccountManager::accountRemoved,
|
2017-05-17 11:55:42 +03:00
|
|
|
this, &SettingsDialogMac::accountRemoved);
|
|
|
|
foreach (auto ai, AccountManager::instance()->accounts()) {
|
2015-05-26 18:36:15 +03:00
|
|
|
accountAdded(ai.data());
|
|
|
|
}
|
2014-02-14 06:02:59 +04:00
|
|
|
|
|
|
|
QIcon generalIcon = MacStandardIcon::icon(MacStandardIcon::PreferencesGeneral);
|
|
|
|
GeneralSettings *generalSettings = new GeneralSettings;
|
|
|
|
addPreferencesPanel(generalIcon, tr("General"), generalSettings);
|
|
|
|
|
|
|
|
QIcon networkIcon = MacStandardIcon::icon(MacStandardIcon::Network);
|
|
|
|
NetworkSettings *networkSettings = new NetworkSettings;
|
|
|
|
addPreferencesPanel(networkIcon, tr("Network"), networkSettings);
|
|
|
|
|
|
|
|
QAction *showLogWindow = new QAction(this);
|
|
|
|
showLogWindow->setShortcut(QKeySequence("F12"));
|
2015-05-26 18:36:15 +03:00
|
|
|
connect(showLogWindow, &QAction::triggered, gui, &ownCloudGui::slotToggleLogBrowser);
|
2014-02-14 06:02:59 +04:00
|
|
|
addAction(showLogWindow);
|
|
|
|
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2014-02-14 06:02:59 +04:00
|
|
|
cfg.restoreGeometry(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialogMac::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2014-02-14 06:02:59 +04:00
|
|
|
cfg.saveGeometry(this);
|
|
|
|
MacPreferencesWindow::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialogMac::showActivityPage()
|
|
|
|
{
|
2015-07-16 15:07:05 +03:00
|
|
|
// Count backwards (0-based) from the last panel (multiple accounts can be on the left)
|
|
|
|
setCurrentPanelIndex(preferencePanelCount() - 1 - 2);
|
2014-02-14 06:02:59 +04:00
|
|
|
}
|
|
|
|
|
2017-07-04 15:08:41 +03:00
|
|
|
void SettingsDialogMac::showIssuesList(const QString &folderAlias)
|
|
|
|
{
|
|
|
|
// Count backwards (0-based) from the last panel (multiple accounts can be on the left)
|
|
|
|
setCurrentPanelIndex(preferencePanelCount() - 1 - 2);
|
|
|
|
_activitySettings->slotShowIssuesTab(folderAlias);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-26 18:36:15 +03:00
|
|
|
void SettingsDialogMac::accountAdded(AccountState *s)
|
|
|
|
{
|
|
|
|
QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts);
|
|
|
|
auto accountSettings = new AccountSettings(s, this);
|
2015-07-16 15:07:05 +03:00
|
|
|
|
2017-10-06 13:01:10 +03:00
|
|
|
QString displayName = Theme::instance()->multiAccount() ? SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), 0) : tr("Account");
|
2015-07-31 15:56:14 +03:00
|
|
|
|
|
|
|
insertPreferencesPanel(0, accountIcon, displayName, accountSettings);
|
2015-05-26 18:36:15 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged);
|
|
|
|
connect(accountSettings, &AccountSettings::openFolderAlias, _gui, &ownCloudGui::slotFolderOpenAction);
|
2017-07-04 15:08:41 +03:00
|
|
|
connect(accountSettings, &AccountSettings::showIssuesList, this, &SettingsDialogMac::showIssuesList);
|
2015-11-17 13:53:49 +03:00
|
|
|
|
2017-04-12 18:55:28 +03:00
|
|
|
connect(s->account().data(), SIGNAL(accountChangedAvatar()), this, SLOT(slotAccountAvatarChanged()));
|
|
|
|
|
2015-11-17 13:53:49 +03:00
|
|
|
slotRefreshActivity(s);
|
2015-05-26 18:36:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialogMac::accountRemoved(AccountState *s)
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
auto list = findChildren<AccountSettings *>(QString());
|
|
|
|
foreach (auto p, list) {
|
2015-05-26 18:36:15 +03:00
|
|
|
if (p->accountsState() == s) {
|
2015-07-16 15:07:05 +03:00
|
|
|
removePreferencesPanel(p);
|
2015-05-26 18:36:15 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-17 13:53:49 +03:00
|
|
|
|
|
|
|
_activitySettings->slotRemoveAccount(s);
|
2015-05-26 18:36:15 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void SettingsDialogMac::slotRefreshActivity(AccountState *accountState)
|
2015-11-17 13:53:49 +03:00
|
|
|
{
|
|
|
|
if (accountState) {
|
|
|
|
_activitySettings->slotRefresh(accountState);
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 18:36:15 +03:00
|
|
|
|
2017-04-12 18:55:28 +03:00
|
|
|
void SettingsDialogMac::slotAccountAvatarChanged()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
Account *account = static_cast<Account *>(sender());
|
|
|
|
auto list = findChildren<AccountSettings *>(QString());
|
|
|
|
foreach (auto p, list) {
|
2017-04-12 18:55:28 +03:00
|
|
|
if (p->accountsState()->account() == account) {
|
|
|
|
int idx = indexForPanel(p);
|
|
|
|
QImage pix = account->avatar();
|
|
|
|
if (!pix.isNull()) {
|
|
|
|
setPreferencesPanelIcon(idx, circleMask(pix));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 06:02:59 +04:00
|
|
|
}
|