Diffstat (limited to 'core/pim/addressbook/abview.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/addressbook/abview.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 8d61582..aa242b7 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp | |||
@@ -1,80 +1,80 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) | 2 | ** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** | 14 | ** |
15 | **********************************************************************/ | 15 | **********************************************************************/ |
16 | 16 | ||
17 | #include "abview.h" | 17 | #include "abview.h" |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <opie2/ocontactaccessbackend_vcard.h> |
20 | 20 | ||
21 | #include <qpe/global.h> | 21 | #include <qpe/global.h> |
22 | 22 | ||
23 | #include <opie/ocontactaccessbackend_vcard.h> | 23 | #include <qlayout.h> |
24 | 24 | ||
25 | #include <assert.h> | 25 | #include <assert.h> |
26 | 26 | ||
27 | 27 | ||
28 | // Is defined in LibQPE | 28 | // Is defined in LibQPE |
29 | extern QString categoryFileName(); | 29 | extern QString categoryFileName(); |
30 | 30 | ||
31 | QString addressbookPersonalVCardName() | 31 | QString addressbookPersonalVCardName() |
32 | { | 32 | { |
33 | QString filename = Global::applicationFileName("addressbook", | 33 | QString filename = Global::applicationFileName("addressbook", |
34 | "businesscard.vcf"); | 34 | "businesscard.vcf"); |
35 | return filename; | 35 | return filename; |
36 | } | 36 | } |
37 | 37 | ||
38 | 38 | ||
39 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): | 39 | AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): |
40 | QWidget(parent), | 40 | QWidget(parent), |
41 | mCat(0), | 41 | mCat(0), |
42 | m_inSearch( false ), | 42 | m_inSearch( false ), |
43 | m_inPersonal( false ), | 43 | m_inPersonal( false ), |
44 | m_curr_category( -1 ), | 44 | m_curr_category( -1 ), |
45 | m_curr_View( TableView ), | 45 | m_curr_View( TableView ), |
46 | m_prev_View( TableView ), | 46 | m_prev_View( TableView ), |
47 | m_curr_Contact ( 0 ), | 47 | m_curr_Contact ( 0 ), |
48 | m_contactdb ( 0l ), | 48 | m_contactdb ( 0l ), |
49 | m_storedDB ( 0l ), | 49 | m_storedDB ( 0l ), |
50 | m_viewStack( 0l ), | 50 | m_viewStack( 0l ), |
51 | m_abTable( 0l ), | 51 | m_abTable( 0l ), |
52 | m_orderedFields( ordered ) | 52 | m_orderedFields( ordered ) |
53 | { | 53 | { |
54 | qWarning("AbView::c'tor"); | 54 | qWarning("AbView::c'tor"); |
55 | // Load default database and handle syncing myself.. ! | 55 | // Load default database and handle syncing myself.. ! |
56 | m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ); | 56 | m_contactdb = new Opie::OPimContactAccess ( "addressbook", 0l, 0l, false ); |
57 | m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available | 57 | m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available |
58 | mCat.load( categoryFileName() ); | 58 | mCat.load( categoryFileName() ); |
59 | 59 | ||
60 | // Create Layout and put WidgetStack into it. | 60 | // Create Layout and put WidgetStack into it. |
61 | QVBoxLayout *vb = new QVBoxLayout( this ); | 61 | QVBoxLayout *vb = new QVBoxLayout( this ); |
62 | m_viewStack = new QWidgetStack( this ); | 62 | m_viewStack = new QWidgetStack( this ); |
63 | vb->addWidget( m_viewStack ); | 63 | vb->addWidget( m_viewStack ); |
64 | 64 | ||
65 | // Creat TableView | 65 | // Creat TableView |
66 | QVBox* tableBox = new QVBox( m_viewStack ); | 66 | QVBox* tableBox = new QVBox( m_viewStack ); |
67 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); | 67 | m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); |
68 | m_abTable->setCurrentCell( 0, 0 ); | 68 | m_abTable->setCurrentCell( 0, 0 ); |
69 | m_abTable->setFocus(); | 69 | m_abTable->setFocus(); |
70 | 70 | ||
71 | // Add TableView to WidgetStack and raise it | 71 | // Add TableView to WidgetStack and raise it |
72 | m_viewStack -> addWidget( tableBox , TableView ); | 72 | m_viewStack -> addWidget( tableBox , TableView ); |
73 | 73 | ||
74 | // Create CardView and add it to WidgetStack | 74 | // Create CardView and add it to WidgetStack |
75 | QVBox* cardBox = new QVBox( m_viewStack ); | 75 | QVBox* cardBox = new QVBox( m_viewStack ); |
76 | m_ablabel = new AbLabel( cardBox, "CardView"); | 76 | m_ablabel = new AbLabel( cardBox, "CardView"); |
77 | m_viewStack -> addWidget( cardBox , CardView ); | 77 | m_viewStack -> addWidget( cardBox , CardView ); |
78 | 78 | ||
79 | // Connect views to me | 79 | // Connect views to me |
80 | connect ( m_abTable, SIGNAL( signalSwitch(void) ), | 80 | connect ( m_abTable, SIGNAL( signalSwitch(void) ), |
@@ -83,73 +83,73 @@ AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): | |||
83 | this, SLOT( slotSwitch(void) ) ); | 83 | this, SLOT( slotSwitch(void) ) ); |
84 | 84 | ||
85 | load(); | 85 | load(); |
86 | } | 86 | } |
87 | 87 | ||
88 | AbView::~AbView() | 88 | AbView::~AbView() |
89 | { | 89 | { |
90 | m_contactdb -> save(); | 90 | m_contactdb -> save(); |
91 | delete m_contactdb; | 91 | delete m_contactdb; |
92 | 92 | ||
93 | if ( m_storedDB ){ | 93 | if ( m_storedDB ){ |
94 | m_storedDB -> save(); | 94 | m_storedDB -> save(); |
95 | delete m_storedDB; | 95 | delete m_storedDB; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void AbView::setView( Views view ) | 100 | void AbView::setView( Views view ) |
101 | { | 101 | { |
102 | qWarning("AbView::setView( Views view )"); | 102 | qWarning("AbView::setView( Views view )"); |
103 | m_curr_View = view; | 103 | m_curr_View = view; |
104 | load(); | 104 | load(); |
105 | } | 105 | } |
106 | 106 | ||
107 | void AbView::addEntry( const OContact &newContact ) | 107 | void AbView::addEntry( const Opie::OPimContact &newContact ) |
108 | { | 108 | { |
109 | qWarning("abview:AddContact"); | 109 | qWarning("abview:AddContact"); |
110 | m_contactdb->add ( newContact ); | 110 | m_contactdb->add ( newContact ); |
111 | load(); | 111 | load(); |
112 | 112 | ||
113 | } | 113 | } |
114 | void AbView::removeEntry( const int UID ) | 114 | void AbView::removeEntry( const int UID ) |
115 | { | 115 | { |
116 | qWarning("abview:RemoveContact"); | 116 | qWarning("abview:RemoveContact"); |
117 | m_contactdb->remove( UID ); | 117 | m_contactdb->remove( UID ); |
118 | load(); | 118 | load(); |
119 | } | 119 | } |
120 | 120 | ||
121 | void AbView::replaceEntry( const OContact &contact ) | 121 | void AbView::replaceEntry( const Opie::OPimContact &contact ) |
122 | { | 122 | { |
123 | qWarning("abview:ReplaceContact"); | 123 | qWarning("abview:ReplaceContact"); |
124 | m_contactdb->replace( contact ); | 124 | m_contactdb->replace( contact ); |
125 | load(); | 125 | load(); |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | OContact AbView::currentEntry() | 129 | Opie::OPimContact AbView::currentEntry() |
130 | { | 130 | { |
131 | OContact currentContact; | 131 | Opie::OPimContact currentContact; |
132 | 132 | ||
133 | switch ( (int) m_curr_View ) { | 133 | switch ( (int) m_curr_View ) { |
134 | case TableView: | 134 | case TableView: |
135 | currentContact = m_abTable -> currentEntry(); | 135 | currentContact = m_abTable -> currentEntry(); |
136 | break; | 136 | break; |
137 | case CardView: | 137 | case CardView: |
138 | currentContact = m_ablabel -> currentEntry(); | 138 | currentContact = m_ablabel -> currentEntry(); |
139 | break; | 139 | break; |
140 | } | 140 | } |
141 | m_curr_Contact = currentContact.uid(); | 141 | m_curr_Contact = currentContact.uid(); |
142 | return currentContact; | 142 | return currentContact; |
143 | } | 143 | } |
144 | 144 | ||
145 | bool AbView::save() | 145 | bool AbView::save() |
146 | { | 146 | { |
147 | //qWarning("abView:Save data"); | 147 | //qWarning("abView:Save data"); |
148 | 148 | ||
149 | return m_contactdb->save(); | 149 | return m_contactdb->save(); |
150 | } | 150 | } |
151 | 151 | ||
152 | void AbView::load() | 152 | void AbView::load() |
153 | { | 153 | { |
154 | qWarning("abView:Load data"); | 154 | qWarning("abView:Load data"); |
155 | 155 | ||
@@ -207,112 +207,112 @@ void AbView::setShowByCategory( const QString& cat ) | |||
207 | } | 207 | } |
208 | 208 | ||
209 | } | 209 | } |
210 | 210 | ||
211 | void AbView::setShowToView( Views view ) | 211 | void AbView::setShowToView( Views view ) |
212 | { | 212 | { |
213 | qWarning("void AbView::setShowToView( View %d )", view); | 213 | qWarning("void AbView::setShowToView( View %d )", view); |
214 | 214 | ||
215 | if ( m_curr_View != view ){ | 215 | if ( m_curr_View != view ){ |
216 | qWarning ("Change the View (Category is: %d)", m_curr_category); | 216 | qWarning ("Change the View (Category is: %d)", m_curr_category); |
217 | m_prev_View = m_curr_View; | 217 | m_prev_View = m_curr_View; |
218 | m_curr_View = view; | 218 | m_curr_View = view; |
219 | 219 | ||
220 | updateView(); | 220 | updateView(); |
221 | } | 221 | } |
222 | 222 | ||
223 | } | 223 | } |
224 | 224 | ||
225 | void AbView::setShowByLetter( char c, AbConfig::LPSearchMode mode ) | 225 | void AbView::setShowByLetter( char c, AbConfig::LPSearchMode mode ) |
226 | { | 226 | { |
227 | qWarning("void AbView::setShowByLetter( %c, %d )", c, mode ); | 227 | qWarning("void AbView::setShowByLetter( %c, %d )", c, mode ); |
228 | 228 | ||
229 | assert( mode < AbConfig::LASTELEMENT ); | 229 | assert( mode < AbConfig::LASTELEMENT ); |
230 | 230 | ||
231 | OContact query; | 231 | Opie::OPimContact query; |
232 | if ( c == 0 ){ | 232 | if ( c == 0 ){ |
233 | load(); | 233 | load(); |
234 | return; | 234 | return; |
235 | }else{ | 235 | }else{ |
236 | // If the current Backend is unable to solve the query, we will | 236 | // If the current Backend is unable to solve the query, we will |
237 | // ignore the request .. | 237 | // ignore the request .. |
238 | if ( ! m_contactdb->hasQuerySettings( OContactAccess::WildCards | OContactAccess::IgnoreCase ) ){ | 238 | if ( ! m_contactdb->hasQuerySettings( Opie::OPimContactAccess::WildCards | Opie::OPimContactAccess::IgnoreCase ) ){ |
239 | return; | 239 | return; |
240 | } | 240 | } |
241 | 241 | ||
242 | switch( mode ){ | 242 | switch( mode ){ |
243 | case AbConfig::LastName: | 243 | case AbConfig::LastName: |
244 | query.setLastName( QString("%1*").arg(c) ); | 244 | query.setLastName( QString("%1*").arg(c) ); |
245 | break; | 245 | break; |
246 | case AbConfig::FileAs: | 246 | case AbConfig::FileAs: |
247 | query.setFileAs( QString("%1*").arg(c) ); | 247 | query.setFileAs( QString("%1*").arg(c) ); |
248 | break; | 248 | break; |
249 | default: | 249 | default: |
250 | qWarning( "Unknown Searchmode for AbView::setShowByLetter ! -> %d", mode ); | 250 | qWarning( "Unknown Searchmode for AbView::setShowByLetter ! -> %d", mode ); |
251 | qWarning( "I will ignore it.." ); | 251 | qWarning( "I will ignore it.." ); |
252 | return; | 252 | return; |
253 | } | 253 | } |
254 | m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards | OContactAccess::IgnoreCase ); | 254 | m_list = m_contactdb->queryByExample( query, Opie::OPimContactAccess::WildCards | Opie::OPimContactAccess::IgnoreCase ); |
255 | if ( m_curr_category != -1 ) | 255 | if ( m_curr_category != -1 ) |
256 | clearForCategory(); | 256 | clearForCategory(); |
257 | m_curr_Contact = 0; | 257 | m_curr_Contact = 0; |
258 | } | 258 | } |
259 | updateView( true ); | 259 | updateView( true ); |
260 | } | 260 | } |
261 | 261 | ||
262 | void AbView::setListOrder( const QValueList<int>& ordered ) | 262 | void AbView::setListOrder( const QValueList<int>& ordered ) |
263 | { | 263 | { |
264 | m_orderedFields = ordered; | 264 | m_orderedFields = ordered; |
265 | if ( m_abTable ){ | 265 | if ( m_abTable ){ |
266 | m_abTable->setOrderedList( ordered ); | 266 | m_abTable->setOrderedList( ordered ); |
267 | m_abTable->refresh(); | 267 | m_abTable->refresh(); |
268 | } | 268 | } |
269 | updateView(); | 269 | updateView(); |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | QString AbView::showCategory() const | 273 | QString AbView::showCategory() const |
274 | { | 274 | { |
275 | return mCat.label( "Contacts", m_curr_category ); | 275 | return mCat.label( "Contacts", m_curr_category ); |
276 | } | 276 | } |
277 | 277 | ||
278 | void AbView::showPersonal( bool personal ) | 278 | void AbView::showPersonal( bool personal ) |
279 | { | 279 | { |
280 | qWarning ("void AbView::showPersonal( %d )", personal); | 280 | qWarning ("void AbView::showPersonal( %d )", personal); |
281 | 281 | ||
282 | if ( personal ){ | 282 | if ( personal ){ |
283 | 283 | ||
284 | if ( m_inPersonal ) | 284 | if ( m_inPersonal ) |
285 | return; | 285 | return; |
286 | 286 | ||
287 | // Now switch to vCard Backend and load data. | 287 | // Now switch to vCard Backend and load data. |
288 | // The current default backend will be stored | 288 | // The current default backend will be stored |
289 | // to avoid unneeded load/stores. | 289 | // to avoid unneeded load/stores. |
290 | m_storedDB = m_contactdb; | 290 | m_storedDB = m_contactdb; |
291 | 291 | ||
292 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 292 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
293 | addressbookPersonalVCardName() ); | 293 | addressbookPersonalVCardName() ); |
294 | m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 294 | m_contactdb = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
295 | 295 | ||
296 | m_inPersonal = true; | 296 | m_inPersonal = true; |
297 | m_curr_View = CardView; | 297 | m_curr_View = CardView; |
298 | 298 | ||
299 | }else{ | 299 | }else{ |
300 | 300 | ||
301 | if ( !m_inPersonal ) | 301 | if ( !m_inPersonal ) |
302 | return; | 302 | return; |
303 | 303 | ||
304 | // Remove vCard Backend and restore default | 304 | // Remove vCard Backend and restore default |
305 | m_contactdb->save(); | 305 | m_contactdb->save(); |
306 | delete m_contactdb; | 306 | delete m_contactdb; |
307 | 307 | ||
308 | m_contactdb = m_storedDB; | 308 | m_contactdb = m_storedDB; |
309 | m_storedDB = 0l; | 309 | m_storedDB = 0l; |
310 | 310 | ||
311 | m_curr_View = TableView; | 311 | m_curr_View = TableView; |
312 | m_inPersonal = false; | 312 | m_inPersonal = false; |
313 | 313 | ||
314 | } | 314 | } |
315 | load(); | 315 | load(); |
316 | } | 316 | } |
317 | 317 | ||
318 | void AbView::setCurrentUid( int uid ){ | 318 | void AbView::setCurrentUid( int uid ){ |
@@ -380,66 +380,66 @@ void AbView::offSearch() | |||
380 | } | 380 | } |
381 | 381 | ||
382 | void AbView::slotSwitch(){ | 382 | void AbView::slotSwitch(){ |
383 | //qWarning("AbView::slotSwitch()"); | 383 | //qWarning("AbView::slotSwitch()"); |
384 | 384 | ||
385 | m_prev_View = m_curr_View; | 385 | m_prev_View = m_curr_View; |
386 | switch ( (int) m_curr_View ){ | 386 | switch ( (int) m_curr_View ){ |
387 | case TableView: | 387 | case TableView: |
388 | qWarning("Switching to CardView"); | 388 | qWarning("Switching to CardView"); |
389 | m_curr_View = CardView; | 389 | m_curr_View = CardView; |
390 | break; | 390 | break; |
391 | case CardView: | 391 | case CardView: |
392 | qWarning("Switching to TableView"); | 392 | qWarning("Switching to TableView"); |
393 | m_curr_View = TableView; | 393 | m_curr_View = TableView; |
394 | break; | 394 | break; |
395 | } | 395 | } |
396 | updateView(); | 396 | updateView(); |
397 | 397 | ||
398 | } | 398 | } |
399 | 399 | ||
400 | // END: Slots | 400 | // END: Slots |
401 | 401 | ||
402 | void AbView::clearForCategory() | 402 | void AbView::clearForCategory() |
403 | { | 403 | { |
404 | OContactAccess::List::Iterator it; | 404 | Opie::OPimContactAccess::List::Iterator it; |
405 | // Now remove all contacts with wrong category if any category selected | 405 | // Now remove all contacts with wrong category if any category selected |
406 | 406 | ||
407 | OContactAccess::List allList = m_list; | 407 | Opie::OPimContactAccess::List allList = m_list; |
408 | if ( m_curr_category != -1 ){ | 408 | if ( m_curr_category != -1 ){ |
409 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 409 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
410 | if ( !contactCompare( *it, m_curr_category ) ){ | 410 | if ( !contactCompare( *it, m_curr_category ) ){ |
411 | // qWarning("Removing %d", (*it).uid()); | 411 | // qWarning("Removing %d", (*it).uid()); |
412 | m_list.remove( (*it).uid() ); | 412 | m_list.remove( (*it).uid() ); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | } | 417 | } |
418 | 418 | ||
419 | bool AbView::contactCompare( const OContact &cnt, int category ) | 419 | bool AbView::contactCompare( const Opie::OPimContact &cnt, int category ) |
420 | { | 420 | { |
421 | //qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); | 421 | //qWarning ("bool AbView::contactCompare( const Opie::OPimContact &cnt, %d )", category); |
422 | 422 | ||
423 | bool returnMe; | 423 | bool returnMe; |
424 | QArray<int> cats; | 424 | QArray<int> cats; |
425 | cats = cnt.categories(); | 425 | cats = cnt.categories(); |
426 | 426 | ||
427 | //qWarning ("Number of categories: %d", cats.count() ); | 427 | //qWarning ("Number of categories: %d", cats.count() ); |
428 | 428 | ||
429 | returnMe = false; | 429 | returnMe = false; |
430 | if ( cats.count() == 0 && category == 0 ) | 430 | if ( cats.count() == 0 && category == 0 ) |
431 | // Contacts with no category will just shown on "All" and "Unfiled" | 431 | // Contacts with no category will just shown on "All" and "Unfiled" |
432 | returnMe = true; | 432 | returnMe = true; |
433 | else { | 433 | else { |
434 | int i; | 434 | int i; |
435 | for ( i = 0; i < int(cats.count()); i++ ) { | 435 | for ( i = 0; i < int(cats.count()); i++ ) { |
436 | // qWarning("Comparing %d with %d",cats[i],category ); | 436 | // qWarning("Comparing %d with %d",cats[i],category ); |
437 | if ( cats[i] == category ) { | 437 | if ( cats[i] == category ) { |
438 | returnMe = true; | 438 | returnMe = true; |
439 | break; | 439 | break; |
440 | } | 440 | } |
441 | } | 441 | } |
442 | } | 442 | } |
443 | //qWarning ("Return: %d", returnMe); | 443 | //qWarning ("Return: %d", returnMe); |
444 | return returnMe; | 444 | return returnMe; |
445 | } | 445 | } |