summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/TODO18
-rw-r--r--core/pim/addressbook/abtable.cpp3
-rw-r--r--core/pim/addressbook/abtable.h2
-rw-r--r--core/pim/addressbook/addressbook.cpp2
4 files changed, 14 insertions, 11 deletions
diff --git a/core/pim/addressbook/TODO b/core/pim/addressbook/TODO
index 0accd87..4daa2a8 100644
--- a/core/pim/addressbook/TODO
+++ b/core/pim/addressbook/TODO
@@ -1,31 +1,33 @@
1Stuff todo: 1Stuff todo until OPIE 1.0 :
2 2
3Urgent: 3Urgent:
4 4
5- Font menu is invisible using german translation 5- Font menu is invisible using german translation
6 6
7Important: 7Important:
8 8
9- Finishing of new View functions (List, Phonebook...) 9- Picker: Activated letter schould be more visible
10- Reload if contacts were changed externally
11- "What's this" should be added 10- "What's this" should be added
12- The names of the countries are sorted by there english names, only..
13 Even if they are translated.. :S
14- Store last settings of combo-boxes 11- Store last settings of combo-boxes
15- Mail-Icon is missing 12- Mail-Icon is missing
13- Finishing of new View functions (List, Phonebook...)
14- The names of the countries are sorted by there english names, only..
15 Even if they are translated.. :S
16- Reload if contacts were changed externally
16 17
17Less important: 18Less important:
18 19
19- Find widget should be replaced by something like
20 qpdf has.
21- The picker (alphabetical sort widget) should be 20- The picker (alphabetical sort widget) should be
22 placed verticaly or horizontally (configurable) 21 placed verticaly or horizontally (configurable)
23- Use advanced database functions in abtable to decrease 22- Use advanced database functions in abtable to decrease
24 memory footprint and to make everything more easy ! 23 memory footprint and to make everything more easy !
25 (abtable should store Iterator for selected Category) 24 (abtable should store Iterator for selected Category)
26 25
27Should be Fixed (not absolute sure, need validation): 26Should be Fixed (not absolute sure, need further validation):
28- "Nonenglish" translation bug has to be fixed. 27- "Nonenglish" translation bug has to be fixed.
29 28
30Fixed: 29Fixed:
31- Syncing: abtable not reloaded after sync. 30- Syncing: abtable not reloaded after sync.
31- Find widget should be replaced by something like
32 qpdf has.
33- Adding a configuration dialog \ No newline at end of file
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index 97f4a8f..d4dcf7b 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -125,891 +125,892 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam
125 // #else 125 // #else
126 : QTable( parent, name ), 126 : QTable( parent, name ),
127 // #endif 127 // #endif
128 lastSortCol( -1 ), 128 lastSortCol( -1 ),
129 asc( TRUE ), 129 asc( TRUE ),
130 intFields( order ), 130 intFields( order ),
131 currFindRow( -1 ), 131 currFindRow( -1 ),
132 mCat( 0 ), 132 mCat( 0 ),
133 m_contactdb ("addressbook", 0l, 0l, false) // Handle syncing myself.. ! 133 m_contactdb ("addressbook", 0l, 0l, false) // Handle syncing myself.. !
134{ 134{
135 mCat.load( categoryFileName() ); 135 mCat.load( categoryFileName() );
136 setSelectionMode( NoSelection ); 136 setSelectionMode( NoSelection );
137 init(); 137 init();
138 setSorting( TRUE ); 138 setSorting( TRUE );
139 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), 139 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)),
140 this, SLOT(itemClicked(int,int)) ); 140 this, SLOT(itemClicked(int,int)) );
141} 141}
142 142
143AbTable::~AbTable() 143AbTable::~AbTable()
144{ 144{
145} 145}
146 146
147void AbTable::init() 147void AbTable::init()
148{ 148{
149 showChar = '\0'; 149 showChar = '\0';
150 setNumRows( 0 ); 150 setNumRows( 0 );
151 setNumCols( 2 ); 151 setNumCols( 2 );
152 152
153 horizontalHeader()->setLabel( 0, tr( "Full Name" )); 153 horizontalHeader()->setLabel( 0, tr( "Full Name" ));
154 horizontalHeader()->setLabel( 1, tr( "Contact" )); 154 horizontalHeader()->setLabel( 1, tr( "Contact" ));
155 setLeftMargin( 0 ); 155 setLeftMargin( 0 );
156 verticalHeader()->hide(); 156 verticalHeader()->hide();
157 columnVisible = true; 157 columnVisible = true;
158} 158}
159 159
160void AbTable::columnClicked( int col ) 160void AbTable::columnClicked( int col )
161{ 161{
162 if ( !sorting() ) 162 if ( !sorting() )
163 return; 163 return;
164 164
165 if ( lastSortCol == -1 ) 165 if ( lastSortCol == -1 )
166 lastSortCol = col; 166 lastSortCol = col;
167 167
168 if ( col == lastSortCol ) { 168 if ( col == lastSortCol ) {
169 asc = !asc; 169 asc = !asc;
170 } else { 170 } else {
171 lastSortCol = col; 171 lastSortCol = col;
172 asc = TRUE; 172 asc = TRUE;
173 } 173 }
174 //QMessageBox::information( this, "resort", "columnClicked" ); 174 //QMessageBox::information( this, "resort", "columnClicked" );
175 resort(); 175 resort();
176} 176}
177 177
178void AbTable::resort() 178void AbTable::resort()
179{ 179{
180 if ( sorting() ) { 180 if ( sorting() ) {
181 if ( lastSortCol == -1 ) 181 if ( lastSortCol == -1 )
182 lastSortCol = 0; 182 lastSortCol = 0;
183 sortColumn( lastSortCol, asc, TRUE ); 183 sortColumn( lastSortCol, asc, TRUE );
184 //QMessageBox::information( this, "resort", "resort" ); 184 //QMessageBox::information( this, "resort", "resort" );
185 updateVisible(); 185 updateVisible();
186 } 186 }
187} 187}
188 188
189OContact AbTable::currentEntry() 189OContact AbTable::currentEntry()
190{ 190{
191 OContact cnt; 191 OContact cnt;
192 AbTableItem *abItem; 192 AbTableItem *abItem;
193 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); 193 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 ));
194 if ( abItem ) { 194 if ( abItem ) {
195 cnt = contactList[abItem]; 195 cnt = contactList[abItem];
196 //cnt = contactList[currentRow()]; 196 //cnt = contactList[currentRow()];
197 } 197 }
198 return cnt; 198 return cnt;
199} 199}
200 200
201void AbTable::replaceCurrentEntry( const OContact &newContact ) 201void AbTable::replaceCurrentEntry( const OContact &newContact )
202{ 202{
203 int row = currentRow(); 203 int row = currentRow();
204 updateVisible(); 204 updateVisible();
205 205
206 journalFreeReplace( newContact, row ); 206 journalFreeReplace( newContact, row );
207 207
208} 208}
209 209
210void AbTable::deleteCurrentEntry() 210void AbTable::deleteCurrentEntry()
211{ 211{
212 int row = currentRow(); 212 int row = currentRow();
213 213
214 // a little wasteful, but it ensure's there is only one place 214 // a little wasteful, but it ensure's there is only one place
215 // where we delete. 215 // where we delete.
216 journalFreeRemove( row ); 216 journalFreeRemove( row );
217 updateVisible(); 217 updateVisible();
218 218
219 if ( numRows() == 0 ) 219 if ( numRows() == 0 )
220 emit empty( TRUE ); 220 emit empty( TRUE );
221 221
222} 222}
223 223
224void AbTable::clear() 224void AbTable::clear()
225{ 225{
226 contactList.clear(); 226 contactList.clear();
227 for ( int r = 0; r < numRows(); ++r ) { 227 for ( int r = 0; r < numRows(); ++r ) {
228 for ( int c = 0; c < numCols(); ++c ) { 228 for ( int c = 0; c < numCols(); ++c ) {
229 if ( cellWidget( r, c ) ) 229 if ( cellWidget( r, c ) )
230 clearCellWidget( r, c ); 230 clearCellWidget( r, c );
231 clearCell( r, c ); 231 clearCell( r, c );
232 } 232 }
233 } 233 }
234 setNumRows( 0 ); 234 setNumRows( 0 );
235} 235}
236 236
237void AbTable::refresh() 237void AbTable::refresh()
238{ 238{
239 int rows = numRows(); 239 int rows = numRows();
240 QString value; 240 QString value;
241 AbTableItem *abi; 241 AbTableItem *abi;
242 242
243 // hide columns so no flashing ? 243 // hide columns so no flashing ?
244 if ( showBk == "Cards" ) { 244 if ( showBk == "Cards" ) {
245 hideColumn(0); 245 hideColumn(0);
246 hideColumn(1); 246 hideColumn(1);
247 } 247 }
248 for ( int r = 0; r < rows; ++r ) { 248 for ( int r = 0; r < rows; ++r ) {
249 abi = static_cast<AbTableItem*>( item(r, 0) ); 249 abi = static_cast<AbTableItem*>( item(r, 0) );
250 value = findContactContact( contactList[abi], r ); 250 value = findContactContact( contactList[abi], r );
251 static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); 251 static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() );
252 } 252 }
253 resort(); 253 resort();
254} 254}
255 255
256void AbTable::keyPressEvent( QKeyEvent *e ) 256void AbTable::keyPressEvent( QKeyEvent *e )
257{ 257{
258 char key = toupper( e->ascii() ); 258 char key = toupper( e->ascii() );
259 259
260 if ( key >= 'A' && key <= 'Z' ) 260 if ( key >= 'A' && key <= 'Z' )
261 moveTo( key ); 261 moveTo( key );
262 262
263 switch( e->key() ) { 263 switch( e->key() ) {
264 case Qt::Key_Space: 264 case Qt::Key_Space:
265 case Qt::Key_Return: 265 case Qt::Key_Return:
266 case Qt::Key_Enter: 266 case Qt::Key_Enter:
267 emit details(); 267 emit details();
268 break; 268 break;
269 default: 269 default:
270 QTable::keyPressEvent( e ); 270 QTable::keyPressEvent( e );
271 } 271 }
272} 272}
273 273
274void AbTable::moveTo( char c ) 274void AbTable::moveTo( char c )
275{ 275{
276 276
277 int rows = numRows(); 277 int rows = numRows();
278 QString value; 278 QString value;
279 AbTableItem *abi; 279 AbTableItem *abi;
280 int r; 280 int r;
281 if ( asc ) { 281 if ( asc ) {
282 r = 0; 282 r = 0;
283 while ( r < rows-1) { 283 while ( r < rows-1) {
284 abi = static_cast<AbTableItem*>( item(r, 0) ); 284 abi = static_cast<AbTableItem*>( item(r, 0) );
285 QChar first = abi->key()[0]; 285 QChar first = abi->key()[0];
286 //### is there a bug in QChar to char comparison??? 286 //### is there a bug in QChar to char comparison???
287 if ( first.row() || first.cell() >= c ) 287 if ( first.row() || first.cell() >= c )
288 break; 288 break;
289 r++; 289 r++;
290 } 290 }
291 } else { 291 } else {
292 //### should probably disable reverse sorting instead 292 //### should probably disable reverse sorting instead
293 r = rows - 1; 293 r = rows - 1;
294 while ( r > 0 ) { 294 while ( r > 0 ) {
295 abi = static_cast<AbTableItem*>( item(r, 0) ); 295 abi = static_cast<AbTableItem*>( item(r, 0) );
296 QChar first = abi->key()[0]; 296 QChar first = abi->key()[0];
297 //### is there a bug in QChar to char comparison??? 297 //### is there a bug in QChar to char comparison???
298 if ( first.row() || first.cell() >= c ) 298 if ( first.row() || first.cell() >= c )
299 break; 299 break;
300 r--; 300 r--;
301 } 301 }
302 } 302 }
303 setCurrentCell( r, currentColumn() ); 303 setCurrentCell( r, currentColumn() );
304} 304}
305 305
306 306
307QString AbTable::findContactName( const OContact &entry ) 307QString AbTable::findContactName( const OContact &entry )
308{ 308{
309 // We use the fileAs, then company, defaultEmail 309 // We use the fileAs, then company, defaultEmail
310 QString str; 310 QString str;
311 str = entry.fileAs(); 311 str = entry.fileAs();
312 if ( str.isEmpty() ) { 312 if ( str.isEmpty() ) {
313 str = entry.company(); 313 str = entry.company();
314 if ( str.isEmpty() ) { 314 if ( str.isEmpty() ) {
315 str = entry.defaultEmail(); 315 str = entry.defaultEmail();
316 } 316 }
317 } 317 }
318 return str; 318 return str;
319} 319}
320 320
321QString AbTable::findContactContact( const OContact &entry, int /* row */ ) 321QString AbTable::findContactContact( const OContact &entry, int /* row */ )
322{ 322{
323 QString value; 323 QString value;
324 value = ""; 324 value = "";
325 for ( QValueList<int>::ConstIterator it = intFields->begin(); 325 for ( QValueList<int>::ConstIterator it = intFields->begin();
326 it != intFields->end(); ++it ) { 326 it != intFields->end(); ++it ) {
327 switch ( *it ) { 327 switch ( *it ) {
328 default: 328 default:
329 break; 329 break;
330 case Qtopia::Title: 330 case Qtopia::Title:
331 value = entry.title(); 331 value = entry.title();
332 break; 332 break;
333 case Qtopia::Suffix: 333 case Qtopia::Suffix:
334 value = entry.suffix(); 334 value = entry.suffix();
335 break; 335 break;
336 case Qtopia::FileAs: 336 case Qtopia::FileAs:
337 value = entry.fileAs(); 337 value = entry.fileAs();
338 break; 338 break;
339 case Qtopia::DefaultEmail: 339 case Qtopia::DefaultEmail:
340 value = entry.defaultEmail(); 340 value = entry.defaultEmail();
341 case Qtopia::Emails: 341 case Qtopia::Emails:
342 value = entry.emails(); 342 value = entry.emails();
343 break; 343 break;
344 case Qtopia::HomeStreet: 344 case Qtopia::HomeStreet:
345 value = entry.homeStreet(); 345 value = entry.homeStreet();
346 break; 346 break;
347 case Qtopia::HomeCity: 347 case Qtopia::HomeCity:
348 value = entry.homeCity(); 348 value = entry.homeCity();
349 break; 349 break;
350 case Qtopia::HomeState: 350 case Qtopia::HomeState:
351 value = entry.homeState(); 351 value = entry.homeState();
352 break; 352 break;
353 case Qtopia::HomeZip: 353 case Qtopia::HomeZip:
354 value = entry.homeZip(); 354 value = entry.homeZip();
355 break; 355 break;
356 case Qtopia::HomeCountry: 356 case Qtopia::HomeCountry:
357 value = entry.homeCountry(); 357 value = entry.homeCountry();
358 break; 358 break;
359 case Qtopia::HomePhone: 359 case Qtopia::HomePhone:
360 value = entry.homePhone(); 360 value = entry.homePhone();
361 break; 361 break;
362 case Qtopia::HomeFax: 362 case Qtopia::HomeFax:
363 value = entry.homeFax(); 363 value = entry.homeFax();
364 break; 364 break;
365 case Qtopia::HomeMobile: 365 case Qtopia::HomeMobile:
366 value = entry.homeMobile(); 366 value = entry.homeMobile();
367 break; 367 break;
368 case Qtopia::HomeWebPage: 368 case Qtopia::HomeWebPage:
369 value = entry.homeWebpage(); 369 value = entry.homeWebpage();
370 break; 370 break;
371 case Qtopia::Company: 371 case Qtopia::Company:
372 value = entry.company(); 372 value = entry.company();
373 break; 373 break;
374 case Qtopia::BusinessCity: 374 case Qtopia::BusinessCity:
375 value = entry.businessCity(); 375 value = entry.businessCity();
376 break; 376 break;
377 case Qtopia::BusinessStreet: 377 case Qtopia::BusinessStreet:
378 value = entry.businessStreet(); 378 value = entry.businessStreet();
379 break; 379 break;
380 case Qtopia::BusinessZip: 380 case Qtopia::BusinessZip:
381 value = entry.businessZip(); 381 value = entry.businessZip();
382 break; 382 break;
383 case Qtopia::BusinessCountry: 383 case Qtopia::BusinessCountry:
384 value = entry.businessCountry(); 384 value = entry.businessCountry();
385 break; 385 break;
386 case Qtopia::BusinessWebPage: 386 case Qtopia::BusinessWebPage:
387 value = entry.businessWebpage(); 387 value = entry.businessWebpage();
388 break; 388 break;
389 case Qtopia::JobTitle: 389 case Qtopia::JobTitle:
390 value = entry.jobTitle(); 390 value = entry.jobTitle();
391 break; 391 break;
392 case Qtopia::Department: 392 case Qtopia::Department:
393 value = entry.department(); 393 value = entry.department();
394 break; 394 break;
395 case Qtopia::Office: 395 case Qtopia::Office:
396 value = entry.office(); 396 value = entry.office();
397 break; 397 break;
398 case Qtopia::BusinessPhone: 398 case Qtopia::BusinessPhone:
399 value = entry.businessPhone(); 399 value = entry.businessPhone();
400 break; 400 break;
401 case Qtopia::BusinessFax: 401 case Qtopia::BusinessFax:
402 value = entry.businessFax(); 402 value = entry.businessFax();
403 break; 403 break;
404 case Qtopia::BusinessMobile: 404 case Qtopia::BusinessMobile:
405 value = entry.businessMobile(); 405 value = entry.businessMobile();
406 break; 406 break;
407 case Qtopia::BusinessPager: 407 case Qtopia::BusinessPager:
408 value = entry.businessPager(); 408 value = entry.businessPager();
409 break; 409 break;
410 case Qtopia::Profession: 410 case Qtopia::Profession:
411 value = entry.profession(); 411 value = entry.profession();
412 break; 412 break;
413 case Qtopia::Assistant: 413 case Qtopia::Assistant:
414 value = entry.assistant(); 414 value = entry.assistant();
415 break; 415 break;
416 case Qtopia::Manager: 416 case Qtopia::Manager:
417 value = entry.manager(); 417 value = entry.manager();
418 break; 418 break;
419 case Qtopia::Spouse: 419 case Qtopia::Spouse:
420 value = entry.spouse(); 420 value = entry.spouse();
421 break; 421 break;
422 case Qtopia::Gender: 422 case Qtopia::Gender:
423 value = entry.gender(); 423 value = entry.gender();
424 break; 424 break;
425 case Qtopia::Birthday: 425 case Qtopia::Birthday:
426 value = entry.birthday(); 426 value = entry.birthday();
427 break; 427 break;
428 case Qtopia::Anniversary: 428 case Qtopia::Anniversary:
429 value = entry.anniversary(); 429 value = entry.anniversary();
430 break; 430 break;
431 case Qtopia::Nickname: 431 case Qtopia::Nickname:
432 value = entry.nickname(); 432 value = entry.nickname();
433 break; 433 break;
434 case Qtopia::Children: 434 case Qtopia::Children:
435 value = entry.children(); 435 value = entry.children();
436 break; 436 break;
437 case Qtopia::Notes: 437 case Qtopia::Notes:
438 value = entry.notes(); 438 value = entry.notes();
439 break; 439 break;
440 } 440 }
441 if ( !value.isEmpty() ) 441 if ( !value.isEmpty() )
442 break; 442 break;
443 } 443 }
444 return value; 444 return value;
445} 445}
446 446
447void AbTable::addEntry( const OContact &newCnt ) 447void AbTable::addEntry( const OContact &newCnt )
448{ 448{
449 int row = numRows(); 449 int row = numRows();
450 450
451 setNumRows( row + 1 ); 451 setNumRows( row + 1 );
452 insertIntoTable( newCnt, row ); 452 insertIntoTable( newCnt, row );
453 453
454 qWarning("abtable:AddContact"); 454 qWarning("abtable:AddContact");
455 m_contactdb.add ( newCnt ); 455 m_contactdb.add ( newCnt );
456 456
457 setCurrentCell( row, 0 ); 457 setCurrentCell( row, 0 );
458 // updateVisible(); 458 // updateVisible();
459} 459}
460 460
461void AbTable::resizeRows() { 461void AbTable::resizeRows() {
462 /* 462 /*
463 if (numRows()) { 463 if (numRows()) {
464 for (int i = 0; i < numRows(); i++) { 464 for (int i = 0; i < numRows(); i++) {
465 setRowHeight( i, size ); 465 setRowHeight( i, size );
466 } 466 }
467 } 467 }
468 updateVisible(); 468 updateVisible();
469 */ 469 */
470} 470}
471 471
472 472
473bool AbTable::save() 473bool AbTable::save()
474{ 474{
475 // QTime t; 475 // QTime t;
476 // t.start(); 476 // t.start();
477 qWarning("abtable:Save data"); 477 qWarning("abtable:Save data");
478 478
479 return m_contactdb.save(); 479 return m_contactdb.save();
480} 480}
481 481
482void AbTable::load() 482void AbTable::load()
483{ 483{
484 setSorting( false ); 484 setSorting( false );
485 setUpdatesEnabled( FALSE ); 485 setUpdatesEnabled( FALSE );
486 486
487 qWarning("abtable:Load data"); 487 qWarning("abtable:Load data");
488 488
489 OContactAccess::List list = m_contactdb.allRecords(); 489 OContactAccess::List list = m_contactdb.allRecords();
490 OContactAccess::List::Iterator it; 490 OContactAccess::List::Iterator it;
491 setNumRows( list.count() ); 491 setNumRows( list.count() );
492 int row = 0; 492 int row = 0;
493 for ( it = list.begin(); it != list.end(); ++it ) 493 for ( it = list.begin(); it != list.end(); ++it )
494 insertIntoTable( *it, row++ ); 494 insertIntoTable( *it, row++ );
495 495
496 setUpdatesEnabled( TRUE ); 496 setUpdatesEnabled( TRUE );
497 497
498 setSorting( true ); 498 setSorting( true );
499 resort(); 499 resort();
500} 500}
501 501
502 502
503void AbTable::reload() 503void AbTable::reload()
504{ 504{
505 m_contactdb.reload(); 505 m_contactdb.reload();
506 load(); 506 load();
507} 507}
508 508
509void AbTable::realignTable( int row ) 509void AbTable::realignTable( int row )
510{ 510{
511 QTableItem *ti1, 511 QTableItem *ti1,
512 *ti2; 512 *ti2;
513 int totalRows = numRows(); 513 int totalRows = numRows();
514 for ( int curr = row; curr < totalRows - 1; curr++ ) { 514 for ( int curr = row; curr < totalRows - 1; curr++ ) {
515 // the same info from the todo list still applies, but I 515 // the same info from the todo list still applies, but I
516 // don't think it is _too_ bad. 516 // don't think it is _too_ bad.
517 ti1 = item( curr + 1, 0 ); 517 ti1 = item( curr + 1, 0 );
518 ti2 = item( curr + 1, 1 ); 518 ti2 = item( curr + 1, 1 );
519 takeItem( ti1 ); 519 takeItem( ti1 );
520 takeItem( ti2 ); 520 takeItem( ti2 );
521 setItem( curr, 0, ti1 ); 521 setItem( curr, 0, ti1 );
522 setItem( curr, 1, ti2 ); 522 setItem( curr, 1, ti2 );
523 } 523 }
524 setNumRows( totalRows - 1 ); 524 setNumRows( totalRows - 1 );
525 resort(); 525 resort();
526} 526}
527 527
528// Add contact into table. 528// Add contact into table.
529void AbTable::insertIntoTable( const OContact &cnt, int row ) 529void AbTable::insertIntoTable( const OContact &cnt, int row )
530{ 530{
531 QString strName, 531 QString strName,
532 strContact; 532 strContact;
533 533
534 strName = findContactName( cnt ); 534 strName = findContactName( cnt );
535 strContact = findContactContact( cnt, row ); 535 strContact = findContactContact( cnt, row );
536 536
537 AbTableItem *ati; 537 AbTableItem *ati;
538 ati = new AbTableItem( this, QTableItem::Never, strName, strContact); 538 ati = new AbTableItem( this, QTableItem::Never, strName, strContact);
539 contactList.insert( ati, cnt ); 539 contactList.insert( ati, cnt );
540 setItem( row, 0, ati ); 540 setItem( row, 0, ati );
541 ati = new AbTableItem( this, QTableItem::Never, strContact, strName); 541 ati = new AbTableItem( this, QTableItem::Never, strContact, strName);
542 setItem( row, 1, ati ); 542 setItem( row, 1, ati );
543 543
544 //### cannot do this; table only has two columns at this point 544 //### cannot do this; table only has two columns at this point
545 // setItem( row, 2, new AbPickItem( this ) ); 545 // setItem( row, 2, new AbPickItem( this ) );
546 546
547 // resort at some point? 547 // resort at some point?
548} 548}
549 549
550 550
551// Replace or add an entry 551// Replace or add an entry
552void AbTable::journalFreeReplace( const OContact &cnt, int row ) 552void AbTable::journalFreeReplace( const OContact &cnt, int row )
553{ 553{
554 QString strName, 554 QString strName,
555 strContact; 555 strContact;
556 AbTableItem *ati = 0l; 556 AbTableItem *ati = 0l;
557 557
558 strName = findContactName( cnt ); 558 strName = findContactName( cnt );
559 strContact = findContactContact( cnt, row ); 559 strContact = findContactContact( cnt, row );
560 ati = static_cast<AbTableItem*>(item(row, 0)); 560 ati = static_cast<AbTableItem*>(item(row, 0));
561 561
562 // Replace element if found in row "row" 562 // Replace element if found in row "row"
563 // or add this element if not. 563 // or add this element if not.
564 if ( ati != 0 ) { // replace 564 if ( ati != 0 ) { // replace
565 // :SX db access -> replace 565 // :SX db access -> replace
566 qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() ); 566 qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() );
567 m_contactdb.replace ( cnt ); 567 m_contactdb.replace ( cnt );
568 568
569 contactList.remove( ati ); 569 contactList.remove( ati );
570 ati->setItem( strName, strContact ); 570 ati->setItem( strName, strContact );
571 contactList.insert( ati, cnt ); 571 contactList.insert( ati, cnt );
572 572
573 ati = static_cast<AbTableItem*>(item(row, 1)); 573 ati = static_cast<AbTableItem*>(item(row, 1));
574 ati->setItem( strContact, strName ); 574 ati->setItem( strContact, strName );
575 575
576 }else{ // add 576 }else{ // add
577 int myrows = numRows(); 577 int myrows = numRows();
578 setNumRows( myrows + 1 ); 578 setNumRows( myrows + 1 );
579 insertIntoTable( cnt, myrows ); 579 insertIntoTable( cnt, myrows );
580 // gets deleted when returning -- Why ? (se) 580 // gets deleted when returning -- Why ? (se)
581 // :SX db access -> add 581 // :SX db access -> add
582 qWarning ("Are you sure to add to database ? -> Currently disabled !!"); 582 qWarning ("Are you sure to add to database ? -> Currently disabled !!");
583 // m_contactdb.add( cnt ); 583 // m_contactdb.add( cnt );
584 } 584 }
585} 585}
586 586
587// Remove entry 587// Remove entry
588void AbTable::journalFreeRemove( int row ) 588void AbTable::journalFreeRemove( int row )
589{ 589{
590 AbTableItem *ati; 590 AbTableItem *ati;
591 ati = static_cast<AbTableItem*>(item(row, 0)); 591 ati = static_cast<AbTableItem*>(item(row, 0));
592 if ( !ati ) 592 if ( !ati )
593 return; 593 return;
594 594
595 // :SX db access -> remove 595 // :SX db access -> remove
596 qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() ); 596 qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() );
597 m_contactdb.remove( contactList[ati].uid() ); 597 m_contactdb.remove( contactList[ati].uid() );
598 598
599 contactList.remove( ati ); 599 contactList.remove( ati );
600 600
601 realignTable( row ); 601 realignTable( row );
602 602
603} 603}
604 604
605#if QT_VERSION <= 230 605#if QT_VERSION <= 230
606#ifndef SINGLE_APP 606#ifndef SINGLE_APP
607void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) 607void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
608{ 608{
609 // Region of the rect we should draw 609 // Region of the rect we should draw
610 QRegion reg( QRect( cx, cy, cw, ch ) ); 610 QRegion reg( QRect( cx, cy, cw, ch ) );
611 // Subtract the table from it 611 // Subtract the table from it
612 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); 612 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) );
613 // And draw the rectangles (transformed as needed) 613 // And draw the rectangles (transformed as needed)
614 QArray<QRect> r = reg.rects(); 614 QArray<QRect> r = reg.rects();
615 for (unsigned int i=0; i<r.count(); i++) 615 for (unsigned int i=0; i<r.count(); i++)
616 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); 616 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) );
617} 617}
618#endif 618#endif
619#endif 619#endif
620 620
621 621
622// int AbTable::rowHeight( int ) const 622// int AbTable::rowHeight( int ) const
623// { 623// {
624// return 18; 624// return 18;
625// } 625// }
626 626
627// int AbTable::rowPos( int row ) const 627// int AbTable::rowPos( int row ) const
628// { 628// {
629// return 18*row; 629// return 18*row;
630// } 630// }
631 631
632// int AbTable::rowAt( int pos ) const 632// int AbTable::rowAt( int pos ) const
633// { 633// {
634// return QMIN( pos/18, numRows()-1 ); 634// return QMIN( pos/18, numRows()-1 );
635// } 635// }
636 636
637void AbTable::slotDoFind( const QString &findString, bool caseSensitive, 637void AbTable::slotDoFind( const QString &findString, bool caseSensitive, bool useRegExp,
638 bool backwards, QString cat /* int category */ ) 638 bool backwards, QString cat /* int category */ )
639{ 639{
640 int category = 0; 640 int category = 0;
641 641
642 // Use the current Category if nothing else selected 642 // Use the current Category if nothing else selected
643 if ( cat.isEmpty() ) 643 if ( cat.isEmpty() )
644 category = mCat.id( "Contacts", showCat ); 644 category = mCat.id( "Contacts", showCat );
645 else{ 645 else{
646 category = mCat.id("Contacts", cat ); 646 category = mCat.id("Contacts", cat );
647 } 647 }
648 648
649 qWarning ("Found in Category %d", category); 649 qWarning ("Found in Category %d", category);
650 650
651 if ( currFindRow < -1 ) 651 if ( currFindRow < -1 )
652 currFindRow = - 1; 652 currFindRow = - 1;
653 653
654 clearSelection( TRUE ); 654 clearSelection( TRUE );
655 int rows, row; 655 int rows, row;
656 AbTableItem *ati; 656 AbTableItem *ati;
657 QRegExp r( findString ); 657 QRegExp r( findString );
658 r.setCaseSensitive( caseSensitive ); 658 r.setCaseSensitive( caseSensitive );
659 r.setWildcard( !useRegExp );
659 rows = numRows(); 660 rows = numRows();
660 static bool wrapAround = true; 661 static bool wrapAround = true;
661 662
662 if ( !backwards ) { 663 if ( !backwards ) {
663 for ( row = currFindRow + 1; row < rows; row++ ) { 664 for ( row = currFindRow + 1; row < rows; row++ ) {
664 ati = static_cast<AbTableItem*>( item(row, 0) ); 665 ati = static_cast<AbTableItem*>( item(row, 0) );
665 if ( contactCompare( contactList[ati], r, category ) ) 666 if ( contactCompare( contactList[ati], r, category ) )
666 break; 667 break;
667 } 668 }
668 } else { 669 } else {
669 for ( row = currFindRow - 1; row > -1; row-- ) { 670 for ( row = currFindRow - 1; row > -1; row-- ) {
670 ati = static_cast<AbTableItem*>( item(row, 0) ); 671 ati = static_cast<AbTableItem*>( item(row, 0) );
671 if ( contactCompare( contactList[ati], r, category ) ) 672 if ( contactCompare( contactList[ati], r, category ) )
672 break; 673 break;
673 } 674 }
674 } 675 }
675 if ( row >= rows || row < 0 ) { 676 if ( row >= rows || row < 0 ) {
676 if ( row < 0 ) 677 if ( row < 0 )
677 currFindRow = rows; 678 currFindRow = rows;
678 else 679 else
679 currFindRow = -1; 680 currFindRow = -1;
680 681
681 if ( wrapAround ) 682 if ( wrapAround )
682 emit signalWrapAround(); 683 emit signalWrapAround();
683 else 684 else
684 emit signalNotFound(); 685 emit signalNotFound();
685 686
686 wrapAround = !wrapAround; 687 wrapAround = !wrapAround;
687 } else { 688 } else {
688 currFindRow = row; 689 currFindRow = row;
689 QTableSelection foundSelection; 690 QTableSelection foundSelection;
690 foundSelection.init( currFindRow, 0 ); 691 foundSelection.init( currFindRow, 0 );
691 foundSelection.expandTo( currFindRow, numCols() - 1 ); 692 foundSelection.expandTo( currFindRow, numCols() - 1 );
692 addSelection( foundSelection ); 693 addSelection( foundSelection );
693 setCurrentCell( currFindRow, 0 /* numCols() - 1 */ ); 694 setCurrentCell( currFindRow, 0 /* numCols() - 1 */ );
694 wrapAround = true; 695 wrapAround = true;
695 } 696 }
696} 697}
697 698
698static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) 699static bool contactCompare( const OContact &cnt, const QRegExp &r, int category )
699{ 700{
700 bool returnMe; 701 bool returnMe;
701 QArray<int> cats; 702 QArray<int> cats;
702 cats = cnt.categories(); 703 cats = cnt.categories();
703 704
704 returnMe = false; 705 returnMe = false;
705 if ( (cats.count() == 0) || (category == 0) ) 706 if ( (cats.count() == 0) || (category == 0) )
706 returnMe = cnt.match( r ); 707 returnMe = cnt.match( r );
707 else { 708 else {
708 int i; 709 int i;
709 for ( i = 0; i < int(cats.count()); i++ ) { 710 for ( i = 0; i < int(cats.count()); i++ ) {
710 if ( cats[i] == category ) { 711 if ( cats[i] == category ) {
711 returnMe = cnt.match( r ); 712 returnMe = cnt.match( r );
712 break; 713 break;
713 } 714 }
714 } 715 }
715 } 716 }
716 717
717 return returnMe; 718 return returnMe;
718} 719}
719 720
720void AbTable::fitColumns() 721void AbTable::fitColumns()
721{ 722{
722 int contentsWidth = visibleWidth() / 2; 723 int contentsWidth = visibleWidth() / 2;
723 724
724 if ( showBk == "Cards" ) { 725 if ( showBk == "Cards" ) {
725 showColumn(1); 726 showColumn(1);
726 //adjustColumn(1); 727 //adjustColumn(1);
727 setColumnWidth( 1, visibleWidth() ); 728 setColumnWidth( 1, visibleWidth() );
728 columnVisible = false; 729 columnVisible = false;
729 } else { 730 } else {
730 if ( columnVisible == false ){ 731 if ( columnVisible == false ){
731 showColumn(0); 732 showColumn(0);
732 columnVisible = true; 733 columnVisible = true;
733 } 734 }
734 setColumnWidth( 0, contentsWidth ); 735 setColumnWidth( 0, contentsWidth );
735 adjustColumn(1); 736 adjustColumn(1);
736 if ( columnWidth(1) < contentsWidth ) 737 if ( columnWidth(1) < contentsWidth )
737 setColumnWidth( 1, contentsWidth ); 738 setColumnWidth( 1, contentsWidth );
738 } 739 }
739} 740}
740 741
741void AbTable::show() 742void AbTable::show()
742{ 743{
743 fitColumns(); 744 fitColumns();
744 QTable::show(); 745 QTable::show();
745} 746}
746 747
747void AbTable::setChoiceNames( const QStringList& list) 748void AbTable::setChoiceNames( const QStringList& list)
748{ 749{
749 choicenames = list; 750 choicenames = list;
750 if ( choicenames.isEmpty() ) { 751 if ( choicenames.isEmpty() ) {
751 // hide pick column 752 // hide pick column
752 setNumCols( 2 ); 753 setNumCols( 2 );
753 } else { 754 } else {
754 // show pick column 755 // show pick column
755 setNumCols( 3 ); 756 setNumCols( 3 );
756 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); 757 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 );
757 horizontalHeader()->setLabel( 2, tr( "Pick" )); 758 horizontalHeader()->setLabel( 2, tr( "Pick" ));
758 } 759 }
759 fitColumns(); 760 fitColumns();
760} 761}
761 762
762void AbTable::itemClicked(int,int col) 763void AbTable::itemClicked(int,int col)
763{ 764{
764 if ( col == 2 ) { 765 if ( col == 2 ) {
765 return; 766 return;
766 } else { 767 } else {
767 emit details(); 768 emit details();
768 } 769 }
769} 770}
770 771
771QStringList AbTable::choiceNames() const 772QStringList AbTable::choiceNames() const
772{ 773{
773 return choicenames; 774 return choicenames;
774} 775}
775 776
776void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) 777void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/)
777{ 778{
778 /* ###### 779 /* ######
779 780
780 QString selname = choicenames.at(index); 781 QString selname = choicenames.at(index);
781 for (each row) { 782 for (each row) {
782 OContact *c = contactForRow(row); 783 OContact *c = contactForRow(row);
783 if ( list.contains(c->email) ) { 784 if ( list.contains(c->email) ) {
784 list.remove(c->email); 785 list.remove(c->email);
785 setText(row, 2, selname); 786 setText(row, 2, selname);
786 } 787 }
787 } 788 }
788 for (remaining list items) { 789 for (remaining list items) {
789 OContact *c = new contact(item); 790 OContact *c = new contact(item);
790 setText(newrow, 2, selname); 791 setText(newrow, 2, selname);
791 } 792 }
792 793
793 */ 794 */
794} 795}
795 796
796QStringList AbTable::choiceSelection(int /*index*/) const 797QStringList AbTable::choiceSelection(int /*index*/) const
797{ 798{
798 QStringList r; 799 QStringList r;
799 /* ###### 800 /* ######
800 801
801 QString selname = choicenames.at(index); 802 QString selname = choicenames.at(index);
802 for (each row) { 803 for (each row) {
803 OContact *c = contactForRow(row); 804 OContact *c = contactForRow(row);
804 if ( text(row,2) == selname ) { 805 if ( text(row,2) == selname ) {
805 r.append(c->email); 806 r.append(c->email);
806 } 807 }
807 } 808 }
808 809
809 */ 810 */
810 return r; 811 return r;
811} 812}
812 813
813void AbTable::setShowCategory( const QString &b, const QString &c ) 814void AbTable::setShowCategory( const QString &b, const QString &c )
814{ 815{
815 showBk = b; 816 showBk = b;
816 showCat = c; 817 showCat = c;
817 //QMessageBox::information( this, "setShowCategory", "setShowCategory" ); 818 //QMessageBox::information( this, "setShowCategory", "setShowCategory" );
818 //updateVisible(); 819 //updateVisible();
819 refresh(); 820 refresh();
820 ensureCellVisible( currentRow(), 0 ); 821 ensureCellVisible( currentRow(), 0 );
821 updateVisible(); // :SX 822 updateVisible(); // :SX
822} 823}
823 824
824void AbTable::setShowByLetter( char c ) 825void AbTable::setShowByLetter( char c )
825{ 826{
826 showChar = tolower(c); 827 showChar = tolower(c);
827 updateVisible(); 828 updateVisible();
828} 829}
829 830
830QString AbTable::showCategory() const 831QString AbTable::showCategory() const
831{ 832{
832 return showCat; 833 return showCat;
833} 834}
834 835
835QString AbTable::showBook() const 836QString AbTable::showBook() const
836{ 837{
837 return showBk; 838 return showBk;
838} 839}
839 840
840QStringList AbTable::categories() 841QStringList AbTable::categories()
841{ 842{
842 mCat.load( categoryFileName() ); 843 mCat.load( categoryFileName() );
843 QStringList categoryList = mCat.labels( "Contacts" ); 844 QStringList categoryList = mCat.labels( "Contacts" );
844 return categoryList; 845 return categoryList;
845} 846}
846 847
847void AbTable::updateVisible() 848void AbTable::updateVisible()
848{ 849{
849 int visible, 850 int visible,
850 totalRows, 851 totalRows,
851 id, 852 id,
852 totalCats, 853 totalCats,
853 it, 854 it,
854 row; 855 row;
855 bool hide; 856 bool hide;
856 AbTableItem *ati; 857 AbTableItem *ati;
857 OContact *cnt; 858 OContact *cnt;
858 QString fileAsName; 859 QString fileAsName;
859 QString tmpStr; 860 QString tmpStr;
860 visible = 0; 861 visible = 0;
861 862
862 setPaintingEnabled( FALSE ); 863 setPaintingEnabled( FALSE );
863 864
864 totalRows = numRows(); 865 totalRows = numRows();
865 id = mCat.id( "Contacts", showCat ); 866 id = mCat.id( "Contacts", showCat );
866 QArray<int> cats; 867 QArray<int> cats;
867 for ( row = 0; row < totalRows; row++ ) { 868 for ( row = 0; row < totalRows; row++ ) {
868 ati = static_cast<AbTableItem*>( item(row, 0) ); 869 ati = static_cast<AbTableItem*>( item(row, 0) );
869 cnt = &contactList[ati]; 870 cnt = &contactList[ati];
870 cats = cnt->categories(); 871 cats = cnt->categories();
871 fileAsName = cnt->fileAs(); 872 fileAsName = cnt->fileAs();
872 hide = false; 873 hide = false;
873 if ( !showCat.isEmpty() ) { 874 if ( !showCat.isEmpty() ) {
874 if ( showCat == tr( "Unfiled" ) ) { 875 if ( showCat == tr( "Unfiled" ) ) {
875 if ( cats.count() > 0 ) 876 if ( cats.count() > 0 )
876 hide = true; 877 hide = true;
877 } else { 878 } else {
878 // do some comparing 879 // do some comparing
879 if ( !hide ) { 880 if ( !hide ) {
880 hide = true; 881 hide = true;
881 totalCats = int(cats.count()); 882 totalCats = int(cats.count());
882 for ( it = 0; it < totalCats; it++ ) { 883 for ( it = 0; it < totalCats; it++ ) {
883 if ( cats[it] == id ) { 884 if ( cats[it] == id ) {
884 hide = false; 885 hide = false;
885 break; 886 break;
886 } 887 }
887 } 888 }
888 } 889 }
889 } 890 }
890 } 891 }
891 if ( showChar != '\0' ) { 892 if ( showChar != '\0' ) {
892 tmpStr = fileAsName.left(1); 893 tmpStr = fileAsName.left(1);
893 tmpStr = tmpStr.lower(); 894 tmpStr = tmpStr.lower();
894 if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) { 895 if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) {
895 hide = true; 896 hide = true;
896 } 897 }
897 if ( showChar == '#' ) { 898 if ( showChar == '#' ) {
898 if (tmpStr == "a") 899 if (tmpStr == "a")
899 hide = true; 900 hide = true;
900 901
901 if (tmpStr == "b") 902 if (tmpStr == "b")
902 hide = true; 903 hide = true;
903 904
904 if (tmpStr == "c") 905 if (tmpStr == "c")
905 hide = true; 906 hide = true;
906 907
907 if (tmpStr == "d") 908 if (tmpStr == "d")
908 hide = true; 909 hide = true;
909 910
910 if (tmpStr == "e") 911 if (tmpStr == "e")
911 hide = true; 912 hide = true;
912 913
913 if (tmpStr == "f") 914 if (tmpStr == "f")
914 hide = true; 915 hide = true;
915 916
916 if (tmpStr == "g") 917 if (tmpStr == "g")
917 hide = true; 918 hide = true;
918 919
919 if (tmpStr == "h") 920 if (tmpStr == "h")
920 hide = true; 921 hide = true;
921 922
922 if (tmpStr == "i") 923 if (tmpStr == "i")
923 hide = true; 924 hide = true;
924 925
925 if (tmpStr == "j") 926 if (tmpStr == "j")
926 hide = true; 927 hide = true;
927 928
928 if (tmpStr == "k") 929 if (tmpStr == "k")
929 hide = true; 930 hide = true;
930 931
931 if (tmpStr == "l") 932 if (tmpStr == "l")
932 hide = true; 933 hide = true;
933 934
934 if (tmpStr == "m") 935 if (tmpStr == "m")
935 hide = true; 936 hide = true;
936 937
937 if (tmpStr == "n") 938 if (tmpStr == "n")
938 hide = true; 939 hide = true;
939 940
940 if (tmpStr == "o") 941 if (tmpStr == "o")
941 hide = true; 942 hide = true;
942 943
943 if (tmpStr == "p") 944 if (tmpStr == "p")
944 hide = true; 945 hide = true;
945 946
946 if (tmpStr == "q") 947 if (tmpStr == "q")
947 hide = true; 948 hide = true;
948 949
949 if (tmpStr == "r") 950 if (tmpStr == "r")
950 hide = true; 951 hide = true;
951 952
952 if (tmpStr == "s") 953 if (tmpStr == "s")
953 hide = true; 954 hide = true;
954 955
955 if (tmpStr == "t") 956 if (tmpStr == "t")
956 hide = true; 957 hide = true;
957 958
958 if (tmpStr == "u") 959 if (tmpStr == "u")
959 hide = true; 960 hide = true;
960 961
961 if (tmpStr == "v") 962 if (tmpStr == "v")
962 hide = true; 963 hide = true;
963 964
964 if (tmpStr == "w") 965 if (tmpStr == "w")
965 hide = true; 966 hide = true;
966 967
967 if (tmpStr == "x") 968 if (tmpStr == "x")
968 hide = true; 969 hide = true;
969 970
970 if (tmpStr == "y") 971 if (tmpStr == "y")
971 hide = true; 972 hide = true;
972 973
973 if (tmpStr == "z") 974 if (tmpStr == "z")
974 hide = true; 975 hide = true;
975 } 976 }
976 977
977 } 978 }
978 if ( hide ) { 979 if ( hide ) {
979 if ( currentRow() == row ) 980 if ( currentRow() == row )
980 setCurrentCell( -1, 0 ); 981 setCurrentCell( -1, 0 );
981 if ( rowHeight(row) > 0 ) 982 if ( rowHeight(row) > 0 )
982 hideRow( row ); 983 hideRow( row );
983 } else { 984 } else {
984 if ( rowHeight(row) == 0 ) { 985 if ( rowHeight(row) == 0 ) {
985 showRow( row ); 986 showRow( row );
986 adjustRow( row ); 987 adjustRow( row );
987 } 988 }
988 visible++; 989 visible++;
989 } 990 }
990 } 991 }
991 if ( !visible ) 992 if ( !visible )
992 setCurrentCell( -1, 0 ); 993 setCurrentCell( -1, 0 );
993 994
994 setPaintingEnabled( TRUE ); 995 setPaintingEnabled( TRUE );
995} 996}
996 997
997 998
998void AbTable::setPaintingEnabled( bool e ) 999void AbTable::setPaintingEnabled( bool e )
999{ 1000{
1000 if ( e != enablePainting ) { 1001 if ( e != enablePainting ) {
1001 if ( !enablePainting ) { 1002 if ( !enablePainting ) {
1002 enablePainting = true; 1003 enablePainting = true;
1003 rowHeightChanged( 0 ); 1004 rowHeightChanged( 0 );
1004 viewport()->update(); 1005 viewport()->update();
1005 } else { 1006 } else {
1006 enablePainting = false; 1007 enablePainting = false;
1007 } 1008 }
1008 } 1009 }
1009} 1010}
1010 1011
1011void AbTable::rowHeightChanged( int row ) 1012void AbTable::rowHeightChanged( int row )
1012{ 1013{
1013 if ( enablePainting ) 1014 if ( enablePainting )
1014 QTable::rowHeightChanged( row ); 1015 QTable::rowHeightChanged( row );
1015} 1016}
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h
index 1039e66..b445874 100644
--- a/core/pim/addressbook/abtable.h
+++ b/core/pim/addressbook/abtable.h
@@ -1,154 +1,154 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
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** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef ABTABLE_H 21#ifndef ABTABLE_H
22#define ABTABLE_H 22#define ABTABLE_H
23 23
24#include <qpe/categories.h> 24#include <qpe/categories.h>
25#include <opie/ocontact.h> 25#include <opie/ocontact.h>
26 26
27#include <qmap.h> 27#include <qmap.h>
28#include <qtable.h> 28#include <qtable.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31 31
32#include <opie/ocontactaccess.h> 32#include <opie/ocontactaccess.h>
33 33
34class AbTableItem : public QTableItem 34class AbTableItem : public QTableItem
35{ 35{
36public: 36public:
37 AbTableItem( QTable *t, EditType et, const QString &s, 37 AbTableItem( QTable *t, EditType et, const QString &s,
38 const QString &secondSortKey); 38 const QString &secondSortKey);
39 QString entryKey() const; 39 QString entryKey() const;
40 void setEntryKey( const QString & k ); 40 void setEntryKey( const QString & k );
41 virtual int alignment() const; 41 virtual int alignment() const;
42 virtual QString key() const; 42 virtual QString key() const;
43 void setItem( const QString &txt, const QString &secondKey ); 43 void setItem( const QString &txt, const QString &secondKey );
44 44
45private: 45private:
46 QString sortKey; 46 QString sortKey;
47}; 47};
48 48
49class AbPickItem : public QTableItem 49class AbPickItem : public QTableItem
50{ 50{
51public: 51public:
52 AbPickItem( QTable *t ); 52 AbPickItem( QTable *t );
53 53
54 QWidget *createEditor() const; 54 QWidget *createEditor() const;
55 void setContentFromEditor( QWidget *w ); 55 void setContentFromEditor( QWidget *w );
56 56
57private: 57private:
58 QGuardedPtr<QComboBox> cb; 58 QGuardedPtr<QComboBox> cb;
59}; 59};
60 60
61class AbTable : public QTable 61class AbTable : public QTable
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64 64
65public: 65public:
66 AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); 66 AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 );
67 ~AbTable(); 67 ~AbTable();
68 // NEW 68 // NEW
69 void addEntry( const OContact &newContact ); 69 void addEntry( const OContact &newContact );
70 OContact currentEntry(); 70 OContact currentEntry();
71 void replaceCurrentEntry( const OContact &newContact ); 71 void replaceCurrentEntry( const OContact &newContact );
72 72
73 void init(); 73 void init();
74 74
75 void deleteCurrentEntry(); 75 void deleteCurrentEntry();
76 void clear(); 76 void clear();
77 void clearFindRow() { currFindRow = -1; } 77 void clearFindRow() { currFindRow = -1; }
78 void loadFields(); 78 void loadFields();
79 void refresh(); 79 void refresh();
80 bool save(); 80 bool save();
81 void load(); 81 void load();
82 void reload(); 82 void reload();
83 83
84 // addresspicker mode 84 // addresspicker mode
85 void setChoiceNames( const QStringList& list); 85 void setChoiceNames( const QStringList& list);
86 QStringList choiceNames() const; 86 QStringList choiceNames() const;
87 void setChoiceSelection(int index, const QStringList& list); 87 void setChoiceSelection(int index, const QStringList& list);
88 QStringList choiceSelection(int index) const; 88 QStringList choiceSelection(int index) const;
89 void setShowCategory( const QString &b, const QString &c ); 89 void setShowCategory( const QString &b, const QString &c );
90 void setShowByLetter( char c ); 90 void setShowByLetter( char c );
91 QString showCategory() const; 91 QString showCategory() const;
92 QStringList categories(); 92 QStringList categories();
93 93
94 void resizeRows(); 94 void resizeRows();
95 95
96 void show(); 96 void show();
97 void setPaintingEnabled( bool e ); 97 void setPaintingEnabled( bool e );
98 98
99 QString showBook() const; 99 QString showBook() const;
100 100
101public slots: 101public slots:
102 void slotDoFind( const QString &str, bool caseSensitive, bool backwards, 102 void slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, bool backwards,
103 QString category = QString::null ); 103 QString category = QString::null );
104signals: 104signals:
105 void empty( bool ); 105 void empty( bool );
106 void details(); 106 void details();
107 void signalNotFound(); 107 void signalNotFound();
108 void signalWrapAround(); 108 void signalWrapAround();
109 109
110protected: 110protected:
111 virtual void keyPressEvent( QKeyEvent *e ); 111 virtual void keyPressEvent( QKeyEvent *e );
112 112
113// int rowHeight( int ) const; 113// int rowHeight( int ) const;
114// int rowPos( int row ) const; 114// int rowPos( int row ) const;
115// virtual int rowAt( int pos ) const; 115// virtual int rowAt( int pos ) const;
116 116
117 117
118protected slots: 118protected slots:
119 void moveTo( char ); 119 void moveTo( char );
120 virtual void columnClicked( int col ); 120 virtual void columnClicked( int col );
121 void itemClicked(int,int col); 121 void itemClicked(int,int col);
122 void rowHeightChanged( int row ); 122 void rowHeightChanged( int row );
123 123
124private: 124private:
125 void loadFile( const QString &strFile, bool journalFile ); 125 void loadFile( const QString &strFile, bool journalFile );
126 void fitColumns(); 126 void fitColumns();
127 void resort(); 127 void resort();
128 void updateJournal( const OContact &contact, OContact::journal_action action, 128 void updateJournal( const OContact &contact, OContact::journal_action action,
129 int row = -1 ); 129 int row = -1 );
130 void insertIntoTable( const OContact &contact, int row ); 130 void insertIntoTable( const OContact &contact, int row );
131 QString findContactName( const OContact &entry ); 131 QString findContactName( const OContact &entry );
132 QString findContactContact( const OContact &entry, int row ); 132 QString findContactContact( const OContact &entry, int row );
133 void journalFreeReplace( const OContact &cnt, int row ); 133 void journalFreeReplace( const OContact &cnt, int row );
134 void journalFreeRemove( int row ); 134 void journalFreeRemove( int row );
135 void realignTable( int ); 135 void realignTable( int );
136 void updateVisible(); 136 void updateVisible();
137 int lastSortCol; 137 int lastSortCol;
138 bool asc; 138 bool asc;
139 char showChar; 139 char showChar;
140 QMap<AbTableItem*, OContact> contactList; 140 QMap<AbTableItem*, OContact> contactList;
141 const QValueList<int> *intFields; 141 const QValueList<int> *intFields;
142 int currFindRow; 142 int currFindRow;
143 QString showCat; 143 QString showCat;
144 QStringList choicenames; 144 QStringList choicenames;
145 bool enablePainting; 145 bool enablePainting;
146 Categories mCat; 146 Categories mCat;
147 147
148 QString showBk; 148 QString showBk;
149 bool columnVisible; 149 bool columnVisible;
150 150
151 OContactAccess m_contactdb; 151 OContactAccess m_contactdb;
152 152
153}; 153};
154#endif // ABTABLE_H 154#endif // ABTABLE_H
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index 84e66fb..f7e4c95 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -435,622 +435,622 @@ void AddressbookWindow::slotListView()
435 showView(); 435 showView();
436} 436}
437 437
438void AddressbookWindow::slotListDelete() 438void AddressbookWindow::slotListDelete()
439{ 439{
440 if(!syncing) { 440 if(!syncing) {
441 OContact tmpEntry = abList->currentEntry(); 441 OContact tmpEntry = abList->currentEntry();
442 442
443 // get a name, do the best we can... 443 // get a name, do the best we can...
444 QString strName = tmpEntry.fullName(); 444 QString strName = tmpEntry.fullName();
445 if ( strName.isEmpty() ) { 445 if ( strName.isEmpty() ) {
446 strName = tmpEntry.company(); 446 strName = tmpEntry.company();
447 if ( strName.isEmpty() ) 447 if ( strName.isEmpty() )
448 strName = "No Name"; 448 strName = "No Name";
449 } 449 }
450 450
451 451
452 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), 452 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ),
453 strName ) ) { 453 strName ) ) {
454 abList->deleteCurrentEntry(); 454 abList->deleteCurrentEntry();
455 showList(); 455 showList();
456 } 456 }
457 } else { 457 } else {
458 QMessageBox::warning( this, tr("Contacts"), 458 QMessageBox::warning( this, tr("Contacts"),
459 tr("Can not edit data, currently syncing") ); 459 tr("Can not edit data, currently syncing") );
460 } 460 }
461} 461}
462 462
463void AddressbookWindow::slotViewBack() 463void AddressbookWindow::slotViewBack()
464{ 464{
465 showList(); 465 showList();
466} 466}
467 467
468void AddressbookWindow::slotViewEdit() 468void AddressbookWindow::slotViewEdit()
469{ 469{
470 if(!syncing) { 470 if(!syncing) {
471 if (actionPersonal->isOn()) { 471 if (actionPersonal->isOn()) {
472 editPersonal(); 472 editPersonal();
473 } else { 473 } else {
474 if ( !bAbEditFirstTime ) 474 if ( !bAbEditFirstTime )
475 abEditor->setEntry( abList->currentEntry() ); 475 abEditor->setEntry( abList->currentEntry() );
476 editEntry( EditEntry ); 476 editEntry( EditEntry );
477 } 477 }
478 } else { 478 } else {
479 QMessageBox::warning( this, tr("Contacts"), 479 QMessageBox::warning( this, tr("Contacts"),
480 tr("Can not edit data, currently syncing") ); 480 tr("Can not edit data, currently syncing") );
481 } 481 }
482} 482}
483 483
484 484
485 485
486void AddressbookWindow::writeMail() 486void AddressbookWindow::writeMail()
487{ 487{
488 OContact c = abList->currentEntry(); 488 OContact c = abList->currentEntry();
489 QString name = c.fileAs(); 489 QString name = c.fileAs();
490 QString email = c.defaultEmail(); 490 QString email = c.defaultEmail();
491 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 491 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
492 e << name << email; 492 e << name << email;
493} 493}
494 494
495static const char * beamfile = "/tmp/obex/contact.vcf"; 495static const char * beamfile = "/tmp/obex/contact.vcf";
496 496
497void AddressbookWindow::slotBeam() 497void AddressbookWindow::slotBeam()
498{ 498{
499 QString filename; 499 QString filename;
500 OContact c; 500 OContact c;
501 if ( actionPersonal->isOn() ) { 501 if ( actionPersonal->isOn() ) {
502 filename = addressbookPersonalVCardName(); 502 filename = addressbookPersonalVCardName();
503 if (!QFile::exists(filename)) 503 if (!QFile::exists(filename))
504 return; // can't beam a non-existent file 504 return; // can't beam a non-existent file
505 c = OContact::readVCard( filename )[0]; 505 c = OContact::readVCard( filename )[0];
506 } else { 506 } else {
507 unlink( beamfile ); // delete if exists 507 unlink( beamfile ); // delete if exists
508 c = abList->currentEntry(); 508 c = abList->currentEntry();
509 mkdir("/tmp/obex/", 0755); 509 mkdir("/tmp/obex/", 0755);
510 OContact::writeVCard( beamfile, c ); 510 OContact::writeVCard( beamfile, c );
511 filename = beamfile; 511 filename = beamfile;
512 } 512 }
513 Ir *ir = new Ir( this ); 513 Ir *ir = new Ir( this );
514 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 514 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
515 QString description = c.fullName(); 515 QString description = c.fullName();
516 ir->send( filename, description, "text/x-vCard" ); 516 ir->send( filename, description, "text/x-vCard" );
517} 517}
518 518
519void AddressbookWindow::beamDone( Ir *ir ) 519void AddressbookWindow::beamDone( Ir *ir )
520{ 520{
521 delete ir; 521 delete ir;
522 unlink( beamfile ); 522 unlink( beamfile );
523} 523}
524 524
525 525
526static void parseName( const QString& name, QString *first, QString *middle, 526static void parseName( const QString& name, QString *first, QString *middle,
527 QString * last ) 527 QString * last )
528{ 528{
529 529
530 int comma = name.find ( "," ); 530 int comma = name.find ( "," );
531 QString rest; 531 QString rest;
532 if ( comma > 0 ) { 532 if ( comma > 0 ) {
533 *last = name.left( comma ); 533 *last = name.left( comma );
534 comma++; 534 comma++;
535 while ( comma < int(name.length()) && name[comma] == ' ' ) 535 while ( comma < int(name.length()) && name[comma] == ' ' )
536 comma++; 536 comma++;
537 rest = name.mid( comma ); 537 rest = name.mid( comma );
538 } else { 538 } else {
539 int space = name.findRev( ' ' ); 539 int space = name.findRev( ' ' );
540 *last = name.mid( space+1 ); 540 *last = name.mid( space+1 );
541 rest = name.left( space ); 541 rest = name.left( space );
542 } 542 }
543 int space = rest.find( ' ' ); 543 int space = rest.find( ' ' );
544 if ( space <= 0 ) { 544 if ( space <= 0 ) {
545 *first = rest; 545 *first = rest;
546 } else { 546 } else {
547 *first = rest.left( space ); 547 *first = rest.left( space );
548 *middle = rest.mid( space+1 ); 548 *middle = rest.mid( space+1 );
549 } 549 }
550 550
551} 551}
552 552
553 553
554void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) 554void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
555{ 555{
556 if (msg == "editPersonal()") { 556 if (msg == "editPersonal()") {
557 editPersonal(); 557 editPersonal();
558 } else if (msg == "editPersonalAndClose()") { 558 } else if (msg == "editPersonalAndClose()") {
559 editPersonal(); 559 editPersonal();
560 close(); 560 close();
561 } else if ( msg == "addContact(QString,QString)" ) { 561 } else if ( msg == "addContact(QString,QString)" ) {
562 QDataStream stream(data,IO_ReadOnly); 562 QDataStream stream(data,IO_ReadOnly);
563 QString name, email; 563 QString name, email;
564 stream >> name >> email; 564 stream >> name >> email;
565 565
566 OContact cnt; 566 OContact cnt;
567 QString fn, mn, ln; 567 QString fn, mn, ln;
568 parseName( name, &fn, &mn, &ln ); 568 parseName( name, &fn, &mn, &ln );
569 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); 569 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
570 cnt.setFirstName( fn ); 570 cnt.setFirstName( fn );
571 cnt.setMiddleName( mn ); 571 cnt.setMiddleName( mn );
572 cnt.setLastName( ln ); 572 cnt.setLastName( ln );
573 cnt.insertEmails( email ); 573 cnt.insertEmails( email );
574 cnt.setDefaultEmail( email ); 574 cnt.setDefaultEmail( email );
575 cnt.setFileAs(); 575 cnt.setFileAs();
576 576
577 if ( bAbEditFirstTime ) { 577 if ( bAbEditFirstTime ) {
578 abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, 578 abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields,
579 this, "editor" ); 579 this, "editor" );
580 bAbEditFirstTime = FALSE; 580 bAbEditFirstTime = FALSE;
581 } else { 581 } else {
582 abEditor->setEntry( cnt ); 582 abEditor->setEntry( cnt );
583 } 583 }
584 abView()->init( cnt ); 584 abView()->init( cnt );
585 editEntry( NewEntry ); 585 editEntry( NewEntry );
586 586
587 587
588 588
589 } 589 }
590#if 0 590#if 0
591 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { 591 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) {
592 QDataStream stream(data,IO_ReadOnly); 592 QDataStream stream(data,IO_ReadOnly);
593 QCString ch,m; 593 QCString ch,m;
594 QStringList types; 594 QStringList types;
595 stream >> ch >> m >> types; 595 stream >> ch >> m >> types;
596 AddressPicker picker(abList,this,0,TRUE); 596 AddressPicker picker(abList,this,0,TRUE);
597 picker.showMaximized(); 597 picker.showMaximized();
598 picker.setChoiceNames(types); 598 picker.setChoiceNames(types);
599 int i=0; 599 int i=0;
600 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 600 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
601 QStringList sel; 601 QStringList sel;
602 stream >> sel; 602 stream >> sel;
603 picker.setSelection(i++,sel); 603 picker.setSelection(i++,sel);
604 } 604 }
605 picker.showMaximized(); 605 picker.showMaximized();
606 picker.exec(); 606 picker.exec();
607 607
608 // ###### note: contacts may have been added - save here! 608 // ###### note: contacts may have been added - save here!
609 609
610 setCentralWidget(abList); 610 setCentralWidget(abList);
611 QCopEnvelope e(ch,m); 611 QCopEnvelope e(ch,m);
612 i=0; 612 i=0;
613 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 613 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
614 QStringList sel = picker.selection(i++); 614 QStringList sel = picker.selection(i++);
615 e << sel; 615 e << sel;
616 } 616 }
617 } 617 }
618#endif 618#endif
619 619
620} 620}
621 621
622void AddressbookWindow::editPersonal() 622void AddressbookWindow::editPersonal()
623{ 623{
624 QString filename = addressbookPersonalVCardName(); 624 QString filename = addressbookPersonalVCardName();
625 OContact me; 625 OContact me;
626 if (QFile::exists(filename)) 626 if (QFile::exists(filename))
627 me = OContact::readVCard( filename )[0]; 627 me = OContact::readVCard( filename )[0];
628 if (bAbEditFirstTime) { 628 if (bAbEditFirstTime) {
629 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, 629 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields,
630 this, "editor" ); 630 this, "editor" );
631 // don't create a new editor every time 631 // don't create a new editor every time
632 bAbEditFirstTime = FALSE; 632 bAbEditFirstTime = FALSE;
633 } else 633 } else
634 abEditor->setEntry( me ); 634 abEditor->setEntry( me );
635 635
636 abEditor->setCaption(tr("Edit My Personal Details")); 636 abEditor->setCaption(tr("Edit My Personal Details"));
637 abEditor->showMaximized(); 637 abEditor->showMaximized();
638 638
639 // fix the foxus... 639 // fix the foxus...
640 abEditor->setNameFocus(); 640 abEditor->setNameFocus();
641 if ( abEditor->exec() ) { 641 if ( abEditor->exec() ) {
642 setFocus(); 642 setFocus();
643 OContact new_personal = abEditor->entry(); 643 OContact new_personal = abEditor->entry();
644 QString fname = addressbookPersonalVCardName(); 644 QString fname = addressbookPersonalVCardName();
645 OContact::writeVCard( fname, new_personal ); 645 OContact::writeVCard( fname, new_personal );
646 abView()->init(new_personal); 646 abView()->init(new_personal);
647 abView()->sync(); 647 abView()->sync();
648 } 648 }
649 abEditor->setCaption( tr("Edit Address") ); 649 abEditor->setCaption( tr("Edit Address") );
650} 650}
651 651
652void AddressbookWindow::slotPersonalView() 652void AddressbookWindow::slotPersonalView()
653{ 653{
654 if (!actionPersonal->isOn()) { 654 if (!actionPersonal->isOn()) {
655 // we just turned it off 655 // we just turned it off
656 setCaption( tr("Contacts") ); 656 setCaption( tr("Contacts") );
657 actionNew->setEnabled(TRUE); 657 actionNew->setEnabled(TRUE);
658 actionTrash->setEnabled(TRUE); 658 actionTrash->setEnabled(TRUE);
659#ifndef MAKE_FOR_SHARP_ROM 659#ifndef MAKE_FOR_SHARP_ROM
660 actionFind->setEnabled(TRUE); 660 actionFind->setEnabled(TRUE);
661#endif 661#endif
662 slotUpdateToolbar(); // maybe some of the above could be moved there 662 slotUpdateToolbar(); // maybe some of the above could be moved there
663 showList(); 663 showList();
664 return; 664 return;
665 } 665 }
666 666
667 // XXX need to disable some QActions. 667 // XXX need to disable some QActions.
668 actionNew->setEnabled(FALSE); 668 actionNew->setEnabled(FALSE);
669 actionTrash->setEnabled(FALSE); 669 actionTrash->setEnabled(FALSE);
670#ifndef MAKE_FOR_SHARP_ROM 670#ifndef MAKE_FOR_SHARP_ROM
671 actionFind->setEnabled(FALSE); 671 actionFind->setEnabled(FALSE);
672#endif 672#endif
673 actionMail->setEnabled(FALSE); 673 actionMail->setEnabled(FALSE);
674 674
675 setCaption( tr("Contacts - My Personal Details") ); 675 setCaption( tr("Contacts - My Personal Details") );
676 QString filename = addressbookPersonalVCardName(); 676 QString filename = addressbookPersonalVCardName();
677 OContact me; 677 OContact me;
678 if (QFile::exists(filename)) 678 if (QFile::exists(filename))
679 me = OContact::readVCard( filename )[0]; 679 me = OContact::readVCard( filename )[0];
680 680
681 abView()->init( me ); 681 abView()->init( me );
682 abView()->sync(); 682 abView()->sync();
683 listContainer->hide(); 683 listContainer->hide();
684 setCentralWidget( abView() ); 684 setCentralWidget( abView() );
685 mView->show(); 685 mView->show();
686 mView->setFocus(); 686 mView->setFocus();
687} 687}
688 688
689void AddressbookWindow::editEntry( EntryMode entryMode ) 689void AddressbookWindow::editEntry( EntryMode entryMode )
690{ 690{
691 OContact entry; 691 OContact entry;
692 if ( bAbEditFirstTime ) { 692 if ( bAbEditFirstTime ) {
693 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, 693 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields,
694 this, "editor" ); 694 this, "editor" );
695 bAbEditFirstTime = FALSE; 695 bAbEditFirstTime = FALSE;
696 if ( entryMode == EditEntry ) 696 if ( entryMode == EditEntry )
697 abEditor->setEntry( abList->currentEntry() ); 697 abEditor->setEntry( abList->currentEntry() );
698 } 698 }
699 // other things may chane the caption. 699 // other things may chane the caption.
700 abEditor->setCaption( tr("Edit Address") ); 700 abEditor->setCaption( tr("Edit Address") );
701 701
702#if defined(Q_WS_QWS) || defined(_WS_QWS_) 702#if defined(Q_WS_QWS) || defined(_WS_QWS_)
703 abEditor->showMaximized(); 703 abEditor->showMaximized();
704#endif 704#endif
705 // fix the foxus... 705 // fix the foxus...
706 abEditor->setNameFocus(); 706 abEditor->setNameFocus();
707 if ( abEditor->exec() ) { 707 if ( abEditor->exec() ) {
708 setFocus(); 708 setFocus();
709 if ( entryMode == NewEntry ) { 709 if ( entryMode == NewEntry ) {
710 OContact insertEntry = abEditor->entry(); 710 OContact insertEntry = abEditor->entry();
711 insertEntry.assignUid(); 711 insertEntry.assignUid();
712 abList->addEntry( insertEntry ); 712 abList->addEntry( insertEntry );
713 } else { 713 } else {
714 OContact replaceEntry = abEditor->entry(); 714 OContact replaceEntry = abEditor->entry();
715 if ( !replaceEntry.isValidUid() ) 715 if ( !replaceEntry.isValidUid() )
716 replaceEntry.assignUid(); 716 replaceEntry.assignUid();
717 abList->replaceCurrentEntry( replaceEntry ); 717 abList->replaceCurrentEntry( replaceEntry );
718 } 718 }
719 } 719 }
720 populateCategories(); 720 populateCategories();
721 showList(); 721 showList();
722} 722}
723 723
724void AddressbookWindow::listIsEmpty( bool empty ) 724void AddressbookWindow::listIsEmpty( bool empty )
725{ 725{
726 if ( !empty ) { 726 if ( !empty ) {
727 deleteButton->setEnabled( TRUE ); 727 deleteButton->setEnabled( TRUE );
728 } 728 }
729} 729}
730 730
731void AddressbookWindow::reload() 731void AddressbookWindow::reload()
732{ 732{
733 syncing = FALSE; 733 syncing = FALSE;
734 abList->clear(); 734 abList->clear();
735 abList->reload(); 735 abList->reload();
736} 736}
737 737
738void AddressbookWindow::flush() 738void AddressbookWindow::flush()
739{ 739{
740 syncing = TRUE; 740 syncing = TRUE;
741 abList->save(); 741 abList->save();
742} 742}
743 743
744 744
745void AddressbookWindow::closeEvent( QCloseEvent *e ) 745void AddressbookWindow::closeEvent( QCloseEvent *e )
746{ 746{
747 if ( centralWidget() == mView ) { 747 if ( centralWidget() == mView ) {
748 if (actionPersonal->isOn()) { 748 if (actionPersonal->isOn()) {
749 // pretend we clicked it off 749 // pretend we clicked it off
750 actionPersonal->setOn(FALSE); 750 actionPersonal->setOn(FALSE);
751 slotPersonalView(); 751 slotPersonalView();
752 } else { 752 } else {
753 showList(); 753 showList();
754 } 754 }
755 e->ignore(); 755 e->ignore();
756 return; 756 return;
757 } 757 }
758 758
759 if(syncing) { 759 if(syncing) {
760 /* shouldn't we save, I hear you say? well its already been set 760 /* shouldn't we save, I hear you say? well its already been set
761 so that an edit can not occur during a sync, and we flushed 761 so that an edit can not occur during a sync, and we flushed
762 at the start of the sync, so there is no need to save 762 at the start of the sync, so there is no need to save
763 Saving however itself would cause problems. */ 763 Saving however itself would cause problems. */
764 e->accept(); 764 e->accept();
765 return; 765 return;
766 } 766 }
767 //################## shouldn't always save 767 //################## shouldn't always save
768 // True, but the database handles this automatically ! (se) 768 // True, but the database handles this automatically ! (se)
769 if ( save() ) 769 if ( save() )
770 e->accept(); 770 e->accept();
771 else 771 else
772 e->ignore(); 772 e->ignore();
773} 773}
774 774
775/* 775/*
776 Returns TRUE if it is OK to exit 776 Returns TRUE if it is OK to exit
777*/ 777*/
778 778
779bool AddressbookWindow::save() 779bool AddressbookWindow::save()
780{ 780{
781 if ( !abList->save() ) { 781 if ( !abList->save() ) {
782 if ( QMessageBox::critical( 0, tr( "Out of space" ), 782 if ( QMessageBox::critical( 0, tr( "Out of space" ),
783 tr("Unable to save information.\n" 783 tr("Unable to save information.\n"
784 "Free up some space\n" 784 "Free up some space\n"
785 "and try again.\n" 785 "and try again.\n"
786 "\nQuit anyway?"), 786 "\nQuit anyway?"),
787 QMessageBox::Yes|QMessageBox::Escape, 787 QMessageBox::Yes|QMessageBox::Escape,
788 QMessageBox::No|QMessageBox::Default ) 788 QMessageBox::No|QMessageBox::Default )
789 != QMessageBox::No ) 789 != QMessageBox::No )
790 return TRUE; 790 return TRUE;
791 else 791 else
792 return FALSE; 792 return FALSE;
793 } 793 }
794 return TRUE; 794 return TRUE;
795} 795}
796 796
797#ifdef __DEBUG_RELEASE 797#ifdef __DEBUG_RELEASE
798void AddressbookWindow::slotSave() 798void AddressbookWindow::slotSave()
799{ 799{
800 save(); 800 save();
801} 801}
802#endif 802#endif
803 803
804void AddressbookWindow::slotSettings() 804void AddressbookWindow::slotSettings()
805{ 805{
806 AddressSettings frmSettings( this ); 806 AddressSettings frmSettings( this );
807#if defined(Q_WS_QWS) || defined(_WS_QWS_) 807#if defined(Q_WS_QWS) || defined(_WS_QWS_)
808 frmSettings.showMaximized(); 808 frmSettings.showMaximized();
809#endif 809#endif
810 810
811 if ( frmSettings.exec() ) { 811 if ( frmSettings.exec() ) {
812 allFields.clear(); 812 allFields.clear();
813 orderedFields.clear(); 813 orderedFields.clear();
814 slOrderedFields.clear(); 814 slOrderedFields.clear();
815 initFields(); 815 initFields();
816 if ( abEditor ) 816 if ( abEditor )
817 abEditor->loadFields(); 817 abEditor->loadFields();
818 abList->refresh(); 818 abList->refresh();
819 } 819 }
820} 820}
821 821
822 822
823void AddressbookWindow::initFields() 823void AddressbookWindow::initFields()
824{ 824{
825 // we really don't need the things from the configuration, anymore 825 // we really don't need the things from the configuration, anymore
826 // only thing that is important are the important categories. So, 826 // only thing that is important are the important categories. So,
827 // Call the contact functions that correspond to these old functions... 827 // Call the contact functions that correspond to these old functions...
828 828
829 QStringList xmlFields = OContact::fields(); 829 QStringList xmlFields = OContact::fields();
830 QStringList visibleFields = OContact::untrfields(); 830 QStringList visibleFields = OContact::untrfields();
831 // QStringList trFields = OContact::trfields(); 831 // QStringList trFields = OContact::trfields();
832 832
833 xmlFields.remove( "Title" ); 833 xmlFields.remove( "Title" );
834 visibleFields.remove( "Name Title" ); 834 visibleFields.remove( "Name Title" );
835 visibleFields.remove( "Notes" ); 835 visibleFields.remove( "Notes" );
836 836
837 int i, version; 837 int i, version;
838 Config cfg( "AddressBook" ); 838 Config cfg( "AddressBook" );
839 QString zn; 839 QString zn;
840 840
841 // ### Write a function to keep this from happening again... 841 // ### Write a function to keep this from happening again...
842 QStringList::ConstIterator it; 842 QStringList::ConstIterator it;
843 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { 843 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) {
844 allFields.append( i + 3 ); 844 allFields.append( i + 3 );
845 } 845 }
846 846
847 cfg.setGroup( "Version" ); 847 cfg.setGroup( "Version" );
848 version = cfg.readNumEntry( "version" ); 848 version = cfg.readNumEntry( "version" );
849 i = 0; 849 i = 0;
850 startFontSize = 1; 850 startFontSize = 1;
851 851
852 if ( version >= ADDRESSVERSION ) { 852 if ( version >= ADDRESSVERSION ) {
853 853
854 cfg.setGroup( "ImportantCategory" ); 854 cfg.setGroup( "ImportantCategory" );
855 855
856 zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); 856 zn = cfg.readEntry( "Category" + QString::number(i), QString::null );
857 while ( !zn.isNull() ) { 857 while ( !zn.isNull() ) {
858 if ( zn.contains( "Work" ) || zn.contains( "Mb" ) ) { 858 if ( zn.contains( "Work" ) || zn.contains( "Mb" ) ) {
859 slOrderedFields.clear(); 859 slOrderedFields.clear();
860 break; 860 break;
861 } 861 }
862 slOrderedFields.append( zn ); 862 slOrderedFields.append( zn );
863 zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); 863 zn = cfg.readEntry( "Category" + QString::number(++i), QString::null );
864 } 864 }
865 cfg.setGroup( "Font" ); 865 cfg.setGroup( "Font" );
866 startFontSize = cfg.readNumEntry( "fontSize", 1 ); 866 startFontSize = cfg.readNumEntry( "fontSize", 1 );
867 867
868 868
869 } else { 869 } else {
870 QString str; 870 QString str;
871 str = getenv("HOME"); 871 str = getenv("HOME");
872 str += "/Settings/AddressBook.conf"; 872 str += "/Settings/AddressBook.conf";
873 QFile::remove( str ); 873 QFile::remove( str );
874 } 874 }
875 875
876 if ( slOrderedFields.count() > 0 ) { 876 if ( slOrderedFields.count() > 0 ) {
877 for( QStringList::ConstIterator it = slOrderedFields.begin(); 877 for( QStringList::ConstIterator it = slOrderedFields.begin();
878 it != slOrderedFields.end(); ++it ) { 878 it != slOrderedFields.end(); ++it ) {
879 QValueList<int>::ConstIterator itVl; 879 QValueList<int>::ConstIterator itVl;
880 QStringList::ConstIterator itVis; 880 QStringList::ConstIterator itVis;
881 itVl = allFields.begin(); 881 itVl = allFields.begin();
882 for ( itVis = visibleFields.begin(); 882 for ( itVis = visibleFields.begin();
883 itVis != visibleFields.end() && itVl != allFields.end(); 883 itVis != visibleFields.end() && itVl != allFields.end();
884 ++itVis, ++itVl ) { 884 ++itVis, ++itVl ) {
885 if ( *it == *itVis && itVl != allFields.end() ) { 885 if ( *it == *itVis && itVl != allFields.end() ) {
886 orderedFields.append( *itVl ); 886 orderedFields.append( *itVl );
887 } 887 }
888 } 888 }
889 } 889 }
890 } else { 890 } else {
891 QValueList<int>::ConstIterator it; 891 QValueList<int>::ConstIterator it;
892 for ( it = allFields.begin(); it != allFields.end(); ++it ) 892 for ( it = allFields.begin(); it != allFields.end(); ++it )
893 orderedFields.append( *it ); 893 orderedFields.append( *it );
894 894
895 slOrderedFields = visibleFields; 895 slOrderedFields = visibleFields;
896 orderedFields.remove( Qtopia::AddressUid ); 896 orderedFields.remove( Qtopia::AddressUid );
897 orderedFields.remove( Qtopia::Title ); 897 orderedFields.remove( Qtopia::Title );
898 orderedFields.remove( Qtopia::Groups ); 898 orderedFields.remove( Qtopia::Groups );
899 orderedFields.remove( Qtopia::AddressCategory ); 899 orderedFields.remove( Qtopia::AddressCategory );
900 orderedFields.remove( Qtopia::FirstName ); 900 orderedFields.remove( Qtopia::FirstName );
901 orderedFields.remove( Qtopia::LastName ); 901 orderedFields.remove( Qtopia::LastName );
902 orderedFields.remove( Qtopia::DefaultEmail ); 902 orderedFields.remove( Qtopia::DefaultEmail );
903 orderedFields.remove( Qtopia::FileAs ); 903 orderedFields.remove( Qtopia::FileAs );
904 orderedFields.remove( Qtopia::Notes ); 904 orderedFields.remove( Qtopia::Notes );
905 orderedFields.remove( Qtopia::Gender ); 905 orderedFields.remove( Qtopia::Gender );
906 slOrderedFields.remove( "Name Title" ); 906 slOrderedFields.remove( "Name Title" );
907 slOrderedFields.remove( "First Name" ); 907 slOrderedFields.remove( "First Name" );
908 slOrderedFields.remove( "Last Name" ); 908 slOrderedFields.remove( "Last Name" );
909 slOrderedFields.remove( "File As" ); 909 slOrderedFields.remove( "File As" );
910 slOrderedFields.remove( "Default Email" ); 910 slOrderedFields.remove( "Default Email" );
911 slOrderedFields.remove( "Notes" ); 911 slOrderedFields.remove( "Notes" );
912 slOrderedFields.remove( "Gender" ); 912 slOrderedFields.remove( "Gender" );
913 913
914 } 914 }
915} 915}
916 916
917 917
918AbLabel *AddressbookWindow::abView() 918AbLabel *AddressbookWindow::abView()
919{ 919{
920 if ( !mView ) { 920 if ( !mView ) {
921 mView = new AbLabel( this, "viewer" ); 921 mView = new AbLabel( this, "viewer" );
922 mView->init( OContact() ); 922 mView->init( OContact() );
923 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); 923 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
924 } 924 }
925 return mView; 925 return mView;
926} 926}
927 927
928void AddressbookWindow::slotFindOpen() 928void AddressbookWindow::slotFindOpen()
929{ 929{
930 searchBar->show(); 930 searchBar->show();
931 searchEdit->setFocus(); 931 searchEdit->setFocus();
932} 932}
933void AddressbookWindow::slotFindClose() 933void AddressbookWindow::slotFindClose()
934{ 934{
935 searchBar->hide(); 935 searchBar->hide();
936 abList->setFocus(); 936 abList->setFocus();
937} 937}
938void AddressbookWindow::slotFindNext() 938void AddressbookWindow::slotFindNext()
939{ 939{
940 if ( centralWidget() == abView() ) 940 if ( centralWidget() == abView() )
941 showList(); 941 showList();
942 942
943 // Maybe we should react on Wraparound and notfound ? 943 // Maybe we should react on Wraparound and notfound ?
944 // QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); 944 // QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) );
945 // QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); 945 // QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) );
946 946
947 abList->slotDoFind( searchEdit->text(), false, false); 947 abList->slotDoFind( searchEdit->text(), caseSensitive, useRegExp, false);
948 948
949 949
950 if ( abList->numSelections() ) 950 if ( abList->numSelections() )
951 abList->clearSelection(); 951 abList->clearSelection();
952 952
953} 953}
954 954
955void AddressbookWindow::slotFind() 955void AddressbookWindow::slotFind()
956{ 956{
957 957
958 abList->clearFindRow(); 958 abList->clearFindRow();
959 slotFindNext(); 959 slotFindNext();
960} 960}
961 961
962void AddressbookWindow::slotSetCategory( int c ) 962void AddressbookWindow::slotSetCategory( int c )
963{ 963{
964 964
965 QString cat, book; 965 QString cat, book;
966 966
967 if ( c <= 0 ) 967 if ( c <= 0 )
968 return; 968 return;
969 969
970 // Set checkItem for selected one 970 // Set checkItem for selected one
971 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 971 for ( unsigned int i = 1; i < catMenu->count(); i++ )
972 catMenu->setItemChecked( i, c == (int)i ); 972 catMenu->setItemChecked( i, c == (int)i );
973 973
974 for ( unsigned int i = 1; i < catMenu->count(); i++ ) { 974 for ( unsigned int i = 1; i < catMenu->count(); i++ ) {
975 if (catMenu->isItemChecked( i )) { 975 if (catMenu->isItemChecked( i )) {
976 if ( i == 1 ) // default List view 976 if ( i == 1 ) // default List view
977 book = QString::null; 977 book = QString::null;
978 else if ( i == 2 ) 978 else if ( i == 2 )
979 book = "Phone"; 979 book = "Phone";
980 else if ( i == 3 ) 980 else if ( i == 3 )
981 book = "Company"; 981 book = "Company";
982 else if ( i == 4 ) 982 else if ( i == 4 )
983 book = "Email"; 983 book = "Email";
984 else if ( i == 5 ) 984 else if ( i == 5 )
985 book = "Cards"; 985 book = "Cards";
986 else if ( i == 6 ) // default All Categories 986 else if ( i == 6 ) // default All Categories
987 cat = QString::null; 987 cat = QString::null;
988 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled 988 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled
989 cat = "Unfiled"; 989 cat = "Unfiled";
990 else 990 else
991 cat = abList->categories()[i - 7]; 991 cat = abList->categories()[i - 7];
992 } 992 }
993 } 993 }
994 994
995 abList->setShowCategory( book, cat ); 995 abList->setShowCategory( book, cat );
996 996
997 if ( book.isEmpty() ) 997 if ( book.isEmpty() )
998 book = "List"; 998 book = "List";
999 if ( cat.isEmpty() ) 999 if ( cat.isEmpty() )
1000 cat = "All"; 1000 cat = "All";
1001 1001
1002 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) ); 1002 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) );
1003} 1003}
1004 1004
1005void AddressbookWindow::slotSetLetter( char c ) { 1005void AddressbookWindow::slotSetLetter( char c ) {
1006 1006
1007 abList->setShowByLetter( c ); 1007 abList->setShowByLetter( c );
1008 1008
1009} 1009}
1010 1010
1011void AddressbookWindow::populateCategories() 1011void AddressbookWindow::populateCategories()
1012{ 1012{
1013 catMenu->clear(); 1013 catMenu->clear();
1014 1014
1015 int id, rememberId; 1015 int id, rememberId;
1016 id = 1; 1016 id = 1;
1017 rememberId = 0; 1017 rememberId = 0;
1018 1018
1019 catMenu->insertItem( tr( "List" ), id++ ); 1019 catMenu->insertItem( tr( "List" ), id++ );
1020 catMenu->insertItem( tr( "Phone Book" ), id++ ); 1020 catMenu->insertItem( tr( "Phone Book" ), id++ );
1021 catMenu->insertItem( tr( "Company Book" ), id++ ); 1021 catMenu->insertItem( tr( "Company Book" ), id++ );
1022 catMenu->insertItem( tr( "Email Book" ), id++ ); 1022 catMenu->insertItem( tr( "Email Book" ), id++ );
1023 catMenu->insertItem( tr( "Cards" ), id++ ); 1023 catMenu->insertItem( tr( "Cards" ), id++ );
1024 catMenu->insertSeparator(); 1024 catMenu->insertSeparator();
1025 1025
1026 catMenu->insertItem( tr( "All" ), id++ ); 1026 catMenu->insertItem( tr( "All" ), id++ );
1027 QStringList categories = abList->categories(); 1027 QStringList categories = abList->categories();
1028 categories.append( tr( "Unfiled" ) ); 1028 categories.append( tr( "Unfiled" ) );
1029 for ( QStringList::Iterator it = categories.begin(); 1029 for ( QStringList::Iterator it = categories.begin();
1030 it != categories.end(); ++it ) { 1030 it != categories.end(); ++it ) {
1031 catMenu->insertItem( *it, id ); 1031 catMenu->insertItem( *it, id );
1032 if ( *it == abList->showCategory() ) 1032 if ( *it == abList->showCategory() )
1033 rememberId = id; 1033 rememberId = id;
1034 ++id; 1034 ++id;
1035 } 1035 }
1036 1036
1037 if ( abList->showBook().isEmpty() ) { 1037 if ( abList->showBook().isEmpty() ) {
1038 catMenu->setItemChecked( 1, true ); 1038 catMenu->setItemChecked( 1, true );
1039 } else if ( abList->showBook() == "Phone" ) { 1039 } else if ( abList->showBook() == "Phone" ) {
1040 catMenu->setItemChecked( 2, true ); 1040 catMenu->setItemChecked( 2, true );
1041 } else if ( abList->showBook() == "Company" ) { 1041 } else if ( abList->showBook() == "Company" ) {
1042 catMenu->setItemChecked( 3, true ); 1042 catMenu->setItemChecked( 3, true );
1043 } else if ( abList->showBook() == "Email" ) { 1043 } else if ( abList->showBook() == "Email" ) {
1044 catMenu->setItemChecked( 4, true ); 1044 catMenu->setItemChecked( 4, true );
1045 } else if ( abList->showBook() == "Cards" ) { 1045 } else if ( abList->showBook() == "Cards" ) {
1046 catMenu->setItemChecked( 5, true ); 1046 catMenu->setItemChecked( 5, true );
1047 } 1047 }
1048 1048
1049 if ( abList->showCategory().isEmpty() ) { 1049 if ( abList->showCategory().isEmpty() ) {
1050 slotSetCategory( 6 ); 1050 slotSetCategory( 6 );
1051 } 1051 }
1052 else { 1052 else {
1053 slotSetCategory( rememberId ); 1053 slotSetCategory( rememberId );
1054 } 1054 }
1055} 1055}
1056 1056