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
v3.5.13-sru
tpearson 15 years ago
parent 7cb81641f4
commit 7973cbae43

@ -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" );

@ -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();

Loading…
Cancel
Save