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_conduit_null()
00048 {
00049     return new NullConduitFactory;
00050 }
00051 
00052 }
00053 
00054 class NullConduitConfig : public ConduitConfigBase
00055 {
00056 public:
00057     NullConduitConfig(QWidget *parent=0L, const char *n=0L);
00058     virtual void commit(KConfig *);
00059     virtual void load(KConfig *);
00060     static ConduitConfigBase *create(QWidget *p,const char *n)
00061         { return new NullConduitConfig(p,n); } ;
00062 protected:
00063     NullWidget *fConfigWidget;
00064 } ;
00065 
00066 NullConduitConfig::NullConduitConfig(QWidget *p, const char *n) :
00067     ConduitConfigBase(p,n),
00068     fConfigWidget(new NullWidget(p))
00069 {
00070     FUNCTIONSETUP;
00071     fConduitName = i18n("Null");
00072     UIDialog::addAboutPage(fConfigWidget->tabWidget,NullConduitFactory::about());
00073     fWidget=fConfigWidget;
00074     QObject::connect(fConfigWidget->fLogMessage,SIGNAL(textChanged(const QString&)),
00075         this,SLOT(modified()));
00076     QObject::connect(fConfigWidget->fDatabases,SIGNAL(textChanged(const QString&)),
00077         this,SLOT(modified()));
00078     QObject::connect(fConfigWidget->fFailImmediately,SIGNAL(toggled(bool)),
00079         this,SLOT(modified()));
00080 }
00081 
00082 /* virtual */ void NullConduitConfig::commit(KConfig *fConfig)
00083 {
00084     FUNCTIONSETUP;
00085 
00086 #ifdef DEBUG
00087     DEBUGCONDUIT << fname
00088         << ": Message="
00089         << fConfigWidget->fLogMessage->text()
00090         << endl;
00091     DEBUGCONDUIT << fname
00092         << ": Databases="
00093         << fConfigWidget->fDatabases->text()
00094         << endl;
00095 #endif
00096 
00097     KConfigGroupSaver s(fConfig,NullConduitFactory::group);
00098 
00099     fConfig->writeEntry(NullConduitFactory::message,fConfigWidget->fLogMessage->text());
00100     fConfig->writeEntry(NullConduitFactory::databases,fConfigWidget->fDatabases->text());
00101     fConfig->writeEntry(NullConduitFactory::failImmediately,
00102         fConfigWidget->fFailImmediately->isChecked());
00103 }
00104 
00105 /* virtual */ void NullConduitConfig::load(KConfig *fConfig)
00106 {
00107     FUNCTIONSETUP;
00108 
00109     KConfigGroupSaver s(fConfig,NullConduitFactory::group);
00110 
00111     fConfigWidget->fLogMessage->setText(
00112         fConfig->readEntry(NullConduitFactory::message,i18n("KPilot was here!")));
00113     fConfigWidget->fDatabases->setText(
00114         fConfig->readEntry(NullConduitFactory::databases));
00115     fConfigWidget->fFailImmediately->setChecked(
00116         fConfig->readBoolEntry(NullConduitFactory::failImmediately,false));
00117 
00118 #ifdef DEBUG
00119     DEBUGCONDUIT << fname
00120         << ": Read Message="
00121         << fConfigWidget->fLogMessage->text()
00122         << endl;
00123     DEBUGCONDUIT << fname
00124         << ": Read Database="
00125         << fConfigWidget->fDatabases->text()
00126         << endl;
00127 #endif
00128 
00129     fModified=false;
00130 }
00131 
00132 /* static */ const char * const NullConduitFactory::group = "Null-conduit";
00133 const char * const NullConduitFactory::databases = "Databases" ;
00134 const char * const NullConduitFactory::message = "LogMessage";
00135 const char * const NullConduitFactory::failImmediately = "FailNow";
00136 
00137 KAboutData *NullConduitFactory::fAbout = 0L;
00138 NullConduitFactory::NullConduitFactory(QObject *p, const char *n) :
00139     KLibFactory(p,n)
00140 {
00141     FUNCTIONSETUP;
00142 
00143     fInstance = new KInstance("nullconduit");
00144     fAbout = new KAboutData("nullConduit",
00145         I18N_NOOP("Null Conduit for KPilot"),
00146         KPILOT_VERSION,
00147         I18N_NOOP("Configures the Null Conduit for KPilot"),
00148         KAboutData::License_GPL,
00149         "(C) 2001, Adriaan de Groot");
00150     fAbout->addAuthor("Adriaan de Groot",
00151         I18N_NOOP("Primary Author"),
00152         "groot@kde.org",
00153         "http://www.cs.kun.nl/~adridg/kpilot");
00154 }
00155 
00156 NullConduitFactory::~NullConduitFactory()
00157 {
00158     FUNCTIONSETUP;
00159 
00160     KPILOT_DELETE(fInstance);
00161     KPILOT_DELETE(fAbout);
00162 }
00163 
00164 /* virtual */ QObject *NullConduitFactory::createObject( QObject *p,
00165     const char *n,
00166     const char *c,
00167     const QStringList &a)
00168 {
00169     FUNCTIONSETUP;
00170 
00171 #ifdef DEBUG
00172     DEBUGCONDUIT << fname
00173         << ": Creating object of class "
00174         << c
00175         << endl;
00176 #endif
00177 
00178     if (qstrcmp(c,"ConduitConfigBase")==0)
00179     {
00180         QWidget *w = dynamic_cast<QWidget *>(p);
00181         if (w)
00182         {
00183             return new NullConduitConfig(w);
00184         }
00185         else
00186         {
00187             return 0L;
00188         }
00189     }
00190     else
00191     if (qstrcmp(c,"ConduitConfig")==0)
00192     {
00193         QWidget *w = dynamic_cast<QWidget *>(p);
00194 
00195         if (w)
00196         {
00197             return new ConduitConfigImplementation(w,n,a,
00198                 NullConduitConfig::create);
00199         }
00200         else
00201         {
00202 #ifdef DEBUG
00203             DEBUGCONDUIT << fname
00204                 << ": Couldn't cast parent to widget."
00205                 << endl;
00206 #endif
00207             return 0L;
00208         }
00209     }
00210     else if (qstrcmp(c,"SyncAction")==0)
00211     {
00212         KPilotDeviceLink *d = dynamic_cast<KPilotDeviceLink *>(p);
00213 
00214         if (d)
00215         {
00216             return new NullConduit(d,n,a);
00217         }
00218         else
00219         {
00220             kdError() << k_funcinfo
00221                 << ": Couldn't cast to KPilotDeviceLink"
00222                 << endl;
00223             return 0L;
00224         }
00225     }
00226 
00227     return 0L;
00228 }
00229 
00230 
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:48 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003