summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/pim/ocontactfields.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/pim/ocontactfields.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/pim/ocontactfields.cpp477
1 files changed, 477 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/ocontactfields.cpp b/noncore/unsupported/libopie/pim/ocontactfields.cpp
new file mode 100644
index 0000000..0f08a5a
--- a/dev/null
+++ b/noncore/unsupported/libopie/pim/ocontactfields.cpp
@@ -0,0 +1,477 @@
1
2#include "ocontactfields.h"
3
4#include <qstringlist.h>
5#include <qobject.h>
6
7// We should use our own enum in the future ..
8#include <qpe/recordfields.h>
9#include <qpe/config.h>
10#include <opie/ocontact.h>
11
12/*!
13 \internal
14 Returns a list of personal field names for a contact.
15*/
16QStringList OContactFields::personalfields( bool sorted, bool translated )
17{
18 QStringList list;
19 QMap<int, QString> mapIdToStr;
20 if ( translated )
21 mapIdToStr = idToTrFields();
22 else
23 mapIdToStr = idToUntrFields();
24
25 list.append( mapIdToStr[ Qtopia::AddressUid ] );
26 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
27
28 list.append( mapIdToStr[ Qtopia::Title ] );
29 list.append( mapIdToStr[ Qtopia::FirstName ] );
30 list.append( mapIdToStr[ Qtopia::MiddleName ] );
31 list.append( mapIdToStr[ Qtopia::LastName ] );
32 list.append( mapIdToStr[ Qtopia::Suffix ] );
33 list.append( mapIdToStr[ Qtopia::FileAs ] );
34
35 list.append( mapIdToStr[ Qtopia::JobTitle ] );
36 list.append( mapIdToStr[ Qtopia::Department ] );
37 list.append( mapIdToStr[ Qtopia::Company ] );
38
39 list.append( mapIdToStr[ Qtopia::Notes ] );
40 list.append( mapIdToStr[ Qtopia::Groups ] );
41
42 if (sorted) list.sort();
43 return list;
44}
45
46/*!
47 \internal
48 Returns a list of details field names for a contact.
49*/
50QStringList OContactFields::detailsfields( bool sorted, bool translated )
51{
52 QStringList list;
53 QMap<int, QString> mapIdToStr;
54 if ( translated )
55 mapIdToStr = idToTrFields();
56 else
57 mapIdToStr = idToUntrFields();
58
59 list.append( mapIdToStr[ Qtopia::Office ] );
60 list.append( mapIdToStr[ Qtopia::Profession ] );
61 list.append( mapIdToStr[ Qtopia::Assistant ] );
62 list.append( mapIdToStr[ Qtopia::Manager ] );
63
64 list.append( mapIdToStr[ Qtopia::Spouse ] );
65 list.append( mapIdToStr[ Qtopia::Gender ] );
66 list.append( mapIdToStr[ Qtopia::Birthday ] );
67 list.append( mapIdToStr[ Qtopia::Anniversary ] );
68 list.append( mapIdToStr[ Qtopia::Nickname ] );
69 list.append( mapIdToStr[ Qtopia::Children ] );
70
71 if (sorted) list.sort();
72 return list;
73}
74
75/*!
76 \internal
77 Returns a list of phone field names for a contact.
78*/
79QStringList OContactFields::phonefields( bool sorted, bool translated )
80{
81 QStringList list;
82 QMap<int, QString> mapIdToStr;
83 if ( translated )
84 mapIdToStr = idToTrFields();
85 else
86 mapIdToStr = idToUntrFields();
87
88 list.append( mapIdToStr[Qtopia::BusinessPhone] );
89 list.append( mapIdToStr[Qtopia::BusinessFax] );
90 list.append( mapIdToStr[Qtopia::BusinessMobile] );
91 list.append( mapIdToStr[Qtopia::BusinessPager] );
92 list.append( mapIdToStr[Qtopia::BusinessWebPage] );
93
94 list.append( mapIdToStr[Qtopia::DefaultEmail] );
95 list.append( mapIdToStr[Qtopia::Emails] );
96
97 list.append( mapIdToStr[Qtopia::HomePhone] );
98 list.append( mapIdToStr[Qtopia::HomeFax] );
99 list.append( mapIdToStr[Qtopia::HomeMobile] );
100 // list.append( mapIdToStr[Qtopia::HomePager] );
101 list.append( mapIdToStr[Qtopia::HomeWebPage] );
102
103 if (sorted) list.sort();
104
105 return list;
106}
107
108/*!
109 \internal
110 Returns a list of field names for a contact.
111*/
112QStringList OContactFields::fields( bool sorted, bool translated )
113{
114 QStringList list;
115 QMap<int, QString> mapIdToStr;
116 if ( translated )
117 mapIdToStr = idToTrFields();
118 else
119 mapIdToStr = idToUntrFields();
120
121 list += personalfields( sorted, translated );
122
123 list += phonefields( sorted, translated );
124
125 list.append( mapIdToStr[Qtopia::BusinessStreet] );
126 list.append( mapIdToStr[Qtopia::BusinessCity] );
127 list.append( mapIdToStr[Qtopia::BusinessState] );
128 list.append( mapIdToStr[Qtopia::BusinessZip] );
129 list.append( mapIdToStr[Qtopia::BusinessCountry] );
130
131 list.append( mapIdToStr[Qtopia::HomeStreet] );
132 list.append( mapIdToStr[Qtopia::HomeCity] );
133 list.append( mapIdToStr[Qtopia::HomeState] );
134 list.append( mapIdToStr[Qtopia::HomeZip] );
135 list.append( mapIdToStr[Qtopia::HomeCountry] );
136
137 list += detailsfields( sorted, translated );
138
139 if (sorted) list.sort();
140
141 return list;
142}
143
144
145/*!
146 \internal
147 Returns an untranslated list of personal field names for a contact.
148*/
149QStringList OContactFields::untrpersonalfields( bool sorted )
150{
151 return personalfields( sorted, false );
152}
153
154
155/*!
156 \internal
157 Returns a translated list of personal field names for a contact.
158*/
159QStringList OContactFields::trpersonalfields( bool sorted )
160{
161 return personalfields( sorted, true );
162}
163
164
165/*!
166 \internal
167 Returns an untranslated list of details field names for a contact.
168*/
169QStringList OContactFields::untrdetailsfields( bool sorted )
170{
171 return detailsfields( sorted, false );
172}
173
174
175/*!
176 \internal
177 Returns a translated list of details field names for a contact.
178*/
179QStringList OContactFields::trdetailsfields( bool sorted )
180{
181 return detailsfields( sorted, true );
182}
183
184
185/*!
186 \internal
187 Returns a translated list of phone field names for a contact.
188*/
189QStringList OContactFields::trphonefields( bool sorted )
190{
191 return phonefields( sorted, true );
192}
193
194/*!
195 \internal
196 Returns an untranslated list of phone field names for a contact.
197*/
198QStringList OContactFields::untrphonefields( bool sorted )
199{
200 return phonefields( sorted, false );
201}
202
203
204/*!
205 \internal
206 Returns a translated list of field names for a contact.
207*/
208QStringList OContactFields::trfields( bool sorted )
209{
210 return fields( sorted, true );
211}
212
213/*!
214 \internal
215 Returns an untranslated list of field names for a contact.
216*/
217QStringList OContactFields::untrfields( bool sorted )
218{
219 return fields( sorted, false );
220}
221
222QMap<int, QString> OContactFields::idToTrFields()
223{
224 QMap<int, QString> ret_map;
225
226 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
227 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
228
229 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") );
230 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
231 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
232 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
233 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ));
234 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
235
236 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
237 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
238 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
239 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
240 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
241 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ));
242
243 // email
244 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
245 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
246
247 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
248 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
249 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
250
251 // business
252 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
253 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
254 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
255 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
256 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
257 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
258 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
259
260 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
261 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
262 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
263 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
264
265 // home
266 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
267 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
268 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
269 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
270 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
271 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
272
273 //personal
274 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
275 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
276 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
277 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
278 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
279 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
280
281 // other
282 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
283
284
285 return ret_map;
286}
287
288QMap<int, QString> OContactFields::idToUntrFields()
289{
290 QMap<int, QString> ret_map;
291
292 ret_map.insert( Qtopia::AddressUid, "User Id" );
293 ret_map.insert( Qtopia::AddressCategory, "Categories" );
294
295 ret_map.insert( Qtopia::Title, "Name Title" );
296 ret_map.insert( Qtopia::FirstName, "First Name" );
297 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
298 ret_map.insert( Qtopia::LastName, "Last Name" );
299 ret_map.insert( Qtopia::Suffix, "Suffix" );
300 ret_map.insert( Qtopia::FileAs, "File As" );
301
302 ret_map.insert( Qtopia::JobTitle, "Job Title" );
303 ret_map.insert( Qtopia::Department, "Department" );
304 ret_map.insert( Qtopia::Company, "Company" );
305 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
306 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
307 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
308
309 // email
310 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
311 ret_map.insert( Qtopia::Emails, "Emails" );
312
313 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
314 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
315 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
316
317 // business
318 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
319 ret_map.insert( Qtopia::BusinessCity, "Business City" );
320 ret_map.insert( Qtopia::BusinessState, "Business State" );
321 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
322 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
323 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
324 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
325
326 ret_map.insert( Qtopia::Office, "Office" );
327 ret_map.insert( Qtopia::Profession, "Profession" );
328 ret_map.insert( Qtopia::Assistant, "Assistant" );
329 ret_map.insert( Qtopia::Manager, "Manager" );
330
331 // home
332 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
333 ret_map.insert( Qtopia::HomeCity, "Home City" );
334 ret_map.insert( Qtopia::HomeState, "Home State" );
335 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
336 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
337 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
338
339 //personal
340 ret_map.insert( Qtopia::Spouse, "Spouse" );
341 ret_map.insert( Qtopia::Gender, "Gender" );
342 ret_map.insert( Qtopia::Birthday, "Birthday" );
343 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
344 ret_map.insert( Qtopia::Nickname, "Nickname" );
345 ret_map.insert( Qtopia::Children, "Children" );
346
347 // other
348 ret_map.insert( Qtopia::Notes, "Notes" );
349 ret_map.insert( Qtopia::Groups, "Groups" );
350
351
352 return ret_map;
353}
354
355QMap<QString, int> OContactFields::trFieldsToId()
356{
357 QMap<int, QString> idtostr = idToTrFields();
358 QMap<QString, int> ret_map;
359
360
361 QMap<int, QString>::Iterator it;
362 for( it = idtostr.begin(); it != idtostr.end(); ++it )
363 ret_map.insert( *it, it.key() );
364
365
366 return ret_map;
367}
368
369/* ======================================================================= */
370
371QMap<QString, int> OContactFields::untrFieldsToId()
372{
373 QMap<int, QString> idtostr = idToUntrFields();
374 QMap<QString, int> ret_map;
375
376
377 QMap<int, QString>::Iterator it;
378 for( it = idtostr.begin(); it != idtostr.end(); ++it )
379 ret_map.insert( *it, it.key() );
380
381
382 return ret_map;
383}
384
385
386OContactFields::OContactFields():
387 fieldOrder( DEFAULT_FIELD_ORDER ),
388 changedFieldOrder( false )
389{
390 // Get the global field order from the config file and
391 // use it as a start pattern
392 Config cfg ( "AddressBook" );
393 cfg.setGroup( "ContactFieldOrder" );
394 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
395}
396
397OContactFields::~OContactFields(){
398
399 // We will store the fieldorder into the config file
400 // to reuse it for the future..
401 if ( changedFieldOrder ){
402 Config cfg ( "AddressBook" );
403 cfg.setGroup( "ContactFieldOrder" );
404 cfg.writeEntry( "General", globalFieldOrder );
405 }
406}
407
408
409
410void OContactFields::saveToRecord( OContact &cnt ){
411
412 qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1());
413
414 // Store fieldorder into this contact.
415 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
416
417 globalFieldOrder = fieldOrder;
418 changedFieldOrder = true;
419
420}
421
422void OContactFields::loadFromRecord( const OContact &cnt ){
423 qDebug("ocontactfields loadFromRecord");
424 qDebug("loading >%s<",cnt.fullName().latin1());
425
426 // Get fieldorder for this contact. If none is defined,
427 // we will use the global one from the config file..
428
429 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
430
431 qDebug("fieldOrder from contact>%s<",fieldOrder.latin1());
432
433 if (fieldOrder.isEmpty()){
434 fieldOrder = globalFieldOrder;
435 }
436
437
438 qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1());
439}
440
441void OContactFields::setFieldOrder( int num, int index ){
442 qDebug("qcontactfields setfieldorder pos %i -> %i",num,index);
443
444 fieldOrder[num] = QString::number( index, 16 )[0];
445
446 // We will store this new fieldorder globally to
447 // remember it for contacts which have none
448 globalFieldOrder = fieldOrder;
449 changedFieldOrder = true;
450
451 qDebug("fieldOrder >%s<",fieldOrder.latin1());
452}
453
454int OContactFields::getFieldOrder( int num, int defIndex ){
455 qDebug("ocontactfields getFieldOrder");
456 qDebug("fieldOrder >%s<",fieldOrder.latin1());
457
458 // Get index of combo as char..
459 QChar poschar = fieldOrder[num];
460
461 bool ok;
462 int ret = 0;
463 // Convert char to number..
464 if ( !( poschar == QChar::null ) )
465 ret = QString( poschar ).toInt(&ok, 16);
466 else
467 ok = false;
468
469 // Return default value if index for
470 // num was not set or if anything else happened..
471 if ( !ok ) ret = defIndex;
472
473 qDebug("returning >%i<",ret);
474
475 return ret;
476
477}