kpilot Library API Documentation

sysinfo-setup.cc

00001 /* SysInfo-setup.cc                      KPilot
00002 **
00003 ** Copyright (C) 2003 by Reinhold Kainhofer
00004 **
00005 ** This file defines the setup dialog for the SysInfo-conduit plugin.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 #include "options.h"
00030 
00031 #include <qtabwidget.h>
00032 #include <qradiobutton.h>
00033 #include <qcheckbox.h>
00034 #include <qbuttongroup.h>
00035 #include <qlistview.h>
00036 #include <kapplication.h>
00037 #include <kconfig.h>
00038 #include <kurlrequester.h>
00039 
00040 #include "sysinfo-setup_dialog.h"
00041 
00042 #include "sysinfo-factory.h"
00043 #include "sysinfo-setup.h"
00044 
00045 typedef struct { const char *name; const char *key; } sysinfoEntry_t;
00046 
00047 const sysinfoEntry_t sysinfoEntries[] =
00048 {
00049     { I18N_NOOP("Hardware information"),
00050         SysInfoConduitFactory::fHardwareInfo },
00051     { I18N_NOOP("User information"),
00052         SysInfoConduitFactory::fUserInfo },
00053     { I18N_NOOP("Memory information"),
00054         SysInfoConduitFactory::fMemoryInfo },
00055     { I18N_NOOP("Storage info (SD card, memory stick, ...)"),
00056         SysInfoConduitFactory::fStorageInfo },
00057     { I18N_NOOP("List of databases on handheld (takes long!)"),
00058         SysInfoConduitFactory::fDBList },
00059     { I18N_NOOP("Number of addresses, todos, events and memos"),
00060         SysInfoConduitFactory::fRecordNumber },
00061     { I18N_NOOP("Synchronization information"),
00062         SysInfoConduitFactory::fSyncInfo },
00063     { I18N_NOOP("Version of KPilot, pilot-link and KDE"),
00064         SysInfoConduitFactory::fKDEVersion },
00065     { I18N_NOOP("PalmOS version"),
00066         SysInfoConduitFactory::fPalmOSVersion },
00067     { I18N_NOOP("Debug information (for KPilot developers)"),
00068         SysInfoConduitFactory::fDebugInfo },
00069     { 0L,0L }
00070 } ;
00071 
00072 
00073 /*
00074 ** The QCheckListItems used in the list of parts to print have
00075 ** several text fields with special meanings.
00076 **    0: The text displayed in the list.
00077 **    1: The KConfig key the item came from.
00078 **    2: This string is empty if the part was originally not checked,
00079 **       and non-empty (probably "1") if the part was originally checked.
00080 **       This is used to detect changes in the configuration.
00081 ** We introduce some defines for these numbers.
00082 */
00083 
00084 #define PART_NAME   (0)
00085 #define PART_KEY    (1)
00086 #define PART_SETTING    (2)
00087 
00088 /*
00089 ** This is a convenience define to update an item's "original setting".
00090 */
00091 #define updateSetting(i) { QCheckListItem *ubbu=(i); \
00092     ubbu->setText(PART_SETTING,(ubbu->isOn() ? CSL1("1") : QString::null)); }
00093 
00094 
00095 SysInfoWidgetConfig::SysInfoWidgetConfig(QWidget *w, const char *n) :
00096     ConduitConfigBase(w,n),
00097     fConfigWidget(new SysInfoWidget(w))
00098 {
00099     FUNCTIONSETUP;
00100     UIDialog::addAboutPage(fConfigWidget->tabWidget,SysInfoConduitFactory::about());
00101     fWidget=fConfigWidget;
00102 
00103     QObject::connect(fConfigWidget->fOutputFile,SIGNAL(textChanged(const QString&)),
00104         this,SLOT(modified()));
00105     QObject::connect(fConfigWidget->fTemplateFile,SIGNAL(textChanged(const QString&)),
00106         this,SLOT(modified()));
00107     QObject::connect(fConfigWidget->fOutputType,SIGNAL(clicked(int)),
00108         this,SLOT(modified()));
00109     fConduitName=i18n("System Information");
00110 }
00111 
00112 void SysInfoWidgetConfig::commit(KConfig *fConfig)
00113 {
00114     FUNCTIONSETUP;
00115     KConfigGroupSaver s(fConfig,SysInfoConduitFactory::fGroup);
00116     fConfig->writePathEntry(SysInfoConduitFactory::fOutputFile,
00117         fConfigWidget->fOutputFile->url());
00118     fConfig->writeEntry(SysInfoConduitFactory::fTemplateFile,
00119         fConfigWidget->fTemplateFile->url());
00120     fConfig->writeEntry(SysInfoConduitFactory::fOutputType,
00121         fConfigWidget->fOutputType->id(fConfigWidget->fOutputType->selected()));
00122 
00123     QListViewItem *i = fConfigWidget->fPartsList->firstChild();
00124     QCheckListItem *ci = dynamic_cast<QCheckListItem *>(i);
00125 
00126     while(ci)
00127     {
00128 #ifdef DEBUG
00129         DEBUGCONDUIT << fname << ": Saving " << ci->text(PART_KEY)
00130             << (ci->isOn() ? " on" : " off") << endl;
00131 #endif
00132         fConfig->writeEntry(ci->text(PART_KEY),ci->isOn());
00133         updateSetting(ci);
00134         i=i->nextSibling();
00135         ci = dynamic_cast<QCheckListItem *>(i);
00136     }
00137     unmodified();
00138 }
00139 
00140 void SysInfoWidgetConfig::load(KConfig *fConfig)
00141 {
00142     FUNCTIONSETUP;
00143     KConfigGroupSaver s(fConfig,SysInfoConduitFactory::fGroup);
00144     fConfigWidget->fOutputFile->setURL(fConfig->readPathEntry(SysInfoConduitFactory::fOutputFile));
00145     fConfigWidget->fTemplateFile->setURL(fConfig->readPathEntry(SysInfoConduitFactory::fTemplateFile));
00146     fConfigWidget->fOutputType->setButton(fConfig->readNumEntry(SysInfoConduitFactory::fOutputType, 0));
00147 
00148     const sysinfoEntry_t *p = sysinfoEntries;
00149     QCheckListItem *i = 0L;
00150     while (p && p->name)
00151     {
00152         i = new QCheckListItem(fConfigWidget->fPartsList,i18n(p->name),QCheckListItem::CheckBox);
00153         // by default let the sysinfo conduit write out all available information
00154         i->setOn(fConfig->readBoolEntry(p->key, true));
00155         i->setText(PART_KEY,QString::fromLatin1(p->key));
00156         updateSetting(i);
00157 #ifdef DEBUG
00158         DEBUGCONDUIT << fname << ": Loaded " << p->key
00159             << (i->isOn() ? " on" : " off") << endl;
00160 #endif
00161         p++;
00162     }
00163     unmodified();
00164 }
00165 
00166 /* virtual */ bool SysInfoWidgetConfig::isModified() const
00167 {
00168     FUNCTIONSETUP;
00169     if (fModified) return true;
00170 
00171     QListViewItem *i = fConfigWidget->fPartsList->firstChild();
00172     QCheckListItem *ci = dynamic_cast<QCheckListItem *>(i);
00173 
00174     while(ci)
00175     {
00176         bool current = ci->isOn();
00177         bool original = !ci->text(PART_SETTING).isEmpty();
00178 #ifdef DEBUG
00179         DEBUGCONDUIT << fname << ": Checking " << ci->text(PART_KEY)
00180             <<  " was " << (original ? " on" : " off")
00181             << " now " << (current ? " on" : " off") << endl;
00182 #endif
00183 
00184         if (current!=original) return true;
00185         i=i->nextSibling();
00186         ci = dynamic_cast<QCheckListItem *>(i);
00187     }
00188     return false;
00189 }
00190 
00191 SysInfoWidgetSetup::SysInfoWidgetSetup(QWidget *w, const char *n,
00192     const QStringList & a) :
00193     ConduitConfig(w,n,a)
00194 {
00195     FUNCTIONSETUP;
00196 
00197     fConfigBase = new SysInfoWidgetConfig(widget(),"ConfigWidget");
00198     fConduitName = i18n("System Information");
00199 }
00200 
00201 SysInfoWidgetSetup::~SysInfoWidgetSetup()
00202 {
00203     FUNCTIONSETUP;
00204 }
00205 
00206 /* virtual */ void SysInfoWidgetSetup::commitChanges()
00207 {
00208     FUNCTIONSETUP;
00209 
00210     if (!fConfig) return;
00211     fConfigBase->commit(fConfig);
00212 }
00213 
00214 /* virtual */ void SysInfoWidgetSetup::readSettings()
00215 {
00216     FUNCTIONSETUP;
00217 
00218     if (!fConfig) return;
00219     fConfigBase->load(fConfig);
00220 }
00221 
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:49 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003