-rw-r--r-- | libopie/pim/ocontact.h | 4 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.cpp | 8 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.h | 8 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend.h | 7 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 20 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 20 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 8 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 8 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.h | 4 |
10 files changed, 86 insertions, 8 deletions
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h index 382ab94..038a59f 100644 --- a/libopie/pim/ocontact.h +++ b/libopie/pim/ocontact.h | |||
@@ -1,246 +1,242 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Qtopia Environment. | 5 | ** This file is part of the Qtopia Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef __OCONTACT_H__ | 22 | #ifndef __OCONTACT_H__ |
23 | #define __OCONTACT_H__ | 23 | #define __OCONTACT_H__ |
24 | 24 | ||
25 | #include <opie/opimrecord.h> | 25 | #include <opie/opimrecord.h> |
26 | #include <qpe/recordfields.h> | 26 | #include <qpe/recordfields.h> |
27 | 27 | ||
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | 30 | ||
31 | #if defined(QPC_TEMPLATEDLL) | 31 | #if defined(QPC_TEMPLATEDLL) |
32 | // MOC_SKIP_BEGIN | 32 | // MOC_SKIP_BEGIN |
33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
34 | // MOC_SKIP_END | 34 | // MOC_SKIP_END |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) | 37 | class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) |
38 | class QPC_EXPORT OContact : public OPimRecord | 38 | class QPC_EXPORT OContact : public OPimRecord |
39 | { | 39 | { |
40 | friend class DataSet; | 40 | friend class DataSet; |
41 | public: | 41 | public: |
42 | OContact(); | 42 | OContact(); |
43 | OContact( const QMap<int, QString> &fromMap ); | 43 | OContact( const QMap<int, QString> &fromMap ); |
44 | virtual ~OContact(); | 44 | virtual ~OContact(); |
45 | 45 | ||
46 | static void writeVCard( const QString &filename, const QValueList<OContact> &contacts); | 46 | static void writeVCard( const QString &filename, const QValueList<OContact> &contacts); |
47 | static void writeVCard( const QString &filename, const OContact &c ); | 47 | static void writeVCard( const QString &filename, const OContact &c ); |
48 | static QValueList<OContact> readVCard( const QString &filename ); | 48 | static QValueList<OContact> readVCard( const QString &filename ); |
49 | 49 | ||
50 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 50 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
51 | 51 | ||
52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
58 | void setFileAs(); | 58 | void setFileAs(); |
59 | 59 | ||
60 | // default email address | 60 | // default email address |
61 | void setDefaultEmail( const QString &v ); | 61 | void setDefaultEmail( const QString &v ); |
62 | // inserts email to list and ensure's doesn't already exist | 62 | // inserts email to list and ensure's doesn't already exist |
63 | void insertEmail( const QString &v ); | 63 | void insertEmail( const QString &v ); |
64 | void removeEmail( const QString &v ); | 64 | void removeEmail( const QString &v ); |
65 | void clearEmails(); | 65 | void clearEmails(); |
66 | void insertEmails( const QStringList &v ); | 66 | void insertEmails( const QStringList &v ); |
67 | 67 | ||
68 | // home | 68 | // home |
69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
78 | 78 | ||
79 | // business | 79 | // business |
80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
87 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 87 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
88 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 88 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
89 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 89 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
90 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 90 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
91 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } | 91 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } |
92 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } | 92 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } |
93 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } | 93 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } |
94 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } | 94 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } |
95 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } | 95 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } |
96 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } | 96 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } |
97 | 97 | ||
98 | // personal | 98 | // personal |
99 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } | 99 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } |
100 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } | 100 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } |
101 | void setBirthday( const QDate &v ); | 101 | void setBirthday( const QDate &v ); |
102 | void setAnniversary( const QDate &v ); | 102 | void setAnniversary( const QDate &v ); |
103 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } | 103 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } |
104 | void setChildren( const QString &v ); | 104 | void setChildren( const QString &v ); |
105 | 105 | ||
106 | // other | 106 | // other |
107 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 107 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
108 | 108 | ||
109 | bool match( const QString ®exp ) const; | 109 | bool match( const QString ®exp ) const; |
110 | |||
111 | // DON'T ATTEMPT TO USE THIS | ||
112 | #ifdef QTOPIA_INTERNAL_CONTACT_MRE | ||
113 | bool match( const QRegExp ®exp ) const; | 110 | bool match( const QRegExp ®exp ) const; |
114 | #endif | ||
115 | 111 | ||
116 | // // custom | 112 | // // custom |
117 | // void setCustomField( const QString &key, const QString &v ) | 113 | // void setCustomField( const QString &key, const QString &v ) |
118 | // { replace(Custom- + key, v ); } | 114 | // { replace(Custom- + key, v ); } |
119 | 115 | ||
120 | // name | 116 | // name |
121 | QString fullName() const; | 117 | QString fullName() const; |
122 | QString title() const { return find( Qtopia::Title ); } | 118 | QString title() const { return find( Qtopia::Title ); } |
123 | QString firstName() const { return find( Qtopia::FirstName ); } | 119 | QString firstName() const { return find( Qtopia::FirstName ); } |
124 | QString middleName() const { return find( Qtopia::MiddleName ); } | 120 | QString middleName() const { return find( Qtopia::MiddleName ); } |
125 | QString lastName() const { return find( Qtopia::LastName ); } | 121 | QString lastName() const { return find( Qtopia::LastName ); } |
126 | QString suffix() const { return find( Qtopia::Suffix ); } | 122 | QString suffix() const { return find( Qtopia::Suffix ); } |
127 | QString fileAs() const { return find( Qtopia::FileAs ); } | 123 | QString fileAs() const { return find( Qtopia::FileAs ); } |
128 | 124 | ||
129 | 125 | ||
130 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 126 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
131 | QStringList emailList() const; | 127 | QStringList emailList() const; |
132 | 128 | ||
133 | // home | 129 | // home |
134 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 130 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
135 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 131 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
136 | QString homeState() const { return find( Qtopia::HomeState ); } | 132 | QString homeState() const { return find( Qtopia::HomeState ); } |
137 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 133 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
138 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 134 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
139 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 135 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
140 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 136 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
141 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 137 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
142 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 138 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
143 | /** Multi line string containing all non-empty address info in the form | 139 | /** Multi line string containing all non-empty address info in the form |
144 | * Street | 140 | * Street |
145 | * City, State Zip | 141 | * City, State Zip |
146 | * Country | 142 | * Country |
147 | */ | 143 | */ |
148 | QString displayHomeAddress() const; | 144 | QString displayHomeAddress() const; |
149 | 145 | ||
150 | // business | 146 | // business |
151 | QString company() const { return find( Qtopia::Company ); } | 147 | QString company() const { return find( Qtopia::Company ); } |
152 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 148 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
153 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 149 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
154 | QString businessState() const { return find( Qtopia::BusinessState ); } | 150 | QString businessState() const { return find( Qtopia::BusinessState ); } |
155 | QString businessZip() const { return find( Qtopia::BusinessZip ); } | 151 | QString businessZip() const { return find( Qtopia::BusinessZip ); } |
156 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } | 152 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } |
157 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } | 153 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } |
158 | QString jobTitle() const { return find( Qtopia::JobTitle ); } | 154 | QString jobTitle() const { return find( Qtopia::JobTitle ); } |
159 | QString department() const { return find( Qtopia::Department ); } | 155 | QString department() const { return find( Qtopia::Department ); } |
160 | QString office() const { return find( Qtopia::Office ); } | 156 | QString office() const { return find( Qtopia::Office ); } |
161 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } | 157 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } |
162 | QString businessFax() const { return find( Qtopia::BusinessFax ); } | 158 | QString businessFax() const { return find( Qtopia::BusinessFax ); } |
163 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } | 159 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } |
164 | QString businessPager() const { return find( Qtopia::BusinessPager ); } | 160 | QString businessPager() const { return find( Qtopia::BusinessPager ); } |
165 | QString profession() const { return find( Qtopia::Profession ); } | 161 | QString profession() const { return find( Qtopia::Profession ); } |
166 | QString assistant() const { return find( Qtopia::Assistant ); } | 162 | QString assistant() const { return find( Qtopia::Assistant ); } |
167 | QString manager() const { return find( Qtopia::Manager ); } | 163 | QString manager() const { return find( Qtopia::Manager ); } |
168 | /** Multi line string containing all non-empty address info in the form | 164 | /** Multi line string containing all non-empty address info in the form |
169 | * Street | 165 | * Street |
170 | * City, State Zip | 166 | * City, State Zip |
171 | * Country | 167 | * Country |
172 | */ | 168 | */ |
173 | QString displayBusinessAddress() const; | 169 | QString displayBusinessAddress() const; |
174 | 170 | ||
175 | //personal | 171 | //personal |
176 | QString spouse() const { return find( Qtopia::Spouse ); } | 172 | QString spouse() const { return find( Qtopia::Spouse ); } |
177 | QString gender() const { return find( Qtopia::Gender ); } | 173 | QString gender() const { return find( Qtopia::Gender ); } |
178 | QDate birthday() const; | 174 | QDate birthday() const; |
179 | QDate anniversary() const; | 175 | QDate anniversary() const; |
180 | QString nickname() const { return find( Qtopia::Nickname ); } | 176 | QString nickname() const { return find( Qtopia::Nickname ); } |
181 | QString children() const { return find( Qtopia::Children ); } | 177 | QString children() const { return find( Qtopia::Children ); } |
182 | QStringList childrenList() const; | 178 | QStringList childrenList() const; |
183 | 179 | ||
184 | // other | 180 | // other |
185 | QString notes() const { return find( Qtopia::Notes ); } | 181 | QString notes() const { return find( Qtopia::Notes ); } |
186 | QString groups() const { return find( Qtopia::Groups ); } | 182 | QString groups() const { return find( Qtopia::Groups ); } |
187 | QStringList groupList() const; | 183 | QStringList groupList() const; |
188 | 184 | ||
189 | // // custom | 185 | // // custom |
190 | // const QString &customField( const QString &key ) | 186 | // const QString &customField( const QString &key ) |
191 | // { return find( Custom- + key ); } | 187 | // { return find( Custom- + key ); } |
192 | 188 | ||
193 | static QStringList fields(); | 189 | static QStringList fields(); |
194 | static QStringList trfields(); | 190 | static QStringList trfields(); |
195 | static QStringList untrfields(); | 191 | static QStringList untrfields(); |
196 | 192 | ||
197 | QString toRichText() const; | 193 | QString toRichText() const; |
198 | QMap<int, QString> toMap() const; | 194 | QMap<int, QString> toMap() const; |
199 | QString field( int key ) const { return find( key ); } | 195 | QString field( int key ) const { return find( key ); } |
200 | 196 | ||
201 | 197 | ||
202 | // journaling... | 198 | // journaling... |
203 | void saveJournal( journal_action action, const QString &key = QString::null ); | 199 | void saveJournal( journal_action action, const QString &key = QString::null ); |
204 | void save( QString &buf ) const; | 200 | void save( QString &buf ) const; |
205 | 201 | ||
206 | void setUid( int i ) | 202 | void setUid( int i ) |
207 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } | 203 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } |
208 | 204 | ||
209 | QString toShortText()const; | 205 | QString toShortText()const; |
210 | QString OContact::type()const; | 206 | QString OContact::type()const; |
211 | QMap<QString,QString> OContact::toExtraMap() const; | 207 | QMap<QString,QString> OContact::toExtraMap() const; |
212 | class QString OContact::recordField(int) const; | 208 | class QString OContact::recordField(int) const; |
213 | 209 | ||
214 | // Why private ? (eilers,se) | 210 | // Why private ? (eilers,se) |
215 | QString emailSeparator() const { return " "; } | 211 | QString emailSeparator() const { return " "; } |
216 | // the emails should be seperated by a comma | 212 | // the emails should be seperated by a comma |
217 | void setEmails( const QString &v ); | 213 | void setEmails( const QString &v ); |
218 | QString emails() const { return find( Qtopia::Emails ); } | 214 | QString emails() const { return find( Qtopia::Emails ); } |
219 | 215 | ||
220 | 216 | ||
221 | private: | 217 | private: |
222 | friend class AbEditor; | 218 | friend class AbEditor; |
223 | friend class AbTable; | 219 | friend class AbTable; |
224 | friend class AddressBookAccessPrivate; | 220 | friend class AddressBookAccessPrivate; |
225 | friend class XMLIO; | 221 | friend class XMLIO; |
226 | 222 | ||
227 | void insert( int key, const QString &value ); | 223 | void insert( int key, const QString &value ); |
228 | void replace( int key, const QString &value ); | 224 | void replace( int key, const QString &value ); |
229 | QString find( int key ) const; | 225 | QString find( int key ) const; |
230 | 226 | ||
231 | QString displayAddress( const QString &street, | 227 | QString displayAddress( const QString &street, |
232 | const QString &city, | 228 | const QString &city, |
233 | const QString &state, | 229 | const QString &state, |
234 | const QString &zip, | 230 | const QString &zip, |
235 | const QString &country ) const; | 231 | const QString &country ) const; |
236 | 232 | ||
237 | Qtopia::UidGen &uidGen() { return sUidGen; } | 233 | Qtopia::UidGen &uidGen() { return sUidGen; } |
238 | 234 | ||
239 | 235 | ||
240 | static Qtopia::UidGen sUidGen; | 236 | static Qtopia::UidGen sUidGen; |
241 | QMap<int, QString> mMap; | 237 | QMap<int, QString> mMap; |
242 | ContactPrivate *d; | 238 | ContactPrivate *d; |
243 | }; | 239 | }; |
244 | 240 | ||
245 | 241 | ||
246 | #endif | 242 | #endif |
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp index 2ca0283..f868b53 100644 --- a/libopie/pim/ocontactaccess.cpp +++ b/libopie/pim/ocontactaccess.cpp | |||
@@ -1,153 +1,161 @@ | |||
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.6 2002/11/01 15:10:42 eilers | ||
25 | * Added regExp-search in database for all fields in a contact. | ||
26 | * | ||
24 | * Revision 1.5 2002/10/16 10:52:40 eilers | 27 | * Revision 1.5 2002/10/16 10:52:40 eilers |
25 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 28 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
26 | * | 29 | * |
27 | * Revision 1.4 2002/10/14 16:21:54 eilers | 30 | * Revision 1.4 2002/10/14 16:21:54 eilers |
28 | * Some minor interface updates | 31 | * Some minor interface updates |
29 | * | 32 | * |
30 | * Revision 1.3 2002/10/07 17:34:24 eilers | 33 | * Revision 1.3 2002/10/07 17:34:24 eilers |
31 | * added OBackendFactory for advanced backend access | 34 | * added OBackendFactory for advanced backend access |
32 | * | 35 | * |
33 | * Revision 1.2 2002/10/02 16:18:11 eilers | 36 | * Revision 1.2 2002/10/02 16:18:11 eilers |
34 | * debugged and seems to work almost perfectly .. | 37 | * debugged and seems to work almost perfectly .. |
35 | * | 38 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 39 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 40 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 41 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 42 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 43 | * Please read README_COMPILE for compiling ! |
41 | * | 44 | * |
42 | * | 45 | * |
43 | */ | 46 | */ |
44 | 47 | ||
45 | #include "ocontactaccess.h" | 48 | #include "ocontactaccess.h" |
46 | #include "obackendfactory.h" | 49 | #include "obackendfactory.h" |
47 | 50 | ||
48 | #include <qasciidict.h> | 51 | #include <qasciidict.h> |
49 | #include <qdatetime.h> | 52 | #include <qdatetime.h> |
50 | #include <qfile.h> | 53 | #include <qfile.h> |
51 | #include <qregexp.h> | 54 | #include <qregexp.h> |
52 | #include <qlist.h> | 55 | #include <qlist.h> |
53 | #include <qcopchannel_qws.h> | 56 | #include <qcopchannel_qws.h> |
54 | 57 | ||
55 | //#include <qpe/qcopenvelope_qws.h> | 58 | //#include <qpe/qcopenvelope_qws.h> |
56 | #include <qpe/global.h> | 59 | #include <qpe/global.h> |
57 | 60 | ||
58 | #include <errno.h> | 61 | #include <errno.h> |
59 | #include <fcntl.h> | 62 | #include <fcntl.h> |
60 | #include <unistd.h> | 63 | #include <unistd.h> |
61 | #include <stdlib.h> | 64 | #include <stdlib.h> |
62 | 65 | ||
63 | #include "ocontactaccessbackend_xml.h" | 66 | #include "ocontactaccessbackend_xml.h" |
64 | 67 | ||
65 | 68 | ||
66 | OContactAccess::OContactAccess ( const QString appname, const QString , | 69 | OContactAccess::OContactAccess ( const QString appname, const QString , |
67 | OContactAccessBackend* end, bool autosync ): | 70 | OContactAccessBackend* end, bool autosync ): |
68 | OPimAccessTemplate<OContact>( end ) | 71 | OPimAccessTemplate<OContact>( end ) |
69 | { | 72 | { |
70 | /* take care of the backend. If there is no one defined, we | 73 | /* take care of the backend. If there is no one defined, we |
71 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 74 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
72 | */ | 75 | */ |
73 | if( end == 0 ) { | 76 | if( end == 0 ) { |
74 | qWarning ("Using BackendFactory !"); | 77 | qWarning ("Using BackendFactory !"); |
75 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | 78 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); |
76 | } | 79 | } |
77 | // Set backend locally and in template | 80 | // Set backend locally and in template |
78 | m_backEnd = end; | 81 | m_backEnd = end; |
79 | OPimAccessTemplate<OContact>::setBackEnd (end); | 82 | OPimAccessTemplate<OContact>::setBackEnd (end); |
80 | 83 | ||
81 | 84 | ||
82 | /* Connect signal of external db change to function */ | 85 | /* Connect signal of external db change to function */ |
83 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | 86 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); |
84 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 87 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
85 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 88 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
86 | if ( autosync ){ | 89 | if ( autosync ){ |
87 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | 90 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); |
88 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 91 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
89 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 92 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
90 | } | 93 | } |
91 | 94 | ||
92 | 95 | ||
93 | } | 96 | } |
94 | OContactAccess::~OContactAccess () | 97 | OContactAccess::~OContactAccess () |
95 | { | 98 | { |
96 | /* The user may forget to save the changed database, therefore try to | 99 | /* The user may forget to save the changed database, therefore try to |
97 | * do it for him.. | 100 | * do it for him.. |
98 | */ | 101 | */ |
99 | save(); | 102 | save(); |
100 | // delete m_backEnd; is done by template.. | 103 | // delete m_backEnd; is done by template.. |
101 | } | 104 | } |
102 | 105 | ||
103 | 106 | ||
104 | bool OContactAccess::save () | 107 | bool OContactAccess::save () |
105 | { | 108 | { |
106 | /* If the database was changed externally, we could not save the | 109 | /* If the database was changed externally, we could not save the |
107 | * Data. This will remove added items which is unacceptable ! | 110 | * Data. This will remove added items which is unacceptable ! |
108 | * Therefore: Reload database and merge the data... | 111 | * Therefore: Reload database and merge the data... |
109 | */ | 112 | */ |
110 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | 113 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
111 | reload(); | 114 | reload(); |
112 | 115 | ||
113 | bool status = OPimAccessTemplate<OContact>::save(); | 116 | bool status = OPimAccessTemplate<OContact>::save(); |
114 | if ( !status ) return false; | 117 | if ( !status ) return false; |
115 | 118 | ||
116 | /* Now tell everyone that new data is available. | 119 | /* Now tell everyone that new data is available. |
117 | */ | 120 | */ |
118 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 121 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
119 | 122 | ||
120 | return true; | 123 | return true; |
121 | } | 124 | } |
122 | 125 | ||
126 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ | ||
127 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); | ||
128 | return ( ORecordList<OContact>(matchingContacts, this) ); | ||
129 | } | ||
130 | |||
123 | const uint OContactAccess::querySettings() | 131 | const uint OContactAccess::querySettings() |
124 | { | 132 | { |
125 | return ( m_backEnd->querySettings() ); | 133 | return ( m_backEnd->querySettings() ); |
126 | } | 134 | } |
127 | 135 | ||
128 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 136 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
129 | { | 137 | { |
130 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 138 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
131 | } | 139 | } |
132 | 140 | ||
133 | 141 | ||
134 | bool OContactAccess::wasChangedExternally()const | 142 | bool OContactAccess::wasChangedExternally()const |
135 | { | 143 | { |
136 | return ( m_backEnd->wasChangedExternally() ); | 144 | return ( m_backEnd->wasChangedExternally() ); |
137 | } | 145 | } |
138 | 146 | ||
139 | 147 | ||
140 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 148 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
141 | { | 149 | { |
142 | if ( msg == "addressbookUpdated()" ){ | 150 | if ( msg == "addressbookUpdated()" ){ |
143 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 151 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
144 | emit signalChanged ( this ); | 152 | emit signalChanged ( this ); |
145 | } else if ( msg == "flush()" ) { | 153 | } else if ( msg == "flush()" ) { |
146 | qWarning ("OContactAccess: Received flush()"); | 154 | qWarning ("OContactAccess: Received flush()"); |
147 | save (); | 155 | save (); |
148 | } else if ( msg == "reload()" ) { | 156 | } else if ( msg == "reload()" ) { |
149 | qWarning ("OContactAccess: Received reload()"); | 157 | qWarning ("OContactAccess: Received reload()"); |
150 | reload (); | 158 | reload (); |
151 | emit signalChanged ( this ); | 159 | emit signalChanged ( this ); |
152 | } | 160 | } |
153 | } | 161 | } |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index da9c942..b4921d5 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -1,131 +1,139 @@ | |||
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 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.4 2002/11/01 15:10:42 eilers | ||
21 | * Added regExp-search in database for all fields in a contact. | ||
22 | * | ||
20 | * Revision 1.3 2002/10/16 10:52:40 eilers | 23 | * Revision 1.3 2002/10/16 10:52:40 eilers |
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
22 | * | 25 | * |
23 | * Revision 1.2 2002/10/14 16:21:54 eilers | 26 | * Revision 1.2 2002/10/14 16:21:54 eilers |
24 | * Some minor interface updates | 27 | * Some minor interface updates |
25 | * | 28 | * |
26 | * Revision 1.1 2002/09/27 17:11:44 eilers | 29 | * Revision 1.1 2002/09/27 17:11:44 eilers |
27 | * Added API for accessing the Contact-Database ! It is compiling, but | 30 | * Added API for accessing the Contact-Database ! It is compiling, but |
28 | * please do not expect that anything is working ! | 31 | * please do not expect that anything is working ! |
29 | * I will debug that stuff in the next time .. | 32 | * I will debug that stuff in the next time .. |
30 | * Please read README_COMPILE for compiling ! | 33 | * Please read README_COMPILE for compiling ! |
31 | * | 34 | * |
32 | * ===================================================================== | 35 | * ===================================================================== |
33 | */ | 36 | */ |
34 | #ifndef _OCONTACTACCESS_H | 37 | #ifndef _OCONTACTACCESS_H |
35 | #define _OCONTACTACCESS_H | 38 | #define _OCONTACTACCESS_H |
36 | 39 | ||
37 | #include <qobject.h> | 40 | #include <qobject.h> |
38 | 41 | ||
39 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
40 | 43 | ||
41 | #include <qvaluelist.h> | 44 | #include <qvaluelist.h> |
42 | #include <qfileinfo.h> | 45 | #include <qfileinfo.h> |
43 | 46 | ||
44 | #include "ocontact.h" | 47 | #include "ocontact.h" |
45 | #include "ocontactaccessbackend.h" | 48 | #include "ocontactaccessbackend.h" |
46 | #include "opimaccesstemplate.h" | 49 | #include "opimaccesstemplate.h" |
47 | 50 | ||
48 | /** Class to access the contacts database. | 51 | /** Class to access the contacts database. |
49 | * This is just a frontend for the real database handling which is | 52 | * This is just a frontend for the real database handling which is |
50 | * done by the backend. | 53 | * done by the backend. |
54 | * @see OPimAccessTemplate | ||
51 | */ | 55 | */ |
52 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 56 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
53 | { | 57 | { |
54 | Q_OBJECT | 58 | Q_OBJECT |
55 | 59 | ||
56 | public: | 60 | public: |
57 | /** Create Database with contacts (addressbook). | 61 | /** Create Database with contacts (addressbook). |
58 | * @param appname Name of application which wants access to the database | 62 | * @param appname Name of application which wants access to the database |
59 | * (i.e. "todolist") | 63 | * (i.e. "todolist") |
60 | * @param filename The name of the database file. If not set, the default one | 64 | * @param filename The name of the database file. If not set, the default one |
61 | * is used. | 65 | * is used. |
62 | * @param backend Pointer to an alternative Backend. If not set, we will use | 66 | * @param backend Pointer to an alternative Backend. If not set, we will use |
63 | * the default backend. | 67 | * the default backend. |
64 | * @param handlesync If <b>true</b> the database stores the current state | 68 | * @param handlesync If <b>true</b> the database stores the current state |
65 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 69 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
66 | * which are used before and after synchronisation. If the application wants | 70 | * which are used before and after synchronisation. If the application wants |
67 | * to react itself, it should be disabled by setting it to <b>false</b> | 71 | * to react itself, it should be disabled by setting it to <b>false</b> |
68 | * @see OContactAccessBackend | 72 | * @see OContactAccessBackend |
69 | */ | 73 | */ |
70 | OContactAccess (const QString appname, const QString filename = 0l, | 74 | OContactAccess (const QString appname, const QString filename = 0l, |
71 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 75 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
72 | ~OContactAccess (); | 76 | ~OContactAccess (); |
73 | 77 | ||
74 | /** Constants for query. | 78 | /** Constants for query. |
75 | * Use this constants to set the query parameters. | 79 | * Use this constants to set the query parameters. |
76 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 80 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
77 | * @see queryByExample() | 81 | * @see queryByExample() |
78 | */ | 82 | */ |
79 | enum QuerySettings { | 83 | enum QuerySettings { |
80 | WildCards = 0x0001, | 84 | WildCards = 0x0001, |
81 | IgnoreCase = 0x0002, | 85 | IgnoreCase = 0x0002, |
82 | RegExp = 0x0004, | 86 | RegExp = 0x0004, |
83 | ExactMatch = 0x0008, | 87 | ExactMatch = 0x0008, |
88 | MatchOne = 0x0010 // Only one Entry must match | ||
84 | }; | 89 | }; |
85 | 90 | ||
91 | |||
92 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | ||
93 | |||
86 | /** Return all possible settings. | 94 | /** Return all possible settings. |
87 | * @return All settings provided by the current backend | 95 | * @return All settings provided by the current backend |
88 | * (i.e.: query_WildCards & query_IgnoreCase) | 96 | * (i.e.: query_WildCards & query_IgnoreCase) |
89 | */ | 97 | */ |
90 | const uint querySettings(); | 98 | const uint querySettings(); |
91 | 99 | ||
92 | /** Check whether settings are correct. | 100 | /** Check whether settings are correct. |
93 | * @return <i>true</i> if the given settings are correct and possible. | 101 | * @return <i>true</i> if the given settings are correct and possible. |
94 | */ | 102 | */ |
95 | bool hasQuerySettings ( int querySettings ) const; | 103 | bool hasQuerySettings ( int querySettings ) const; |
96 | 104 | ||
97 | /** | 105 | /** |
98 | * if the resource was changed externally. | 106 | * if the resource was changed externally. |
99 | * You should use the signal instead of polling possible changes ! | 107 | * You should use the signal instead of polling possible changes ! |
100 | */ | 108 | */ |
101 | bool wasChangedExternally()const; | 109 | bool wasChangedExternally()const; |
102 | 110 | ||
103 | 111 | ||
104 | /** Save contacts database. | 112 | /** Save contacts database. |
105 | * Save is more a "commit". After calling this function, all changes are public available. | 113 | * Save is more a "commit". After calling this function, all changes are public available. |
106 | * @return true if successful | 114 | * @return true if successful |
107 | */ | 115 | */ |
108 | bool save(); | 116 | bool save(); |
109 | 117 | ||
110 | signals: | 118 | signals: |
111 | /* Signal is emitted if the database was changed. Therefore | 119 | /* Signal is emitted if the database was changed. Therefore |
112 | * we may need to reload to stay consistent. | 120 | * we may need to reload to stay consistent. |
113 | * @param which Pointer to the database who created this event. This pointer | 121 | * @param which Pointer to the database who created this event. This pointer |
114 | * is useful if an application has to handle multiple databases at the same time. | 122 | * is useful if an application has to handle multiple databases at the same time. |
115 | * @see reload() | 123 | * @see reload() |
116 | */ | 124 | */ |
117 | void signalChanged ( const OContactAccess *which ); | 125 | void signalChanged ( const OContactAccess *which ); |
118 | 126 | ||
119 | 127 | ||
120 | private: | 128 | private: |
121 | // class OContactAccessPrivate; | 129 | // class OContactAccessPrivate; |
122 | // OContactAccessPrivate* d; | 130 | // OContactAccessPrivate* d; |
123 | OContactAccessBackend *m_backEnd; | 131 | OContactAccessBackend *m_backEnd; |
124 | bool m_loading:1; | 132 | bool m_loading:1; |
125 | 133 | ||
126 | private slots: | 134 | private slots: |
127 | void copMessage( const QCString &msg, const QByteArray &data ); | 135 | void copMessage( const QCString &msg, const QByteArray &data ); |
128 | 136 | ||
129 | 137 | ||
130 | }; | 138 | }; |
131 | #endif | 139 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h index a651477..c898f61 100644 --- a/libopie/pim/ocontactaccessbackend.h +++ b/libopie/pim/ocontactaccessbackend.h | |||
@@ -1,74 +1,81 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.3 2002/11/01 15:10:42 eilers | ||
23 | * Added regExp-search in database for all fields in a contact. | ||
24 | * | ||
22 | * Revision 1.2 2002/10/07 17:34:24 eilers | 25 | * Revision 1.2 2002/10/07 17:34:24 eilers |
23 | * added OBackendFactory for advanced backend access | 26 | * added OBackendFactory for advanced backend access |
24 | * | 27 | * |
25 | * Revision 1.1 2002/09/27 17:11:44 eilers | 28 | * Revision 1.1 2002/09/27 17:11:44 eilers |
26 | * Added API for accessing the Contact-Database ! It is compiling, but | 29 | * Added API for accessing the Contact-Database ! It is compiling, but |
27 | * please do not expect that anything is working ! | 30 | * please do not expect that anything is working ! |
28 | * I will debug that stuff in the next time .. | 31 | * I will debug that stuff in the next time .. |
29 | * Please read README_COMPILE for compiling ! | 32 | * Please read README_COMPILE for compiling ! |
30 | * | 33 | * |
31 | * ===================================================================== | 34 | * ===================================================================== |
32 | * | 35 | * |
33 | */ | 36 | */ |
34 | 37 | ||
35 | #ifndef _OCONTACTACCESSBACKEND_H_ | 38 | #ifndef _OCONTACTACCESSBACKEND_H_ |
36 | #define _OCONTACTACCESSBACKEND_H_ | 39 | #define _OCONTACTACCESSBACKEND_H_ |
37 | 40 | ||
38 | #include "ocontact.h" | 41 | #include "ocontact.h" |
39 | #include "opimaccessbackend.h" | 42 | #include "opimaccessbackend.h" |
40 | 43 | ||
44 | #include "qregexp.h" | ||
45 | |||
41 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 46 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
42 | public: | 47 | public: |
43 | OContactAccessBackend() {} | 48 | OContactAccessBackend() {} |
44 | virtual ~OContactAccessBackend() {} | 49 | virtual ~OContactAccessBackend() {} |
45 | 50 | ||
46 | 51 | ||
47 | /** Return if database was changed externally. | 52 | /** Return if database was changed externally. |
48 | * This may just make sense on file based databases like a XML-File. | 53 | * This may just make sense on file based databases like a XML-File. |
49 | * It is used to prevent to overwrite the current database content | 54 | * It is used to prevent to overwrite the current database content |
50 | * if the file was already changed by something else ! | 55 | * if the file was already changed by something else ! |
51 | * If this happens, we have to reload before save our data. | 56 | * If this happens, we have to reload before save our data. |
52 | * If we use real databases, this should be handled by the database | 57 | * If we use real databases, this should be handled by the database |
53 | * management system themselve, therefore this function should always return false in | 58 | * management system themselve, therefore this function should always return false in |
54 | * this case. It is not our problem to handle this conflict ... | 59 | * this case. It is not our problem to handle this conflict ... |
55 | * @return <i>true</i> if the database was changed and if save without reload will | 60 | * @return <i>true</i> if the database was changed and if save without reload will |
56 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 61 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
57 | * in this situation. | 62 | * in this situation. |
58 | */ | 63 | */ |
59 | virtual bool wasChangedExternally() = 0; | 64 | virtual bool wasChangedExternally() = 0; |
60 | 65 | ||
66 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | ||
67 | |||
61 | /** Return all possible settings. | 68 | /** Return all possible settings. |
62 | * @return All settings provided by the current backend | 69 | * @return All settings provided by the current backend |
63 | * (i.e.: query_WildCards & query_IgnoreCase) | 70 | * (i.e.: query_WildCards & query_IgnoreCase) |
64 | */ | 71 | */ |
65 | virtual const uint querySettings() = 0; | 72 | virtual const uint querySettings() = 0; |
66 | 73 | ||
67 | /** Check whether settings are correct. | 74 | /** Check whether settings are correct. |
68 | * @return <i>true</i> if the given settings are correct and possible. | 75 | * @return <i>true</i> if the given settings are correct and possible. |
69 | */ | 76 | */ |
70 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 77 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
71 | 78 | ||
72 | 79 | ||
73 | }; | 80 | }; |
74 | #endif | 81 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index 12a75ba..f7e8207 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -1,582 +1,602 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
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 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2002/11/01 15:10:42 eilers | ||
21 | * Added regExp-search in database for all fields in a contact. | ||
22 | * | ||
20 | * Revision 1.4 2002/10/16 10:52:40 eilers | 23 | * Revision 1.4 2002/10/16 10:52:40 eilers |
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
22 | * | 25 | * |
23 | * Revision 1.3 2002/10/14 16:21:54 eilers | 26 | * Revision 1.3 2002/10/14 16:21:54 eilers |
24 | * Some minor interface updates | 27 | * Some minor interface updates |
25 | * | 28 | * |
26 | * Revision 1.2 2002/10/07 17:34:24 eilers | 29 | * Revision 1.2 2002/10/07 17:34:24 eilers |
27 | * added OBackendFactory for advanced backend access | 30 | * added OBackendFactory for advanced backend access |
28 | * | 31 | * |
29 | * Revision 1.1 2002/09/27 17:11:44 eilers | 32 | * Revision 1.1 2002/09/27 17:11:44 eilers |
30 | * Added API for accessing the Contact-Database ! It is compiling, but | 33 | * Added API for accessing the Contact-Database ! It is compiling, but |
31 | * please do not expect that anything is working ! | 34 | * please do not expect that anything is working ! |
32 | * I will debug that stuff in the next time .. | 35 | * I will debug that stuff in the next time .. |
33 | * Please read README_COMPILE for compiling ! | 36 | * Please read README_COMPILE for compiling ! |
34 | * | 37 | * |
35 | * | 38 | * |
36 | */ | 39 | */ |
37 | 40 | ||
38 | #ifndef _OContactAccessBackend_XML_ | 41 | #ifndef _OContactAccessBackend_XML_ |
39 | #define _OContactAccessBackend_XML_ | 42 | #define _OContactAccessBackend_XML_ |
40 | 43 | ||
41 | #include <qasciidict.h> | 44 | #include <qasciidict.h> |
42 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
43 | #include <qfile.h> | 46 | #include <qfile.h> |
44 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
45 | #include <qregexp.h> | 48 | #include <qregexp.h> |
46 | #include <qarray.h> | 49 | #include <qarray.h> |
47 | 50 | ||
48 | #include <qpe/global.h> | 51 | #include <qpe/global.h> |
49 | 52 | ||
50 | #include <opie/xmltree.h> | 53 | #include <opie/xmltree.h> |
51 | #include "ocontactaccessbackend.h" | 54 | #include "ocontactaccessbackend.h" |
52 | #include "ocontactaccess.h" | 55 | #include "ocontactaccess.h" |
53 | 56 | ||
54 | #include <stdlib.h> | 57 | #include <stdlib.h> |
55 | #include <errno.h> | 58 | #include <errno.h> |
56 | 59 | ||
57 | using namespace Opie; | 60 | using namespace Opie; |
58 | 61 | ||
59 | /* the default xml implementation */ | 62 | /* the default xml implementation */ |
60 | class OContactAccessBackend_XML : public OContactAccessBackend { | 63 | class OContactAccessBackend_XML : public OContactAccessBackend { |
61 | public: | 64 | public: |
62 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 65 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
63 | m_changed( false ) | 66 | m_changed( false ) |
64 | { | 67 | { |
65 | m_appName = appname; | 68 | m_appName = appname; |
66 | 69 | ||
67 | /* Set journalfile name ... */ | 70 | /* Set journalfile name ... */ |
68 | m_journalName = getenv("HOME"); | 71 | m_journalName = getenv("HOME"); |
69 | m_journalName +="/.abjournal" + appname; | 72 | m_journalName +="/.abjournal" + appname; |
70 | 73 | ||
71 | /* Expecting to access the default filename if nothing else is set */ | 74 | /* Expecting to access the default filename if nothing else is set */ |
72 | if ( filename.isEmpty() ){ | 75 | if ( filename.isEmpty() ){ |
73 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 76 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
74 | } else | 77 | } else |
75 | m_fileName = filename; | 78 | m_fileName = filename; |
76 | 79 | ||
77 | /* Load Database now */ | 80 | /* Load Database now */ |
78 | load (); | 81 | load (); |
79 | } | 82 | } |
80 | 83 | ||
81 | bool save() { | 84 | bool save() { |
82 | 85 | ||
83 | if ( !m_changed ) | 86 | if ( !m_changed ) |
84 | return true; | 87 | return true; |
85 | 88 | ||
86 | QString strNewFile = m_fileName + ".new"; | 89 | QString strNewFile = m_fileName + ".new"; |
87 | QFile f( strNewFile ); | 90 | QFile f( strNewFile ); |
88 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 91 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
89 | return false; | 92 | return false; |
90 | 93 | ||
91 | int total_written; | 94 | int total_written; |
92 | QString out; | 95 | QString out; |
93 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 96 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
94 | " <Groups>\n" | 97 | " <Groups>\n" |
95 | " </Groups>\n" | 98 | " </Groups>\n" |
96 | " <Contacts>\n"; | 99 | " <Contacts>\n"; |
97 | //QValueList<Contact>::iterator it; | 100 | //QValueList<Contact>::iterator it; |
98 | QValueListConstIterator<OContact> it; | 101 | QValueListConstIterator<OContact> it; |
99 | for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) { | 102 | for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) { |
100 | out += "<Contact "; | 103 | out += "<Contact "; |
101 | (*it).save( out ); | 104 | (*it).save( out ); |
102 | out += "/>\n"; | 105 | out += "/>\n"; |
103 | QCString cstr = out.utf8(); | 106 | QCString cstr = out.utf8(); |
104 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 107 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
105 | if ( total_written != int(cstr.length()) ) { | 108 | if ( total_written != int(cstr.length()) ) { |
106 | f.close(); | 109 | f.close(); |
107 | QFile::remove( strNewFile ); | 110 | QFile::remove( strNewFile ); |
108 | return false; | 111 | return false; |
109 | } | 112 | } |
110 | out = ""; | 113 | out = ""; |
111 | } | 114 | } |
112 | out += " </Contacts>\n</AddressBook>\n"; | 115 | out += " </Contacts>\n</AddressBook>\n"; |
113 | 116 | ||
114 | QCString cstr = out.utf8(); | 117 | QCString cstr = out.utf8(); |
115 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 118 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
116 | if ( total_written != int( cstr.length() ) ) { | 119 | if ( total_written != int( cstr.length() ) ) { |
117 | f.close(); | 120 | f.close(); |
118 | QFile::remove( strNewFile ); | 121 | QFile::remove( strNewFile ); |
119 | return false; | 122 | return false; |
120 | } | 123 | } |
121 | f.close(); | 124 | f.close(); |
122 | 125 | ||
123 | // move the file over, I'm just going to use the system call | 126 | // move the file over, I'm just going to use the system call |
124 | // because, I don't feel like using QDir. | 127 | // because, I don't feel like using QDir. |
125 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 128 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
126 | qWarning( "problem renaming file %s to %s, errno: %d", | 129 | qWarning( "problem renaming file %s to %s, errno: %d", |
127 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 130 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
128 | // remove the tmp file... | 131 | // remove the tmp file... |
129 | QFile::remove( strNewFile ); | 132 | QFile::remove( strNewFile ); |
130 | } | 133 | } |
131 | 134 | ||
132 | /* The journalfile should be removed now... */ | 135 | /* The journalfile should be removed now... */ |
133 | removeJournal(); | 136 | removeJournal(); |
134 | 137 | ||
135 | m_changed = false; | 138 | m_changed = false; |
136 | return true; | 139 | return true; |
137 | } | 140 | } |
138 | 141 | ||
139 | bool load () { | 142 | bool load () { |
140 | m_contactList.clear(); | 143 | m_contactList.clear(); |
141 | 144 | ||
142 | /* Load XML-File and journal if it exists */ | 145 | /* Load XML-File and journal if it exists */ |
143 | if ( !load ( m_fileName, false ) ) | 146 | if ( !load ( m_fileName, false ) ) |
144 | return false; | 147 | return false; |
145 | /* The returncode of the journalfile is ignored due to the | 148 | /* The returncode of the journalfile is ignored due to the |
146 | * fact that it does not exist when this class is instantiated ! | 149 | * fact that it does not exist when this class is instantiated ! |
147 | * But there may such a file exist, if the application crashed. | 150 | * But there may such a file exist, if the application crashed. |
148 | * Therefore we try to load it to get the changes before the # | 151 | * Therefore we try to load it to get the changes before the # |
149 | * crash happened... | 152 | * crash happened... |
150 | */ | 153 | */ |
151 | load (m_journalName, true); | 154 | load (m_journalName, true); |
152 | 155 | ||
153 | return true; | 156 | return true; |
154 | } | 157 | } |
155 | 158 | ||
156 | void clear () { | 159 | void clear () { |
157 | m_contactList.clear(); | 160 | m_contactList.clear(); |
158 | m_changed = false; | 161 | m_changed = false; |
159 | 162 | ||
160 | } | 163 | } |
161 | 164 | ||
162 | bool wasChangedExternally() | 165 | bool wasChangedExternally() |
163 | { | 166 | { |
164 | QFileInfo fi( m_fileName ); | 167 | QFileInfo fi( m_fileName ); |
165 | 168 | ||
166 | QDateTime lastmod = fi.lastModified (); | 169 | QDateTime lastmod = fi.lastModified (); |
167 | 170 | ||
168 | return (lastmod != m_readtime); | 171 | return (lastmod != m_readtime); |
169 | } | 172 | } |
170 | 173 | ||
171 | QArray<int> allRecords() const { | 174 | QArray<int> allRecords() const { |
172 | QArray<int> uid_list( m_contactList.count() ); | 175 | QArray<int> uid_list( m_contactList.count() ); |
173 | 176 | ||
174 | uint counter = 0; | 177 | uint counter = 0; |
175 | QValueListConstIterator<OContact> it; | 178 | QValueListConstIterator<OContact> it; |
176 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 179 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
177 | uid_list[counter++] = (*it).uid(); | 180 | uid_list[counter++] = (*it).uid(); |
178 | } | 181 | } |
179 | 182 | ||
180 | return ( uid_list ); | 183 | return ( uid_list ); |
181 | } | 184 | } |
182 | 185 | ||
183 | OContact find ( int uid ) const | 186 | OContact find ( int uid ) const |
184 | { | 187 | { |
185 | bool found = false; | 188 | bool found = false; |
186 | OContact foundContact; //Create empty contact | 189 | OContact foundContact; //Create empty contact |
187 | 190 | ||
188 | QValueListConstIterator<OContact> it; | 191 | QValueListConstIterator<OContact> it; |
189 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 192 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
190 | if ((*it).uid() == uid){ | 193 | if ((*it).uid() == uid){ |
191 | found = true; | 194 | found = true; |
192 | break; | 195 | break; |
193 | } | 196 | } |
194 | } | 197 | } |
195 | if ( found ){ | 198 | if ( found ){ |
196 | foundContact = *it; | 199 | foundContact = *it; |
197 | } | 200 | } |
198 | 201 | ||
199 | return ( foundContact ); | 202 | return ( foundContact ); |
200 | } | 203 | } |
201 | 204 | ||
202 | QArray<int> queryByExample ( const OContact &query, int settings ){ | 205 | QArray<int> queryByExample ( const OContact &query, int settings ){ |
203 | 206 | ||
204 | QArray<int> m_currentQuery( m_contactList.count() ); | 207 | QArray<int> m_currentQuery( m_contactList.count() ); |
205 | QValueListConstIterator<OContact> it; | 208 | QValueListConstIterator<OContact> it; |
206 | uint arraycounter = 0; | 209 | uint arraycounter = 0; |
207 | 210 | ||
208 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 211 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
209 | /* Search all fields and compare them with query object. Store them into list | 212 | /* Search all fields and compare them with query object. Store them into list |
210 | * if all fields matches. | 213 | * if all fields matches. |
211 | */ | 214 | */ |
212 | bool allcorrect = true; | 215 | bool allcorrect = true; |
213 | for ( int i = 0; i < Qtopia::rid; i++ ) { | 216 | for ( int i = 0; i < Qtopia::rid; i++ ) { |
214 | /* Just compare fields which are not empty in the query object */ | 217 | /* Just compare fields which are not empty in the query object */ |
215 | if ( !query.field(i).isEmpty() ){ | 218 | if ( !query.field(i).isEmpty() ){ |
216 | switch ( settings & ~OContactAccess::IgnoreCase ){ | 219 | switch ( settings & ~OContactAccess::IgnoreCase ){ |
217 | case OContactAccess::RegExp:{ | 220 | case OContactAccess::RegExp:{ |
218 | QRegExp expr ( query.field(i), | 221 | QRegExp expr ( query.field(i), |
219 | !(settings & OContactAccess::IgnoreCase), | 222 | !(settings & OContactAccess::IgnoreCase), |
220 | false ); | 223 | false ); |
221 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 224 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) |
222 | allcorrect = false; | 225 | allcorrect = false; |
223 | } | 226 | } |
224 | break; | 227 | break; |
225 | case OContactAccess::WildCards:{ | 228 | case OContactAccess::WildCards:{ |
226 | QRegExp expr ( query.field(i), | 229 | QRegExp expr ( query.field(i), |
227 | !(settings & OContactAccess::IgnoreCase), | 230 | !(settings & OContactAccess::IgnoreCase), |
228 | true ); | 231 | true ); |
229 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 232 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) |
230 | allcorrect = false; | 233 | allcorrect = false; |
231 | } | 234 | } |
232 | break; | 235 | break; |
233 | case OContactAccess::ExactMatch:{ | 236 | case OContactAccess::ExactMatch:{ |
234 | if (settings & OContactAccess::IgnoreCase){ | 237 | if (settings & OContactAccess::IgnoreCase){ |
235 | if ( query.field(i).upper() != | 238 | if ( query.field(i).upper() != |
236 | (*it).field(i).upper() ) | 239 | (*it).field(i).upper() ) |
237 | allcorrect = false; | 240 | allcorrect = false; |
238 | }else{ | 241 | }else{ |
239 | if ( query.field(i) != (*it).field(i) ) | 242 | if ( query.field(i) != (*it).field(i) ) |
240 | allcorrect = false; | 243 | allcorrect = false; |
241 | } | 244 | } |
242 | } | 245 | } |
243 | break; | 246 | break; |
244 | } | 247 | } |
245 | } | 248 | } |
246 | } | 249 | } |
247 | if ( allcorrect ){ | 250 | if ( allcorrect ){ |
248 | m_currentQuery[arraycounter++] = (*it).uid(); | 251 | m_currentQuery[arraycounter++] = (*it).uid(); |
249 | } | 252 | } |
250 | } | 253 | } |
251 | 254 | ||
252 | // Shrink to fit.. | 255 | // Shrink to fit.. |
253 | m_currentQuery.resize(arraycounter); | 256 | m_currentQuery.resize(arraycounter); |
254 | 257 | ||
255 | return m_currentQuery; | 258 | return m_currentQuery; |
256 | } | 259 | } |
260 | |||
261 | QArray<int> matchRegexp( const QRegExp &r ) const{ | ||
262 | QArray<int> m_currentQuery( m_contactList.count() ); | ||
263 | QValueListConstIterator<OContact> it; | ||
264 | uint arraycounter = 0; | ||
265 | |||
266 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | ||
267 | if ( (*it).match( r ) ){ | ||
268 | m_currentQuery[arraycounter++] = (*it).uid(); | ||
269 | } | ||
270 | |||
271 | } | ||
272 | // Shrink to fit.. | ||
273 | m_currentQuery.resize(arraycounter); | ||
274 | |||
275 | return m_currentQuery; | ||
276 | } | ||
257 | 277 | ||
258 | const uint querySettings() | 278 | const uint querySettings() |
259 | { | 279 | { |
260 | return ( OContactAccess::WildCards | 280 | return ( OContactAccess::WildCards |
261 | & OContactAccess::IgnoreCase | 281 | & OContactAccess::IgnoreCase |
262 | & OContactAccess::RegExp | 282 | & OContactAccess::RegExp |
263 | & OContactAccess::ExactMatch ); | 283 | & OContactAccess::ExactMatch ); |
264 | } | 284 | } |
265 | 285 | ||
266 | bool hasQuerySettings (uint querySettings) const | 286 | bool hasQuerySettings (uint querySettings) const |
267 | { | 287 | { |
268 | /* OContactAccess::IgnoreCase may be added with one | 288 | /* OContactAccess::IgnoreCase may be added with one |
269 | * of the other settings, but never used alone. | 289 | * of the other settings, but never used alone. |
270 | * The other settings are just valid alone... | 290 | * The other settings are just valid alone... |
271 | */ | 291 | */ |
272 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ | 292 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ |
273 | case OContactAccess::RegExp: | 293 | case OContactAccess::RegExp: |
274 | return ( true ); | 294 | return ( true ); |
275 | case OContactAccess::WildCards: | 295 | case OContactAccess::WildCards: |
276 | return ( true ); | 296 | return ( true ); |
277 | case OContactAccess::ExactMatch: | 297 | case OContactAccess::ExactMatch: |
278 | return ( true ); | 298 | return ( true ); |
279 | default: | 299 | default: |
280 | return ( false ); | 300 | return ( false ); |
281 | } | 301 | } |
282 | } | 302 | } |
283 | 303 | ||
284 | bool add ( const OContact &newcontact ) | 304 | bool add ( const OContact &newcontact ) |
285 | { | 305 | { |
286 | //qWarning("odefaultbackend: ACTION::ADD"); | 306 | //qWarning("odefaultbackend: ACTION::ADD"); |
287 | updateJournal (newcontact, OContact::ACTION_ADD); | 307 | updateJournal (newcontact, OContact::ACTION_ADD); |
288 | addContact_p( newcontact ); | 308 | addContact_p( newcontact ); |
289 | 309 | ||
290 | m_changed = true; | 310 | m_changed = true; |
291 | 311 | ||
292 | return true; | 312 | return true; |
293 | } | 313 | } |
294 | 314 | ||
295 | bool replace ( const OContact &contact ) | 315 | bool replace ( const OContact &contact ) |
296 | { | 316 | { |
297 | m_changed = true; | 317 | m_changed = true; |
298 | 318 | ||
299 | bool found = false; | 319 | bool found = false; |
300 | 320 | ||
301 | QValueListIterator<OContact> it; | 321 | QValueListIterator<OContact> it; |
302 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 322 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
303 | if ( (*it).uid() == contact.uid() ){ | 323 | if ( (*it).uid() == contact.uid() ){ |
304 | found = true; | 324 | found = true; |
305 | break; | 325 | break; |
306 | } | 326 | } |
307 | } | 327 | } |
308 | if (found) { | 328 | if (found) { |
309 | updateJournal (contact, OContact::ACTION_REPLACE); | 329 | updateJournal (contact, OContact::ACTION_REPLACE); |
310 | m_contactList.remove (it); | 330 | m_contactList.remove (it); |
311 | m_contactList.append (contact); | 331 | m_contactList.append (contact); |
312 | return true; | 332 | return true; |
313 | } else | 333 | } else |
314 | return false; | 334 | return false; |
315 | } | 335 | } |
316 | 336 | ||
317 | bool remove ( int uid ) | 337 | bool remove ( int uid ) |
318 | { | 338 | { |
319 | m_changed = true; | 339 | m_changed = true; |
320 | 340 | ||
321 | bool found = false; | 341 | bool found = false; |
322 | QValueListIterator<OContact> it; | 342 | QValueListIterator<OContact> it; |
323 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 343 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
324 | if ((*it).uid() == uid){ | 344 | if ((*it).uid() == uid){ |
325 | found = true; | 345 | found = true; |
326 | break; | 346 | break; |
327 | } | 347 | } |
328 | } | 348 | } |
329 | if (found) { | 349 | if (found) { |
330 | updateJournal ( *it, OContact::ACTION_REMOVE); | 350 | updateJournal ( *it, OContact::ACTION_REMOVE); |
331 | m_contactList.remove (it); | 351 | m_contactList.remove (it); |
332 | return true; | 352 | return true; |
333 | } else | 353 | } else |
334 | return false; | 354 | return false; |
335 | } | 355 | } |
336 | 356 | ||
337 | bool reload(){ | 357 | bool reload(){ |
338 | /* Reload is the same as load in this implementation */ | 358 | /* Reload is the same as load in this implementation */ |
339 | return ( load() ); | 359 | return ( load() ); |
340 | } | 360 | } |
341 | 361 | ||
342 | private: | 362 | private: |
343 | void addContact_p( const OContact &newcontact ){ | 363 | void addContact_p( const OContact &newcontact ){ |
344 | m_contactList.append (newcontact); | 364 | m_contactList.append (newcontact); |
345 | } | 365 | } |
346 | 366 | ||
347 | /* This function loads the xml-database and the journalfile */ | 367 | /* This function loads the xml-database and the journalfile */ |
348 | bool load( const QString filename, bool isJournal ) { | 368 | bool load( const QString filename, bool isJournal ) { |
349 | 369 | ||
350 | /* We use the time of the last read to check if the file was | 370 | /* We use the time of the last read to check if the file was |
351 | * changed externally. | 371 | * changed externally. |
352 | */ | 372 | */ |
353 | if ( !isJournal ){ | 373 | if ( !isJournal ){ |
354 | QFileInfo fi( filename ); | 374 | QFileInfo fi( filename ); |
355 | m_readtime = fi.lastModified (); | 375 | m_readtime = fi.lastModified (); |
356 | } | 376 | } |
357 | 377 | ||
358 | const int JOURNALACTION = Qtopia::Notes + 1; | 378 | const int JOURNALACTION = Qtopia::Notes + 1; |
359 | const int JOURNALROW = JOURNALACTION + 1; | 379 | const int JOURNALROW = JOURNALACTION + 1; |
360 | 380 | ||
361 | bool foundAction = false; | 381 | bool foundAction = false; |
362 | OContact::journal_action action = OContact::ACTION_ADD; | 382 | OContact::journal_action action = OContact::ACTION_ADD; |
363 | int journalKey = 0; | 383 | int journalKey = 0; |
364 | QMap<int, QString> contactMap; | 384 | QMap<int, QString> contactMap; |
365 | QMap<QString, QString> customMap; | 385 | QMap<QString, QString> customMap; |
366 | QMap<QString, QString>::Iterator customIt; | 386 | QMap<QString, QString>::Iterator customIt; |
367 | QAsciiDict<int> dict( 47 ); | 387 | QAsciiDict<int> dict( 47 ); |
368 | 388 | ||
369 | dict.setAutoDelete( TRUE ); | 389 | dict.setAutoDelete( TRUE ); |
370 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 390 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
371 | dict.insert( "Title", new int(Qtopia::Title) ); | 391 | dict.insert( "Title", new int(Qtopia::Title) ); |
372 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 392 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
373 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 393 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
374 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 394 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
375 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 395 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
376 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 396 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
377 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 397 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
378 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 398 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
379 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 399 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
380 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 400 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
381 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 401 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
382 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 402 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
383 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 403 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
384 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 404 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
385 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 405 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
386 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 406 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
387 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 407 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
388 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 408 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
389 | dict.insert( "Company", new int(Qtopia::Company) ); | 409 | dict.insert( "Company", new int(Qtopia::Company) ); |
390 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 410 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
391 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 411 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
392 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 412 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
393 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 413 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
394 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 414 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
395 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 415 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
396 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 416 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
397 | dict.insert( "Department", new int(Qtopia::Department) ); | 417 | dict.insert( "Department", new int(Qtopia::Department) ); |
398 | dict.insert( "Office", new int(Qtopia::Office) ); | 418 | dict.insert( "Office", new int(Qtopia::Office) ); |
399 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 419 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
400 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 420 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
401 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 421 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
402 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 422 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
403 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 423 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
404 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 424 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
405 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 425 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
406 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 426 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
407 | dict.insert( "Children", new int(Qtopia::Children) ); | 427 | dict.insert( "Children", new int(Qtopia::Children) ); |
408 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 428 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
409 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 429 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
410 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 430 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
411 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 431 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
412 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 432 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
413 | dict.insert( "action", new int(JOURNALACTION) ); | 433 | dict.insert( "action", new int(JOURNALACTION) ); |
414 | dict.insert( "actionrow", new int(JOURNALROW) ); | 434 | dict.insert( "actionrow", new int(JOURNALROW) ); |
415 | 435 | ||
416 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 436 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
417 | 437 | ||
418 | XMLElement *root = XMLElement::load( filename ); | 438 | XMLElement *root = XMLElement::load( filename ); |
419 | if(root != 0l ){ // start parsing | 439 | if(root != 0l ){ // start parsing |
420 | /* Parse all XML-Elements and put the data into the | 440 | /* Parse all XML-Elements and put the data into the |
421 | * Contact-Class | 441 | * Contact-Class |
422 | */ | 442 | */ |
423 | XMLElement *element = root->firstChild(); | 443 | XMLElement *element = root->firstChild(); |
424 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 444 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
425 | element = element->firstChild(); | 445 | element = element->firstChild(); |
426 | 446 | ||
427 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 447 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
428 | while( element && !isJournal ){ | 448 | while( element && !isJournal ){ |
429 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 449 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
430 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 450 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
431 | // element->tagName().latin1()); | 451 | // element->tagName().latin1()); |
432 | element = element->nextChild(); | 452 | element = element->nextChild(); |
433 | } else { | 453 | } else { |
434 | element = element->firstChild(); | 454 | element = element->firstChild(); |
435 | break; | 455 | break; |
436 | } | 456 | } |
437 | } | 457 | } |
438 | /* Parse all Contacts and ignore unknown tags */ | 458 | /* Parse all Contacts and ignore unknown tags */ |
439 | while( element ){ | 459 | while( element ){ |
440 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 460 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
441 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 461 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
442 | // element->tagName().latin1()); | 462 | // element->tagName().latin1()); |
443 | element = element->nextChild(); | 463 | element = element->nextChild(); |
444 | continue; | 464 | continue; |
445 | } | 465 | } |
446 | /* Found alement with tagname "contact", now parse and store all | 466 | /* Found alement with tagname "contact", now parse and store all |
447 | * attributes contained | 467 | * attributes contained |
448 | */ | 468 | */ |
449 | //qWarning("OContactDefBack::load element tagName() : %s", | 469 | //qWarning("OContactDefBack::load element tagName() : %s", |
450 | // element->tagName().latin1() ); | 470 | // element->tagName().latin1() ); |
451 | QString dummy; | 471 | QString dummy; |
452 | foundAction = false; | 472 | foundAction = false; |
453 | 473 | ||
454 | XMLElement::AttributeMap aMap = element->attributes(); | 474 | XMLElement::AttributeMap aMap = element->attributes(); |
455 | XMLElement::AttributeMap::Iterator it; | 475 | XMLElement::AttributeMap::Iterator it; |
456 | contactMap.clear(); | 476 | contactMap.clear(); |
457 | customMap.clear(); | 477 | customMap.clear(); |
458 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 478 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
459 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 479 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
460 | 480 | ||
461 | int *find = dict[ it.key() ]; | 481 | int *find = dict[ it.key() ]; |
462 | /* Unknown attributes will be stored as "Custom" elements */ | 482 | /* Unknown attributes will be stored as "Custom" elements */ |
463 | if ( !find ) { | 483 | if ( !find ) { |
464 | qWarning("Attribute %s not known.", it.key().latin1()); | 484 | qWarning("Attribute %s not known.", it.key().latin1()); |
465 | //contact.setCustomField(it.key(), it.data()); | 485 | //contact.setCustomField(it.key(), it.data()); |
466 | customMap.insert( it.key(), it.data() ); | 486 | customMap.insert( it.key(), it.data() ); |
467 | continue; | 487 | continue; |
468 | } | 488 | } |
469 | 489 | ||
470 | /* Check if special conversion is needed and add attribute | 490 | /* Check if special conversion is needed and add attribute |
471 | * into Contact class | 491 | * into Contact class |
472 | */ | 492 | */ |
473 | switch( *find ) { | 493 | switch( *find ) { |
474 | /* | 494 | /* |
475 | case Qtopia::AddressUid: | 495 | case Qtopia::AddressUid: |
476 | contact.setUid( it.data().toInt() ); | 496 | contact.setUid( it.data().toInt() ); |
477 | break; | 497 | break; |
478 | case Qtopia::AddressCategory: | 498 | case Qtopia::AddressCategory: |
479 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 499 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
480 | break; | 500 | break; |
481 | */ | 501 | */ |
482 | case JOURNALACTION: | 502 | case JOURNALACTION: |
483 | action = OContact::journal_action(it.data().toInt()); | 503 | action = OContact::journal_action(it.data().toInt()); |
484 | foundAction = true; | 504 | foundAction = true; |
485 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 505 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
486 | break; | 506 | break; |
487 | case JOURNALROW: | 507 | case JOURNALROW: |
488 | journalKey = it.data().toInt(); | 508 | journalKey = it.data().toInt(); |
489 | break; | 509 | break; |
490 | default: // no conversion needed add them to the map | 510 | default: // no conversion needed add them to the map |
491 | contactMap.insert( *find, it.data() ); | 511 | contactMap.insert( *find, it.data() ); |
492 | break; | 512 | break; |
493 | } | 513 | } |
494 | } | 514 | } |
495 | /* now generate the Contact contact */ | 515 | /* now generate the Contact contact */ |
496 | OContact contact( contactMap ); | 516 | OContact contact( contactMap ); |
497 | 517 | ||
498 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 518 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
499 | contact.setCustomField( customIt.key(), customIt.data() ); | 519 | contact.setCustomField( customIt.key(), customIt.data() ); |
500 | } | 520 | } |
501 | 521 | ||
502 | if (foundAction){ | 522 | if (foundAction){ |
503 | foundAction = false; | 523 | foundAction = false; |
504 | switch ( action ) { | 524 | switch ( action ) { |
505 | case OContact::ACTION_ADD: | 525 | case OContact::ACTION_ADD: |
506 | addContact_p (contact); | 526 | addContact_p (contact); |
507 | break; | 527 | break; |
508 | case OContact::ACTION_REMOVE: | 528 | case OContact::ACTION_REMOVE: |
509 | if ( !remove (contact.uid()) ) | 529 | if ( !remove (contact.uid()) ) |
510 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 530 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
511 | contact.uid() ); | 531 | contact.uid() ); |
512 | break; | 532 | break; |
513 | case OContact::ACTION_REPLACE: | 533 | case OContact::ACTION_REPLACE: |
514 | if ( !replace ( contact ) ) | 534 | if ( !replace ( contact ) ) |
515 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 535 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
516 | contact.uid() ); | 536 | contact.uid() ); |
517 | break; | 537 | break; |
518 | default: | 538 | default: |
519 | qWarning ("Unknown action: ignored !"); | 539 | qWarning ("Unknown action: ignored !"); |
520 | break; | 540 | break; |
521 | } | 541 | } |
522 | }else{ | 542 | }else{ |
523 | /* Add contact to list */ | 543 | /* Add contact to list */ |
524 | addContact_p (contact); | 544 | addContact_p (contact); |
525 | } | 545 | } |
526 | 546 | ||
527 | /* Move to next element */ | 547 | /* Move to next element */ |
528 | element = element->nextChild(); | 548 | element = element->nextChild(); |
529 | } | 549 | } |
530 | }else { | 550 | }else { |
531 | qWarning("ODefBack::could not load"); | 551 | qWarning("ODefBack::could not load"); |
532 | } | 552 | } |
533 | delete root; | 553 | delete root; |
534 | qWarning("returning from loading" ); | 554 | qWarning("returning from loading" ); |
535 | return true; | 555 | return true; |
536 | } | 556 | } |
537 | 557 | ||
538 | 558 | ||
539 | void updateJournal( const OContact& cnt, | 559 | void updateJournal( const OContact& cnt, |
540 | OContact::journal_action action ) { | 560 | OContact::journal_action action ) { |
541 | QFile f( m_journalName ); | 561 | QFile f( m_journalName ); |
542 | bool created = !f.exists(); | 562 | bool created = !f.exists(); |
543 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 563 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
544 | return; | 564 | return; |
545 | 565 | ||
546 | QString buf; | 566 | QString buf; |
547 | QCString str; | 567 | QCString str; |
548 | 568 | ||
549 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 569 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
550 | // get a XML-File which is readable by our parser. | 570 | // get a XML-File which is readable by our parser. |
551 | // This is just a cheat, but better than rewrite the parser. | 571 | // This is just a cheat, but better than rewrite the parser. |
552 | if ( created ){ | 572 | if ( created ){ |
553 | buf = "<Contacts>"; | 573 | buf = "<Contacts>"; |
554 | QCString cstr = buf.utf8(); | 574 | QCString cstr = buf.utf8(); |
555 | f.writeBlock( cstr.data(), cstr.length() ); | 575 | f.writeBlock( cstr.data(), cstr.length() ); |
556 | } | 576 | } |
557 | 577 | ||
558 | buf = "<Contact "; | 578 | buf = "<Contact "; |
559 | cnt.save( buf ); | 579 | cnt.save( buf ); |
560 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 580 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
561 | buf += "/>\n"; | 581 | buf += "/>\n"; |
562 | QCString cstr = buf.utf8(); | 582 | QCString cstr = buf.utf8(); |
563 | f.writeBlock( cstr.data(), cstr.length() ); | 583 | f.writeBlock( cstr.data(), cstr.length() ); |
564 | } | 584 | } |
565 | 585 | ||
566 | void removeJournal() | 586 | void removeJournal() |
567 | { | 587 | { |
568 | QFile f ( m_journalName ); | 588 | QFile f ( m_journalName ); |
569 | if ( f.exists() ) | 589 | if ( f.exists() ) |
570 | f.remove(); | 590 | f.remove(); |
571 | } | 591 | } |
572 | 592 | ||
573 | protected: | 593 | protected: |
574 | bool m_changed; | 594 | bool m_changed; |
575 | QString m_journalName; | 595 | QString m_journalName; |
576 | QString m_fileName; | 596 | QString m_fileName; |
577 | QString m_appName; | 597 | QString m_appName; |
578 | QValueList<OContact> m_contactList; | 598 | QValueList<OContact> m_contactList; |
579 | QDateTime m_readtime; | 599 | QDateTime m_readtime; |
580 | }; | 600 | }; |
581 | 601 | ||
582 | #endif | 602 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index a651477..c898f61 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,74 +1,81 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.3 2002/11/01 15:10:42 eilers | ||
23 | * Added regExp-search in database for all fields in a contact. | ||
24 | * | ||
22 | * Revision 1.2 2002/10/07 17:34:24 eilers | 25 | * Revision 1.2 2002/10/07 17:34:24 eilers |
23 | * added OBackendFactory for advanced backend access | 26 | * added OBackendFactory for advanced backend access |
24 | * | 27 | * |
25 | * Revision 1.1 2002/09/27 17:11:44 eilers | 28 | * Revision 1.1 2002/09/27 17:11:44 eilers |
26 | * Added API for accessing the Contact-Database ! It is compiling, but | 29 | * Added API for accessing the Contact-Database ! It is compiling, but |
27 | * please do not expect that anything is working ! | 30 | * please do not expect that anything is working ! |
28 | * I will debug that stuff in the next time .. | 31 | * I will debug that stuff in the next time .. |
29 | * Please read README_COMPILE for compiling ! | 32 | * Please read README_COMPILE for compiling ! |
30 | * | 33 | * |
31 | * ===================================================================== | 34 | * ===================================================================== |
32 | * | 35 | * |
33 | */ | 36 | */ |
34 | 37 | ||
35 | #ifndef _OCONTACTACCESSBACKEND_H_ | 38 | #ifndef _OCONTACTACCESSBACKEND_H_ |
36 | #define _OCONTACTACCESSBACKEND_H_ | 39 | #define _OCONTACTACCESSBACKEND_H_ |
37 | 40 | ||
38 | #include "ocontact.h" | 41 | #include "ocontact.h" |
39 | #include "opimaccessbackend.h" | 42 | #include "opimaccessbackend.h" |
40 | 43 | ||
44 | #include "qregexp.h" | ||
45 | |||
41 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 46 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
42 | public: | 47 | public: |
43 | OContactAccessBackend() {} | 48 | OContactAccessBackend() {} |
44 | virtual ~OContactAccessBackend() {} | 49 | virtual ~OContactAccessBackend() {} |
45 | 50 | ||
46 | 51 | ||
47 | /** Return if database was changed externally. | 52 | /** Return if database was changed externally. |
48 | * This may just make sense on file based databases like a XML-File. | 53 | * This may just make sense on file based databases like a XML-File. |
49 | * It is used to prevent to overwrite the current database content | 54 | * It is used to prevent to overwrite the current database content |
50 | * if the file was already changed by something else ! | 55 | * if the file was already changed by something else ! |
51 | * If this happens, we have to reload before save our data. | 56 | * If this happens, we have to reload before save our data. |
52 | * If we use real databases, this should be handled by the database | 57 | * If we use real databases, this should be handled by the database |
53 | * management system themselve, therefore this function should always return false in | 58 | * management system themselve, therefore this function should always return false in |
54 | * this case. It is not our problem to handle this conflict ... | 59 | * this case. It is not our problem to handle this conflict ... |
55 | * @return <i>true</i> if the database was changed and if save without reload will | 60 | * @return <i>true</i> if the database was changed and if save without reload will |
56 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 61 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
57 | * in this situation. | 62 | * in this situation. |
58 | */ | 63 | */ |
59 | virtual bool wasChangedExternally() = 0; | 64 | virtual bool wasChangedExternally() = 0; |
60 | 65 | ||
66 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | ||
67 | |||
61 | /** Return all possible settings. | 68 | /** Return all possible settings. |
62 | * @return All settings provided by the current backend | 69 | * @return All settings provided by the current backend |
63 | * (i.e.: query_WildCards & query_IgnoreCase) | 70 | * (i.e.: query_WildCards & query_IgnoreCase) |
64 | */ | 71 | */ |
65 | virtual const uint querySettings() = 0; | 72 | virtual const uint querySettings() = 0; |
66 | 73 | ||
67 | /** Check whether settings are correct. | 74 | /** Check whether settings are correct. |
68 | * @return <i>true</i> if the given settings are correct and possible. | 75 | * @return <i>true</i> if the given settings are correct and possible. |
69 | */ | 76 | */ |
70 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 77 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
71 | 78 | ||
72 | 79 | ||
73 | }; | 80 | }; |
74 | #endif | 81 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 12a75ba..f7e8207 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -1,582 +1,602 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
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 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2002/11/01 15:10:42 eilers | ||
21 | * Added regExp-search in database for all fields in a contact. | ||
22 | * | ||
20 | * Revision 1.4 2002/10/16 10:52:40 eilers | 23 | * Revision 1.4 2002/10/16 10:52:40 eilers |
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
22 | * | 25 | * |
23 | * Revision 1.3 2002/10/14 16:21:54 eilers | 26 | * Revision 1.3 2002/10/14 16:21:54 eilers |
24 | * Some minor interface updates | 27 | * Some minor interface updates |
25 | * | 28 | * |
26 | * Revision 1.2 2002/10/07 17:34:24 eilers | 29 | * Revision 1.2 2002/10/07 17:34:24 eilers |
27 | * added OBackendFactory for advanced backend access | 30 | * added OBackendFactory for advanced backend access |
28 | * | 31 | * |
29 | * Revision 1.1 2002/09/27 17:11:44 eilers | 32 | * Revision 1.1 2002/09/27 17:11:44 eilers |
30 | * Added API for accessing the Contact-Database ! It is compiling, but | 33 | * Added API for accessing the Contact-Database ! It is compiling, but |
31 | * please do not expect that anything is working ! | 34 | * please do not expect that anything is working ! |
32 | * I will debug that stuff in the next time .. | 35 | * I will debug that stuff in the next time .. |
33 | * Please read README_COMPILE for compiling ! | 36 | * Please read README_COMPILE for compiling ! |
34 | * | 37 | * |
35 | * | 38 | * |
36 | */ | 39 | */ |
37 | 40 | ||
38 | #ifndef _OContactAccessBackend_XML_ | 41 | #ifndef _OContactAccessBackend_XML_ |
39 | #define _OContactAccessBackend_XML_ | 42 | #define _OContactAccessBackend_XML_ |
40 | 43 | ||
41 | #include <qasciidict.h> | 44 | #include <qasciidict.h> |
42 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
43 | #include <qfile.h> | 46 | #include <qfile.h> |
44 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
45 | #include <qregexp.h> | 48 | #include <qregexp.h> |
46 | #include <qarray.h> | 49 | #include <qarray.h> |
47 | 50 | ||
48 | #include <qpe/global.h> | 51 | #include <qpe/global.h> |
49 | 52 | ||
50 | #include <opie/xmltree.h> | 53 | #include <opie/xmltree.h> |
51 | #include "ocontactaccessbackend.h" | 54 | #include "ocontactaccessbackend.h" |
52 | #include "ocontactaccess.h" | 55 | #include "ocontactaccess.h" |
53 | 56 | ||
54 | #include <stdlib.h> | 57 | #include <stdlib.h> |
55 | #include <errno.h> | 58 | #include <errno.h> |
56 | 59 | ||
57 | using namespace Opie; | 60 | using namespace Opie; |
58 | 61 | ||
59 | /* the default xml implementation */ | 62 | /* the default xml implementation */ |
60 | class OContactAccessBackend_XML : public OContactAccessBackend { | 63 | class OContactAccessBackend_XML : public OContactAccessBackend { |
61 | public: | 64 | public: |
62 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 65 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
63 | m_changed( false ) | 66 | m_changed( false ) |
64 | { | 67 | { |
65 | m_appName = appname; | 68 | m_appName = appname; |
66 | 69 | ||
67 | /* Set journalfile name ... */ | 70 | /* Set journalfile name ... */ |
68 | m_journalName = getenv("HOME"); | 71 | m_journalName = getenv("HOME"); |
69 | m_journalName +="/.abjournal" + appname; | 72 | m_journalName +="/.abjournal" + appname; |
70 | 73 | ||
71 | /* Expecting to access the default filename if nothing else is set */ | 74 | /* Expecting to access the default filename if nothing else is set */ |
72 | if ( filename.isEmpty() ){ | 75 | if ( filename.isEmpty() ){ |
73 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 76 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
74 | } else | 77 | } else |
75 | m_fileName = filename; | 78 | m_fileName = filename; |
76 | 79 | ||
77 | /* Load Database now */ | 80 | /* Load Database now */ |
78 | load (); | 81 | load (); |
79 | } | 82 | } |
80 | 83 | ||
81 | bool save() { | 84 | bool save() { |
82 | 85 | ||
83 | if ( !m_changed ) | 86 | if ( !m_changed ) |
84 | return true; | 87 | return true; |
85 | 88 | ||
86 | QString strNewFile = m_fileName + ".new"; | 89 | QString strNewFile = m_fileName + ".new"; |
87 | QFile f( strNewFile ); | 90 | QFile f( strNewFile ); |
88 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 91 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
89 | return false; | 92 | return false; |
90 | 93 | ||
91 | int total_written; | 94 | int total_written; |
92 | QString out; | 95 | QString out; |
93 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 96 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
94 | " <Groups>\n" | 97 | " <Groups>\n" |
95 | " </Groups>\n" | 98 | " </Groups>\n" |
96 | " <Contacts>\n"; | 99 | " <Contacts>\n"; |
97 | //QValueList<Contact>::iterator it; | 100 | //QValueList<Contact>::iterator it; |
98 | QValueListConstIterator<OContact> it; | 101 | QValueListConstIterator<OContact> it; |
99 | for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) { | 102 | for ( it = m_contactList.begin(); it != m_contactList.end(); ++it ) { |
100 | out += "<Contact "; | 103 | out += "<Contact "; |
101 | (*it).save( out ); | 104 | (*it).save( out ); |
102 | out += "/>\n"; | 105 | out += "/>\n"; |
103 | QCString cstr = out.utf8(); | 106 | QCString cstr = out.utf8(); |
104 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 107 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
105 | if ( total_written != int(cstr.length()) ) { | 108 | if ( total_written != int(cstr.length()) ) { |
106 | f.close(); | 109 | f.close(); |
107 | QFile::remove( strNewFile ); | 110 | QFile::remove( strNewFile ); |
108 | return false; | 111 | return false; |
109 | } | 112 | } |
110 | out = ""; | 113 | out = ""; |
111 | } | 114 | } |
112 | out += " </Contacts>\n</AddressBook>\n"; | 115 | out += " </Contacts>\n</AddressBook>\n"; |
113 | 116 | ||
114 | QCString cstr = out.utf8(); | 117 | QCString cstr = out.utf8(); |
115 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 118 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
116 | if ( total_written != int( cstr.length() ) ) { | 119 | if ( total_written != int( cstr.length() ) ) { |
117 | f.close(); | 120 | f.close(); |
118 | QFile::remove( strNewFile ); | 121 | QFile::remove( strNewFile ); |
119 | return false; | 122 | return false; |
120 | } | 123 | } |
121 | f.close(); | 124 | f.close(); |
122 | 125 | ||
123 | // move the file over, I'm just going to use the system call | 126 | // move the file over, I'm just going to use the system call |
124 | // because, I don't feel like using QDir. | 127 | // because, I don't feel like using QDir. |
125 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 128 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
126 | qWarning( "problem renaming file %s to %s, errno: %d", | 129 | qWarning( "problem renaming file %s to %s, errno: %d", |
127 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 130 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
128 | // remove the tmp file... | 131 | // remove the tmp file... |
129 | QFile::remove( strNewFile ); | 132 | QFile::remove( strNewFile ); |
130 | } | 133 | } |
131 | 134 | ||
132 | /* The journalfile should be removed now... */ | 135 | /* The journalfile should be removed now... */ |
133 | removeJournal(); | 136 | removeJournal(); |
134 | 137 | ||
135 | m_changed = false; | 138 | m_changed = false; |
136 | return true; | 139 | return true; |
137 | } | 140 | } |
138 | 141 | ||
139 | bool load () { | 142 | bool load () { |
140 | m_contactList.clear(); | 143 | m_contactList.clear(); |
141 | 144 | ||
142 | /* Load XML-File and journal if it exists */ | 145 | /* Load XML-File and journal if it exists */ |
143 | if ( !load ( m_fileName, false ) ) | 146 | if ( !load ( m_fileName, false ) ) |
144 | return false; | 147 | return false; |
145 | /* The returncode of the journalfile is ignored due to the | 148 | /* The returncode of the journalfile is ignored due to the |
146 | * fact that it does not exist when this class is instantiated ! | 149 | * fact that it does not exist when this class is instantiated ! |
147 | * But there may such a file exist, if the application crashed. | 150 | * But there may such a file exist, if the application crashed. |
148 | * Therefore we try to load it to get the changes before the # | 151 | * Therefore we try to load it to get the changes before the # |
149 | * crash happened... | 152 | * crash happened... |
150 | */ | 153 | */ |
151 | load (m_journalName, true); | 154 | load (m_journalName, true); |
152 | 155 | ||
153 | return true; | 156 | return true; |
154 | } | 157 | } |
155 | 158 | ||
156 | void clear () { | 159 | void clear () { |
157 | m_contactList.clear(); | 160 | m_contactList.clear(); |
158 | m_changed = false; | 161 | m_changed = false; |
159 | 162 | ||
160 | } | 163 | } |
161 | 164 | ||
162 | bool wasChangedExternally() | 165 | bool wasChangedExternally() |
163 | { | 166 | { |
164 | QFileInfo fi( m_fileName ); | 167 | QFileInfo fi( m_fileName ); |
165 | 168 | ||
166 | QDateTime lastmod = fi.lastModified (); | 169 | QDateTime lastmod = fi.lastModified (); |
167 | 170 | ||
168 | return (lastmod != m_readtime); | 171 | return (lastmod != m_readtime); |
169 | } | 172 | } |
170 | 173 | ||
171 | QArray<int> allRecords() const { | 174 | QArray<int> allRecords() const { |
172 | QArray<int> uid_list( m_contactList.count() ); | 175 | QArray<int> uid_list( m_contactList.count() ); |
173 | 176 | ||
174 | uint counter = 0; | 177 | uint counter = 0; |
175 | QValueListConstIterator<OContact> it; | 178 | QValueListConstIterator<OContact> it; |
176 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 179 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
177 | uid_list[counter++] = (*it).uid(); | 180 | uid_list[counter++] = (*it).uid(); |
178 | } | 181 | } |
179 | 182 | ||
180 | return ( uid_list ); | 183 | return ( uid_list ); |
181 | } | 184 | } |
182 | 185 | ||
183 | OContact find ( int uid ) const | 186 | OContact find ( int uid ) const |
184 | { | 187 | { |
185 | bool found = false; | 188 | bool found = false; |
186 | OContact foundContact; //Create empty contact | 189 | OContact foundContact; //Create empty contact |
187 | 190 | ||
188 | QValueListConstIterator<OContact> it; | 191 | QValueListConstIterator<OContact> it; |
189 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 192 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
190 | if ((*it).uid() == uid){ | 193 | if ((*it).uid() == uid){ |
191 | found = true; | 194 | found = true; |
192 | break; | 195 | break; |
193 | } | 196 | } |
194 | } | 197 | } |
195 | if ( found ){ | 198 | if ( found ){ |
196 | foundContact = *it; | 199 | foundContact = *it; |
197 | } | 200 | } |
198 | 201 | ||
199 | return ( foundContact ); | 202 | return ( foundContact ); |
200 | } | 203 | } |
201 | 204 | ||
202 | QArray<int> queryByExample ( const OContact &query, int settings ){ | 205 | QArray<int> queryByExample ( const OContact &query, int settings ){ |
203 | 206 | ||
204 | QArray<int> m_currentQuery( m_contactList.count() ); | 207 | QArray<int> m_currentQuery( m_contactList.count() ); |
205 | QValueListConstIterator<OContact> it; | 208 | QValueListConstIterator<OContact> it; |
206 | uint arraycounter = 0; | 209 | uint arraycounter = 0; |
207 | 210 | ||
208 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 211 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
209 | /* Search all fields and compare them with query object. Store them into list | 212 | /* Search all fields and compare them with query object. Store them into list |
210 | * if all fields matches. | 213 | * if all fields matches. |
211 | */ | 214 | */ |
212 | bool allcorrect = true; | 215 | bool allcorrect = true; |
213 | for ( int i = 0; i < Qtopia::rid; i++ ) { | 216 | for ( int i = 0; i < Qtopia::rid; i++ ) { |
214 | /* Just compare fields which are not empty in the query object */ | 217 | /* Just compare fields which are not empty in the query object */ |
215 | if ( !query.field(i).isEmpty() ){ | 218 | if ( !query.field(i).isEmpty() ){ |
216 | switch ( settings & ~OContactAccess::IgnoreCase ){ | 219 | switch ( settings & ~OContactAccess::IgnoreCase ){ |
217 | case OContactAccess::RegExp:{ | 220 | case OContactAccess::RegExp:{ |
218 | QRegExp expr ( query.field(i), | 221 | QRegExp expr ( query.field(i), |
219 | !(settings & OContactAccess::IgnoreCase), | 222 | !(settings & OContactAccess::IgnoreCase), |
220 | false ); | 223 | false ); |
221 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 224 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) |
222 | allcorrect = false; | 225 | allcorrect = false; |
223 | } | 226 | } |
224 | break; | 227 | break; |
225 | case OContactAccess::WildCards:{ | 228 | case OContactAccess::WildCards:{ |
226 | QRegExp expr ( query.field(i), | 229 | QRegExp expr ( query.field(i), |
227 | !(settings & OContactAccess::IgnoreCase), | 230 | !(settings & OContactAccess::IgnoreCase), |
228 | true ); | 231 | true ); |
229 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) | 232 | if ( expr.find ( (*it).field(i), 0 ) == -1 ) |
230 | allcorrect = false; | 233 | allcorrect = false; |
231 | } | 234 | } |
232 | break; | 235 | break; |
233 | case OContactAccess::ExactMatch:{ | 236 | case OContactAccess::ExactMatch:{ |
234 | if (settings & OContactAccess::IgnoreCase){ | 237 | if (settings & OContactAccess::IgnoreCase){ |
235 | if ( query.field(i).upper() != | 238 | if ( query.field(i).upper() != |
236 | (*it).field(i).upper() ) | 239 | (*it).field(i).upper() ) |
237 | allcorrect = false; | 240 | allcorrect = false; |
238 | }else{ | 241 | }else{ |
239 | if ( query.field(i) != (*it).field(i) ) | 242 | if ( query.field(i) != (*it).field(i) ) |
240 | allcorrect = false; | 243 | allcorrect = false; |
241 | } | 244 | } |
242 | } | 245 | } |
243 | break; | 246 | break; |
244 | } | 247 | } |
245 | } | 248 | } |
246 | } | 249 | } |
247 | if ( allcorrect ){ | 250 | if ( allcorrect ){ |
248 | m_currentQuery[arraycounter++] = (*it).uid(); | 251 | m_currentQuery[arraycounter++] = (*it).uid(); |
249 | } | 252 | } |
250 | } | 253 | } |
251 | 254 | ||
252 | // Shrink to fit.. | 255 | // Shrink to fit.. |
253 | m_currentQuery.resize(arraycounter); | 256 | m_currentQuery.resize(arraycounter); |
254 | 257 | ||
255 | return m_currentQuery; | 258 | return m_currentQuery; |
256 | } | 259 | } |
260 | |||
261 | QArray<int> matchRegexp( const QRegExp &r ) const{ | ||
262 | QArray<int> m_currentQuery( m_contactList.count() ); | ||
263 | QValueListConstIterator<OContact> it; | ||
264 | uint arraycounter = 0; | ||
265 | |||
266 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | ||
267 | if ( (*it).match( r ) ){ | ||
268 | m_currentQuery[arraycounter++] = (*it).uid(); | ||
269 | } | ||
270 | |||
271 | } | ||
272 | // Shrink to fit.. | ||
273 | m_currentQuery.resize(arraycounter); | ||
274 | |||
275 | return m_currentQuery; | ||
276 | } | ||
257 | 277 | ||
258 | const uint querySettings() | 278 | const uint querySettings() |
259 | { | 279 | { |
260 | return ( OContactAccess::WildCards | 280 | return ( OContactAccess::WildCards |
261 | & OContactAccess::IgnoreCase | 281 | & OContactAccess::IgnoreCase |
262 | & OContactAccess::RegExp | 282 | & OContactAccess::RegExp |
263 | & OContactAccess::ExactMatch ); | 283 | & OContactAccess::ExactMatch ); |
264 | } | 284 | } |
265 | 285 | ||
266 | bool hasQuerySettings (uint querySettings) const | 286 | bool hasQuerySettings (uint querySettings) const |
267 | { | 287 | { |
268 | /* OContactAccess::IgnoreCase may be added with one | 288 | /* OContactAccess::IgnoreCase may be added with one |
269 | * of the other settings, but never used alone. | 289 | * of the other settings, but never used alone. |
270 | * The other settings are just valid alone... | 290 | * The other settings are just valid alone... |
271 | */ | 291 | */ |
272 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ | 292 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ |
273 | case OContactAccess::RegExp: | 293 | case OContactAccess::RegExp: |
274 | return ( true ); | 294 | return ( true ); |
275 | case OContactAccess::WildCards: | 295 | case OContactAccess::WildCards: |
276 | return ( true ); | 296 | return ( true ); |
277 | case OContactAccess::ExactMatch: | 297 | case OContactAccess::ExactMatch: |
278 | return ( true ); | 298 | return ( true ); |
279 | default: | 299 | default: |
280 | return ( false ); | 300 | return ( false ); |
281 | } | 301 | } |
282 | } | 302 | } |
283 | 303 | ||
284 | bool add ( const OContact &newcontact ) | 304 | bool add ( const OContact &newcontact ) |
285 | { | 305 | { |
286 | //qWarning("odefaultbackend: ACTION::ADD"); | 306 | //qWarning("odefaultbackend: ACTION::ADD"); |
287 | updateJournal (newcontact, OContact::ACTION_ADD); | 307 | updateJournal (newcontact, OContact::ACTION_ADD); |
288 | addContact_p( newcontact ); | 308 | addContact_p( newcontact ); |
289 | 309 | ||
290 | m_changed = true; | 310 | m_changed = true; |
291 | 311 | ||
292 | return true; | 312 | return true; |
293 | } | 313 | } |
294 | 314 | ||
295 | bool replace ( const OContact &contact ) | 315 | bool replace ( const OContact &contact ) |
296 | { | 316 | { |
297 | m_changed = true; | 317 | m_changed = true; |
298 | 318 | ||
299 | bool found = false; | 319 | bool found = false; |
300 | 320 | ||
301 | QValueListIterator<OContact> it; | 321 | QValueListIterator<OContact> it; |
302 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 322 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
303 | if ( (*it).uid() == contact.uid() ){ | 323 | if ( (*it).uid() == contact.uid() ){ |
304 | found = true; | 324 | found = true; |
305 | break; | 325 | break; |
306 | } | 326 | } |
307 | } | 327 | } |
308 | if (found) { | 328 | if (found) { |
309 | updateJournal (contact, OContact::ACTION_REPLACE); | 329 | updateJournal (contact, OContact::ACTION_REPLACE); |
310 | m_contactList.remove (it); | 330 | m_contactList.remove (it); |
311 | m_contactList.append (contact); | 331 | m_contactList.append (contact); |
312 | return true; | 332 | return true; |
313 | } else | 333 | } else |
314 | return false; | 334 | return false; |
315 | } | 335 | } |
316 | 336 | ||
317 | bool remove ( int uid ) | 337 | bool remove ( int uid ) |
318 | { | 338 | { |
319 | m_changed = true; | 339 | m_changed = true; |
320 | 340 | ||
321 | bool found = false; | 341 | bool found = false; |
322 | QValueListIterator<OContact> it; | 342 | QValueListIterator<OContact> it; |
323 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 343 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
324 | if ((*it).uid() == uid){ | 344 | if ((*it).uid() == uid){ |
325 | found = true; | 345 | found = true; |
326 | break; | 346 | break; |
327 | } | 347 | } |
328 | } | 348 | } |
329 | if (found) { | 349 | if (found) { |
330 | updateJournal ( *it, OContact::ACTION_REMOVE); | 350 | updateJournal ( *it, OContact::ACTION_REMOVE); |
331 | m_contactList.remove (it); | 351 | m_contactList.remove (it); |
332 | return true; | 352 | return true; |
333 | } else | 353 | } else |
334 | return false; | 354 | return false; |
335 | } | 355 | } |
336 | 356 | ||
337 | bool reload(){ | 357 | bool reload(){ |
338 | /* Reload is the same as load in this implementation */ | 358 | /* Reload is the same as load in this implementation */ |
339 | return ( load() ); | 359 | return ( load() ); |
340 | } | 360 | } |
341 | 361 | ||
342 | private: | 362 | private: |
343 | void addContact_p( const OContact &newcontact ){ | 363 | void addContact_p( const OContact &newcontact ){ |
344 | m_contactList.append (newcontact); | 364 | m_contactList.append (newcontact); |
345 | } | 365 | } |
346 | 366 | ||
347 | /* This function loads the xml-database and the journalfile */ | 367 | /* This function loads the xml-database and the journalfile */ |
348 | bool load( const QString filename, bool isJournal ) { | 368 | bool load( const QString filename, bool isJournal ) { |
349 | 369 | ||
350 | /* We use the time of the last read to check if the file was | 370 | /* We use the time of the last read to check if the file was |
351 | * changed externally. | 371 | * changed externally. |
352 | */ | 372 | */ |
353 | if ( !isJournal ){ | 373 | if ( !isJournal ){ |
354 | QFileInfo fi( filename ); | 374 | QFileInfo fi( filename ); |
355 | m_readtime = fi.lastModified (); | 375 | m_readtime = fi.lastModified (); |
356 | } | 376 | } |
357 | 377 | ||
358 | const int JOURNALACTION = Qtopia::Notes + 1; | 378 | const int JOURNALACTION = Qtopia::Notes + 1; |
359 | const int JOURNALROW = JOURNALACTION + 1; | 379 | const int JOURNALROW = JOURNALACTION + 1; |
360 | 380 | ||
361 | bool foundAction = false; | 381 | bool foundAction = false; |
362 | OContact::journal_action action = OContact::ACTION_ADD; | 382 | OContact::journal_action action = OContact::ACTION_ADD; |
363 | int journalKey = 0; | 383 | int journalKey = 0; |
364 | QMap<int, QString> contactMap; | 384 | QMap<int, QString> contactMap; |
365 | QMap<QString, QString> customMap; | 385 | QMap<QString, QString> customMap; |
366 | QMap<QString, QString>::Iterator customIt; | 386 | QMap<QString, QString>::Iterator customIt; |
367 | QAsciiDict<int> dict( 47 ); | 387 | QAsciiDict<int> dict( 47 ); |
368 | 388 | ||
369 | dict.setAutoDelete( TRUE ); | 389 | dict.setAutoDelete( TRUE ); |
370 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 390 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
371 | dict.insert( "Title", new int(Qtopia::Title) ); | 391 | dict.insert( "Title", new int(Qtopia::Title) ); |
372 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 392 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
373 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 393 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
374 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 394 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
375 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 395 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
376 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 396 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
377 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 397 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
378 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 398 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
379 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 399 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
380 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 400 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
381 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 401 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
382 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 402 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
383 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 403 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
384 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 404 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
385 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 405 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
386 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 406 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
387 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 407 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
388 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 408 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
389 | dict.insert( "Company", new int(Qtopia::Company) ); | 409 | dict.insert( "Company", new int(Qtopia::Company) ); |
390 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 410 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
391 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 411 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
392 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 412 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
393 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 413 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
394 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 414 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
395 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 415 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
396 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 416 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
397 | dict.insert( "Department", new int(Qtopia::Department) ); | 417 | dict.insert( "Department", new int(Qtopia::Department) ); |
398 | dict.insert( "Office", new int(Qtopia::Office) ); | 418 | dict.insert( "Office", new int(Qtopia::Office) ); |
399 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 419 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
400 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 420 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
401 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 421 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
402 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 422 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
403 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 423 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
404 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 424 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
405 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 425 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
406 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 426 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
407 | dict.insert( "Children", new int(Qtopia::Children) ); | 427 | dict.insert( "Children", new int(Qtopia::Children) ); |
408 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 428 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
409 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 429 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
410 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 430 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
411 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 431 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
412 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 432 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
413 | dict.insert( "action", new int(JOURNALACTION) ); | 433 | dict.insert( "action", new int(JOURNALACTION) ); |
414 | dict.insert( "actionrow", new int(JOURNALROW) ); | 434 | dict.insert( "actionrow", new int(JOURNALROW) ); |
415 | 435 | ||
416 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 436 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
417 | 437 | ||
418 | XMLElement *root = XMLElement::load( filename ); | 438 | XMLElement *root = XMLElement::load( filename ); |
419 | if(root != 0l ){ // start parsing | 439 | if(root != 0l ){ // start parsing |
420 | /* Parse all XML-Elements and put the data into the | 440 | /* Parse all XML-Elements and put the data into the |
421 | * Contact-Class | 441 | * Contact-Class |
422 | */ | 442 | */ |
423 | XMLElement *element = root->firstChild(); | 443 | XMLElement *element = root->firstChild(); |
424 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 444 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
425 | element = element->firstChild(); | 445 | element = element->firstChild(); |
426 | 446 | ||
427 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 447 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
428 | while( element && !isJournal ){ | 448 | while( element && !isJournal ){ |
429 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 449 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
430 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 450 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
431 | // element->tagName().latin1()); | 451 | // element->tagName().latin1()); |
432 | element = element->nextChild(); | 452 | element = element->nextChild(); |
433 | } else { | 453 | } else { |
434 | element = element->firstChild(); | 454 | element = element->firstChild(); |
435 | break; | 455 | break; |
436 | } | 456 | } |
437 | } | 457 | } |
438 | /* Parse all Contacts and ignore unknown tags */ | 458 | /* Parse all Contacts and ignore unknown tags */ |
439 | while( element ){ | 459 | while( element ){ |
440 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 460 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
441 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 461 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
442 | // element->tagName().latin1()); | 462 | // element->tagName().latin1()); |
443 | element = element->nextChild(); | 463 | element = element->nextChild(); |
444 | continue; | 464 | continue; |
445 | } | 465 | } |
446 | /* Found alement with tagname "contact", now parse and store all | 466 | /* Found alement with tagname "contact", now parse and store all |
447 | * attributes contained | 467 | * attributes contained |
448 | */ | 468 | */ |
449 | //qWarning("OContactDefBack::load element tagName() : %s", | 469 | //qWarning("OContactDefBack::load element tagName() : %s", |
450 | // element->tagName().latin1() ); | 470 | // element->tagName().latin1() ); |
451 | QString dummy; | 471 | QString dummy; |
452 | foundAction = false; | 472 | foundAction = false; |
453 | 473 | ||
454 | XMLElement::AttributeMap aMap = element->attributes(); | 474 | XMLElement::AttributeMap aMap = element->attributes(); |
455 | XMLElement::AttributeMap::Iterator it; | 475 | XMLElement::AttributeMap::Iterator it; |
456 | contactMap.clear(); | 476 | contactMap.clear(); |
457 | customMap.clear(); | 477 | customMap.clear(); |
458 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 478 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
459 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 479 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
460 | 480 | ||
461 | int *find = dict[ it.key() ]; | 481 | int *find = dict[ it.key() ]; |
462 | /* Unknown attributes will be stored as "Custom" elements */ | 482 | /* Unknown attributes will be stored as "Custom" elements */ |
463 | if ( !find ) { | 483 | if ( !find ) { |
464 | qWarning("Attribute %s not known.", it.key().latin1()); | 484 | qWarning("Attribute %s not known.", it.key().latin1()); |
465 | //contact.setCustomField(it.key(), it.data()); | 485 | //contact.setCustomField(it.key(), it.data()); |
466 | customMap.insert( it.key(), it.data() ); | 486 | customMap.insert( it.key(), it.data() ); |
467 | continue; | 487 | continue; |
468 | } | 488 | } |
469 | 489 | ||
470 | /* Check if special conversion is needed and add attribute | 490 | /* Check if special conversion is needed and add attribute |
471 | * into Contact class | 491 | * into Contact class |
472 | */ | 492 | */ |
473 | switch( *find ) { | 493 | switch( *find ) { |
474 | /* | 494 | /* |
475 | case Qtopia::AddressUid: | 495 | case Qtopia::AddressUid: |
476 | contact.setUid( it.data().toInt() ); | 496 | contact.setUid( it.data().toInt() ); |
477 | break; | 497 | break; |
478 | case Qtopia::AddressCategory: | 498 | case Qtopia::AddressCategory: |
479 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 499 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
480 | break; | 500 | break; |
481 | */ | 501 | */ |
482 | case JOURNALACTION: | 502 | case JOURNALACTION: |
483 | action = OContact::journal_action(it.data().toInt()); | 503 | action = OContact::journal_action(it.data().toInt()); |
484 | foundAction = true; | 504 | foundAction = true; |
485 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 505 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
486 | break; | 506 | break; |
487 | case JOURNALROW: | 507 | case JOURNALROW: |
488 | journalKey = it.data().toInt(); | 508 | journalKey = it.data().toInt(); |
489 | break; | 509 | break; |
490 | default: // no conversion needed add them to the map | 510 | default: // no conversion needed add them to the map |
491 | contactMap.insert( *find, it.data() ); | 511 | contactMap.insert( *find, it.data() ); |
492 | break; | 512 | break; |
493 | } | 513 | } |
494 | } | 514 | } |
495 | /* now generate the Contact contact */ | 515 | /* now generate the Contact contact */ |
496 | OContact contact( contactMap ); | 516 | OContact contact( contactMap ); |
497 | 517 | ||
498 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 518 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
499 | contact.setCustomField( customIt.key(), customIt.data() ); | 519 | contact.setCustomField( customIt.key(), customIt.data() ); |
500 | } | 520 | } |
501 | 521 | ||
502 | if (foundAction){ | 522 | if (foundAction){ |
503 | foundAction = false; | 523 | foundAction = false; |
504 | switch ( action ) { | 524 | switch ( action ) { |
505 | case OContact::ACTION_ADD: | 525 | case OContact::ACTION_ADD: |
506 | addContact_p (contact); | 526 | addContact_p (contact); |
507 | break; | 527 | break; |
508 | case OContact::ACTION_REMOVE: | 528 | case OContact::ACTION_REMOVE: |
509 | if ( !remove (contact.uid()) ) | 529 | if ( !remove (contact.uid()) ) |
510 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 530 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
511 | contact.uid() ); | 531 | contact.uid() ); |
512 | break; | 532 | break; |
513 | case OContact::ACTION_REPLACE: | 533 | case OContact::ACTION_REPLACE: |
514 | if ( !replace ( contact ) ) | 534 | if ( !replace ( contact ) ) |
515 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 535 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
516 | contact.uid() ); | 536 | contact.uid() ); |
517 | break; | 537 | break; |
518 | default: | 538 | default: |
519 | qWarning ("Unknown action: ignored !"); | 539 | qWarning ("Unknown action: ignored !"); |
520 | break; | 540 | break; |
521 | } | 541 | } |
522 | }else{ | 542 | }else{ |
523 | /* Add contact to list */ | 543 | /* Add contact to list */ |
524 | addContact_p (contact); | 544 | addContact_p (contact); |
525 | } | 545 | } |
526 | 546 | ||
527 | /* Move to next element */ | 547 | /* Move to next element */ |
528 | element = element->nextChild(); | 548 | element = element->nextChild(); |
529 | } | 549 | } |
530 | }else { | 550 | }else { |
531 | qWarning("ODefBack::could not load"); | 551 | qWarning("ODefBack::could not load"); |
532 | } | 552 | } |
533 | delete root; | 553 | delete root; |
534 | qWarning("returning from loading" ); | 554 | qWarning("returning from loading" ); |
535 | return true; | 555 | return true; |
536 | } | 556 | } |
537 | 557 | ||
538 | 558 | ||
539 | void updateJournal( const OContact& cnt, | 559 | void updateJournal( const OContact& cnt, |
540 | OContact::journal_action action ) { | 560 | OContact::journal_action action ) { |
541 | QFile f( m_journalName ); | 561 | QFile f( m_journalName ); |
542 | bool created = !f.exists(); | 562 | bool created = !f.exists(); |
543 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 563 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
544 | return; | 564 | return; |
545 | 565 | ||
546 | QString buf; | 566 | QString buf; |
547 | QCString str; | 567 | QCString str; |
548 | 568 | ||
549 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 569 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
550 | // get a XML-File which is readable by our parser. | 570 | // get a XML-File which is readable by our parser. |
551 | // This is just a cheat, but better than rewrite the parser. | 571 | // This is just a cheat, but better than rewrite the parser. |
552 | if ( created ){ | 572 | if ( created ){ |
553 | buf = "<Contacts>"; | 573 | buf = "<Contacts>"; |
554 | QCString cstr = buf.utf8(); | 574 | QCString cstr = buf.utf8(); |
555 | f.writeBlock( cstr.data(), cstr.length() ); | 575 | f.writeBlock( cstr.data(), cstr.length() ); |
556 | } | 576 | } |
557 | 577 | ||
558 | buf = "<Contact "; | 578 | buf = "<Contact "; |
559 | cnt.save( buf ); | 579 | cnt.save( buf ); |
560 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 580 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
561 | buf += "/>\n"; | 581 | buf += "/>\n"; |
562 | QCString cstr = buf.utf8(); | 582 | QCString cstr = buf.utf8(); |
563 | f.writeBlock( cstr.data(), cstr.length() ); | 583 | f.writeBlock( cstr.data(), cstr.length() ); |
564 | } | 584 | } |
565 | 585 | ||
566 | void removeJournal() | 586 | void removeJournal() |
567 | { | 587 | { |
568 | QFile f ( m_journalName ); | 588 | QFile f ( m_journalName ); |
569 | if ( f.exists() ) | 589 | if ( f.exists() ) |
570 | f.remove(); | 590 | f.remove(); |
571 | } | 591 | } |
572 | 592 | ||
573 | protected: | 593 | protected: |
574 | bool m_changed; | 594 | bool m_changed; |
575 | QString m_journalName; | 595 | QString m_journalName; |
576 | QString m_fileName; | 596 | QString m_fileName; |
577 | QString m_appName; | 597 | QString m_appName; |
578 | QValueList<OContact> m_contactList; | 598 | QValueList<OContact> m_contactList; |
579 | QDateTime m_readtime; | 599 | QDateTime m_readtime; |
580 | }; | 600 | }; |
581 | 601 | ||
582 | #endif | 602 | #endif |
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 2ca0283..f868b53 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -1,153 +1,161 @@ | |||
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.6 2002/11/01 15:10:42 eilers | ||
25 | * Added regExp-search in database for all fields in a contact. | ||
26 | * | ||
24 | * Revision 1.5 2002/10/16 10:52:40 eilers | 27 | * Revision 1.5 2002/10/16 10:52:40 eilers |
25 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 28 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
26 | * | 29 | * |
27 | * Revision 1.4 2002/10/14 16:21:54 eilers | 30 | * Revision 1.4 2002/10/14 16:21:54 eilers |
28 | * Some minor interface updates | 31 | * Some minor interface updates |
29 | * | 32 | * |
30 | * Revision 1.3 2002/10/07 17:34:24 eilers | 33 | * Revision 1.3 2002/10/07 17:34:24 eilers |
31 | * added OBackendFactory for advanced backend access | 34 | * added OBackendFactory for advanced backend access |
32 | * | 35 | * |
33 | * Revision 1.2 2002/10/02 16:18:11 eilers | 36 | * Revision 1.2 2002/10/02 16:18:11 eilers |
34 | * debugged and seems to work almost perfectly .. | 37 | * debugged and seems to work almost perfectly .. |
35 | * | 38 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 39 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 40 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 41 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 42 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 43 | * Please read README_COMPILE for compiling ! |
41 | * | 44 | * |
42 | * | 45 | * |
43 | */ | 46 | */ |
44 | 47 | ||
45 | #include "ocontactaccess.h" | 48 | #include "ocontactaccess.h" |
46 | #include "obackendfactory.h" | 49 | #include "obackendfactory.h" |
47 | 50 | ||
48 | #include <qasciidict.h> | 51 | #include <qasciidict.h> |
49 | #include <qdatetime.h> | 52 | #include <qdatetime.h> |
50 | #include <qfile.h> | 53 | #include <qfile.h> |
51 | #include <qregexp.h> | 54 | #include <qregexp.h> |
52 | #include <qlist.h> | 55 | #include <qlist.h> |
53 | #include <qcopchannel_qws.h> | 56 | #include <qcopchannel_qws.h> |
54 | 57 | ||
55 | //#include <qpe/qcopenvelope_qws.h> | 58 | //#include <qpe/qcopenvelope_qws.h> |
56 | #include <qpe/global.h> | 59 | #include <qpe/global.h> |
57 | 60 | ||
58 | #include <errno.h> | 61 | #include <errno.h> |
59 | #include <fcntl.h> | 62 | #include <fcntl.h> |
60 | #include <unistd.h> | 63 | #include <unistd.h> |
61 | #include <stdlib.h> | 64 | #include <stdlib.h> |
62 | 65 | ||
63 | #include "ocontactaccessbackend_xml.h" | 66 | #include "ocontactaccessbackend_xml.h" |
64 | 67 | ||
65 | 68 | ||
66 | OContactAccess::OContactAccess ( const QString appname, const QString , | 69 | OContactAccess::OContactAccess ( const QString appname, const QString , |
67 | OContactAccessBackend* end, bool autosync ): | 70 | OContactAccessBackend* end, bool autosync ): |
68 | OPimAccessTemplate<OContact>( end ) | 71 | OPimAccessTemplate<OContact>( end ) |
69 | { | 72 | { |
70 | /* take care of the backend. If there is no one defined, we | 73 | /* take care of the backend. If there is no one defined, we |
71 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 74 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
72 | */ | 75 | */ |
73 | if( end == 0 ) { | 76 | if( end == 0 ) { |
74 | qWarning ("Using BackendFactory !"); | 77 | qWarning ("Using BackendFactory !"); |
75 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | 78 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); |
76 | } | 79 | } |
77 | // Set backend locally and in template | 80 | // Set backend locally and in template |
78 | m_backEnd = end; | 81 | m_backEnd = end; |
79 | OPimAccessTemplate<OContact>::setBackEnd (end); | 82 | OPimAccessTemplate<OContact>::setBackEnd (end); |
80 | 83 | ||
81 | 84 | ||
82 | /* Connect signal of external db change to function */ | 85 | /* Connect signal of external db change to function */ |
83 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | 86 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); |
84 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 87 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
85 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 88 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
86 | if ( autosync ){ | 89 | if ( autosync ){ |
87 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | 90 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); |
88 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 91 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
89 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 92 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
90 | } | 93 | } |
91 | 94 | ||
92 | 95 | ||
93 | } | 96 | } |
94 | OContactAccess::~OContactAccess () | 97 | OContactAccess::~OContactAccess () |
95 | { | 98 | { |
96 | /* The user may forget to save the changed database, therefore try to | 99 | /* The user may forget to save the changed database, therefore try to |
97 | * do it for him.. | 100 | * do it for him.. |
98 | */ | 101 | */ |
99 | save(); | 102 | save(); |
100 | // delete m_backEnd; is done by template.. | 103 | // delete m_backEnd; is done by template.. |
101 | } | 104 | } |
102 | 105 | ||
103 | 106 | ||
104 | bool OContactAccess::save () | 107 | bool OContactAccess::save () |
105 | { | 108 | { |
106 | /* If the database was changed externally, we could not save the | 109 | /* If the database was changed externally, we could not save the |
107 | * Data. This will remove added items which is unacceptable ! | 110 | * Data. This will remove added items which is unacceptable ! |
108 | * Therefore: Reload database and merge the data... | 111 | * Therefore: Reload database and merge the data... |
109 | */ | 112 | */ |
110 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | 113 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
111 | reload(); | 114 | reload(); |
112 | 115 | ||
113 | bool status = OPimAccessTemplate<OContact>::save(); | 116 | bool status = OPimAccessTemplate<OContact>::save(); |
114 | if ( !status ) return false; | 117 | if ( !status ) return false; |
115 | 118 | ||
116 | /* Now tell everyone that new data is available. | 119 | /* Now tell everyone that new data is available. |
117 | */ | 120 | */ |
118 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 121 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
119 | 122 | ||
120 | return true; | 123 | return true; |
121 | } | 124 | } |
122 | 125 | ||
126 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ | ||
127 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); | ||
128 | return ( ORecordList<OContact>(matchingContacts, this) ); | ||
129 | } | ||
130 | |||
123 | const uint OContactAccess::querySettings() | 131 | const uint OContactAccess::querySettings() |
124 | { | 132 | { |
125 | return ( m_backEnd->querySettings() ); | 133 | return ( m_backEnd->querySettings() ); |
126 | } | 134 | } |
127 | 135 | ||
128 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 136 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
129 | { | 137 | { |
130 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 138 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
131 | } | 139 | } |
132 | 140 | ||
133 | 141 | ||
134 | bool OContactAccess::wasChangedExternally()const | 142 | bool OContactAccess::wasChangedExternally()const |
135 | { | 143 | { |
136 | return ( m_backEnd->wasChangedExternally() ); | 144 | return ( m_backEnd->wasChangedExternally() ); |
137 | } | 145 | } |
138 | 146 | ||
139 | 147 | ||
140 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 148 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
141 | { | 149 | { |
142 | if ( msg == "addressbookUpdated()" ){ | 150 | if ( msg == "addressbookUpdated()" ){ |
143 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 151 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
144 | emit signalChanged ( this ); | 152 | emit signalChanged ( this ); |
145 | } else if ( msg == "flush()" ) { | 153 | } else if ( msg == "flush()" ) { |
146 | qWarning ("OContactAccess: Received flush()"); | 154 | qWarning ("OContactAccess: Received flush()"); |
147 | save (); | 155 | save (); |
148 | } else if ( msg == "reload()" ) { | 156 | } else if ( msg == "reload()" ) { |
149 | qWarning ("OContactAccess: Received reload()"); | 157 | qWarning ("OContactAccess: Received reload()"); |
150 | reload (); | 158 | reload (); |
151 | emit signalChanged ( this ); | 159 | emit signalChanged ( this ); |
152 | } | 160 | } |
153 | } | 161 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index da9c942..b4921d5 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,131 +1,139 @@ | |||
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 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.4 2002/11/01 15:10:42 eilers | ||
21 | * Added regExp-search in database for all fields in a contact. | ||
22 | * | ||
20 | * Revision 1.3 2002/10/16 10:52:40 eilers | 23 | * Revision 1.3 2002/10/16 10:52:40 eilers |
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
22 | * | 25 | * |
23 | * Revision 1.2 2002/10/14 16:21:54 eilers | 26 | * Revision 1.2 2002/10/14 16:21:54 eilers |
24 | * Some minor interface updates | 27 | * Some minor interface updates |
25 | * | 28 | * |
26 | * Revision 1.1 2002/09/27 17:11:44 eilers | 29 | * Revision 1.1 2002/09/27 17:11:44 eilers |
27 | * Added API for accessing the Contact-Database ! It is compiling, but | 30 | * Added API for accessing the Contact-Database ! It is compiling, but |
28 | * please do not expect that anything is working ! | 31 | * please do not expect that anything is working ! |
29 | * I will debug that stuff in the next time .. | 32 | * I will debug that stuff in the next time .. |
30 | * Please read README_COMPILE for compiling ! | 33 | * Please read README_COMPILE for compiling ! |
31 | * | 34 | * |
32 | * ===================================================================== | 35 | * ===================================================================== |
33 | */ | 36 | */ |
34 | #ifndef _OCONTACTACCESS_H | 37 | #ifndef _OCONTACTACCESS_H |
35 | #define _OCONTACTACCESS_H | 38 | #define _OCONTACTACCESS_H |
36 | 39 | ||
37 | #include <qobject.h> | 40 | #include <qobject.h> |
38 | 41 | ||
39 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
40 | 43 | ||
41 | #include <qvaluelist.h> | 44 | #include <qvaluelist.h> |
42 | #include <qfileinfo.h> | 45 | #include <qfileinfo.h> |
43 | 46 | ||
44 | #include "ocontact.h" | 47 | #include "ocontact.h" |
45 | #include "ocontactaccessbackend.h" | 48 | #include "ocontactaccessbackend.h" |
46 | #include "opimaccesstemplate.h" | 49 | #include "opimaccesstemplate.h" |
47 | 50 | ||
48 | /** Class to access the contacts database. | 51 | /** Class to access the contacts database. |
49 | * This is just a frontend for the real database handling which is | 52 | * This is just a frontend for the real database handling which is |
50 | * done by the backend. | 53 | * done by the backend. |
54 | * @see OPimAccessTemplate | ||
51 | */ | 55 | */ |
52 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 56 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
53 | { | 57 | { |
54 | Q_OBJECT | 58 | Q_OBJECT |
55 | 59 | ||
56 | public: | 60 | public: |
57 | /** Create Database with contacts (addressbook). | 61 | /** Create Database with contacts (addressbook). |
58 | * @param appname Name of application which wants access to the database | 62 | * @param appname Name of application which wants access to the database |
59 | * (i.e. "todolist") | 63 | * (i.e. "todolist") |
60 | * @param filename The name of the database file. If not set, the default one | 64 | * @param filename The name of the database file. If not set, the default one |
61 | * is used. | 65 | * is used. |
62 | * @param backend Pointer to an alternative Backend. If not set, we will use | 66 | * @param backend Pointer to an alternative Backend. If not set, we will use |
63 | * the default backend. | 67 | * the default backend. |
64 | * @param handlesync If <b>true</b> the database stores the current state | 68 | * @param handlesync If <b>true</b> the database stores the current state |
65 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 69 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
66 | * which are used before and after synchronisation. If the application wants | 70 | * which are used before and after synchronisation. If the application wants |
67 | * to react itself, it should be disabled by setting it to <b>false</b> | 71 | * to react itself, it should be disabled by setting it to <b>false</b> |
68 | * @see OContactAccessBackend | 72 | * @see OContactAccessBackend |
69 | */ | 73 | */ |
70 | OContactAccess (const QString appname, const QString filename = 0l, | 74 | OContactAccess (const QString appname, const QString filename = 0l, |
71 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 75 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
72 | ~OContactAccess (); | 76 | ~OContactAccess (); |
73 | 77 | ||
74 | /** Constants for query. | 78 | /** Constants for query. |
75 | * Use this constants to set the query parameters. | 79 | * Use this constants to set the query parameters. |
76 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 80 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
77 | * @see queryByExample() | 81 | * @see queryByExample() |
78 | */ | 82 | */ |
79 | enum QuerySettings { | 83 | enum QuerySettings { |
80 | WildCards = 0x0001, | 84 | WildCards = 0x0001, |
81 | IgnoreCase = 0x0002, | 85 | IgnoreCase = 0x0002, |
82 | RegExp = 0x0004, | 86 | RegExp = 0x0004, |
83 | ExactMatch = 0x0008, | 87 | ExactMatch = 0x0008, |
88 | MatchOne = 0x0010 // Only one Entry must match | ||
84 | }; | 89 | }; |
85 | 90 | ||
91 | |||
92 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | ||
93 | |||
86 | /** Return all possible settings. | 94 | /** Return all possible settings. |
87 | * @return All settings provided by the current backend | 95 | * @return All settings provided by the current backend |
88 | * (i.e.: query_WildCards & query_IgnoreCase) | 96 | * (i.e.: query_WildCards & query_IgnoreCase) |
89 | */ | 97 | */ |
90 | const uint querySettings(); | 98 | const uint querySettings(); |
91 | 99 | ||
92 | /** Check whether settings are correct. | 100 | /** Check whether settings are correct. |
93 | * @return <i>true</i> if the given settings are correct and possible. | 101 | * @return <i>true</i> if the given settings are correct and possible. |
94 | */ | 102 | */ |
95 | bool hasQuerySettings ( int querySettings ) const; | 103 | bool hasQuerySettings ( int querySettings ) const; |
96 | 104 | ||
97 | /** | 105 | /** |
98 | * if the resource was changed externally. | 106 | * if the resource was changed externally. |
99 | * You should use the signal instead of polling possible changes ! | 107 | * You should use the signal instead of polling possible changes ! |
100 | */ | 108 | */ |
101 | bool wasChangedExternally()const; | 109 | bool wasChangedExternally()const; |
102 | 110 | ||
103 | 111 | ||
104 | /** Save contacts database. | 112 | /** Save contacts database. |
105 | * Save is more a "commit". After calling this function, all changes are public available. | 113 | * Save is more a "commit". After calling this function, all changes are public available. |
106 | * @return true if successful | 114 | * @return true if successful |
107 | */ | 115 | */ |
108 | bool save(); | 116 | bool save(); |
109 | 117 | ||
110 | signals: | 118 | signals: |
111 | /* Signal is emitted if the database was changed. Therefore | 119 | /* Signal is emitted if the database was changed. Therefore |
112 | * we may need to reload to stay consistent. | 120 | * we may need to reload to stay consistent. |
113 | * @param which Pointer to the database who created this event. This pointer | 121 | * @param which Pointer to the database who created this event. This pointer |
114 | * is useful if an application has to handle multiple databases at the same time. | 122 | * is useful if an application has to handle multiple databases at the same time. |
115 | * @see reload() | 123 | * @see reload() |
116 | */ | 124 | */ |
117 | void signalChanged ( const OContactAccess *which ); | 125 | void signalChanged ( const OContactAccess *which ); |
118 | 126 | ||
119 | 127 | ||
120 | private: | 128 | private: |
121 | // class OContactAccessPrivate; | 129 | // class OContactAccessPrivate; |
122 | // OContactAccessPrivate* d; | 130 | // OContactAccessPrivate* d; |
123 | OContactAccessBackend *m_backEnd; | 131 | OContactAccessBackend *m_backEnd; |
124 | bool m_loading:1; | 132 | bool m_loading:1; |
125 | 133 | ||
126 | private slots: | 134 | private slots: |
127 | void copMessage( const QCString &msg, const QByteArray &data ); | 135 | void copMessage( const QCString &msg, const QByteArray &data ); |
128 | 136 | ||
129 | 137 | ||
130 | }; | 138 | }; |
131 | #endif | 139 | #endif |
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index 382ab94..038a59f 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h | |||
@@ -1,246 +1,242 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Qtopia Environment. | 5 | ** This file is part of the Qtopia Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef __OCONTACT_H__ | 22 | #ifndef __OCONTACT_H__ |
23 | #define __OCONTACT_H__ | 23 | #define __OCONTACT_H__ |
24 | 24 | ||
25 | #include <opie/opimrecord.h> | 25 | #include <opie/opimrecord.h> |
26 | #include <qpe/recordfields.h> | 26 | #include <qpe/recordfields.h> |
27 | 27 | ||
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | 30 | ||
31 | #if defined(QPC_TEMPLATEDLL) | 31 | #if defined(QPC_TEMPLATEDLL) |
32 | // MOC_SKIP_BEGIN | 32 | // MOC_SKIP_BEGIN |
33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
34 | // MOC_SKIP_END | 34 | // MOC_SKIP_END |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) | 37 | class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) |
38 | class QPC_EXPORT OContact : public OPimRecord | 38 | class QPC_EXPORT OContact : public OPimRecord |
39 | { | 39 | { |
40 | friend class DataSet; | 40 | friend class DataSet; |
41 | public: | 41 | public: |
42 | OContact(); | 42 | OContact(); |
43 | OContact( const QMap<int, QString> &fromMap ); | 43 | OContact( const QMap<int, QString> &fromMap ); |
44 | virtual ~OContact(); | 44 | virtual ~OContact(); |
45 | 45 | ||
46 | static void writeVCard( const QString &filename, const QValueList<OContact> &contacts); | 46 | static void writeVCard( const QString &filename, const QValueList<OContact> &contacts); |
47 | static void writeVCard( const QString &filename, const OContact &c ); | 47 | static void writeVCard( const QString &filename, const OContact &c ); |
48 | static QValueList<OContact> readVCard( const QString &filename ); | 48 | static QValueList<OContact> readVCard( const QString &filename ); |
49 | 49 | ||
50 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 50 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
51 | 51 | ||
52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
58 | void setFileAs(); | 58 | void setFileAs(); |
59 | 59 | ||
60 | // default email address | 60 | // default email address |
61 | void setDefaultEmail( const QString &v ); | 61 | void setDefaultEmail( const QString &v ); |
62 | // inserts email to list and ensure's doesn't already exist | 62 | // inserts email to list and ensure's doesn't already exist |
63 | void insertEmail( const QString &v ); | 63 | void insertEmail( const QString &v ); |
64 | void removeEmail( const QString &v ); | 64 | void removeEmail( const QString &v ); |
65 | void clearEmails(); | 65 | void clearEmails(); |
66 | void insertEmails( const QStringList &v ); | 66 | void insertEmails( const QStringList &v ); |
67 | 67 | ||
68 | // home | 68 | // home |
69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
78 | 78 | ||
79 | // business | 79 | // business |
80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
87 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 87 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
88 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 88 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
89 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 89 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
90 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 90 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
91 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } | 91 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } |
92 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } | 92 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } |
93 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } | 93 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } |
94 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } | 94 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } |
95 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } | 95 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } |
96 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } | 96 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } |
97 | 97 | ||
98 | // personal | 98 | // personal |
99 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } | 99 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } |
100 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } | 100 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } |
101 | void setBirthday( const QDate &v ); | 101 | void setBirthday( const QDate &v ); |
102 | void setAnniversary( const QDate &v ); | 102 | void setAnniversary( const QDate &v ); |
103 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } | 103 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } |
104 | void setChildren( const QString &v ); | 104 | void setChildren( const QString &v ); |
105 | 105 | ||
106 | // other | 106 | // other |
107 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 107 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
108 | 108 | ||
109 | bool match( const QString ®exp ) const; | 109 | bool match( const QString ®exp ) const; |
110 | |||
111 | // DON'T ATTEMPT TO USE THIS | ||
112 | #ifdef QTOPIA_INTERNAL_CONTACT_MRE | ||
113 | bool match( const QRegExp ®exp ) const; | 110 | bool match( const QRegExp ®exp ) const; |
114 | #endif | ||
115 | 111 | ||
116 | // // custom | 112 | // // custom |
117 | // void setCustomField( const QString &key, const QString &v ) | 113 | // void setCustomField( const QString &key, const QString &v ) |
118 | // { replace(Custom- + key, v ); } | 114 | // { replace(Custom- + key, v ); } |
119 | 115 | ||
120 | // name | 116 | // name |
121 | QString fullName() const; | 117 | QString fullName() const; |
122 | QString title() const { return find( Qtopia::Title ); } | 118 | QString title() const { return find( Qtopia::Title ); } |
123 | QString firstName() const { return find( Qtopia::FirstName ); } | 119 | QString firstName() const { return find( Qtopia::FirstName ); } |
124 | QString middleName() const { return find( Qtopia::MiddleName ); } | 120 | QString middleName() const { return find( Qtopia::MiddleName ); } |
125 | QString lastName() const { return find( Qtopia::LastName ); } | 121 | QString lastName() const { return find( Qtopia::LastName ); } |
126 | QString suffix() const { return find( Qtopia::Suffix ); } | 122 | QString suffix() const { return find( Qtopia::Suffix ); } |
127 | QString fileAs() const { return find( Qtopia::FileAs ); } | 123 | QString fileAs() const { return find( Qtopia::FileAs ); } |
128 | 124 | ||
129 | 125 | ||
130 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 126 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
131 | QStringList emailList() const; | 127 | QStringList emailList() const; |
132 | 128 | ||
133 | // home | 129 | // home |
134 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 130 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
135 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 131 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
136 | QString homeState() const { return find( Qtopia::HomeState ); } | 132 | QString homeState() const { return find( Qtopia::HomeState ); } |
137 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 133 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
138 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 134 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
139 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 135 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
140 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 136 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
141 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 137 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
142 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 138 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
143 | /** Multi line string containing all non-empty address info in the form | 139 | /** Multi line string containing all non-empty address info in the form |
144 | * Street | 140 | * Street |
145 | * City, State Zip | 141 | * City, State Zip |
146 | * Country | 142 | * Country |
147 | */ | 143 | */ |
148 | QString displayHomeAddress() const; | 144 | QString displayHomeAddress() const; |
149 | 145 | ||
150 | // business | 146 | // business |
151 | QString company() const { return find( Qtopia::Company ); } | 147 | QString company() const { return find( Qtopia::Company ); } |
152 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 148 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
153 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 149 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
154 | QString businessState() const { return find( Qtopia::BusinessState ); } | 150 | QString businessState() const { return find( Qtopia::BusinessState ); } |
155 | QString businessZip() const { return find( Qtopia::BusinessZip ); } | 151 | QString businessZip() const { return find( Qtopia::BusinessZip ); } |
156 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } | 152 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } |
157 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } | 153 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } |
158 | QString jobTitle() const { return find( Qtopia::JobTitle ); } | 154 | QString jobTitle() const { return find( Qtopia::JobTitle ); } |
159 | QString department() const { return find( Qtopia::Department ); } | 155 | QString department() const { return find( Qtopia::Department ); } |
160 | QString office() const { return find( Qtopia::Office ); } | 156 | QString office() const { return find( Qtopia::Office ); } |
161 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } | 157 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } |
162 | QString businessFax() const { return find( Qtopia::BusinessFax ); } | 158 | QString businessFax() const { return find( Qtopia::BusinessFax ); } |
163 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } | 159 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } |
164 | QString businessPager() const { return find( Qtopia::BusinessPager ); } | 160 | QString businessPager() const { return find( Qtopia::BusinessPager ); } |
165 | QString profession() const { return find( Qtopia::Profession ); } | 161 | QString profession() const { return find( Qtopia::Profession ); } |
166 | QString assistant() const { return find( Qtopia::Assistant ); } | 162 | QString assistant() const { return find( Qtopia::Assistant ); } |
167 | QString manager() const { return find( Qtopia::Manager ); } | 163 | QString manager() const { return find( Qtopia::Manager ); } |
168 | /** Multi line string containing all non-empty address info in the form | 164 | /** Multi line string containing all non-empty address info in the form |
169 | * Street | 165 | * Street |
170 | * City, State Zip | 166 | * City, State Zip |
171 | * Country | 167 | * Country |
172 | */ | 168 | */ |
173 | QString displayBusinessAddress() const; | 169 | QString displayBusinessAddress() const; |
174 | 170 | ||
175 | //personal | 171 | //personal |
176 | QString spouse() const { return find( Qtopia::Spouse ); } | 172 | QString spouse() const { return find( Qtopia::Spouse ); } |
177 | QString gender() const { return find( Qtopia::Gender ); } | 173 | QString gender() const { return find( Qtopia::Gender ); } |
178 | QDate birthday() const; | 174 | QDate birthday() const; |
179 | QDate anniversary() const; | 175 | QDate anniversary() const; |
180 | QString nickname() const { return find( Qtopia::Nickname ); } | 176 | QString nickname() const { return find( Qtopia::Nickname ); } |
181 | QString children() const { return find( Qtopia::Children ); } | 177 | QString children() const { return find( Qtopia::Children ); } |
182 | QStringList childrenList() const; | 178 | QStringList childrenList() const; |
183 | 179 | ||
184 | // other | 180 | // other |
185 | QString notes() const { return find( Qtopia::Notes ); } | 181 | QString notes() const { return find( Qtopia::Notes ); } |
186 | QString groups() const { return find( Qtopia::Groups ); } | 182 | QString groups() const { return find( Qtopia::Groups ); } |
187 | QStringList groupList() const; | 183 | QStringList groupList() const; |
188 | 184 | ||
189 | // // custom | 185 | // // custom |
190 | // const QString &customField( const QString &key ) | 186 | // const QString &customField( const QString &key ) |
191 | // { return find( Custom- + key ); } | 187 | // { return find( Custom- + key ); } |
192 | 188 | ||
193 | static QStringList fields(); | 189 | static QStringList fields(); |
194 | static QStringList trfields(); | 190 | static QStringList trfields(); |
195 | static QStringList untrfields(); | 191 | static QStringList untrfields(); |
196 | 192 | ||
197 | QString toRichText() const; | 193 | QString toRichText() const; |
198 | QMap<int, QString> toMap() const; | 194 | QMap<int, QString> toMap() const; |
199 | QString field( int key ) const { return find( key ); } | 195 | QString field( int key ) const { return find( key ); } |
200 | 196 | ||
201 | 197 | ||
202 | // journaling... | 198 | // journaling... |
203 | void saveJournal( journal_action action, const QString &key = QString::null ); | 199 | void saveJournal( journal_action action, const QString &key = QString::null ); |
204 | void save( QString &buf ) const; | 200 | void save( QString &buf ) const; |
205 | 201 | ||
206 | void setUid( int i ) | 202 | void setUid( int i ) |
207 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } | 203 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } |
208 | 204 | ||
209 | QString toShortText()const; | 205 | QString toShortText()const; |
210 | QString OContact::type()const; | 206 | QString OContact::type()const; |
211 | QMap<QString,QString> OContact::toExtraMap() const; | 207 | QMap<QString,QString> OContact::toExtraMap() const; |
212 | class QString OContact::recordField(int) const; | 208 | class QString OContact::recordField(int) const; |
213 | 209 | ||
214 | // Why private ? (eilers,se) | 210 | // Why private ? (eilers,se) |
215 | QString emailSeparator() const { return " "; } | 211 | QString emailSeparator() const { return " "; } |
216 | // the emails should be seperated by a comma | 212 | // the emails should be seperated by a comma |
217 | void setEmails( const QString &v ); | 213 | void setEmails( const QString &v ); |
218 | QString emails() const { return find( Qtopia::Emails ); } | 214 | QString emails() const { return find( Qtopia::Emails ); } |
219 | 215 | ||
220 | 216 | ||
221 | private: | 217 | private: |
222 | friend class AbEditor; | 218 | friend class AbEditor; |
223 | friend class AbTable; | 219 | friend class AbTable; |
224 | friend class AddressBookAccessPrivate; | 220 | friend class AddressBookAccessPrivate; |
225 | friend class XMLIO; | 221 | friend class XMLIO; |
226 | 222 | ||
227 | void insert( int key, const QString &value ); | 223 | void insert( int key, const QString &value ); |
228 | void replace( int key, const QString &value ); | 224 | void replace( int key, const QString &value ); |
229 | QString find( int key ) const; | 225 | QString find( int key ) const; |
230 | 226 | ||
231 | QString displayAddress( const QString &street, | 227 | QString displayAddress( const QString &street, |
232 | const QString &city, | 228 | const QString &city, |
233 | const QString &state, | 229 | const QString &state, |
234 | const QString &zip, | 230 | const QString &zip, |
235 | const QString &country ) const; | 231 | const QString &country ) const; |
236 | 232 | ||
237 | Qtopia::UidGen &uidGen() { return sUidGen; } | 233 | Qtopia::UidGen &uidGen() { return sUidGen; } |
238 | 234 | ||
239 | 235 | ||
240 | static Qtopia::UidGen sUidGen; | 236 | static Qtopia::UidGen sUidGen; |
241 | QMap<int, QString> mMap; | 237 | QMap<int, QString> mMap; |
242 | ContactPrivate *d; | 238 | ContactPrivate *d; |
243 | }; | 239 | }; |
244 | 240 | ||
245 | 241 | ||
246 | #endif | 242 | #endif |