1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include "./settingsdialog.h"
#include "./syncthingapplet.h"
#include "ui_appearanceoptionpage.h"
#include <syncthingwidgets/settings/settingsdialog.h>
#include <qtutilities/settingsdialog/optioncategory.h>
#include <qtutilities/settingsdialog/optioncategorymodel.h>
#include <qtutilities/settingsdialog/optionpage.h>
#include <qtutilities/settingsdialog/settingsdialog.h>
#include <KConfigGroup>
#include <QCoreApplication>
#include <QFormLayout>
#include <QKeySequenceEdit>
#include <QVBoxLayout>
using namespace Data;
using namespace QtGui;
using namespace QtUtilities;
namespace Plasmoid {
static 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);
}
// ShortcutOptionPage
ShortcutOptionPage::ShortcutOptionPage(SyncthingApplet &applet, QWidget *parentWidget)
: ShortcutOptionPageBase(parentWidget)
, m_applet(&applet)
{
}
ShortcutOptionPage::~ShortcutOptionPage()
{
}
bool ShortcutOptionPage::apply()
{
m_applet->setGlobalShortcut(m_globalShortcutEdit->keySequence());
return true;
}
void ShortcutOptionPage::reset()
{
m_globalShortcutEdit->setKeySequence(m_applet->globalShortcut());
}
QWidget *ShortcutOptionPage::setupWidget()
{
auto *const widget = new QWidget();
widget->setWindowTitle(QCoreApplication::translate("Plasmoid::ShortcutOptionPage", "Shortcuts"));
widget->setWindowIcon(QIcon::fromTheme(QStringLiteral("configure-shortcuts")));
widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
auto *const mainLayout = new QVBoxLayout(widget);
auto *const formLayout = new QFormLayout;
formLayout->addRow(
QCoreApplication::translate("Plasmoid::ShortcutOptionPage", "Global shortcut"), m_globalShortcutEdit = new QKeySequenceEdit(widget));
mainLayout->addLayout(formLayout);
mainLayout->addStretch(1);
addPlasmoidSpecificNote(mainLayout, widget);
return widget;
}
// AppearanceOptionPage
AppearanceOptionPage::AppearanceOptionPage(SyncthingApplet &applet, QWidget *parentWidget)
: AppearanceOptionPageBase(parentWidget)
, m_applet(&applet)
{
}
AppearanceOptionPage::~AppearanceOptionPage()
{
}
bool AppearanceOptionPage::apply()
{
KConfigGroup config = m_applet->config();
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
config.writeEntry<bool>("showTabTexts", ui()->showTabTextsCheckBox->isChecked());
config.writeEntry<bool>("showDownloads", ui()->showDownloadsCheckBox->isChecked());
config.writeEntry<bool>("preferIconsFromTheme", ui()->preferIconsFromThemeCheckBox->isChecked());
config.writeEntry("passiveStates", m_passiveStatusSelection.toVariantList());
return true;
}
void AppearanceOptionPage::reset()
{
const KConfigGroup config = m_applet->config();
const auto size(config.readEntry<>("size", QSize(25, 25)));
ui()->widthSpinBox->setValue(size.width());
ui()->heightSpinBox->setValue(size.height());
ui()->showTabTextsCheckBox->setChecked(config.readEntry<>("showTabTexts", false));
ui()->showDownloadsCheckBox->setChecked(config.readEntry<>("showDownloads", false));
ui()->preferIconsFromThemeCheckBox->setChecked(config.readEntry<>("preferIconsFromTheme", false));
m_passiveStatusSelection.applyVariantList(config.readEntry("passiveStates", QVariantList()));
}
QWidget *AppearanceOptionPage::setupWidget()
{
auto *const widget = AppearanceOptionPageBase::setupWidget();
addPlasmoidSpecificNote(ui()->verticalLayout, widget);
ui()->passiveListView->setModel(&m_passiveStatusSelection);
return widget;
}
SettingsDialog::SettingsDialog(Plasmoid::SyncthingApplet &applet)
{
// setup categories
QList<OptionCategory *> categories;
OptionCategory *category;
category = new OptionCategory;
m_appearanceOptionPage = new AppearanceOptionPage(applet);
translateCategory(category, [] { return QCoreApplication::translate("Plasmoid::SettingsDialog", "Plasmoid"); });
category->assignPages({ new ConnectionOptionPage(applet.connection()), new NotificationsOptionPage(GuiType::Plasmoid), m_appearanceOptionPage,
new IconsOptionPage, new ShortcutOptionPage(applet) });
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 generalWebViewPage = new GeneralWebViewOptionPage;
auto *const builtinWebViewPage = new BuiltinWebViewOptionPage;
auto setWindowTitle = [generalWebViewPage, builtinWebViewPage] {
generalWebViewPage->widget()->setWindowTitle(QCoreApplication::translate("Plasmoid::SettingsDialog", "General web view settings"));
builtinWebViewPage->widget()->setWindowTitle(QCoreApplication::translate("Plasmoid::SettingsDialog", "Built-in web view"));
};
setWindowTitle();
connect(this, &QtUtilities::SettingsDialog::retranslationRequired, this, std::move(setWindowTitle));
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
auto *const systemdPage = new SystemdOptionPage;
#endif
category = new OptionCategory;
translateCategory(category, [] { return QCoreApplication::translate("Plasmoid::SettingsDialog", "Extras"); });
category->assignPages({ generalWebViewPage, builtinWebViewPage
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
,
systemdPage
#endif
});
category->setIcon(
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))));
categories << category;
categoryModel()->setCategories(categories);
}
} // namespace Plasmoid
|