00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <opie2/ocontactaccess.h>
00037 #include <opie2/obackendfactory.h>
00038
00039
00040 #include <opie2/ocontactaccessbackend_xml.h>
00041 #include <opie2/opimresolver.h>
00042 #include <opie2/opimglobal.h>
00043 #include <opie2/odebug.h>
00044
00045
00046 #include <qpe/global.h>
00047
00048
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
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
00070
00071
00072 if( end == 0 ) {
00073 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
00074 }
00075
00076 m_backEnd = end;
00077 OPimAccessTemplate<OPimContact>::setBackEnd (end);
00078
00079
00080
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
00095
00096
00097 save();
00098
00099 }
00100
00101
00102 bool OPimContactAccess::save ()
00103 {
00104
00105
00106
00107
00108 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
00109 reload();
00110
00111 bool status = OPimAccessTemplate<OPimContact>::save();
00112 if ( !status ) return false;
00113
00114
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 }