-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 24 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 98 |
2 files changed, 37 insertions, 85 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 040226c..106596f 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -1,671 +1,675 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | //US | 28 | //US |
29 | #include "kglobal.h" | 29 | #include "kglobal.h" |
30 | #include "klocale.h" | 30 | #include "klocale.h" |
31 | 31 | ||
32 | 32 | ||
33 | #include "qtopiaconverter.h" | 33 | #include "qtopiaconverter.h" |
34 | 34 | ||
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
38 | //#include <.h> | 38 | //#include <.h> |
39 | 39 | ||
40 | //#include <qpe/categories.h> | 40 | //#include <qpe/categories.h> |
41 | #include <libkdepim/ksyncprofile.h> | 41 | #include <libkdepim/ksyncprofile.h> |
42 | //US #include <qpe/categoryselect.h> | 42 | //US #include <qpe/categoryselect.h> |
43 | 43 | ||
44 | 44 | ||
45 | using namespace KABC; | 45 | using namespace KABC; |
46 | 46 | ||
47 | QtopiaConverter::QtopiaConverter() | 47 | QtopiaConverter::QtopiaConverter() |
48 | { | 48 | { |
49 | m_edit = 0; | 49 | m_edit = 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | QtopiaConverter::~QtopiaConverter() | 52 | QtopiaConverter::~QtopiaConverter() |
53 | { | 53 | { |
54 | deinit(); | 54 | deinit(); |
55 | } | 55 | } |
56 | 56 | ||
57 | bool QtopiaConverter::init() | 57 | bool QtopiaConverter::init() |
58 | { | 58 | { |
59 | QString fn = QDir::homeDirPath() +"/Settings/Categories.xml"; | 59 | QString fn = QDir::homeDirPath() +"/Settings/Categories.xml"; |
60 | m_edit = new CategoryEdit( fn); | 60 | m_edit = new CategoryEdit( fn); |
61 | return true; | 61 | return true; |
62 | } | 62 | } |
63 | 63 | ||
64 | void QtopiaConverter::deinit() | 64 | void QtopiaConverter::deinit() |
65 | { | 65 | { |
66 | if (m_edit) | 66 | if (m_edit) |
67 | { | 67 | { |
68 | delete m_edit; | 68 | delete m_edit; |
69 | m_edit = 0; | 69 | m_edit = 0; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) | 72 | QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) |
73 | { | 73 | { |
74 | startover: | 74 | startover: |
75 | QStringList dummy; | 75 | QStringList dummy; |
76 | QValueList<OpieCategories>::ConstIterator catIt; | 76 | QValueList<OpieCategories>::ConstIterator catIt; |
77 | QValueList<OpieCategories> categories = m_edit->categories(); | 77 | QValueList<OpieCategories> categories = m_edit->categories(); |
78 | bool found = false; | 78 | bool found = false; |
79 | for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { | 79 | for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { |
80 | /* skip empty category name */ | 80 | /* skip empty category name */ |
81 | if ( (*listIt).isEmpty() ) continue; | 81 | if ( (*listIt).isEmpty() ) continue; |
82 | 82 | ||
83 | found = false; | 83 | found = false; |
84 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 84 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
85 | /* | 85 | /* |
86 | * We currently do not take app into account | 86 | * We currently do not take app into account |
87 | * if name matches and the id isn't already in dummy we'll add it | 87 | * if name matches and the id isn't already in dummy we'll add it |
88 | */ | 88 | */ |
89 | if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name | 89 | if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name |
90 | found= true; | 90 | found= true; |
91 | dummy << (*catIt).id(); | 91 | dummy << (*catIt).id(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | /* if not found and the category is not empty | 94 | /* if not found and the category is not empty |
95 | * | 95 | * |
96 | * generate a new category and start over again | 96 | * generate a new category and start over again |
97 | * ugly goto to reiterate | 97 | * ugly goto to reiterate |
98 | */ | 98 | */ |
99 | 99 | ||
100 | if ( !found && !(*listIt).isEmpty() ){ | 100 | if ( !found && !(*listIt).isEmpty() ){ |
101 | m_edit->addCategory( app, (*listIt) ); // generate a new category | 101 | m_edit->addCategory( app, (*listIt) ); // generate a new category |
102 | goto startover; | 102 | goto startover; |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | return dummy.join(";"); | 106 | return dummy.join(";"); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | // FROM TT timeconversion.cpp GPLed | 110 | // FROM TT timeconversion.cpp GPLed |
111 | QDate QtopiaConverter::fromString( const QString &datestr ) | 111 | QDate QtopiaConverter::fromString( const QString &datestr ) |
112 | { | 112 | { |
113 | if (datestr.isEmpty() ) | 113 | if (datestr.isEmpty() ) |
114 | return QDate(); | 114 | return QDate(); |
115 | 115 | ||
116 | int monthPos = datestr.find('.'); | 116 | int monthPos = datestr.find('.'); |
117 | int yearPos = datestr.find('.', monthPos+1 ); | 117 | int yearPos = datestr.find('.', monthPos+1 ); |
118 | if ( monthPos == -1 || yearPos == -1 ) { | 118 | if ( monthPos == -1 || yearPos == -1 ) { |
119 | return QDate(); | 119 | return QDate(); |
120 | } | 120 | } |
121 | int d = datestr.left( monthPos ).toInt(); | 121 | int d = datestr.left( monthPos ).toInt(); |
122 | int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt(); | 122 | int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt(); |
123 | int y = datestr.mid( yearPos+1 ).toInt(); | 123 | int y = datestr.mid( yearPos+1 ).toInt(); |
124 | QDate date ( y,m,d ); | 124 | QDate date ( y,m,d ); |
125 | 125 | ||
126 | 126 | ||
127 | return date; | 127 | return date; |
128 | } | 128 | } |
129 | 129 | ||
130 | QDate QtopiaConverter::dateFromString( const QString& s ) | 130 | QDate QtopiaConverter::dateFromString( const QString& s ) |
131 | { | 131 | { |
132 | QDate date; | 132 | QDate date; |
133 | 133 | ||
134 | if ( s.isEmpty() ) | 134 | if ( s.isEmpty() ) |
135 | return date; | 135 | return date; |
136 | 136 | ||
137 | // Be backward compatible to old Opie format: | 137 | // Be backward compatible to old Opie format: |
138 | // Try to load old format. If it fails, try new ISO-Format! | 138 | // Try to load old format. If it fails, try new ISO-Format! |
139 | date = fromString ( s ); | 139 | date = fromString ( s ); |
140 | if ( date.isValid() ) | 140 | if ( date.isValid() ) |
141 | return date; | 141 | return date; |
142 | 142 | ||
143 | // Read ISO-Format (YYYYMMDD) | 143 | // Read ISO-Format (YYYYMMDD) |
144 | int year = s.mid(0, 4).toInt(); | 144 | int year = s.mid(0, 4).toInt(); |
145 | int month = s.mid(4,2).toInt(); | 145 | int month = s.mid(4,2).toInt(); |
146 | int day = s.mid(6,2).toInt(); | 146 | int day = s.mid(6,2).toInt(); |
147 | 147 | ||
148 | // do some quick sanity checking | 148 | // do some quick sanity checking |
149 | if ( year < 1900 || year > 3000 ) | 149 | if ( year < 1900 || year > 3000 ) |
150 | return date; | 150 | return date; |
151 | 151 | ||
152 | if ( month < 0 || month > 12 ) | 152 | if ( month < 0 || month > 12 ) |
153 | return date; | 153 | return date; |
154 | 154 | ||
155 | if ( day < 0 || day > 31 ) | 155 | if ( day < 0 || day > 31 ) |
156 | return date; | 156 | return date; |
157 | 157 | ||
158 | 158 | ||
159 | date.setYMD( year, month, day ); | 159 | date.setYMD( year, month, day ); |
160 | 160 | ||
161 | if ( !date.isValid() ) | 161 | if ( !date.isValid() ) |
162 | return QDate(); | 162 | return QDate(); |
163 | 163 | ||
164 | 164 | ||
165 | return date; | 165 | return date; |
166 | } | 166 | } |
167 | QString QtopiaConverter::dateToString( const QDate &d ) | 167 | QString QtopiaConverter::dateToString( const QDate &d ) |
168 | { | 168 | { |
169 | if ( d.isNull() || !d.isValid() ) | 169 | if ( d.isNull() || !d.isValid() ) |
170 | return QString::null; | 170 | return QString::null; |
171 | 171 | ||
172 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 | 172 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 |
173 | QString year = QString::number( d.year() ); | 173 | QString year = QString::number( d.year() ); |
174 | QString month = QString::number( d.month() ); | 174 | QString month = QString::number( d.month() ); |
175 | month = month.rightJustify( 2, '0' ); | 175 | month = month.rightJustify( 2, '0' ); |
176 | QString day = QString::number( d.day() ); | 176 | QString day = QString::number( d.day() ); |
177 | day = day.rightJustify( 2, '0' ); | 177 | day = day.rightJustify( 2, '0' ); |
178 | 178 | ||
179 | QString str = year + month + day; | 179 | QString str = year + month + day; |
180 | 180 | ||
181 | return str; | 181 | return str; |
182 | } | 182 | } |
183 | 183 | ||
184 | bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) | 184 | bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) |
185 | { | 185 | { |
186 | { //LR | 186 | { //LR |
187 | 187 | ||
188 | adr.setUid( el.attribute("Uid" ) ); | 188 | adr.setUid( el.attribute("Uid" ) ); |
189 | adr.setFamilyName( el.attribute( "LastName" ) ); | 189 | adr.setFamilyName( el.attribute( "LastName" ) ); |
190 | adr.setGivenName( el.attribute( "FirstName" ) ); | 190 | adr.setGivenName( el.attribute( "FirstName" ) ); |
191 | adr.setAdditionalName( el.attribute( "MiddleName" ) ); | 191 | adr.setAdditionalName( el.attribute( "MiddleName" ) ); |
192 | adr.setSuffix( el.attribute( "Suffix" ) ); | 192 | adr.setSuffix( el.attribute( "Suffix" ) ); |
193 | adr.setNickName( el.attribute( "Nickname" ) ); | 193 | adr.setNickName( el.attribute( "Nickname" ) ); |
194 | 194 | ||
195 | QDate date = dateFromString( el.attribute( "Birthday" ) ); | 195 | QDate date = dateFromString( el.attribute( "Birthday" ) ); |
196 | if ( date.isValid() ) | 196 | if ( date.isValid() ) |
197 | adr.setBirthday( date ); | 197 | adr.setBirthday( date ); |
198 | 198 | ||
199 | adr.setRole( el.attribute( "JobTitle" ) ); | 199 | adr.setRole( el.attribute( "JobTitle" ) ); |
200 | if ( !el.attribute( "FileAs" ).isEmpty() ) | 200 | if ( !el.attribute( "FileAs" ).isEmpty() ) |
201 | adr.setFormattedName( el.attribute( "FileAs" ) ); | 201 | adr.setFormattedName( el.attribute( "FileAs" ) ); |
202 | 202 | ||
203 | adr.setOrganization( el.attribute( "Company" ) ); | 203 | adr.setOrganization( el.attribute( "Company" ) ); |
204 | 204 | ||
205 | KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), | 205 | KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), |
206 | KABC::PhoneNumber::Work ); | 206 | KABC::PhoneNumber::Work ); |
207 | KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), | 207 | KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), |
208 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 208 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
209 | KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), | 209 | KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), |
210 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); | 210 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); |
211 | KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), | 211 | KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), |
212 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Pager ); | 212 | KABC::PhoneNumber::Work | KABC::PhoneNumber::Pager ); |
213 | if ( !businessPhoneNum.number().isEmpty() ) | 213 | if ( !businessPhoneNum.number().isEmpty() ) |
214 | adr.insertPhoneNumber( businessPhoneNum ); | 214 | adr.insertPhoneNumber( businessPhoneNum ); |
215 | if ( !businessFaxNum.number().isEmpty() ) | 215 | if ( !businessFaxNum.number().isEmpty() ) |
216 | adr.insertPhoneNumber( businessFaxNum ); | 216 | adr.insertPhoneNumber( businessFaxNum ); |
217 | if ( !businessMobile.number().isEmpty() ) | 217 | if ( !businessMobile.number().isEmpty() ) |
218 | adr.insertPhoneNumber( businessMobile ); | 218 | adr.insertPhoneNumber( businessMobile ); |
219 | if ( !businessPager.number().isEmpty() ) | 219 | if ( !businessPager.number().isEmpty() ) |
220 | adr.insertPhoneNumber( businessPager ); | 220 | adr.insertPhoneNumber( businessPager ); |
221 | 221 | ||
222 | // Handle multiple mail addresses | 222 | // Handle multiple mail addresses |
223 | QString DefaultEmail = el.attribute( "DefaultEmail" ); | 223 | QString DefaultEmail = el.attribute( "DefaultEmail" ); |
224 | if ( !DefaultEmail.isEmpty() ) | 224 | if ( !DefaultEmail.isEmpty() ) |
225 | adr.insertEmail( DefaultEmail, true ); // preferred | 225 | adr.insertEmail( DefaultEmail, true ); // preferred |
226 | 226 | ||
227 | QStringList Emails = QStringList::split(" ",el.attribute("Emails")); | 227 | QStringList Emails = QStringList::split(" ",el.attribute("Emails")); |
228 | int i; | 228 | int i; |
229 | for (i = 0;i < Emails.count();++i) { | 229 | for (i = 0;i < Emails.count();++i) { |
230 | if ( Emails[i] != DefaultEmail ) | 230 | if ( Emails[i] != DefaultEmail ) |
231 | adr.insertEmail( Emails[i], false ); | 231 | adr.insertEmail( Emails[i], false ); |
232 | } | 232 | } |
233 | 233 | ||
234 | KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ), | 234 | KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ), |
235 | KABC::PhoneNumber::Home ); | 235 | KABC::PhoneNumber::Home ); |
236 | KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ), | 236 | KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ), |
237 | KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); | 237 | KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); |
238 | 238 | ||
239 | KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ), | 239 | KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ), |
240 | KABC::PhoneNumber::Cell ); | 240 | KABC::PhoneNumber::Cell ); |
241 | 241 | ||
242 | if ( !homePhoneNum.number().isEmpty() ) | 242 | if ( !homePhoneNum.number().isEmpty() ) |
243 | adr.insertPhoneNumber( homePhoneNum ); | 243 | adr.insertPhoneNumber( homePhoneNum ); |
244 | if ( !homeFax.number().isEmpty() ) | 244 | if ( !homeFax.number().isEmpty() ) |
245 | adr.insertPhoneNumber( homeFax ); | 245 | adr.insertPhoneNumber( homeFax ); |
246 | if ( !homeMobile.number().isEmpty() ) | 246 | if ( !homeMobile.number().isEmpty() ) |
247 | adr.insertPhoneNumber( homeMobile ); | 247 | adr.insertPhoneNumber( homeMobile ); |
248 | 248 | ||
249 | KABC::Address business( KABC::Address::Work ); | 249 | KABC::Address business( KABC::Address::Work ); |
250 | business.setStreet( el.attribute( "BusinessStreet" ) ); | 250 | business.setStreet( el.attribute( "BusinessStreet" ) ); |
251 | business.setLocality( el.attribute( "BusinessCity" ) ); | 251 | business.setLocality( el.attribute( "BusinessCity" ) ); |
252 | business.setRegion( el.attribute( "BusinessState" ) ); | 252 | business.setRegion( el.attribute( "BusinessState" ) ); |
253 | business.setPostalCode( el.attribute( "BusinessZip" ) ); | 253 | business.setPostalCode( el.attribute( "BusinessZip" ) ); |
254 | business.setCountry( el.attribute( "BusinessCountry" ) ); | 254 | business.setCountry( el.attribute( "BusinessCountry" ) ); |
255 | 255 | ||
256 | if ( !business.isEmpty() ) | 256 | if ( !business.isEmpty() ) |
257 | adr.insertAddress( business ); | 257 | adr.insertAddress( business ); |
258 | 258 | ||
259 | KABC::Address home( KABC::Address::Home ); | 259 | KABC::Address home( KABC::Address::Home ); |
260 | home.setStreet( el.attribute( "HomeStreet" ) ); | 260 | home.setStreet( el.attribute( "HomeStreet" ) ); |
261 | home.setLocality( el.attribute( "HomeCity" ) ); | 261 | home.setLocality( el.attribute( "HomeCity" ) ); |
262 | home.setRegion( el.attribute( "HomeState" ) ); | 262 | home.setRegion( el.attribute( "HomeState" ) ); |
263 | home.setPostalCode( el.attribute( "HomeZip" ) ); | 263 | home.setPostalCode( el.attribute( "HomeZip" ) ); |
264 | home.setCountry( el.attribute( "HomeCountry" ) ); | 264 | home.setCountry( el.attribute( "HomeCountry" ) ); |
265 | 265 | ||
266 | if ( !home.isEmpty() ) | 266 | if ( !home.isEmpty() ) |
267 | adr.insertAddress( home ); | 267 | adr.insertAddress( home ); |
268 | 268 | ||
269 | adr.setNickName( el.attribute( "Nickname" ) ); | 269 | adr.setNickName( el.attribute( "Nickname" ) ); |
270 | adr.setNote( el.attribute( "Notes" ) ); | 270 | adr.setNote( el.attribute( "Notes" ) ); |
271 | 271 | ||
272 | { | 272 | { |
273 | QStringList categories = QStringList::split(";", el.attribute("Categories" ) ); | 273 | QStringList categories = QStringList::split(";", el.attribute("Categories" ) ); |
274 | QString cat; | 274 | QString cat; |
275 | QStringList added; | 275 | QStringList added; |
276 | for ( uint i = 0; i < categories.count(); i++ ) { | 276 | for ( uint i = 0; i < categories.count(); i++ ) { |
277 | cat = m_edit->categoryById( categories[ i ], "Contacts" ); | 277 | cat = m_edit->categoryById( categories[ i ], "Contacts" ); |
278 | 278 | ||
279 | // if name is not empty and we did not add the | 279 | // if name is not empty and we did not add the |
280 | // cat try to repair broken files | 280 | // cat try to repair broken files |
281 | if ( !cat.isEmpty() && !added.contains( cat ) ) { | 281 | if ( !cat.isEmpty() && !added.contains( cat ) ) { |
282 | adr.insertCategory( cat ); | 282 | adr.insertCategory( cat ); |
283 | added << cat; | 283 | added << cat; |
284 | } | 284 | } |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | if ( !el.attribute( "Department" ).isEmpty() ) | 288 | if ( !el.attribute( "Department" ).isEmpty() ) |
289 | adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) ); | 289 | adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) ); |
290 | if ( !el.attribute( "HomeWebPage" ).isEmpty() ) | 290 | if ( !el.attribute( "HomeWebPage" ).isEmpty() ) |
291 | adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) ); | 291 | adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) ); |
292 | if ( !el.attribute( "Spouse" ).isEmpty() ) | 292 | if ( !el.attribute( "Spouse" ).isEmpty() ) |
293 | adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) ); | 293 | adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) ); |
294 | if ( !el.attribute( "Gender" ).isEmpty() ) | 294 | if ( !el.attribute( "Gender" ).isEmpty() ) { |
295 | adr.insertCustom( "opie", "Gender", el.attribute( "Gender" ) ); | 295 | if ( el.attribute( "Gender" ) == "1" ) |
296 | 296 | adr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); | |
297 | else if ( el.attribute( "Gender" ) == "2" ) | ||
298 | adr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); | ||
299 | } | ||
297 | QDate ann = dateFromString( el.attribute( "Anniversary" ) ); | 300 | QDate ann = dateFromString( el.attribute( "Anniversary" ) ); |
298 | if ( ann.isValid() ) { | 301 | if ( ann.isValid() ) { |
299 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); | 302 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); |
300 | adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt ); | 303 | adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt ); |
301 | } | 304 | } |
302 | 305 | ||
303 | if ( !el.attribute( "Children" ).isEmpty() ) | 306 | if ( !el.attribute( "Children" ).isEmpty() ) |
304 | adr.insertCustom("opie", "Children", el.attribute("Children") ); | 307 | adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); |
305 | if ( !el.attribute( "Office" ).isEmpty() ) | 308 | if ( !el.attribute( "Office" ).isEmpty() ) |
306 | adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); | 309 | adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); |
307 | if ( !el.attribute( "Profession" ).isEmpty() ) | 310 | if ( !el.attribute( "Profession" ).isEmpty() ) |
308 | adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); | 311 | adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); |
309 | if ( !el.attribute( "Assistant" ).isEmpty() ) | 312 | if ( !el.attribute( "Assistant" ).isEmpty() ) |
310 | adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); | 313 | adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); |
311 | if ( !el.attribute( "Manager" ).isEmpty() ) | 314 | if ( !el.attribute( "Manager" ).isEmpty() ) |
312 | adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); | 315 | adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); |
313 | 316 | ||
314 | 317 | ||
315 | } | 318 | } |
316 | return true; | 319 | return true; |
317 | } | 320 | } |
318 | 321 | ||
319 | bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) | 322 | bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) |
320 | { | 323 | { |
321 | *stream << "<Contact "; | 324 | *stream << "<Contact "; |
322 | *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; | 325 | *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; |
323 | *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; | 326 | *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; |
324 | *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; | 327 | *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; |
325 | *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; | 328 | *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; |
326 | 329 | ||
327 | QString sortStr; | 330 | QString sortStr; |
328 | sortStr = ab.formattedName(); | 331 | sortStr = ab.formattedName(); |
329 | /* is formattedName is empty we use the assembled name as fallback */ | 332 | /* is formattedName is empty we use the assembled name as fallback */ |
330 | if (sortStr.isEmpty() ) | 333 | if (sortStr.isEmpty() ) |
331 | sortStr = ab.assembledName(); | 334 | sortStr = ab.assembledName(); |
332 | *stream << "FileAs=\"" << escape(sortStr) << "\" "; | 335 | *stream << "FileAs=\"" << escape(sortStr) << "\" "; |
333 | 336 | ||
334 | *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; | 337 | *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; |
335 | *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; | 338 | *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; |
336 | *stream << "Company=\"" << escape(ab.organization()) << "\" "; | 339 | *stream << "Company=\"" << escape(ab.organization()) << "\" "; |
337 | 340 | ||
338 | KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work ); | 341 | KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work ); |
339 | *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" "; | 342 | *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" "; |
340 | 343 | ||
341 | KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 344 | KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
342 | *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" "; | 345 | *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" "; |
343 | 346 | ||
344 | KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); | 347 | KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); |
345 | *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" "; | 348 | *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" "; |
346 | 349 | ||
347 | *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" "; | 350 | *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" "; |
348 | QStringList list = ab.emails(); | 351 | QStringList list = ab.emails(); |
349 | if ( list.count() > 0 ) { | 352 | if ( list.count() > 0 ) { |
350 | QStringList::Iterator it = list.begin(); | 353 | QStringList::Iterator it = list.begin(); |
351 | *stream << "Emails=\"" << escape( *it ); | 354 | *stream << "Emails=\"" << escape( *it ); |
352 | while (++it != list.end()) | 355 | while (++it != list.end()) |
353 | *stream << ' ' << escape( *it ); | 356 | *stream << ' ' << escape( *it ); |
354 | *stream << "\" "; | 357 | *stream << "\" "; |
355 | } | 358 | } |
356 | 359 | ||
357 | KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home ); | 360 | KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home ); |
358 | *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" "; | 361 | *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" "; |
359 | 362 | ||
360 | KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); | 363 | KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); |
361 | *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" "; | 364 | *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" "; |
362 | 365 | ||
363 | KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell ); | 366 | KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell ); |
364 | *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" "; | 367 | *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" "; |
365 | 368 | ||
366 | KABC::Address business = ab.address(KABC::Address::Work ); | 369 | KABC::Address business = ab.address(KABC::Address::Work ); |
367 | *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" "; | 370 | *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" "; |
368 | *stream << "BusinessCity=\"" << escape( business.locality() ) << "\" "; | 371 | *stream << "BusinessCity=\"" << escape( business.locality() ) << "\" "; |
369 | *stream << "BusinessZip=\"" << escape( business.postalCode() ) << "\" "; | 372 | *stream << "BusinessZip=\"" << escape( business.postalCode() ) << "\" "; |
370 | *stream << "BusinessCountry=\"" << escape( business.country() ) << "\" "; | 373 | *stream << "BusinessCountry=\"" << escape( business.country() ) << "\" "; |
371 | *stream << "BusinessState=\"" << escape( business.region() ) << "\" "; | 374 | *stream << "BusinessState=\"" << escape( business.region() ) << "\" "; |
372 | //stream << "BusinessPager=\"" << << "\" "; | 375 | //stream << "BusinessPager=\"" << << "\" "; |
373 | *stream << "Office=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Office" ) ) << "\" "; | 376 | *stream << "Office=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Office" ) ) << "\" "; |
374 | *stream << "Profession=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Profession" ) ) << "\" "; | 377 | *stream << "Profession=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Profession" ) ) << "\" "; |
375 | *stream << "Assistant=\"" << escape( ab.custom( "KADDRESSBOOK", "X-AssistantsName") ) << "\" "; | 378 | *stream << "Assistant=\"" << escape( ab.custom( "KADDRESSBOOK", "X-AssistantsName") ) << "\" "; |
376 | *stream << "Manager=\"" << escape( ab.custom( "KADDRESSBOOK", "X-ManagersName" ) ) << "\" "; | 379 | *stream << "Manager=\"" << escape( ab.custom( "KADDRESSBOOK", "X-ManagersName" ) ) << "\" "; |
377 | 380 | ||
378 | KABC::Address home = ab.address( KABC::Address::Home ); | 381 | KABC::Address home = ab.address( KABC::Address::Home ); |
379 | *stream << "HomeStreet=\"" << escape( home.street() ) << "\" "; | 382 | *stream << "HomeStreet=\"" << escape( home.street() ) << "\" "; |
380 | *stream << "HomeCity=\"" << escape( home.locality() ) << "\" "; | 383 | *stream << "HomeCity=\"" << escape( home.locality() ) << "\" "; |
381 | *stream << "HomeState=\"" << escape( home.region() ) << "\" "; | 384 | *stream << "HomeState=\"" << escape( home.region() ) << "\" "; |
382 | *stream << "HomeZip=\"" << escape( home.postalCode() ) << "\" "; | 385 | *stream << "HomeZip=\"" << escape( home.postalCode() ) << "\" "; |
383 | *stream << "HomeCountry=\"" << escape( home.country() ) << "\" "; | 386 | *stream << "HomeCountry=\"" << escape( home.country() ) << "\" "; |
384 | 387 | ||
385 | *stream << "HomeWebPage=\"" << escape( ab.custom( "opie", "HomeWebPage" ) ) << "\" "; | 388 | *stream << "HomeWebPage=\"" << escape( ab.custom( "opie", "HomeWebPage" ) ) << "\" "; |
386 | *stream << "Spouse=\"" << escape( ab.custom( "KADDRESSBOOK", "X-SpousesName") ) << "\" "; | 389 | *stream << "Spouse=\"" << escape( ab.custom( "KADDRESSBOOK", "X-SpousesName") ) << "\" "; |
387 | *stream << "Gender=\"" << escape( ab.custom( "opie", "Gender") ) << "\" "; | 390 | QString gen = "0"; |
391 | if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "male" ) | ||
392 | gen = "1"; | ||
393 | else if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "female" ) | ||
394 | gen = "2"; | ||
395 | *stream << "Gender=\"" << escape( gen ) << "\" "; | ||
388 | 396 | ||
389 | if ( ab.birthday().date().isValid() ) | 397 | if ( ab.birthday().date().isValid() ) |
390 | *stream << "Birthday=\"" << escape( dateToString(ab.birthday().date() ) ) << "\" "; | 398 | *stream << "Birthday=\"" << escape( dateToString(ab.birthday().date() ) ) << "\" "; |
391 | 399 | ||
392 | /* | ||
393 | * Anniversary block again | ||
394 | * Go from ISO -> QDate -> toString and then escape | ||
395 | */ | ||
396 | { | 400 | { |
397 | QDate ann = KGlobal::locale()->readDate( ab.custom("KADDRESSBOOK", "X-Anniversary" ), | 401 | QDate ann = KGlobal::locale()->readDate( ab.custom("KADDRESSBOOK", "X-Anniversary" ), |
398 | "%Y-%m-%d"); | 402 | "%Y-%m-%d"); |
399 | if (ann.isValid() ) { | 403 | if (ann.isValid() ) { |
400 | *stream << "Anniversary=\"" << escape( dateToString( ann ) ) << "\" "; | 404 | *stream << "Anniversary=\"" << escape( dateToString( ann ) ) << "\" "; |
401 | } | 405 | } |
402 | } | 406 | } |
403 | *stream << "Nickname=\"" << escape( ab.nickName() ) << "\" "; | 407 | *stream << "Nickname=\"" << escape( ab.nickName() ) << "\" "; |
404 | *stream << "Children=\"" << escape( ab.custom("opie", "Children" ) ) << "\" "; | 408 | *stream << "Children=\"" << escape( ab.custom("KADDRESSBOOK", "X-Children" ) ) << "\" "; |
405 | *stream << "Notes=\"" << escape( ab.note() ) << "\" "; | 409 | *stream << "Notes=\"" << escape( ab.note() ) << "\" "; |
406 | *stream << "Categories=\"" << categoriesToNumber( ab.categories(), "Contacts") << "\" "; | 410 | *stream << "Categories=\"" << categoriesToNumber( ab.categories(), "Contacts") << "\" "; |
407 | 411 | ||
408 | QString uid = ab.uid(); | 412 | QString uid = ab.uid(); |
409 | *stream << "Uid=\"" << uid << "\" "; | 413 | *stream << "Uid=\"" << uid << "\" "; |
410 | //*stream << map.toString( "addressbook", uid ); | 414 | //*stream << map.toString( "addressbook", uid ); |
411 | *stream << " />" << "\n"; | 415 | *stream << " />" << "\n"; |
412 | 416 | ||
413 | return true; | 417 | return true; |
414 | } | 418 | } |
415 | 419 | ||
416 | 420 | ||
417 | #if 0 | 421 | #if 0 |
418 | 422 | ||
419 | KTempFile* AddressBook::fromKDE( KSync::AddressBookSyncee *syncee, ExtraMap& map ) | 423 | KTempFile* AddressBook::fromKDE( KSync::AddressBookSyncee *syncee, ExtraMap& map ) |
420 | { | 424 | { |
421 | 425 | ||
422 | } | 426 | } |
423 | 427 | ||
424 | QStringList AddressBook::attributes()const { | 428 | QStringList AddressBook::attributes()const { |
425 | QStringList lst; | 429 | QStringList lst; |
426 | lst << "FirstName"; | 430 | lst << "FirstName"; |
427 | lst << "MiddleName"; | 431 | lst << "MiddleName"; |
428 | lst << "LastName"; | 432 | lst << "LastName"; |
429 | lst << "Suffix"; | 433 | lst << "Suffix"; |
430 | lst << "FileAs"; | 434 | lst << "FileAs"; |
431 | lst << "JobTitle"; | 435 | lst << "JobTitle"; |
432 | lst << "Department"; | 436 | lst << "Department"; |
433 | lst << "Company"; | 437 | lst << "Company"; |
434 | lst << "BusinessPhone"; | 438 | lst << "BusinessPhone"; |
435 | lst << "BusinessFax"; | 439 | lst << "BusinessFax"; |
436 | lst << "BusinessMobile"; | 440 | lst << "BusinessMobile"; |
437 | lst << "DefaultEmail"; | 441 | lst << "DefaultEmail"; |
438 | lst << "Emails"; | 442 | lst << "Emails"; |
439 | lst << "HomePhone"; | 443 | lst << "HomePhone"; |
440 | lst << "HomeFax"; | 444 | lst << "HomeFax"; |
441 | lst << "HomeMobile"; | 445 | lst << "HomeMobile"; |
442 | lst << "BusinessStreet"; | 446 | lst << "BusinessStreet"; |
443 | lst << "BusinessCity"; | 447 | lst << "BusinessCity"; |
444 | lst << "BusinessZip"; | 448 | lst << "BusinessZip"; |
445 | lst << "BusinessCountry"; | 449 | lst << "BusinessCountry"; |
446 | lst << "BusinessState"; | 450 | lst << "BusinessState"; |
447 | lst << "Office"; | 451 | lst << "Office"; |
448 | lst << "Profession"; | 452 | lst << "Profession"; |
449 | lst << "Assistant"; | 453 | lst << "Assistant"; |
450 | lst << "Manager"; | 454 | lst << "Manager"; |
451 | lst << "HomeStreet"; | 455 | lst << "HomeStreet"; |
452 | lst << "HomeCity"; | 456 | lst << "HomeCity"; |
453 | lst << "HomeState"; | 457 | lst << "HomeState"; |
454 | lst << "HomeZip"; | 458 | lst << "HomeZip"; |
455 | lst << "HomeCountry"; | 459 | lst << "HomeCountry"; |
456 | lst << "HomeWebPage"; | 460 | lst << "HomeWebPage"; |
457 | lst << "Spouse"; | 461 | lst << "Spouse"; |
458 | lst << "Gender"; | 462 | lst << "Gender"; |
459 | lst << "Anniversary"; | 463 | lst << "Anniversary"; |
460 | lst << "Nickname"; | 464 | lst << "Nickname"; |
461 | lst << "Children"; | 465 | lst << "Children"; |
462 | lst << "Notes"; | 466 | lst << "Notes"; |
463 | lst << "Categories"; | 467 | lst << "Categories"; |
464 | lst << "Uid"; | 468 | lst << "Uid"; |
465 | lst << "Birthday"; | 469 | lst << "Birthday"; |
466 | 470 | ||
467 | return lst; | 471 | return lst; |
468 | } | 472 | } |
469 | 473 | ||
470 | 474 | ||
471 | 475 | ||
472 | #endif | 476 | #endif |
473 | 477 | ||
474 | 478 | ||
475 | CategoryEdit::CategoryEdit(){ | 479 | CategoryEdit::CategoryEdit(){ |
476 | } | 480 | } |
477 | CategoryEdit::CategoryEdit(const QString &fileName){ | 481 | CategoryEdit::CategoryEdit(const QString &fileName){ |
478 | parse( fileName ); | 482 | parse( fileName ); |
479 | } | 483 | } |
480 | CategoryEdit::~CategoryEdit(){ | 484 | CategoryEdit::~CategoryEdit(){ |
481 | } | 485 | } |
482 | void CategoryEdit::save(const QString& fileName)const{ | 486 | void CategoryEdit::save(const QString& fileName)const{ |
483 | QFile file( fileName ); | 487 | QFile file( fileName ); |
484 | QString endl = "\n"; | 488 | QString endl = "\n"; |
485 | if ( file.open( IO_WriteOnly ) ) { | 489 | if ( file.open( IO_WriteOnly ) ) { |
486 | QTextStream stream( &file ); | 490 | QTextStream stream( &file ); |
487 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 491 | stream.setEncoding( QTextStream::UnicodeUTF8 ); |
488 | stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; | 492 | stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; |
489 | stream << "<!DOCTYPE CategoryList>" << endl; | 493 | stream << "<!DOCTYPE CategoryList>" << endl; |
490 | stream << "<Categories>" << endl; | 494 | stream << "<Categories>" << endl; |
491 | for ( QValueList<OpieCategories>::ConstIterator it = m_categories.begin(); | 495 | for ( QValueList<OpieCategories>::ConstIterator it = m_categories.begin(); |
492 | it != m_categories.end(); ++it ) | 496 | it != m_categories.end(); ++it ) |
493 | { | 497 | { |
494 | stream << "<Category id=\""<< ( (*it).id() ) << "\" "; | 498 | stream << "<Category id=\""<< ( (*it).id() ) << "\" "; |
495 | 499 | ||
496 | if ( !(*it).app().isEmpty() ) | 500 | if ( !(*it).app().isEmpty() ) |
497 | stream << " app=\""<< ( (*it).app() ) << "\" "; | 501 | stream << " app=\""<< ( (*it).app() ) << "\" "; |
498 | 502 | ||
499 | stream << "name=\"" << ( (*it).name() ) << "\" "; | 503 | stream << "name=\"" << ( (*it).name() ) << "\" "; |
500 | stream << " />" << endl; | 504 | stream << " />" << endl; |
501 | } | 505 | } |
502 | stream << "</Categories>" << endl; | 506 | stream << "</Categories>" << endl; |
503 | file.close(); | 507 | file.close(); |
504 | } | 508 | } |
505 | } | 509 | } |
506 | int CategoryEdit::addCategory( const QString &name, int id ){ | 510 | int CategoryEdit::addCategory( const QString &name, int id ){ |
507 | return addCategory( QString::null, name, id ); | 511 | return addCategory( QString::null, name, id ); |
508 | } | 512 | } |
509 | int CategoryEdit::addCategory( const QString &appName, const QString &name, int id ){ | 513 | int CategoryEdit::addCategory( const QString &appName, const QString &name, int id ){ |
510 | if ( id == 0 ) { | 514 | if ( id == 0 ) { |
511 | // code from tt | 515 | // code from tt |
512 | //generate uid | 516 | //generate uid |
513 | QDateTime dt = QDateTime::currentDateTime(); | 517 | QDateTime dt = QDateTime::currentDateTime(); |
514 | id = -1 * (int) dt.secsTo( QDateTime(QDate( 2000,1,1)) ); | 518 | id = -1 * (int) dt.secsTo( QDateTime(QDate( 2000,1,1)) ); |
515 | while ( ids.contains( id ) ){ | 519 | while ( ids.contains( id ) ){ |
516 | id += -1; | 520 | id += -1; |
517 | if ( id > 0 ) | 521 | if ( id > 0 ) |
518 | id = -1; | 522 | id = -1; |
519 | } | 523 | } |
520 | } | 524 | } |
521 | ids.insert( id, TRUE ); | 525 | ids.insert( id, TRUE ); |
522 | OpieCategories categories(QString::number(id), name, appName); | 526 | OpieCategories categories(QString::number(id), name, appName); |
523 | //pending FIXME LR m_categories.remove( categories); | 527 | //pending FIXME LR m_categories.remove( categories); |
524 | m_categories.append( categories); | 528 | m_categories.append( categories); |
525 | return id; | 529 | return id; |
526 | } | 530 | } |
527 | /* | 531 | /* |
528 | * we parse the simple Category File here | 532 | * we parse the simple Category File here |
529 | * We also keep track of global Cats | 533 | * We also keep track of global Cats |
530 | * and Of Organizer and Contact cats and then | 534 | * and Of Organizer and Contact cats and then |
531 | * we will add them to the kde side... | 535 | * we will add them to the kde side... |
532 | */ | 536 | */ |
533 | void CategoryEdit::parse( const QString &tempFile ){ | 537 | void CategoryEdit::parse( const QString &tempFile ){ |
534 | clear(); | 538 | clear(); |
535 | 539 | ||
536 | QDomDocument doc( "mydocument" ); | 540 | QDomDocument doc( "mydocument" ); |
537 | QFile f( tempFile ); | 541 | QFile f( tempFile ); |
538 | if ( !f.open( IO_ReadOnly ) ) | 542 | if ( !f.open( IO_ReadOnly ) ) |
539 | return; | 543 | return; |
540 | 544 | ||
541 | if ( !doc.setContent( &f ) ) { | 545 | if ( !doc.setContent( &f ) ) { |
542 | f.close(); | 546 | f.close(); |
543 | return; | 547 | return; |
544 | } | 548 | } |
545 | f.close(); | 549 | f.close(); |
546 | 550 | ||
547 | QStringList global, contact, organizer; | 551 | QStringList global, contact, organizer; |
548 | 552 | ||
549 | // print out the element names of all elements that are a direct child | 553 | // print out the element names of all elements that are a direct child |
550 | // of the outermost element. | 554 | // of the outermost element. |
551 | QDomElement docElem = doc.documentElement(); | 555 | QDomElement docElem = doc.documentElement(); |
552 | QDomNode n = docElem.firstChild(); | 556 | QDomNode n = docElem.firstChild(); |
553 | if( docElem.nodeName() == QString::fromLatin1("Categories") ){ | 557 | if( docElem.nodeName() == QString::fromLatin1("Categories") ){ |
554 | while( !n.isNull() ) { | 558 | while( !n.isNull() ) { |
555 | QDomElement e = n.toElement(); // try to convert the node to an element. | 559 | QDomElement e = n.toElement(); // try to convert the node to an element. |
556 | if( !e.isNull() ) { // the node was really an element. | 560 | if( !e.isNull() ) { // the node was really an element. |
557 | QString id = e.attribute("id" ); | 561 | QString id = e.attribute("id" ); |
558 | QString app = e.attribute("app" ); | 562 | QString app = e.attribute("app" ); |
559 | QString name = e.attribute("name"); | 563 | QString name = e.attribute("name"); |
560 | 564 | ||
561 | /* | 565 | /* |
562 | * see where it belongs default to global | 566 | * see where it belongs default to global |
563 | */ | 567 | */ |
564 | if (app == QString::fromLatin1("Calendar") || app == QString::fromLatin1("Todo List") ) | 568 | if (app == QString::fromLatin1("Calendar") || app == QString::fromLatin1("Todo List") ) |
565 | organizer.append( name ); | 569 | organizer.append( name ); |
566 | else if ( app == QString::fromLatin1("Contacts") ) | 570 | else if ( app == QString::fromLatin1("Contacts") ) |
567 | contact.append( name ); | 571 | contact.append( name ); |
568 | else | 572 | else |
569 | global.append( name ); | 573 | global.append( name ); |
570 | 574 | ||
571 | OpieCategories category( id, name, app ); | 575 | OpieCategories category( id, name, app ); |
572 | m_categories.append( category ); // cheater | 576 | m_categories.append( category ); // cheater |
573 | } | 577 | } |
574 | n = n.nextSibling(); | 578 | n = n.nextSibling(); |
575 | } | 579 | } |
576 | } | 580 | } |
577 | updateKDE( "kaddressbookrc", global + contact ); | 581 | updateKDE( "kaddressbookrc", global + contact ); |
578 | updateKDE( "korganizerrc", global + organizer ); | 582 | updateKDE( "korganizerrc", global + organizer ); |
579 | 583 | ||
580 | } | 584 | } |
581 | void CategoryEdit::clear() | 585 | void CategoryEdit::clear() |
582 | { | 586 | { |
583 | ids.clear(); | 587 | ids.clear(); |
584 | m_categories.clear(); | 588 | m_categories.clear(); |
585 | } | 589 | } |
586 | QString CategoryEdit::categoryById( const QString &id, const QString &app )const | 590 | QString CategoryEdit::categoryById( const QString &id, const QString &app )const |
587 | { | 591 | { |
588 | QValueList<OpieCategories>::ConstIterator it; | 592 | QValueList<OpieCategories>::ConstIterator it; |
589 | QString category; | 593 | QString category; |
590 | QString fallback; | 594 | QString fallback; |
591 | for( it = m_categories.begin(); it != m_categories.end(); ++it ){ | 595 | for( it = m_categories.begin(); it != m_categories.end(); ++it ){ |
592 | if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){ | 596 | if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){ |
593 | if( app == (*it).app() ){ | 597 | if( app == (*it).app() ){ |
594 | category = (*it).name(); | 598 | category = (*it).name(); |
595 | break; | 599 | break; |
596 | }else{ | 600 | }else{ |
597 | fallback = (*it).name(); | 601 | fallback = (*it).name(); |
598 | } | 602 | } |
599 | } | 603 | } |
600 | } | 604 | } |
601 | return category.isEmpty() ? fallback : category; | 605 | return category.isEmpty() ? fallback : category; |
602 | } | 606 | } |
603 | QStringList CategoryEdit::categoriesByIds( const QStringList& ids, | 607 | QStringList CategoryEdit::categoriesByIds( const QStringList& ids, |
604 | const QString& app) { | 608 | const QString& app) { |
605 | 609 | ||
606 | QStringList list; | 610 | QStringList list; |
607 | QStringList::ConstIterator it; | 611 | QStringList::ConstIterator it; |
608 | QString temp; | 612 | QString temp; |
609 | for ( it = ids.begin(); it != ids.end(); ++it ) { | 613 | for ( it = ids.begin(); it != ids.end(); ++it ) { |
610 | temp = categoryById( (*it), app ); | 614 | temp = categoryById( (*it), app ); |
611 | if (!temp.isEmpty() ) | 615 | if (!temp.isEmpty() ) |
612 | list << temp; | 616 | list << temp; |
613 | } | 617 | } |
614 | 618 | ||
615 | return list; | 619 | return list; |
616 | } | 620 | } |
617 | void CategoryEdit::updateKDE( const QString& configFile, const QStringList& cats ) { | 621 | void CategoryEdit::updateKDE( const QString& configFile, const QStringList& cats ) { |
618 | KConfig conf(configFile); | 622 | KConfig conf(configFile); |
619 | conf.setGroup("General"); | 623 | conf.setGroup("General"); |
620 | QStringList avail = conf.readListEntry("Custom Categories"); | 624 | QStringList avail = conf.readListEntry("Custom Categories"); |
621 | for (QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) { | 625 | for (QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) { |
622 | if (!avail.contains( (*it) ) ) | 626 | if (!avail.contains( (*it) ) ) |
623 | avail << (*it); | 627 | avail << (*it); |
624 | } | 628 | } |
625 | conf.writeEntry("Custom Categories", avail ); | 629 | conf.writeEntry("Custom Categories", avail ); |
626 | } | 630 | } |
627 | 631 | ||
628 | 632 | ||
629 | 633 | ||
630 | OpieCategories::OpieCategories() | 634 | OpieCategories::OpieCategories() |
631 | { | 635 | { |
632 | 636 | ||
633 | } | 637 | } |
634 | OpieCategories::OpieCategories(const QString &id, const QString &name, const QString &app ) | 638 | OpieCategories::OpieCategories(const QString &id, const QString &name, const QString &app ) |
635 | { | 639 | { |
636 | m_name = name; | 640 | m_name = name; |
637 | m_id = id; | 641 | m_id = id; |
638 | m_app = app; | 642 | m_app = app; |
639 | } | 643 | } |
640 | OpieCategories::OpieCategories(const OpieCategories &op ) | 644 | OpieCategories::OpieCategories(const OpieCategories &op ) |
641 | { | 645 | { |
642 | (*this) = op; | 646 | (*this) = op; |
643 | } | 647 | } |
644 | QString OpieCategories::id() const | 648 | QString OpieCategories::id() const |
645 | { | 649 | { |
646 | return m_id; | 650 | return m_id; |
647 | } | 651 | } |
648 | QString OpieCategories::name() const | 652 | QString OpieCategories::name() const |
649 | { | 653 | { |
650 | return m_name; | 654 | return m_name; |
651 | } | 655 | } |
652 | QString OpieCategories::app() const | 656 | QString OpieCategories::app() const |
653 | { | 657 | { |
654 | return m_app; | 658 | return m_app; |
655 | } | 659 | } |
656 | OpieCategories &OpieCategories::operator=(const OpieCategories &op ) | 660 | OpieCategories &OpieCategories::operator=(const OpieCategories &op ) |
657 | { | 661 | { |
658 | m_name = op.m_name; | 662 | m_name = op.m_name; |
659 | m_app = op.m_app; | 663 | m_app = op.m_app; |
660 | m_id = op.m_id; | 664 | m_id = op.m_id; |
661 | return (*this); | 665 | return (*this); |
662 | } | 666 | } |
663 | 667 | ||
664 | 668 | ||
665 | bool operator== (const OpieCategories& a, const OpieCategories &b ) | 669 | bool operator== (const OpieCategories& a, const OpieCategories &b ) |
666 | { | 670 | { |
667 | if ( a.id() == b.id() && a.name() == b.name() && a.app() == b.app() ) | 671 | if ( a.id() == b.id() && a.name() == b.name() && a.app() == b.app() ) |
668 | return true; | 672 | return true; |
669 | return false; | 673 | return false; |
670 | } | 674 | } |
671 | 675 | ||
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index b7263bb..4ee3c3c 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,382 +1,330 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | //US #include <qtimer.h> | 36 | //US #include <qtimer.h> |
37 | 37 | ||
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <kconfig.h> | 39 | #include <kconfig.h> |
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | //US #include <ksavefile.h> | 42 | //US #include <ksavefile.h> |
43 | #include <kstandarddirs.h> | 43 | #include <kstandarddirs.h> |
44 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
45 | 45 | ||
46 | #include <qpe/pim/addressbookaccess.h> | 46 | #include <qpe/pim/addressbookaccess.h> |
47 | 47 | ||
48 | 48 | ||
49 | #include "resourceqtopiaconfig.h" | 49 | #include "resourceqtopiaconfig.h" |
50 | #include "stdaddressbook.h" | 50 | #include "stdaddressbook.h" |
51 | 51 | ||
52 | #include "qtopiaconverter.h" | 52 | #include "qtopiaconverter.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | 55 | ||
56 | using namespace KABC; | 56 | using namespace KABC; |
57 | extern "C" | 57 | extern "C" |
58 | { | 58 | { |
59 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
60 | { | 60 | { |
61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | ResourceQtopia::ResourceQtopia( const KConfig *config ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config ) |
66 | : Resource( config ), mConverter (0) | 66 | : Resource( config ), mConverter (0) |
67 | { | 67 | { |
68 | // we can not choose the filename. Therefore use the default to display | 68 | // we can not choose the filename. Therefore use the default to display |
69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
70 | init( fileName ); | 70 | init( fileName ); |
71 | } | 71 | } |
72 | 72 | ||
73 | ResourceQtopia::ResourceQtopia( const QString &fileName ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName ) |
74 | : Resource( 0 ) | 74 | : Resource( 0 ) |
75 | { | 75 | { |
76 | init( fileName ); | 76 | init( fileName ); |
77 | } | 77 | } |
78 | 78 | ||
79 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
80 | { | 80 | { |
81 | 81 | #ifdef _USE_DIRWATCH_ | |
82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
85 | 85 | #endif | |
86 | setFileName( fileName ); | 86 | setFileName( fileName ); |
87 | } | 87 | } |
88 | 88 | ||
89 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
90 | { | 90 | { |
91 | if (mConverter != 0) | 91 | if (mConverter != 0) |
92 | delete mConverter; | 92 | delete mConverter; |
93 | 93 | ||
94 | } | 94 | } |
95 | 95 | ||
96 | void ResourceQtopia::writeConfig( KConfig *config ) | 96 | void ResourceQtopia::writeConfig( KConfig *config ) |
97 | { | 97 | { |
98 | Resource::writeConfig( config ); | 98 | Resource::writeConfig( config ); |
99 | } | 99 | } |
100 | 100 | ||
101 | Ticket *ResourceQtopia::requestSaveTicket() | 101 | Ticket *ResourceQtopia::requestSaveTicket() |
102 | { | 102 | { |
103 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 103 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
104 | 104 | ||
105 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | 105 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); |
106 | 106 | ||
107 | if ( !addressBook() ) return 0; | 107 | if ( !addressBook() ) return 0; |
108 | 108 | ||
109 | if ( !lock( fileName() ) ) { | 109 | if ( !lock( fileName() ) ) { |
110 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 110 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
111 | << fileName() << "'" << endl; | 111 | << fileName() << "'" << endl; |
112 | return 0; | 112 | return 0; |
113 | } | 113 | } |
114 | return createTicket( this ); | 114 | return createTicket( this ); |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | bool ResourceQtopia::doOpen() | 118 | bool ResourceQtopia::doOpen() |
119 | { | 119 | { |
120 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 120 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
121 | 121 | ||
122 | 122 | ||
123 | if (mConverter == 0) | 123 | if (mConverter == 0) |
124 | { | 124 | { |
125 | mConverter = new QtopiaConverter(); | 125 | mConverter = new QtopiaConverter(); |
126 | bool res = mConverter->init(); | 126 | bool res = mConverter->init(); |
127 | if ( !res ) | 127 | if ( !res ) |
128 | { | 128 | { |
129 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 129 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
130 | qDebug(msg); | 130 | qDebug(msg); |
131 | return false; | 131 | return false; |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | return true; | 135 | return true; |
136 | } | 136 | } |
137 | 137 | ||
138 | void ResourceQtopia::doClose() | 138 | void ResourceQtopia::doClose() |
139 | { | 139 | { |
140 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 140 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
141 | 141 | ||
142 | 142 | ||
143 | // it seems so, that deletion of access deletes backend as well | 143 | // it seems so, that deletion of access deletes backend as well |
144 | //delete backend; | 144 | //delete backend; |
145 | 145 | ||
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | 148 | ||
149 | bool ResourceQtopia::load() | 149 | bool ResourceQtopia::load() |
150 | { | 150 | { |
151 | 151 | ||
152 | QFile file( fileName() ); | 152 | QFile file( fileName() ); |
153 | if ( !file.open(IO_ReadOnly ) ) { | 153 | if ( !file.open(IO_ReadOnly ) ) { |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | 156 | ||
157 | QDomDocument doc("mydocument" ); | 157 | QDomDocument doc("mydocument" ); |
158 | if ( !doc.setContent( &file ) ) { | 158 | if ( !doc.setContent( &file ) ) { |
159 | file.close(); | 159 | file.close(); |
160 | return false; | 160 | return false; |
161 | } | 161 | } |
162 | bool res; | 162 | bool res; |
163 | QDomElement docElem = doc.documentElement( ); | 163 | QDomElement docElem = doc.documentElement( ); |
164 | QDomNode n = docElem.firstChild(); | 164 | QDomNode n = docElem.firstChild(); |
165 | while ( !n.isNull() ) { | 165 | while ( !n.isNull() ) { |
166 | QDomElement e = n.toElement(); | 166 | QDomElement e = n.toElement(); |
167 | if ( !e.isNull() ) { | 167 | if ( !e.isNull() ) { |
168 | if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { // we're looking for them | 168 | if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { |
169 | QDomNode no = e.firstChild(); | 169 | QDomNode no = e.firstChild(); |
170 | while ( !no.isNull() ) { | 170 | while ( !no.isNull() ) { |
171 | QDomElement el = no.toElement(); | 171 | QDomElement el = no.toElement(); |
172 | if ( !el.isNull() ) { | 172 | if ( !el.isNull() ) { |
173 | KABC::Addressee addressee; | 173 | KABC::Addressee addressee; |
174 | res = mConverter->qtopiaToAddressee( el, addressee ); | 174 | res = mConverter->qtopiaToAddressee( el, addressee ); |
175 | if ( !addressee.isEmpty() && res ) | 175 | if ( !addressee.isEmpty() && res ) |
176 | { | 176 | { |
177 | addressee.setResource( this ); | 177 | addressee.setResource( this ); |
178 | addressBook()->insertAddressee( addressee ); | 178 | addressBook()->insertAddressee( addressee ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | no = no.nextSibling(); | 182 | no = no.nextSibling(); |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | n = n.nextSibling(); | 187 | n = n.nextSibling(); |
188 | } | 188 | } |
189 | |||
190 | #if 0 | ||
191 | / old code | ||
192 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | ||
193 | |||
194 | AddressBookIterator it(*mAccess); | ||
195 | const PimContact* contact; | ||
196 | bool res; | ||
197 | |||
198 | for (contact=it.toFirst(); it.current(); ++it) | ||
199 | { | ||
200 | contact = it.current(); | ||
201 | |||
202 | KABC::Addressee addressee; | ||
203 | |||
204 | //LRres = mConverter->qtopiaToAddressee( (*contact), addressee ); | ||
205 | |||
206 | if ( !addressee.isEmpty() && res ) | ||
207 | { | ||
208 | addressee.setResource( this ); | ||
209 | addressBook()->insertAddressee( addressee ); | ||
210 | } | ||
211 | } | ||
212 | #endif | ||
213 | return true; | 189 | return true; |
214 | } | 190 | } |
215 | 191 | ||
216 | bool ResourceQtopia::save( Ticket *ticket ) | 192 | bool ResourceQtopia::save( Ticket *ticket ) |
217 | { | 193 | { |
218 | 194 | #ifdef _USE_DIRWATCH_ | |
219 | mDirWatch.stopScan(); | 195 | mDirWatch.stopScan(); |
196 | #endif | ||
220 | KABC::AddressBook::Iterator it; | 197 | KABC::AddressBook::Iterator it; |
221 | bool res; | 198 | bool res; |
222 | //pending open file for stream | 199 | QFile file( fileName() ); |
223 | QTextStream *stream;// = tempFile->textStream(); | 200 | if (!file.open( IO_WriteOnly ) ) { |
201 | return false; | ||
202 | } | ||
203 | QTextStream ts( &file ); | ||
204 | QTextStream *stream = &ts; | ||
224 | stream->setEncoding( QTextStream::UnicodeUTF8 ); | 205 | stream->setEncoding( QTextStream::UnicodeUTF8 ); |
225 | *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; | 206 | *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; |
226 | *stream << " <Groups>" << endl; | 207 | *stream << " <Groups>" << endl; |
227 | *stream << " </Groups>" << endl; | 208 | *stream << " </Groups>" << endl; |
228 | *stream << " <Contacts> " << endl; | 209 | *stream << " <Contacts> " << endl; |
229 | // for all entries | 210 | // for all entries |
230 | KABC::Addressee ab; | 211 | KABC::Addressee ab; |
231 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 212 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
232 | KABC::Addressee addressee = (*it); | 213 | KABC::Addressee addressee = (*it); |
233 | res = mConverter->addresseeToQtopia( addressee, stream ); | 214 | res = mConverter->addresseeToQtopia( addressee, stream ); |
234 | if (!res == true) | 215 | if (!res == true) |
235 | { | 216 | { |
236 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 217 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
237 | } | 218 | } |
238 | } | 219 | } |
239 | |||
240 | |||
241 | *stream << "</Contacts>" << endl; | 220 | *stream << "</Contacts>" << endl; |
242 | *stream << "</AddressBook>" << endl; | 221 | *stream << "</AddressBook>" << endl; |
243 | //pending close file | 222 | file.close(); |
223 | #ifdef _USE_DIRWATCH_ | ||
244 | mDirWatch.startScan(); | 224 | mDirWatch.startScan(); |
245 | 225 | #endif | |
246 | delete ticket; | 226 | delete ticket; |
247 | unlock( fileName() ); | 227 | unlock( fileName() ); |
248 | |||
249 | |||
250 | #if 0 | ||
251 | //old code | ||
252 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | ||
253 | |||
254 | mDirWatch.stopScan(); | ||
255 | |||
256 | KABC::AddressBook::Iterator it; | ||
257 | bool res; | ||
258 | |||
259 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
260 | PimContact c; | ||
261 | KABC::Addressee addressee = (*it); | ||
262 | |||
263 | //res = mConverter->addresseeToQtopia( *it, c ); | ||
264 | if (res == true) | ||
265 | { | ||
266 | mAccess->addContact(c); | ||
267 | // if (res == false) | ||
268 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | // mAccess->addressBookUpdated(); | ||
277 | |||
278 | mDirWatch.startScan(); | ||
279 | |||
280 | delete ticket; | ||
281 | unlock( fileName() ); | ||
282 | #endif | ||
283 | return true; | 228 | return true; |
284 | } | 229 | } |
285 | 230 | ||
286 | bool ResourceQtopia::lock( const QString &lockfileName ) | 231 | bool ResourceQtopia::lock( const QString &lockfileName ) |
287 | { | 232 | { |
233 | //disabled | ||
234 | return true; | ||
288 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 235 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
289 | |||
290 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | ||
291 | |||
292 | QString fn = lockfileName; | 236 | QString fn = lockfileName; |
293 | 237 | ||
294 | KURL url(fn); | 238 | KURL url(fn); |
295 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 239 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
296 | 240 | ||
297 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
298 | |||
299 | if (QFile::exists( lockName )) | 241 | if (QFile::exists( lockName )) |
300 | { | 242 | { |
301 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 243 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
302 | return false; | 244 | return false; |
303 | } | 245 | } |
304 | 246 | ||
305 | QString lockUniqueName; | 247 | QString lockUniqueName; |
306 | lockUniqueName = fn + KApplication::randomString( 8 ); | 248 | lockUniqueName = fn + KApplication::randomString( 8 ); |
307 | 249 | ||
308 | url = lockUniqueName; | 250 | url = lockUniqueName; |
309 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 251 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
310 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 252 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
311 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 253 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
312 | 254 | ||
313 | // Create unique file | 255 | // Create unique file |
314 | QFile file( mLockUniqueName ); | 256 | QFile file( mLockUniqueName ); |
315 | file.open( IO_WriteOnly ); | 257 | file.open( IO_WriteOnly ); |
316 | file.close(); | 258 | file.close(); |
317 | 259 | ||
318 | // Create lock file | 260 | // Create lock file |
319 | int result = 0; | 261 | int result = 0; |
320 | #ifndef _WIN32_ | 262 | #ifndef _WIN32_ |
321 | result = ::link( QFile::encodeName( mLockUniqueName ), | 263 | result = ::link( QFile::encodeName( mLockUniqueName ), |
322 | QFile::encodeName( lockName ) ); | 264 | QFile::encodeName( lockName ) ); |
323 | #endif | 265 | #endif |
324 | if ( result == 0 ) { | 266 | if ( result == 0 ) { |
325 | addressBook()->emitAddressBookLocked(); | 267 | addressBook()->emitAddressBookLocked(); |
326 | return true; | 268 | return true; |
327 | } | 269 | } |
328 | 270 | ||
329 | // TODO: check stat | 271 | // TODO: check stat |
330 | 272 | ||
331 | return false; | 273 | return false; |
332 | } | 274 | } |
333 | 275 | ||
334 | void ResourceQtopia::unlock( const QString &fileName ) | 276 | void ResourceQtopia::unlock( const QString &fileName ) |
335 | { | 277 | { |
278 | //disabled | ||
279 | return; | ||
336 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 280 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
337 | 281 | ||
338 | QString fn = fileName; | 282 | QString fn = fileName; |
339 | KURL url(fn); | 283 | KURL url(fn); |
340 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 284 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
341 | 285 | ||
342 | QFile::remove( lockName ); | 286 | QFile::remove( lockName ); |
343 | QFile::remove( mLockUniqueName ); | 287 | QFile::remove( mLockUniqueName ); |
344 | addressBook()->emitAddressBookUnlocked(); | 288 | addressBook()->emitAddressBookUnlocked(); |
345 | } | 289 | } |
346 | 290 | ||
347 | void ResourceQtopia::setFileName( const QString &newFileName ) | 291 | void ResourceQtopia::setFileName( const QString &newFileName ) |
348 | { | 292 | { |
293 | #ifdef _USE_DIRWATCH_ | ||
349 | mDirWatch.stopScan(); | 294 | mDirWatch.stopScan(); |
295 | #endif | ||
350 | mDirWatch.removeFile( fileName() ); | 296 | mDirWatch.removeFile( fileName() ); |
351 | 297 | ||
352 | Resource::setFileName( newFileName ); | 298 | Resource::setFileName( newFileName ); |
353 | 299 | ||
354 | mDirWatch.addFile( fileName() ); | 300 | mDirWatch.addFile( fileName() ); |
301 | #ifdef _USE_DIRWATCH_ | ||
355 | mDirWatch.startScan(); | 302 | mDirWatch.startScan(); |
303 | #endif | ||
356 | } | 304 | } |
357 | 305 | ||
358 | 306 | ||
359 | void ResourceQtopia::fileChanged() | 307 | void ResourceQtopia::fileChanged() |
360 | { | 308 | { |
361 | // There is a small theoretical chance that KDirWatch calls us before | 309 | // There is a small theoretical chance that KDirWatch calls us before |
362 | // we are fully constructed | 310 | // we are fully constructed |
363 | if (!addressBook()) | 311 | if (!addressBook()) |
364 | return; | 312 | return; |
365 | 313 | ||
366 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 314 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
367 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 315 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
368 | load(); | 316 | load(); |
369 | addressBook()->emitAddressBookChanged(); | 317 | addressBook()->emitAddressBookChanged(); |
370 | } | 318 | } |
371 | } | 319 | } |
372 | 320 | ||
373 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 321 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
374 | { | 322 | { |
375 | } | 323 | } |
376 | 324 | ||
377 | void ResourceQtopia::cleanUp() | 325 | void ResourceQtopia::cleanUp() |
378 | { | 326 | { |
379 | unlock( fileName() ); | 327 | unlock( fileName() ); |
380 | } | 328 | } |
381 | 329 | ||
382 | //US #include "resourceqtopia.moc" | 330 | //US #include "resourceqtopia.moc" |