File indexing completed on 2024-05-19 04:58:06

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "behaviorconfig.h"
0010 
0011 #include "ui_behaviorconfig_general.h"
0012 #include "ui_behaviorconfig_notifications.h"
0013 
0014 #include <QTabWidget>
0015 #include <QVBoxLayout>
0016 
0017 #include <KAboutData>
0018 #include <KCModuleProxy>
0019 #include <KLocalizedString>
0020 #include <KPluginFactory>
0021 
0022 #include "behaviorconfig_shorten.h"
0023 #include "behaviordebug.h"
0024 #include "choqokbehaviorsettings.h"
0025 
0026 K_PLUGIN_FACTORY_WITH_JSON(ChoqokBehaviorConfigFactory, "choqok_behaviorconfig.json",
0027                            registerPlugin<BehaviorConfig>();)
0028 
0029 class BehaviorConfig::Private
0030 {
0031 public:
0032     QTabWidget *mBehaviorTabCtl;
0033 
0034     Ui_BehaviorConfig_General mPrfsGeneral;
0035     Ui_BehaviorConfig_Notifications mPrfsNotify;
0036     BehaviorConfig_Shorten *mPrfsShorten;
0037     KCModuleProxy *proxyModule;
0038 };
0039 
0040 BehaviorConfig::BehaviorConfig(QWidget *parent, const QVariantList &args)
0041     : KCModule(parent, args)
0042     , d(new Private)
0043 {
0044     qCDebug(CHOQOK);
0045     QVBoxLayout *layout = new QVBoxLayout(this);
0046     // since KSetting::Dialog has margins here, we don't need our own.
0047     layout->setContentsMargins(0, 0, 0, 0);
0048 
0049     d->mBehaviorTabCtl = new QTabWidget(this);
0050     d->mBehaviorTabCtl->setObjectName(QLatin1String("mBehaviorTabCtl"));
0051     layout->addWidget(d->mBehaviorTabCtl);
0052 
0053     // "General" TAB ============================================================
0054     QWidget *mPrfsGeneralDlg = new QWidget(d->mBehaviorTabCtl);
0055     d->mPrfsGeneral.setupUi(mPrfsGeneralDlg);
0056     addConfig(Choqok::BehaviorSettings::self(), mPrfsGeneralDlg);
0057     d->mBehaviorTabCtl->addTab(mPrfsGeneralDlg, i18n("&General"));
0058 
0059 #ifdef QTINDICATE_BUILD
0060     // "Notifications" TAB ============================================================
0061     QWidget *mPrfsNotifyDlg = new QWidget(d->mBehaviorTabCtl);
0062     d->mPrfsNotify.setupUi(mPrfsNotifyDlg);
0063     addConfig(Choqok::BehaviorSettings::self(), mPrfsNotifyDlg);
0064     d->mBehaviorTabCtl->addTab(mPrfsNotifyDlg, i18n("&Notifications"));
0065     /* Remove below code, when all functions on tab will work*/
0066     d->mPrfsNotify.kcfg_notifyInterval->setVisible(false);
0067     d->mPrfsNotify.kcfg_showAllNotifiesInOne->setVisible(false);
0068     d->mPrfsNotify.label_4->setVisible(false);
0069     /*     */
0070 #endif
0071 
0072     // "Shortening" TAB ===============================================================
0073     d->mPrfsShorten = new BehaviorConfig_Shorten(d->mBehaviorTabCtl);
0074     addConfig(Choqok::BehaviorSettings::self(), d->mPrfsShorten);
0075     d->mBehaviorTabCtl->addTab(d->mPrfsShorten, i18n("URL &Shortening"));
0076 
0077     const KService::Ptr proxyKCMService = KService::serviceByDesktopName(QStringLiteral("proxy"));
0078     d->proxyModule = new KCModuleProxy(proxyKCMService, parent);
0079     d->mBehaviorTabCtl->addTab(d->proxyModule, proxyKCMService->name());
0080 
0081     connect(d->mPrfsShorten, (void (BehaviorConfig_Shorten::*)(bool))&BehaviorConfig_Shorten::changed,
0082             this, &BehaviorConfig::markAsChanged);
0083     connect(d->proxyModule, (void (KCModuleProxy::*)(KCModuleProxy*))&KCModuleProxy::changed,
0084             this, &BehaviorConfig::markAsChanged);
0085 
0086     load();
0087 
0088 }
0089 
0090 BehaviorConfig::~BehaviorConfig()
0091 {
0092     delete d;
0093 }
0094 
0095 void BehaviorConfig::save()
0096 {
0097     qCDebug(CHOQOK);
0098 
0099     KCModule::save();
0100     d->mPrfsShorten->save();
0101     d->proxyModule->save();
0102 //     Choqok::BehaviorSettings::self()->writeConfig();
0103 
0104     load();
0105 }
0106 
0107 void BehaviorConfig::load()
0108 {
0109     KCModule::load();
0110     d->mPrfsShorten->load();
0111     d->proxyModule->load();
0112 }
0113 
0114 #include "behaviorconfig.moc"
0115 #include "moc_behaviorconfig.cpp"