summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-22 18:54:01 (UTC)
committer zautrix <zautrix>2005-04-22 18:54:01 (UTC)
commit3fa082fb01716c63546df5d753c1b677e54c59ce (patch) (unidiff)
treef19e79e515174aab2cea0e8016eb9aa59bcc5095
parente6feb1ca0c45397ba7b922198c87fe9b95b7d872 (diff)
downloadkdepimpi-3fa082fb01716c63546df5d753c1b677e54c59ce.zip
kdepimpi-3fa082fb01716c63546df5d753c1b677e54c59ce.tar.gz
kdepimpi-3fa082fb01716c63546df5d753c1b677e54c59ce.tar.bz2
fixxx
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/incsearchwidget.cpp1
-rw-r--r--kaddressbook/kabcore.cpp19
-rw-r--r--kaddressbook/mainembedded.cpp26
-rw-r--r--kaddressbook/viewmanager.cpp4
4 files changed, 27 insertions, 23 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
index 7577079..b1ffe04 100644
--- a/kaddressbook/incsearchwidget.cpp
+++ b/kaddressbook/incsearchwidget.cpp
@@ -1,177 +1,178 @@
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 <qapplication.h> 27#include <qapplication.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29 29
30#include <kdialog.h> 30#include <kdialog.h>
31#include <klineedit.h> 31#include <klineedit.h>
32#include <klocale.h> 32#include <klocale.h>
33#include <kglobal.h> 33#include <kglobal.h>
34#include <kglobal.h> 34#include <kglobal.h>
35#include "kabprefs.h" 35#include "kabprefs.h"
36 36
37#include "incsearchwidget.h" 37#include "incsearchwidget.h"
38 38
39IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) 39IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
40 : QWidget( parent, name ) 40 : QWidget( parent, name )
41{ 41{
42#ifndef KAB_EMBEDDED 42#ifndef KAB_EMBEDDED
43//US setCaption( i18n( "Incremental Search" ) ); 43//US setCaption( i18n( "Incremental Search" ) );
44#endif //KAB_EMBEDDED 44#endif //KAB_EMBEDDED
45 45
46 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); 46 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
47 47
48#ifdef DESKTOP_VERSION 48#ifdef DESKTOP_VERSION
49 QLabel *label = new QLabel( i18n( "Search:" ), this ); 49 QLabel *label = new QLabel( i18n( "Search:" ), this );
50 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); 50 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
51 layout->addWidget( label ); 51 layout->addWidget( label );
52#endif //KAB_EMBEDDED 52#endif //KAB_EMBEDDED
53 53
54 mSearchText = new KLineEdit( this ); 54 mSearchText = new KLineEdit( this );
55 layout->addWidget( mSearchText ); 55 layout->addWidget( mSearchText );
56// #ifdef KAB_EMBEDDED 56// #ifdef KAB_EMBEDDED
57// if (KGlobal::getOrientation() == KGlobal::Portrait) 57// if (KGlobal::getOrientation() == KGlobal::Portrait)
58// mSearchText->setMaximumWidth(30); 58// mSearchText->setMaximumWidth(30);
59// #endif //KAB_EMBEDDED 59// #endif //KAB_EMBEDDED
60 //mSearchText->setMaximumWidth(60); 60 //mSearchText->setMaximumWidth(60);
61 61
62 62
63 mFieldCombo = new QComboBox( false, this ); 63 mFieldCombo = new QComboBox( false, this );
64 layout->addWidget( mFieldCombo ); 64 layout->addWidget( mFieldCombo );
65 mFieldCombo->setMaximumHeight( 34 ); 65 mFieldCombo->setMaximumHeight( 34 );
66 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); 66 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
67 67
68// #ifndef KAB_EMBEDDED 68// #ifndef KAB_EMBEDDED
69// resize( QSize(420, 50).expandedTo( sizeHint() ) ); 69// resize( QSize(420, 50).expandedTo( sizeHint() ) );
70// #else //KAB_EMBEDDED 70// #else //KAB_EMBEDDED
71// resize( QSize(30, 10).expandedTo( sizeHint() ) ); 71// resize( QSize(30, 10).expandedTo( sizeHint() ) );
72// #endif //KAB_EMBEDDED 72// #endif //KAB_EMBEDDED
73 73
74 74
75 // for performance reasons, we do a search on the pda only after return is pressed 75 // for performance reasons, we do a search on the pda only after return is pressed
76 connect( mSearchText, SIGNAL( textChanged( const QString& ) ), 76 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
77 SLOT( announceDoSearch2() ) ); 77 SLOT( announceDoSearch2() ) );
78 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 78 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
79 SLOT( announceDoSearch2() ) ); 79 SLOT( announceDoSearch2() ) );
80 80
81 connect( mSearchText, SIGNAL( returnPressed() ), 81 connect( mSearchText, SIGNAL( returnPressed() ),
82 SLOT( announceDoSearch() ) ); 82 SLOT( announceDoSearch() ) );
83 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 83 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
84 SLOT( announceFieldChanged() ) ); 84 SLOT( announceFieldChanged() ) );
85 85
86 86
87 87
88 connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); 88 connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() ));
89 connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); 89 connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() ));
90 90
91 91
92 setFocusProxy( mSearchText ); 92 setFocusProxy( mSearchText );
93} 93}
94 94
95IncSearchWidget::~IncSearchWidget() 95IncSearchWidget::~IncSearchWidget()
96{ 96{
97 97
98} 98}
99void IncSearchWidget::announceDoSearch2() 99void IncSearchWidget::announceDoSearch2()
100{ 100{
101 if ( KABPrefs::instance()->mSearchWithReturn ) 101 if ( KABPrefs::instance()->mSearchWithReturn )
102 return; 102 return;
103 emit doSearch( mSearchText->text() ); 103 emit doSearch( mSearchText->text() );
104 //qDebug("emit dosreach "); 104 //qDebug("emit dosreach ");
105} 105}
106 106
107void IncSearchWidget::announceDoSearch() 107void IncSearchWidget::announceDoSearch()
108{ 108{
109 109
110 emit doSearch( mSearchText->text() ); 110 emit doSearch( mSearchText->text() );
111 // qDebug("emit dosreach "); 111 // qDebug("emit dosreach ");
112} 112}
113 113
114void IncSearchWidget::announceFieldChanged() 114void IncSearchWidget::announceFieldChanged()
115{ 115{
116 emit fieldChanged(); 116 emit fieldChanged();
117} 117}
118void IncSearchWidget::setSize() 118void IncSearchWidget::setSize()
119{ 119{
120 if ( KABPrefs::instance()->mHideSearchOnSwitch && QApplication::desktop()->width() == 480) { 120 if ( KABPrefs::instance()->mHideSearchOnSwitch && QApplication::desktop()->width() == 480) {
121 mFieldCombo->setMaximumWidth( 40 ); 121 mFieldCombo->setMaximumWidth( 40 );
122 mSearchText->setMaximumWidth( 30 ); 122 mSearchText->setMaximumWidth( 30 );
123 } else { 123 } else {
124 QFontMetrics fm ( mFieldCombo->font() ); 124 QFontMetrics fm ( mFieldCombo->font() );
125 int wid = fm.width(i18n( "All Fields" ) ); 125 int wid = fm.width(i18n( "All Fields" ) );
126#ifdef DESKTOP_VERSION 126#ifdef DESKTOP_VERSION
127 mFieldCombo->setMinimumWidth( wid+60 );
127 wid = wid * 2; 128 wid = wid * 2;
128#endif 129#endif
129 mFieldCombo->setMaximumWidth( wid+60 ); 130 mFieldCombo->setMaximumWidth( wid+60 );
130 mSearchText->setMaximumWidth( 1024 ); 131 mSearchText->setMaximumWidth( 1024 );
131 } 132 }
132} 133}
133void IncSearchWidget::setFields( const KABC::Field::List &list ) 134void IncSearchWidget::setFields( const KABC::Field::List &list )
134{ 135{
135 136
136 mFieldCombo->clear(); 137 mFieldCombo->clear();
137 mFieldCombo->insertItem( i18n( "All Fields" ) ); 138 mFieldCombo->insertItem( i18n( "All Fields" ) );
138 139
139 KABC::Field::List::ConstIterator it; 140 KABC::Field::List::ConstIterator it;
140 for ( it = list.begin(); it != list.end(); ++it ) { 141 for ( it = list.begin(); it != list.end(); ++it ) {
141 mFieldCombo->insertItem( (*it)->label() ); 142 mFieldCombo->insertItem( (*it)->label() );
142 } 143 }
143 144
144 mFieldList = list; 145 mFieldList = list;
145 146
146 announceDoSearch(); 147 announceDoSearch();
147 announceFieldChanged(); 148 announceFieldChanged();
148 setSize(); 149 setSize();
149} 150}
150 151
151KABC::Field::List IncSearchWidget::fields() const 152KABC::Field::List IncSearchWidget::fields() const
152{ 153{
153 return mFieldList; 154 return mFieldList;
154} 155}
155 156
156KABC::Field *IncSearchWidget::currentField()const 157KABC::Field *IncSearchWidget::currentField()const
157{ 158{
158 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) 159 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
159 return 0; // for error or 'use all fields' 160 return 0; // for error or 'use all fields'
160 else 161 else
161 return mFieldList[ mFieldCombo->currentItem() - 1 ]; 162 return mFieldList[ mFieldCombo->currentItem() - 1 ];
162} 163}
163 164
164void IncSearchWidget::setCurrentItem( int pos ) 165void IncSearchWidget::setCurrentItem( int pos )
165{ 166{
166 mFieldCombo->setCurrentItem( pos ); 167 mFieldCombo->setCurrentItem( pos );
167 announceFieldChanged(); 168 announceFieldChanged();
168} 169}
169 170
170int IncSearchWidget::currentItem() const 171int IncSearchWidget::currentItem() const
171{ 172{
172 173
173 return mFieldCombo->currentItem(); 174 return mFieldCombo->currentItem();
174} 175}
175#ifndef KAB_EMBEDDED 176#ifndef KAB_EMBEDDED
176#include "incsearchwidget.moc" 177#include "incsearchwidget.moc"
177#endif //KAB_EMBEDDED 178#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a4f3579..cba5850 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -396,402 +396,385 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
396 setModified( false ); 396 setModified( false );
397 mBRdisabled = false; 397 mBRdisabled = false;
398#ifndef DESKTOP_VERSION 398#ifndef DESKTOP_VERSION
399 infrared = 0; 399 infrared = 0;
400#endif 400#endif
401 //toggleBeamReceive( ); 401 //toggleBeamReceive( );
402 mMainWindow->toolBar()->show(); 402 mMainWindow->toolBar()->show();
403 // we have a toolbar repainting error on the Zaurus when starting KA/Pi 403 // we have a toolbar repainting error on the Zaurus when starting KA/Pi
404 QTimer::singleShot( 10, this , SLOT ( updateToolBar())); 404 QTimer::singleShot( 10, this , SLOT ( updateToolBar()));
405} 405}
406 406
407void KABCore::updateToolBar() 407void KABCore::updateToolBar()
408{ 408{
409 static int iii = 0; 409 static int iii = 0;
410 ++iii; 410 ++iii;
411 mMainWindow->toolBar()->repaintMe(); 411 mMainWindow->toolBar()->repaintMe();
412 if ( iii < 4 ) 412 if ( iii < 4 )
413 QTimer::singleShot( 100*iii, this , SLOT ( updateToolBar())); 413 QTimer::singleShot( 100*iii, this , SLOT ( updateToolBar()));
414} 414}
415KABCore::~KABCore() 415KABCore::~KABCore()
416{ 416{
417 // save(); 417 // save();
418 //saveSettings(); 418 //saveSettings();
419 //KABPrefs::instance()->writeConfig(); 419 //KABPrefs::instance()->writeConfig();
420 delete AddresseeConfig::instance(); 420 delete AddresseeConfig::instance();
421 mAddressBook = 0; 421 mAddressBook = 0;
422 KABC::StdAddressBook::close(); 422 KABC::StdAddressBook::close();
423 423
424 delete syncManager; 424 delete syncManager;
425#ifndef DESKTOP_VERSION 425#ifndef DESKTOP_VERSION
426 if ( infrared ) 426 if ( infrared )
427 delete infrared; 427 delete infrared;
428#endif 428#endif
429} 429}
430void KABCore::receive( const QCString& cmsg, const QByteArray& data ) 430void KABCore::receive( const QCString& cmsg, const QByteArray& data )
431{ 431{
432 //qDebug("KA: QCOP message received: %s ", cmsg.data() ); 432 //qDebug("KA: QCOP message received: %s ", cmsg.data() );
433 if ( cmsg == "setDocument(QString)" ) { 433 if ( cmsg == "setDocument(QString)" ) {
434 QDataStream stream( data, IO_ReadOnly ); 434 QDataStream stream( data, IO_ReadOnly );
435 QString fileName; 435 QString fileName;
436 stream >> fileName; 436 stream >> fileName;
437 recieve( fileName ); 437 recieve( fileName );
438 return; 438 return;
439 } 439 }
440} 440}
441void KABCore::toggleBeamReceive( ) 441void KABCore::toggleBeamReceive( )
442{ 442{
443 if ( mBRdisabled ) 443 if ( mBRdisabled )
444 return; 444 return;
445#ifndef DESKTOP_VERSION 445#ifndef DESKTOP_VERSION
446 if ( infrared ) { 446 if ( infrared ) {
447 qDebug("KA: AB disable BeamReceive "); 447 qDebug("KA: AB disable BeamReceive ");
448 delete infrared; 448 delete infrared;
449 infrared = 0; 449 infrared = 0;
450 mActionBR->setChecked(false); 450 mActionBR->setChecked(false);
451 return; 451 return;
452 } 452 }
453 qDebug("KA: AB enable BeamReceive "); 453 qDebug("KA: AB enable BeamReceive ");
454 mActionBR->setChecked(true); 454 mActionBR->setChecked(true);
455 455
456 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; 456 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ;
457 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); 457 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& )));
458#endif 458#endif
459} 459}
460 460
461 461
462void KABCore::disableBR(bool b) 462void KABCore::disableBR(bool b)
463{ 463{
464#ifndef DESKTOP_VERSION 464#ifndef DESKTOP_VERSION
465 if ( b ) { 465 if ( b ) {
466 if ( infrared ) { 466 if ( infrared ) {
467 toggleBeamReceive( ); 467 toggleBeamReceive( );
468 } 468 }
469 mBRdisabled = true; 469 mBRdisabled = true;
470 } else { 470 } else {
471 if ( mBRdisabled ) { 471 if ( mBRdisabled ) {
472 mBRdisabled = false; 472 mBRdisabled = false;
473 //toggleBeamReceive( ); 473 //toggleBeamReceive( );
474 } 474 }
475 } 475 }
476#endif 476#endif
477 477
478} 478}
479void KABCore::recieve( QString fn ) 479void KABCore::recieve( QString fn )
480{ 480{
481 //qDebug("KABCore::recieve "); 481 //qDebug("KABCore::recieve ");
482 int count = mAddressBook->importFromFile( fn, true ); 482 int count = mAddressBook->importFromFile( fn, true );
483 if ( count ) 483 if ( count )
484 setModified( true ); 484 setModified( true );
485 mViewManager->refreshView(); 485 mViewManager->refreshView();
486 message(i18n("%1 contact(s) received!").arg( count )); 486 message(i18n("%1 contact(s) received!").arg( count ));
487 topLevelWidget()->showMaximized(); 487 topLevelWidget()->showMaximized();
488 topLevelWidget()->raise(); 488 topLevelWidget()->raise();
489} 489}
490void KABCore::restoreSettings() 490void KABCore::restoreSettings()
491{ 491{
492 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 492 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
493 493
494 bool state; 494 bool state;
495 495
496 if (mMultipleViewsAtOnce) 496 if (mMultipleViewsAtOnce)
497 state = KABPrefs::instance()->mDetailsPageVisible; 497 state = KABPrefs::instance()->mDetailsPageVisible;
498 else 498 else
499 state = false; 499 state = false;
500 500
501 mActionDetails->setChecked( state ); 501 mActionDetails->setChecked( state );
502 setDetailsVisible( state ); 502 setDetailsVisible( state );
503 503
504 state = KABPrefs::instance()->mJumpButtonBarVisible; 504 state = KABPrefs::instance()->mJumpButtonBarVisible;
505 505
506 mActionJumpBar->setChecked( state ); 506 mActionJumpBar->setChecked( state );
507 setJumpButtonBarVisible( state ); 507 setJumpButtonBarVisible( state );
508/*US 508/*US
509 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 509 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
510 if ( splitterSize.count() == 0 ) { 510 if ( splitterSize.count() == 0 ) {
511 splitterSize.append( width() / 2 ); 511 splitterSize.append( width() / 2 );
512 splitterSize.append( width() / 2 ); 512 splitterSize.append( width() / 2 );
513 } 513 }
514 mMiniSplitter->setSizes( splitterSize ); 514 mMiniSplitter->setSizes( splitterSize );
515 if ( mExtensionBarSplitter ) { 515 if ( mExtensionBarSplitter ) {
516 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 516 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
517 if ( splitterSize.count() == 0 ) { 517 if ( splitterSize.count() == 0 ) {
518 splitterSize.append( width() / 2 ); 518 splitterSize.append( width() / 2 );
519 splitterSize.append( width() / 2 ); 519 splitterSize.append( width() / 2 );
520 } 520 }
521 mExtensionBarSplitter->setSizes( splitterSize ); 521 mExtensionBarSplitter->setSizes( splitterSize );
522 522
523 } 523 }
524*/ 524*/
525 mViewManager->restoreSettings(); 525 mViewManager->restoreSettings();
526 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 526 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
527 mExtensionManager->restoreSettings(); 527 mExtensionManager->restoreSettings();
528#ifdef DESKTOP_VERSION 528#ifdef DESKTOP_VERSION
529 int wid = width(); 529 int wid = width();
530 if ( wid < 10 ) 530 if ( wid < 10 )
531 wid = 400; 531 wid = 400;
532#else 532#else
533 int wid = QApplication::desktop()->width(); 533 int wid = QApplication::desktop()->width();
534 if ( wid < 640 ) 534 if ( wid < 640 )
535 wid = QApplication::desktop()->height(); 535 wid = QApplication::desktop()->height();
536#endif 536#endif
537 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 537 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
538 if ( true /*splitterSize.count() == 0*/ ) { 538 if ( true /*splitterSize.count() == 0*/ ) {
539 splitterSize.append( wid / 2 ); 539 splitterSize.append( wid / 2 );
540 splitterSize.append( wid / 2 ); 540 splitterSize.append( wid / 2 );
541 } 541 }
542 mMiniSplitter->setSizes( splitterSize ); 542 mMiniSplitter->setSizes( splitterSize );
543 if ( mExtensionBarSplitter ) { 543 if ( mExtensionBarSplitter ) {
544 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 544 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
545 if ( true /*splitterSize.count() == 0*/ ) { 545 if ( true /*splitterSize.count() == 0*/ ) {
546 splitterSize.append( wid / 2 ); 546 splitterSize.append( wid / 2 );
547 splitterSize.append( wid / 2 ); 547 splitterSize.append( wid / 2 );
548 } 548 }
549 mExtensionBarSplitter->setSizes( splitterSize ); 549 mExtensionBarSplitter->setSizes( splitterSize );
550 550
551 } 551 }
552#ifdef DESKTOP_VERSION 552#ifdef DESKTOP_VERSION
553 KConfig *config = KABPrefs::instance()->getConfig(); 553 KConfig *config = KABPrefs::instance()->getConfig();
554 config->setGroup("WidgetLayout"); 554 config->setGroup("WidgetLayout");
555 QStringList list; 555 QStringList list;
556 list = config->readListEntry("MainLayout"); 556 list = config->readListEntry("MainLayout");
557 int x,y,w,h; 557 int x,y,w,h;
558 if ( ! list.isEmpty() ) { 558 if ( ! list.isEmpty() ) {
559 x = list[0].toInt(); 559 x = list[0].toInt();
560 y = list[1].toInt(); 560 y = list[1].toInt();
561 w = list[2].toInt(); 561 w = list[2].toInt();
562 h = list[3].toInt(); 562 h = list[3].toInt();
563 KApplication::testCoords( &x,&y,&w,&h ); 563 KApplication::testCoords( &x,&y,&w,&h );
564 topLevelWidget()->setGeometry(x,y,w,h); 564 topLevelWidget()->setGeometry(x,y,w,h);
565 565
566 } else { 566 } else {
567 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 567 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
568 } 568 }
569#endif 569#endif
570} 570}
571 571
572void KABCore::saveSettings() 572void KABCore::saveSettings()
573{ 573{
574 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 574 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
575 if ( mExtensionBarSplitter ) 575 if ( mExtensionBarSplitter )
576 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 576 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
577 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 577 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
578 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 578 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
579#ifndef KAB_EMBEDDED 579#ifndef KAB_EMBEDDED
580 580
581 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 581 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
582 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 582 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
583#endif //KAB_EMBEDDED 583#endif //KAB_EMBEDDED
584 mExtensionManager->saveSettings(); 584 mExtensionManager->saveSettings();
585 mViewManager->saveSettings(); 585 mViewManager->saveSettings();
586 586
587 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 587 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
588#ifdef DESKTOP_VERSION 588
589 KConfig *config = KABPrefs::instance()->getConfig();
590 config->setGroup("WidgetLayout");
591 QStringList list ;//= config->readListEntry("MainLayout");
592 int x,y,w,h;
593 QWidget* wid;
594 wid = topLevelWidget();
595 x = wid->geometry().x();
596 y = wid->geometry().y();
597 w = wid->width();
598 h = wid->height();
599 list.clear();
600 list << QString::number( x );
601 list << QString::number( y );
602 list << QString::number( w );
603 list << QString::number( h );
604 config->writeEntry("MainLayout",list );
605#endif
606 KABPrefs::instance()->writeConfig(); 589 KABPrefs::instance()->writeConfig();
607 qDebug("KA: KABCore::saveSettings() "); 590 qDebug("KA: KABCore::saveSettings() ");
608} 591}
609 592
610KABC::AddressBook *KABCore::addressBook() const 593KABC::AddressBook *KABCore::addressBook() const
611{ 594{
612 return mAddressBook; 595 return mAddressBook;
613} 596}
614 597
615KConfig *KABCore::config() 598KConfig *KABCore::config()
616{ 599{
617#ifndef KAB_EMBEDDED 600#ifndef KAB_EMBEDDED
618 return KABPrefs::instance()->config(); 601 return KABPrefs::instance()->config();
619#else //KAB_EMBEDDED 602#else //KAB_EMBEDDED
620 return KABPrefs::instance()->getConfig(); 603 return KABPrefs::instance()->getConfig();
621#endif //KAB_EMBEDDED 604#endif //KAB_EMBEDDED
622} 605}
623 606
624KActionCollection *KABCore::actionCollection() const 607KActionCollection *KABCore::actionCollection() const
625{ 608{
626 return mGUIClient->actionCollection(); 609 return mGUIClient->actionCollection();
627} 610}
628 611
629KABC::Field *KABCore::currentSearchField() const 612KABC::Field *KABCore::currentSearchField() const
630{ 613{
631 if (mIncSearchWidget) 614 if (mIncSearchWidget)
632 return mIncSearchWidget->currentField(); 615 return mIncSearchWidget->currentField();
633 else 616 else
634 return 0; 617 return 0;
635} 618}
636 619
637QStringList KABCore::selectedUIDs() const 620QStringList KABCore::selectedUIDs() const
638{ 621{
639 return mViewManager->selectedUids(); 622 return mViewManager->selectedUids();
640} 623}
641 624
642KABC::Resource *KABCore::requestResource( QWidget *parent ) 625KABC::Resource *KABCore::requestResource( QWidget *parent )
643{ 626{
644 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 627 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
645 628
646 QPtrList<KRES::Resource> kresResources; 629 QPtrList<KRES::Resource> kresResources;
647 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 630 QPtrListIterator<KABC::Resource> resIt( kabcResources );
648 KABC::Resource *resource; 631 KABC::Resource *resource;
649 while ( ( resource = resIt.current() ) != 0 ) { 632 while ( ( resource = resIt.current() ) != 0 ) {
650 ++resIt; 633 ++resIt;
651 if ( !resource->readOnly() ) { 634 if ( !resource->readOnly() ) {
652 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 635 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
653 if ( res ) 636 if ( res )
654 kresResources.append( res ); 637 kresResources.append( res );
655 } 638 }
656 } 639 }
657 640
658 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 641 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
659 return static_cast<KABC::Resource*>( res ); 642 return static_cast<KABC::Resource*>( res );
660} 643}
661 644
662#ifndef KAB_EMBEDDED 645#ifndef KAB_EMBEDDED
663KAboutData *KABCore::createAboutData() 646KAboutData *KABCore::createAboutData()
664#else //KAB_EMBEDDED 647#else //KAB_EMBEDDED
665void KABCore::createAboutData() 648void KABCore::createAboutData()
666#endif //KAB_EMBEDDED 649#endif //KAB_EMBEDDED
667{ 650{
668 651
669 652
670 QString version; 653 QString version;
671#include <../version> 654#include <../version>
672 QMessageBox::about( this, "About KAddressbook/Pi", 655 QMessageBox::about( this, "About KAddressbook/Pi",
673 "KAddressbook/Platform-independent\n" 656 "KAddressbook/Platform-independent\n"
674 "(KA/Pi) " +version + " - " + 657 "(KA/Pi) " +version + " - " +
675#ifdef DESKTOP_VERSION 658#ifdef DESKTOP_VERSION
676 "Desktop Edition\n" 659 "Desktop Edition\n"
677#else 660#else
678 "PDA-Edition\n" 661 "PDA-Edition\n"
679 "for: Zaurus 5500 / 7x0 / 8x0\n" 662 "for: Zaurus 5500 / 7x0 / 8x0\n"
680#endif 663#endif
681 664
682 "(c) 2004 Ulf Schenk\n" 665 "(c) 2004 Ulf Schenk\n"
683 "(c) 2004-2005 Lutz Rogowski\nrogowski@kde.org\n" 666 "(c) 2004-2005 Lutz Rogowski\nrogowski@kde.org\n"
684 "(c) 1997-2003, The KDE PIM Team\n" 667 "(c) 1997-2003, The KDE PIM Team\n"
685 "Tobias Koenig Maintainer\n" 668 "Tobias Koenig Maintainer\n"
686 "Don Sanders Original author\n" 669 "Don Sanders Original author\n"
687 "Cornelius Schumacher Co-maintainer\n" 670 "Cornelius Schumacher Co-maintainer\n"
688 "Mike Pilone GUI and framework redesign\n" 671 "Mike Pilone GUI and framework redesign\n"
689 "Greg Stern DCOP interface\n" 672 "Greg Stern DCOP interface\n"
690 "Mark Westcot Contact pinning\n" 673 "Mark Westcot Contact pinning\n"
691 "Michel Boyer de la Giroday LDAP Lookup\n" 674 "Michel Boyer de la Giroday LDAP Lookup\n"
692 "Steffen Hansen LDAP Lookup" 675 "Steffen Hansen LDAP Lookup"
693#ifdef _WIN32_ 676#ifdef _WIN32_
694 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 677 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
695#endif 678#endif
696 ); 679 );
697} 680}
698 681
699void KABCore::setContactSelected( const QString &uid ) 682void KABCore::setContactSelected( const QString &uid )
700{ 683{
701 KABC::Addressee addr = mAddressBook->findByUid( uid ); 684 KABC::Addressee addr = mAddressBook->findByUid( uid );
702 if ( !mDetails->isHidden() ) 685 if ( !mDetails->isHidden() )
703 mDetails->setAddressee( addr ); 686 mDetails->setAddressee( addr );
704 687
705 if ( !addr.isEmpty() ) { 688 if ( !addr.isEmpty() ) {
706 emit contactSelected( addr.formattedName() ); 689 emit contactSelected( addr.formattedName() );
707 KABC::Picture pic = addr.photo(); 690 KABC::Picture pic = addr.photo();
708 if ( pic.isIntern() ) { 691 if ( pic.isIntern() ) {
709//US emit contactSelected( pic.data() ); 692//US emit contactSelected( pic.data() );
710//US instead use: 693//US instead use:
711 QPixmap px; 694 QPixmap px;
712 if (pic.data().isNull() != true) 695 if (pic.data().isNull() != true)
713 { 696 {
714 px.convertFromImage(pic.data()); 697 px.convertFromImage(pic.data());
715 } 698 }
716 699
717 emit contactSelected( px ); 700 emit contactSelected( px );
718 } 701 }
719 } 702 }
720 703
721 704
722 mExtensionManager->setSelectionChanged(); 705 mExtensionManager->setSelectionChanged();
723 706
724 // update the actions 707 // update the actions
725 bool selected = !uid.isEmpty(); 708 bool selected = !uid.isEmpty();
726 709
727 if ( mReadWrite ) { 710 if ( mReadWrite ) {
728 mActionCut->setEnabled( selected ); 711 mActionCut->setEnabled( selected );
729 mActionPaste->setEnabled( selected ); 712 mActionPaste->setEnabled( selected );
730 } 713 }
731 714
732 mActionCopy->setEnabled( selected ); 715 mActionCopy->setEnabled( selected );
733 mActionDelete->setEnabled( selected ); 716 mActionDelete->setEnabled( selected );
734 mActionEditAddressee->setEnabled( selected ); 717 mActionEditAddressee->setEnabled( selected );
735 mActionMail->setEnabled( selected ); 718 mActionMail->setEnabled( selected );
736 mActionMailVCard->setEnabled( selected ); 719 mActionMailVCard->setEnabled( selected );
737 //if (mActionBeam) 720 //if (mActionBeam)
738 //mActionBeam->setEnabled( selected ); 721 //mActionBeam->setEnabled( selected );
739 mActionWhoAmI->setEnabled( selected ); 722 mActionWhoAmI->setEnabled( selected );
740} 723}
741 724
742void KABCore::sendMail() 725void KABCore::sendMail()
743{ 726{
744 sendMail( mViewManager->selectedEmails().join( ", " ) ); 727 sendMail( mViewManager->selectedEmails().join( ", " ) );
745} 728}
746 729
747void KABCore::sendMail( const QString& emaillist ) 730void KABCore::sendMail( const QString& emaillist )
748{ 731{
749 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 732 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
750 if (emaillist.contains(",") > 0) 733 if (emaillist.contains(",") > 0)
751 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 734 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
752 else 735 else
753 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 736 ExternalAppHandler::instance()->mailToOneContact( emaillist );
754} 737}
755 738
756 739
757 740
758void KABCore::mailVCard() 741void KABCore::mailVCard()
759{ 742{
760 QStringList uids = mViewManager->selectedUids(); 743 QStringList uids = mViewManager->selectedUids();
761 if ( !uids.isEmpty() ) 744 if ( !uids.isEmpty() )
762 mailVCard( uids ); 745 mailVCard( uids );
763} 746}
764 747
765void KABCore::mailVCard( const QStringList& uids ) 748void KABCore::mailVCard( const QStringList& uids )
766{ 749{
767 QStringList urls; 750 QStringList urls;
768 751
769// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 752// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
770 753
771 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 754 QString dirName = "/tmp/" + KApplication::randomString( 8 );
772 755
773 756
774 757
775 QDir().mkdir( dirName, true ); 758 QDir().mkdir( dirName, true );
776 759
777 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 760 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
778 KABC::Addressee a = mAddressBook->findByUid( *it ); 761 KABC::Addressee a = mAddressBook->findByUid( *it );
779 762
780 if ( a.isEmpty() ) 763 if ( a.isEmpty() )
781 continue; 764 continue;
782 765
783 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 766 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
784 767
785 QString fileName = dirName + "/" + name; 768 QString fileName = dirName + "/" + name;
786 769
787 QFile outFile(fileName); 770 QFile outFile(fileName);
788 771
789 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 772 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
790 KABC::VCardConverter converter; 773 KABC::VCardConverter converter;
791 QString vcard; 774 QString vcard;
792 775
793 converter.addresseeToVCard( a, vcard ); 776 converter.addresseeToVCard( a, vcard );
794 777
795 QTextStream t( &outFile ); // use a text stream 778 QTextStream t( &outFile ); // use a text stream
796 t.setEncoding( QTextStream::UnicodeUTF8 ); 779 t.setEncoding( QTextStream::UnicodeUTF8 );
797 t << vcard; 780 t << vcard;
diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp
index 336e350..50db377 100644
--- a/kaddressbook/mainembedded.cpp
+++ b/kaddressbook/mainembedded.cpp
@@ -1,103 +1,119 @@
1#ifndef DESKTOP_VERSION 1#ifndef DESKTOP_VERSION
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qcopchannel_qws.h> 3#include <qcopchannel_qws.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#else 5#else
6#include <qapplication.h> 6#include <qapplication.h>
7#include <qwindowsstyle.h> 7#include <qwindowsstyle.h>
8#include <qplatinumstyle.h> 8#include <qplatinumstyle.h>
9#include <qmainwindow.h> 9#include <qmainwindow.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#endif 12#endif
13 13
14#include <qtextcodec.h> 14#include <qtextcodec.h>
15#include <kstandarddirs.h> 15#include <kstandarddirs.h>
16#include <qregexp.h> 16#include <qregexp.h>
17#include <kglobal.h> 17#include <kglobal.h>
18#include <stdio.h> 18#include <stdio.h>
19#include <qdir.h> 19#include <qdir.h>
20#include "kabprefs.h" 20#include "kabprefs.h"
21#include "kaddressbookmain.h" 21#include "kaddressbookmain.h"
22#include "externalapphandler.h" 22#include "externalapphandler.h"
23#include <libkdepim/kpimglobalprefs.h> 23#include <libkdepim/kpimglobalprefs.h>
24void dumpMissing(); 24void dumpMissing();
25int main( int argc, char **argv ) 25int main( int argc, char **argv )
26{ 26{
27#ifndef DESKTOP_VERSION 27#ifndef DESKTOP_VERSION
28 QPEApplication a( argc, argv ); 28 QPEApplication a( argc, argv );
29 a.setKeepRunning (); 29 a.setKeepRunning ();
30#else 30#else
31 QApplication a( argc, argv ); 31 QApplication a( argc, argv );
32 QApplication::setStyle( new QPlatinumStyle ()); 32 QApplication::setStyle( new QPlatinumStyle ());
33#ifdef _WIN32_ 33#ifdef _WIN32_
34 QString hdir ( getenv( "HOME") ); 34 QString hdir ( getenv( "HOME") );
35 if ( hdir.isEmpty() ) { 35 if ( hdir.isEmpty() ) {
36 QString hd ("C:/" ); 36 QString hd ("C:/" );
37 //QMessageBox::information(0,"hh",QDir::homeDirPath()+" xx" +hd ); 37 //QMessageBox::information(0,"hh",QDir::homeDirPath()+" xx" +hd );
38 if ( QDir::homeDirPath().lower() == hd.lower() ) { 38 if ( QDir::homeDirPath().lower() == hd.lower() ) {
39 _putenv( "HOME=C:"); 39 _putenv( "HOME=C:");
40 //QMessageBox::information(0,"hh",QString ( getenv( "HOME") ) ); 40 //QMessageBox::information(0,"hh",QString ( getenv( "HOME") ) );
41 } 41 }
42 } else { 42 } else {
43 QDir app_dir; 43 QDir app_dir;
44 if ( !app_dir.exists(hdir) ) 44 if ( !app_dir.exists(hdir) )
45 app_dir.mkdir (hdir); 45 app_dir.mkdir (hdir);
46 } 46 }
47#endif 47#endif
48#endif 48#endif
49 49
50 bool exitHelp = false; 50 bool exitHelp = false;
51 if ( argc > 1 ) { 51 if ( argc > 1 ) {
52 QString command = argv[1]; 52 QString command = argv[1];
53 if ( command == "-help" ){ 53 if ( command == "-help" ){
54 printf("KA/E command line commands:\n"); 54 printf("KA/E command line commands:\n");
55 printf(" no command: Start KA/E in usual way\n"); 55 printf(" no command: Start KA/E in usual way\n");
56 printf(" -help: This output\n"); 56 printf(" -help: This output\n");
57 printf(" KA/E is exiting now. Bye!\n"); 57 printf(" KA/E is exiting now. Bye!\n");
58 exitHelp = true; 58 exitHelp = true;
59 } 59 }
60 } 60 }
61 if ( ! exitHelp ) { 61 if ( ! exitHelp ) {
62 62
63 KGlobal::setAppName( "kaddressbook" ); 63 KGlobal::setAppName( "kaddressbook" );
64#ifndef DESKTOP_VERSION 64#ifndef DESKTOP_VERSION
65 if ( QApplication::desktop()->width() > 320 ) 65 if ( QApplication::desktop()->width() > 320 )
66 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons22/"); 66 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons22/");
67 else 67 else
68 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/"); 68 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/");
69#else 69#else
70 QString fileName ; 70 QString fileName ;
71 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons22/"; 71 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons22/";
72 KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName)); 72 KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName));
73 QApplication::addLibraryPath ( qApp->applicationDirPath () ); 73 QApplication::addLibraryPath ( qApp->applicationDirPath () );
74 74
75#endif 75#endif
76 KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook"))); 76 KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook")));
77 // init language 77 // init language
78 KPimGlobalPrefs::instance()->setGlobalConfig(); 78 KPimGlobalPrefs::instance()->setGlobalConfig();
79 QApplication::setFont( KPimGlobalPrefs::instance()->mApplicationFont ); 79 QApplication::setFont( KPimGlobalPrefs::instance()->mApplicationFont );
80 KAddressBookMain m ; 80 KAddressBookMain m ;
81//US MainWindow m; 81//US MainWindow m;
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); 83 QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
84#endif 84#endif
85 85
86 86
87#ifndef DESKTOP_VERSION 87#ifndef DESKTOP_VERSION
88 a.showMainWidget( &m ); 88 a.showMainWidget( &m );
89 89
90#else 90#else
91 a.setMainWidget( &m ); 91 a.setMainWidget( &m );
92 m.resize (640, 480 );
93 m.show(); 92 m.show();
94#endif 93#endif
95 a.exec(); 94 a.exec();
96 95#ifdef DESKTOP_VERSION
97 dumpMissing(); 96 KConfig *config = KABPrefs::instance()->getConfig();
98 97 config->setGroup("WidgetLayout");
99 KPimGlobalPrefs::instance()->writeConfig(); 98 QStringList list ;//= config->readListEntry("MainLayout");
99 int x,y,w,h;
100 QWidget* wid;
101 wid = &m;
102 x = wid->geometry().x();
103 y = wid->geometry().y();
104 w = wid->width();
105 h = wid->height();
106 list.clear();
107 list << QString::number( x );
108 list << QString::number( y );
109 list << QString::number( w );
110 list << QString::number( h );
111 config->writeEntry("MainLayout",list );
112#endif
113 dumpMissing();
114
115 KPimGlobalPrefs::instance()->writeConfig();
100 } 116 }
101 qDebug("KA: Bye! "); 117 qDebug("KA: Bye! ");
102} 118}
103 119
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index 0614d06..c738ad8 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -1,302 +1,304 @@
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/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (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 <qapplication.h> 63#include <qapplication.h>
64#include <qwidgetstack.h> 64#include <qwidgetstack.h>
65 65
66#include <kabc/addressbook.h> 66#include <kabc/addressbook.h>
67#include "filtereditdialog.h" 67#include "filtereditdialog.h"
68#include "addviewdialog.h" 68#include "addviewdialog.h"
69#include "kabcore.h" 69#include "kabcore.h"
70#include "kabprefs.h" 70#include "kabprefs.h"
71#include "viewmanager.h" 71#include "viewmanager.h"
72 72
73ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 73ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
74 : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) 74 : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
75{ 75{
76 initGUI(); 76 initGUI();
77 initActions(); 77 initActions();
78 78
79 mViewDict.setAutoDelete( true ); 79 mViewDict.setAutoDelete( true );
80 80
81 createViewFactories(); 81 createViewFactories();
82} 82}
83 83
84ViewManager::~ViewManager() 84ViewManager::~ViewManager()
85{ 85{
86 unloadViews(); 86 unloadViews();
87 mViewFactoryDict.clear(); 87 mViewFactoryDict.clear();
88} 88}
89void ViewManager::scrollUP() 89void ViewManager::scrollUP()
90{ 90{
91 if ( mActiveView ) 91 if ( mActiveView )
92 mActiveView->scrollUP(); 92 mActiveView->scrollUP();
93} 93}
94void ViewManager::scrollDOWN() 94void ViewManager::scrollDOWN()
95{ 95{
96 if ( mActiveView ) 96 if ( mActiveView )
97 mActiveView->scrollDOWN(); 97 mActiveView->scrollDOWN();
98} 98}
99void ViewManager::restoreSettings() 99void ViewManager::restoreSettings()
100{ 100{
101 mViewNameList = KABPrefs::instance()->mViewNames; 101 mViewNameList = KABPrefs::instance()->mViewNames;
102 QString activeViewName = KABPrefs::instance()->mCurrentView; 102 QString activeViewName = KABPrefs::instance()->mCurrentView;
103 103
104 mActionSelectView->setItems( mViewNameList ); 104 mActionSelectView->setItems( mViewNameList );
105 105
106 // Filter 106 // Filter
107 mFilterList = Filter::restore( mCore->config(), "Filter" ); 107 mFilterList = Filter::restore( mCore->config(), "Filter" );
108 mActionSelectFilter->setItems( filterNames() ); 108 mActionSelectFilter->setItems( filterNames() );
109 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); 109 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
110 int cw = 150; 110 int cw = 150;
111 if ( QApplication::desktop()->width() >= 800 )
112 cw = 200;
111 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) 113 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch)
112 cw = 0; 114 cw = 0;
113 mActionSelectFilter->setComboWidth( cw ); 115 mActionSelectFilter->setComboWidth( cw );
114 // Tell the views to reread their config, since they may have 116 // Tell the views to reread their config, since they may have
115 // been modified by global settings 117 // been modified by global settings
116 QString _oldgroup = mCore->config()->group(); 118 QString _oldgroup = mCore->config()->group();
117 119
118 QDictIterator<KAddressBookView> it( mViewDict ); 120 QDictIterator<KAddressBookView> it( mViewDict );
119 for ( it.toFirst(); it.current(); ++it ) { 121 for ( it.toFirst(); it.current(); ++it ) {
120 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 122 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
121 it.current()->readConfig( mCore->config() ); 123 it.current()->readConfig( mCore->config() );
122 } 124 }
123 setActiveView( activeViewName ); 125 setActiveView( activeViewName );
124 126
125 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 127 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
126} 128}
127 129
128void ViewManager::saveSettings() 130void ViewManager::saveSettings()
129{ 131{
130 QString _oldgroup = mCore->config()->group(); 132 QString _oldgroup = mCore->config()->group();
131 133
132 QDictIterator<KAddressBookView> it( mViewDict ); 134 QDictIterator<KAddressBookView> it( mViewDict );
133 for ( it.toFirst(); it.current(); ++it ) { 135 for ( it.toFirst(); it.current(); ++it ) {
134 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 136 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
135#ifdef DESKTOP_VERSION 137#ifdef DESKTOP_VERSION
136 (*it)->writeConfig( mCore->config() ); 138 (*it)->writeConfig( mCore->config() );
137#else 139#else
138 (*it).writeConfig( mCore->config() ); 140 (*it).writeConfig( mCore->config() );
139#endif 141#endif
140 } 142 }
141 143
142 Filter::save( mCore->config(), "Filter", mFilterList ); 144 Filter::save( mCore->config(), "Filter", mFilterList );
143 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 145 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
144 146
145 // write the view name list 147 // write the view name list
146 KABPrefs::instance()->mViewNames = mViewNameList; 148 KABPrefs::instance()->mViewNames = mViewNameList;
147 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 149 KABPrefs::instance()->mCurrentView = mActiveView->caption();
148 150
149} 151}
150 152
151QStringList ViewManager::selectedUids() const 153QStringList ViewManager::selectedUids() const
152{ 154{
153 if ( mActiveView ) 155 if ( mActiveView )
154 return mActiveView->selectedUids(); 156 return mActiveView->selectedUids();
155 else 157 else
156 return QStringList(); 158 return QStringList();
157} 159}
158 160
159QStringList ViewManager::selectedEmails() const 161QStringList ViewManager::selectedEmails() const
160{ 162{
161 if ( mActiveView ) 163 if ( mActiveView )
162 return mActiveView->selectedEmails(); 164 return mActiveView->selectedEmails();
163 else 165 else
164 return QStringList(); 166 return QStringList();
165} 167}
166 168
167KABC::Addressee::List ViewManager::selectedAddressees() const 169KABC::Addressee::List ViewManager::selectedAddressees() const
168{ 170{
169 KABC::Addressee::List list; 171 KABC::Addressee::List list;
170 if ( mActiveView ) { 172 if ( mActiveView ) {
171 QStringList uids = mActiveView->selectedUids(); 173 QStringList uids = mActiveView->selectedUids();
172 QStringList::Iterator it; 174 QStringList::Iterator it;
173 for ( it = uids.begin(); it != uids.end(); ++it ) { 175 for ( it = uids.begin(); it != uids.end(); ++it ) {
174 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 176 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
175 if ( !addr.isEmpty() ) 177 if ( !addr.isEmpty() )
176 list.append( addr ); 178 list.append( addr );
177 } 179 }
178 } 180 }
179 181
180 return list; 182 return list;
181} 183}
182//US added another method with no parameter, since my moc compiler does not support default parameters. 184//US added another method with no parameter, since my moc compiler does not support default parameters.
183void ViewManager::setSelected() 185void ViewManager::setSelected()
184{ 186{
185 setSelected( QString::null, true ); 187 setSelected( QString::null, true );
186} 188}
187 189
188void ViewManager::setSelected( const QString &uid, bool selected ) 190void ViewManager::setSelected( const QString &uid, bool selected )
189{ 191{
190 if ( mActiveView ) 192 if ( mActiveView )
191 mActiveView->setSelected( uid, selected ); 193 mActiveView->setSelected( uid, selected );
192} 194}
193 195
194void ViewManager::setListSelected(QStringList list) 196void ViewManager::setListSelected(QStringList list)
195{ 197{
196 int i, count = list.count(); 198 int i, count = list.count();
197 for ( i = 0; i < count;++i ) 199 for ( i = 0; i < count;++i )
198 setSelected( list[i], true ); 200 setSelected( list[i], true );
199 201
200} 202}
201void ViewManager::unloadViews() 203void ViewManager::unloadViews()
202{ 204{
203 mViewDict.clear(); 205 mViewDict.clear();
204 mActiveView = 0; 206 mActiveView = 0;
205} 207}
206 208
207void ViewManager::selectView( const QString &name ) 209void ViewManager::selectView( const QString &name )
208{ 210{
209 setActiveView( name ); 211 setActiveView( name );
210 mCore->saveSettings(); 212 mCore->saveSettings();
211} 213}
212void ViewManager::setActiveView( const QString &name ) 214void ViewManager::setActiveView( const QString &name )
213{ 215{
214 KAddressBookView *view = 0; 216 KAddressBookView *view = 0;
215 217
216 // Check that this isn't the same as the current active view 218 // Check that this isn't the same as the current active view
217 if ( mActiveView && ( mActiveView->caption() == name ) ) 219 if ( mActiveView && ( mActiveView->caption() == name ) )
218 return; 220 return;
219 221
220 // At this point we know the view that should be active is not 222 // At this point we know the view that should be active is not
221 // currently active. We will try to find the new on in the list. If 223 // currently active. We will try to find the new on in the list. If
222 // we can't find it, it means it hasn't been instantiated, so we will 224 // we can't find it, it means it hasn't been instantiated, so we will
223 // create it on demand. 225 // create it on demand.
224 226
225 view = mViewDict.find( name ); 227 view = mViewDict.find( name );
226 228
227 // Check if we found the view. If we didn't, then we need to create it 229 // Check if we found the view. If we didn't, then we need to create it
228 if ( view == 0 ) { 230 if ( view == 0 ) {
229 KConfig *config = mCore->config(); 231 KConfig *config = mCore->config();
230 232
231 KConfigGroupSaver saver( config, name ); 233 KConfigGroupSaver saver( config, name );
232 234
233 QString type = config->readEntry( "Type", "Table" ); 235 QString type = config->readEntry( "Type", "Table" );
234 236
235 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 237 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
236 238
237 ViewFactory *factory = mViewFactoryDict.find( type ); 239 ViewFactory *factory = mViewFactoryDict.find( type );
238 if ( factory ) 240 if ( factory )
239 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 241 view = factory->view( mCore->addressBook(), mViewWidgetStack );
240 242
241 if ( view ) { 243 if ( view ) {
242 view->setCaption( name ); 244 view->setCaption( name );
243 mViewDict.insert( name, view ); 245 mViewDict.insert( name, view );
244//US my version needs an int as second parameter to addWidget 246//US my version needs an int as second parameter to addWidget
245 mViewWidgetStack->addWidget( view, -1 ); 247 mViewWidgetStack->addWidget( view, -1 );
246 view->readConfig( config ); 248 view->readConfig( config );
247 249
248 // The manager just relays the signals 250 // The manager just relays the signals
249 connect( view, SIGNAL( selected( const QString& ) ), 251 connect( view, SIGNAL( selected( const QString& ) ),
250 SIGNAL( selected( const QString & ) ) ); 252 SIGNAL( selected( const QString & ) ) );
251 connect( view, SIGNAL( executed( const QString& ) ), 253 connect( view, SIGNAL( executed( const QString& ) ),
252 SIGNAL( executed( const QString& ) ) ); 254 SIGNAL( executed( const QString& ) ) );
253 255
254 connect( view, SIGNAL( deleteRequest( ) ), 256 connect( view, SIGNAL( deleteRequest( ) ),
255 SIGNAL( deleteRequest( ) ) ); 257 SIGNAL( deleteRequest( ) ) );
256 258
257 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 259 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
258 connect( view, SIGNAL( dropped( QDropEvent* ) ), 260 connect( view, SIGNAL( dropped( QDropEvent* ) ),
259 SLOT( dropped( QDropEvent* ) ) ); 261 SLOT( dropped( QDropEvent* ) ) );
260 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 262 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
261 } 263 }
262 } 264 }
263 265
264 // If we found or created the view, raise it and refresh it 266 // If we found or created the view, raise it and refresh it
265 if ( view ) { 267 if ( view ) {
266 mActiveView = view; 268 mActiveView = view;
267 mViewWidgetStack->raiseWidget( view ); 269 mViewWidgetStack->raiseWidget( view );
268 // Set the proper filter in the view. By setting the combo 270 // Set the proper filter in the view. By setting the combo
269 // box, the activated slot will be called, which will push 271 // box, the activated slot will be called, which will push
270 // the filter to the view and refresh it. 272 // the filter to the view and refresh it.
271 273
272 if ( view->defaultFilterType() == KAddressBookView::None ) { 274 if ( view->defaultFilterType() == KAddressBookView::None ) {
273 275
274 mActionSelectFilter->setCurrentItem( 0 ); 276 mActionSelectFilter->setCurrentItem( 0 );
275 setActiveFilter( 0 ); 277 setActiveFilter( 0 );
276 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 278 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
277 setActiveFilter( mActionSelectFilter->currentItem() ); 279 setActiveFilter( mActionSelectFilter->currentItem() );
278 } else { 280 } else {
279 uint pos = filterPosition( view->defaultFilterName() ); 281 uint pos = filterPosition( view->defaultFilterName() );
280 mActionSelectFilter->setCurrentItem( pos ); 282 mActionSelectFilter->setCurrentItem( pos );
281 setActiveFilter( pos ); 283 setActiveFilter( pos );
282 } 284 }
283//US qDebug("ViewManager::setActiveView 6" ); 285//US qDebug("ViewManager::setActiveView 6" );
284 286
285 // Update the inc search widget to show the fields in the new active 287 // Update the inc search widget to show the fields in the new active
286 // view. 288 // view.
287 mCore->setSearchFields( mActiveView->fields() ); 289 mCore->setSearchFields( mActiveView->fields() );
288 290
289//US performance optimization. setActiveFilter calls also mActiveView->refresh() 291//US performance optimization. setActiveFilter calls also mActiveView->refresh()
290//US mActiveView->refresh(); 292//US mActiveView->refresh();
291 } 293 }
292 else 294 else
293 { 295 {
294 qDebug("ViewManager::setActiveView: unable to find view" ); 296 qDebug("ViewManager::setActiveView: unable to find view" );
295 } 297 }
296} 298}
297 299
298//US added another method with no parameter, since my moc compiler does not support default parameters. 300//US added another method with no parameter, since my moc compiler does not support default parameters.
299void ViewManager::refreshView() 301void ViewManager::refreshView()
300{ 302{
301 refreshView( QString::null ); 303 refreshView( QString::null );
302} 304}
@@ -415,323 +417,325 @@ void ViewManager::addView()
415 // Check for name conflicts 417 // Check for name conflicts
416 bool firstConflict = true; 418 bool firstConflict = true;
417 int numTries = 1; 419 int numTries = 1;
418 while ( mViewNameList.contains( newName ) > 0 ) { 420 while ( mViewNameList.contains( newName ) > 0 ) {
419 if ( !firstConflict ) { 421 if ( !firstConflict ) {
420 newName = newName.left( newName.length() - 4 ); 422 newName = newName.left( newName.length() - 4 );
421 firstConflict = false; 423 firstConflict = false;
422 } 424 }
423 425
424 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 426 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
425 numTries++; 427 numTries++;
426 } 428 }
427 429
428 // Add the new one to the list 430 // Add the new one to the list
429 mViewNameList.append( newName ); 431 mViewNameList.append( newName );
430 432
431 // write the view to the config file, 433 // write the view to the config file,
432 KConfig *config = mCore->config(); 434 KConfig *config = mCore->config();
433 435
434 config->deleteGroup( newName ); 436 config->deleteGroup( newName );
435 437
436 KConfigGroupSaver saver( config, newName ); 438 KConfigGroupSaver saver( config, newName );
437 439
438 config->writeEntry( "Type", type ); 440 config->writeEntry( "Type", type );
439 441
440 // try to set the active view 442 // try to set the active view
441 mActionSelectView->setItems( mViewNameList ); 443 mActionSelectView->setItems( mViewNameList );
442 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 444 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
443 setActiveView( newName ); 445 setActiveView( newName );
444 446
445 editView(); 447 editView();
446 448
447 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 449 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
448 } 450 }
449} 451}
450 452
451void ViewManager::createViewFactories() 453void ViewManager::createViewFactories()
452{ 454{
453#ifndef KAB_EMBEDDED 455#ifndef KAB_EMBEDDED
454 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 456 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
455 KTrader::OfferList::ConstIterator it; 457 KTrader::OfferList::ConstIterator it;
456 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 458 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
457 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 459 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
458 continue; 460 continue;
459 461
460 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 462 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
461 463
462 if ( !factory ) { 464 if ( !factory ) {
463 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 465 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
464 continue; 466 continue;
465 } 467 }
466 468
467 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); 469 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
468 470
469 if ( !viewFactory ) { 471 if ( !viewFactory ) {
470 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; 472 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
471 continue; 473 continue;
472 } 474 }
473 475
474 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 476 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
475 } 477 }
476 478
477#else //KAB_EMBEDDED 479#else //KAB_EMBEDDED
478 ViewFactory* viewFactory = new IconViewFactory(); 480 ViewFactory* viewFactory = new IconViewFactory();
479 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 481 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
480// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 482// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
481 483
482 viewFactory = new TableViewFactory(); 484 viewFactory = new TableViewFactory();
483 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 485 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
484// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 486// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
485 487
486 viewFactory = new CardViewFactory(); 488 viewFactory = new CardViewFactory();
487 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 489 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
488// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 490// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
489 491
490#endif //KAB_EMBEDDED 492#endif //KAB_EMBEDDED
491 493
492} 494}
493 495
494void ViewManager::dropped( QDropEvent *e ) 496void ViewManager::dropped( QDropEvent *e )
495{ 497{
496 498
497#ifndef KAB_EMBEDDED 499#ifndef KAB_EMBEDDED
498 500
499 QString clipText, vcards; 501 QString clipText, vcards;
500 KURL::List urls; 502 KURL::List urls;
501 503
502 if ( KURLDrag::decode( e, urls) ) { 504 if ( KURLDrag::decode( e, urls) ) {
503 KURL::List::Iterator it = urls.begin(); 505 KURL::List::Iterator it = urls.begin();
504 int c = urls.count(); 506 int c = urls.count();
505 if ( c > 1 ) { 507 if ( c > 1 ) {
506 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); 508 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
507 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { 509 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
508 for ( ; it != urls.end(); ++it ) 510 for ( ; it != urls.end(); ++it )
509 emit urlDropped( *it ); 511 emit urlDropped( *it );
510 } 512 }
511 } else if ( c == 1 ) 513 } else if ( c == 1 )
512 emit urlDropped( *it ); 514 emit urlDropped( *it );
513 } else if ( KVCardDrag::decode( e, vcards ) ) { 515 } else if ( KVCardDrag::decode( e, vcards ) ) {
514 KABC::Addressee addr; 516 KABC::Addressee addr;
515 KABC::VCardConverter converter; 517 KABC::VCardConverter converter;
516 QStringList list = QStringList::split( "\r\n\r\n", vcards ); 518 QStringList list = QStringList::split( "\r\n\r\n", vcards );
517 QStringList::Iterator it; 519 QStringList::Iterator it;
518 for ( it = list.begin(); it != list.end(); ++it ) { 520 for ( it = list.begin(); it != list.end(); ++it ) {
519 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { 521 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
520 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); 522 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
521 if ( a.isEmpty() ) { 523 if ( a.isEmpty() ) {
522 mCore->addressBook()->insertAddressee( addr ); 524 mCore->addressBook()->insertAddressee( addr );
523 emit modified(); 525 emit modified();
524 } 526 }
525 } 527 }
526 } 528 }
527 529
528 mActiveView->refresh(); 530 mActiveView->refresh();
529 } 531 }
530#else //KAB_EMBEDDED 532#else //KAB_EMBEDDED
531qDebug("ViewManager::dropped() has to be changed!!" ); 533qDebug("ViewManager::dropped() has to be changed!!" );
532#endif //KAB_EMBEDDED 534#endif //KAB_EMBEDDED
533 535
534} 536}
535 537
536void ViewManager::startDrag() 538void ViewManager::startDrag()
537{ 539{
538 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 540 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
539 541
540#ifndef KAB_EMBEDDED 542#ifndef KAB_EMBEDDED
541 543
542 // Get the list of all the selected addressees 544 // Get the list of all the selected addressees
543 KABC::Addressee::List addrList; 545 KABC::Addressee::List addrList;
544 QStringList uidList = selectedUids(); 546 QStringList uidList = selectedUids();
545 QStringList::Iterator iter; 547 QStringList::Iterator iter;
546 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 548 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
547 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 549 addrList.append( mCore->addressBook()->findByUid( *iter ) );
548 550
549 KMultipleDrag *drag = new KMultipleDrag( this ); 551 KMultipleDrag *drag = new KMultipleDrag( this );
550 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 552 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
551 KABC::Addressee::List::Iterator it; 553 KABC::Addressee::List::Iterator it;
552 QStringList vcards; 554 QStringList vcards;
553 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 555 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
554 QString vcard = QString::null; 556 QString vcard = QString::null;
555 KABC::VCardConverter converter; 557 KABC::VCardConverter converter;
556 if ( converter.addresseeToVCard( *it, vcard ) ) 558 if ( converter.addresseeToVCard( *it, vcard ) )
557 vcards.append( vcard ); 559 vcards.append( vcard );
558 } 560 }
559 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 561 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
560 562
561 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 563 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
562 drag->dragCopy(); 564 drag->dragCopy();
563 565
564#else //KAB_EMBEDDED 566#else //KAB_EMBEDDED
565qDebug("ViewManager::startDrag() has to be changed!!" ); 567qDebug("ViewManager::startDrag() has to be changed!!" );
566#endif //KAB_EMBEDDED 568#endif //KAB_EMBEDDED
567 569
568} 570}
569void ViewManager::doSearch( const QString& s,KABC::Field *field ) 571void ViewManager::doSearch( const QString& s,KABC::Field *field )
570{ 572{
571 if ( mActiveView ) 573 if ( mActiveView )
572 mActiveView->doSearch( s, field ); 574 mActiveView->doSearch( s, field );
573 575
574} 576}
575void ViewManager::setActiveFilter( int index ) 577void ViewManager::setActiveFilter( int index )
576{ 578{
577 Filter currentFilter; 579 Filter currentFilter;
578 580
579 if ( ( index - 1 ) < 0 ) 581 if ( ( index - 1 ) < 0 )
580 currentFilter = Filter(); 582 currentFilter = Filter();
581 else 583 else
582 currentFilter = mFilterList[ index - 1 ]; 584 currentFilter = mFilterList[ index - 1 ];
583 585
584 // Check if we have a view. Since the filter combo is created before 586 // Check if we have a view. Since the filter combo is created before
585 // the view, this slot could be called before there is a valid view. 587 // the view, this slot could be called before there is a valid view.
586 if ( mActiveView ) { 588 if ( mActiveView ) {
587 mActiveView->setFilter( currentFilter ); 589 mActiveView->setFilter( currentFilter );
588 mActiveView->refresh(); 590 mActiveView->refresh();
589 emit selected( QString::null ); 591 emit selected( QString::null );
590 } 592 }
591} 593}
592 594
593void ViewManager::configureFilters() 595void ViewManager::configureFilters()
594{ 596{
595 FilterDialog dlg( this ); 597 FilterDialog dlg( this );
596 598
597 dlg.setFilters( mFilterList ); 599 dlg.setFilters( mFilterList );
598 600
599 if ( dlg.exec() ) 601 if ( dlg.exec() )
600 mFilterList = dlg.filters(); 602 mFilterList = dlg.filters();
601 603
602 uint pos = mActionSelectFilter->currentItem(); 604 uint pos = mActionSelectFilter->currentItem();
603 mActionSelectFilter->setItems( filterNames() ); 605 mActionSelectFilter->setItems( filterNames() );
604 mActionSelectFilter->setCurrentItem( pos ); 606 mActionSelectFilter->setCurrentItem( pos );
605 setActiveFilter( pos ); 607 setActiveFilter( pos );
606 int cw = 150; 608 int cw = 150;
609 if ( QApplication::desktop()->width() >= 800 )
610 cw = 200;
607 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) 611 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch)
608 cw = 0; 612 cw = 0;
609 mActionSelectFilter->setComboWidth( cw ); 613 mActionSelectFilter->setComboWidth( cw );
610 saveSettings(); 614 saveSettings();
611} 615}
612 616
613QStringList ViewManager::filterNames() const 617QStringList ViewManager::filterNames() const
614{ 618{
615 QStringList names( i18n( "No Filter" ) ); 619 QStringList names( i18n( "No Filter" ) );
616 620
617 Filter::List::ConstIterator it; 621 Filter::List::ConstIterator it;
618 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 622 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
619 names.append( (*it).name() ); 623 names.append( (*it).name() );
620 624
621 return names; 625 return names;
622} 626}
623Filter ViewManager::getFilterByName( const QString &name ) const 627Filter ViewManager::getFilterByName( const QString &name ) const
624{ 628{
625 Filter::List::ConstIterator it; 629 Filter::List::ConstIterator it;
626 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 630 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
627 if ( name == (*it).name() ) 631 if ( name == (*it).name() )
628 return (*it); 632 return (*it);
629 633
630 return Filter(); 634 return Filter();
631} 635}
632 636
633int ViewManager::filterPosition( const QString &name ) const 637int ViewManager::filterPosition( const QString &name ) const
634{ 638{
635 int pos = 0; 639 int pos = 0;
636 640
637 Filter::List::ConstIterator it; 641 Filter::List::ConstIterator it;
638 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) 642 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
639 if ( name == (*it).name() ) 643 if ( name == (*it).name() )
640 return pos + 1; 644 return pos + 1;
641 645
642 return 0; 646 return 0;
643} 647}
644 648
645void ViewManager::initActions() 649void ViewManager::initActions()
646{ 650{
647//US <ActionList name="view_loadedviews"/> 651//US <ActionList name="view_loadedviews"/>
648//US <Separator/> 652//US <Separator/>
649 653
650#ifdef KAB_EMBEDDED 654#ifdef KAB_EMBEDDED
651 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); 655 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
652 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); 656 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
653 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); 657 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
654#endif //KAB_EMBEDDED 658#endif //KAB_EMBEDDED
655 659
656 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); 660 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
657#if KDE_VERSION >= 309 661#if KDE_VERSION >= 309
658 mActionSelectView->setMenuAccelsEnabled( false ); 662 mActionSelectView->setMenuAccelsEnabled( false );
659#endif 663#endif
660 connect( mActionSelectView, SIGNAL( activated( const QString& ) ), 664 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
661 SLOT( selectView( const QString& ) ) ); 665 SLOT( selectView( const QString& ) ) );
662 666
663 667
664#ifdef KAB_EMBEDDED 668#ifdef KAB_EMBEDDED
665 mActionSelectView->plug(viewmenu); 669 mActionSelectView->plug(viewmenu);
666 viewmenu->insertSeparator(); 670 viewmenu->insertSeparator();
667#endif //KAB_EMBEDDED 671#endif //KAB_EMBEDDED
668 672
669 KAction *action; 673 KAction *action;
670 674
671 action = new KAction( i18n( "Modify View..." ), "configure", 0, this, 675 action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
672 SLOT( editView() ), mCore->actionCollection(), "view_modify" ); 676 SLOT( editView() ), mCore->actionCollection(), "view_modify" );
673#ifndef KAB_EMBEDDED 677#ifndef KAB_EMBEDDED
674 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); 678 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) );
675#else //KAB_EMBEDDED 679#else //KAB_EMBEDDED
676 action->plug(viewmenu); 680 action->plug(viewmenu);
677#endif //KAB_EMBEDDED 681#endif //KAB_EMBEDDED
678 682
679 action = new KAction( i18n( "Add View..." ), "window_new", 0, this, 683 action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
680 SLOT( addView() ), mCore->actionCollection(), "view_add" ); 684 SLOT( addView() ), mCore->actionCollection(), "view_add" );
681#ifndef KAB_EMBEDDED 685#ifndef KAB_EMBEDDED
682 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); 686 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) );
683#else //KAB_EMBEDDED 687#else //KAB_EMBEDDED
684 action->plug(viewmenu); 688 action->plug(viewmenu);
685#endif //KAB_EMBEDDED 689#endif //KAB_EMBEDDED
686 690
687 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, 691 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
688 this, SLOT( deleteView() ), 692 this, SLOT( deleteView() ),
689 mCore->actionCollection(), "view_delete" ); 693 mCore->actionCollection(), "view_delete" );
690#ifndef KAB_EMBEDDED 694#ifndef KAB_EMBEDDED
691 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); 695 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
692#else //KAB_EMBEDDED 696#else //KAB_EMBEDDED
693 mActionDeleteView->plug(viewmenu); 697 mActionDeleteView->plug(viewmenu);
694 viewmenu->insertSeparator(); 698 viewmenu->insertSeparator();
695#endif //KAB_EMBEDDED 699#endif //KAB_EMBEDDED
696 700
697#ifndef KAB_EMBEDDED 701#ifndef KAB_EMBEDDED
698 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 702 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
699 SLOT( refreshView(const QString &) ), mCore->actionCollection(), 703 SLOT( refreshView(const QString &) ), mCore->actionCollection(),
700 "view_refresh" ); 704 "view_refresh" );
701 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); 705 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
702#else //KAB_EMBEDDED 706#else //KAB_EMBEDDED
703 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 707 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
704 SLOT( refreshView()), mCore->actionCollection(), 708 SLOT( refreshView()), mCore->actionCollection(),
705 "view_refresh" ); 709 "view_refresh" );
706 action->plug(viewmenu); 710 action->plug(viewmenu);
707 //viewmenu->insertSeparator(); 711 //viewmenu->insertSeparator();
708#endif //KAB_EMBEDDED 712#endif //KAB_EMBEDDED
709 713
710 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, 714 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
711 SLOT( configureFilters() ), mCore->actionCollection(), 715 SLOT( configureFilters() ), mCore->actionCollection(),
712 "options_edit_filters" ); 716 "options_edit_filters" );
713 717
714 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); 718 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
715#if KDE_VERSION >= 309 719#if KDE_VERSION >= 309
716 mActionSelectFilter->setMenuAccelsEnabled( false ); 720 mActionSelectFilter->setMenuAccelsEnabled( false );
717#endif 721#endif
718 connect( mActionSelectFilter, SIGNAL( activated( int ) ), 722 connect( mActionSelectFilter, SIGNAL( activated( int ) ),
719 SLOT( setActiveFilter( int ) ) ); 723 SLOT( setActiveFilter( int ) ) );
720 724
721#ifdef KAB_EMBEDDED 725#ifdef KAB_EMBEDDED
722 action->plug(settingsmenu); 726 action->plug(settingsmenu);
723 mActionSelectFilter->plug(viewmenu,0); 727 mActionSelectFilter->plug(viewmenu,0);
724#endif //KAB_EMBEDDED 728#endif //KAB_EMBEDDED
725 729
726} 730}
727 731
728void ViewManager::initGUI() 732void ViewManager::initGUI()
729{ 733{
730 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); 734 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 );
731 mViewWidgetStack = new QWidgetStack( this ); 735 mViewWidgetStack = new QWidgetStack( this );
732 layout->addWidget( mViewWidgetStack ); 736 layout->addWidget( mViewWidgetStack );
733} 737}
734 738
735#ifndef KAB_EMBEDDED 739#ifndef KAB_EMBEDDED
736#include "viewmanager.moc" 740#include "viewmanager.moc"
737#endif //KAB_EMBEDDED 741#endif //KAB_EMBEDDED