libopie PIM API Documentation

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.8 2003/05/08 13:55:09 tille Exp $
00021  * =====================================================================
00022  * History:
00023  * $Log: ocontactaccess.cpp,v $
00024  * Revision 1.8  2003/05/08 13:55:09  tille
00025  * search stuff
00026  * and match, toRichText & toShortText in oevent
00027  *
00028  * Revision 1.7  2002/11/13 14:14:51  eilers
00029  * Added sorted for Contacts..
00030  *
00031  * Revision 1.6  2002/11/01 15:10:42  eilers
00032  * Added regExp-search in database for all fields in a contact.
00033  *
00034  * Revision 1.5  2002/10/16 10:52:40  eilers
00035  * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
00036  *
00037  * Revision 1.4  2002/10/14 16:21:54  eilers
00038  * Some minor interface updates
00039  *
00040  * Revision 1.3  2002/10/07 17:34:24  eilers
00041  * added OBackendFactory for advanced backend access
00042  *
00043  * Revision 1.2  2002/10/02 16:18:11  eilers
00044  * debugged and seems to work almost perfectly ..
00045  *
00046  * Revision 1.1  2002/09/27 17:11:44  eilers
00047  * Added API for accessing the Contact-Database ! It is compiling, but
00048  * please do not expect that anything is working !
00049  * I will debug that stuff in the next time ..
00050  * Please read README_COMPILE for compiling !
00051  *
00052  *
00053  */
00054 
00055 #include "ocontactaccess.h"
00056 #include "obackendfactory.h"
00057 
00058 #include <qasciidict.h>
00059 #include <qdatetime.h>
00060 #include <qfile.h>
00061 #include <qregexp.h>
00062 #include <qlist.h>
00063 #include <qcopchannel_qws.h>
00064 
00065 //#include <qpe/qcopenvelope_qws.h>
00066 #include <qpe/global.h>
00067 
00068 #include <errno.h>
00069 #include <fcntl.h>
00070 #include <unistd.h>
00071 #include <stdlib.h>
00072 
00073 #include "ocontactaccessbackend_xml.h"
00074 
00075 
00076 OContactAccess::OContactAccess ( const QString appname, const QString ,
00077              OContactAccessBackend* end, bool autosync ):
00078     OPimAccessTemplate<OContact>( end )
00079 {
00080         /* take care of the backend. If there is no one defined, we
00081      * will use the XML-Backend as default (until we have a cute SQL-Backend..).
00082      */
00083         if( end == 0 ) {
00084         qWarning ("Using BackendFactory !");
00085         end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
00086         }
00087     // Set backend locally and in template
00088         m_backEnd = end;
00089     OPimAccessTemplate<OContact>::setBackEnd (end);
00090 
00091 
00092     /* Connect signal of external db change to function */
00093     QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
00094     connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)),
00095                this, SLOT(copMessage( const QCString &, const QByteArray &)) );
00096     if ( autosync ){
00097         QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
00098         connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
00099              this, SLOT(copMessage( const QCString &, const QByteArray &)) );
00100     }
00101 
00102 
00103 }
00104 OContactAccess::~OContactAccess ()
00105 {
00106     /* The user may forget to save the changed database, therefore try to
00107      * do it for him..
00108      */
00109     save();
00110     // delete m_backEnd; is done by template..
00111 }
00112 
00113 
00114 bool OContactAccess::save ()
00115 {
00116     /* If the database was changed externally, we could not save the
00117      * Data. This will remove added items which is unacceptable !
00118      * Therefore: Reload database and merge the data...
00119      */
00120     if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
00121         reload();
00122 
00123     bool status = OPimAccessTemplate<OContact>::save();
00124     if ( !status ) return false;
00125 
00126     /* Now tell everyone that new data is available.
00127      */
00128     QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
00129 
00130     return true;
00131 }
00132 
00133 const uint OContactAccess::querySettings()
00134 {
00135     return ( m_backEnd->querySettings() );
00136 }
00137 
00138 bool OContactAccess::hasQuerySettings ( int querySettings ) const
00139 {
00140     return ( m_backEnd->hasQuerySettings ( querySettings ) );
00141 }
00142 ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
00143 {
00144     QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
00145     return ( ORecordList<OContact>(matchingContacts, this) );
00146 }
00147 
00148 
00149 bool OContactAccess::wasChangedExternally()const
00150 {
00151     return ( m_backEnd->wasChangedExternally() );
00152 }
00153 
00154 
00155 void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
00156 {
00157     if ( msg == "addressbookUpdated()" ){
00158         qWarning ("OContactAccess: Received addressbokUpdated()");
00159         emit signalChanged ( this );
00160     } else if ( msg == "flush()" ) {
00161         qWarning ("OContactAccess: Received flush()");
00162         save ();
00163     } else if ( msg == "reload()" ) {
00164         qWarning ("OContactAccess: Received reload()");
00165         reload ();
00166         emit signalChanged ( this );
00167     }
00168 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:19 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001