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

ocontactaccess.cpp

Go to the documentation of this file.
00001 /*
00002  * Class to manage the Contacts.
00003  *
00004  * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
00005  *
00006  * =====================================================================
00007  *      This program is free software; you can redistribute it and/or
00008  *      modify it under the terms of the GNU Library General Public
00009  *      License as published by the Free Software Foundation; either
00010  *      version 2 of the License, or (at your option) any later version.
00011  * =====================================================================
00012  * Info: This class could just work with a change in the header-file
00013  *       of the Contact class ! Therefore our libopie only compiles
00014  *       with our version of libqpe
00015  * =====================================================================
00016  * ToDo: XML-Backend: Automatic reload if something was changed...
00017  *
00018  *
00019  * =====================================================================
00020  * Version: $Id: ocontactaccess.cpp,v 1.1 2004/11/16 21:46:07 mickeyl Exp $
00021  * =====================================================================
00022  * History:
00023  * $Log: ocontactaccess.cpp,v $
00024  * Revision 1.1  2004/11/16 21:46:07  mickeyl
00025  * libopie1 goes into unsupported
00026  *
00027  * Revision 1.9  2004/03/02 12:14:22  alwin
00028  * run the optimize_connect script
00029  * the whole cvs is tagged with "before_optimize_connect" if there are problems you
00030  * can check the diff (but it had compiled and run here)
00031  *
00032  * Revision 1.8  2003/05/08 13:55:09  tille
00033  * search stuff
00034  * and match, toRichText & toShortText in oevent
00035  *
00036  * Revision 1.7  2002/11/13 14:14:51  eilers
00037  * Added sorted for Contacts..
00038  *
00039  * Revision 1.6  2002/11/01 15:10:42  eilers
00040  * Added regExp-search in database for all fields in a contact.
00041  *
00042  * Revision 1.5  2002/10/16 10:52:40  eilers
00043  * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
00044  *
00045  * Revision 1.4  2002/10/14 16:21:54  eilers
00046  * Some minor interface updates
00047  *
00048  * Revision 1.3  2002/10/07 17:34:24  eilers
00049  * added OBackendFactory for advanced backend access
00050  *
00051  * Revision 1.2  2002/10/02 16:18:11  eilers
00052  * debugged and seems to work almost perfectly ..
00053  *
00054  * Revision 1.1  2002/09/27 17:11:44  eilers
00055  * Added API for accessing the Contact-Database ! It is compiling, but
00056  * please do not expect that anything is working !
00057  * I will debug that stuff in the next time ..
00058  * Please read README_COMPILE for compiling !
00059  *
00060  *
00061  */
00062 
00063 #include "ocontactaccess.h"
00064 #include "obackendfactory.h"
00065 
00066 #include <qasciidict.h>
00067 #include <qdatetime.h>
00068 #include <qfile.h>
00069 #include <qregexp.h>
00070 #include <qlist.h>
00071 #include <qcopchannel_qws.h>
00072 
00073 //#include <qpe/qcopenvelope_qws.h>
00074 #include <qpe/global.h>
00075 
00076 #include <errno.h>
00077 #include <fcntl.h>
00078 #include <unistd.h>
00079 #include <stdlib.h>
00080 
00081 #include "ocontactaccessbackend_xml.h"
00082 
00083 
00084 OContactAccess::OContactAccess ( const QString appname, const QString ,
00085                          OContactAccessBackend* end, bool autosync ):
00086         OPimAccessTemplate<OContact>( end )
00087 {
00088         /* take care of the backend. If there is no one defined, we
00089          * will use the XML-Backend as default (until we have a cute SQL-Backend..).
00090          */
00091         if( end == 0 ) {
00092                 qWarning ("Using BackendFactory !");
00093                 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
00094         }
00095         // Set backend locally and in template
00096         m_backEnd = end;
00097         OPimAccessTemplate<OContact>::setBackEnd (end);
00098 
00099 
00100         /* Connect signal of external db change to function */
00101         QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
00102         connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
00103                this, SLOT(copMessage(const QCString&,const QByteArray&)) );
00104         if ( autosync ){
00105                 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
00106                 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
00107                          this, SLOT(copMessage(const QCString&,const QByteArray&)) );
00108         }
00109 
00110 
00111 }
00112 OContactAccess::~OContactAccess ()
00113 {
00114         /* The user may forget to save the changed database, therefore try to
00115          * do it for him..
00116          */
00117         save();
00118         // delete m_backEnd; is done by template..
00119 }
00120 
00121 
00122 bool OContactAccess::save ()
00123 {
00124         /* If the database was changed externally, we could not save the
00125          * Data. This will remove added items which is unacceptable !
00126          * Therefore: Reload database and merge the data...
00127          */
00128         if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
00129                 reload();
00130 
00131         bool status = OPimAccessTemplate<OContact>::save();
00132         if ( !status ) return false;
00133 
00134         /* Now tell everyone that new data is available.
00135          */
00136         QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
00137 
00138         return true;
00139 }
00140 
00141 const uint OContactAccess::querySettings()
00142 {
00143         return ( m_backEnd->querySettings() );
00144 }
00145 
00146 bool OContactAccess::hasQuerySettings ( int querySettings ) const
00147 {
00148         return ( m_backEnd->hasQuerySettings ( querySettings ) );
00149 }
00150 ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
00151 {
00152         QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
00153         return ( ORecordList<OContact>(matchingContacts, this) );
00154 }
00155 
00156 
00157 bool OContactAccess::wasChangedExternally()const
00158 {
00159         return ( m_backEnd->wasChangedExternally() );
00160 }
00161 
00162 
00163 void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
00164 {
00165         if ( msg == "addressbookUpdated()" ){
00166                 qWarning ("OContactAccess: Received addressbokUpdated()");
00167                 emit signalChanged ( this );
00168         } else if ( msg == "flush()" ) {
00169                 qWarning ("OContactAccess: Received flush()");
00170                 save ();
00171         } else if ( msg == "reload()" ) {
00172                 qWarning ("OContactAccess: Received reload()");
00173                 reload ();
00174                 emit signalChanged ( this );
00175         }
00176 }

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