summaryrefslogtreecommitdiff
path: root/libopie/pim/ocontactaccess.cpp
Unidiff
Diffstat (limited to 'libopie/pim/ocontactaccess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccess.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp
index 2e3ec1f..bc359f7 100644
--- a/libopie/pim/ocontactaccess.cpp
+++ b/libopie/pim/ocontactaccess.cpp
@@ -1,147 +1,152 @@
1/* 1/*
2 * Class to manage the Contacts. 2 * Class to manage the Contacts.
3 * 3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 5 *
6 * ===================================================================== 6 * =====================================================================
7 *This program is free software; you can redistribute it and/or 7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * Info: This class could just work with a change in the header-file 12 * Info: This class could just work with a change in the header-file
13 * of the Contact class ! Therefore our libopie only compiles 13 * of the Contact class ! Therefore our libopie only compiles
14 * with our version of libqpe 14 * with our version of libqpe
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: XML-Backend: Automatic reload if something was changed... 16 * ToDo: XML-Backend: Automatic reload if something was changed...
17 * 17 *
18 * 18 *
19 * ===================================================================== 19 * =====================================================================
20 * Version: $Id$ 20 * Version: $Id$
21 * ===================================================================== 21 * =====================================================================
22 * History: 22 * History:
23 * $Log$ 23 * $Log$
24 * Revision 1.9 2004/03/02 12:14:22 alwin
25 * run the optimize_connect script
26 * the whole cvs is tagged with "before_optimize_connect" if there are problems you
27 * can check the diff (but it had compiled and run here)
28 *
24 * Revision 1.8 2003/05/08 13:55:09 tille 29 * Revision 1.8 2003/05/08 13:55:09 tille
25 * search stuff 30 * search stuff
26 * and match, toRichText & toShortText in oevent 31 * and match, toRichText & toShortText in oevent
27 * 32 *
28 * Revision 1.7 2002/11/13 14:14:51 eilers 33 * Revision 1.7 2002/11/13 14:14:51 eilers
29 * Added sorted for Contacts.. 34 * Added sorted for Contacts..
30 * 35 *
31 * Revision 1.6 2002/11/01 15:10:42 eilers 36 * Revision 1.6 2002/11/01 15:10:42 eilers
32 * Added regExp-search in database for all fields in a contact. 37 * Added regExp-search in database for all fields in a contact.
33 * 38 *
34 * Revision 1.5 2002/10/16 10:52:40 eilers 39 * Revision 1.5 2002/10/16 10:52:40 eilers
35 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 40 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
36 * 41 *
37 * Revision 1.4 2002/10/14 16:21:54 eilers 42 * Revision 1.4 2002/10/14 16:21:54 eilers
38 * Some minor interface updates 43 * Some minor interface updates
39 * 44 *
40 * Revision 1.3 2002/10/07 17:34:24 eilers 45 * Revision 1.3 2002/10/07 17:34:24 eilers
41 * added OBackendFactory for advanced backend access 46 * added OBackendFactory for advanced backend access
42 * 47 *
43 * Revision 1.2 2002/10/02 16:18:11 eilers 48 * Revision 1.2 2002/10/02 16:18:11 eilers
44 * debugged and seems to work almost perfectly .. 49 * debugged and seems to work almost perfectly ..
45 * 50 *
46 * Revision 1.1 2002/09/27 17:11:44 eilers 51 * Revision 1.1 2002/09/27 17:11:44 eilers
47 * Added API for accessing the Contact-Database ! It is compiling, but 52 * Added API for accessing the Contact-Database ! It is compiling, but
48 * please do not expect that anything is working ! 53 * please do not expect that anything is working !
49 * I will debug that stuff in the next time .. 54 * I will debug that stuff in the next time ..
50 * Please read README_COMPILE for compiling ! 55 * Please read README_COMPILE for compiling !
51 * 56 *
52 * 57 *
53 */ 58 */
54 59
55#include "ocontactaccess.h" 60#include "ocontactaccess.h"
56#include "obackendfactory.h" 61#include "obackendfactory.h"
57 62
58#include <qasciidict.h> 63#include <qasciidict.h>
59#include <qdatetime.h> 64#include <qdatetime.h>
60#include <qfile.h> 65#include <qfile.h>
61#include <qregexp.h> 66#include <qregexp.h>
62#include <qlist.h> 67#include <qlist.h>
63#include <qcopchannel_qws.h> 68#include <qcopchannel_qws.h>
64 69
65//#include <qpe/qcopenvelope_qws.h> 70//#include <qpe/qcopenvelope_qws.h>
66#include <qpe/global.h> 71#include <qpe/global.h>
67 72
68#include <errno.h> 73#include <errno.h>
69#include <fcntl.h> 74#include <fcntl.h>
70#include <unistd.h> 75#include <unistd.h>
71#include <stdlib.h> 76#include <stdlib.h>
72 77
73#include "ocontactaccessbackend_xml.h" 78#include "ocontactaccessbackend_xml.h"
74 79
75 80
76OContactAccess::OContactAccess ( const QString appname, const QString , 81OContactAccess::OContactAccess ( const QString appname, const QString ,
77 OContactAccessBackend* end, bool autosync ): 82 OContactAccessBackend* end, bool autosync ):
78 OPimAccessTemplate<OContact>( end ) 83 OPimAccessTemplate<OContact>( end )
79{ 84{
80 /* take care of the backend. If there is no one defined, we 85 /* take care of the backend. If there is no one defined, we
81 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 86 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
82 */ 87 */
83 if( end == 0 ) { 88 if( end == 0 ) {
84 qWarning ("Using BackendFactory !"); 89 qWarning ("Using BackendFactory !");
85 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); 90 end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname );
86 } 91 }
87 // Set backend locally and in template 92 // Set backend locally and in template
88 m_backEnd = end; 93 m_backEnd = end;
89 OPimAccessTemplate<OContact>::setBackEnd (end); 94 OPimAccessTemplate<OContact>::setBackEnd (end);
90 95
91 96
92 /* Connect signal of external db change to function */ 97 /* Connect signal of external db change to function */
93 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 98 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
94 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), 99 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
95 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 100 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
96 if ( autosync ){ 101 if ( autosync ){
97 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 102 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
98 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), 103 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
99 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 104 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
100 } 105 }
101 106
102 107
103} 108}
104OContactAccess::~OContactAccess () 109OContactAccess::~OContactAccess ()
105{ 110{
106 /* The user may forget to save the changed database, therefore try to 111 /* The user may forget to save the changed database, therefore try to
107 * do it for him.. 112 * do it for him..
108 */ 113 */
109 save(); 114 save();
110 // delete m_backEnd; is done by template.. 115 // delete m_backEnd; is done by template..
111} 116}
112 117
113 118
114bool OContactAccess::save () 119bool OContactAccess::save ()
115{ 120{
116 /* If the database was changed externally, we could not save the 121 /* If the database was changed externally, we could not save the
117 * Data. This will remove added items which is unacceptable ! 122 * Data. This will remove added items which is unacceptable !
118 * Therefore: Reload database and merge the data... 123 * Therefore: Reload database and merge the data...
119 */ 124 */
120 if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) 125 if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
121 reload(); 126 reload();
122 127
123 bool status = OPimAccessTemplate<OContact>::save(); 128 bool status = OPimAccessTemplate<OContact>::save();
124 if ( !status ) return false; 129 if ( !status ) return false;
125 130
126 /* Now tell everyone that new data is available. 131 /* Now tell everyone that new data is available.
127 */ 132 */
128 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 133 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
129 134
130 return true; 135 return true;
131} 136}
132 137
133const uint OContactAccess::querySettings() 138const uint OContactAccess::querySettings()
134{ 139{
135 return ( m_backEnd->querySettings() ); 140 return ( m_backEnd->querySettings() );
136} 141}
137 142
138bool OContactAccess::hasQuerySettings ( int querySettings ) const 143bool OContactAccess::hasQuerySettings ( int querySettings ) const
139{ 144{
140 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 145 return ( m_backEnd->hasQuerySettings ( querySettings ) );
141} 146}
142ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 147ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
143{ 148{
144 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 149 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
145 return ( ORecordList<OContact>(matchingContacts, this) ); 150 return ( ORecordList<OContact>(matchingContacts, this) );
146} 151}
147 152