Fix typo found by Yuri Chornoivan
[kdepim.git] / knode / knnntpaccount.cpp
blobed6e68eff01a6b373ca73959c81009f201adad47
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #include <kconfig.h>
16 #include <kstandarddirs.h>
17 #include <kdebug.h>
19 #include "utilities.h"
20 #include "kncollectionviewitem.h"
21 #include "knnntpaccount.h"
22 #include "knconfig.h"
23 #include "knconfigmanager.h"
24 #include "knconfigwidgets.h"
25 #include "kngroupmanager.h"
26 #include "knglobals.h"
29 KNNntpAccountIntervalChecking::KNNntpAccountIntervalChecking(KNNntpAccount* account) : t_imer(0) {
30 a_ccount = account;
35 KNNntpAccountIntervalChecking::~KNNntpAccountIntervalChecking()
37 if (t_imer) deinstallTimer();
38 a_ccount = 0;
43 void KNNntpAccountIntervalChecking::installTimer()
45 if (a_ccount->checkInterval() <= 0) return;
46 if(!t_imer)
48 t_imer = new QTimer();
49 connect(t_imer,SIGNAL(timeout()),this,SLOT(slotCheckNews()));
51 else
53 t_imer->stop();
55 t_imer->start(a_ccount->checkInterval()*60000);
60 void KNNntpAccountIntervalChecking::deinstallTimer()
62 delete t_imer;
63 t_imer = 0;
68 void KNNntpAccountIntervalChecking::slotCheckNews()
70 knGlobals.groupManager()->checkAll(a_ccount, true);
75 KNNntpAccount::KNNntpAccount()
76 : KNCollection(0), KNServerInfo(), i_dentity(0), f_etchDescriptions(true), w_asOpen(false), i_ntervalChecking(false), c_heckInterval(10)
78 l_astNewFetch = QDate::currentDate();
79 a_ccountIntervalChecking = new KNNntpAccountIntervalChecking(this);
80 mCleanupConf = new KNode::Cleanup( false );
84 KNNntpAccount::~KNNntpAccount()
86 delete a_ccountIntervalChecking;
87 delete i_dentity;
88 delete mCleanupConf;
92 // tries to read information, returns false if it fails to do so
93 bool KNNntpAccount::readInfo(const QString &confPath)
95 KConfigGroup conf( KSharedConfig::openConfig(confPath, KConfig::SimpleConfig), QString() );
97 n_ame = conf.readEntry("name");
98 //u_nsentCount = conf.readEntry("unsentCnt", 0);
99 f_etchDescriptions = conf.readEntry("fetchDescriptions", true);
100 l_astNewFetch = conf.readEntry("lastNewFetch", QDateTime() ).date();
101 w_asOpen = conf.readEntry("listItemOpen", false);
102 u_seDiskCache = conf.readEntry("useDiskCache", false);
103 i_ntervalChecking=conf.readEntry("intervalChecking", false);
104 c_heckInterval=conf.readEntry("checkInterval", 10);
105 KNServerInfo::readConf(conf);
107 startTimer();
109 i_dentity=new KNode::Identity(false);
110 i_dentity->loadConfig(conf);
111 if(!i_dentity->isEmpty()) {
112 kDebug(5003) <<"KNGroup::readInfo(const QString &confPath) : using alternative user for" << n_ame;
113 } else {
114 delete i_dentity;
115 i_dentity=0;
118 mCleanupConf->loadConfig( conf );
120 if (n_ame.isEmpty() || s_erver.isEmpty() || i_d == -1)
121 return false;
122 else
123 return true;
127 void KNNntpAccount::saveInfo()
129 QString dir(path());
130 if (dir.isNull())
131 return;
133 KConfigGroup conf(KSharedConfig::openConfig( dir+"info", KConfig::SimpleConfig), QString() );
135 conf.writeEntry("name", n_ame);
136 //conf.writeEntry("unsentCnt", u_nsentCount);
137 conf.writeEntry("fetchDescriptions", f_etchDescriptions);
138 conf.writeEntry("lastNewFetch", QDateTime(l_astNewFetch));
139 if(l_istItem)
140 conf.writeEntry("listItemOpen", l_istItem->isExpanded());
141 conf.writeEntry("useDiskCache", u_seDiskCache);
142 conf.writeEntry("intervalChecking", i_ntervalChecking);
143 conf.writeEntry("checkInterval", c_heckInterval);
145 KNServerInfo::saveConf(conf); // save not KNNntpAccount specific settings
147 if(i_dentity)
148 i_dentity->saveConfig(conf);
149 else if(conf.hasKey("Email")) {
150 conf.deleteEntry("Name", false);
151 conf.deleteEntry("Email", false);
152 conf.deleteEntry("Reply-To", false);
153 conf.deleteEntry("Mail-Copies-To", false);
154 conf.deleteEntry("Org", false);
155 conf.deleteEntry("UseSigFile", false);
156 conf.deleteEntry("UseSigGenerator", false);
157 conf.deleteEntry("sigFile", false);
158 conf.deleteEntry("sigText", false);
161 mCleanupConf->saveConfig( conf );
165 /*void KNNntpAccount::syncInfo()
167 QString dir(path());
168 if (dir.isNull())
169 return;
170 KSimpleConfig conf(dir+"info");
171 conf.writeEntry("unsentCnt", u_nsentCount);
175 QString KNNntpAccount::path()
177 QString dir( KStandardDirs::locateLocal( "data", QString( "knode/nntp.%1/" ).arg( i_d ) ) );
178 if (dir.isNull())
179 KNHelper::displayInternalFileError();
180 return (dir);
184 bool KNNntpAccount::editProperties(QWidget *parent)
186 if(!i_dentity) i_dentity=new KNode::Identity(false);
187 KNode::NntpAccountConfDialog *d = new KNode::NntpAccountConfDialog(this, parent);
189 bool ret=false;
190 if (d->exec()) {
191 updateListItem();
192 ret=true;
195 if(i_dentity->isEmpty()) {
196 delete i_dentity;
197 i_dentity=0;
200 delete d;
201 return ret;
204 void KNNntpAccount::startTimer()
206 if ( (i_ntervalChecking == true) && (c_heckInterval > 0) )
208 a_ccountIntervalChecking->installTimer();
210 else
212 a_ccountIntervalChecking->deinstallTimer();
216 void KNNntpAccount::setCheckInterval(int c)
218 c_heckInterval = c;
219 startTimer();
222 KNode::Cleanup *KNNntpAccount::activeCleanupConfig() const
224 if (cleanupConfig()->useDefault())
225 return knGlobals.configManager()->cleanup();
226 return cleanupConfig();
229 #include "knnntpaccount.moc"