summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
Unidiff
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
@@ -14,5 +14,5 @@
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**
@@ -96,4 +96,6 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
96 syncing(FALSE) 96 syncing(FALSE)
97{ 97{
98 isLoading = true;
99
98 initFields(); 100 initFields();
99 101
@@ -188,5 +190,4 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
188 a->addTo( edit ); 190 a->addTo( edit );
189 191
190
191 edit->insertSeparator(); 192 edit->insertSeparator();
192 193
@@ -208,5 +209,7 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
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"
@@ -221,11 +224,8 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
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;
@@ -246,5 +246,5 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
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);
@@ -264,4 +264,8 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
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
@@ -283,5 +287,6 @@ void AddressbookWindow::slotSetFont( int size ) {
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:
@@ -291,5 +296,6 @@ void AddressbookWindow::slotSetFont( int size ) {
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:
@@ -299,5 +305,6 @@ void AddressbookWindow::slotSetFont( int size ) {
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 }
@@ -315,8 +322,9 @@ void AddressbookWindow::importvCard() {
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() );
@@ -348,5 +356,5 @@ AddressbookWindow::~AddressbookWindow()
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}
@@ -354,9 +362,22 @@ void AddressbookWindow::slotUpdateToolbar()
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
@@ -373,5 +394,5 @@ void AddressbookWindow::showView()
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 )
@@ -380,5 +401,5 @@ void AddressbookWindow::slotListNew()
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 }
@@ -395,5 +416,5 @@ void 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...
@@ -442,5 +463,5 @@ void AddressbookWindow::slotViewEdit()
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();
@@ -449,7 +470,4 @@ void AddressbookWindow::writeMail()
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
@@ -457,15 +475,15 @@ void 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 }
@@ -523,5 +541,5 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
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 );
@@ -582,7 +600,7 @@ void 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,
@@ -600,7 +618,7 @@ void AddressbookWindow::editPersonal()
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();
@@ -634,7 +652,7 @@ void AddressbookWindow::slotPersonalView()
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 );
@@ -648,5 +666,5 @@ void AddressbookWindow::slotPersonalView()
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,
@@ -667,9 +685,9 @@ void AddressbookWindow::editEntry( EntryMode entryMode )
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();
@@ -725,4 +743,5 @@ void AddressbookWindow::closeEvent( QCloseEvent *e )
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();
@@ -793,12 +812,11 @@ void AddressbookWindow::initFields()
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;
@@ -884,5 +902,5 @@ AbLabel *AddressbookWindow::abView()
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 }
@@ -912,21 +930,51 @@ void AddressbookWindow::slotFind()
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
@@ -939,8 +987,15 @@ void AddressbookWindow::populateCategories()
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();
@@ -953,7 +1008,23 @@ void AddressbookWindow::populateCategories()
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