2015-12-05 22:11:57 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de>
|
2015-12-05 22:11:57 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-12-05 22:11:57 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
#include "sendnotifications_config.h"
|
2015-12-05 22:11:57 +00:00
|
|
|
#include "notifyingapplicationmodel.h"
|
|
|
|
|
|
|
|
#include <KCModule>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
2023-07-21 11:42:38 +01:00
|
|
|
K_PLUGIN_CLASS(SendNotificationsConfig)
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-21 11:26:19 +01:00
|
|
|
SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
|
|
|
|
: KdeConnectPluginKcm(parent, data, args)
|
2015-12-05 22:11:57 +00:00
|
|
|
, appModel(new NotifyingApplicationModel)
|
|
|
|
{
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.setupUi(widget());
|
|
|
|
m_ui.appList->setIconSize(QSize(32, 32));
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.appList->setModel(appModel);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.appList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::QHeaderView::Fixed);
|
|
|
|
m_ui.appList->horizontalHeader()->setSectionResizeMode(1, QHeaderView::QHeaderView::Stretch);
|
|
|
|
m_ui.appList->horizontalHeader()->setSectionResizeMode(2, QHeaderView::QHeaderView::Stretch);
|
2015-12-05 22:11:57 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.appList->resizeColumnToContents(i);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-26 09:40:17 +01:00
|
|
|
connect(m_ui.appList->horizontalHeader(), &QHeaderView::sortIndicatorChanged, m_ui.appList, &QTableView::sortByColumn);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-26 09:40:17 +01:00
|
|
|
connect(m_ui.check_persistent, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
|
|
|
|
connect(m_ui.spin_urgency, &QSpinBox::editingFinished, this, &SendNotificationsConfig::markAsChanged);
|
|
|
|
connect(m_ui.check_body, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
|
|
|
|
connect(m_ui.check_icons, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2023-07-20 15:22:29 +01:00
|
|
|
connect(appModel, &NotifyingApplicationModel::applicationsChanged, this, &SendNotificationsConfig::markAsChanged);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2016-11-26 14:12:38 +00:00
|
|
|
connect(config(), &KdeConnectPluginConfig::configChanged, this, &SendNotificationsConfig::loadApplications);
|
2015-12-05 22:11:57 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::defaults()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
|
|
|
KCModule::defaults();
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.check_persistent->setChecked(false);
|
|
|
|
m_ui.spin_urgency->setValue(0);
|
|
|
|
m_ui.check_body->setChecked(true);
|
|
|
|
m_ui.check_icons->setChecked(true);
|
2023-04-17 18:10:08 +01:00
|
|
|
markAsChanged();
|
2015-12-05 22:11:57 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::loadApplications()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
|
|
|
appModel->clearApplications();
|
2016-11-26 14:38:08 +00:00
|
|
|
QVariantList list = config()->getList(QStringLiteral("applications"));
|
2022-09-10 22:23:52 +01:00
|
|
|
for (const auto &a : list) {
|
2015-12-05 22:11:57 +00:00
|
|
|
NotifyingApplication app = a.value<NotifyingApplication>();
|
|
|
|
if (!appModel->containsApp(app.name)) {
|
|
|
|
appModel->appendApp(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::load()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
|
|
|
KCModule::load();
|
2019-10-27 17:08:51 +00:00
|
|
|
bool persistent = config()->getBool(QStringLiteral("generalPersistent"), false);
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.check_persistent->setChecked(persistent);
|
2019-10-27 17:08:51 +00:00
|
|
|
bool body = config()->getBool(QStringLiteral("generalIncludeBody"), true);
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.check_body->setChecked(body);
|
2019-10-27 17:08:51 +00:00
|
|
|
bool icons = config()->getBool(QStringLiteral("generalSynchronizeIcons"), true);
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.check_icons->setChecked(icons);
|
2019-10-27 17:08:51 +00:00
|
|
|
int urgency = config()->getInt(QStringLiteral("generalUrgency"), 0);
|
2023-07-26 09:40:17 +01:00
|
|
|
m_ui.spin_urgency->setValue(urgency);
|
2015-12-05 22:11:57 +00:00
|
|
|
|
|
|
|
loadApplications();
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::save()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
2023-04-17 18:10:08 +01:00
|
|
|
KCModule::save();
|
2023-07-26 09:40:17 +01:00
|
|
|
config()->set(QStringLiteral("generalPersistent"), m_ui.check_persistent->isChecked());
|
|
|
|
config()->set(QStringLiteral("generalIncludeBody"), m_ui.check_body->isChecked());
|
|
|
|
config()->set(QStringLiteral("generalSynchronizeIcons"), m_ui.check_icons->isChecked());
|
|
|
|
config()->set(QStringLiteral("generalUrgency"), m_ui.spin_urgency->value());
|
2015-12-05 22:11:57 +00:00
|
|
|
|
|
|
|
QVariantList list;
|
2018-11-25 22:58:24 +00:00
|
|
|
const auto apps = appModel->apps();
|
|
|
|
list.reserve(apps.size());
|
2022-09-10 22:23:52 +01:00
|
|
|
for (const auto &a : apps) {
|
2016-11-26 15:19:00 +00:00
|
|
|
list.append(QVariant::fromValue<NotifyingApplication>(a));
|
|
|
|
}
|
2016-11-26 14:38:08 +00:00
|
|
|
config()->setList(QStringLiteral("applications"), list);
|
2015-12-05 22:11:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_sendnotifications_config.cpp"
|
2016-05-25 19:49:13 +01:00
|
|
|
#include "sendnotifications_config.moc"
|