nextcloud-desktop/src/gui/settingsdialogmac.cpp

137 lines
4.8 KiB
C++
Raw Normal View History

/*
* 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
* 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 "settingsdialogmac.h"
#include "macstandardicon.h"
#include "folderman.h"
#include "theme.h"
#include "generalsettings.h"
#include "networksettings.h"
#include "accountsettings.h"
#include "creds/abstractcredentials.h"
2014-11-10 01:25:57 +03:00
#include "configfile.h"
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "protocolwidget.h"
#include "accountmanager.h"
#include <QLabel>
#include <QStandardItemModel>
#include <QPushButton>
#include <QDebug>
#include <QSettings>
2014-11-10 00:34:07 +03:00
namespace OCC {
//
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp !
//
SettingsDialogMac::SettingsDialogMac(ownCloudGui *gui, QWidget *parent)
: MacPreferencesWindow(parent), _gui(gui)
{
// do not show minimize button. There is no use, and restoring the
// dialog from minimize is broken in MacPreferencesWindow
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint |
Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
// Emulate dialog behavior: Escape means close
QAction *closeDialogAction = new QAction(this);
closeDialogAction->setShortcut(QKeySequence(Qt::Key_Escape));
connect(closeDialogAction, &QAction::triggered, this, &SettingsDialogMac::close);
addAction(closeDialogAction);
// People perceive this as a Window, so also make Ctrl+W work
QAction *closeWindowAction = new QAction(this);
closeWindowAction->setShortcut(QKeySequence("Ctrl+W"));
connect(closeWindowAction, &QAction::triggered, this, &SettingsDialogMac::close);
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"));
connect(hideWindowAction, &QAction::triggered, this, &SettingsDialogMac::hide);
2014-09-30 17:21:55 +04:00
addAction(hideWindowAction);
setObjectName("SettingsMac"); // required as group for saveGeometry call
setWindowTitle(tr("%1").arg(Theme::instance()->appNameGUI()));
connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &SettingsDialogMac::accountAdded);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
this, &SettingsDialogMac::accountRemoved);
foreach (auto ai , AccountManager::instance()->accounts()) {
accountAdded(ai.data());
}
2014-12-08 20:00:29 +03:00
QIcon protocolIcon(QLatin1String(":/client/resources/activity.png"));
_protocolWidget = new ProtocolWidget;
addPreferencesPanel(protocolIcon, tr("Activity"), _protocolWidget);
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"));
connect(showLogWindow, &QAction::triggered, gui, &ownCloudGui::slotToggleLogBrowser);
addAction(showLogWindow);
2014-11-10 00:30:29 +03:00
ConfigFile cfg;
cfg.restoreGeometry(this);
}
void SettingsDialogMac::closeEvent(QCloseEvent *event)
{
2014-11-10 00:30:29 +03:00
ConfigFile cfg;
cfg.saveGeometry(this);
MacPreferencesWindow::closeEvent(event);
}
void SettingsDialogMac::showActivityPage()
{
// Count backwards (0-based) from the last panel (multiple accounts can be on the left)
setCurrentPanelIndex(preferencePanelCount() - 1 - 2);
}
void SettingsDialogMac::accountAdded(AccountState *s)
{
QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts);
auto accountSettings = new AccountSettings(s, this);
QString displayName = s->shortDisplayNameForSettings();
insertPreferencesPanel(0, accountIcon, displayName, accountSettings);
connect( accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged);
connect( accountSettings, &AccountSettings::openFolderAlias, _gui, &ownCloudGui::slotFolderOpenAction);
}
void SettingsDialogMac::accountRemoved(AccountState *s)
{
auto list = findChildren<AccountSettings*>(QString());
foreach(auto p, list) {
if (p->accountsState() == s) {
removePreferencesPanel(p);
}
}
}
}