+void DolphinContextMenu::openTrashContextMenu()
+{
+ Q_ASSERT(m_context & TrashContext);
+
+ KMenu* popup = new KMenu(m_dolphinView);
+
+ QAction* emptyTrashAction = new QAction(KIcon("user-trash"), i18n("Emtpy Trash"), popup);
+ KConfig trashConfig("trashrc", KConfig::OnlyLocal);
+ emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
+ popup->addAction(emptyTrashAction);
+
+ DolphinMainWindow* mainWindow = m_dolphinView->mainWindow();
+ QAction* propertiesAction = mainWindow->actionCollection()->action("properties");
+ popup->addAction(propertiesAction);
+
+ if (popup->exec(QCursor::pos()) == emptyTrashAction) {
+ const QString text(i18n("Do you really want to empty the Trash? All items will get deleted."));
+ const bool del = KMessageBox::warningContinueCancel(mainWindow,
+ text,
+ QString(),
+ KGuiItem(i18n("Empty Trash"), KIcon("user-trash"))
+ ) == KMessageBox::Continue;
+ if (del) {
+ KonqOperations::emptyTrash(m_dolphinView);
+ }
+ }
+
+ popup->deleteLater();
+}
+
+void DolphinContextMenu::openTrashItemContextMenu()
+{
+ Q_ASSERT(m_context & TrashContext);
+ Q_ASSERT(m_context & ItemContext);
+
+ KMenu* popup = new KMenu(m_dolphinView);
+
+ DolphinMainWindow* mainWindow = m_dolphinView->mainWindow();
+ QAction* restoreAction = new QAction(i18n("Restore"), m_dolphinView);
+ popup->addAction(restoreAction);
+
+ QAction* deleteAction = mainWindow->actionCollection()->action("delete");
+ popup->addAction(deleteAction);
+
+ QAction* propertiesAction = mainWindow->actionCollection()->action("properties");
+ popup->addAction(propertiesAction);
+
+ if (popup->exec(QCursor::pos()) == restoreAction) {
+ const KUrl::List urls = m_dolphinView->selectedUrls();
+ KonqOperations::restoreTrashedItems(urls, m_dolphinView);
+ }
+
+ popup->deleteLater();
+}
+
+void DolphinContextMenu::openItemContextMenu()
+{
+ Q_ASSERT(m_fileInfo != 0);
+
+ KMenu* popup = new KMenu(m_dolphinView);
+ insertDefaultItemActions(popup);
+
+ DolphinMainWindow* mainWindow = m_dolphinView->mainWindow();
+ const KUrl::List urls = m_dolphinView->selectedUrls();
+
+ // insert 'Bookmark this folder' entry if exactly one item is selected
+ QAction* bookmarkAction = 0;
+ if (m_fileInfo->isDir() && (urls.count() == 1)) {
+ bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark this folder"));
+ }
+
+ // Insert 'Open With...' sub menu
+ QVector<KService::Ptr> openWithVector;
+ const QList<QAction*> openWithActions = insertOpenWithItems(popup, openWithVector);
+
+ // Insert 'Actions' sub menu
+ QVector<KDEDesktopMimeType::Service> actionsVector;
+ const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
+ popup->addSeparator();
+
+ // insert 'Properties...' entry
+ QAction* propertiesAction = mainWindow->actionCollection()->action("properties");
+ popup->addAction(propertiesAction);
+
+ QAction* activatedAction = popup->exec(QCursor::pos());
+
+ if ((bookmarkAction!= 0) && (activatedAction == bookmarkAction)) {
+ const KUrl selectedUrl(m_fileInfo->url());
+ KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add folder as bookmark"),
+ selectedUrl.fileName(),
+ selectedUrl,
+ "bookmark");
+ if (!bookmark.isNull()) {
+ KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager();
+ KBookmarkGroup root = manager->root();
+ root.addBookmark(manager, bookmark);
+ manager->emitChanged(root);
+ }
+ }
+ else if (serviceActions.contains(activatedAction)) {
+ // one of the 'Actions' items has been selected
+ int id = serviceActions.indexOf(activatedAction);
+ KDEDesktopMimeType::executeService(urls, actionsVector[id]);
+ }
+ else if (openWithActions.contains(activatedAction)) {
+ // one of the 'Open With' items has been selected
+ if (openWithActions.last() == activatedAction) {
+ // the item 'Other...' has been selected
+ KRun::displayOpenWithDialog(urls, m_dolphinView);
+ }
+ else {
+ int id = openWithActions.indexOf(activatedAction);
+ KService::Ptr servicePtr = openWithVector[id];
+ KRun::run(*servicePtr, urls, m_dolphinView);
+ }
+ }
+
+ openWithVector.clear();
+ actionsVector.clear();
+ popup->deleteLater();
+}
+