File indexing completed on 2024-12-15 04:51:47
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "notenetworkconfig.h" 0008 0009 #include "notesharedglobalconfig.h" 0010 0011 #include <KLocalizedString> 0012 #include <QLineEdit> 0013 #include <QSpinBox> 0014 0015 #include <QCheckBox> 0016 #include <QGroupBox> 0017 #include <QLabel> 0018 #include <QVBoxLayout> 0019 #include <QWhatsThis> 0020 0021 using namespace NoteShared; 0022 0023 NoteNetworkConfigWidget::NoteNetworkConfigWidget(QWidget *parent) 0024 : QWidget(parent) 0025 { 0026 auto layout = new QVBoxLayout(this); 0027 // layout->setContentsMargins(0, 0, 0, 0); 0028 0029 auto incoming = new QGroupBox(i18n("Incoming Notes")); 0030 auto tmpLayout = new QHBoxLayout; 0031 0032 mTmpChkB = new QCheckBox(i18n("Accept incoming notes"), this); 0033 mTmpChkB->setObjectName(QLatin1StringView("kcfg_ReceiveNotes")); 0034 tmpLayout->addWidget(mTmpChkB); 0035 incoming->setLayout(tmpLayout); 0036 layout->addWidget(incoming); 0037 0038 auto outgoing = new QGroupBox(i18n("Outgoing Notes"), this); 0039 tmpLayout = new QHBoxLayout; 0040 0041 auto label_SenderID = new QLabel(i18n("&Sender ID:"), this); 0042 m_kcfg_SenderID = new QLineEdit; 0043 m_kcfg_SenderID->setClearButtonEnabled(true); 0044 m_kcfg_SenderID->setObjectName(QLatin1StringView("kcfg_SenderID")); 0045 label_SenderID->setBuddy(m_kcfg_SenderID); 0046 tmpLayout->addWidget(label_SenderID); 0047 tmpLayout->addWidget(m_kcfg_SenderID); 0048 outgoing->setLayout(tmpLayout); 0049 layout->addWidget(outgoing); 0050 0051 tmpLayout = new QHBoxLayout; 0052 0053 auto label_Port = new QLabel(i18n("&Port:"), this); 0054 0055 tmpLayout->addWidget(label_Port); 0056 0057 kcfg_Port = new QSpinBox(this); 0058 kcfg_Port->setObjectName(QLatin1StringView("kcfg_Port")); 0059 kcfg_Port->setRange(0, 65535); 0060 label_Port->setBuddy(kcfg_Port); 0061 tmpLayout->addWidget(kcfg_Port); 0062 layout->addLayout(tmpLayout); 0063 layout->addStretch(); 0064 load(); 0065 } 0066 0067 NoteNetworkConfigWidget::~NoteNetworkConfigWidget() = default; 0068 0069 void NoteNetworkConfigWidget::save() 0070 { 0071 NoteShared::NoteSharedGlobalConfig::self()->setReceiveNotes(mTmpChkB->isChecked()); 0072 NoteShared::NoteSharedGlobalConfig::self()->setSenderID(m_kcfg_SenderID->text()); 0073 NoteShared::NoteSharedGlobalConfig::self()->setPort(kcfg_Port->value()); 0074 NoteShared::NoteSharedGlobalConfig::self()->save(); 0075 } 0076 0077 void NoteNetworkConfigWidget::load() 0078 { 0079 mTmpChkB->setChecked(NoteShared::NoteSharedGlobalConfig::self()->receiveNotes()); 0080 m_kcfg_SenderID->setText(NoteShared::NoteSharedGlobalConfig::self()->senderID()); 0081 kcfg_Port->setValue(NoteShared::NoteSharedGlobalConfig::self()->port()); 0082 } 0083 0084 NoteNetworkConfig::NoteNetworkConfig(QObject *parent, const KPluginMetaData &data) 0085 : KCModule(parent, data) 0086 { 0087 auto lay = new QVBoxLayout(widget()); 0088 lay->setContentsMargins(0, 0, 0, 0); 0089 auto noteNetworkConfigWidget = new NoteNetworkConfigWidget(widget()); 0090 lay->addWidget(noteNetworkConfigWidget); 0091 addConfig(NoteShared::NoteSharedGlobalConfig::self(), noteNetworkConfigWidget); 0092 load(); 0093 } 0094 0095 void NoteNetworkConfig::save() 0096 { 0097 KCModule::save(); 0098 } 0099 0100 void NoteNetworkConfig::load() 0101 { 0102 KCModule::load(); 0103 } 0104 0105 #include "moc_notenetworkconfig.cpp"