File indexing completed on 2024-04-21 04:56:54
0001 /** 0002 * SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "sendnotifications_config.h" 0008 #include "notifyingapplicationmodel.h" 0009 0010 #include <KCModule> 0011 #include <KPluginFactory> 0012 0013 K_PLUGIN_CLASS(SendNotificationsConfig) 0014 0015 SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) 0016 : KdeConnectPluginKcm(parent, data, args) 0017 , appModel(new NotifyingApplicationModel) 0018 { 0019 m_ui.setupUi(widget()); 0020 m_ui.appList->setIconSize(QSize(32, 32)); 0021 0022 m_ui.appList->setModel(appModel); 0023 0024 m_ui.appList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::QHeaderView::Fixed); 0025 m_ui.appList->horizontalHeader()->setSectionResizeMode(1, QHeaderView::QHeaderView::Stretch); 0026 m_ui.appList->horizontalHeader()->setSectionResizeMode(2, QHeaderView::QHeaderView::Stretch); 0027 for (int i = 0; i < 3; i++) 0028 m_ui.appList->resizeColumnToContents(i); 0029 0030 connect(m_ui.appList->horizontalHeader(), &QHeaderView::sortIndicatorChanged, m_ui.appList, &QTableView::sortByColumn); 0031 0032 connect(m_ui.check_persistent, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged); 0033 connect(m_ui.spin_urgency, &QSpinBox::editingFinished, this, &SendNotificationsConfig::markAsChanged); 0034 connect(m_ui.check_body, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged); 0035 connect(m_ui.check_icons, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged); 0036 0037 connect(appModel, &NotifyingApplicationModel::applicationsChanged, this, &SendNotificationsConfig::markAsChanged); 0038 0039 connect(config(), &KdeConnectPluginConfig::configChanged, this, &SendNotificationsConfig::loadApplications); 0040 } 0041 0042 void SendNotificationsConfig::defaults() 0043 { 0044 KCModule::defaults(); 0045 m_ui.check_persistent->setChecked(false); 0046 m_ui.spin_urgency->setValue(0); 0047 m_ui.check_body->setChecked(true); 0048 m_ui.check_icons->setChecked(true); 0049 markAsChanged(); 0050 } 0051 0052 void SendNotificationsConfig::loadApplications() 0053 { 0054 appModel->clearApplications(); 0055 QVariantList list = config()->getList(QStringLiteral("applications")); 0056 for (const auto &a : list) { 0057 NotifyingApplication app = a.value<NotifyingApplication>(); 0058 if (!appModel->containsApp(app.name)) { 0059 appModel->appendApp(app); 0060 } 0061 } 0062 } 0063 0064 void SendNotificationsConfig::load() 0065 { 0066 KCModule::load(); 0067 bool persistent = config()->getBool(QStringLiteral("generalPersistent"), false); 0068 m_ui.check_persistent->setChecked(persistent); 0069 bool body = config()->getBool(QStringLiteral("generalIncludeBody"), true); 0070 m_ui.check_body->setChecked(body); 0071 bool icons = config()->getBool(QStringLiteral("generalSynchronizeIcons"), true); 0072 m_ui.check_icons->setChecked(icons); 0073 int urgency = config()->getInt(QStringLiteral("generalUrgency"), 0); 0074 m_ui.spin_urgency->setValue(urgency); 0075 0076 loadApplications(); 0077 } 0078 0079 void SendNotificationsConfig::save() 0080 { 0081 KCModule::save(); 0082 config()->set(QStringLiteral("generalPersistent"), m_ui.check_persistent->isChecked()); 0083 config()->set(QStringLiteral("generalIncludeBody"), m_ui.check_body->isChecked()); 0084 config()->set(QStringLiteral("generalSynchronizeIcons"), m_ui.check_icons->isChecked()); 0085 config()->set(QStringLiteral("generalUrgency"), m_ui.spin_urgency->value()); 0086 0087 QVariantList list; 0088 const auto apps = appModel->apps(); 0089 list.reserve(apps.size()); 0090 for (const auto &a : apps) { 0091 list.append(QVariant::fromValue<NotifyingApplication>(a)); 0092 } 0093 config()->setList(QStringLiteral("applications"), list); 0094 } 0095 0096 #include "moc_sendnotifications_config.cpp" 0097 #include "sendnotifications_config.moc"