From 7973cbae4380599be85347745753327c94ebd806 Mon Sep 17 00:00:00 2001 From: tpearson Date: Sun, 11 Jul 2010 22:09:14 +0000 Subject: Added right-click popup menu to KAddressBook resources git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1148784 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kaddressbook/features/resourceselection.cpp | 64 +++++++++++++++++++++++++++++ kaddressbook/features/resourceselection.h | 7 ++++ 2 files changed, 71 insertions(+) diff --git a/kaddressbook/features/resourceselection.cpp b/kaddressbook/features/resourceselection.cpp index c18d8b168..dcd40dc12 100644 --- a/kaddressbook/features/resourceselection.cpp +++ b/kaddressbook/features/resourceselection.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -148,6 +149,11 @@ ResourceSelection::ResourceSelection( KAB::Core *core, QWidget *parent, const ch connect( mListView, SIGNAL( clicked( QListViewItem* ) ), SLOT( currentChanged( QListViewItem* ) ) ); + connect( mListView, SIGNAL( contextMenuRequested ( QListViewItem *, + const QPoint &, int ) ), + SLOT( contextMenuRequested( QListViewItem *, const QPoint &, + int ) ) ); + QTimer::singleShot( 0, this, SLOT( updateView() ) ); } @@ -155,6 +161,64 @@ ResourceSelection::~ResourceSelection() { } +void ResourceSelection::contextMenuRequested ( QListViewItem *i, + const QPoint &pos, int ) +{ + ResourceItem *item = static_cast( i ); + + QPopupMenu *menu = new QPopupMenu( this ); + connect( menu, SIGNAL( aboutToHide() ), menu, SLOT( deleteLater() ) ); + if ( item ) { + int reloadId = menu->insertItem( i18n("Re&load"), this, + SLOT( reloadResource() ) ); + menu->setItemEnabled( reloadId, item->resource()->isActive() ); + int saveId = menu->insertItem( i18n("&Save"), this, + SLOT( saveResource() ) ); + menu->setItemEnabled( saveId, item->resource()->isActive() ); + menu->insertSeparator(); + +// menu->insertItem( i18n("Show &Info"), this, SLOT( showInfo() ) ); + + menu->insertItem( i18n("&Edit..."), this, SLOT( edit() ) ); + menu->insertItem( i18n("&Remove"), this, SLOT( remove() ) ); + + menu->insertSeparator(); + } + menu->insertItem( i18n("&Add..."), this, SLOT( add() ) ); + + menu->popup( pos ); +} + +void ResourceSelection::reloadResource() +{ + ResourceItem *item = selectedItem(); + if ( !item ) return; + + KABC::Resource *r = item->resource(); + r->load(); +} + +void ResourceSelection::saveResource() +{ + ResourceItem *item = selectedItem(); + if ( !item ) return; + + KABC::Resource *r = item->resource(); + KABC::Ticket *ticket = core()->addressBook()->requestSaveTicket( r ); + if ( ticket ) { + r->save( ticket ); + } +} + +void ResourceSelection::showInfo() +{ + ResourceItem *item = selectedItem(); + if ( !item ) return; + +// QString txt = "" + item->resource()->infoText() + ""; +// KMessageBox::information( this, txt ); +} + QString ResourceSelection::title() const { return i18n( "Address Books" ); diff --git a/kaddressbook/features/resourceselection.h b/kaddressbook/features/resourceselection.h index 6e1a56b04..a2eff8c13 100644 --- a/kaddressbook/features/resourceselection.h +++ b/kaddressbook/features/resourceselection.h @@ -66,6 +66,13 @@ class ResourceSelection : public KAB::ExtensionWidget const QString& /*type*/, const QString& subResource ); + void contextMenuRequested ( QListViewItem *i, const QPoint &pos, int ); + + void showInfo(); + + void reloadResource(); + void saveResource(); + private: void initGUI(); -- cgit v1.2.1