summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index b5d9419..5cfe3ad 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -37,44 +37,48 @@ $Id$
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 <q3popupmenu.h>
54//Added by qt3to4:
55#include <Q3HBoxLayout>
56#include <QDropEvent>
54#include <kconfigbase.h> 57#include <kconfigbase.h>
55 58
56#endif //KAB_EMBEDDED 59#endif //KAB_EMBEDDED
57 60
58 61
59#include <kdebug.h> 62#include <kdebug.h>
60#include <kactionclasses.h> 63#include <kactionclasses.h>
61 64
62#include <qlayout.h> 65#include <qlayout.h>
63#include <qapplication.h> 66#include <qapplication.h>
64#include <qwidgetstack.h> 67#include <QDesktopWidget>
68#include <q3widgetstack.h>
65 69
66#include <kabc/addressbook.h> 70#include <kabc/addressbook.h>
67#include "filtereditdialog.h" 71#include "filtereditdialog.h"
68#include "addviewdialog.h" 72#include "addviewdialog.h"
69#include "kabcore.h" 73#include "kabcore.h"
70#include "kabprefs.h" 74#include "kabprefs.h"
71#include "viewmanager.h" 75#include "viewmanager.h"
72 76
73ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 77ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
74 : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) 78 : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
75{ 79{
76 initGUI(); 80 initGUI();
77 initActions(); 81 initActions();
78 82
79 mViewDict.setAutoDelete( true ); 83 mViewDict.setAutoDelete( true );
80 84
@@ -104,77 +108,77 @@ void ViewManager::restoreSettings()
104 mActionSelectView->setItems( mViewNameList ); 108 mActionSelectView->setItems( mViewNameList );
105 109
106 // Filter 110 // Filter
107 mFilterList = Filter::restore( mCore->config(), "Filter" ); 111 mFilterList = Filter::restore( mCore->config(), "Filter" );
108 mActionSelectFilter->setItems( filterNames() ); 112 mActionSelectFilter->setItems( filterNames() );
109 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); 113 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
110 int cw = 150; 114 int cw = 150;
111 if ( QApplication::desktop()->width() >= 800 ) 115 if ( QApplication::desktop()->width() >= 800 )
112 cw = 200; 116 cw = 200;
113 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch) 117 if (QApplication::desktop()->width() == 480 && !KABPrefs::instance()->mHideSearchOnSwitch)
114 cw = 0; 118 cw = 0;
115 mActionSelectFilter->setComboWidth( cw ); 119 mActionSelectFilter->setComboWidth( cw );
116 // Tell the views to reread their config, since they may have 120 // Tell the views to reread their config, since they may have
117 // been modified by global settings 121 // been modified by global settings
118 QString _oldgroup = mCore->config()->group(); 122 QString _oldgroup = mCore->config()->group();
119 123
120 QDictIterator<KAddressBookView> it( mViewDict ); 124 Q3DictIterator<KAddressBookView> it( mViewDict );
121 for ( it.toFirst(); it.current(); ++it ) { 125 for ( it.toFirst(); it.current(); ++it ) {
122 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 126 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
123 it.current()->readConfig( mCore->config() ); 127 it.current()->readConfig( mCore->config() );
124 } 128 }
125 setActiveView( activeViewName ); 129 setActiveView( activeViewName );
126 130
127 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 131 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
128} 132}
129 133
130void ViewManager::saveSettings() 134void ViewManager::saveSettings()
131{ 135{
132 QString _oldgroup = mCore->config()->group(); 136 QString _oldgroup = mCore->config()->group();
133 137
134 QDictIterator<KAddressBookView> it( mViewDict ); 138 Q3DictIterator<KAddressBookView> it( mViewDict );
135 for ( it.toFirst(); it.current(); ++it ) { 139 for ( it.toFirst(); it.current(); ++it ) {
136 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 140 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
137#ifdef DESKTOP_VERSION 141#ifdef DESKTOP_VERSION
138 (*it)->writeConfig( mCore->config() ); 142 (*it)->writeConfig( mCore->config() );
139#else 143#else
140 (*it).writeConfig( mCore->config() ); 144 (*it).writeConfig( mCore->config() );
141#endif 145#endif
142 } 146 }
143 147
144 Filter::save( mCore->config(), "Filter", mFilterList ); 148 Filter::save( mCore->config(), "Filter", mFilterList );
145 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 149 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
146 150
147 // write the view name list 151 // write the view name list
148 KABPrefs::instance()->mViewNames = mViewNameList; 152 KABPrefs::instance()->mViewNames = mViewNameList;
149 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 153 KABPrefs::instance()->mCurrentView = mActiveView->caption();
150 154
151} 155}
152 156
153QStringList ViewManager::selectedUids() const 157QStringList ViewManager::selectedUids() const
154{ 158{
155 if ( mActiveView ) 159 if ( mActiveView )
156 return mActiveView->selectedUids(); 160 return mActiveView->selectedUids();
157 else 161 else
158 return QStringList(); 162 return QStringList();
159} 163}
160 164
161QStringList ViewManager::selectedEmails() const 165QStringList ViewManager::selectedEmails() const
162{ 166{
163 if ( mActiveView ) 167 if ( mActiveView )
164 return mActiveView->selectedEmails(); 168 return QStringList(mActiveView->selectedEmails());
165 else 169 else
166 return QStringList(); 170 return QStringList();
167} 171}
168 172
169KABC::Addressee::List ViewManager::selectedAddressees() const 173KABC::Addressee::List ViewManager::selectedAddressees() const
170{ 174{
171 KABC::Addressee::List list; 175 KABC::Addressee::List list;
172 if ( mActiveView ) { 176 if ( mActiveView ) {
173 QStringList uids = mActiveView->selectedUids(); 177 QStringList uids = mActiveView->selectedUids();
174 QStringList::Iterator it; 178 QStringList::Iterator it;
175 for ( it = uids.begin(); it != uids.end(); ++it ) { 179 for ( it = uids.begin(); it != uids.end(); ++it ) {
176 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 180 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
177 if ( !addr.isEmpty() ) 181 if ( !addr.isEmpty() )
178 list.append( addr ); 182 list.append( addr );
179 } 183 }
180 } 184 }
@@ -543,33 +547,33 @@ qDebug("ViewManager::dropped() has to be changed!!" );
543} 547}
544 548
545void ViewManager::startDrag() 549void ViewManager::startDrag()
546{ 550{
547 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 551 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
548 552
549#ifndef KAB_EMBEDDED 553#ifndef KAB_EMBEDDED
550 554
551 // Get the list of all the selected addressees 555 // Get the list of all the selected addressees
552 KABC::Addressee::List addrList; 556 KABC::Addressee::List addrList;
553 QStringList uidList = selectedUids(); 557 QStringList uidList = selectedUids();
554 QStringList::Iterator iter; 558 QStringList::Iterator iter;
555 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 559 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
556 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 560 addrList.append( mCore->addressBook()->findByUid( *iter ) );
557 561
558 KMultipleDrag *drag = new KMultipleDrag( this ); 562 KMultipleDrag *drag = new KMultipleDrag( this );
559 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 563 drag->addDragObject( new Q3TextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
560 KABC::Addressee::List::Iterator it; 564 KABC::Addressee::List::Iterator it;
561 QStringList vcards; 565 QStringList vcards;
562 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 566 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
563 QString vcard = QString::null; 567 QString vcard = QString::null;
564 KABC::VCardConverter converter; 568 KABC::VCardConverter converter;
565 if ( converter.addresseeToVCard( *it, vcard ) ) 569 if ( converter.addresseeToVCard( *it, vcard ) )
566 vcards.append( vcard ); 570 vcards.append( vcard );
567 } 571 }
568 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 572 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
569 573
570 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 574 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
571 drag->dragCopy(); 575 drag->dragCopy();
572 576
573#else //KAB_EMBEDDED 577#else //KAB_EMBEDDED
574qDebug("ViewManager::startDrag() has to be changed!!" ); 578qDebug("ViewManager::startDrag() has to be changed!!" );
575#endif //KAB_EMBEDDED 579#endif //KAB_EMBEDDED
@@ -646,35 +650,35 @@ int ViewManager::filterPosition( const QString &name ) const
646 int pos = 0; 650 int pos = 0;
647 651
648 Filter::List::ConstIterator it; 652 Filter::List::ConstIterator it;
649 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) 653 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
650 if ( name == (*it).name() ) 654 if ( name == (*it).name() )
651 return pos + 1; 655 return pos + 1;
652 656
653 return 0; 657 return 0;
654} 658}
655 659
656void ViewManager::initActions() 660void ViewManager::initActions()
657{ 661{
658//US <ActionList name="view_loadedviews"/> 662//US <ActionList name="view_loadedviews"/>
659//US <Separator/> 663//US <Separator/>
660 664
661#ifdef KAB_EMBEDDED 665#ifdef KAB_EMBEDDED
662 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); 666 Q3PopupMenu *viewmenu = (Q3PopupMenu*)mCore->getViewMenu();
663 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); 667 Q3PopupMenu *settingsmenu = (Q3PopupMenu*)mCore->getSettingsMenu();
664 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); 668 Q3PopupMenu *filtermenu = (Q3PopupMenu*)mCore->getFilterMenu();
665#endif //KAB_EMBEDDED 669#endif //KAB_EMBEDDED
666 670
667 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); 671 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
668#if KDE_VERSION >= 309 672#if KDE_VERSION >= 309
669 mActionSelectView->setMenuAccelsEnabled( false ); 673 mActionSelectView->setMenuAccelsEnabled( false );
670#endif 674#endif
671 connect( mActionSelectView, SIGNAL( activated( const QString& ) ), 675 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
672 SLOT( selectView( const QString& ) ) ); 676 SLOT( selectView( const QString& ) ) );
673 677
674 678
675#ifdef KAB_EMBEDDED 679#ifdef KAB_EMBEDDED
676 mActionSelectView->plug(viewmenu); 680 mActionSelectView->plug(viewmenu);
677 viewmenu->insertSeparator(); 681 viewmenu->insertSeparator();
678#endif //KAB_EMBEDDED 682#endif //KAB_EMBEDDED
679 683
680 KAction *action; 684 KAction *action;
@@ -725,24 +729,24 @@ void ViewManager::initActions()
725 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); 729 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
726#if KDE_VERSION >= 309 730#if KDE_VERSION >= 309
727 mActionSelectFilter->setMenuAccelsEnabled( false ); 731 mActionSelectFilter->setMenuAccelsEnabled( false );
728#endif 732#endif
729 connect( mActionSelectFilter, SIGNAL( activated( int ) ), 733 connect( mActionSelectFilter, SIGNAL( activated( int ) ),
730 SLOT( setActiveFilter( int ) ) ); 734 SLOT( setActiveFilter( int ) ) );
731 735
732#ifdef KAB_EMBEDDED 736#ifdef KAB_EMBEDDED
733 action->plug(settingsmenu); 737 action->plug(settingsmenu);
734 mActionSelectFilter->plug(viewmenu,0); 738 mActionSelectFilter->plug(viewmenu,0);
735#endif //KAB_EMBEDDED 739#endif //KAB_EMBEDDED
736 740
737} 741}
738 742
739void ViewManager::initGUI() 743void ViewManager::initGUI()
740{ 744{
741 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); 745 Q3HBoxLayout *layout = new Q3HBoxLayout( this, 0, 0 );
742 mViewWidgetStack = new QWidgetStack( this ); 746 mViewWidgetStack = new Q3WidgetStack( this );
743 layout->addWidget( mViewWidgetStack ); 747 layout->addWidget( mViewWidgetStack );
744} 748}
745 749
746#ifndef KAB_EMBEDDED 750#ifndef KAB_EMBEDDED_
747#include "viewmanager.moc" 751#include "moc_viewmanager.cpp"
748#endif //KAB_EMBEDDED 752#endif //KAB_EMBEDDED