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                              This file is part of the Opie Project
00003                              Copyright (C) The Main Author <main-author@whereever.org>
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: XML-Backend: Automatic reload if something was changed...
00032  *
00033  *
00034  */
00035 
00036 #include <opie2/ocontactaccess.h>
00037 #include <opie2/obackendfactory.h>
00038 
00039 /* OPIE */
00040 #include <opie2/ocontactaccessbackend_xml.h>
00041 #include <opie2/opimresolver.h>
00042 #include <opie2/opimglobal.h>
00043 #include <opie2/odebug.h>
00044 
00045 //#include <qpe/qcopenvelope_qws.h>
00046 #include <qpe/global.h>
00047 
00048 /* QT */
00049 #include <qasciidict.h>
00050 #include <qdatetime.h>
00051 #include <qfile.h>
00052 #include <qregexp.h>
00053 #include <qlist.h>
00054 #include <qcopchannel_qws.h>
00055 
00056 /* STD */
00057 #include <errno.h>
00058 #include <fcntl.h>
00059 #include <unistd.h>
00060 #include <stdlib.h>
00061 
00062 
00063 namespace Opie {
00064 
00065 OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
00066                                        OPimContactAccessBackend* end, bool autosync ):
00067         OPimAccessTemplate<OPimContact>( end )
00068 {
00069         /* take care of the backend. If there is no one defined, we
00070          * will use the XML-Backend as default (until we have a cute SQL-Backend..).
00071          */
00072         if( end == 0 ) {
00073                 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
00074         }
00075         // Set backend locally and in template
00076         m_backEnd = end;
00077         OPimAccessTemplate<OPimContact>::setBackEnd (end);
00078 
00079 
00080         /* Connect signal of external db change to function */
00081         QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
00082         connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
00083                  this, SLOT(copMessage(const QCString&,const QByteArray&)) );
00084         if ( autosync ){
00085                 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
00086                 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
00087                          this, SLOT(copMessage(const QCString&,const QByteArray&)) );
00088         }
00089 
00090 
00091 }
00092 OPimContactAccess::~OPimContactAccess ()
00093 {
00094     /* The user may forget to save the changed database, therefore try to
00095      * do it for him..
00096      */
00097     save();
00098     // delete m_backEnd; is done by template..
00099 }
00100 
00101 
00102 bool OPimContactAccess::save ()
00103 {
00104     /* If the database was changed externally, we could not save the
00105      * Data. This will remove added items which is unacceptable !
00106      * Therefore: Reload database and merge the data...
00107      */
00108     if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
00109         reload();
00110 
00111     bool status = OPimAccessTemplate<OPimContact>::save();
00112     if ( !status ) return false;
00113 
00114     /* Now tell everyone that new data is available.
00115      */
00116     QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
00117 
00118     return true;
00119 }
00120 
00121 
00122 #if 0
00123 OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
00124 {
00125     QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
00126     return ( OPimRecordList<OPimContact>(matchingContacts, this) );
00127 }
00128 #endif
00129 
00130 
00131 bool OPimContactAccess::wasChangedExternally()const
00132 {
00133     return ( m_backEnd->wasChangedExternally() );
00134 }
00135 
00136 
00137 void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
00138 {
00139     if ( msg == "addressbookUpdated()" ){
00140         emit signalChanged ( this );
00141     } else if ( msg == "flush()" ) {
00142         save ();
00143     } else if ( msg == "reload()" ) {
00144         reload ();
00145         emit signalChanged ( this );
00146     }
00147 }
00148 
00149 int OPimContactAccess::rtti() const
00150 {
00151     return OPimResolver::AddressBook;
00152 }
00153 
00154 }

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