kalarmd Library API Documentation

adconfigdatarw.cpp

00001 /*
00002     Client data access for KDE Alarm Daemon.
00003 
00004     This file is part of the KDE alarm daemon.
00005     Copyright (c) 2001 David Jarvie <software@astrojar.org.uk>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <kdebug.h>
00027 #include <kstandarddirs.h>
00028 
00029 #include "adcalendar.h"
00030 
00031 #include "adconfigdatarw.h"
00032 
00033 void ADConfigDataRW::readDaemonData(bool sessionStarting)
00034 {
00035   kdDebug(5900) << "ADConfigDataRW::readDaemonData()" << endl;
00036 
00037   KSimpleConfig clientConfig(clientDataFile());
00038 
00039   ADCalendarFactory calFactory;
00040   bool cls, cals;
00041   QString newClients = readConfigData(sessionStarting, cls, cals, &calFactory);
00042   if (!newClients.isEmpty())
00043   {
00044     // One or more clients in the Clients config entry was invalid, so rewrite the entry
00045     clientConfig.setGroup("General");
00046     clientConfig.writeEntry(CLIENTS_KEY, newClients);
00047   }
00048 
00049   // Read the GUI clients
00050   QStrList guis;
00051   clientConfig.readListEntry(GUIS_KEY, guis);
00052   bool writeNewGuis = false;
00053   QString newGuis;
00054   for (unsigned int i = 0;  i < guis.count();  ++i)
00055   {
00056     QCString gui = guis.at(i);
00057     kdDebug(5900) << "ADConfigDataRW::readDaemonData(): gui: " << gui << endl;
00058     if (gui.isEmpty()
00059     ||  KStandardDirs::findExe(gui).isNull())
00060     {
00061       // Null client name, or application doesn't exist
00062       if (!gui.isEmpty())
00063         clientConfig.deleteGroup(GUI_KEY + gui, true);
00064       writeNewGuis = true;
00065     }
00066     else
00067     {
00068       // Get this client's details from its own config section
00069       QString groupKey = GUI_KEY + gui;
00070       clientConfig.setGroup(groupKey);
00071       QCString dcopObject = clientConfig.readEntry(CLIENT_DCOP_OBJECT_KEY).local8Bit();
00072       mGuis.insert(gui, dcopObject);
00073       if (!newGuis.isEmpty())
00074         newGuis += ',';
00075       newGuis += gui;
00076     }
00077   }
00078   if (writeNewGuis)
00079   {
00080     // One or more clients in the Guis config entry was invalid, so rewrite the entry
00081     clientConfig.setGroup("General");
00082     clientConfig.writeEntry(GUIS_KEY, newGuis);
00083   }
00084 }
00085 
00086 /*
00087  * Write a client application's details to the client data file.
00088  * Any existing entries relating to the application are deleted,
00089  * including calendar file information.
00090  */
00091 void ADConfigDataRW::writeConfigClient(const QCString& appName, const ClientInfo& cinfo)
00092 {
00093   KSimpleConfig clientConfig(clientDataFile());
00094   addConfigClient(clientConfig, appName, CLIENTS_KEY);
00095 
00096   QString groupKey = CLIENT_KEY + appName;
00097   clientConfig.deleteGroup(groupKey, true);
00098 
00099   clientConfig.setGroup(groupKey);
00100   clientConfig.writeEntry(CLIENT_TITLE_KEY, cinfo.title);
00101   if (!cinfo.dcopObject.isEmpty())
00102     clientConfig.writeEntry(CLIENT_DCOP_OBJECT_KEY, QString::fromLocal8Bit(cinfo.dcopObject));
00103   clientConfig.writeEntry(CLIENT_NOTIFICATION_KEY, cinfo.notificationType);
00104   clientConfig.writeEntry(CLIENT_DISP_CAL_KEY, cinfo.displayCalName);
00105   int i = 0;
00106   for (ADCalendarBase* cal = mCalendars.first();  cal;  cal = mCalendars.next())
00107   {
00108     if (cal->appName() == appName)
00109     {
00110       cal->setRcIndex(++i);
00111       writeConfigCalendar(cal, clientConfig);
00112     }
00113   }
00114 }
00115 
00116 /*
00117  * Write a GUI client application's details to the client data file.
00118  */
00119 void ADConfigDataRW::writeConfigClientGui(const QCString& appName, const QString& dcopObject)
00120 {
00121   KSimpleConfig clientConfig(clientDataFile());
00122   addConfigClient(clientConfig, appName, GUIS_KEY);
00123 
00124   QString groupKey = GUI_KEY + appName;
00125 
00126   clientConfig.setGroup(groupKey);
00127   clientConfig.writeEntry(CLIENT_DCOP_OBJECT_KEY, dcopObject);
00128 }
00129 
00130 /*
00131  * Add a client application's name to the client data file list.
00132  */
00133 void ADConfigDataRW::addConfigClient(KSimpleConfig& clientConfig, const QCString& appName, const QString& key)
00134 {
00135   clientConfig.setGroup("General");
00136   QStringList clients = QStringList::split(',', clientConfig.readEntry(key), true);
00137   if (clients.find(appName) == clients.end())
00138   {
00139     // It's a new client, so add it to the Clients config file entry
00140     for (QStringList::Iterator i = clients.begin();  i != clients.end();  )
00141     {
00142       if ((*i).isEmpty())
00143         i = clients.remove(i);    // remove null entries
00144       else
00145         ++i;
00146     }
00147     clients.append(appName);
00148     clientConfig.writeEntry(key, clients.join(","));
00149   }
00150 }
00151 
00152 // Add a calendar file URL to the client data file for a specified application.
00153 void ADConfigDataRW::addConfigCalendar(const QCString& appName, ADCalendarBase* cal)
00154 {
00155   KSimpleConfig clientConfig(clientDataFile());
00156   QString groupKey = CLIENT_KEY + appName;
00157   QMap<QString, QString> entries = clientConfig.entryMap(groupKey);
00158   // Find an unused CalendarN entry for this calendar
00159   for (int i = 1;  ;  ++i)
00160   {
00161     QString key = CLIENT_CALENDAR_KEY + QString::number(i);
00162     if (entries.find(key) == entries.end())
00163     {
00164       // This calendar index is unused, so use it for the new calendar
00165       cal->setRcIndex(i);
00166       writeConfigCalendar(cal, clientConfig);
00167       return;
00168     }
00169   }
00170 }
00171 
00172 // Update a calendar file entry in the client data file.
00173 void ADConfigDataRW::writeConfigCalendar(const ADCalendarBase* cal)
00174 {
00175   if (cal->rcIndex() > 0)
00176   {
00177     KSimpleConfig clientConfig(clientDataFile());
00178     writeConfigCalendar(cal, clientConfig);
00179   }
00180 }
00181 
00182 // Update a calendar file entry in the client data file.
00183 void ADConfigDataRW::writeConfigCalendar(const ADCalendarBase* cal, KSimpleConfig& clientConfig)
00184 {
00185   if (cal->rcIndex() > 0)
00186   {
00187     clientConfig.setGroup(CLIENT_KEY + cal->appName());
00188     QString dt;
00189     if (cal->lastCheck().isValid())
00190       dt = QString::number(baseDateTime().secsTo(cal->lastCheck()));
00191     clientConfig.writeEntry(CLIENT_CALENDAR_KEY + QString::number(cal->rcIndex()),
00192                             QString("%1,%2,%3").arg(cal->actionType()).arg(dt).arg(cal->urlString()));
00193   }
00194 }
00195 
00196 /*
00197  * Delete all entries in the client data file for the specified calendar
00198  */
00199 void ADConfigDataRW::deleteConfigCalendar(const ADCalendarBase* cal)
00200 {
00201   KSimpleConfig clientConfig(clientDataFile());
00202   QString groupKey = CLIENT_KEY + cal->appName();
00203   int len = CLIENT_CALENDAR_KEY.length();
00204   QMap<QString, QString> entries = clientConfig.entryMap(groupKey);
00205   for (QMap<QString, QString>::ConstIterator it = entries.begin();  it != entries.end();  ++it)
00206   {
00207     if (it.key().startsWith(CLIENT_CALENDAR_KEY))
00208     {
00209       bool ok;
00210       it.key().mid(len).toInt(&ok);
00211       if (ok)
00212       {
00213         // The config file key is CalendarN
00214         int comma = it.data().find(',');
00215         if (comma >= 0  &&  it.data().mid(comma + 1) == cal->urlString())
00216         {
00217           clientConfig.setGroup(groupKey);
00218           clientConfig.deleteEntry(it.key(), true);
00219         }
00220       }
00221     }
00222   }
00223 }
00224 
00225 /*
00226  * Flush changes in the client data file to disc.
00227  */
00228 void ADConfigDataRW::sync()
00229 {
00230   KSimpleConfig clientConfig(clientDataFile());
00231   clientConfig.sync();
00232 }
KDE Logo
This file is part of the documentation for kalarmd Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:04 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003