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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
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
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
00089
00090
00091 if( end == 0 ) {
00092 qWarning ("Using BackendFactory !");
00093 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
00094 }
00095
00096 m_backEnd = end;
00097 OPimAccessTemplate<OContact>::setBackEnd (end);
00098
00099
00100
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
00115
00116
00117 save();
00118
00119 }
00120
00121
00122 bool OContactAccess::save ()
00123 {
00124
00125
00126
00127
00128 if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
00129 reload();
00130
00131 bool status = OPimAccessTemplate<OContact>::save();
00132 if ( !status ) return false;
00133
00134
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 }