kpilot Library API Documentation

null-factory.cc

00001 /* null-factory.cc                      KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 **
00005 ** This file defines the factory for the null-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 Lesser General Public License as published by
00011 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU Lesser 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 <qlineedit.h>
00033 #include <qcheckbox.h>
00034 
00035 #include <kconfig.h>
00036 #include <kinstance.h>
00037 #include <kaboutdata.h>
00038 
00039 #include "setup_base.h"
00040 #include "null-conduit.h"
00041 #include "null-factory.moc"
00042 
00043 
00044 extern "C"
00045 {
00046 
00047 void *init_libnullconduit()
00048 {
00049         return new NullConduitFactory;
00050 }
00051 
00052 } ;
00053 
00054 
00055 /* static */ const char * const NullConduitFactory::group = "Null-conduit";
00056 const char * const NullConduitFactory::databases = "Databases" ;
00057 const char * const NullConduitFactory::message = "LogMessage";
00058 const char * const NullConduitFactory::failImmediately = "FailNow";
00059 
00060 KAboutData *NullConduitFactory::fAbout = 0L;
00061 NullConduitFactory::NullConduitFactory(QObject *p, const char *n) :
00062         KLibFactory(p,n)
00063 {
00064         FUNCTIONSETUP;
00065 
00066         fInstance = new KInstance("nullconduit");
00067         fAbout = new KAboutData("nullConduit",
00068                 I18N_NOOP("Null Conduit for KPilot"),
00069                 KPILOT_VERSION,
00070                 I18N_NOOP("Configures the Null Conduit for KPilot"),
00071                 KAboutData::License_GPL,
00072                 "(C) 2001, Adriaan de Groot");
00073         fAbout->addAuthor("Adriaan de Groot",
00074                 I18N_NOOP("Primary Author"),
00075                 "groot@kde.org",
00076                 "http://www.cs.kun.nl/~adridg/kpilot");
00077 }
00078 
00079 NullConduitFactory::~NullConduitFactory()
00080 {
00081         FUNCTIONSETUP;
00082 
00083         KPILOT_DELETE(fInstance);
00084         KPILOT_DELETE(fAbout);
00085 }
00086 
00087 /* virtual */ QObject *NullConduitFactory::createObject( QObject *p,
00088         const char *n,
00089         const char *c,
00090         const QStringList &a)
00091 {
00092         FUNCTIONSETUP;
00093 
00094 #ifdef DEBUG
00095         DEBUGCONDUIT << fname
00096                 << ": Creating object of class "
00097                 << c
00098                 << endl;
00099 #endif
00100 
00101         if (qstrcmp(c,"ConduitConfig")==0)
00102         {
00103                 QWidget *w = dynamic_cast<QWidget *>(p);
00104 
00105                 if (w)
00106                 {
00107                         return new NullWidgetSetup(w,n,a);
00108                 }
00109                 else 
00110                 {
00111 #ifdef DEBUG
00112                         DEBUGCONDUIT << fname
00113                                 << ": Couldn't cast parent to widget."
00114                                 << endl;
00115 #endif
00116                         return 0L;
00117                 }
00118         }
00119         else if (qstrcmp(c,"SyncAction")==0)
00120         {
00121                 KPilotDeviceLink *d = dynamic_cast<KPilotDeviceLink *>(p);
00122 
00123                 if (d)
00124                 {
00125                         return new NullConduit(d,n,a);
00126                 }
00127                 else
00128                 {
00129                         kdError() << k_funcinfo
00130                                 << ": Couldn't cast to KPilotDeviceLink"
00131                                 << endl;
00132                         return 0L;
00133                 }
00134         }
00135 
00136         return 0L;
00137 }
00138 
00139 NullWidgetSetup::NullWidgetSetup(QWidget *w, const char *n, 
00140         const QStringList & a) :
00141         ConduitConfig(w,n,a)
00142 {
00143         FUNCTIONSETUP;
00144 
00145         fConfigWidget = new NullWidget(widget());
00146         setTabWidget(fConfigWidget->tabWidget);
00147         addAboutPage(false,NullConduitFactory::about());
00148 
00149         fConfigWidget->tabWidget->adjustSize();
00150         fConfigWidget->resize(fConfigWidget->tabWidget->size());
00151 }
00152 
00153 NullWidgetSetup::~NullWidgetSetup()
00154 {
00155         FUNCTIONSETUP;
00156 }
00157 
00158 /* virtual */ void NullWidgetSetup::commitChanges()
00159 {
00160         FUNCTIONSETUP;
00161 
00162         if (!fConfig) return;
00163 
00164 #ifdef DEBUG
00165         DEBUGCONDUIT << fname
00166                 << ": Message="
00167                 << fConfigWidget->fLogMessage->text()
00168                 << endl;
00169         DEBUGCONDUIT << fname
00170                 << ": Databases="
00171                 << fConfigWidget->fDatabases->text()
00172                 << endl;
00173 #endif
00174 
00175         KConfigGroupSaver s(fConfig,NullConduitFactory::group);
00176 
00177         fConfig->writeEntry(NullConduitFactory::message,fConfigWidget->fLogMessage->text());
00178         fConfig->writeEntry(NullConduitFactory::databases,fConfigWidget->fDatabases->text());
00179         fConfig->writeEntry(NullConduitFactory::failImmediately,
00180                 fConfigWidget->fFailImmediately->isChecked());
00181 }
00182 
00183 /* virtual */ void NullWidgetSetup::readSettings()
00184 {
00185         FUNCTIONSETUP;
00186 
00187         if (!fConfig) return;
00188 
00189         KConfigGroupSaver s(fConfig,NullConduitFactory::group);
00190 
00191         fConfigWidget->fLogMessage->setText(
00192                 fConfig->readEntry(NullConduitFactory::message,i18n("KPilot was here!")));
00193         fConfigWidget->fDatabases->setText(
00194                 fConfig->readEntry(NullConduitFactory::databases));
00195 
00196 #ifdef DEBUG
00197         DEBUGCONDUIT << fname
00198                 << ": Read Message="
00199                 << fConfigWidget->fLogMessage->text()
00200                 << endl;
00201         DEBUGCONDUIT << fname
00202                 << ": Read Database="
00203                 << fConfigWidget->fDatabases->text()
00204                 << endl;
00205 #endif
00206 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001