-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 42 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 6 |
5 files changed, 48 insertions, 15 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 94c37e7..2ffa357 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp | |||
@@ -1,147 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qlabel.h> | 24 | #include <qlabel.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qtooltip.h> | 26 | #include <qtooltip.h> |
27 | #include <qcombobox.h> | 27 | #include <qcombobox.h> |
28 | 28 | ||
29 | #include <kdialog.h> | 29 | #include <kdialog.h> |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | 33 | ||
34 | #include "incsearchwidget.h" | 34 | #include "incsearchwidget.h" |
35 | 35 | ||
36 | IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) | 36 | IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) |
37 | : QWidget( parent, name ) | 37 | : QWidget( parent, name ) |
38 | { | 38 | { |
39 | #ifndef KAB_EMBEDDED | 39 | #ifndef KAB_EMBEDDED |
40 | //US setCaption( i18n( "Incremental Search" ) ); | 40 | //US setCaption( i18n( "Incremental Search" ) ); |
41 | #endif //KAB_EMBEDDED | 41 | #endif //KAB_EMBEDDED |
42 | 42 | ||
43 | QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); | 43 | QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); |
44 | 44 | ||
45 | #ifdef DESKTOP_VERSION | 45 | #ifdef DESKTOP_VERSION |
46 | QLabel *label = new QLabel( i18n( "Search:" ), this ); | 46 | QLabel *label = new QLabel( i18n( "Search:" ), this ); |
47 | label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); | 47 | label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); |
48 | layout->addWidget( label ); | 48 | layout->addWidget( label ); |
49 | #endif //KAB_EMBEDDED | 49 | #endif //KAB_EMBEDDED |
50 | 50 | ||
51 | mSearchText = new KLineEdit( this ); | 51 | mSearchText = new KLineEdit( this ); |
52 | layout->addWidget( mSearchText ); | 52 | layout->addWidget( mSearchText ); |
53 | // #ifdef KAB_EMBEDDED | 53 | // #ifdef KAB_EMBEDDED |
54 | // if (KGlobal::getOrientation() == KGlobal::Portrait) | 54 | // if (KGlobal::getOrientation() == KGlobal::Portrait) |
55 | // mSearchText->setMaximumWidth(30); | 55 | // mSearchText->setMaximumWidth(30); |
56 | // #endif //KAB_EMBEDDED | 56 | // #endif //KAB_EMBEDDED |
57 | 57 | ||
58 | 58 | ||
59 | mFieldCombo = new QComboBox( false, this ); | 59 | mFieldCombo = new QComboBox( false, this ); |
60 | layout->addWidget( mFieldCombo ); | 60 | layout->addWidget( mFieldCombo ); |
61 | mFieldCombo->setMaximumHeight( 34 ); | 61 | mFieldCombo->setMaximumHeight( 34 ); |
62 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); | 62 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); |
63 | 63 | ||
64 | // #ifndef KAB_EMBEDDED | 64 | // #ifndef KAB_EMBEDDED |
65 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); | 65 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); |
66 | // #else //KAB_EMBEDDED | 66 | // #else //KAB_EMBEDDED |
67 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); | 67 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); |
68 | // #endif //KAB_EMBEDDED | 68 | // #endif //KAB_EMBEDDED |
69 | 69 | ||
70 | #ifdef DESKTOP_VERSION | ||
71 | // for performance reasons, we do a search on the pda only after return is pressed | ||
70 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), | 72 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), |
71 | SLOT( announceDoSearch() ) ); | 73 | SLOT( announceDoSearch() ) ); |
72 | connect( mSearchText, SIGNAL( returnPressed() ), | ||
73 | SLOT( announceDoSearch() ) ); | ||
74 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 74 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
75 | SLOT( announceDoSearch() ) ); | 75 | SLOT( announceDoSearch() ) ); |
76 | #endif | ||
77 | connect( mSearchText, SIGNAL( returnPressed() ), | ||
78 | SLOT( announceDoSearch() ) ); | ||
76 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 79 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
77 | SLOT( announceFieldChanged() ) ); | 80 | SLOT( announceFieldChanged() ) ); |
78 | 81 | ||
79 | setFocusProxy( mSearchText ); | 82 | setFocusProxy( mSearchText ); |
80 | } | 83 | } |
81 | 84 | ||
82 | IncSearchWidget::~IncSearchWidget() | 85 | IncSearchWidget::~IncSearchWidget() |
83 | { | 86 | { |
84 | 87 | ||
85 | } | 88 | } |
86 | 89 | ||
87 | void IncSearchWidget::announceDoSearch() | 90 | void IncSearchWidget::announceDoSearch() |
88 | { | 91 | { |
89 | emit doSearch( mSearchText->text() ); | 92 | emit doSearch( mSearchText->text() ); |
90 | } | 93 | } |
91 | 94 | ||
92 | void IncSearchWidget::announceFieldChanged() | 95 | void IncSearchWidget::announceFieldChanged() |
93 | { | 96 | { |
94 | emit fieldChanged(); | 97 | emit fieldChanged(); |
95 | } | 98 | } |
96 | 99 | ||
97 | void IncSearchWidget::setFields( const KABC::Field::List &list ) | 100 | void IncSearchWidget::setFields( const KABC::Field::List &list ) |
98 | { | 101 | { |
99 | 102 | ||
100 | mFieldCombo->clear(); | 103 | mFieldCombo->clear(); |
101 | mFieldCombo->insertItem( i18n( "All Fields" ) ); | 104 | mFieldCombo->insertItem( i18n( "All Fields" ) ); |
102 | QFontMetrics fm ( mFieldCombo->font() ); | 105 | QFontMetrics fm ( mFieldCombo->font() ); |
103 | int wid = fm.width(i18n( "All Fields" ) ); | 106 | int wid = fm.width(i18n( "All Fields" ) ); |
104 | int max = wid; | 107 | int max = wid; |
105 | 108 | ||
106 | KABC::Field::List::ConstIterator it; | 109 | KABC::Field::List::ConstIterator it; |
107 | for ( it = list.begin(); it != list.end(); ++it ) { | 110 | for ( it = list.begin(); it != list.end(); ++it ) { |
108 | mFieldCombo->insertItem( (*it)->label() ); | 111 | mFieldCombo->insertItem( (*it)->label() ); |
109 | // wid = fm.width((*it)->label() ); | 112 | // wid = fm.width((*it)->label() ); |
110 | //if ( wid > max ) | 113 | //if ( wid > max ) |
111 | // max = wid; | 114 | // max = wid; |
112 | } | 115 | } |
113 | 116 | ||
114 | mFieldList = list; | 117 | mFieldList = list; |
115 | 118 | ||
116 | announceDoSearch(); | 119 | announceDoSearch(); |
117 | announceFieldChanged(); | 120 | announceFieldChanged(); |
118 | mFieldCombo->setMaximumWidth( wid+60 ); | 121 | mFieldCombo->setMaximumWidth( wid+60 ); |
119 | } | 122 | } |
120 | 123 | ||
121 | KABC::Field::List IncSearchWidget::fields() const | 124 | KABC::Field::List IncSearchWidget::fields() const |
122 | { | 125 | { |
123 | return mFieldList; | 126 | return mFieldList; |
124 | } | 127 | } |
125 | 128 | ||
126 | KABC::Field *IncSearchWidget::currentField()const | 129 | KABC::Field *IncSearchWidget::currentField()const |
127 | { | 130 | { |
128 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) | 131 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) |
129 | return 0; // for error or 'use all fields' | 132 | return 0; // for error or 'use all fields' |
130 | else | 133 | else |
131 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; | 134 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; |
132 | } | 135 | } |
133 | 136 | ||
134 | void IncSearchWidget::setCurrentItem( int pos ) | 137 | void IncSearchWidget::setCurrentItem( int pos ) |
135 | { | 138 | { |
136 | mFieldCombo->setCurrentItem( pos ); | 139 | mFieldCombo->setCurrentItem( pos ); |
137 | announceFieldChanged(); | 140 | announceFieldChanged(); |
138 | } | 141 | } |
139 | 142 | ||
140 | int IncSearchWidget::currentItem() const | 143 | int IncSearchWidget::currentItem() const |
141 | { | 144 | { |
142 | 145 | ||
143 | return mFieldCombo->currentItem(); | 146 | return mFieldCombo->currentItem(); |
144 | } | 147 | } |
145 | #ifndef KAB_EMBEDDED | 148 | #ifndef KAB_EMBEDDED |
146 | #include "incsearchwidget.moc" | 149 | #include "incsearchwidget.moc" |
147 | #endif //KAB_EMBEDDED | 150 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f0f08f4..4299ebd 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -452,795 +452,817 @@ void KABCore::setContactSelected( const QString &uid ) | |||
452 | KABC::Picture pic = addr.photo(); | 452 | KABC::Picture pic = addr.photo(); |
453 | if ( pic.isIntern() ) { | 453 | if ( pic.isIntern() ) { |
454 | //US emit contactSelected( pic.data() ); | 454 | //US emit contactSelected( pic.data() ); |
455 | //US instead use: | 455 | //US instead use: |
456 | QPixmap px; | 456 | QPixmap px; |
457 | if (pic.data().isNull() != true) | 457 | if (pic.data().isNull() != true) |
458 | { | 458 | { |
459 | px.convertFromImage(pic.data()); | 459 | px.convertFromImage(pic.data()); |
460 | } | 460 | } |
461 | 461 | ||
462 | emit contactSelected( px ); | 462 | emit contactSelected( px ); |
463 | } | 463 | } |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | mExtensionManager->setSelectionChanged(); | 467 | mExtensionManager->setSelectionChanged(); |
468 | 468 | ||
469 | // update the actions | 469 | // update the actions |
470 | bool selected = !uid.isEmpty(); | 470 | bool selected = !uid.isEmpty(); |
471 | 471 | ||
472 | if ( mReadWrite ) { | 472 | if ( mReadWrite ) { |
473 | mActionCut->setEnabled( selected ); | 473 | mActionCut->setEnabled( selected ); |
474 | mActionPaste->setEnabled( selected ); | 474 | mActionPaste->setEnabled( selected ); |
475 | } | 475 | } |
476 | 476 | ||
477 | mActionCopy->setEnabled( selected ); | 477 | mActionCopy->setEnabled( selected ); |
478 | mActionDelete->setEnabled( selected ); | 478 | mActionDelete->setEnabled( selected ); |
479 | mActionEditAddressee->setEnabled( selected ); | 479 | mActionEditAddressee->setEnabled( selected ); |
480 | mActionMail->setEnabled( selected ); | 480 | mActionMail->setEnabled( selected ); |
481 | mActionMailVCard->setEnabled( selected ); | 481 | mActionMailVCard->setEnabled( selected ); |
482 | //if (mActionBeam) | 482 | //if (mActionBeam) |
483 | //mActionBeam->setEnabled( selected ); | 483 | //mActionBeam->setEnabled( selected ); |
484 | 484 | ||
485 | if (mActionBeamVCard) | 485 | if (mActionBeamVCard) |
486 | mActionBeamVCard->setEnabled( selected ); | 486 | mActionBeamVCard->setEnabled( selected ); |
487 | 487 | ||
488 | mActionWhoAmI->setEnabled( selected ); | 488 | mActionWhoAmI->setEnabled( selected ); |
489 | mActionCategories->setEnabled( selected ); | 489 | mActionCategories->setEnabled( selected ); |
490 | } | 490 | } |
491 | 491 | ||
492 | void KABCore::sendMail() | 492 | void KABCore::sendMail() |
493 | { | 493 | { |
494 | sendMail( mViewManager->selectedEmails().join( ", " ) ); | 494 | sendMail( mViewManager->selectedEmails().join( ", " ) ); |
495 | } | 495 | } |
496 | 496 | ||
497 | void KABCore::sendMail( const QString& emaillist ) | 497 | void KABCore::sendMail( const QString& emaillist ) |
498 | { | 498 | { |
499 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " | 499 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " |
500 | if (emaillist.contains(",") > 0) | 500 | if (emaillist.contains(",") > 0) |
501 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); | 501 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); |
502 | else | 502 | else |
503 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); | 503 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | 507 | ||
508 | void KABCore::mailVCard() | 508 | void KABCore::mailVCard() |
509 | { | 509 | { |
510 | QStringList uids = mViewManager->selectedUids(); | 510 | QStringList uids = mViewManager->selectedUids(); |
511 | if ( !uids.isEmpty() ) | 511 | if ( !uids.isEmpty() ) |
512 | mailVCard( uids ); | 512 | mailVCard( uids ); |
513 | } | 513 | } |
514 | 514 | ||
515 | void KABCore::mailVCard( const QStringList& uids ) | 515 | void KABCore::mailVCard( const QStringList& uids ) |
516 | { | 516 | { |
517 | QStringList urls; | 517 | QStringList urls; |
518 | 518 | ||
519 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 519 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
520 | 520 | ||
521 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); | 521 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); |
522 | 522 | ||
523 | 523 | ||
524 | 524 | ||
525 | QDir().mkdir( dirName, true ); | 525 | QDir().mkdir( dirName, true ); |
526 | 526 | ||
527 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 527 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
528 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 528 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
529 | 529 | ||
530 | if ( a.isEmpty() ) | 530 | if ( a.isEmpty() ) |
531 | continue; | 531 | continue; |
532 | 532 | ||
533 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; | 533 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; |
534 | 534 | ||
535 | QString fileName = dirName + "/" + name; | 535 | QString fileName = dirName + "/" + name; |
536 | 536 | ||
537 | QFile outFile(fileName); | 537 | QFile outFile(fileName); |
538 | 538 | ||
539 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | 539 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully |
540 | KABC::VCardConverter converter; | 540 | KABC::VCardConverter converter; |
541 | QString vcard; | 541 | QString vcard; |
542 | 542 | ||
543 | converter.addresseeToVCard( a, vcard ); | 543 | converter.addresseeToVCard( a, vcard ); |
544 | 544 | ||
545 | QTextStream t( &outFile ); // use a text stream | 545 | QTextStream t( &outFile ); // use a text stream |
546 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 546 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
547 | t << vcard; | 547 | t << vcard; |
548 | 548 | ||
549 | outFile.close(); | 549 | outFile.close(); |
550 | 550 | ||
551 | urls.append( fileName ); | 551 | urls.append( fileName ); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); | 555 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); |
556 | 556 | ||
557 | 557 | ||
558 | /*US | 558 | /*US |
559 | kapp->invokeMailer( QString::null, QString::null, QString::null, | 559 | kapp->invokeMailer( QString::null, QString::null, QString::null, |
560 | QString::null, // subject | 560 | QString::null, // subject |
561 | QString::null, // body | 561 | QString::null, // body |
562 | QString::null, | 562 | QString::null, |
563 | urls ); // attachments | 563 | urls ); // attachments |
564 | */ | 564 | */ |
565 | 565 | ||
566 | } | 566 | } |
567 | 567 | ||
568 | /** | 568 | /** |
569 | Beams the "WhoAmI contact. | 569 | Beams the "WhoAmI contact. |
570 | */ | 570 | */ |
571 | void KABCore::beamMySelf() | 571 | void KABCore::beamMySelf() |
572 | { | 572 | { |
573 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | 573 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); |
574 | if (!a.isEmpty()) | 574 | if (!a.isEmpty()) |
575 | { | 575 | { |
576 | QStringList uids; | 576 | QStringList uids; |
577 | uids << a.uid(); | 577 | uids << a.uid(); |
578 | 578 | ||
579 | beamVCard(uids); | 579 | beamVCard(uids); |
580 | } else { | 580 | } else { |
581 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 581 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
582 | 582 | ||
583 | 583 | ||
584 | } | 584 | } |
585 | } | 585 | } |
586 | 586 | ||
587 | void KABCore::beamVCard() | 587 | void KABCore::beamVCard() |
588 | { | 588 | { |
589 | QStringList uids = mViewManager->selectedUids(); | 589 | QStringList uids = mViewManager->selectedUids(); |
590 | if ( !uids.isEmpty() ) | 590 | if ( !uids.isEmpty() ) |
591 | beamVCard( uids ); | 591 | beamVCard( uids ); |
592 | } | 592 | } |
593 | 593 | ||
594 | 594 | ||
595 | void KABCore::beamVCard(const QStringList& uids) | 595 | void KABCore::beamVCard(const QStringList& uids) |
596 | { | 596 | { |
597 | /*US | 597 | /*US |
598 | QString beamFilename; | 598 | QString beamFilename; |
599 | Opie::OPimContact c; | 599 | Opie::OPimContact c; |
600 | if ( actionPersonal->isOn() ) { | 600 | if ( actionPersonal->isOn() ) { |
601 | beamFilename = addressbookPersonalVCardName(); | 601 | beamFilename = addressbookPersonalVCardName(); |
602 | if ( !QFile::exists( beamFilename ) ) | 602 | if ( !QFile::exists( beamFilename ) ) |
603 | return; // can't beam a non-existent file | 603 | return; // can't beam a non-existent file |
604 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 604 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
605 | beamFilename ); | 605 | beamFilename ); |
606 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 606 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
607 | Opie::OPimContactAccess::List allList = access->allRecords(); | 607 | Opie::OPimContactAccess::List allList = access->allRecords(); |
608 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | 608 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first |
609 | c = *it; | 609 | c = *it; |
610 | 610 | ||
611 | delete access; | 611 | delete access; |
612 | } else { | 612 | } else { |
613 | unlink( beamfile ); // delete if exists | 613 | unlink( beamfile ); // delete if exists |
614 | mkdir("/tmp/obex/", 0755); | 614 | mkdir("/tmp/obex/", 0755); |
615 | c = m_abView -> currentEntry(); | 615 | c = m_abView -> currentEntry(); |
616 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 616 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
617 | beamfile ); | 617 | beamfile ); |
618 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 618 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
619 | access->add( c ); | 619 | access->add( c ); |
620 | access->save(); | 620 | access->save(); |
621 | delete access; | 621 | delete access; |
622 | 622 | ||
623 | beamFilename = beamfile; | 623 | beamFilename = beamfile; |
624 | } | 624 | } |
625 | 625 | ||
626 | owarn << "Beaming: " << beamFilename << oendl; | 626 | owarn << "Beaming: " << beamFilename << oendl; |
627 | */ | 627 | */ |
628 | 628 | ||
629 | #if 0 | 629 | #if 0 |
630 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 630 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
631 | 631 | ||
632 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); | 632 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); |
633 | 633 | ||
634 | QString name = "contact.vcf"; | 634 | QString name = "contact.vcf"; |
635 | 635 | ||
636 | QString fileName = dirName + "/" + name; | 636 | QString fileName = dirName + "/" + name; |
637 | #endif | 637 | #endif |
638 | // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory | 638 | // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory |
639 | // | 639 | // |
640 | QString fileName = "/tmp/kdepimbeamfile"; | 640 | QString fileName = "/tmp/kdepimbeamfile"; |
641 | 641 | ||
642 | 642 | ||
643 | //QDir().mkdir( dirName, true ); | 643 | //QDir().mkdir( dirName, true ); |
644 | 644 | ||
645 | QFile outFile(fileName); | 645 | QFile outFile(fileName); |
646 | KABC::VCardConverter converter; | 646 | KABC::VCardConverter converter; |
647 | QString description; | 647 | QString description; |
648 | 648 | ||
649 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | 649 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully |
650 | 650 | ||
651 | QTextStream t( &outFile ); // use a text stream | 651 | QTextStream t( &outFile ); // use a text stream |
652 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 652 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
653 | 653 | ||
654 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 654 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
655 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 655 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
656 | 656 | ||
657 | if ( a.isEmpty() ) | 657 | if ( a.isEmpty() ) |
658 | continue; | 658 | continue; |
659 | 659 | ||
660 | if (description.isEmpty()) | 660 | if (description.isEmpty()) |
661 | description = a.formattedName(); | 661 | description = a.formattedName(); |
662 | 662 | ||
663 | QString vcard; | 663 | QString vcard; |
664 | converter.addresseeToVCard( a, vcard ); | 664 | converter.addresseeToVCard( a, vcard ); |
665 | t << vcard; | 665 | t << vcard; |
666 | 666 | ||
667 | } | 667 | } |
668 | } else { | 668 | } else { |
669 | qDebug("Error open temp beam file "); | 669 | qDebug("Error open temp beam file "); |
670 | return; | 670 | return; |
671 | } | 671 | } |
672 | 672 | ||
673 | outFile.close(); | 673 | outFile.close(); |
674 | 674 | ||
675 | #ifndef DESKTOP_VERSION | 675 | #ifndef DESKTOP_VERSION |
676 | Ir *ir = new Ir( this ); | 676 | Ir *ir = new Ir( this ); |
677 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 677 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
678 | ir->send( fileName, description, "text/x-vCard" ); | 678 | ir->send( fileName, description, "text/x-vCard" ); |
679 | #endif | 679 | #endif |
680 | 680 | ||
681 | } | 681 | } |
682 | 682 | ||
683 | void KABCore::beamDone( Ir *ir ) | 683 | void KABCore::beamDone( Ir *ir ) |
684 | { | 684 | { |
685 | #ifndef DESKTOP_VERSION | 685 | #ifndef DESKTOP_VERSION |
686 | delete ir; | 686 | delete ir; |
687 | #endif | 687 | #endif |
688 | } | 688 | } |
689 | 689 | ||
690 | 690 | ||
691 | void KABCore::browse( const QString& url ) | 691 | void KABCore::browse( const QString& url ) |
692 | { | 692 | { |
693 | #ifndef KAB_EMBEDDED | 693 | #ifndef KAB_EMBEDDED |
694 | kapp->invokeBrowser( url ); | 694 | kapp->invokeBrowser( url ); |
695 | #else //KAB_EMBEDDED | 695 | #else //KAB_EMBEDDED |
696 | qDebug("KABCore::browse must be fixed"); | 696 | qDebug("KABCore::browse must be fixed"); |
697 | #endif //KAB_EMBEDDED | 697 | #endif //KAB_EMBEDDED |
698 | } | 698 | } |
699 | 699 | ||
700 | void KABCore::selectAllContacts() | 700 | void KABCore::selectAllContacts() |
701 | { | 701 | { |
702 | mViewManager->setSelected( QString::null, true ); | 702 | mViewManager->setSelected( QString::null, true ); |
703 | } | 703 | } |
704 | 704 | ||
705 | void KABCore::deleteContacts() | 705 | void KABCore::deleteContacts() |
706 | { | 706 | { |
707 | QStringList uidList = mViewManager->selectedUids(); | 707 | QStringList uidList = mViewManager->selectedUids(); |
708 | deleteContacts( uidList ); | 708 | deleteContacts( uidList ); |
709 | } | 709 | } |
710 | 710 | ||
711 | void KABCore::deleteContacts( const QStringList &uids ) | 711 | void KABCore::deleteContacts( const QStringList &uids ) |
712 | { | 712 | { |
713 | if ( uids.count() > 0 ) { | 713 | if ( uids.count() > 0 ) { |
714 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); | 714 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); |
715 | UndoStack::instance()->push( command ); | 715 | UndoStack::instance()->push( command ); |
716 | RedoStack::instance()->clear(); | 716 | RedoStack::instance()->clear(); |
717 | 717 | ||
718 | // now if we deleted anything, refresh | 718 | // now if we deleted anything, refresh |
719 | setContactSelected( QString::null ); | 719 | setContactSelected( QString::null ); |
720 | setModified( true ); | 720 | setModified( true ); |
721 | } | 721 | } |
722 | } | 722 | } |
723 | 723 | ||
724 | void KABCore::copyContacts() | 724 | void KABCore::copyContacts() |
725 | { | 725 | { |
726 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 726 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
727 | 727 | ||
728 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); | 728 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); |
729 | 729 | ||
730 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; | 730 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; |
731 | 731 | ||
732 | QClipboard *cb = QApplication::clipboard(); | 732 | QClipboard *cb = QApplication::clipboard(); |
733 | cb->setText( clipText ); | 733 | cb->setText( clipText ); |
734 | } | 734 | } |
735 | 735 | ||
736 | void KABCore::cutContacts() | 736 | void KABCore::cutContacts() |
737 | { | 737 | { |
738 | QStringList uidList = mViewManager->selectedUids(); | 738 | QStringList uidList = mViewManager->selectedUids(); |
739 | 739 | ||
740 | //US if ( uidList.size() > 0 ) { | 740 | //US if ( uidList.size() > 0 ) { |
741 | if ( uidList.count() > 0 ) { | 741 | if ( uidList.count() > 0 ) { |
742 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); | 742 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); |
743 | UndoStack::instance()->push( command ); | 743 | UndoStack::instance()->push( command ); |
744 | RedoStack::instance()->clear(); | 744 | RedoStack::instance()->clear(); |
745 | 745 | ||
746 | setModified( true ); | 746 | setModified( true ); |
747 | } | 747 | } |
748 | } | 748 | } |
749 | 749 | ||
750 | void KABCore::pasteContacts() | 750 | void KABCore::pasteContacts() |
751 | { | 751 | { |
752 | QClipboard *cb = QApplication::clipboard(); | 752 | QClipboard *cb = QApplication::clipboard(); |
753 | 753 | ||
754 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); | 754 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); |
755 | 755 | ||
756 | pasteContacts( list ); | 756 | pasteContacts( list ); |
757 | } | 757 | } |
758 | 758 | ||
759 | void KABCore::pasteContacts( KABC::Addressee::List &list ) | 759 | void KABCore::pasteContacts( KABC::Addressee::List &list ) |
760 | { | 760 | { |
761 | KABC::Resource *resource = requestResource( this ); | 761 | KABC::Resource *resource = requestResource( this ); |
762 | KABC::Addressee::List::Iterator it; | 762 | KABC::Addressee::List::Iterator it; |
763 | for ( it = list.begin(); it != list.end(); ++it ) | 763 | for ( it = list.begin(); it != list.end(); ++it ) |
764 | (*it).setResource( resource ); | 764 | (*it).setResource( resource ); |
765 | 765 | ||
766 | PwPasteCommand *command = new PwPasteCommand( this, list ); | 766 | PwPasteCommand *command = new PwPasteCommand( this, list ); |
767 | UndoStack::instance()->push( command ); | 767 | UndoStack::instance()->push( command ); |
768 | RedoStack::instance()->clear(); | 768 | RedoStack::instance()->clear(); |
769 | 769 | ||
770 | setModified( true ); | 770 | setModified( true ); |
771 | } | 771 | } |
772 | 772 | ||
773 | void KABCore::setWhoAmI() | 773 | void KABCore::setWhoAmI() |
774 | { | 774 | { |
775 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 775 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
776 | 776 | ||
777 | if ( addrList.count() > 1 ) { | 777 | if ( addrList.count() > 1 ) { |
778 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 778 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
779 | return; | 779 | return; |
780 | } | 780 | } |
781 | 781 | ||
782 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 782 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
783 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 783 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
784 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 784 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
785 | } | 785 | } |
786 | 786 | ||
787 | void KABCore::setCategories() | 787 | void KABCore::setCategories() |
788 | { | 788 | { |
789 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 789 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
790 | if ( !dlg.exec() ) | 790 | if ( !dlg.exec() ) |
791 | return; | 791 | return; |
792 | 792 | ||
793 | bool merge = false; | 793 | bool merge = false; |
794 | QString msg = i18n( "Merge with existing categories?" ); | 794 | QString msg = i18n( "Merge with existing categories?" ); |
795 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) | 795 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) |
796 | merge = true; | 796 | merge = true; |
797 | 797 | ||
798 | QStringList categories = dlg.selectedCategories(); | 798 | QStringList categories = dlg.selectedCategories(); |
799 | 799 | ||
800 | QStringList uids = mViewManager->selectedUids(); | 800 | QStringList uids = mViewManager->selectedUids(); |
801 | QStringList::Iterator it; | 801 | QStringList::Iterator it; |
802 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 802 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
803 | KABC::Addressee addr = mAddressBook->findByUid( *it ); | 803 | KABC::Addressee addr = mAddressBook->findByUid( *it ); |
804 | if ( !addr.isEmpty() ) { | 804 | if ( !addr.isEmpty() ) { |
805 | if ( !merge ) | 805 | if ( !merge ) |
806 | addr.setCategories( categories ); | 806 | addr.setCategories( categories ); |
807 | else { | 807 | else { |
808 | QStringList addrCategories = addr.categories(); | 808 | QStringList addrCategories = addr.categories(); |
809 | QStringList::Iterator catIt; | 809 | QStringList::Iterator catIt; |
810 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 810 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
811 | if ( !addrCategories.contains( *catIt ) ) | 811 | if ( !addrCategories.contains( *catIt ) ) |
812 | addrCategories.append( *catIt ); | 812 | addrCategories.append( *catIt ); |
813 | } | 813 | } |
814 | addr.setCategories( addrCategories ); | 814 | addr.setCategories( addrCategories ); |
815 | } | 815 | } |
816 | 816 | ||
817 | mAddressBook->insertAddressee( addr ); | 817 | mAddressBook->insertAddressee( addr ); |
818 | } | 818 | } |
819 | } | 819 | } |
820 | 820 | ||
821 | if ( uids.count() > 0 ) | 821 | if ( uids.count() > 0 ) |
822 | setModified( true ); | 822 | setModified( true ); |
823 | } | 823 | } |
824 | 824 | ||
825 | void KABCore::setSearchFields( const KABC::Field::List &fields ) | 825 | void KABCore::setSearchFields( const KABC::Field::List &fields ) |
826 | { | 826 | { |
827 | mIncSearchWidget->setFields( fields ); | 827 | mIncSearchWidget->setFields( fields ); |
828 | } | 828 | } |
829 | 829 | ||
830 | void KABCore::incrementalSearch( const QString& text ) | 830 | void KABCore::incrementalSearch( const QString& text ) |
831 | { | 831 | { |
832 | mViewManager->setSelected( QString::null, false ); | 832 | mViewManager->setSelected( QString::null, false ); |
833 | 833 | ||
834 | if ( !text.isEmpty() ) { | 834 | if ( !text.isEmpty() ) { |
835 | KABC::Field *field = mIncSearchWidget->currentField(); | 835 | KABC::Field *field = mIncSearchWidget->currentField(); |
836 | 836 | QString pattern = text.lower()+"*"; | |
837 | QString pattern = text.lower(); | 837 | QRegExp re; |
838 | 838 | re.setWildcard(true); // most people understand these better. | |
839 | re.setCaseSensitive(false); | ||
840 | re.setPattern( pattern ); | ||
841 | QStringList foundUids; | ||
842 | if (!re.isValid()) | ||
843 | return; | ||
839 | #if 1 //KDE_VERSION >= 319 | 844 | #if 1 //KDE_VERSION >= 319 |
840 | KABC::AddresseeList list( mAddressBook->allAddressees() ); | 845 | KABC::AddresseeList list( mAddressBook->allAddressees() ); |
841 | if ( field ) { | 846 | if ( field ) { |
842 | list.sortByField( field ); | 847 | list.sortByField( field ); |
843 | KABC::AddresseeList::Iterator it; | 848 | KABC::AddresseeList::Iterator it; |
844 | for ( it = list.begin(); it != list.end(); ++it ) { | 849 | for ( it = list.begin(); it != list.end(); ++it ) { |
845 | if ( field->value( *it ).lower().startsWith( pattern ) ) { | 850 | |
846 | mViewManager->setSelected( (*it).uid(), true ); | 851 | #if QT_VERSION >= 300 |
847 | return; | 852 | if (re.search(field->value( *it ).lower()) != -1) |
848 | } | 853 | #else |
854 | if (re.match(field->value( *it ).lower()) != -1) | ||
855 | #endif | ||
856 | { | ||
857 | // if ( field->value( *it ).lower().startsWith( pattern ) ) { | ||
858 | //mViewManager->setSelected( (*it).uid(), true ); | ||
859 | foundUids.append( (*it).uid() ); | ||
860 | //return; | ||
861 | } | ||
849 | } | 862 | } |
850 | } else { | 863 | } else { |
851 | KABC::AddresseeList::Iterator it; | 864 | KABC::AddresseeList::Iterator it; |
852 | for ( it = list.begin(); it != list.end(); ++it ) { | 865 | for ( it = list.begin(); it != list.end(); ++it ) { |
853 | KABC::Field::List fieldList = mIncSearchWidget->fields(); | 866 | KABC::Field::List fieldList = mIncSearchWidget->fields(); |
854 | KABC::Field::List::ConstIterator fieldIt; | 867 | KABC::Field::List::ConstIterator fieldIt; |
855 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 868 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
856 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | 869 | #if QT_VERSION >= 300 |
857 | mViewManager->setSelected( (*it).uid(), true ); | 870 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
858 | return; | 871 | #else |
872 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | ||
873 | #endif | ||
874 | { | ||
875 | // if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | ||
876 | //mViewManager->setSelected( (*it).uid(), true ); | ||
877 | foundUids.append( (*it).uid() ); | ||
878 | //return; | ||
859 | } | 879 | } |
860 | } | 880 | } |
861 | } | 881 | } |
862 | } | 882 | } |
883 | if ( foundUids.count() > 0 ) | ||
884 | mViewManager->setListSelected( foundUids ); | ||
863 | #else | 885 | #else |
864 | KABC::AddressBook::Iterator it; | 886 | KABC::AddressBook::Iterator it; |
865 | for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 887 | for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
866 | if ( field ) { | 888 | if ( field ) { |
867 | if ( field->value( *it ).lower().startsWith( pattern ) ) { | 889 | if ( field->value( *it ).lower().startsWith( pattern ) ) { |
868 | mViewManager->setSelected( (*it).uid(), true ); | 890 | mViewManager->setSelected( (*it).uid(), true ); |
869 | return; | 891 | return; |
870 | } | 892 | } |
871 | } else { | 893 | } else { |
872 | KABC::Field::List fieldList = mIncSearchWidget->fields(); | 894 | KABC::Field::List fieldList = mIncSearchWidget->fields(); |
873 | KABC::Field::List::ConstIterator fieldIt; | 895 | KABC::Field::List::ConstIterator fieldIt; |
874 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 896 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
875 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | 897 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { |
876 | mViewManager->setSelected( (*it).uid(), true ); | 898 | mViewManager->setSelected( (*it).uid(), true ); |
877 | return; | 899 | return; |
878 | } | 900 | } |
879 | } | 901 | } |
880 | } | 902 | } |
881 | } | 903 | } |
882 | #endif | 904 | #endif |
883 | } | 905 | } |
884 | } | 906 | } |
885 | 907 | ||
886 | void KABCore::setModified() | 908 | void KABCore::setModified() |
887 | { | 909 | { |
888 | setModified( true ); | 910 | setModified( true ); |
889 | } | 911 | } |
890 | 912 | ||
891 | void KABCore::setModifiedWOrefresh() | 913 | void KABCore::setModifiedWOrefresh() |
892 | { | 914 | { |
893 | // qDebug("KABCore::setModifiedWOrefresh() "); | 915 | // qDebug("KABCore::setModifiedWOrefresh() "); |
894 | mModified = true; | 916 | mModified = true; |
895 | mActionSave->setEnabled( mModified ); | 917 | mActionSave->setEnabled( mModified ); |
896 | #ifdef DESKTOP_VERSION | 918 | #ifdef DESKTOP_VERSION |
897 | mDetails->refreshView(); | 919 | mDetails->refreshView(); |
898 | #endif | 920 | #endif |
899 | 921 | ||
900 | } | 922 | } |
901 | void KABCore::setModified( bool modified ) | 923 | void KABCore::setModified( bool modified ) |
902 | { | 924 | { |
903 | mModified = modified; | 925 | mModified = modified; |
904 | mActionSave->setEnabled( mModified ); | 926 | mActionSave->setEnabled( mModified ); |
905 | 927 | ||
906 | if ( modified ) | 928 | if ( modified ) |
907 | mJumpButtonBar->recreateButtons(); | 929 | mJumpButtonBar->recreateButtons(); |
908 | 930 | ||
909 | mViewManager->refreshView(); | 931 | mViewManager->refreshView(); |
910 | mDetails->refreshView(); | 932 | mDetails->refreshView(); |
911 | 933 | ||
912 | } | 934 | } |
913 | 935 | ||
914 | bool KABCore::modified() const | 936 | bool KABCore::modified() const |
915 | { | 937 | { |
916 | return mModified; | 938 | return mModified; |
917 | } | 939 | } |
918 | 940 | ||
919 | void KABCore::contactModified( const KABC::Addressee &addr ) | 941 | void KABCore::contactModified( const KABC::Addressee &addr ) |
920 | { | 942 | { |
921 | 943 | ||
922 | Command *command = 0; | 944 | Command *command = 0; |
923 | QString uid; | 945 | QString uid; |
924 | 946 | ||
925 | // check if it exists already | 947 | // check if it exists already |
926 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); | 948 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); |
927 | if ( origAddr.isEmpty() ) | 949 | if ( origAddr.isEmpty() ) |
928 | command = new PwNewCommand( mAddressBook, addr ); | 950 | command = new PwNewCommand( mAddressBook, addr ); |
929 | else { | 951 | else { |
930 | command = new PwEditCommand( mAddressBook, origAddr, addr ); | 952 | command = new PwEditCommand( mAddressBook, origAddr, addr ); |
931 | uid = addr.uid(); | 953 | uid = addr.uid(); |
932 | } | 954 | } |
933 | 955 | ||
934 | UndoStack::instance()->push( command ); | 956 | UndoStack::instance()->push( command ); |
935 | RedoStack::instance()->clear(); | 957 | RedoStack::instance()->clear(); |
936 | 958 | ||
937 | setModified( true ); | 959 | setModified( true ); |
938 | } | 960 | } |
939 | 961 | ||
940 | void KABCore::newContact() | 962 | void KABCore::newContact() |
941 | { | 963 | { |
942 | 964 | ||
943 | 965 | ||
944 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); | 966 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); |
945 | 967 | ||
946 | QPtrList<KRES::Resource> kresResources; | 968 | QPtrList<KRES::Resource> kresResources; |
947 | QPtrListIterator<KABC::Resource> it( kabcResources ); | 969 | QPtrListIterator<KABC::Resource> it( kabcResources ); |
948 | KABC::Resource *resource; | 970 | KABC::Resource *resource; |
949 | while ( ( resource = it.current() ) != 0 ) { | 971 | while ( ( resource = it.current() ) != 0 ) { |
950 | ++it; | 972 | ++it; |
951 | if ( !resource->readOnly() ) { | 973 | if ( !resource->readOnly() ) { |
952 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 974 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
953 | if ( res ) | 975 | if ( res ) |
954 | kresResources.append( res ); | 976 | kresResources.append( res ); |
955 | } | 977 | } |
956 | } | 978 | } |
957 | 979 | ||
958 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); | 980 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); |
959 | resource = static_cast<KABC::Resource*>( res ); | 981 | resource = static_cast<KABC::Resource*>( res ); |
960 | 982 | ||
961 | if ( resource ) { | 983 | if ( resource ) { |
962 | KABC::Addressee addr; | 984 | KABC::Addressee addr; |
963 | addr.setResource( resource ); | 985 | addr.setResource( resource ); |
964 | mEditorDialog->setAddressee( addr ); | 986 | mEditorDialog->setAddressee( addr ); |
965 | KApplication::execDialog ( mEditorDialog ); | 987 | KApplication::execDialog ( mEditorDialog ); |
966 | 988 | ||
967 | } else | 989 | } else |
968 | return; | 990 | return; |
969 | 991 | ||
970 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); | 992 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); |
971 | 993 | ||
972 | 994 | ||
973 | } | 995 | } |
974 | 996 | ||
975 | void KABCore::addEmail( QString aStr ) | 997 | void KABCore::addEmail( QString aStr ) |
976 | { | 998 | { |
977 | #ifndef KAB_EMBEDDED | 999 | #ifndef KAB_EMBEDDED |
978 | QString fullName, email; | 1000 | QString fullName, email; |
979 | 1001 | ||
980 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); | 1002 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); |
981 | 1003 | ||
982 | // Try to lookup the addressee matching the email address | 1004 | // Try to lookup the addressee matching the email address |
983 | bool found = false; | 1005 | bool found = false; |
984 | QStringList emailList; | 1006 | QStringList emailList; |
985 | KABC::AddressBook::Iterator it; | 1007 | KABC::AddressBook::Iterator it; |
986 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { | 1008 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { |
987 | emailList = (*it).emails(); | 1009 | emailList = (*it).emails(); |
988 | if ( emailList.contains( email ) > 0 ) { | 1010 | if ( emailList.contains( email ) > 0 ) { |
989 | found = true; | 1011 | found = true; |
990 | (*it).setNameFromString( fullName ); | 1012 | (*it).setNameFromString( fullName ); |
991 | editContact( (*it).uid() ); | 1013 | editContact( (*it).uid() ); |
992 | } | 1014 | } |
993 | } | 1015 | } |
994 | 1016 | ||
995 | if ( !found ) { | 1017 | if ( !found ) { |
996 | KABC::Addressee addr; | 1018 | KABC::Addressee addr; |
997 | addr.setNameFromString( fullName ); | 1019 | addr.setNameFromString( fullName ); |
998 | addr.insertEmail( email, true ); | 1020 | addr.insertEmail( email, true ); |
999 | 1021 | ||
1000 | mAddressBook->insertAddressee( addr ); | 1022 | mAddressBook->insertAddressee( addr ); |
1001 | mViewManager->refreshView( addr.uid() ); | 1023 | mViewManager->refreshView( addr.uid() ); |
1002 | editContact( addr.uid() ); | 1024 | editContact( addr.uid() ); |
1003 | } | 1025 | } |
1004 | #else //KAB_EMBEDDED | 1026 | #else //KAB_EMBEDDED |
1005 | qDebug("KABCore::addEmail finsih method"); | 1027 | qDebug("KABCore::addEmail finsih method"); |
1006 | #endif //KAB_EMBEDDED | 1028 | #endif //KAB_EMBEDDED |
1007 | } | 1029 | } |
1008 | 1030 | ||
1009 | void KABCore::importVCard( const KURL &url, bool showPreview ) | 1031 | void KABCore::importVCard( const KURL &url, bool showPreview ) |
1010 | { | 1032 | { |
1011 | mXXPortManager->importVCard( url, showPreview ); | 1033 | mXXPortManager->importVCard( url, showPreview ); |
1012 | } | 1034 | } |
1013 | void KABCore::importFromOL() | 1035 | void KABCore::importFromOL() |
1014 | { | 1036 | { |
1015 | #ifdef _WIN32_ | 1037 | #ifdef _WIN32_ |
1016 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); | 1038 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); |
1017 | idgl->exec(); | 1039 | idgl->exec(); |
1018 | KABC::Addressee::List list = idgl->getAddressList(); | 1040 | KABC::Addressee::List list = idgl->getAddressList(); |
1019 | if ( list.count() > 0 ) { | 1041 | if ( list.count() > 0 ) { |
1020 | KABC::Addressee::List listNew; | 1042 | KABC::Addressee::List listNew; |
1021 | KABC::Addressee::List listExisting; | 1043 | KABC::Addressee::List listExisting; |
1022 | KABC::Addressee::List::Iterator it; | 1044 | KABC::Addressee::List::Iterator it; |
1023 | KABC::AddressBook::Iterator iter; | 1045 | KABC::AddressBook::Iterator iter; |
1024 | for ( it = list.begin(); it != list.end(); ++it ) { | 1046 | for ( it = list.begin(); it != list.end(); ++it ) { |
1025 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) | 1047 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) |
1026 | listNew.append( (*it) ); | 1048 | listNew.append( (*it) ); |
1027 | else | 1049 | else |
1028 | listExisting.append( (*it) ); | 1050 | listExisting.append( (*it) ); |
1029 | } | 1051 | } |
1030 | if ( listExisting.count() > 0 ) | 1052 | if ( listExisting.count() > 0 ) |
1031 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); | 1053 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); |
1032 | if ( listNew.count() > 0 ) { | 1054 | if ( listNew.count() > 0 ) { |
1033 | pasteWithNewUid = false; | 1055 | pasteWithNewUid = false; |
1034 | pasteContacts( listNew ); | 1056 | pasteContacts( listNew ); |
1035 | pasteWithNewUid = true; | 1057 | pasteWithNewUid = true; |
1036 | } | 1058 | } |
1037 | } | 1059 | } |
1038 | delete idgl; | 1060 | delete idgl; |
1039 | #endif | 1061 | #endif |
1040 | } | 1062 | } |
1041 | 1063 | ||
1042 | void KABCore::importVCard( const QString &vCard, bool showPreview ) | 1064 | void KABCore::importVCard( const QString &vCard, bool showPreview ) |
1043 | { | 1065 | { |
1044 | mXXPortManager->importVCard( vCard, showPreview ); | 1066 | mXXPortManager->importVCard( vCard, showPreview ); |
1045 | } | 1067 | } |
1046 | 1068 | ||
1047 | //US added a second method without defaultparameter | 1069 | //US added a second method without defaultparameter |
1048 | void KABCore::editContact2() { | 1070 | void KABCore::editContact2() { |
1049 | editContact( QString::null ); | 1071 | editContact( QString::null ); |
1050 | } | 1072 | } |
1051 | 1073 | ||
1052 | void KABCore::editContact( const QString &uid ) | 1074 | void KABCore::editContact( const QString &uid ) |
1053 | { | 1075 | { |
1054 | 1076 | ||
1055 | if ( mExtensionManager->isQuickEditVisible() ) | 1077 | if ( mExtensionManager->isQuickEditVisible() ) |
1056 | return; | 1078 | return; |
1057 | 1079 | ||
1058 | // First, locate the contact entry | 1080 | // First, locate the contact entry |
1059 | QString localUID = uid; | 1081 | QString localUID = uid; |
1060 | if ( localUID.isNull() ) { | 1082 | if ( localUID.isNull() ) { |
1061 | QStringList uidList = mViewManager->selectedUids(); | 1083 | QStringList uidList = mViewManager->selectedUids(); |
1062 | if ( uidList.count() > 0 ) | 1084 | if ( uidList.count() > 0 ) |
1063 | localUID = *( uidList.at( 0 ) ); | 1085 | localUID = *( uidList.at( 0 ) ); |
1064 | } | 1086 | } |
1065 | 1087 | ||
1066 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); | 1088 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); |
1067 | if ( !addr.isEmpty() ) { | 1089 | if ( !addr.isEmpty() ) { |
1068 | mEditorDialog->setAddressee( addr ); | 1090 | mEditorDialog->setAddressee( addr ); |
1069 | KApplication::execDialog ( mEditorDialog ); | 1091 | KApplication::execDialog ( mEditorDialog ); |
1070 | } | 1092 | } |
1071 | } | 1093 | } |
1072 | 1094 | ||
1073 | /** | 1095 | /** |
1074 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 1096 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
1075 | the method will try to find a selected addressee in the view. | 1097 | the method will try to find a selected addressee in the view. |
1076 | */ | 1098 | */ |
1077 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | 1099 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) |
1078 | { | 1100 | { |
1079 | if ( mMultipleViewsAtOnce ) | 1101 | if ( mMultipleViewsAtOnce ) |
1080 | { | 1102 | { |
1081 | editContact( uid ); | 1103 | editContact( uid ); |
1082 | } | 1104 | } |
1083 | else | 1105 | else |
1084 | { | 1106 | { |
1085 | setDetailsVisible( true ); | 1107 | setDetailsVisible( true ); |
1086 | mActionDetails->setChecked(true); | 1108 | mActionDetails->setChecked(true); |
1087 | } | 1109 | } |
1088 | 1110 | ||
1089 | } | 1111 | } |
1090 | 1112 | ||
1091 | void KABCore::save() | 1113 | void KABCore::save() |
1092 | { | 1114 | { |
1093 | if ( !mModified ) | 1115 | if ( !mModified ) |
1094 | return; | 1116 | return; |
1095 | QString text = i18n( "There was an error while attempting to save\n the " | 1117 | QString text = i18n( "There was an error while attempting to save\n the " |
1096 | "address book. Please check that some \nother application is " | 1118 | "address book. Please check that some \nother application is " |
1097 | "not using it. " ); | 1119 | "not using it. " ); |
1098 | statusMessage(i18n("Saving addressbook ... ")); | 1120 | statusMessage(i18n("Saving addressbook ... ")); |
1099 | #ifndef KAB_EMBEDDED | 1121 | #ifndef KAB_EMBEDDED |
1100 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); | 1122 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); |
1101 | if ( !b || !b->save() ) { | 1123 | if ( !b || !b->save() ) { |
1102 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); | 1124 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); |
1103 | } | 1125 | } |
1104 | #else //KAB_EMBEDDED | 1126 | #else //KAB_EMBEDDED |
1105 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); | 1127 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); |
1106 | if ( !b || !b->save() ) { | 1128 | if ( !b || !b->save() ) { |
1107 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1129 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1108 | } | 1130 | } |
1109 | #endif //KAB_EMBEDDED | 1131 | #endif //KAB_EMBEDDED |
1110 | 1132 | ||
1111 | statusMessage(i18n("Addressbook saved!")); | 1133 | statusMessage(i18n("Addressbook saved!")); |
1112 | setModified( false ); | 1134 | setModified( false ); |
1113 | } | 1135 | } |
1114 | 1136 | ||
1115 | void KABCore::statusMessage(QString mess , int time ) | 1137 | void KABCore::statusMessage(QString mess , int time ) |
1116 | { | 1138 | { |
1117 | //topLevelWidget()->setCaption( mess ); | 1139 | //topLevelWidget()->setCaption( mess ); |
1118 | // pending setting timer to revome message | 1140 | // pending setting timer to revome message |
1119 | } | 1141 | } |
1120 | void KABCore::undo() | 1142 | void KABCore::undo() |
1121 | { | 1143 | { |
1122 | UndoStack::instance()->undo(); | 1144 | UndoStack::instance()->undo(); |
1123 | 1145 | ||
1124 | // Refresh the view | 1146 | // Refresh the view |
1125 | mViewManager->refreshView(); | 1147 | mViewManager->refreshView(); |
1126 | } | 1148 | } |
1127 | 1149 | ||
1128 | void KABCore::redo() | 1150 | void KABCore::redo() |
1129 | { | 1151 | { |
1130 | RedoStack::instance()->redo(); | 1152 | RedoStack::instance()->redo(); |
1131 | 1153 | ||
1132 | // Refresh the view | 1154 | // Refresh the view |
1133 | mViewManager->refreshView(); | 1155 | mViewManager->refreshView(); |
1134 | } | 1156 | } |
1135 | 1157 | ||
1136 | void KABCore::setJumpButtonBarVisible( bool visible ) | 1158 | void KABCore::setJumpButtonBarVisible( bool visible ) |
1137 | { | 1159 | { |
1138 | if (mMultipleViewsAtOnce) | 1160 | if (mMultipleViewsAtOnce) |
1139 | { | 1161 | { |
1140 | if ( visible ) | 1162 | if ( visible ) |
1141 | mJumpButtonBar->show(); | 1163 | mJumpButtonBar->show(); |
1142 | else | 1164 | else |
1143 | mJumpButtonBar->hide(); | 1165 | mJumpButtonBar->hide(); |
1144 | } | 1166 | } |
1145 | else | 1167 | else |
1146 | { | 1168 | { |
1147 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" | 1169 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" |
1148 | if (mViewManager->isVisible()) | 1170 | if (mViewManager->isVisible()) |
1149 | { | 1171 | { |
1150 | if ( visible ) | 1172 | if ( visible ) |
1151 | mJumpButtonBar->show(); | 1173 | mJumpButtonBar->show(); |
1152 | else | 1174 | else |
1153 | mJumpButtonBar->hide(); | 1175 | mJumpButtonBar->hide(); |
1154 | } | 1176 | } |
1155 | else | 1177 | else |
1156 | { | 1178 | { |
1157 | mJumpButtonBar->hide(); | 1179 | mJumpButtonBar->hide(); |
1158 | } | 1180 | } |
1159 | } | 1181 | } |
1160 | } | 1182 | } |
1161 | 1183 | ||
1162 | 1184 | ||
1163 | void KABCore::setDetailsToState() | 1185 | void KABCore::setDetailsToState() |
1164 | { | 1186 | { |
1165 | setDetailsVisible( mActionDetails->isChecked() ); | 1187 | setDetailsVisible( mActionDetails->isChecked() ); |
1166 | } | 1188 | } |
1167 | 1189 | ||
1168 | 1190 | ||
1169 | 1191 | ||
1170 | void KABCore::setDetailsVisible( bool visible ) | 1192 | void KABCore::setDetailsVisible( bool visible ) |
1171 | { | 1193 | { |
1172 | if (visible && mDetails->isHidden()) | 1194 | if (visible && mDetails->isHidden()) |
1173 | { | 1195 | { |
1174 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 1196 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
1175 | if ( addrList.count() > 0 ) | 1197 | if ( addrList.count() > 0 ) |
1176 | mDetails->setAddressee( addrList[ 0 ] ); | 1198 | mDetails->setAddressee( addrList[ 0 ] ); |
1177 | } | 1199 | } |
1178 | 1200 | ||
1179 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between | 1201 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between |
1180 | // the listview and the detailview. We do that by changing the splitbar size. | 1202 | // the listview and the detailview. We do that by changing the splitbar size. |
1181 | if (mMultipleViewsAtOnce) | 1203 | if (mMultipleViewsAtOnce) |
1182 | { | 1204 | { |
1183 | if ( visible ) | 1205 | if ( visible ) |
1184 | mDetails->show(); | 1206 | mDetails->show(); |
1185 | else | 1207 | else |
1186 | mDetails->hide(); | 1208 | mDetails->hide(); |
1187 | } | 1209 | } |
1188 | else | 1210 | else |
1189 | { | 1211 | { |
1190 | if ( visible ) { | 1212 | if ( visible ) { |
1191 | mViewManager->hide(); | 1213 | mViewManager->hide(); |
1192 | mDetails->show(); | 1214 | mDetails->show(); |
1193 | } | 1215 | } |
1194 | else { | 1216 | else { |
1195 | mViewManager->show(); | 1217 | mViewManager->show(); |
1196 | mDetails->hide(); | 1218 | mDetails->hide(); |
1197 | } | 1219 | } |
1198 | setJumpButtonBarVisible( !visible ); | 1220 | setJumpButtonBarVisible( !visible ); |
1199 | } | 1221 | } |
1200 | 1222 | ||
1201 | } | 1223 | } |
1202 | 1224 | ||
1203 | void KABCore::extensionChanged( int id ) | 1225 | void KABCore::extensionChanged( int id ) |
1204 | { | 1226 | { |
1205 | //change the details view only for non desktop systems | 1227 | //change the details view only for non desktop systems |
1206 | #ifndef DESKTOP_VERSION | 1228 | #ifndef DESKTOP_VERSION |
1207 | 1229 | ||
1208 | if (id == 0) | 1230 | if (id == 0) |
1209 | { | 1231 | { |
1210 | //the user disabled the extension. | 1232 | //the user disabled the extension. |
1211 | 1233 | ||
1212 | if (mMultipleViewsAtOnce) | 1234 | if (mMultipleViewsAtOnce) |
1213 | { // enable detailsview again | 1235 | { // enable detailsview again |
1214 | setDetailsVisible( true ); | 1236 | setDetailsVisible( true ); |
1215 | mActionDetails->setChecked( true ); | 1237 | mActionDetails->setChecked( true ); |
1216 | } | 1238 | } |
1217 | else | 1239 | else |
1218 | { //go back to the listview | 1240 | { //go back to the listview |
1219 | setDetailsVisible( false ); | 1241 | setDetailsVisible( false ); |
1220 | mActionDetails->setChecked( false ); | 1242 | mActionDetails->setChecked( false ); |
1221 | mActionDetails->setEnabled(true); | 1243 | mActionDetails->setEnabled(true); |
1222 | } | 1244 | } |
1223 | 1245 | ||
1224 | } | 1246 | } |
1225 | else | 1247 | else |
1226 | { | 1248 | { |
1227 | //the user enabled the extension. | 1249 | //the user enabled the extension. |
1228 | setDetailsVisible( false ); | 1250 | setDetailsVisible( false ); |
1229 | mActionDetails->setChecked( false ); | 1251 | mActionDetails->setChecked( false ); |
1230 | 1252 | ||
1231 | if (!mMultipleViewsAtOnce) | 1253 | if (!mMultipleViewsAtOnce) |
1232 | { | 1254 | { |
1233 | mActionDetails->setEnabled(false); | 1255 | mActionDetails->setEnabled(false); |
1234 | } | 1256 | } |
1235 | 1257 | ||
1236 | mExtensionManager->setSelectionChanged(); | 1258 | mExtensionManager->setSelectionChanged(); |
1237 | 1259 | ||
1238 | } | 1260 | } |
1239 | 1261 | ||
1240 | #endif// DESKTOP_VERSION | 1262 | #endif// DESKTOP_VERSION |
1241 | 1263 | ||
1242 | } | 1264 | } |
1243 | 1265 | ||
1244 | 1266 | ||
1245 | void KABCore::extensionModified( const KABC::Addressee::List &list ) | 1267 | void KABCore::extensionModified( const KABC::Addressee::List &list ) |
1246 | { | 1268 | { |
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 45c7b55..c93d51a 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp | |||
@@ -1,564 +1,571 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | 31 | ||
32 | #ifndef KAB_EMBEDDED | 32 | #ifndef KAB_EMBEDDED |
33 | #include <libkdepim/kvcarddrag.h> | 33 | #include <libkdepim/kvcarddrag.h> |
34 | #include <kabc/vcardconverter.h> | 34 | #include <kabc/vcardconverter.h> |
35 | #include <kconfig.h> | 35 | #include <kconfig.h> |
36 | #include <kdeversion.h> | 36 | #include <kdeversion.h> |
37 | #include <kiconloader.h> | 37 | #include <kiconloader.h> |
38 | #include <klocale.h> | 38 | #include <klocale.h> |
39 | #include <kmessagebox.h> | 39 | #include <kmessagebox.h> |
40 | #include <kmultipledrag.h> | 40 | #include <kmultipledrag.h> |
41 | #include <ktrader.h> | 41 | #include <ktrader.h> |
42 | #include <kurldrag.h> | 42 | #include <kurldrag.h> |
43 | 43 | ||
44 | #include "addresseeutil.h" | 44 | #include "addresseeutil.h" |
45 | #else //KAB_EMBEDDED | 45 | #else //KAB_EMBEDDED |
46 | #include "views/kaddressbookiconview.h" | 46 | #include "views/kaddressbookiconview.h" |
47 | #include "views/kaddressbooktableview.h" | 47 | #include "views/kaddressbooktableview.h" |
48 | #include "views/kaddressbookcardview.h" | 48 | #include "views/kaddressbookcardview.h" |
49 | #include "kaddressbookview.h" | 49 | #include "kaddressbookview.h" |
50 | 50 | ||
51 | #include <qaction.h> | 51 | #include <qaction.h> |
52 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
53 | #include <qpopupmenu.h> | 53 | #include <qpopupmenu.h> |
54 | #include <kconfigbase.h> | 54 | #include <kconfigbase.h> |
55 | 55 | ||
56 | #endif //KAB_EMBEDDED | 56 | #endif //KAB_EMBEDDED |
57 | 57 | ||
58 | 58 | ||
59 | #include <kdebug.h> | 59 | #include <kdebug.h> |
60 | #include <kactionclasses.h> | 60 | #include <kactionclasses.h> |
61 | 61 | ||
62 | #include <qlayout.h> | 62 | #include <qlayout.h> |
63 | #include <qwidgetstack.h> | 63 | #include <qwidgetstack.h> |
64 | 64 | ||
65 | #include <kabc/addressbook.h> | 65 | #include <kabc/addressbook.h> |
66 | #include "filtereditdialog.h" | 66 | #include "filtereditdialog.h" |
67 | #include "addviewdialog.h" | 67 | #include "addviewdialog.h" |
68 | #include "kabcore.h" | 68 | #include "kabcore.h" |
69 | #include "kabprefs.h" | 69 | #include "kabprefs.h" |
70 | #include "viewmanager.h" | 70 | #include "viewmanager.h" |
71 | 71 | ||
72 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) | 72 | ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) |
73 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) | 73 | : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) |
74 | { | 74 | { |
75 | initGUI(); | 75 | initGUI(); |
76 | initActions(); | 76 | initActions(); |
77 | 77 | ||
78 | mViewDict.setAutoDelete( true ); | 78 | mViewDict.setAutoDelete( true ); |
79 | 79 | ||
80 | createViewFactories(); | 80 | createViewFactories(); |
81 | } | 81 | } |
82 | 82 | ||
83 | ViewManager::~ViewManager() | 83 | ViewManager::~ViewManager() |
84 | { | 84 | { |
85 | unloadViews(); | 85 | unloadViews(); |
86 | mViewFactoryDict.clear(); | 86 | mViewFactoryDict.clear(); |
87 | } | 87 | } |
88 | 88 | ||
89 | void ViewManager::restoreSettings() | 89 | void ViewManager::restoreSettings() |
90 | { | 90 | { |
91 | mViewNameList = KABPrefs::instance()->mViewNames; | 91 | mViewNameList = KABPrefs::instance()->mViewNames; |
92 | QString activeViewName = KABPrefs::instance()->mCurrentView; | 92 | QString activeViewName = KABPrefs::instance()->mCurrentView; |
93 | 93 | ||
94 | mActionSelectView->setItems( mViewNameList ); | 94 | mActionSelectView->setItems( mViewNameList ); |
95 | 95 | ||
96 | // Filter | 96 | // Filter |
97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); | 97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); |
98 | mActionSelectFilter->setItems( filterNames() ); | 98 | mActionSelectFilter->setItems( filterNames() ); |
99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); | 99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); |
100 | 100 | ||
101 | // Tell the views to reread their config, since they may have | 101 | // Tell the views to reread their config, since they may have |
102 | // been modified by global settings | 102 | // been modified by global settings |
103 | QString _oldgroup = mCore->config()->group(); | 103 | QString _oldgroup = mCore->config()->group(); |
104 | 104 | ||
105 | QDictIterator<KAddressBookView> it( mViewDict ); | 105 | QDictIterator<KAddressBookView> it( mViewDict ); |
106 | for ( it.toFirst(); it.current(); ++it ) { | 106 | for ( it.toFirst(); it.current(); ++it ) { |
107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
108 | it.current()->readConfig( mCore->config() ); | 108 | it.current()->readConfig( mCore->config() ); |
109 | } | 109 | } |
110 | setActiveView( activeViewName ); | 110 | setActiveView( activeViewName ); |
111 | 111 | ||
112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
113 | } | 113 | } |
114 | 114 | ||
115 | void ViewManager::saveSettings() | 115 | void ViewManager::saveSettings() |
116 | { | 116 | { |
117 | QString _oldgroup = mCore->config()->group(); | 117 | QString _oldgroup = mCore->config()->group(); |
118 | 118 | ||
119 | QDictIterator<KAddressBookView> it( mViewDict ); | 119 | QDictIterator<KAddressBookView> it( mViewDict ); |
120 | for ( it.toFirst(); it.current(); ++it ) { | 120 | for ( it.toFirst(); it.current(); ++it ) { |
121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
122 | #ifdef DESKTOP_VERSION | 122 | #ifdef DESKTOP_VERSION |
123 | (*it)->writeConfig( mCore->config() ); | 123 | (*it)->writeConfig( mCore->config() ); |
124 | #else | 124 | #else |
125 | (*it).writeConfig( mCore->config() ); | 125 | (*it).writeConfig( mCore->config() ); |
126 | #endif | 126 | #endif |
127 | } | 127 | } |
128 | 128 | ||
129 | Filter::save( mCore->config(), "Filter", mFilterList ); | 129 | Filter::save( mCore->config(), "Filter", mFilterList ); |
130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); | 130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); |
131 | 131 | ||
132 | // write the view name list | 132 | // write the view name list |
133 | KABPrefs::instance()->mViewNames = mViewNameList; | 133 | KABPrefs::instance()->mViewNames = mViewNameList; |
134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); | 134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | QStringList ViewManager::selectedUids() const | 138 | QStringList ViewManager::selectedUids() const |
139 | { | 139 | { |
140 | if ( mActiveView ) | 140 | if ( mActiveView ) |
141 | return mActiveView->selectedUids(); | 141 | return mActiveView->selectedUids(); |
142 | else | 142 | else |
143 | return QStringList(); | 143 | return QStringList(); |
144 | } | 144 | } |
145 | 145 | ||
146 | QStringList ViewManager::selectedEmails() const | 146 | QStringList ViewManager::selectedEmails() const |
147 | { | 147 | { |
148 | if ( mActiveView ) | 148 | if ( mActiveView ) |
149 | return mActiveView->selectedEmails(); | 149 | return mActiveView->selectedEmails(); |
150 | else | 150 | else |
151 | return QStringList(); | 151 | return QStringList(); |
152 | } | 152 | } |
153 | 153 | ||
154 | KABC::Addressee::List ViewManager::selectedAddressees() const | 154 | KABC::Addressee::List ViewManager::selectedAddressees() const |
155 | { | 155 | { |
156 | KABC::Addressee::List list; | 156 | KABC::Addressee::List list; |
157 | if ( mActiveView ) { | 157 | if ( mActiveView ) { |
158 | QStringList uids = mActiveView->selectedUids(); | 158 | QStringList uids = mActiveView->selectedUids(); |
159 | QStringList::Iterator it; | 159 | QStringList::Iterator it; |
160 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 160 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); | 161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); |
162 | if ( !addr.isEmpty() ) | 162 | if ( !addr.isEmpty() ) |
163 | list.append( addr ); | 163 | list.append( addr ); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | return list; | 167 | return list; |
168 | } | 168 | } |
169 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 169 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
170 | void ViewManager::setSelected() | 170 | void ViewManager::setSelected() |
171 | { | 171 | { |
172 | setSelected( QString::null, true ); | 172 | setSelected( QString::null, true ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void ViewManager::setSelected( const QString &uid, bool selected ) | 175 | void ViewManager::setSelected( const QString &uid, bool selected ) |
176 | { | 176 | { |
177 | if ( mActiveView ) | 177 | if ( mActiveView ) |
178 | mActiveView->setSelected( uid, selected ); | 178 | mActiveView->setSelected( uid, selected ); |
179 | } | 179 | } |
180 | 180 | ||
181 | void ViewManager::setListSelected(QStringList list) | ||
182 | { | ||
183 | int i, count = list.count(); | ||
184 | for ( i = 0; i < count;++i ) | ||
185 | setSelected( list[i], true ); | ||
186 | |||
187 | } | ||
181 | void ViewManager::unloadViews() | 188 | void ViewManager::unloadViews() |
182 | { | 189 | { |
183 | mViewDict.clear(); | 190 | mViewDict.clear(); |
184 | mActiveView = 0; | 191 | mActiveView = 0; |
185 | } | 192 | } |
186 | 193 | ||
187 | void ViewManager::setActiveView( const QString &name ) | 194 | void ViewManager::setActiveView( const QString &name ) |
188 | { | 195 | { |
189 | KAddressBookView *view = 0; | 196 | KAddressBookView *view = 0; |
190 | 197 | ||
191 | // Check that this isn't the same as the current active view | 198 | // Check that this isn't the same as the current active view |
192 | if ( mActiveView && ( mActiveView->caption() == name ) ) | 199 | if ( mActiveView && ( mActiveView->caption() == name ) ) |
193 | return; | 200 | return; |
194 | 201 | ||
195 | // At this point we know the view that should be active is not | 202 | // At this point we know the view that should be active is not |
196 | // currently active. We will try to find the new on in the list. If | 203 | // currently active. We will try to find the new on in the list. If |
197 | // we can't find it, it means it hasn't been instantiated, so we will | 204 | // we can't find it, it means it hasn't been instantiated, so we will |
198 | // create it on demand. | 205 | // create it on demand. |
199 | 206 | ||
200 | view = mViewDict.find( name ); | 207 | view = mViewDict.find( name ); |
201 | 208 | ||
202 | // Check if we found the view. If we didn't, then we need to create it | 209 | // Check if we found the view. If we didn't, then we need to create it |
203 | if ( view == 0 ) { | 210 | if ( view == 0 ) { |
204 | KConfig *config = mCore->config(); | 211 | KConfig *config = mCore->config(); |
205 | 212 | ||
206 | KConfigGroupSaver saver( config, name ); | 213 | KConfigGroupSaver saver( config, name ); |
207 | 214 | ||
208 | QString type = config->readEntry( "Type", "Table" ); | 215 | QString type = config->readEntry( "Type", "Table" ); |
209 | 216 | ||
210 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; | 217 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; |
211 | 218 | ||
212 | ViewFactory *factory = mViewFactoryDict.find( type ); | 219 | ViewFactory *factory = mViewFactoryDict.find( type ); |
213 | if ( factory ) | 220 | if ( factory ) |
214 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); | 221 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); |
215 | 222 | ||
216 | if ( view ) { | 223 | if ( view ) { |
217 | view->setCaption( name ); | 224 | view->setCaption( name ); |
218 | mViewDict.insert( name, view ); | 225 | mViewDict.insert( name, view ); |
219 | //US my version needs an int as second parameter to addWidget | 226 | //US my version needs an int as second parameter to addWidget |
220 | mViewWidgetStack->addWidget( view, -1 ); | 227 | mViewWidgetStack->addWidget( view, -1 ); |
221 | view->readConfig( config ); | 228 | view->readConfig( config ); |
222 | 229 | ||
223 | // The manager just relays the signals | 230 | // The manager just relays the signals |
224 | connect( view, SIGNAL( selected( const QString& ) ), | 231 | connect( view, SIGNAL( selected( const QString& ) ), |
225 | SIGNAL( selected( const QString & ) ) ); | 232 | SIGNAL( selected( const QString & ) ) ); |
226 | connect( view, SIGNAL( executed( const QString& ) ), | 233 | connect( view, SIGNAL( executed( const QString& ) ), |
227 | SIGNAL( executed( const QString& ) ) ); | 234 | SIGNAL( executed( const QString& ) ) ); |
228 | 235 | ||
229 | connect( view, SIGNAL( deleteRequest( ) ), | 236 | connect( view, SIGNAL( deleteRequest( ) ), |
230 | SIGNAL( deleteRequest( ) ) ); | 237 | SIGNAL( deleteRequest( ) ) ); |
231 | 238 | ||
232 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); | 239 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); |
233 | connect( view, SIGNAL( dropped( QDropEvent* ) ), | 240 | connect( view, SIGNAL( dropped( QDropEvent* ) ), |
234 | SLOT( dropped( QDropEvent* ) ) ); | 241 | SLOT( dropped( QDropEvent* ) ) ); |
235 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); | 242 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); |
236 | } | 243 | } |
237 | } | 244 | } |
238 | 245 | ||
239 | // If we found or created the view, raise it and refresh it | 246 | // If we found or created the view, raise it and refresh it |
240 | if ( view ) { | 247 | if ( view ) { |
241 | mActiveView = view; | 248 | mActiveView = view; |
242 | mViewWidgetStack->raiseWidget( view ); | 249 | mViewWidgetStack->raiseWidget( view ); |
243 | // Set the proper filter in the view. By setting the combo | 250 | // Set the proper filter in the view. By setting the combo |
244 | // box, the activated slot will be called, which will push | 251 | // box, the activated slot will be called, which will push |
245 | // the filter to the view and refresh it. | 252 | // the filter to the view and refresh it. |
246 | 253 | ||
247 | if ( view->defaultFilterType() == KAddressBookView::None ) { | 254 | if ( view->defaultFilterType() == KAddressBookView::None ) { |
248 | 255 | ||
249 | mActionSelectFilter->setCurrentItem( 0 ); | 256 | mActionSelectFilter->setCurrentItem( 0 ); |
250 | setActiveFilter( 0 ); | 257 | setActiveFilter( 0 ); |
251 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { | 258 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { |
252 | setActiveFilter( mActionSelectFilter->currentItem() ); | 259 | setActiveFilter( mActionSelectFilter->currentItem() ); |
253 | } else { | 260 | } else { |
254 | uint pos = filterPosition( view->defaultFilterName() ); | 261 | uint pos = filterPosition( view->defaultFilterName() ); |
255 | mActionSelectFilter->setCurrentItem( pos ); | 262 | mActionSelectFilter->setCurrentItem( pos ); |
256 | setActiveFilter( pos ); | 263 | setActiveFilter( pos ); |
257 | } | 264 | } |
258 | //US qDebug("ViewManager::setActiveView 6" ); | 265 | //US qDebug("ViewManager::setActiveView 6" ); |
259 | 266 | ||
260 | // Update the inc search widget to show the fields in the new active | 267 | // Update the inc search widget to show the fields in the new active |
261 | // view. | 268 | // view. |
262 | mCore->setSearchFields( mActiveView->fields() ); | 269 | mCore->setSearchFields( mActiveView->fields() ); |
263 | 270 | ||
264 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 271 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
265 | //US mActiveView->refresh(); | 272 | //US mActiveView->refresh(); |
266 | 273 | ||
267 | } | 274 | } |
268 | else | 275 | else |
269 | { | 276 | { |
270 | qDebug("ViewManager::setActiveView: unable to find view" ); | 277 | qDebug("ViewManager::setActiveView: unable to find view" ); |
271 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; | 278 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; |
272 | } | 279 | } |
273 | } | 280 | } |
274 | 281 | ||
275 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 282 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
276 | void ViewManager::refreshView() | 283 | void ViewManager::refreshView() |
277 | { | 284 | { |
278 | refreshView( QString::null ); | 285 | refreshView( QString::null ); |
279 | } | 286 | } |
280 | 287 | ||
281 | void ViewManager::refreshView( const QString &uid ) | 288 | void ViewManager::refreshView( const QString &uid ) |
282 | { | 289 | { |
283 | if ( mActiveView ) | 290 | if ( mActiveView ) |
284 | mActiveView->refresh( uid ); | 291 | mActiveView->refresh( uid ); |
285 | } | 292 | } |
286 | 293 | ||
287 | void ViewManager::editView() | 294 | void ViewManager::editView() |
288 | { | 295 | { |
289 | if ( !mActiveView ) | 296 | if ( !mActiveView ) |
290 | return; | 297 | return; |
291 | 298 | ||
292 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); | 299 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); |
293 | ViewConfigureWidget *wdg = 0; | 300 | ViewConfigureWidget *wdg = 0; |
294 | ViewConfigureDialog* dlg = 0; | 301 | ViewConfigureDialog* dlg = 0; |
295 | if ( factory ) { | 302 | if ( factory ) { |
296 | // Save the filters so the dialog has the latest set | 303 | // Save the filters so the dialog has the latest set |
297 | Filter::save( mCore->config(), "Filter", mFilterList ); | 304 | Filter::save( mCore->config(), "Filter", mFilterList ); |
298 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); | 305 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); |
299 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); | 306 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); |
300 | } else { | 307 | } else { |
301 | qDebug("ViewManager::editView()::cannot find viewfactory "); | 308 | qDebug("ViewManager::editView()::cannot find viewfactory "); |
302 | return; | 309 | return; |
303 | } | 310 | } |
304 | if ( wdg ) { | 311 | if ( wdg ) { |
305 | dlg->setWidget( wdg ); | 312 | dlg->setWidget( wdg ); |
306 | 313 | ||
307 | #ifndef DESKTOP_VERSION | 314 | #ifndef DESKTOP_VERSION |
308 | //dlg.setMaximumSize( 640, 480 ); | 315 | //dlg.setMaximumSize( 640, 480 ); |
309 | //dlg->setGeometry( 40,40, 400, 300); | 316 | //dlg->setGeometry( 40,40, 400, 300); |
310 | dlg->showMaximized(); | 317 | dlg->showMaximized(); |
311 | #endif | 318 | #endif |
312 | 319 | ||
313 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); | 320 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); |
314 | 321 | ||
315 | dlg->restoreSettings( mCore->config() ); | 322 | dlg->restoreSettings( mCore->config() ); |
316 | 323 | ||
317 | if ( dlg->exec() ) { | 324 | if ( dlg->exec() ) { |
318 | dlg->saveSettings( mCore->config() ); | 325 | dlg->saveSettings( mCore->config() ); |
319 | mActiveView->readConfig( mCore->config() ); | 326 | mActiveView->readConfig( mCore->config() ); |
320 | 327 | ||
321 | // Set the proper filter in the view. By setting the combo | 328 | // Set the proper filter in the view. By setting the combo |
322 | // box, the activated slot will be called, which will push | 329 | // box, the activated slot will be called, which will push |
323 | // the filter to the view and refresh it. | 330 | // the filter to the view and refresh it. |
324 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { | 331 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { |
325 | mActionSelectFilter->setCurrentItem( 0 ); | 332 | mActionSelectFilter->setCurrentItem( 0 ); |
326 | setActiveFilter( 0 ); | 333 | setActiveFilter( 0 ); |
327 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { | 334 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { |
328 | setActiveFilter( mActionSelectFilter->currentItem() ); | 335 | setActiveFilter( mActionSelectFilter->currentItem() ); |
329 | } else { | 336 | } else { |
330 | uint pos = filterPosition( mActiveView->defaultFilterName() ); | 337 | uint pos = filterPosition( mActiveView->defaultFilterName() ); |
331 | mActionSelectFilter->setCurrentItem( pos ); | 338 | mActionSelectFilter->setCurrentItem( pos ); |
332 | setActiveFilter( pos ); | 339 | setActiveFilter( pos ); |
333 | } | 340 | } |
334 | mCore->setSearchFields( mActiveView->fields() ); | 341 | mCore->setSearchFields( mActiveView->fields() ); |
335 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 342 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
336 | //US mActiveView->refresh(); | 343 | //US mActiveView->refresh(); |
337 | 344 | ||
338 | 345 | ||
339 | //US this is a bugfix, that we get notified if we change a views configuration | 346 | //US this is a bugfix, that we get notified if we change a views configuration |
340 | emit modified(); | 347 | emit modified(); |
341 | 348 | ||
342 | } | 349 | } |
343 | 350 | ||
344 | } | 351 | } |
345 | delete dlg; | 352 | delete dlg; |
346 | } | 353 | } |
347 | 354 | ||
348 | void ViewManager::deleteView() | 355 | void ViewManager::deleteView() |
349 | { | 356 | { |
350 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) | 357 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) |
351 | .arg( mActiveView->caption() ); | 358 | .arg( mActiveView->caption() ); |
352 | QString caption = i18n( "Confirm Delete" ); | 359 | QString caption = i18n( "Confirm Delete" ); |
353 | 360 | ||
354 | 361 | ||
355 | if (QMessageBox::information( this, caption, | 362 | if (QMessageBox::information( this, caption, |
356 | text, | 363 | text, |
357 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) | 364 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) |
358 | { | 365 | { |
359 | mViewNameList.remove( mActiveView->caption() ); | 366 | mViewNameList.remove( mActiveView->caption() ); |
360 | 367 | ||
361 | // remove the view from the config file | 368 | // remove the view from the config file |
362 | KConfig *config = mCore->config(); | 369 | KConfig *config = mCore->config(); |
363 | config->deleteGroup( mActiveView->caption() ); | 370 | config->deleteGroup( mActiveView->caption() ); |
364 | 371 | ||
365 | mViewDict.remove( mActiveView->caption() ); | 372 | mViewDict.remove( mActiveView->caption() ); |
366 | mActiveView = 0; | 373 | mActiveView = 0; |
367 | 374 | ||
368 | // we are in an invalid state now, but that should be fixed after | 375 | // we are in an invalid state now, but that should be fixed after |
369 | // we emit the signal | 376 | // we emit the signal |
370 | mActionSelectView->setItems( mViewNameList ); | 377 | mActionSelectView->setItems( mViewNameList ); |
371 | if ( mViewNameList.count() > 0 ) { | 378 | if ( mViewNameList.count() > 0 ) { |
372 | mActionSelectView->setCurrentItem( 0 ); | 379 | mActionSelectView->setCurrentItem( 0 ); |
373 | setActiveView( mViewNameList[ 0 ] ); | 380 | setActiveView( mViewNameList[ 0 ] ); |
374 | } | 381 | } |
375 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 382 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
376 | } | 383 | } |
377 | } | 384 | } |
378 | 385 | ||
379 | void ViewManager::addView() | 386 | void ViewManager::addView() |
380 | { | 387 | { |
381 | AddViewDialog dialog( &mViewFactoryDict, this ); | 388 | AddViewDialog dialog( &mViewFactoryDict, this ); |
382 | 389 | ||
383 | if ( dialog.exec() ) { | 390 | if ( dialog.exec() ) { |
384 | QString newName = dialog.viewName(); | 391 | QString newName = dialog.viewName(); |
385 | QString type = dialog.viewType(); | 392 | QString type = dialog.viewType(); |
386 | 393 | ||
387 | // Check for name conflicts | 394 | // Check for name conflicts |
388 | bool firstConflict = true; | 395 | bool firstConflict = true; |
389 | int numTries = 1; | 396 | int numTries = 1; |
390 | while ( mViewNameList.contains( newName ) > 0 ) { | 397 | while ( mViewNameList.contains( newName ) > 0 ) { |
391 | if ( !firstConflict ) { | 398 | if ( !firstConflict ) { |
392 | newName = newName.left( newName.length() - 4 ); | 399 | newName = newName.left( newName.length() - 4 ); |
393 | firstConflict = false; | 400 | firstConflict = false; |
394 | } | 401 | } |
395 | 402 | ||
396 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); | 403 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); |
397 | numTries++; | 404 | numTries++; |
398 | } | 405 | } |
399 | 406 | ||
400 | // Add the new one to the list | 407 | // Add the new one to the list |
401 | mViewNameList.append( newName ); | 408 | mViewNameList.append( newName ); |
402 | 409 | ||
403 | // write the view to the config file, | 410 | // write the view to the config file, |
404 | KConfig *config = mCore->config(); | 411 | KConfig *config = mCore->config(); |
405 | 412 | ||
406 | config->deleteGroup( newName ); | 413 | config->deleteGroup( newName ); |
407 | 414 | ||
408 | KConfigGroupSaver saver( config, newName ); | 415 | KConfigGroupSaver saver( config, newName ); |
409 | 416 | ||
410 | config->writeEntry( "Type", type ); | 417 | config->writeEntry( "Type", type ); |
411 | 418 | ||
412 | // try to set the active view | 419 | // try to set the active view |
413 | mActionSelectView->setItems( mViewNameList ); | 420 | mActionSelectView->setItems( mViewNameList ); |
414 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); | 421 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); |
415 | setActiveView( newName ); | 422 | setActiveView( newName ); |
416 | 423 | ||
417 | editView(); | 424 | editView(); |
418 | 425 | ||
419 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 426 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
420 | } | 427 | } |
421 | } | 428 | } |
422 | 429 | ||
423 | void ViewManager::createViewFactories() | 430 | void ViewManager::createViewFactories() |
424 | { | 431 | { |
425 | #ifndef KAB_EMBEDDED | 432 | #ifndef KAB_EMBEDDED |
426 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); | 433 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); |
427 | KTrader::OfferList::ConstIterator it; | 434 | KTrader::OfferList::ConstIterator it; |
428 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 435 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
429 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) | 436 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) |
430 | continue; | 437 | continue; |
431 | 438 | ||
432 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 439 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
433 | 440 | ||
434 | if ( !factory ) { | 441 | if ( !factory ) { |
435 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; | 442 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; |
436 | continue; | 443 | continue; |
437 | } | 444 | } |
438 | 445 | ||
439 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); | 446 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); |
440 | 447 | ||
441 | if ( !viewFactory ) { | 448 | if ( !viewFactory ) { |
442 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; | 449 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; |
443 | continue; | 450 | continue; |
444 | } | 451 | } |
445 | 452 | ||
446 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 453 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
447 | } | 454 | } |
448 | 455 | ||
449 | #else //KAB_EMBEDDED | 456 | #else //KAB_EMBEDDED |
450 | ViewFactory* viewFactory = new IconViewFactory(); | 457 | ViewFactory* viewFactory = new IconViewFactory(); |
451 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 458 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
452 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 459 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
453 | 460 | ||
454 | viewFactory = new TableViewFactory(); | 461 | viewFactory = new TableViewFactory(); |
455 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 462 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
456 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 463 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
457 | 464 | ||
458 | viewFactory = new CardViewFactory(); | 465 | viewFactory = new CardViewFactory(); |
459 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 466 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
460 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 467 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
461 | 468 | ||
462 | #endif //KAB_EMBEDDED | 469 | #endif //KAB_EMBEDDED |
463 | 470 | ||
464 | } | 471 | } |
465 | 472 | ||
466 | void ViewManager::dropped( QDropEvent *e ) | 473 | void ViewManager::dropped( QDropEvent *e ) |
467 | { | 474 | { |
468 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; | 475 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; |
469 | 476 | ||
470 | #ifndef KAB_EMBEDDED | 477 | #ifndef KAB_EMBEDDED |
471 | 478 | ||
472 | QString clipText, vcards; | 479 | QString clipText, vcards; |
473 | KURL::List urls; | 480 | KURL::List urls; |
474 | 481 | ||
475 | if ( KURLDrag::decode( e, urls) ) { | 482 | if ( KURLDrag::decode( e, urls) ) { |
476 | KURL::List::Iterator it = urls.begin(); | 483 | KURL::List::Iterator it = urls.begin(); |
477 | int c = urls.count(); | 484 | int c = urls.count(); |
478 | if ( c > 1 ) { | 485 | if ( c > 1 ) { |
479 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); | 486 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); |
480 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { | 487 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { |
481 | for ( ; it != urls.end(); ++it ) | 488 | for ( ; it != urls.end(); ++it ) |
482 | emit urlDropped( *it ); | 489 | emit urlDropped( *it ); |
483 | } | 490 | } |
484 | } else if ( c == 1 ) | 491 | } else if ( c == 1 ) |
485 | emit urlDropped( *it ); | 492 | emit urlDropped( *it ); |
486 | } else if ( KVCardDrag::decode( e, vcards ) ) { | 493 | } else if ( KVCardDrag::decode( e, vcards ) ) { |
487 | KABC::Addressee addr; | 494 | KABC::Addressee addr; |
488 | KABC::VCardConverter converter; | 495 | KABC::VCardConverter converter; |
489 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); | 496 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); |
490 | QStringList::Iterator it; | 497 | QStringList::Iterator it; |
491 | for ( it = list.begin(); it != list.end(); ++it ) { | 498 | for ( it = list.begin(); it != list.end(); ++it ) { |
492 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { | 499 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { |
493 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); | 500 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); |
494 | if ( a.isEmpty() ) { | 501 | if ( a.isEmpty() ) { |
495 | mCore->addressBook()->insertAddressee( addr ); | 502 | mCore->addressBook()->insertAddressee( addr ); |
496 | emit modified(); | 503 | emit modified(); |
497 | } | 504 | } |
498 | } | 505 | } |
499 | } | 506 | } |
500 | 507 | ||
501 | mActiveView->refresh(); | 508 | mActiveView->refresh(); |
502 | } | 509 | } |
503 | #else //KAB_EMBEDDED | 510 | #else //KAB_EMBEDDED |
504 | qDebug("ViewManager::dropped() has to be changed!!" ); | 511 | qDebug("ViewManager::dropped() has to be changed!!" ); |
505 | #endif //KAB_EMBEDDED | 512 | #endif //KAB_EMBEDDED |
506 | 513 | ||
507 | } | 514 | } |
508 | 515 | ||
509 | void ViewManager::startDrag() | 516 | void ViewManager::startDrag() |
510 | { | 517 | { |
511 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; | 518 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; |
512 | 519 | ||
513 | #ifndef KAB_EMBEDDED | 520 | #ifndef KAB_EMBEDDED |
514 | 521 | ||
515 | // Get the list of all the selected addressees | 522 | // Get the list of all the selected addressees |
516 | KABC::Addressee::List addrList; | 523 | KABC::Addressee::List addrList; |
517 | QStringList uidList = selectedUids(); | 524 | QStringList uidList = selectedUids(); |
518 | QStringList::Iterator iter; | 525 | QStringList::Iterator iter; |
519 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) | 526 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) |
520 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); | 527 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); |
521 | 528 | ||
522 | KMultipleDrag *drag = new KMultipleDrag( this ); | 529 | KMultipleDrag *drag = new KMultipleDrag( this ); |
523 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); | 530 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); |
524 | KABC::Addressee::List::Iterator it; | 531 | KABC::Addressee::List::Iterator it; |
525 | QStringList vcards; | 532 | QStringList vcards; |
526 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { | 533 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { |
527 | QString vcard = QString::null; | 534 | QString vcard = QString::null; |
528 | KABC::VCardConverter converter; | 535 | KABC::VCardConverter converter; |
529 | if ( converter.addresseeToVCard( *it, vcard ) ) | 536 | if ( converter.addresseeToVCard( *it, vcard ) ) |
530 | vcards.append( vcard ); | 537 | vcards.append( vcard ); |
531 | } | 538 | } |
532 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); | 539 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); |
533 | 540 | ||
534 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); | 541 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); |
535 | drag->dragCopy(); | 542 | drag->dragCopy(); |
536 | 543 | ||
537 | #else //KAB_EMBEDDED | 544 | #else //KAB_EMBEDDED |
538 | qDebug("ViewManager::startDrag() has to be changed!!" ); | 545 | qDebug("ViewManager::startDrag() has to be changed!!" ); |
539 | #endif //KAB_EMBEDDED | 546 | #endif //KAB_EMBEDDED |
540 | 547 | ||
541 | } | 548 | } |
542 | 549 | ||
543 | void ViewManager::setActiveFilter( int index ) | 550 | void ViewManager::setActiveFilter( int index ) |
544 | { | 551 | { |
545 | Filter currentFilter; | 552 | Filter currentFilter; |
546 | 553 | ||
547 | if ( ( index - 1 ) < 0 ) | 554 | if ( ( index - 1 ) < 0 ) |
548 | currentFilter = Filter(); | 555 | currentFilter = Filter(); |
549 | else | 556 | else |
550 | currentFilter = mFilterList[ index - 1 ]; | 557 | currentFilter = mFilterList[ index - 1 ]; |
551 | 558 | ||
552 | // Check if we have a view. Since the filter combo is created before | 559 | // Check if we have a view. Since the filter combo is created before |
553 | // the view, this slot could be called before there is a valid view. | 560 | // the view, this slot could be called before there is a valid view. |
554 | if ( mActiveView ) { | 561 | if ( mActiveView ) { |
555 | mActiveView->setFilter( currentFilter ); | 562 | mActiveView->setFilter( currentFilter ); |
556 | mActiveView->refresh(); | 563 | mActiveView->refresh(); |
557 | emit selected( QString::null ); | 564 | emit selected( QString::null ); |
558 | } | 565 | } |
559 | } | 566 | } |
560 | 567 | ||
561 | void ViewManager::configureFilters() | 568 | void ViewManager::configureFilters() |
562 | { | 569 | { |
563 | FilterDialog dlg( this ); | 570 | FilterDialog dlg( this ); |
564 | 571 | ||
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index a18e87d..97c2275 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h | |||
@@ -1,152 +1,153 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef VIEWMANAGER_H | 24 | #ifndef VIEWMANAGER_H |
25 | #define VIEWMANAGER_H | 25 | #define VIEWMANAGER_H |
26 | 26 | ||
27 | #include <qwidget.h> | 27 | #include <qwidget.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <kaddressbookview.h> | 29 | #include <kaddressbookview.h> |
30 | #include <qdict.h> | 30 | #include <qdict.h> |
31 | 31 | ||
32 | class KAction; | 32 | class KAction; |
33 | class KSelectAction; | 33 | class KSelectAction; |
34 | 34 | ||
35 | class KABCore; | 35 | class KABCore; |
36 | class QWidgetStack; | 36 | class QWidgetStack; |
37 | class QDropEvent; | 37 | class QDropEvent; |
38 | 38 | ||
39 | namespace KABC { class AddressBook; } | 39 | namespace KABC { class AddressBook; } |
40 | 40 | ||
41 | /** | 41 | /** |
42 | The view manager manages the views and everything related to them. The | 42 | The view manager manages the views and everything related to them. The |
43 | manager will load the views at startup and display a view when told to | 43 | manager will load the views at startup and display a view when told to |
44 | make one active. | 44 | make one active. |
45 | 45 | ||
46 | The view manager will also create and manage all dialogs directly related to | 46 | The view manager will also create and manage all dialogs directly related to |
47 | views (ie: AddView, ConfigureView, DeleteView, etc). | 47 | views (ie: AddView, ConfigureView, DeleteView, etc). |
48 | */ | 48 | */ |
49 | class ViewManager : public QWidget | 49 | class ViewManager : public QWidget |
50 | { | 50 | { |
51 | Q_OBJECT | 51 | Q_OBJECT |
52 | public: | 52 | public: |
53 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); | 53 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); |
54 | ~ViewManager(); | 54 | ~ViewManager(); |
55 | 55 | ||
56 | void restoreSettings(); | 56 | void restoreSettings(); |
57 | void saveSettings(); | 57 | void saveSettings(); |
58 | 58 | ||
59 | void unloadViews(); | 59 | void unloadViews(); |
60 | KSelectAction * getFilterAction() { return mActionSelectFilter; } | 60 | KSelectAction * getFilterAction() { return mActionSelectFilter; } |
61 | 61 | ||
62 | QStringList selectedUids() const; | 62 | QStringList selectedUids() const; |
63 | QStringList selectedEmails() const; | 63 | QStringList selectedEmails() const; |
64 | KABC::Addressee::List selectedAddressees() const; | 64 | KABC::Addressee::List selectedAddressees() const; |
65 | void setListSelected(QStringList); | ||
65 | 66 | ||
66 | public slots: | 67 | public slots: |
67 | 68 | ||
68 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); | 69 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); |
69 | void setSelected( const QString &uid, bool); | 70 | void setSelected( const QString &uid, bool); |
70 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 71 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
71 | void setSelected(); | 72 | void setSelected(); |
72 | 73 | ||
73 | 74 | ||
74 | 75 | ||
75 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 76 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
76 | void refreshView(); | 77 | void refreshView(); |
77 | void refreshView( const QString &uid); | 78 | void refreshView( const QString &uid); |
78 | 79 | ||
79 | void editView(); | 80 | void editView(); |
80 | void deleteView(); | 81 | void deleteView(); |
81 | void addView(); | 82 | void addView(); |
82 | 83 | ||
83 | protected slots: | 84 | protected slots: |
84 | /** | 85 | /** |
85 | Called whenever the user drops something in the active view. | 86 | Called whenever the user drops something in the active view. |
86 | This method will try to decode what was dropped, and if it was | 87 | This method will try to decode what was dropped, and if it was |
87 | a valid addressee, add it to the addressbook. | 88 | a valid addressee, add it to the addressbook. |
88 | */ | 89 | */ |
89 | void dropped( QDropEvent* ); | 90 | void dropped( QDropEvent* ); |
90 | 91 | ||
91 | /** | 92 | /** |
92 | Called whenever the user attempts to start a drag in the view. | 93 | Called whenever the user attempts to start a drag in the view. |
93 | This method will convert all the selected addressees into text (vcard) | 94 | This method will convert all the selected addressees into text (vcard) |
94 | and create a drag object. | 95 | and create a drag object. |
95 | */ | 96 | */ |
96 | void startDrag(); | 97 | void startDrag(); |
97 | 98 | ||
98 | signals: | 99 | signals: |
99 | /** | 100 | /** |
100 | Emitted whenever the user selects an entry in the view. | 101 | Emitted whenever the user selects an entry in the view. |
101 | */ | 102 | */ |
102 | void selected( const QString &uid ); | 103 | void selected( const QString &uid ); |
103 | void deleteRequest( ); | 104 | void deleteRequest( ); |
104 | 105 | ||
105 | /** | 106 | /** |
106 | Emitted whenever the user activates an entry in the view. | 107 | Emitted whenever the user activates an entry in the view. |
107 | */ | 108 | */ |
108 | void executed( const QString &uid ); | 109 | void executed( const QString &uid ); |
109 | 110 | ||
110 | /** | 111 | /** |
111 | Emitted whenever the address book is modified in some way. | 112 | Emitted whenever the address book is modified in some way. |
112 | */ | 113 | */ |
113 | void modified(); | 114 | void modified(); |
114 | 115 | ||
115 | /** | 116 | /** |
116 | Emitted whenever a url is dragged on a view. | 117 | Emitted whenever a url is dragged on a view. |
117 | */ | 118 | */ |
118 | void urlDropped( const KURL& ); | 119 | void urlDropped( const KURL& ); |
119 | 120 | ||
120 | private slots: | 121 | private slots: |
121 | void setActiveView( const QString &name ); | 122 | void setActiveView( const QString &name ); |
122 | void setActiveFilter( int index ); | 123 | void setActiveFilter( int index ); |
123 | void configureFilters(); | 124 | void configureFilters(); |
124 | 125 | ||
125 | private: | 126 | private: |
126 | void createViewFactories(); | 127 | void createViewFactories(); |
127 | QStringList filterNames() const; | 128 | QStringList filterNames() const; |
128 | int filterPosition( const QString &name ) const; | 129 | int filterPosition( const QString &name ) const; |
129 | QStringList viewNames() const; | 130 | QStringList viewNames() const; |
130 | int viewPosition( const QString &name ) const; | 131 | int viewPosition( const QString &name ) const; |
131 | void initActions(); | 132 | void initActions(); |
132 | void initGUI(); | 133 | void initGUI(); |
133 | 134 | ||
134 | KABCore *mCore; | 135 | KABCore *mCore; |
135 | 136 | ||
136 | Filter mCurrentFilter; | 137 | Filter mCurrentFilter; |
137 | Filter::List mFilterList; | 138 | Filter::List mFilterList; |
138 | 139 | ||
139 | QDict<KAddressBookView> mViewDict; | 140 | QDict<KAddressBookView> mViewDict; |
140 | QDict<ViewFactory> mViewFactoryDict; | 141 | QDict<ViewFactory> mViewFactoryDict; |
141 | QStringList mViewNameList; | 142 | QStringList mViewNameList; |
142 | 143 | ||
143 | QWidgetStack *mViewWidgetStack; | 144 | QWidgetStack *mViewWidgetStack; |
144 | KAddressBookView *mActiveView; | 145 | KAddressBookView *mActiveView; |
145 | 146 | ||
146 | KAction *mActionDeleteView; | 147 | KAction *mActionDeleteView; |
147 | KSelectAction *mActionSelectFilter; | 148 | KSelectAction *mActionSelectFilter; |
148 | KSelectAction *mActionSelectView; | 149 | KSelectAction *mActionSelectView; |
149 | 150 | ||
150 | }; | 151 | }; |
151 | 152 | ||
152 | #endif | 153 | #endif |
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 66a3f0b..0847b64 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -1,382 +1,382 @@ | |||
1 | // $Id$ | 1 | // $Id$ |
2 | 2 | ||
3 | #include <qvbox.h> | 3 | #include <qvbox.h> |
4 | #include <qlistbox.h> | 4 | #include <qlistbox.h> |
5 | #include <qwidget.h> | 5 | #include <qwidget.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qimage.h> | 7 | #include <qimage.h> |
8 | #include <qcombobox.h> | 8 | #include <qcombobox.h> |
9 | #include <qapplication.h> | 9 | #include <qapplication.h> |
10 | #include <qdragobject.h> | 10 | #include <qdragobject.h> |
11 | #include <qevent.h> | 11 | #include <qevent.h> |
12 | #include <qurl.h> | 12 | #include <qurl.h> |
13 | #include <qpixmap.h> | 13 | #include <qpixmap.h> |
14 | 14 | ||
15 | #include <kabc/addressbook.h> | 15 | #include <kabc/addressbook.h> |
16 | #include <kapplication.h> | 16 | #include <kapplication.h> |
17 | #include <kconfig.h> | 17 | #include <kconfig.h> |
18 | #include <kcolorbutton.h> | 18 | #include <kcolorbutton.h> |
19 | #include <kdebug.h> | 19 | #include <kdebug.h> |
20 | #include <kglobal.h> | 20 | #include <kglobal.h> |
21 | #include <kiconloader.h> | 21 | #include <kiconloader.h> |
22 | #include <klineedit.h> | 22 | #include <klineedit.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kmessagebox.h> | 24 | #include <kmessagebox.h> |
25 | #include <kurl.h> | 25 | #include <kurl.h> |
26 | #include <kurlrequester.h> | 26 | #include <kurlrequester.h> |
27 | 27 | ||
28 | //US#include "configuretableviewdialog.h" | 28 | //US#include "configuretableviewdialog.h" |
29 | #include "contactlistview.h" | 29 | #include "contactlistview.h" |
30 | #include "kabprefs.h" | 30 | #include "kabprefs.h" |
31 | #include "undocmds.h" | 31 | #include "undocmds.h" |
32 | #include "viewmanager.h" | 32 | #include "viewmanager.h" |
33 | 33 | ||
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | 35 | ||
36 | 36 | ||
37 | #include "kaddressbooktableview.h" | 37 | #include "kaddressbooktableview.h" |
38 | 38 | ||
39 | 39 | ||
40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, | 40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, |
41 | QWidget *parent, const char *name ) | 41 | QWidget *parent, const char *name ) |
42 | : KAddressBookView( ab, parent, name ) | 42 | : KAddressBookView( ab, parent, name ) |
43 | { | 43 | { |
44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); | 44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); |
45 | 45 | ||
46 | // The list view will be created when the config is read. | 46 | // The list view will be created when the config is read. |
47 | mListView = 0; | 47 | mListView = 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | KAddressBookTableView::~KAddressBookTableView() | 50 | KAddressBookTableView::~KAddressBookTableView() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void KAddressBookTableView::reconstructListView() | 54 | void KAddressBookTableView::reconstructListView() |
55 | { | 55 | { |
56 | if (mListView) | 56 | if (mListView) |
57 | { | 57 | { |
58 | disconnect(mListView, SIGNAL(selectionChanged()), | 58 | disconnect(mListView, SIGNAL(selectionChanged()), |
59 | this, SLOT(addresseeSelected())); | 59 | this, SLOT(addresseeSelected())); |
60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), | 60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), |
61 | this, SLOT(addresseeExecuted(QListViewItem*))); | 61 | this, SLOT(addresseeExecuted(QListViewItem*))); |
62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
63 | this, SLOT(addresseeExecuted(QListViewItem*))); | 63 | this, SLOT(addresseeExecuted(QListViewItem*))); |
64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, | 64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, |
65 | SIGNAL(startDrag())); | 65 | SIGNAL(startDrag())); |
66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
67 | this, SLOT(addresseeExecuted(QListViewItem*))); | 67 | this, SLOT(addresseeExecuted(QListViewItem*))); |
68 | 68 | ||
69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
70 | SIGNAL(dropped(QDropEvent*))); | 70 | SIGNAL(dropped(QDropEvent*))); |
71 | delete mListView; | 71 | delete mListView; |
72 | } | 72 | } |
73 | 73 | ||
74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); | 74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); |
75 | 75 | ||
76 | // Add the columns | 76 | // Add the columns |
77 | KABC::Field::List fieldList = fields(); | 77 | KABC::Field::List fieldList = fields(); |
78 | KABC::Field::List::ConstIterator it; | 78 | KABC::Field::List::ConstIterator it; |
79 | 79 | ||
80 | int c = 0; | 80 | int c = 0; |
81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { | 81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { |
82 | mListView->addColumn( (*it)->label() ); | 82 | mListView->addColumn( (*it)->label() ); |
83 | mListView->setColumnWidthMode(c++, QListView::Manual); | 83 | mListView->setColumnWidthMode(c++, QListView::Manual); |
84 | //US | 84 | //US |
85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); | 85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); |
86 | } | 86 | } |
87 | 87 | ||
88 | connect(mListView, SIGNAL(selectionChanged()), | 88 | connect(mListView, SIGNAL(selectionChanged()), |
89 | this, SLOT(addresseeSelected())); | 89 | this, SLOT(addresseeSelected())); |
90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, | 90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, |
91 | SIGNAL(startDrag())); | 91 | SIGNAL(startDrag())); |
92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
93 | SIGNAL(dropped(QDropEvent*))); | 93 | SIGNAL(dropped(QDropEvent*))); |
94 | 94 | ||
95 | if (KABPrefs::instance()->mHonorSingleClick) | 95 | if (KABPrefs::instance()->mHonorSingleClick) |
96 | connect(mListView, SIGNAL(executed(QListViewItem*)), | 96 | connect(mListView, SIGNAL(executed(QListViewItem*)), |
97 | this, SLOT(addresseeExecuted(QListViewItem*))); | 97 | this, SLOT(addresseeExecuted(QListViewItem*))); |
98 | else | 98 | else |
99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
100 | this, SLOT(addresseeExecuted(QListViewItem*))); | 100 | this, SLOT(addresseeExecuted(QListViewItem*))); |
101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
102 | this, SLOT(addresseeExecuted(QListViewItem*))); | 102 | this, SLOT(addresseeExecuted(QListViewItem*))); |
103 | connect(mListView, SIGNAL(signalDelete()), | 103 | connect(mListView, SIGNAL(signalDelete()), |
104 | this, SLOT(addresseeDeleted())); | 104 | this, SLOT(addresseeDeleted())); |
105 | 105 | ||
106 | //US performceimprovement. Refresh is done from the outside | 106 | //US performceimprovement. Refresh is done from the outside |
107 | //US refresh(); | 107 | //US refresh(); |
108 | 108 | ||
109 | mListView->setSorting( 0, true ); | 109 | mListView->setSorting( 0, true ); |
110 | mainLayout->addWidget( mListView ); | 110 | mainLayout->addWidget( mListView ); |
111 | mainLayout->activate(); | 111 | mainLayout->activate(); |
112 | mListView->show(); | 112 | mListView->show(); |
113 | } | 113 | } |
114 | 114 | ||
115 | void KAddressBookTableView::writeConfig(KConfig *config) | 115 | void KAddressBookTableView::writeConfig(KConfig *config) |
116 | { | 116 | { |
117 | KAddressBookView::writeConfig(config); | 117 | KAddressBookView::writeConfig(config); |
118 | 118 | ||
119 | mListView->saveLayout(config, config->group()); | 119 | mListView->saveLayout(config, config->group()); |
120 | } | 120 | } |
121 | 121 | ||
122 | void KAddressBookTableView::readConfig(KConfig *config) | 122 | void KAddressBookTableView::readConfig(KConfig *config) |
123 | { | 123 | { |
124 | KAddressBookView::readConfig( config ); | 124 | KAddressBookView::readConfig( config ); |
125 | // The config could have changed the fields, so we need to reconstruct | ||
126 | // the listview. | ||
127 | reconstructListView(); | ||
125 | 128 | ||
126 | // costum colors? | 129 | // costum colors? |
127 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 130 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
128 | { | 131 | { |
129 | QPalette p( mListView->palette() ); | 132 | QPalette p( mListView->palette() ); |
130 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 133 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
131 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 134 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
132 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 135 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
133 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 136 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
134 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 137 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
135 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 138 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
136 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 139 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
137 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 140 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
138 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 141 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
139 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 142 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
140 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 143 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
141 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 144 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
142 | c = p.color(QPalette::Normal, QColorGroup::Base ); | 145 | c = p.color(QPalette::Normal, QColorGroup::Base ); |
143 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); | 146 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); |
144 | mListView->viewport()->setPalette( p ); | 147 | mListView->viewport()->setPalette( p ); |
145 | } | 148 | } |
146 | else | 149 | else |
147 | { | 150 | { |
148 | // needed if turned off during a session. | 151 | // needed if turned off during a session. |
149 | mListView->viewport()->setPalette( mListView->palette() ); | 152 | mListView->viewport()->setPalette( mListView->palette() ); |
150 | } | 153 | } |
151 | 154 | ||
152 | //custom fonts? | 155 | //custom fonts? |
153 | QFont f( font() ); | 156 | QFont f( font() ); |
154 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 157 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
155 | { | 158 | { |
156 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); | 159 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); |
157 | f.setBold( true ); | 160 | f.setBold( true ); |
158 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 161 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
159 | } | 162 | } |
160 | else | 163 | else |
161 | { | 164 | { |
162 | // mListView->setFont( f ); | 165 | // mListView->setFont( f ); |
163 | f.setBold( true ); | 166 | f.setBold( true ); |
164 | // mListView->setHeaderFont( f ); | 167 | // mListView->setHeaderFont( f ); |
165 | } | 168 | } |
166 | 169 | ||
167 | 170 | ||
168 | 171 | ||
169 | 172 | ||
170 | // The config could have changed the fields, so we need to reconstruct | ||
171 | // the listview. | ||
172 | reconstructListView(); | ||
173 | 173 | ||
174 | // Set the list view options | 174 | // Set the list view options |
175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
176 | true)); | 176 | true)); |
177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
179 | 179 | ||
180 | if (config->readBoolEntry("Background", false)) | 180 | if (config->readBoolEntry("Background", false)) |
181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
182 | 182 | ||
183 | // Restore the layout of the listview | 183 | // Restore the layout of the listview |
184 | mListView->restoreLayout(config, config->group()); | 184 | mListView->restoreLayout(config, config->group()); |
185 | } | 185 | } |
186 | 186 | ||
187 | void KAddressBookTableView::refresh(QString uid) | 187 | void KAddressBookTableView::refresh(QString uid) |
188 | { | 188 | { |
189 | // For now just repopulate. In reality this method should | 189 | // For now just repopulate. In reality this method should |
190 | // check the value of uid, and if valid iterate through | 190 | // check the value of uid, and if valid iterate through |
191 | // the listview to find the entry, then tell it to refresh. | 191 | // the listview to find the entry, then tell it to refresh. |
192 | 192 | ||
193 | if (uid.isNull()) { | 193 | if (uid.isNull()) { |
194 | // Clear the list view | 194 | // Clear the list view |
195 | QString currentUID, nextUID; | 195 | QString currentUID, nextUID; |
196 | #ifndef KAB_EMBEDDED | 196 | #ifndef KAB_EMBEDDED |
197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
198 | #else //KAB_EMBEDDED | 198 | #else //KAB_EMBEDDED |
199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
200 | #endif //KAB_EMBEDDED | 200 | #endif //KAB_EMBEDDED |
201 | 201 | ||
202 | if ( currentItem ) { | 202 | if ( currentItem ) { |
203 | #ifndef KAB_EMBEDDED | 203 | #ifndef KAB_EMBEDDED |
204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
205 | #else //KAB_EMBEDDED | 205 | #else //KAB_EMBEDDED |
206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
207 | #endif //KAB_EMBEDDED | 207 | #endif //KAB_EMBEDDED |
208 | if ( nextItem ) | 208 | if ( nextItem ) |
209 | nextUID = nextItem->addressee().uid(); | 209 | nextUID = nextItem->addressee().uid(); |
210 | currentUID = currentItem->addressee().uid(); | 210 | currentUID = currentItem->addressee().uid(); |
211 | } | 211 | } |
212 | 212 | ||
213 | mListView->clear(); | 213 | mListView->clear(); |
214 | 214 | ||
215 | currentItem = 0; | 215 | currentItem = 0; |
216 | KABC::Addressee::List addresseeList = addressees(); | 216 | KABC::Addressee::List addresseeList = addressees(); |
217 | KABC::Addressee::List::Iterator it; | 217 | KABC::Addressee::List::Iterator it; |
218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
220 | if ( (*it).uid() == currentUID ) | 220 | if ( (*it).uid() == currentUID ) |
221 | currentItem = item; | 221 | currentItem = item; |
222 | else if ( (*it).uid() == nextUID && !currentItem ) | 222 | else if ( (*it).uid() == nextUID && !currentItem ) |
223 | currentItem = item; | 223 | currentItem = item; |
224 | } | 224 | } |
225 | 225 | ||
226 | // Sometimes the background pixmap gets messed up when we add lots | 226 | // Sometimes the background pixmap gets messed up when we add lots |
227 | // of items. | 227 | // of items. |
228 | mListView->repaint(); | 228 | mListView->repaint(); |
229 | 229 | ||
230 | if ( currentItem ) { | 230 | if ( currentItem ) { |
231 | mListView->setCurrentItem( currentItem ); | 231 | mListView->setCurrentItem( currentItem ); |
232 | mListView->ensureItemVisible( currentItem ); | 232 | mListView->ensureItemVisible( currentItem ); |
233 | } | 233 | } |
234 | } else { | 234 | } else { |
235 | // Only need to update on entry. Iterate through and try to find it | 235 | // Only need to update on entry. Iterate through and try to find it |
236 | ContactListViewItem *ceItem; | 236 | ContactListViewItem *ceItem; |
237 | QListViewItemIterator it( mListView ); | 237 | QListViewItemIterator it( mListView ); |
238 | while ( it.current() ) { | 238 | while ( it.current() ) { |
239 | #ifndef KAB_EMBEDDED | 239 | #ifndef KAB_EMBEDDED |
240 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); | 240 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); |
241 | #else //KAB_EMBEDDED | 241 | #else //KAB_EMBEDDED |
242 | ceItem = (ContactListViewItem*)( it.current() ); | 242 | ceItem = (ContactListViewItem*)( it.current() ); |
243 | #endif //KAB_EMBEDDED | 243 | #endif //KAB_EMBEDDED |
244 | 244 | ||
245 | if ( ceItem && ceItem->addressee().uid() == uid ) { | 245 | if ( ceItem && ceItem->addressee().uid() == uid ) { |
246 | ceItem->refresh(); | 246 | ceItem->refresh(); |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | ++it; | 249 | ++it; |
250 | } | 250 | } |
251 | 251 | ||
252 | refresh( QString::null ); | 252 | refresh( QString::null ); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | QStringList KAddressBookTableView::selectedUids() | 256 | QStringList KAddressBookTableView::selectedUids() |
257 | { | 257 | { |
258 | QStringList uidList; | 258 | QStringList uidList; |
259 | QListViewItem *item; | 259 | QListViewItem *item; |
260 | ContactListViewItem *ceItem; | 260 | ContactListViewItem *ceItem; |
261 | 261 | ||
262 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 262 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
263 | { | 263 | { |
264 | if (mListView->isSelected( item )) | 264 | if (mListView->isSelected( item )) |
265 | { | 265 | { |
266 | #ifndef KAB_EMBEDDED | 266 | #ifndef KAB_EMBEDDED |
267 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 267 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
268 | #else //KAB_EMBEDDED | 268 | #else //KAB_EMBEDDED |
269 | ceItem = (ContactListViewItem*)(item); | 269 | ceItem = (ContactListViewItem*)(item); |
270 | #endif //KAB_EMBEDDED | 270 | #endif //KAB_EMBEDDED |
271 | 271 | ||
272 | if (ceItem != 0L) | 272 | if (ceItem != 0L) |
273 | uidList << ceItem->addressee().uid(); | 273 | uidList << ceItem->addressee().uid(); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | if ( uidList.count() == 0 ) | 276 | if ( uidList.count() == 0 ) |
277 | if ( mListView->currentItem() ) { | 277 | if ( mListView->currentItem() ) { |
278 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; | 278 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; |
279 | uidList << ceItem->addressee().uid(); | 279 | uidList << ceItem->addressee().uid(); |
280 | } | 280 | } |
281 | 281 | ||
282 | return uidList; | 282 | return uidList; |
283 | } | 283 | } |
284 | 284 | ||
285 | void KAddressBookTableView::setSelected(QString uid, bool selected) | 285 | void KAddressBookTableView::setSelected(QString uid, bool selected) |
286 | { | 286 | { |
287 | QListViewItem *item; | 287 | QListViewItem *item; |
288 | ContactListViewItem *ceItem; | 288 | ContactListViewItem *ceItem; |
289 | 289 | ||
290 | if (uid.isNull()) | 290 | if (uid.isNull()) |
291 | { | 291 | { |
292 | mListView->selectAll(selected); | 292 | mListView->selectAll(selected); |
293 | } | 293 | } |
294 | else | 294 | else |
295 | { | 295 | { |
296 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 296 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
297 | { | 297 | { |
298 | #ifndef KAB_EMBEDDED | 298 | #ifndef KAB_EMBEDDED |
299 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 299 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
300 | #else //KAB_EMBEDDED | 300 | #else //KAB_EMBEDDED |
301 | ceItem = (ContactListViewItem*)(item); | 301 | ceItem = (ContactListViewItem*)(item); |
302 | #endif //KAB_EMBEDDED | 302 | #endif //KAB_EMBEDDED |
303 | 303 | ||
304 | 304 | ||
305 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) | 305 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) |
306 | { | 306 | { |
307 | mListView->setSelected(item, selected); | 307 | mListView->setSelected(item, selected); |
308 | 308 | ||
309 | if (selected) | 309 | if (selected) |
310 | mListView->ensureItemVisible(item); | 310 | mListView->ensureItemVisible(item); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | void KAddressBookTableView::addresseeSelected() | 316 | void KAddressBookTableView::addresseeSelected() |
317 | { | 317 | { |
318 | // We need to try to find the first selected item. This might not be the | 318 | // We need to try to find the first selected item. This might not be the |
319 | // last selected item, but when QListView is in multiselection mode, | 319 | // last selected item, but when QListView is in multiselection mode, |
320 | // there is no way to figure out which one was | 320 | // there is no way to figure out which one was |
321 | // selected last. | 321 | // selected last. |
322 | QListViewItem *item; | 322 | QListViewItem *item; |
323 | bool found =false; | 323 | bool found =false; |
324 | for (item = mListView->firstChild(); item && !found; | 324 | for (item = mListView->firstChild(); item && !found; |
325 | item = item->nextSibling()) | 325 | item = item->nextSibling()) |
326 | { | 326 | { |
327 | if (item->isSelected()) | 327 | if (item->isSelected()) |
328 | { | 328 | { |
329 | found = true; | 329 | found = true; |
330 | #ifndef KAB_EMBEDDED | 330 | #ifndef KAB_EMBEDDED |
331 | ContactListViewItem *ceItem | 331 | ContactListViewItem *ceItem |
332 | = dynamic_cast<ContactListViewItem*>(item); | 332 | = dynamic_cast<ContactListViewItem*>(item); |
333 | #else //KAB_EMBEDDED | 333 | #else //KAB_EMBEDDED |
334 | ContactListViewItem *ceItem | 334 | ContactListViewItem *ceItem |
335 | = (ContactListViewItem*)(item); | 335 | = (ContactListViewItem*)(item); |
336 | #endif //KAB_EMBEDDED | 336 | #endif //KAB_EMBEDDED |
337 | 337 | ||
338 | if ( ceItem ) emit selected(ceItem->addressee().uid()); | 338 | if ( ceItem ) emit selected(ceItem->addressee().uid()); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | if (!found) | 342 | if (!found) |
343 | emit selected(QString::null); | 343 | emit selected(QString::null); |
344 | } | 344 | } |
345 | 345 | ||
346 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) | 346 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) |
347 | { | 347 | { |
348 | if (item) | 348 | if (item) |
349 | { | 349 | { |
350 | #ifndef KAB_EMBEDDED | 350 | #ifndef KAB_EMBEDDED |
351 | ContactListViewItem *ceItem | 351 | ContactListViewItem *ceItem |
352 | = dynamic_cast<ContactListViewItem*>(item); | 352 | = dynamic_cast<ContactListViewItem*>(item); |
353 | #else //KAB_EMBEDDED | 353 | #else //KAB_EMBEDDED |
354 | ContactListViewItem *ceItem | 354 | ContactListViewItem *ceItem |
355 | = (ContactListViewItem*)(item); | 355 | = (ContactListViewItem*)(item); |
356 | #endif //KAB_EMBEDDED | 356 | #endif //KAB_EMBEDDED |
357 | 357 | ||
358 | if (ceItem) | 358 | if (ceItem) |
359 | { | 359 | { |
360 | emit executed(ceItem->addressee().uid()); | 360 | emit executed(ceItem->addressee().uid()); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | else | 363 | else |
364 | { | 364 | { |
365 | emit executed(QString::null); | 365 | emit executed(QString::null); |
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | void KAddressBookTableView::addresseeDeleted() | 369 | void KAddressBookTableView::addresseeDeleted() |
370 | { | 370 | { |
371 | 371 | ||
372 | emit deleteRequest(); | 372 | emit deleteRequest(); |
373 | 373 | ||
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | 377 | ||
378 | 378 | ||
379 | 379 | ||
380 | #ifndef KAB_EMBEDDED | 380 | #ifndef KAB_EMBEDDED |
381 | #include "kaddressbooktableview.moc" | 381 | #include "kaddressbooktableview.moc" |
382 | #endif //KAB_EMBEDDED | 382 | #endif //KAB_EMBEDDED |