File indexing completed on 2024-05-12 04:45:34
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2013-2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 #include "pluginsettingswidget.h" 0019 #include "libsnore/plugins/plugins.h" 0020 #include "libsnore/snoreconstants.h" 0021 #include "snore.h" 0022 0023 #include <QCheckBox> 0024 #include <QLabel> 0025 0026 using namespace Snore; 0027 0028 PluginSettingsWidget::PluginSettingsWidget(SnorePlugin *snorePlugin, QWidget *parent) : 0029 QWidget(parent), 0030 m_snorePlugin(snorePlugin), 0031 m_layout(new QFormLayout), 0032 m_enabled(new QCheckBox) 0033 { 0034 setLayout(m_layout); 0035 if (m_snorePlugin->type() != SnorePlugin::Backend) { 0036 // backends are handled through a combo box. 0037 addRow(tr("Enabled:"), m_enabled); 0038 } 0039 0040 } 0041 0042 PluginSettingsWidget::~PluginSettingsWidget() 0043 { 0044 0045 } 0046 0047 const QString PluginSettingsWidget::name() const 0048 { 0049 return m_snorePlugin->name(); 0050 } 0051 0052 void PluginSettingsWidget::addRow(const QString &label, QWidget *widget, const QString &toolTip) 0053 { 0054 QLabel *lb = new QLabel(label, this); 0055 m_layout->addRow(lb, widget); 0056 if (!toolTip.isEmpty()) { 0057 widget->setToolTip(toolTip); 0058 lb->setToolTip(toolTip); 0059 } 0060 } 0061 0062 void PluginSettingsWidget::loadSettings() 0063 { 0064 if (m_snorePlugin->type() != SnorePlugin::Backend) { 0065 m_enabled->setChecked(m_snorePlugin->settingsValue(Constants::SettingsKeys::Enabled).toBool()); 0066 } 0067 load(); 0068 } 0069 0070 void PluginSettingsWidget::saveSettings() 0071 { 0072 if (m_snorePlugin->type() != SnorePlugin::Backend) { 0073 m_snorePlugin->setSettingsValue(Constants::SettingsKeys::Enabled, m_enabled->isChecked()); 0074 } 0075 save(); 0076 } 0077 0078 bool PluginSettingsWidget::isDirty() 0079 { 0080 return m_dirty; 0081 } 0082 0083 QVariant PluginSettingsWidget::settingsValue(const SettingsKey &key) const 0084 { 0085 return m_snorePlugin->settingsValue(key); 0086 } 0087 0088 void PluginSettingsWidget::setSettingsValue(const SettingsKey &key, const QVariant &value) 0089 { 0090 if (this->settingsValue(key) != value) { 0091 m_snorePlugin->setSettingsValue(key, value); 0092 m_dirty = true; 0093 } 0094 } 0095 0096 void PluginSettingsWidget::load() 0097 { 0098 0099 } 0100 0101 void PluginSettingsWidget::save() 0102 { 0103 0104 } 0105