1 /*
2 This file is part of Choqok, the KDE micro-blogging client
3 
4 Copyright (C) 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, see http://www.gnu.org/licenses/
21 
22 */
23 
24 #include "behaviorconfig.h"
25 
26 #include "ui_behaviorconfig_general.h"
27 #include "ui_behaviorconfig_notifications.h"
28 
29 #include <QTabWidget>
30 #include <QVBoxLayout>
31 
32 #include <KAboutData>
33 #include <KCModuleInfo>
34 #include <KCModuleProxy>
35 #include <KLocalizedString>
36 #include <KPluginFactory>
37 
38 #include "behaviorconfig_shorten.h"
39 #include "behaviordebug.h"
40 #include "choqokbehaviorsettings.h"
41 
42 K_PLUGIN_FACTORY_WITH_JSON(ChoqokBehaviorConfigFactory, "choqok_behaviorconfig.json",
43                            registerPlugin<BehaviorConfig>();)
44 
45 class BehaviorConfig::Private
46 {
47 public:
48     QTabWidget *mBehaviorTabCtl;
49 
50     Ui_BehaviorConfig_General mPrfsGeneral;
51     Ui_BehaviorConfig_Notifications mPrfsNotify;
52     BehaviorConfig_Shorten *mPrfsShorten;
53     KCModuleProxy *proxyModule;
54 };
55 
BehaviorConfig(QWidget * parent,const QVariantList & args)56 BehaviorConfig::BehaviorConfig(QWidget *parent, const QVariantList &args)
57     : KCModule(KAboutData::pluginData(QLatin1String("kcm_choqok_behaviorconfig")), parent, args)
58     , d(new Private)
59 {
60     qCDebug(CHOQOK);
61     QVBoxLayout *layout = new QVBoxLayout(this);
62     // since KSetting::Dialog has margins here, we don't need our own.
63     layout->setContentsMargins(0, 0, 0, 0);
64 
65     d->mBehaviorTabCtl = new QTabWidget(this);
66     d->mBehaviorTabCtl->setObjectName(QLatin1String("mBehaviorTabCtl"));
67     layout->addWidget(d->mBehaviorTabCtl);
68 
69     // "General" TAB ============================================================
70     QWidget *mPrfsGeneralDlg = new QWidget(d->mBehaviorTabCtl);
71     d->mPrfsGeneral.setupUi(mPrfsGeneralDlg);
72     addConfig(Choqok::BehaviorSettings::self(), mPrfsGeneralDlg);
73     d->mBehaviorTabCtl->addTab(mPrfsGeneralDlg, i18n("&General"));
74 
75 #ifdef QTINDICATE_BUILD
76     // "Notifications" TAB ============================================================
77     QWidget *mPrfsNotifyDlg = new QWidget(d->mBehaviorTabCtl);
78     d->mPrfsNotify.setupUi(mPrfsNotifyDlg);
79     addConfig(Choqok::BehaviorSettings::self(), mPrfsNotifyDlg);
80     d->mBehaviorTabCtl->addTab(mPrfsNotifyDlg, i18n("&Notifications"));
81     /* Remove below code, when all functions on tab will work*/
82     d->mPrfsNotify.kcfg_notifyInterval->setVisible(false);
83     d->mPrfsNotify.kcfg_showAllNotifiesInOne->setVisible(false);
84     d->mPrfsNotify.label_4->setVisible(false);
85     /*     */
86 #endif
87 
88     // "Shortening" TAB ===============================================================
89     d->mPrfsShorten = new BehaviorConfig_Shorten(d->mBehaviorTabCtl);
90     addConfig(Choqok::BehaviorSettings::self(), d->mPrfsShorten);
91     d->mBehaviorTabCtl->addTab(d->mPrfsShorten, i18n("URL &Shortening"));
92 
93     KCModuleInfo proxyInfo(QLatin1String("proxy.desktop"));
94     d->proxyModule = new KCModuleProxy(proxyInfo, parent);
95     d->mBehaviorTabCtl->addTab(d->proxyModule, proxyInfo.moduleName());
96 
97     connect(d->mPrfsShorten, (void (BehaviorConfig_Shorten::*)(bool))&BehaviorConfig_Shorten::changed,
98             this, &BehaviorConfig::markAsChanged);
99     connect(d->proxyModule, (void (KCModuleProxy::*)(KCModuleProxy*))&KCModuleProxy::changed,
100             this, &BehaviorConfig::markAsChanged);
101 
102     load();
103 
104 }
105 
~BehaviorConfig()106 BehaviorConfig::~BehaviorConfig()
107 {
108     delete d;
109 }
110 
save()111 void BehaviorConfig::save()
112 {
113     qCDebug(CHOQOK);
114 
115     KCModule::save();
116     d->mPrfsShorten->save();
117     d->proxyModule->save();
118 //     Choqok::BehaviorSettings::self()->writeConfig();
119 
120     load();
121 }
122 
load()123 void BehaviorConfig::load()
124 {
125     KCModule::load();
126     d->mPrfsShorten->load();
127     d->proxyModule->load();
128 }
129 
130 #include "behaviorconfig.moc"
131