Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

obackendfactory.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 /*
00030  * =====================================================================
00031  * ToDo: Use plugins
00032  * =====================================================================
00033  */
00034 #ifndef OPIE_BACKENDFACTORY_H_
00035 #define OPIE_BACKENDFACTORY_H_
00036 
00037 /* OPIE */
00038 #include <opie2/opimaccessbackend.h>
00039 #include <opie2/opimglobal.h>
00040 #include <opie2/otodoaccessxml.h>
00041 #include <opie2/otodoaccessvcal.h>
00042 #include <opie2/ocontactaccessbackend_xml.h>
00043 #include <opie2/ocontactaccessbackend_vcard.h>
00044 #include <opie2/odatebookaccessbackend_xml.h>
00045 #include <opie2/odebug.h>
00046 
00047 #ifdef __USE_SQL
00048 #include <opie2/otodoaccesssql.h>
00049 #include <opie2/ocontactaccessbackend_sql.h>
00050 #include <opie2/odatebookaccessbackend_sql.h>
00051 #endif
00052 
00053 #include <qpe/config.h>
00054 
00055 /* QT */
00056 #include <qstring.h>
00057 #include <qasciidict.h>
00058 
00059 
00060 
00061 using namespace Opie;
00062 using namespace Opie::Pim;
00063 
00064 namespace Opie {
00065 
00066 class OBackendPrivate;
00067 
00083  template<class T>
00084          class OBackendFactory
00085          {
00086          public:
00087              OBackendFactory() {};
00088 
00097                  static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
00098                                    const QString& appName, const QString& filename = QString::null ){
00099                         owarn << "Selected backend for " << type << " is: " <<
00100 database << oendl;
00101 
00102                         // If we should use the dafult database style, we have to request it
00103                          OPimGlobal::DatabaseStyle use_database = database;
00104                          if ( use_database == OPimGlobal::DEFAULT ){
00105                                  use_database = defaultDB( type );
00106                          }
00107 
00108                          switch ( type ){
00109                          case OPimGlobal::TODOLIST:
00110 
00111                                  switch ( use_database ){
00112                                  default: // Use SQL if something weird is given.
00113                                          // Fall through !!
00114                                  case OPimGlobal::SQL:
00115 #ifdef __USE_SQL
00116                                          return (T*) new OPimTodoAccessBackendSQL( filename );
00117                                          break;
00118 #else
00119                                          owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl;
00120                                          // Fall through !!
00121 #endif
00122                                  case OPimGlobal::XML:
00123                                          return (T*) new OPimTodoAccessXML( appName, filename );
00124                                          break;
00125                                  case OPimGlobal::VCARD:
00126                                          return (T*) new OPimTodoAccessVCal( filename );
00127                                          break;
00128                                  }
00129                          case OPimGlobal::CONTACTLIST:
00130                                  switch ( use_database ){
00131                                  default: // Use SQL if something weird is given.
00132                                          // Fall through !!
00133                                  case OPimGlobal::SQL:
00134 #ifdef __USE_SQL
00135                                          return (T*) new OPimContactAccessBackend_SQL( appName, filename );
00136                                          break;
00137 #else
00138                                          owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl;
00139                                          // Fall through !!
00140 #endif
00141                                  case OPimGlobal::XML:
00142                                          return (T*) new OPimContactAccessBackend_XML( appName, filename );
00143                                          break;
00144                                  case OPimGlobal::VCARD:
00145                                          return (T*) new OPimContactAccessBackend_VCard( appName, filename );
00146                                          break;
00147                                  }
00148                          case OPimGlobal::DATEBOOK:
00149                                  switch ( use_database ){
00150                                  default: // Use SQL if something weird is given.
00151                                          // Fall through !!
00152                                  case OPimGlobal::SQL:
00153 #ifdef __USE_SQL
00154                                          return (T*) new ODateBookAccessBackend_SQL( appName, filename );
00155                                          break;
00156 #else
00157                                          owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl;
00158                                          // Fall through !!
00159 #endif
00160                                  case OPimGlobal::XML:
00161                                          return (T*) new ODateBookAccessBackend_XML( appName, filename );
00162                                          break;
00163                                  case OPimGlobal::VCARD:
00164                                          owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl;
00165                                          return (T*) NULL;
00166                                          break;
00167                                  }
00168                          default:
00169                                  return (T*) NULL;
00170                          }
00171 
00172                  }
00173 
00179                  static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
00180                          QString group_name;
00181                          switch ( type ){
00182                          case OPimGlobal::TODOLIST:
00183                                  group_name = "todo";
00184                                  break;
00185                          case OPimGlobal::CONTACTLIST:
00186                                  group_name = "contact";
00187                                  break;
00188                          case OPimGlobal::DATEBOOK:
00189                                  group_name = "datebook";
00190                                  break;
00191                          default:
00192                                  group_name = "unknown";
00193                          }
00194 
00195                          Config config( "pimaccess" );
00196                          config.setGroup ( group_name );
00197                          QString db_String = config.readEntry( "usebackend", "xml" );
00198 
00199                          QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
00200                          dictDbTypes.setAutoDelete( TRUE );
00201 
00202                          dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
00203                          dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
00204                          dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
00205 
00206                          int* db_find = dictDbTypes[ db_String ];
00207 
00208                          if ( !db_find )
00209                                  return OPimGlobal::UNKNOWN;
00210 
00211                          return (OPimGlobal::DatabaseStyle) *db_find;
00212                  }
00213 
00214 
00222                  static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
00223                          return create( type, OPimGlobal::DEFAULT, appName );
00224                  }
00225          private:
00226                  OBackendPrivate* d;
00227 
00228          };
00229 
00230 }
00231 
00232 #endif

Generated on Sat Nov 5 16:16:13 2005 for OPIE by  doxygen 1.4.2