ocontactaccess.cpp
Go to the documentation of this file.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 #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
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
00081
00082
00083 if( end == 0 ) {
00084 qWarning ("Using BackendFactory !");
00085 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
00086 }
00087
00088 m_backEnd = end;
00089 OPimAccessTemplate<OContact>::setBackEnd (end);
00090
00091
00092
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
00107
00108
00109 save();
00110
00111 }
00112
00113
00114 bool OContactAccess::save ()
00115 {
00116
00117
00118
00119
00120 if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
00121 reload();
00122
00123 bool status = OPimAccessTemplate<OContact>::save();
00124 if ( !status ) return false;
00125
00126
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 }
This file is part of the documentation for OPIE Version 1.1.