2017-09-09 21:40:00 +02:00
|
|
|
#include "./settingsdialog.h"
|
|
|
|
#include "./syncthingapplet.h"
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
#include "ui_appearanceoptionpage.h"
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
#include "../../widgets/settings/settingsdialog.h"
|
|
|
|
|
|
|
|
#include <qtutilities/settingsdialog/optioncategory.h>
|
2018-10-10 17:48:48 +02:00
|
|
|
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
2017-09-09 21:40:00 +02:00
|
|
|
#include <qtutilities/settingsdialog/optionpage.h>
|
|
|
|
#include <qtutilities/settingsdialog/settingsdialog.h>
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
#include <KConfigGroup>
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QKeySequenceEdit>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
using namespace Dialogs;
|
|
|
|
using namespace Data;
|
|
|
|
using namespace QtGui;
|
|
|
|
|
|
|
|
namespace Plasmoid {
|
|
|
|
|
2017-10-03 16:58:50 +02:00
|
|
|
void addPlasmoidSpecificNote(QLayout *layout, QWidget *parent)
|
|
|
|
{
|
|
|
|
auto *const infoLabel = new QLabel(
|
|
|
|
QCoreApplication::translate("Plasmoid::Settings", "The settings on this page are specific to the current instance of the Plasmoid."), parent);
|
|
|
|
infoLabel->setWordWrap(true);
|
|
|
|
QFont infoFont(infoLabel->font());
|
|
|
|
infoFont.setBold(true);
|
|
|
|
infoLabel->setFont(infoFont);
|
|
|
|
auto *const line = new QFrame(parent);
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
layout->addWidget(line);
|
|
|
|
layout->addWidget(infoLabel);
|
|
|
|
}
|
|
|
|
|
2017-09-09 21:40:00 +02:00
|
|
|
// ShortcutOptionPage
|
|
|
|
ShortcutOptionPage::ShortcutOptionPage(SyncthingApplet &applet, QWidget *parentWidget)
|
|
|
|
: ShortcutOptionPageBase(parentWidget)
|
|
|
|
, m_applet(&applet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ShortcutOptionPage::~ShortcutOptionPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShortcutOptionPage::apply()
|
|
|
|
{
|
2017-09-27 00:21:53 +02:00
|
|
|
m_applet->setGlobalShortcut(m_globalShortcutEdit->keySequence());
|
2017-09-09 21:40:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShortcutOptionPage::reset()
|
|
|
|
{
|
2017-09-27 00:21:53 +02:00
|
|
|
m_globalShortcutEdit->setKeySequence(m_applet->globalShortcut());
|
2017-09-09 21:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *ShortcutOptionPage::setupWidget()
|
|
|
|
{
|
2017-10-03 16:58:50 +02:00
|
|
|
auto *const widget = new QWidget();
|
2017-09-09 21:40:00 +02:00
|
|
|
widget->setWindowTitle(QCoreApplication::translate("Plasmoid::ShortcutOptionPage", "Shortcuts"));
|
|
|
|
widget->setWindowIcon(QIcon::fromTheme(QStringLiteral("configure-shortcuts")));
|
2017-10-03 16:58:50 +02:00
|
|
|
widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
auto *const mainLayout = new QVBoxLayout(widget);
|
|
|
|
auto *const formLayout = new QFormLayout;
|
2017-09-09 21:40:00 +02:00
|
|
|
formLayout->addRow(
|
|
|
|
QCoreApplication::translate("Plasmoid::ShortcutOptionPage", "Global shortcut"), m_globalShortcutEdit = new QKeySequenceEdit(widget));
|
|
|
|
mainLayout->addLayout(formLayout);
|
2017-10-03 16:58:50 +02:00
|
|
|
mainLayout->addStretch(1);
|
|
|
|
addPlasmoidSpecificNote(mainLayout, widget);
|
2017-09-09 21:40:00 +02:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
// AppearanceOptionPage
|
|
|
|
AppearanceOptionPage::AppearanceOptionPage(SyncthingApplet &applet, QWidget *parentWidget)
|
|
|
|
: AppearanceOptionPageBase(parentWidget)
|
|
|
|
, m_applet(&applet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppearanceOptionPage::~AppearanceOptionPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppearanceOptionPage::apply()
|
|
|
|
{
|
2017-09-27 00:21:53 +02:00
|
|
|
KConfigGroup config = m_applet->config();
|
|
|
|
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
|
|
|
|
config.writeEntry<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked());
|
2018-10-10 21:00:13 +02:00
|
|
|
config.writeEntry("passiveStates", m_passiveStatusSelection.toVariantList());
|
2018-10-10 17:48:48 +02:00
|
|
|
|
2017-09-18 20:29:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppearanceOptionPage::reset()
|
|
|
|
{
|
2017-09-27 00:21:53 +02:00
|
|
|
const KConfigGroup config = m_applet->config();
|
2018-10-10 17:48:48 +02:00
|
|
|
const auto size(config.readEntry<>("size", QSize(25, 25)));
|
2017-09-27 00:21:53 +02:00
|
|
|
ui()->widthSpinBox->setValue(size.width());
|
|
|
|
ui()->heightSpinBox->setValue(size.height());
|
2018-10-10 17:48:48 +02:00
|
|
|
ui()->brightTextColorsCheckBox->setChecked(config.readEntry<>("brightColors", false));
|
2018-10-10 21:00:13 +02:00
|
|
|
m_passiveStatusSelection.applyVariantList(config.readEntry("passiveStates", QVariantList()));
|
2017-09-18 20:29:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 16:58:50 +02:00
|
|
|
QWidget *AppearanceOptionPage::setupWidget()
|
|
|
|
{
|
|
|
|
auto *const widget = AppearanceOptionPageBase::setupWidget();
|
|
|
|
addPlasmoidSpecificNote(ui()->verticalLayout, widget);
|
2018-10-10 17:48:48 +02:00
|
|
|
ui()->passiveListView->setModel(&m_passiveStatusSelection);
|
2017-10-03 16:58:50 +02:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2018-10-10 17:48:48 +02:00
|
|
|
SettingsDialog::SettingsDialog(Plasmoid::SyncthingApplet &applet)
|
2017-09-09 21:40:00 +02:00
|
|
|
{
|
|
|
|
// setup categories
|
|
|
|
QList<Dialogs::OptionCategory *> categories;
|
|
|
|
Dialogs::OptionCategory *category;
|
|
|
|
|
|
|
|
category = new OptionCategory;
|
2018-10-10 17:48:48 +02:00
|
|
|
m_appearanceOptionPage = new AppearanceOptionPage(applet);
|
2017-09-09 21:40:00 +02:00
|
|
|
category->setDisplayName(QCoreApplication::translate("Plasmoid::SettingsDialog", "Plasmoid"));
|
|
|
|
category->assignPages(QList<Dialogs::OptionPage *>()
|
2018-10-10 17:48:48 +02:00
|
|
|
<< new ConnectionOptionPage(applet.connection()) << new NotificationsOptionPage(GuiType::Plasmoid) << m_appearanceOptionPage
|
2017-09-18 20:29:36 +02:00
|
|
|
<< new ShortcutOptionPage(applet));
|
2017-09-09 21:40:00 +02:00
|
|
|
category->setIcon(QIcon::fromTheme(QStringLiteral("plasma")));
|
|
|
|
categories << category;
|
|
|
|
|
|
|
|
// most startup options don't make much sense for a Plasmoid, so merge webview with startup
|
|
|
|
auto *const webViewPage = new WebViewOptionPage;
|
|
|
|
webViewPage->widget()->setWindowTitle(QCoreApplication::translate("Plasmoid::SettingsDialog", "Web view"));
|
|
|
|
webViewPage->widget()->setWindowIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("internet-web-browser"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/internet-web-browser.svg"))));
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
auto *const systemdPage = new SystemdOptionPage;
|
|
|
|
systemdPage->widget()->setWindowIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("system-run"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/system-run.svg"))));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
category = new OptionCategory;
|
|
|
|
category->setDisplayName(QCoreApplication::translate("Plasmoid::SettingsDialog", "Extras"));
|
|
|
|
category->assignPages(QList<Dialogs::OptionPage *>() << webViewPage
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
<< systemdPage
|
|
|
|
#endif
|
2017-09-17 21:48:15 +02:00
|
|
|
);
|
2017-09-09 21:40:00 +02:00
|
|
|
category->setIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))));
|
|
|
|
categories << category;
|
2018-10-10 17:48:48 +02:00
|
|
|
categoryModel()->setCategories(categories);
|
2017-09-09 21:40:00 +02:00
|
|
|
}
|
2018-10-10 17:48:48 +02:00
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace Plasmoid
|