adconfigdatabase.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <kstandarddirs.h>
00027 #include <kurl.h>
00028 #include <kdebug.h>
00029 #include <ksimpleconfig.h>
00030
00031 #include "adconfigdatabase.h"
00032
00033
00034 #define CLIENT_DATA_FILE "clients"
00035
00036
00037 const QCString ADConfigDataBase::CLIENT_KEY("Client_");
00038 const QString ADConfigDataBase::CLIENTS_KEY("Clients");
00039 const QCString ADConfigDataBase::GUI_KEY("Gui_");
00040 const QString ADConfigDataBase::GUIS_KEY("Guis");
00041
00042 const QString ADConfigDataBase::CLIENT_CALENDAR_KEY("Calendar");
00043 const QString ADConfigDataBase::CLIENT_TITLE_KEY("Title");
00044 const QString ADConfigDataBase::CLIENT_DCOP_OBJECT_KEY("DCOP object");
00045 const QString ADConfigDataBase::CLIENT_NOTIFICATION_KEY("Notification");
00046 const QString ADConfigDataBase::CLIENT_DISP_CAL_KEY("Display calendar names");
00047
00048
00049 ADConfigDataBase::ADConfigDataBase(bool daemon)
00050 : mIsAlarmDaemon(daemon)
00051 {
00052 mCalendars.setAutoDelete(true);
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062 QString ADConfigDataBase::readConfigData(bool sessionStarting, bool& deletedClients, bool& deletedCalendars,
00063 ADCalendarBaseFactory *calFactory)
00064 {
00065 kdDebug(5900) << "ADConfigDataBase::readConfigData()" << endl;
00066 deletedClients = false;
00067 deletedCalendars = false;
00068 if (mClientDataFile.isEmpty())
00069 {
00070 if (mIsAlarmDaemon)
00071 mClientDataFile = locateLocal("appdata", QString(CLIENT_DATA_FILE));
00072 else
00073 mClientDataFile = locate("data", QString("kalarmd/" CLIENT_DATA_FILE));
00074 }
00075 KSimpleConfig clientConfig(mClientDataFile);
00076 clientConfig.setGroup("General");
00077 QStrList clients;
00078 clientConfig.readListEntry(CLIENTS_KEY, clients);
00079
00080
00081 for (ClientList::Iterator cl = mClients.begin(); cl != mClients.end(); )
00082 {
00083 bool found = false;
00084 for (unsigned int i = 0; i < clients.count(); ++i)
00085 if (clients.at(i) == (*cl).appName)
00086 {
00087 found = true;
00088 break;
00089 }
00090 if (!found)
00091 {
00092
00093 for (ADCalendarBase* cal = mCalendars.first(); cal; cal = mCalendars.next())
00094 {
00095 if (cal->appName() == (*cl).appName)
00096 {
00097 mCalendars.remove(cal);
00098 deletedCalendars = true;
00099 }
00100 }
00101 ClientList::Iterator c = cl;
00102 ++cl;
00103 mClients.remove(c);
00104 deletedClients = true;
00105 }
00106 else
00107 ++cl;
00108 }
00109
00110
00111 bool writeNewClients = false;
00112 QString newClients;
00113 for (unsigned int i = 0; i < clients.count(); ++i)
00114 {
00115 kdDebug(5900) << "ADConfigDataBase::readConfigData(): client: "
00116 << clients.at(i) << endl;
00117 QCString client = clients.at(i);
00118 if ( client.isEmpty() ||
00119 KStandardDirs::findExe( client ).isNull() )
00120 {
00121
00122 if (mIsAlarmDaemon)
00123 {
00124 if (!client.isEmpty())
00125 clientConfig.deleteGroup(CLIENT_KEY + client, true);
00126 writeNewClients = true;
00127 }
00128 }
00129 else
00130 {
00131 QString groupKey = CLIENT_KEY + client;
00132
00133
00134
00135 ClientInfo info = getClientInfo( client );
00136 if ( info.isValid() )
00137 removeClientInfo( client );
00138 clientConfig.setGroup(groupKey);
00139 QString title = clientConfig.readEntry(CLIENT_TITLE_KEY, client);
00140 QCString dcopObject = clientConfig.readEntry(CLIENT_DCOP_OBJECT_KEY).local8Bit();
00141 int type = clientConfig.readNumEntry(CLIENT_NOTIFICATION_KEY, 0);
00142 bool displayCalName = clientConfig.readBoolEntry(CLIENT_DISP_CAL_KEY, true);
00143 info = ClientInfo( client, title, dcopObject, type, displayCalName, sessionStarting );
00144 mClients.append( info );
00145
00146
00147 QStrList newCalendars;
00148 int len = CLIENT_CALENDAR_KEY.length();
00149 QMap<QString, QString> entries = clientConfig.entryMap(groupKey);
00150 for (QMap<QString, QString>::ConstIterator it = entries.begin(); it != entries.end(); ++it)
00151 {
00152 if (it.key().startsWith(CLIENT_CALENDAR_KEY))
00153 {
00154 kdDebug(5900) << "ADConfigDataBase::readConfigData(): " << it.key() << "=" << it.data() << endl;
00155 bool ok;
00156 int rcIndex = it.key().mid(len).toInt(&ok);
00157 if (ok)
00158 {
00159
00160 int comma1 = it.data().find(',');
00161 if (comma1 >= 0)
00162 {
00163 QDateTime dateTime;
00164 int comma2 = it.data().find(',', comma1 + 1);
00165 if (comma2 < 0)
00166 {
00167
00168 comma2 = comma1;
00169 }
00170 else
00171 {
00172
00173 int secs = it.data().mid(comma1 + 1, comma2 - comma1 - 1).toInt(&ok);
00174 if (ok)
00175 dateTime = baseDateTime().addSecs(secs);
00176 }
00177 QString calname = it.data().mid(comma2 + 1);
00178 if ( !calname.isEmpty() ) {
00179 ADCalendarBase* cal = getCalendar(calname);
00180 if (cal)
00181 {
00182
00183
00184 if (mIsAlarmDaemon)
00185 deleteConfigCalendar(cal);
00186 }
00187 else
00188 {
00189
00190 cal = calFactory->create(calname, client,
00191 static_cast<ADCalendarBase::Type>(it.data().left(comma1).toInt()));
00192 cal->setRcIndex(rcIndex);
00193 cal->setLastCheck(dateTime);
00194 mCalendars.append(cal);
00195 kdDebug(5900) << "ADConfigDataBase::readConfigData(): calendar " << cal->urlString() << endl;
00196 }
00197 newCalendars.append(calname.latin1());
00198 }
00199 }
00200 }
00201 }
00202 }
00203
00204 if (!newClients.isEmpty())
00205 newClients += ',';
00206 newClients += client;
00207
00208
00209 for (ADCalendarBase *cal = mCalendars.first(); cal; )
00210 {
00211 kdDebug(5900) << "tick..." << endl;
00212 if (cal->appName() == client)
00213 {
00214 if (newCalendars.find(cal->urlString().latin1()) == -1) {
00215 deletedCalendars = true;
00216 mCalendars.remove();
00217 cal = mCalendars.current();
00218 continue;
00219 }
00220 }
00221 cal = mCalendars.next();
00222 }
00223 }
00224 }
00225
00226 kdDebug(5900) << "ADConfigDataBase::readConfigData() done" << endl;
00227
00228 return writeNewClients ? newClients : QString::null;
00229 }
00230
00231 void ADConfigDataBase::deleteConfigCalendar(const ADCalendarBase*)
00232 {
00233 }
00234
00235
00236 ClientInfo ADConfigDataBase::getClientInfo(const QCString& appName)
00237 {
00238 ClientList::Iterator it;
00239 for( it = mClients.begin(); it != mClients.end(); ++it ) {
00240 if ( (*it).appName == appName ) return *it;
00241 }
00242 return ClientInfo();
00243 }
00244
00245 void ADConfigDataBase::removeClientInfo( const QCString &appName )
00246 {
00247 ClientList::Iterator it;
00248 for( it = mClients.begin(); it != mClients.end(); ++it ) {
00249 if ( (*it).appName == appName ) {
00250 mClients.remove(it);
00251 break;
00252 }
00253 }
00254 }
00255
00256
00257 ADCalendarBase *ADConfigDataBase::getCalendar(const QString& calendarURL)
00258 {
00259 if (!calendarURL.isEmpty())
00260 {
00261 for (ADCalendarBase *cal = mCalendars.first(); cal; cal = mCalendars.next())
00262 {
00263 if (cal->urlString() == calendarURL)
00264 return cal;
00265 }
00266 }
00267 return 0L;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276 QString ADConfigDataBase::expandURL(const QString& urlString)
00277 {
00278 if (urlString.isEmpty())
00279 return QString();
00280 return KURL(urlString).url();
00281 }
00282
00283 const QDateTime& ADConfigDataBase::baseDateTime()
00284 {
00285 static const QDateTime bdt(QDate(1970,1,1), QTime(0,0,0));
00286 return bdt;
00287 }
This file is part of the documentation for kalarmd Library Version 3.2.2.