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