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"
|
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-10-01 15:52:07 +04:00
|
|
|
#include "mirall/owncloudgui.h"
|
2013-10-08 16:12:05 +04:00
|
|
|
#include "mirall/protocolwidget.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QDebug>
|
2013-11-15 18:45:21 +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;
|
|
|
|
}
|
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
|
2013-07-04 21:59:40 +04:00
|
|
|
QDialog(parent),
|
2013-07-22 15:59:52 +04:00
|
|
|
_ui(new Ui::SettingsDialog)
|
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);
|
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);
|
|
|
|
|
2013-11-28 12:47:49 +04:00
|
|
|
QIcon protocolIcon(QLatin1String(":/mirall/resources/activity.png"));
|
2013-11-28 12:41:36 +04:00
|
|
|
QListWidgetItem *protocol= new QListWidgetItem(protocolIcon, tr("Activity"), _ui->labelWidget);
|
2013-10-08 16:12:05 +04:00
|
|
|
protocol->setSizeHint(QSize(0, 32));
|
|
|
|
_ui->labelWidget->addItem(protocol);
|
2013-11-25 01:20:43 +04:00
|
|
|
_protocolWidget = new ProtocolWidget;
|
|
|
|
_protocolIdx = _ui->stack->addWidget(_protocolWidget);
|
2013-10-08 16:12:05 +04:00
|
|
|
|
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);
|
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
connect( folderMan, SIGNAL(folderSyncStateChange(QString)),
|
|
|
|
this, SLOT(slotSyncStateChange(QString)));
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
connect( _accountSettings, SIGNAL(folderChanged()), gui, SLOT(slotFoldersChanged()));
|
2013-07-04 21:59:40 +04:00
|
|
|
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
|
2013-10-01 15:52:07 +04:00
|
|
|
gui, SLOT(slotFolderOpenAction(QString)));
|
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-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-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);
|
|
|
|
|
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)
|
|
|
|
{
|
2014-02-22 00:02:35 +04:00
|
|
|
_accountItem = new QListWidgetItem(title);
|
2013-07-22 14:11:12 +04:00
|
|
|
_accountItem->setSizeHint(QSize(0, 32));
|
|
|
|
_ui->labelWidget->addItem(_accountItem);
|
2013-07-04 21:59:40 +04:00
|
|
|
_ui->stack->addWidget(widget);
|
2014-02-22 00:02:35 +04:00
|
|
|
slotSyncStateChange();
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
void SettingsDialog::slotSyncStateChange(const QString& alias)
|
2013-07-22 14:11:12 +04:00
|
|
|
{
|
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-10-01 15:52:07 +04:00
|
|
|
|
2014-02-22 00:02:35 +04:00
|
|
|
if (!alias.isEmpty()) {
|
|
|
|
Folder *folder = folderMan->folder(alias);
|
|
|
|
if( folder ) {
|
|
|
|
_accountSettings->slotUpdateFolderState(folder);
|
|
|
|
}
|
2013-10-01 15:52:07 +04:00
|
|
|
}
|
2013-07-22 14:11:12 +04:00
|
|
|
}
|
|
|
|
|
2013-09-11 12:24:31 +04:00
|
|
|
void SettingsDialog::setGeneralErrors(const QStringList &errors)
|
|
|
|
{
|
2013-10-01 20:25:30 +04:00
|
|
|
if( _accountSettings ) {
|
|
|
|
_accountSettings->setGeneralErrors(errors);
|
|
|
|
}
|
2013-09-11 12:24:31 +04:00
|
|
|
}
|
|
|
|
|
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-11-29 14:18:59 +04:00
|
|
|
void SettingsDialog::showActivityPage()
|
|
|
|
{
|
|
|
|
_ui->labelWidget->setCurrentRow(_protocolIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
} // namespace Mirall
|