void BaseTreeView::insertOpenWithMenu(KPopupMenu *menu, int position) { if (m_openWithMenuId != -1) menu->removeItem(m_openWithMenuId); for (uint i = 0; i < m_openWithActions.count(); i++) { KAction *action = m_openWithActions[i]; delete action; } m_openWithActions.clear(); KURL urlToOpen = currentURL(); QString mimeType = KMimeType::findByURL(urlToOpen, 0, true, true)->name(); KTrader::OfferList offers = KTrader::self()->query(mimeType, "Type == 'Application'"); QDict<QuantaPlugin> plugins = QuantaPluginInterface::ref()->plugins(); m_pluginIds.clear(); if (offers.count() > 0 || plugins.count() > 0) { m_openWithMenu = new KPopupMenu(this); if (offers.count() > 0) { KTrader::OfferList::Iterator it; for (it = offers.begin(); it != offers.end(); ++it) { KAction *action = new KAction((*it)->name(), (*it)->icon(), 0, 0, QFile::encodeName((*it)->desktopEntryPath()).data()); connect(action, SIGNAL(activated()), this, SLOT(slotOpenWithApplication())); action->plug(m_openWithMenu); m_openWithActions.append(action); } m_openWithMenu->insertSeparator(); } if (plugins.count() > 0) { m_openWithMenu->insertTitle(i18n("Plugins")); QDictIterator<QuantaPlugin> it2(plugins); for(;it2.current();++it2) { int id = m_openWithMenu->insertItem(KGlobal::iconLoader()->loadIconSet(it2.current()->icon(),KIcon::Small), it2.current()->name()); m_pluginIds[id] = it2.current(); } connect(m_openWithMenu, SIGNAL(activated(int)), SLOT(slotOpenWithActivated(int))); m_openWithMenu->insertSeparator(); } m_openWithMenu->insertItem(i18n("&Other..."), this, SLOT(slotOpenWith())); m_openWithMenuId = menu->insertItem(i18n("Open &With"), m_openWithMenu, -1, position); } else m_openWithMenuId = menu->insertItem(i18n("Open &With..."), this, SLOT(slotOpenWith()), 0, -1, position); }
void KMMimePartTree::itemRightClicked( QListViewItem* item, const QPoint& point ) { // TODO: remove this member var? mCurrentContextMenuItem = dynamic_cast<KMMimePartTreeItem*>( item ); if ( 0 == mCurrentContextMenuItem ) { kdDebug(5006) << "Item was not a KMMimePartTreeItem!" << endl; } else { kdDebug(5006) << "\n**\n** KMMimePartTree::itemRightClicked() **\n**" << endl; QPopupMenu* popup = new QPopupMenu; if ( mCurrentContextMenuItem->node()->nodeId() > 2 && mCurrentContextMenuItem->node()->typeString() != "Multipart" ) { popup->insertItem( SmallIcon("fileopen"), i18n("to open", "Open"), this, SLOT(slotOpen()) ); popup->insertItem( i18n("Open With..."), this, SLOT(slotOpenWith()) ); popup->insertItem( i18n("to view something", "View"), this, SLOT(slotView()) ); } popup->insertItem( SmallIcon("filesaveas"),i18n( "Save &As..." ), this, SLOT( slotSaveAs() ) ); /* * FIXME mkae optional? popup->insertItem( i18n( "Save as &Encoded..." ), this, SLOT( slotSaveAsEncoded() ) ); */ popup->insertItem( i18n( "Save All Attachments..." ), this, SLOT( slotSaveAll() ) ); // edit + delete only for attachments if ( mCurrentContextMenuItem->node()->nodeId() > 2 && mCurrentContextMenuItem->node()->typeString() != "Multipart" ) { popup->insertItem( SmallIcon("editcopy"), i18n("Copy"), this, SLOT(slotCopy()) ); if ( GlobalSettings::self()->allowAttachmentDeletion() ) popup->insertItem( SmallIcon("editdelete"), i18n( "Delete Attachment" ), this, SLOT( slotDelete() ) ); if ( GlobalSettings::self()->allowAttachmentEditing() ) popup->insertItem( SmallIcon( "edit" ), i18n( "Edit Attachment" ), this, SLOT( slotEdit() ) ); } if ( mCurrentContextMenuItem->node()->nodeId() > 0 ) popup->insertItem( i18n("Properties"), this, SLOT(slotProperties()) ); popup->exec( point ); delete popup; mCurrentContextMenuItem = 0; } }
void KfindWindow::slotContextMenu(KListView *, QListViewItem *item, const QPoint &p) { if(!item) return; int count = selectedItems().count(); if(count == 0) { return; }; if(m_menu == 0) m_menu = new KPopupMenu(this); else m_menu->clear(); if(count == 1) { // menu = new KPopupMenu(item->text(0), this); m_menu->insertTitle(item->text(0)); m_menu->insertItem(SmallIcon("fileopen"), i18n("Menu item", "Open"), this, SLOT(openBinding())); m_menu->insertItem(SmallIcon("window_new"), i18n("Open Folder"), this, SLOT(openFolder())); m_menu->insertSeparator(); m_menu->insertItem(SmallIcon("editcopy"), i18n("Copy"), this, SLOT(copySelection())); m_menu->insertItem(SmallIcon("editdelete"), i18n("Delete"), this, SLOT(deleteFiles())); m_menu->insertSeparator(); m_menu->insertItem(i18n("Open With..."), this, SLOT(slotOpenWith())); m_menu->insertSeparator(); m_menu->insertItem(i18n("Properties"), this, SLOT(fileProperties())); } else { m_menu->insertTitle(i18n("Selected Files")); m_menu->insertItem(SmallIcon("editcopy"), i18n("Copy"), this, SLOT(copySelection())); m_menu->insertItem(SmallIcon("editdelete"), i18n("Delete"), this, SLOT(deleteFiles())); } m_menu->popup(p, 1); }