summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
authoreilers <eilers>2002-10-08 12:33:52 (UTC)
committer eilers <eilers>2002-10-08 12:33:52 (UTC)
commita194611bf645fe7e2e9e83733ababc587fd42f1d (patch) (unidiff)
tree2c21a5576bce48dba2fe83f6c849c0d16025a848 /core/pim/addressbook/addressbook.cpp
parent333fec32d47ea32de9fb4c8cd378a519785a1ff8 (diff)
downloadopie-a194611bf645fe7e2e9e83733ababc587fd42f1d.zip
opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.gz
opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.bz2
Joined development branch: It uses the new PIM API
Some features in "View" added by Darwin Zins, but they are not finished..
Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp191
1 files changed, 131 insertions, 60 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index 3255269..cf2eddf 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -10,13 +10,13 @@
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** OContact 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#define QTOPIA_INTERNAL_FD 21#define QTOPIA_INTERNAL_FD
22 22
@@ -92,12 +92,14 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
92 WFlags f ) 92 WFlags f )
93 : QMainWindow( parent, name, f ), 93 : QMainWindow( parent, name, f ),
94 abEditor(0), 94 abEditor(0),
95 bAbEditFirstTime(TRUE), 95 bAbEditFirstTime(TRUE),
96 syncing(FALSE) 96 syncing(FALSE)
97{ 97{
98 isLoading = true;
99
98 initFields(); 100 initFields();
99 101
100 setCaption( tr("Contacts") ); 102 setCaption( tr("Contacts") );
101 setIcon( Resource::loadPixmap( "AddressBook" ) ); 103 setIcon( Resource::loadPixmap( "AddressBook" ) );
102 104
103 setToolBarsMovable( FALSE ); 105 setToolBarsMovable( FALSE );
@@ -184,13 +186,12 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
184 186
185 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); 187 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE );
186 actionPersonal = a; 188 actionPersonal = a;
187 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); 189 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) );
188 a->addTo( edit ); 190 a->addTo( edit );
189 191
190
191 edit->insertSeparator(); 192 edit->insertSeparator();
192 193
193 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); 194 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
194 actionPersonal = a; 195 actionPersonal = a;
195 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); 196 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
196 a->addTo( edit ); 197 a->addTo( edit );
@@ -204,32 +205,31 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
204 205
205 // This is safe to call without checking to see if it exists... 206 // This is safe to call without checking to see if it exists...
206 // not to mention it also does the necessary stuff for the 207 // not to mention it also does the necessary stuff for the
207 // journaling... 208 // journaling...
208 QString str = addressbookXMLFilename(); 209 QString str = addressbookXMLFilename();
209 if ( str.isNull() ) { 210 if ( str.isNull() ) {
210 QMessageBox::warning( this, tr("Out of Space"), 211 QMessageBox::warning(
212 this,
213 tr("Out of Space"),
211 tr("There is not enough space to create\n" 214 tr("There is not enough space to create\n"
212 "neccessary startup files.\n" 215 "neccessary startup files.\n"
213 "\nFree up some space before\nentering data!") 216 "\nFree up some space before\nentering data!")
214 ); 217 );
215 } 218 }
216 219
217 listContainer = new QWidget( this ); 220 listContainer = new QWidget( this );
218 221
219 QVBoxLayout *vb = new QVBoxLayout( listContainer ); 222 QVBoxLayout *vb = new QVBoxLayout( listContainer );
220 223
221 abList = new AbTable( &orderedFields, listContainer, "table" ); 224 abList = new AbTable( &orderedFields, listContainer, "table" );
222 vb->addWidget(abList); 225 vb->addWidget(abList);
223 abList->setHScrollBarMode( QScrollView::AlwaysOff ); 226 // abList->setHScrollBarMode( QScrollView::AlwaysOff );
224 connect( abList, SIGNAL( empty( bool ) ), 227 connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) );
225 this, SLOT( listIsEmpty( bool ) ) ); 228 connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) );
226 connect( abList, SIGNAL( details() ), 229 connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) );
227 this, SLOT( slotListView() ) );
228 connect( abList, SIGNAL(currentChanged(int,int)),
229 this, SLOT(slotUpdateToolbar()) );
230 230
231 mView = 0; 231 mView = 0;
232 232
233 abList->load( addressbookXMLFilename() ); 233 abList->load( addressbookXMLFilename() );
234 if ( QFile::exists(addressbookOldXMLFilename()) ) { 234 if ( QFile::exists(addressbookOldXMLFilename()) ) {
235 abList->load( addressbookOldXMLFilename() ); 235 abList->load( addressbookOldXMLFilename() );
@@ -242,13 +242,13 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
242 catMenu = new QPopupMenu( this ); 242 catMenu = new QPopupMenu( this );
243 catMenu->setCheckable( TRUE ); 243 catMenu->setCheckable( TRUE );
244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); 244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
245 populateCategories(); 245 populateCategories();
246 246
247 mbList->insertItem( tr("View"), catMenu ); 247 mbList->insertItem( tr("View"), catMenu );
248 setCentralWidget( listContainer ); 248 // setCentralWidget( listContainer );
249 249
250 fontMenu = new QPopupMenu(this); 250 fontMenu = new QPopupMenu(this);
251 fontMenu->setCheckable( true ); 251 fontMenu->setCheckable( true );
252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); 252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int)));
253 253
254 fontMenu->insertItem(tr( "Small" ), 0); 254 fontMenu->insertItem(tr( "Small" ), 0);
@@ -260,12 +260,16 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
260 slotSetFont(startFontSize); 260 slotSetFont(startFontSize);
261 261
262 mbList->insertItem( tr("Font"), fontMenu); 262 mbList->insertItem( tr("Font"), fontMenu);
263 setCentralWidget(listContainer); 263 setCentralWidget(listContainer);
264 264
265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
266
267 abList->setCurrentCell( 0, 0 );
268
269 isLoading = false;
266} 270}
267 271
268 272
269void AddressbookWindow::slotSetFont( int size ) { 273void AddressbookWindow::slotSetFont( int size ) {
270 274
271 if (size > 2 || size < 0) 275 if (size > 2 || size < 0)
@@ -279,29 +283,32 @@ void AddressbookWindow::slotSetFont( int size ) {
279 case 0: 283 case 0:
280 fontMenu->setItemChecked(0, true); 284 fontMenu->setItemChecked(0, true);
281 fontMenu->setItemChecked(1, false); 285 fontMenu->setItemChecked(1, false);
282 fontMenu->setItemChecked(2, false); 286 fontMenu->setItemChecked(2, false);
283 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); 287 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) );
284 currentFont = new QFont (abList->font()); 288 currentFont = new QFont (abList->font());
285 abList->resizeRows(currentFont->pixelSize() + 7); 289 // abList->resizeRows(currentFont->pixelSize() + 7);
290 abList->resizeRows();
286 break; 291 break;
287 case 1: 292 case 1:
288 fontMenu->setItemChecked(0, false); 293 fontMenu->setItemChecked(0, false);
289 fontMenu->setItemChecked(1, true); 294 fontMenu->setItemChecked(1, true);
290 fontMenu->setItemChecked(2, false); 295 fontMenu->setItemChecked(2, false);
291 abList->setFont( *defaultFont ); 296 abList->setFont( *defaultFont );
292 currentFont = new QFont (abList->font()); 297 currentFont = new QFont (abList->font());
293 abList->resizeRows(currentFont->pixelSize() + 7); 298 // abList->resizeRows(currentFont->pixelSize() + 7);
299 abList->resizeRows();
294 break; 300 break;
295 case 2: 301 case 2:
296 fontMenu->setItemChecked(0, false); 302 fontMenu->setItemChecked(0, false);
297 fontMenu->setItemChecked(1, false); 303 fontMenu->setItemChecked(1, false);
298 fontMenu->setItemChecked(2, true); 304 fontMenu->setItemChecked(2, true);
299 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); 305 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) );
300 currentFont = new QFont (abList->font()); 306 currentFont = new QFont (abList->font());
301 abList->resizeRows(currentFont->pixelSize() + 7); 307 //abList->resizeRows(currentFont->pixelSize() + 7);
308 abList->resizeRows();
302 break; 309 break;
303 } 310 }
304} 311}
305 312
306 313
307 314
@@ -311,16 +318,17 @@ void AddressbookWindow::importvCard() {
311 setDocument((const QString&) str ); 318 setDocument((const QString&) str );
312 319
313} 320}
314 321
315void AddressbookWindow::setDocument( const QString &filename ) 322void AddressbookWindow::setDocument( const QString &filename )
316{ 323{
317 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; 324 if ( filename.find(".vcf") != int(filename.length()) - 4 )
325 return;
318 326
319 QValueList<Contact> cl = Contact::readVCard( filename ); 327 QValueList<OContact> cl = OContact::readVCard( filename );
320 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { 328 for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
321// QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") 329// QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
322// .arg( (*it).fullName() ); 330// .arg( (*it).fullName() );
323// if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == 331// if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
324// QMessageBox::Ok ) { 332// QMessageBox::Ok ) {
325 abList->addEntry( *it ); 333 abList->addEntry( *it );
326// } 334// }
@@ -344,23 +352,36 @@ AddressbookWindow::~AddressbookWindow()
344 cfg.setGroup("Font"); 352 cfg.setGroup("Font");
345 cfg.writeEntry("fontSize", startFontSize); 353 cfg.writeEntry("fontSize", startFontSize);
346} 354}
347 355
348void AddressbookWindow::slotUpdateToolbar() 356void AddressbookWindow::slotUpdateToolbar()
349{ 357{
350 Contact ce = abList->currentEntry(); 358 OContact ce = abList->currentEntry();
351 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 359 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
352} 360}
353 361
354void AddressbookWindow::showList() 362void AddressbookWindow::showList()
355{ 363{
356 if ( mView ) mView->hide(); 364 bool visiblemView;
365
366 visiblemView = false;
367 if ( mView ) {
368 mView->hide();
369 visiblemView = true;
370 }
357 setCentralWidget( listContainer ); 371 setCentralWidget( listContainer );
358 listContainer->show(); 372 listContainer->show();
359 // update our focues... (or use a stack widget!); 373 // update our focues... (or use a stack widget!);
360 abList->setFocus(); 374 abList->setFocus();
375
376 // This makes sure we are scrolled all the way to the left
377 abList->setContentsPos( 0, abList->contentsY() );
378
379 //if ( visiblemView && abList->showBook() == "Cards" )
380 //abList->setShowCategory( abList->showBook(), abList->showCategory() );
381
361} 382}
362 383
363void AddressbookWindow::showView() 384void AddressbookWindow::showView()
364{ 385{
365 if ( abList->numRows() > 0 ) { 386 if ( abList->numRows() > 0 ) {
366 listContainer->hide(); 387 listContainer->hide();
@@ -369,20 +390,20 @@ void AddressbookWindow::showView()
369 mView->setFocus(); 390 mView->setFocus();
370 } 391 }
371} 392}
372 393
373void AddressbookWindow::slotListNew() 394void AddressbookWindow::slotListNew()
374{ 395{
375 Contact cnt; 396 OContact cnt;
376 if( !syncing ) { 397 if( !syncing ) {
377 if ( abEditor ) 398 if ( abEditor )
378 abEditor->setEntry( cnt ); 399 abEditor->setEntry( cnt );
379 abView()->init( cnt ); 400 abView()->init( cnt );
380 editEntry( NewEntry ); 401 editEntry( NewEntry );
381 } else { 402 } else {
382 QMessageBox::warning(this, tr("Contacts"), 403 QMessageBox::warning(this, tr("OContacts"),
383 tr("Can not edit data, currently syncing")); 404 tr("Can not edit data, currently syncing"));
384 } 405 }
385} 406}
386 407
387void AddressbookWindow::slotListView() 408void AddressbookWindow::slotListView()
388{ 409{
@@ -391,13 +412,13 @@ void AddressbookWindow::slotListView()
391 showView(); 412 showView();
392} 413}
393 414
394void AddressbookWindow::slotListDelete() 415void AddressbookWindow::slotListDelete()
395{ 416{
396 if(!syncing) { 417 if(!syncing) {
397 Contact tmpEntry = abList->currentEntry(); 418 OContact tmpEntry = abList->currentEntry();
398 419
399 // get a name, do the best we can... 420 // get a name, do the best we can...
400 QString strName = tmpEntry.fullName(); 421 QString strName = tmpEntry.fullName();
401 if ( strName.isEmpty() ) { 422 if ( strName.isEmpty() ) {
402 strName = tmpEntry.company(); 423 strName = tmpEntry.company();
403 if ( strName.isEmpty() ) 424 if ( strName.isEmpty() )
@@ -438,38 +459,35 @@ void AddressbookWindow::slotViewEdit()
438} 459}
439 460
440 461
441 462
442void AddressbookWindow::writeMail() 463void AddressbookWindow::writeMail()
443{ 464{
444 Contact c = abList->currentEntry(); 465 OContact c = abList->currentEntry();
445 QString name = c.fileAs(); 466 QString name = c.fileAs();
446 QString email = c.defaultEmail(); 467 QString email = c.defaultEmail();
447 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 468 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
448 e << name << email; 469 e << name << email;
449} 470}
450 471
451
452
453
454static const char * beamfile = "/tmp/obex/contact.vcf"; 472static const char * beamfile = "/tmp/obex/contact.vcf";
455 473
456void AddressbookWindow::slotBeam() 474void AddressbookWindow::slotBeam()
457{ 475{
458 QString filename; 476 QString filename;
459 Contact c; 477 OContact c;
460 if ( actionPersonal->isOn() ) { 478 if ( actionPersonal->isOn() ) {
461 filename = addressbookPersonalVCardName(); 479 filename = addressbookPersonalVCardName();
462 if (!QFile::exists(filename)) 480 if (!QFile::exists(filename))
463 return; // can't beam a non-existent file 481 return; // can't beam a non-existent file
464 c = Contact::readVCard( filename )[0]; 482 c = OContact::readVCard( filename )[0];
465 } else { 483 } else {
466 unlink( beamfile ); // delete if exists 484 unlink( beamfile ); // delete if exists
467 c = abList->currentEntry(); 485 c = abList->currentEntry();
468 mkdir("/tmp/obex/", 0755); 486 mkdir("/tmp/obex/", 0755);
469 Contact::writeVCard( beamfile, c ); 487 OContact::writeVCard( beamfile, c );
470 filename = beamfile; 488 filename = beamfile;
471 } 489 }
472 Ir *ir = new Ir( this ); 490 Ir *ir = new Ir( this );
473 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 491 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
474 QString description = c.fullName(); 492 QString description = c.fullName();
475 ir->send( filename, description, "text/x-vCard" ); 493 ir->send( filename, description, "text/x-vCard" );
@@ -519,13 +537,13 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
519 close(); 537 close();
520 } else if ( msg == "addContact(QString,QString)" ) { 538 } else if ( msg == "addContact(QString,QString)" ) {
521 QDataStream stream(data,IO_ReadOnly); 539 QDataStream stream(data,IO_ReadOnly);
522 QString name, email; 540 QString name, email;
523 stream >> name >> email; 541 stream >> name >> email;
524 542
525 Contact cnt; 543 OContact cnt;
526 QString fn, mn, ln; 544 QString fn, mn, ln;
527 parseName( name, &fn, &mn, &ln ); 545 parseName( name, &fn, &mn, &ln );
528 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); 546 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
529 cnt.setFirstName( fn ); 547 cnt.setFirstName( fn );
530 cnt.setMiddleName( mn ); 548 cnt.setMiddleName( mn );
531 cnt.setLastName( ln ); 549 cnt.setLastName( ln );
@@ -578,15 +596,15 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
578 596
579} 597}
580 598
581void AddressbookWindow::editPersonal() 599void AddressbookWindow::editPersonal()
582{ 600{
583 QString filename = addressbookPersonalVCardName(); 601 QString filename = addressbookPersonalVCardName();
584 Contact me; 602 OContact me;
585 if (QFile::exists(filename)) 603 if (QFile::exists(filename))
586 me = Contact::readVCard( filename )[0]; 604 me = OContact::readVCard( filename )[0];
587 if (bAbEditFirstTime) { 605 if (bAbEditFirstTime) {
588 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, 606 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields,
589 this, "editor" ); 607 this, "editor" );
590 // don't create a new editor every time 608 // don't create a new editor every time
591 bAbEditFirstTime = FALSE; 609 bAbEditFirstTime = FALSE;
592 } else 610 } else
@@ -596,15 +614,15 @@ void AddressbookWindow::editPersonal()
596 abEditor->showMaximized(); 614 abEditor->showMaximized();
597 615
598 // fix the foxus... 616 // fix the foxus...
599 abEditor->setNameFocus(); 617 abEditor->setNameFocus();
600 if ( abEditor->exec() ) { 618 if ( abEditor->exec() ) {
601 setFocus(); 619 setFocus();
602 Contact new_personal = abEditor->entry(); 620 OContact new_personal = abEditor->entry();
603 QString fname = addressbookPersonalVCardName(); 621 QString fname = addressbookPersonalVCardName();
604 Contact::writeVCard( fname, new_personal ); 622 OContact::writeVCard( fname, new_personal );
605 abView()->init(new_personal); 623 abView()->init(new_personal);
606 abView()->sync(); 624 abView()->sync();
607 } 625 }
608 abEditor->setCaption( tr("Edit Address") ); 626 abEditor->setCaption( tr("Edit Address") );
609} 627}
610 628
@@ -630,27 +648,27 @@ void AddressbookWindow::slotPersonalView()
630 actionFind->setEnabled(FALSE); 648 actionFind->setEnabled(FALSE);
631#endif 649#endif
632 actionMail->setEnabled(FALSE); 650 actionMail->setEnabled(FALSE);
633 651
634 setCaption( tr("Contacts - My Personal Details") ); 652 setCaption( tr("Contacts - My Personal Details") );
635 QString filename = addressbookPersonalVCardName(); 653 QString filename = addressbookPersonalVCardName();
636 Contact me; 654 OContact me;
637 if (QFile::exists(filename)) 655 if (QFile::exists(filename))
638 me = Contact::readVCard( filename )[0]; 656 me = OContact::readVCard( filename )[0];
639 657
640 abView()->init( me ); 658 abView()->init( me );
641 abView()->sync(); 659 abView()->sync();
642 listContainer->hide(); 660 listContainer->hide();
643 setCentralWidget( abView() ); 661 setCentralWidget( abView() );
644 mView->show(); 662 mView->show();
645 mView->setFocus(); 663 mView->setFocus();
646} 664}
647 665
648void AddressbookWindow::editEntry( EntryMode entryMode ) 666void AddressbookWindow::editEntry( EntryMode entryMode )
649{ 667{
650 Contact entry; 668 OContact entry;
651 if ( bAbEditFirstTime ) { 669 if ( bAbEditFirstTime ) {
652 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, 670 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields,
653 this, "editor" ); 671 this, "editor" );
654 bAbEditFirstTime = FALSE; 672 bAbEditFirstTime = FALSE;
655 if ( entryMode == EditEntry ) 673 if ( entryMode == EditEntry )
656 abEditor->setEntry( abList->currentEntry() ); 674 abEditor->setEntry( abList->currentEntry() );
@@ -663,17 +681,17 @@ void AddressbookWindow::editEntry( EntryMode entryMode )
663#endif 681#endif
664 // fix the foxus... 682 // fix the foxus...
665 abEditor->setNameFocus(); 683 abEditor->setNameFocus();
666 if ( abEditor->exec() ) { 684 if ( abEditor->exec() ) {
667 setFocus(); 685 setFocus();
668 if ( entryMode == NewEntry ) { 686 if ( entryMode == NewEntry ) {
669 Contact insertEntry = abEditor->entry(); 687 OContact insertEntry = abEditor->entry();
670 insertEntry.assignUid(); 688 insertEntry.assignUid();
671 abList->addEntry( insertEntry ); 689 abList->addEntry( insertEntry );
672 } else { 690 } else {
673 Contact replaceEntry = abEditor->entry(); 691 OContact replaceEntry = abEditor->entry();
674 if ( !replaceEntry.isValidUid() ) 692 if ( !replaceEntry.isValidUid() )
675 replaceEntry.assignUid(); 693 replaceEntry.assignUid();
676 abList->replaceCurrentEntry( replaceEntry ); 694 abList->replaceCurrentEntry( replaceEntry );
677 } 695 }
678 } 696 }
679 populateCategories(); 697 populateCategories();
@@ -721,12 +739,13 @@ void AddressbookWindow::closeEvent( QCloseEvent *e )
721 at the start of the sync, so there is no need to save 739 at the start of the sync, so there is no need to save
722 Saving however itself would cause problems. */ 740 Saving however itself would cause problems. */
723 e->accept(); 741 e->accept();
724 return; 742 return;
725 } 743 }
726//################## shouldn't always save 744//################## shouldn't always save
745 // True, but the database handles this automatically ! (se)
727 if ( save() ) 746 if ( save() )
728 e->accept(); 747 e->accept();
729 else 748 else
730 e->ignore(); 749 e->ignore();
731} 750}
732 751
@@ -789,20 +808,19 @@ void AddressbookWindow::slotSettings()
789void AddressbookWindow::initFields() 808void AddressbookWindow::initFields()
790{ 809{
791 // we really don't need the things from the configuration, anymore 810 // we really don't need the things from the configuration, anymore
792 // only thing that is important are the important categories. So, 811 // only thing that is important are the important categories. So,
793 // Call the contact functions that correspond to these old functions... 812 // Call the contact functions that correspond to these old functions...
794 813
795 QStringList xmlFields = Contact::fields(); 814 QStringList xmlFields = OContact::fields();
796 QStringList visibleFields = Contact::trfields(); 815 QStringList visibleFields = OContact::trfields();
797 xmlFields.remove( "Title" ); 816 xmlFields.remove( "Title" );
798 visibleFields.remove( tr("Name Title") ); 817 visibleFields.remove( tr("Name Title") );
799 visibleFields.remove( tr("Notes") ); 818 visibleFields.remove( tr("Notes") );
800 819
801 int i, 820 int i, version;
802 version;
803 Config cfg( "AddressBook" ); 821 Config cfg( "AddressBook" );
804 QString zn; 822 QString zn;
805 823
806 // ### Write a function to keep this from happening again... 824 // ### Write a function to keep this from happening again...
807 QStringList::ConstIterator it; 825 QStringList::ConstIterator it;
808 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { 826 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) {
@@ -880,13 +898,13 @@ void AddressbookWindow::initFields()
880 898
881 899
882AbLabel *AddressbookWindow::abView() 900AbLabel *AddressbookWindow::abView()
883{ 901{
884 if ( !mView ) { 902 if ( !mView ) {
885 mView = new AbLabel( this, "viewer" ); 903 mView = new AbLabel( this, "viewer" );
886 mView->init( Contact() ); 904 mView->init( OContact() );
887 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); 905 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
888 } 906 }
889 return mView; 907 return mView;
890} 908}
891 909
892void AddressbookWindow::slotFind() 910void AddressbookWindow::slotFind()
@@ -908,52 +926,105 @@ void AddressbookWindow::slotFind()
908 abList->clearFindRow(); 926 abList->clearFindRow();
909#endif 927#endif
910} 928}
911 929
912void AddressbookWindow::slotSetCategory( int c ) 930void AddressbookWindow::slotSetCategory( int c )
913{ 931{
932
933 QString cat, book;
934
914 if ( c <= 0 ) 935 if ( c <= 0 )
915 return; 936 return;
916 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 937
938 // Checkmark Book Menu Item Selected
939 if ( c < 6 )
940 for ( unsigned int i = 1; i < 6; i++ )
917 catMenu->setItemChecked( i, c == (int)i ); 941 catMenu->setItemChecked( i, c == (int)i );
918 if ( c == 1 ) { 942
919 abList->setShowCategory( QString::null ); 943 // Checkmark Category Menu Item Selected
920 setCaption( tr("Contacts") + " - " + tr ( "All" ) ); 944 else
921 } else if ( c == (int)catMenu->count() ) { 945 for ( unsigned int i = 6; i < catMenu->count(); i++ )
922 abList->setShowCategory( tr( "Unfiled" ) ); 946 catMenu->setItemChecked( i, c == (int)i );
923 setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); 947
924 } else { 948 for ( unsigned int i = 1; i < catMenu->count(); i++ ) {
925 QString cat = abList->categories()[c - 2]; 949 if (catMenu->isItemChecked( i )) {
926 abList->setShowCategory( cat ); 950 if ( i == 1 ) // default List view
927 setCaption( tr("Contacts") + " - " + cat ); 951 book = QString::null;
952 else if ( i == 2 )
953 book = "Phone";
954 else if ( i == 3 )
955 book = "Company";
956 else if ( i == 4 )
957 book = "Email";
958 else if ( i == 5 )
959 book = "Cards";
960 else if ( i == 6 ) // default All Categories
961 cat = QString::null;
962 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled
963 cat = "Unfiled";
964 else
965 cat = abList->categories()[i - 7];
928 } 966 }
929} 967}
930 968
969 abList->setShowCategory( book, cat );
970
971 if ( book.isEmpty() )
972 book = "List";
973 if ( cat.isEmpty() )
974 cat = "All";
975
976 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) );
977}
978
931void AddressbookWindow::slotSetLetter( char c ) { 979void AddressbookWindow::slotSetLetter( char c ) {
932 980
933 abList->setShowByLetter( c ); 981 abList->setShowByLetter( c );
934 982
935} 983}
936 984
937void AddressbookWindow::populateCategories() 985void AddressbookWindow::populateCategories()
938{ 986{
939 catMenu->clear(); 987 catMenu->clear();
940 988
941 int id, 989 int id, rememberId;
942 rememberId;
943 id = 1; 990 id = 1;
944 rememberId = 0; 991 rememberId = 0;
992
993 catMenu->insertItem( tr( "List" ), id++ );
994 catMenu->insertItem( tr( "Phone Book" ), id++ );
995 catMenu->insertItem( tr( "Company Book" ), id++ );
996 catMenu->insertItem( tr( "Email Book" ), id++ );
997 catMenu->insertItem( tr( "Cards" ), id++ );
998 catMenu->insertSeparator();
999
945 catMenu->insertItem( tr( "All" ), id++ ); 1000 catMenu->insertItem( tr( "All" ), id++ );
946 QStringList categories = abList->categories(); 1001 QStringList categories = abList->categories();
947 categories.append( tr( "Unfiled" ) ); 1002 categories.append( tr( "Unfiled" ) );
948 for ( QStringList::Iterator it = categories.begin(); 1003 for ( QStringList::Iterator it = categories.begin();
949 it != categories.end(); ++it ) { 1004 it != categories.end(); ++it ) {
950 catMenu->insertItem( *it, id ); 1005 catMenu->insertItem( *it, id );
951 if ( *it == abList->showCategory() ) 1006 if ( *it == abList->showCategory() )
952 rememberId = id; 1007 rememberId = id;
953 ++id; 1008 ++id;
954 } 1009 }
955 if ( abList->showCategory().isEmpty() ) 1010
956 slotSetCategory( 1 ); 1011 if ( abList->showBook().isEmpty() ) {
957 else 1012 catMenu->setItemChecked( 1, true );
1013 } else if ( abList->showBook() == "Phone" ) {
1014 catMenu->setItemChecked( 2, true );
1015 } else if ( abList->showBook() == "Company" ) {
1016 catMenu->setItemChecked( 3, true );
1017 } else if ( abList->showBook() == "Email" ) {
1018 catMenu->setItemChecked( 4, true );
1019 } else if ( abList->showBook() == "Cards" ) {
1020 catMenu->setItemChecked( 5, true );
1021 }
1022
1023 if ( abList->showCategory().isEmpty() ) {
1024 slotSetCategory( 6 );
1025 }
1026 else {
958 slotSetCategory( rememberId ); 1027 slotSetCategory( rememberId );
959} 1028}
1029}
1030