2015-12-05 22:11:57 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2015 Holger Kaelberer <holger.k@elberer.de>
|
|
|
|
*
|
|
|
|
* 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; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
#include "sendnotifications_config.h"
|
|
|
|
#include "ui_sendnotifications_config.h"
|
2015-12-05 22:11:57 +00:00
|
|
|
#include "notifyingapplicationmodel.h"
|
|
|
|
|
|
|
|
#include <KCModule>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
K_PLUGIN_FACTORY(SendNotificationsConfigFactory, registerPlugin<SendNotificationsConfig>();)
|
2015-12-05 22:11:57 +00:00
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
SendNotificationsConfig::SendNotificationsConfig(QWidget *parent, const QVariantList& args)
|
2016-11-26 14:38:08 +00:00
|
|
|
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_sendnotifications_config"))
|
2016-05-25 19:49:13 +01:00
|
|
|
, m_ui(new Ui::SendNotificationsConfigUi())
|
2015-12-05 22:11:57 +00:00
|
|
|
, appModel(new NotifyingApplicationModel)
|
|
|
|
{
|
|
|
|
qRegisterMetaTypeStreamOperators<NotifyingApplication>("NotifyingApplication");
|
|
|
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
m_ui->appList->setIconSize(QSize(32,32));
|
|
|
|
|
|
|
|
m_ui->appList->setModel(appModel);
|
|
|
|
|
|
|
|
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);
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
m_ui->appList->resizeColumnToContents(i);
|
|
|
|
|
|
|
|
connect(m_ui->appList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
|
|
|
|
m_ui->appList, SLOT(sortByColumn(int)));
|
|
|
|
|
|
|
|
connect(m_ui->check_persistent, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
|
|
|
connect(m_ui->spin_urgency, SIGNAL(editingFinished()), this, SLOT(changed()));
|
|
|
|
connect(m_ui->check_body, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
2016-01-07 16:37:35 +00:00
|
|
|
connect(m_ui->check_icons, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
2015-12-05 22:11:57 +00:00
|
|
|
|
|
|
|
connect(appModel, SIGNAL(applicationsChanged()), this, SLOT(changed()));
|
|
|
|
|
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
|
|
|
SendNotificationsConfig::~SendNotificationsConfig()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
|
|
|
delete m_ui;
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::defaults()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
|
|
|
KCModule::defaults();
|
|
|
|
m_ui->check_persistent->setChecked(false);
|
|
|
|
m_ui->spin_urgency->setValue(0);
|
2016-01-07 16:37:35 +00:00
|
|
|
m_ui->check_body->setChecked(true);
|
|
|
|
m_ui->check_icons->setChecked(true);
|
2015-12-05 22:11:57 +00:00
|
|
|
Q_EMIT changed(true);
|
|
|
|
}
|
|
|
|
|
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"));
|
2015-12-05 22:11:57 +00:00
|
|
|
for (const auto& a: list) {
|
|
|
|
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();
|
2016-11-26 14:38:08 +00:00
|
|
|
bool persistent = config()->get(QStringLiteral("generalPersistent"), false);
|
2015-12-05 22:11:57 +00:00
|
|
|
m_ui->check_persistent->setChecked(persistent);
|
2016-11-26 14:38:08 +00:00
|
|
|
bool body = config()->get(QStringLiteral("generalIncludeBody"), true);
|
2015-12-05 22:11:57 +00:00
|
|
|
m_ui->check_body->setChecked(body);
|
2016-11-26 14:38:08 +00:00
|
|
|
bool icons = config()->get(QStringLiteral("generalSynchronizeIcons"), true);
|
2016-01-07 16:37:35 +00:00
|
|
|
m_ui->check_icons->setChecked(icons);
|
2016-11-26 14:38:08 +00:00
|
|
|
int urgency = config()->get(QStringLiteral("generalUrgency"), 0);
|
2015-12-05 22:11:57 +00:00
|
|
|
m_ui->spin_urgency->setValue(urgency);
|
|
|
|
|
|
|
|
loadApplications();
|
|
|
|
Q_EMIT changed(false);
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
void SendNotificationsConfig::save()
|
2015-12-05 22:11:57 +00:00
|
|
|
{
|
2016-11-26 14:38:08 +00: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;
|
2016-11-26 15:19:00 +00:00
|
|
|
list.reserve(appModel->apps().size());
|
|
|
|
for (const auto& a: appModel->apps()) {
|
|
|
|
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
|
|
|
KCModule::save();
|
|
|
|
Q_EMIT changed(false);
|
|
|
|
}
|
|
|
|
|
2016-05-25 19:49:13 +01:00
|
|
|
#include "sendnotifications_config.moc"
|