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"
|
|
|
|
|
2013-07-22 15:59:52 +04:00
|
|
|
#include "mirall/folderman.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
#include "mirall/theme.h"
|
|
|
|
#include "mirall/generalsettings.h"
|
2013-07-24 21:53:05 +04:00
|
|
|
#include "mirall/networksettings.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
#include "mirall/accountsettings.h"
|
|
|
|
#include "mirall/application.h"
|
2013-07-08 06:01:26 +04:00
|
|
|
#include "mirall/mirallconfigfile.h"
|
2013-07-05 20:46:43 +04:00
|
|
|
#include "mirall/progressdispatcher.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QDebug>
|
2013-07-08 06:01:26 +04:00
|
|
|
#include <QSettings>
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
QIcon createDummy() {
|
|
|
|
QIcon icon;
|
|
|
|
QPixmap p(32,32);
|
|
|
|
p.fill(Qt::transparent);
|
|
|
|
icon.addPixmap(p);
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(Application *app, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
2013-07-22 15:59:52 +04:00
|
|
|
_ui(new Ui::SettingsDialog)
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
2013-07-22 14:28:43 +04:00
|
|
|
setObjectName("Settings"); // required as group for saveGeometry call
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-08-15 13:30:39 +04:00
|
|
|
setWindowTitle(tr("%1").arg(Theme::instance()->appNameGUI()));
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-08-16 17:09:54 +04:00
|
|
|
_accountSettings = new AccountSettings(this);
|
|
|
|
addAccount(tr("Account"), _accountSettings);
|
|
|
|
slotUpdateAccountState();
|
|
|
|
|
2013-07-20 00:14:07 +04:00
|
|
|
QIcon generalIcon(QLatin1String(":/mirall/resources/settings.png"));
|
|
|
|
QListWidgetItem *general = new QListWidgetItem(generalIcon, tr("General"), _ui->labelWidget);
|
2013-07-04 21:59:40 +04:00
|
|
|
general->setSizeHint(QSize(0, 32));
|
|
|
|
_ui->labelWidget->addItem(general);
|
|
|
|
GeneralSettings *generalSettings = new GeneralSettings;
|
|
|
|
_ui->stack->addWidget(generalSettings);
|
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
QIcon networkIcon(QLatin1String(":/mirall/resources/network.png"));
|
|
|
|
QListWidgetItem *network = new QListWidgetItem(networkIcon, tr("Network"), _ui->labelWidget);
|
|
|
|
network->setSizeHint(QSize(0, 32));
|
|
|
|
_ui->labelWidget->addItem(network);
|
|
|
|
NetworkSettings *networkSettings = new NetworkSettings;
|
|
|
|
_ui->stack->addWidget(networkSettings);
|
|
|
|
connect(networkSettings, SIGNAL(proxySettingsChanged()), app, SLOT(slotSetupProxy()));
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
//connect(generalSettings, SIGNAL(resizeToSizeHint()), SLOT(resizeToSizeHint()));
|
|
|
|
|
|
|
|
connect( app, SIGNAL(folderStateChanged(Folder*)), _accountSettings, SLOT(slotUpdateFolderState(Folder*)));
|
2013-07-22 14:11:12 +04:00
|
|
|
connect( app, SIGNAL(folderStateChanged(Folder*)), SLOT(slotUpdateAccountState()));
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
connect( _accountSettings, SIGNAL(folderChanged()), app, SLOT(slotFoldersChanged()));
|
|
|
|
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
|
|
|
|
app, SLOT(slotFolderOpenAction(QString)));
|
2013-08-02 13:33:45 +04:00
|
|
|
connect( _accountSettings, SIGNAL(openProgressDialog()), app, SLOT(slotItemProgressDialog()));
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-07-26 15:44:38 +04:00
|
|
|
connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, Progress::Info)),
|
|
|
|
_accountSettings, SLOT(slotSetProgress(QString, Progress::Info)) );
|
2013-08-02 16:22:01 +04:00
|
|
|
connect( ProgressDispatcher::instance(), SIGNAL(progressSyncProblem(QString,Progress::SyncProblem)),
|
|
|
|
_accountSettings, SLOT(slotProgressProblem(QString,Progress::SyncProblem)) );
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2013-08-16 17:09:54 +04:00
|
|
|
_ui->labelWidget->setCurrentRow(_ui->labelWidget->row(_accountItem));
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
connect(_ui->labelWidget, SIGNAL(currentRowChanged(int)),
|
|
|
|
_ui->stack, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
|
|
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
|
2013-07-20 03:27:00 +04:00
|
|
|
connect(closeButton, SIGNAL(pressed()), 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"));
|
|
|
|
connect(showLogWindow, SIGNAL(triggered()), app, SLOT(slotOpenLogBrowser()));
|
|
|
|
addAction(showLogWindow);
|
|
|
|
|
2013-09-20 12:40:22 +04:00
|
|
|
int iconSize = 32;
|
|
|
|
QListWidget *listWidget = _ui->labelWidget;
|
|
|
|
int spacing = 20;
|
|
|
|
// reverse at least ~8 characters
|
|
|
|
int effectiveWidth = fontMetrics().averageCharWidth() * 8 + iconSize + spacing;
|
|
|
|
// less than ~16 characters, elide otherwise
|
|
|
|
int maxWidth = fontMetrics().averageCharWidth() * 16 + iconSize + spacing;
|
|
|
|
for (int i = 0; i < listWidget->count(); i++) {
|
|
|
|
QListWidgetItem *item = listWidget->item(i);
|
|
|
|
QFontMetrics fm(item->font());
|
|
|
|
int curWidth = fm.width(item->text()) + iconSize + spacing;
|
|
|
|
effectiveWidth = qMax(curWidth, effectiveWidth);
|
|
|
|
if (curWidth > maxWidth) item->setToolTip(item->text());
|
|
|
|
}
|
|
|
|
effectiveWidth = qMin(effectiveWidth, maxWidth);
|
|
|
|
listWidget->setFixedWidth(effectiveWidth);
|
|
|
|
|
2013-07-08 06:01:26 +04:00
|
|
|
MirallConfigFile cfg;
|
2013-07-22 14:28:43 +04:00
|
|
|
cfg.restoreGeometry(this);
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::addAccount(const QString &title, QWidget *widget)
|
|
|
|
{
|
2013-07-22 14:11:12 +04:00
|
|
|
_accountItem = new QListWidgetItem(Theme::instance()->syncStateIcon(SyncResult::Undefined, true), title);
|
|
|
|
_accountItem->setSizeHint(QSize(0, 32));
|
|
|
|
_ui->labelWidget->addItem(_accountItem);
|
2013-07-04 21:59:40 +04:00
|
|
|
_ui->stack->addWidget(widget);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:11:12 +04:00
|
|
|
void SettingsDialog::slotUpdateAccountState()
|
|
|
|
{
|
2013-07-22 15:59:52 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
SyncResult state = folderMan->accountStatus(folderMan->map().values());
|
2013-07-22 14:11:12 +04:00
|
|
|
_accountItem->setIcon(Theme::instance()->syncStateIcon(state.status()));
|
|
|
|
}
|
|
|
|
|
2013-09-11 12:24:31 +04:00
|
|
|
void SettingsDialog::setGeneralErrors(const QStringList &errors)
|
|
|
|
{
|
|
|
|
_accountSettings->setGeneralErrors(errors);
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:18:28 +04:00
|
|
|
|
|
|
|
// close event is not being called here
|
|
|
|
void SettingsDialog::reject() {
|
|
|
|
MirallConfigFile cfg;
|
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::accept() {
|
|
|
|
MirallConfigFile cfg;
|
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
} // namespace Mirall
|