summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-11 22:09:14 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-11 22:09:14 +0000
commit7973cbae4380599be85347745753327c94ebd806 (patch)
treed5807ec9344e5393785ed956b6b8a35adfe52863
parent7cb81641f44874b12945bbd3cceb209866275833 (diff)
downloadtdepim-7973cbae4380599be85347745753327c94ebd806.tar.gz
tdepim-7973cbae4380599be85347745753327c94ebd806.zip
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
-rw-r--r--kaddressbook/features/resourceselection.cpp64
-rw-r--r--kaddressbook/features/resourceselection.h7
2 files changed, 71 insertions, 0 deletions
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 <qlayout.h>
+#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qtimer.h>
#include <qlabel.h>
@@ -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<ResourceItem *>( 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 = "<qt>" + item->resource()->infoText() + "</qt>";
+// 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();