knode
knnntpaccount.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <kconfig.h>
00016 #include <kstandarddirs.h>
00017 #include <kdebug.h>
00018
00019 #include "utilities.h"
00020 #include "kncollectionviewitem.h"
00021 #include "knnntpaccount.h"
00022 #include "knconfig.h"
00023 #include "knconfigmanager.h"
00024 #include "knconfigwidgets.h"
00025 #include "kngroupmanager.h"
00026 #include "knglobals.h"
00027
00028
00029 KNNntpAccountIntervalChecking::KNNntpAccountIntervalChecking(KNNntpAccount* account) : t_imer(0) {
00030 a_ccount = account;
00031 }
00032
00033
00034
00035 KNNntpAccountIntervalChecking::~KNNntpAccountIntervalChecking()
00036 {
00037 if (t_imer) deinstallTimer();
00038 a_ccount = 0;
00039 }
00040
00041
00042
00043 void KNNntpAccountIntervalChecking::installTimer()
00044 {
00045 if (a_ccount->checkInterval() <= 0) return;
00046 if(!t_imer)
00047 {
00048 t_imer = new QTimer();
00049 connect(t_imer,SIGNAL(timeout()),this,SLOT(slotCheckNews()));
00050 }
00051 else
00052 {
00053 t_imer->stop();
00054 }
00055 t_imer->start(a_ccount->checkInterval()*60000);
00056 }
00057
00058
00059
00060 void KNNntpAccountIntervalChecking::deinstallTimer()
00061 {
00062 delete t_imer;
00063 t_imer = 0;
00064 }
00065
00066
00067
00068 void KNNntpAccountIntervalChecking::slotCheckNews()
00069 {
00070 knGlobals.groupManager()->checkAll(a_ccount, true);
00071 }
00072
00073
00074
00075 KNNntpAccount::KNNntpAccount()
00076 : KNCollection(0), KNServerInfo(), i_dentity(0), f_etchDescriptions(true), w_asOpen(false), i_ntervalChecking(false), c_heckInterval(10)
00077 {
00078 l_astNewFetch = QDate::currentDate();
00079 a_ccountIntervalChecking = new KNNntpAccountIntervalChecking(this);
00080 mCleanupConf = new KNode::Cleanup( false );
00081 }
00082
00083
00084 KNNntpAccount::~KNNntpAccount()
00085 {
00086 delete a_ccountIntervalChecking;
00087 delete i_dentity;
00088 delete mCleanupConf;
00089 }
00090
00091
00092
00093 bool KNNntpAccount::readInfo(const QString &confPath)
00094 {
00095 KConfigGroup conf( KSharedConfig::openConfig(confPath, KConfig::SimpleConfig), QString() );
00096
00097 n_ame = conf.readEntry("name");
00098
00099 f_etchDescriptions = conf.readEntry("fetchDescriptions", true);
00100 l_astNewFetch = conf.readEntry("lastNewFetch", QDateTime() ).date();
00101 w_asOpen = conf.readEntry("listItemOpen", false);
00102 u_seDiskCache = conf.readEntry("useDiskCache", false);
00103 i_ntervalChecking=conf.readEntry("intervalChecking", false);
00104 c_heckInterval=conf.readEntry("checkInterval", 10);
00105 KNServerInfo::readConf(conf);
00106
00107 startTimer();
00108
00109 i_dentity=new KNode::Identity(false);
00110 i_dentity->loadConfig(conf);
00111 if(!i_dentity->isEmpty()) {
00112 kDebug(5003) <<"KNGroup::readInfo(const QString &confPath) : using alternative user for" << n_ame;
00113 } else {
00114 delete i_dentity;
00115 i_dentity=0;
00116 }
00117
00118 mCleanupConf->loadConfig( conf );
00119
00120 if (n_ame.isEmpty() || s_erver.isEmpty() || i_d == -1)
00121 return false;
00122 else
00123 return true;
00124 }
00125
00126
00127 void KNNntpAccount::saveInfo()
00128 {
00129 QString dir(path());
00130 if (dir.isNull())
00131 return;
00132
00133 KConfigGroup conf(KSharedConfig::openConfig( dir+"info", KConfig::SimpleConfig), QString() );
00134
00135 conf.writeEntry("name", n_ame);
00136
00137 conf.writeEntry("fetchDescriptions", f_etchDescriptions);
00138 conf.writeEntry("lastNewFetch", QDateTime(l_astNewFetch));
00139 if(l_istItem)
00140 conf.writeEntry("listItemOpen", l_istItem->isOpen());
00141 conf.writeEntry("useDiskCache", u_seDiskCache);
00142 conf.writeEntry("intervalChecking", i_ntervalChecking);
00143 conf.writeEntry("checkInterval", c_heckInterval);
00144
00145 KNServerInfo::saveConf(conf);
00146
00147 if(i_dentity)
00148 i_dentity->saveConfig(conf);
00149 else if(conf.hasKey("Email")) {
00150 conf.deleteEntry("Name", false);
00151 conf.deleteEntry("Email", false);
00152 conf.deleteEntry("Reply-To", false);
00153 conf.deleteEntry("Mail-Copies-To", false);
00154 conf.deleteEntry("Org", false);
00155 conf.deleteEntry("UseSigFile", false);
00156 conf.deleteEntry("UseSigGenerator", false);
00157 conf.deleteEntry("sigFile", false);
00158 conf.deleteEntry("sigText", false);
00159 }
00160
00161 mCleanupConf->saveConfig( conf );
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 QString KNNntpAccount::path()
00176 {
00177 QString dir(KStandardDirs::locateLocal("data","knode/")+QString("nntp.%1/").arg(i_d));
00178 if (dir.isNull())
00179 KNHelper::displayInternalFileError();
00180 return (dir);
00181 }
00182
00183
00184 bool KNNntpAccount::editProperties(QWidget *parent)
00185 {
00186 if(!i_dentity) i_dentity=new KNode::Identity(false);
00187 KNode::NntpAccountConfDialog *d = new KNode::NntpAccountConfDialog(this, parent);
00188
00189 bool ret=false;
00190 if (d->exec()) {
00191 updateListItem();
00192 ret=true;
00193 }
00194
00195 if(i_dentity->isEmpty()) {
00196 delete i_dentity;
00197 i_dentity=0;
00198 }
00199
00200 delete d;
00201 return ret;
00202 }
00203
00204 void KNNntpAccount::startTimer()
00205 {
00206 if ( (i_ntervalChecking == true) && (c_heckInterval > 0) )
00207 {
00208 a_ccountIntervalChecking->installTimer();
00209 }
00210 else
00211 {
00212 a_ccountIntervalChecking->deinstallTimer();
00213 }
00214 }
00215
00216 void KNNntpAccount::setCheckInterval(int c)
00217 {
00218 c_heckInterval = c;
00219 startTimer();
00220 }
00221
00222 KNode::Cleanup *KNNntpAccount::activeCleanupConfig() const
00223 {
00224 if (cleanupConfig()->useDefault())
00225 return knGlobals.configManager()->cleanup();
00226 return cleanupConfig();
00227 }
00228
00229 #include "knnntpaccount.moc"