summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abview.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp
index 34035fd..8a2db96 100644
--- a/core/pim/addressbook/abview.cpp
+++ b/core/pim/addressbook/abview.cpp
@@ -1,516 +1,526 @@
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 <opie2/ocontactaccessbackend_vcard.h> 19#include <opie2/ocontactaccessbackend_vcard.h>
20#include <opie2/odebug.h> 20#include <opie2/odebug.h>
21 21
22#include <qpe/global.h> 22#include <qpe/global.h>
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25 25
26#include <assert.h> 26#include <assert.h>
27 27
28 28
29// Is defined in LibQPE 29// Is defined in LibQPE
30extern QString categoryFileName(); 30extern QString categoryFileName();
31 31
32QString addressbookPersonalVCardName() 32QString addressbookPersonalVCardName()
33{ 33{
34 QString filename = Global::applicationFileName("addressbook", 34 QString filename = Global::applicationFileName("addressbook",
35 "businesscard.vcf"); 35 "businesscard.vcf");
36 return filename; 36 return filename;
37} 37}
38 38
39 39
40AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): 40AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ):
41 QWidget(parent), 41 QWidget(parent),
42 mCat(0), 42 mCat(0),
43 m_inSearch( false ), 43 m_inSearch( false ),
44 m_inPersonal( false ), 44 m_inPersonal( false ),
45 m_curr_category( 0 ), 45 m_curr_category( 0 ),
46 m_curr_View( TableView ), 46 m_curr_View( TableView ),
47 m_prev_View( TableView ), 47 m_prev_View( TableView ),
48 m_curr_Contact ( 0 ), 48 m_curr_Contact ( 0 ),
49 m_contactdb ( 0l ), 49 m_contactdb ( 0l ),
50 m_storedDB ( 0l ), 50 m_storedDB ( 0l ),
51 m_viewStack( 0l ), 51 m_viewStack( 0l ),
52 m_abTable( 0l ), 52 m_abTable( 0l ),
53 m_orderedFields( ordered ) 53 m_orderedFields( ordered )
54{ 54{
55 odebug << "AbView::c'tor" << oendl; 55 odebug << "AbView::c'tor" << oendl;
56 // Load default database and handle syncing myself.. ! 56 // Load default database and handle syncing myself.. !
57 m_contactdb = new Opie::OPimContactAccess ( "addressbook", 0l, 0l, false ); 57 m_contactdb = new Opie::OPimContactAccess ( "addressbook", 0l, 0l, false );
58 m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available 58 m_contactdb -> setReadAhead( 16 ); // Use ReadAhead-Cache if available
59 mCat.load( categoryFileName() ); 59 mCat.load( categoryFileName() );
60 60
61 // Create Layout and put WidgetStack into it. 61 // Create Layout and put WidgetStack into it.
62 QVBoxLayout *vb = new QVBoxLayout( this ); 62 QVBoxLayout *vb = new QVBoxLayout( this );
63 m_viewStack = new QWidgetStack( this ); 63 m_viewStack = new QWidgetStack( this );
64 vb->addWidget( m_viewStack ); 64 vb->addWidget( m_viewStack );
65 65
66 // Creat TableView 66 // Creat TableView
67 QVBox* tableBox = new QVBox( m_viewStack ); 67 QVBox* tableBox = new QVBox( m_viewStack );
68 m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); 68 m_abTable = new AbTable( m_orderedFields, tableBox, "table" );
69 m_abTable->setCurrentCell( 0, 0 ); 69 m_abTable->setCurrentCell( 0, 0 );
70 m_abTable->setFocus(); 70 m_abTable->setFocus();
71 71
72 // Add TableView to WidgetStack and raise it 72 // Add TableView to WidgetStack and raise it
73 m_viewStack -> addWidget( tableBox , TableView ); 73 m_viewStack -> addWidget( tableBox , TableView );
74 74
75 // Create CardView and add it to WidgetStack 75 // Create CardView and add it to WidgetStack
76 QVBox* cardBox = new QVBox( m_viewStack ); 76 QVBox* cardBox = new QVBox( m_viewStack );
77 m_ablabel = new AbLabel( cardBox, "CardView"); 77 m_ablabel = new AbLabel( cardBox, "CardView");
78 m_viewStack -> addWidget( cardBox , CardView ); 78 m_viewStack -> addWidget( cardBox , CardView );
79 79
80 // Connect views to me 80 // Connect views to me
81 connect ( m_abTable, SIGNAL( signalSwitch(void) ), 81 connect ( m_abTable, SIGNAL( signalSwitch(void) ),
82 this, SLOT( slotSwitch(void) ) ); 82 this, SLOT( slotSwitch(void) ) );
83 connect ( m_ablabel, SIGNAL( signalOkPressed(void) ), 83 connect ( m_ablabel, SIGNAL( signalOkPressed(void) ),
84 this, SLOT( slotSwitch(void) ) ); 84 this, SLOT( slotSwitch(void) ) );
85 85
86 load(); 86 load();
87} 87}
88 88
89AbView::~AbView() 89AbView::~AbView()
90{ 90{
91 m_contactdb -> save(); 91 m_contactdb -> save();
92 delete m_contactdb; 92 delete m_contactdb;
93 93
94 if ( m_storedDB ){ 94 if ( m_storedDB ){
95 m_storedDB -> save(); 95 m_storedDB -> save();
96 delete m_storedDB; 96 delete m_storedDB;
97 } 97 }
98} 98}
99 99
100 100
101void AbView::setView( Views view ) 101void AbView::setView( Views view )
102{ 102{
103 odebug << "AbView::setView( Views view )" << oendl; 103 odebug << "AbView::setView( Views view )" << oendl;
104 m_curr_View = view; 104 m_curr_View = view;
105 load(); 105 load();
106} 106}
107 107
108void AbView::addEntry( const Opie::OPimContact &newContact ) 108void AbView::addEntry( const Opie::OPimContact &newContact )
109{ 109{
110 odebug << "AbView::AddContact" << oendl; 110 odebug << "AbView::AddContact" << oendl;
111 m_contactdb->add ( newContact ); 111 m_contactdb->add ( newContact );
112 load(); 112 load();
113 113
114} 114}
115void AbView::removeEntry( const int UID ) 115void AbView::removeEntry( const int UID )
116{ 116{
117 odebug << "AbView;:RemoveContact" << oendl; 117 odebug << "AbView;:RemoveContact" << oendl;
118 m_contactdb->remove( UID ); 118 m_contactdb->remove( UID );
119 load(); 119 load();
120} 120}
121 121
122void AbView::replaceEntry( const Opie::OPimContact &contact ) 122void AbView::replaceEntry( const Opie::OPimContact &contact )
123{ 123{
124 odebug << "AbView::ReplaceContact" << oendl; 124 odebug << "AbView::ReplaceContact" << oendl;
125 m_contactdb->replace( contact ); 125 m_contactdb->replace( contact );
126 load(); 126 load();
127 127
128} 128}
129 129
130Opie::OPimContact AbView::currentEntry() 130Opie::OPimContact AbView::currentEntry()
131{ 131{
132 Opie::OPimContact currentContact; 132 Opie::OPimContact currentContact;
133 133
134 switch ( (int) m_curr_View ) { 134 switch ( (int) m_curr_View ) {
135 case TableView: 135 case TableView:
136 currentContact = m_abTable -> currentEntry(); 136 currentContact = m_abTable -> currentEntry();
137 break; 137 break;
138 case CardView: 138 case CardView:
139 currentContact = m_ablabel -> currentEntry(); 139 currentContact = m_ablabel -> currentEntry();
140 break; 140 break;
141 } 141 }
142 m_curr_Contact = currentContact.uid(); 142 m_curr_Contact = currentContact.uid();
143 return currentContact; 143 return currentContact;
144} 144}
145 145
146bool AbView::save() 146bool AbView::save()
147{ 147{
148 //odebug << "AbView::Save data" << oendl; 148 //odebug << "AbView::Save data" << oendl;
149 149
150 return m_contactdb->save(); 150 return m_contactdb->save();
151} 151}
152 152
153void AbView::load() 153void AbView::load()
154{ 154{
155 odebug << "AbView::Load data" << oendl; 155 odebug << "AbView::Load data" << oendl;
156 156
157 // Letter Search is stopped at this place 157 // Letter Search is stopped at this place
158 emit signalClearLetterPicker(); 158 emit signalClearLetterPicker();
159 159
160 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName, 160 odebug << "selected Category: " << m_curr_category << oendl;
161 Opie::OPimContactAccess::FilterCategory, m_curr_category ); 161
162 162 if ( m_curr_category == -1 ) {
163 // if ( m_curr_category != -1 ) 163 // Show just unfiled contacts
164 // clearForCategory(); 164 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName,
165 Opie::OPimContactAccess::DoNotShowWithCategory, 0 );
166 } elseif ( m_curr_category == 0 ){
167 // Just show all contacts
168 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName,
169 Opie::OPimBase::FilterOff, 0 );
170 } else {
171 // Show contacts with given categories
172 m_list = m_contactdb->sorted( true, Opie::OPimContactAccess::SortFileAsName,
173 Opie::OPimBase::FilterCategory, m_curr_category );
174 }
165 175
166 odebug << "Number of contacts: " << m_list.count() << oendl; 176 odebug << "Number of contacts: " << m_list.count() << oendl;
167 177
168 updateView( true ); 178 updateView( true );
169 179
170} 180}
171 181
172void AbView::reload() 182void AbView::reload()
173{ 183{
174 odebug << "AbView::::reload()" << oendl; 184 odebug << "AbView::::reload()" << oendl;
175 185
176 m_contactdb->reload(); 186 m_contactdb->reload();
177 load(); 187 load();
178} 188}
179 189
180void AbView::clear() 190void AbView::clear()
181{ 191{
182 // :SX 192 // :SX
183} 193}
184 194
185void AbView::setShowByCategory( const QString& cat ) 195void AbView::setShowByCategory( const QString& cat )
186{ 196{
187 odebug << "AbView::setShowCategory( const QString& cat )" << oendl; 197 odebug << "AbView::setShowCategory( const QString& cat )" << oendl;
188 198
189 int intCat = 0; 199 int intCat = 0;
190 200
191 // Unfiled will be stored as -1 201 // Unfiled will be stored as -1
192 if ( cat == tr( "Unfiled" ) ) 202 if ( cat == tr( "Unfiled" ) )
193 intCat = -1; 203 intCat = -1;
194 else if ( cat.isNull() ) 204 else if ( cat.isNull() )
195 intCat = 0; 205 intCat = 0;
196 else 206 else
197 intCat = mCat.id("Contacts", cat ); 207 intCat = mCat.id("Contacts", cat );
198 208
199 // Just do anything if we really change the category 209 // Just do anything if we really change the category
200 if ( intCat != m_curr_category ){ 210 if ( intCat != m_curr_category ){
201 // odebug << "Categories: Selected " << cat << ".. Number: " 211 // odebug << "Categories: Selected " << cat << ".. Number: "
202 // << m_curr_category << oendl; 212 // << m_curr_category << oendl;
203 213
204 m_curr_category = intCat; 214 m_curr_category = intCat;
205 emit signalClearLetterPicker(); 215 emit signalClearLetterPicker();
206 load(); 216 load();
207 } 217 }
208 m_curr_category = intCat; 218 m_curr_category = intCat;
209 219
210} 220}
211 221
212void AbView::setShowToView( Views view ) 222void AbView::setShowToView( Views view )
213{ 223{
214 odebug << "void AbView::setShowToView( View " << view << " )" << oendl; 224 odebug << "void AbView::setShowToView( View " << view << " )" << oendl;
215 225
216 if ( m_curr_View != view ){ 226 if ( m_curr_View != view ){
217 odebug << "Change the View (Category is: " << m_curr_category << ")" << oendl; 227 odebug << "Change the View (Category is: " << m_curr_category << ")" << oendl;
218 m_prev_View = m_curr_View; 228 m_prev_View = m_curr_View;
219 m_curr_View = view; 229 m_curr_View = view;
220 230
221 updateView(); 231 updateView();
222 } 232 }
223 233
224} 234}
225 235
226void AbView::setShowByLetter( char c, AbConfig::LPSearchMode mode ) 236void AbView::setShowByLetter( char c, AbConfig::LPSearchMode mode )
227{ 237{
228 odebug << "void AbView::setShowByLetter( " << c << ", " << mode << " )" << oendl; 238 odebug << "void AbView::setShowByLetter( " << c << ", " << mode << " )" << oendl;
229 239
230 assert( mode < AbConfig::LASTELEMENT ); 240 assert( mode < AbConfig::LASTELEMENT );
231 241
232 Opie::OPimContact query; 242 Opie::OPimContact query;
233 if ( c == 0 ){ 243 if ( c == 0 ){
234 load(); 244 load();
235 return; 245 return;
236 }else{ 246 }else{
237 // If the current Backend is unable to solve the query, we will 247 // If the current Backend is unable to solve the query, we will
238 // ignore the request .. 248 // ignore the request ..
239 if ( ! m_contactdb->hasQuerySettings( Opie::OPimContactAccess::WildCards | 249 if ( ! m_contactdb->hasQuerySettings( Opie::OPimContactAccess::WildCards |
240 Opie::OPimContactAccess::IgnoreCase ) ){ 250 Opie::OPimContactAccess::IgnoreCase ) ){
241 owarn << "Tried to access queryByExample which is not supported by the current backend!!" << oendl; 251 owarn << "Tried to access queryByExample which is not supported by the current backend!!" << oendl;
242 owarn << "I have to ignore this access!" << oendl; 252 owarn << "I have to ignore this access!" << oendl;
243 return; 253 return;
244 } 254 }
245 255
246 switch( mode ){ 256 switch( mode ){
247 case AbConfig::LastName: 257 case AbConfig::LastName:
248 query.setLastName( QString("%1*").arg(c) ); 258 query.setLastName( QString("%1*").arg(c) );
249 break; 259 break;
250 case AbConfig::FileAs: 260 case AbConfig::FileAs:
251 query.setFileAs( QString("%1*").arg(c) ); 261 query.setFileAs( QString("%1*").arg(c) );
252 break; 262 break;
253 default: 263 default:
254 owarn << "Unknown Searchmode for AbView::setShowByLetter ! -> " << mode << oendl 264 owarn << "Unknown Searchmode for AbView::setShowByLetter ! -> " << mode << oendl
255 << "I will ignore it.." << oendl; 265 << "I will ignore it.." << oendl;
256 return; 266 return;
257 } 267 }
258 m_list = m_contactdb->queryByExample( query, Opie::OPimContactAccess::WildCards | Opie::OPimContactAccess::IgnoreCase ); 268 m_list = m_contactdb->queryByExample( query, Opie::OPimContactAccess::WildCards | Opie::OPimContactAccess::IgnoreCase );
259 269
260 if ( m_curr_category != 0 ) 270 if ( m_curr_category != 0 )
261 clearForCategory(); 271 clearForCategory();
262 272
263 // Sort filtered results 273 // Sort filtered results
264 m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortFileAsName, 274 m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortFileAsName,
265 Opie::OPimContactAccess::FilterCategory, m_curr_category ); 275 Opie::OPimContactAccess::FilterCategory, m_curr_category );
266 m_curr_Contact = 0; 276 m_curr_Contact = 0;
267 } 277 }
268 updateView( true ); 278 updateView( true );
269} 279}
270 280
271void AbView::setListOrder( const QValueList<int>& ordered ) 281void AbView::setListOrder( const QValueList<int>& ordered )
272{ 282{
273 m_orderedFields = ordered; 283 m_orderedFields = ordered;
274 if ( m_abTable ){ 284 if ( m_abTable ){
275 m_abTable->setOrderedList( ordered ); 285 m_abTable->setOrderedList( ordered );
276 m_abTable->refresh(); 286 m_abTable->refresh();
277 } 287 }
278 updateView(); 288 updateView();
279} 289}
280 290
281 291
282QString AbView::showCategory() const 292QString AbView::showCategory() const
283{ 293{
284 return mCat.label( "Contacts", m_curr_category ); 294 return mCat.label( "Contacts", m_curr_category );
285} 295}
286 296
287void AbView::showPersonal( bool personal ) 297void AbView::showPersonal( bool personal )
288{ 298{
289 odebug << "void AbView::showPersonal( " << personal << " )" << oendl; 299 odebug << "void AbView::showPersonal( " << personal << " )" << oendl;
290 300
291 if ( personal ){ 301 if ( personal ){
292 302
293 if ( m_inPersonal ) 303 if ( m_inPersonal )
294 return; 304 return;
295 305
296 // Now switch to vCard Backend and load data. 306 // Now switch to vCard Backend and load data.
297 // The current default backend will be stored 307 // The current default backend will be stored
298 // to avoid unneeded load/stores. 308 // to avoid unneeded load/stores.
299 m_storedDB = m_contactdb; 309 m_storedDB = m_contactdb;
300 310
301 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 311 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
302 addressbookPersonalVCardName() ); 312 addressbookPersonalVCardName() );
303 m_contactdb = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 313 m_contactdb = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
304 314
305 m_inPersonal = true; 315 m_inPersonal = true;
306 m_curr_View = CardView; 316 m_curr_View = CardView;
307 317
308 }else{ 318 }else{
309 319
310 if ( !m_inPersonal ) 320 if ( !m_inPersonal )
311 return; 321 return;
312 322
313 // Remove vCard Backend and restore default 323 // Remove vCard Backend and restore default
314 m_contactdb->save(); 324 m_contactdb->save();
315 delete m_contactdb; 325 delete m_contactdb;
316 326
317 m_contactdb = m_storedDB; 327 m_contactdb = m_storedDB;
318 m_storedDB = 0l; 328 m_storedDB = 0l;
319 329
320 m_curr_View = TableView; 330 m_curr_View = TableView;
321 m_inPersonal = false; 331 m_inPersonal = false;
322 332
323 } 333 }
324 load(); 334 load();
325} 335}
326 336
327void AbView::setCurrentUid( int uid ){ 337void AbView::setCurrentUid( int uid ){
328 338
329 m_curr_Contact = uid; 339 m_curr_Contact = uid;
330 updateView( true ); //true: Don't modificate the UID ! 340 updateView( true ); //true: Don't modificate the UID !
331} 341}
332 342
333 343
334QStringList AbView::categories() 344QStringList AbView::categories()
335{ 345{
336 mCat.load( categoryFileName() ); 346 mCat.load( categoryFileName() );
337 QStringList categoryList = mCat.labels( "Contacts" ); 347 QStringList categoryList = mCat.labels( "Contacts" );
338 return categoryList; 348 return categoryList;
339} 349}
340 350
341// BEGIN: Slots 351// BEGIN: Slots
342void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, 352void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
343 bool , QString cat ) 353 bool , QString cat )
344{ 354{
345 //owarn << "void AbView::slotDoFind" << oendl; 355 //owarn << "void AbView::slotDoFind" << oendl;
346 356
347 // We reloading the data: Deselect Letterpicker 357 // We reloading the data: Deselect Letterpicker
348 emit signalClearLetterPicker(); 358 emit signalClearLetterPicker();
349 359
350 // Use the current Category if nothing else selected 360 // Use the current Category if nothing else selected
351 int category = 0; 361 int category = 0;
352 362
353 if ( cat.isEmpty() ) 363 if ( cat.isEmpty() )
354 category = m_curr_category; 364 category = m_curr_category;
355 else{ 365 else{
356 category = mCat.id("Contacts", cat ); 366 category = mCat.id("Contacts", cat );
357 } 367 }
358 368
359 //odebug << "Find in Category " << category << oendl; 369 //odebug << "Find in Category " << category << oendl;
360 370
361 QRegExp r( str ); 371 QRegExp r( str );
362 r.setCaseSensitive( caseSensitive ); 372 r.setCaseSensitive( caseSensitive );
363 r.setWildcard( !useRegExp ); 373 r.setWildcard( !useRegExp );
364 374
365 // Get all matching entries out of the database 375 // Get all matching entries out of the database
366 m_list = m_contactdb->matchRegexp( r ); 376 m_list = m_contactdb->matchRegexp( r );
367 377
368 //odebug << "Found: " << m_list.count() << oendl; 378 //odebug << "Found: " << m_list.count() << oendl;
369 if ( m_list.count() == 0 ){ 379 if ( m_list.count() == 0 ){
370 emit signalNotFound(); 380 emit signalNotFound();
371 return; 381 return;
372 } 382 }
373 383
374 // Now remove all contacts with wrong category (if any selected) 384 // Now remove all contacts with wrong category (if any selected)
375 // This algorithm is a litte bit ineffective, but 385 // This algorithm is a litte bit ineffective, but
376 // we will not have a lot of matching entries.. 386 // we will not have a lot of matching entries..
377 if ( m_curr_category != 0 ) 387 if ( m_curr_category != 0 )
378 clearForCategory(); 388 clearForCategory();
379 389
380 // Now show all found entries 390 // Now show all found entries
381 updateView( true ); 391 updateView( true );
382} 392}
383 393
384void AbView::offSearch() 394void AbView::offSearch()
385{ 395{
386 m_inSearch = false; 396 m_inSearch = false;
387 397
388 load(); 398 load();
389} 399}
390 400
391void AbView::slotSwitch(){ 401void AbView::slotSwitch(){
392 //odebug << "AbView::slotSwitch()" << oendl; 402 //odebug << "AbView::slotSwitch()" << oendl;
393 403
394 m_prev_View = m_curr_View; 404 m_prev_View = m_curr_View;
395 switch ( (int) m_curr_View ){ 405 switch ( (int) m_curr_View ){
396 case TableView: 406 case TableView:
397 odebug << "Switching to CardView" << oendl; 407 odebug << "Switching to CardView" << oendl;
398 m_curr_View = CardView; 408 m_curr_View = CardView;
399 break; 409 break;
400 case CardView: 410 case CardView:
401 odebug << "Switching to TableView" << oendl; 411 odebug << "Switching to TableView" << oendl;
402 m_curr_View = TableView; 412 m_curr_View = TableView;
403 break; 413 break;
404 } 414 }
405 updateView(); 415 updateView();
406 416
407} 417}
408 418
409// END: Slots 419// END: Slots
410 420
411void AbView::clearForCategory() 421void AbView::clearForCategory()
412{ 422{
413 Opie::OPimContactAccess::List::Iterator it; 423 Opie::OPimContactAccess::List::Iterator it;
414 // Now remove all contacts with wrong category if any category selected 424 // Now remove all contacts with wrong category if any category selected
415 425
416 Opie::OPimContactAccess::List allList = m_list; 426 Opie::OPimContactAccess::List allList = m_list;
417 if ( m_curr_category != 0 ){ 427 if ( m_curr_category != 0 ){
418 for ( it = allList.begin(); it != allList.end(); ++it ){ 428 for ( it = allList.begin(); it != allList.end(); ++it ){
419 if ( !contactCompare( *it, m_curr_category ) ){ 429 if ( !contactCompare( *it, m_curr_category ) ){
420 //odebug << "Removing " << (*it).uid() << oendl; 430 //odebug << "Removing " << (*it).uid() << oendl;
421 m_list.remove( (*it).uid() ); 431 m_list.remove( (*it).uid() );
422 } 432 }
423 } 433 }
424 } 434 }
425 435
426} 436}
427 437
428bool AbView::contactCompare( const Opie::OPimContact &cnt, int category ) 438bool AbView::contactCompare( const Opie::OPimContact &cnt, int category )
429{ 439{
430 //odebug << "bool AbView::contactCompare( const Opie::OPimContact &cnt, " 440 //odebug << "bool AbView::contactCompare( const Opie::OPimContact &cnt, "
431 // << category << " )" << oendl; 441 // << category << " )" << oendl;
432 442
433 bool returnMe; 443 bool returnMe;
434 QArray<int> cats; 444 QArray<int> cats;
435 cats = cnt.categories(); 445 cats = cnt.categories();
436 446
437 //odebug << "Number of categories: " << cats.count() << oendl; 447 //odebug << "Number of categories: " << cats.count() << oendl;
438 448
439 returnMe = false; 449 returnMe = false;
440 if ( cats.count() == 0 && category == -1 ) 450 if ( cats.count() == 0 && category == -1 )
441 // Contacts with no category will just shown on "All" and "Unfiled" 451 // Contacts with no category will just shown on "All" and "Unfiled"
442 returnMe = true; 452 returnMe = true;
443 else { 453 else {
444 int i; 454 int i;
445 for ( i = 0; i < int(cats.count()); i++ ) { 455 for ( i = 0; i < int(cats.count()); i++ ) {
446 //odebug << "Comparing " << cats[i] << " with " << category << oendl; 456 //odebug << "Comparing " << cats[i] << " with " << category << oendl;
447 if ( cats[i] == category ) { 457 if ( cats[i] == category ) {
448 returnMe = true; 458 returnMe = true;
449 break; 459 break;
450 } 460 }
451 } 461 }
452 } 462 }
453 //odebug << "Return: " << returnMe << oendl; 463 //odebug << "Return: " << returnMe << oendl;
454 return returnMe; 464 return returnMe;
455} 465}
456 466
457// In Some rare cases we have to update all lists.. 467// In Some rare cases we have to update all lists..
458void AbView::updateListinViews() 468void AbView::updateListinViews()
459{ 469{
460 m_abTable -> setContacts( m_list ); 470 m_abTable -> setContacts( m_list );
461 m_ablabel -> setContacts( m_list ); 471 m_ablabel -> setContacts( m_list );
462} 472}
463 473
464void AbView::updateView( bool newdata ) 474void AbView::updateView( bool newdata )
465{ 475{
466 //odebug << "AbView::updateView()" << oendl; 476 //odebug << "AbView::updateView()" << oendl;
467 477
468 if ( m_viewStack -> visibleWidget() ){ 478 if ( m_viewStack -> visibleWidget() ){
469 m_viewStack -> visibleWidget() -> clearFocus(); 479 m_viewStack -> visibleWidget() -> clearFocus();
470 } 480 }
471 481
472 // If we switching the view, we have to store some information 482 // If we switching the view, we have to store some information
473 if ( !newdata ){ 483 if ( !newdata ){
474 if ( m_list.count() ){ 484 if ( m_list.count() ){
475 switch ( (int) m_prev_View ) { 485 switch ( (int) m_prev_View ) {
476 case TableView: 486 case TableView:
477 m_curr_Contact = m_abTable -> currentEntry_UID(); 487 m_curr_Contact = m_abTable -> currentEntry_UID();
478 break; 488 break;
479 case CardView: 489 case CardView:
480 m_curr_Contact = m_ablabel -> currentEntry_UID(); 490 m_curr_Contact = m_ablabel -> currentEntry_UID();
481 break; 491 break;
482 } 492 }
483 }else 493 }else
484 m_curr_Contact = 0; 494 m_curr_Contact = 0;
485 } 495 }
486 496
487 // Feed all views with new lists 497 // Feed all views with new lists
488 if ( newdata ) 498 if ( newdata )
489 updateListinViews(); 499 updateListinViews();
490 500
491 // Tell the world that the view is changed 501 // Tell the world that the view is changed
492 if ( m_curr_View != m_prev_View ) 502 if ( m_curr_View != m_prev_View )
493 emit signalViewSwitched ( (int) m_curr_View ); 503 emit signalViewSwitched ( (int) m_curr_View );
494 504
495 m_prev_View = m_curr_View; 505 m_prev_View = m_curr_View;
496 506
497 // Switch to new View 507 // Switch to new View
498 switch ( (int) m_curr_View ) { 508 switch ( (int) m_curr_View ) {
499 case TableView: 509 case TableView:
500 m_abTable -> setChoiceSelection( m_orderedFields ); 510 m_abTable -> setChoiceSelection( m_orderedFields );
501 if ( m_curr_Contact != 0 ) 511 if ( m_curr_Contact != 0 )
502 m_abTable -> selectContact ( m_curr_Contact ); 512 m_abTable -> selectContact ( m_curr_Contact );
503 m_abTable -> setFocus(); 513 m_abTable -> setFocus();
504 break; 514 break;
505 case CardView: 515 case CardView:
506 if ( m_curr_Contact != 0 ) 516 if ( m_curr_Contact != 0 )
507 m_ablabel -> selectContact( m_curr_Contact ); 517 m_ablabel -> selectContact( m_curr_Contact );
508 m_ablabel -> setFocus(); 518 m_ablabel -> setFocus();
509 break; 519 break;
510 } 520 }
511 521
512 // Raise the current View 522 // Raise the current View
513 m_viewStack -> raiseWidget( m_curr_View ); 523 m_viewStack -> raiseWidget( m_curr_View );
514} 524}
515 525
516 526