]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
cleanup of unused forward declarations
[dolphin.git] / src / dolphincontextmenu.cpp
index 36a731c0fc36579ab0356d54090c25065035ff59..14760658128d3477ab2361eb7b95e6086a28e502 100644 (file)
@@ -36,6 +36,7 @@
 #include <kio/netaccess.h>
 #include <kmenu.h>
 #include <kmimetypetrader.h>
+#include <knewmenu.h>
 #include <klocale.h>
 #include <kpropertiesdialog.h>
 #include <krun.h>
 #include <QDir>
 
 DolphinContextMenu::DolphinContextMenu(DolphinView* parent,
-                                       KFileItem* fileInfo,
-                                       const QPoint& pos) :
+                                       KFileItem* fileInfo) :
    m_dolphinView(parent),
-   m_fileInfo(fileInfo),
-   m_pos(pos)
+   m_fileInfo(fileInfo)
 {
 }
 
@@ -69,31 +68,15 @@ DolphinContextMenu::~DolphinContextMenu()
 
 void DolphinContextMenu::openViewportContextMenu()
 {
-    // Parts of the following code have been taken
-    // from the class KonqOperations located in
-    // libqonq/konq_operations.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>)
-
     assert(m_fileInfo == 0);
-
     DolphinMainWindow* dolphin = m_dolphinView->mainWindow();
     KMenu* popup = new KMenu(m_dolphinView);
 
     // setup 'Create New' menu
-    KMenu* createNewMenu = new KMenu(i18n("Create New"));
-    createNewMenu->setIcon(SmallIcon("filenew"));
-
-    QAction* createFolderAction = dolphin->actionCollection()->action("create_folder");
-    if (createFolderAction != 0) {
-        createNewMenu->addAction(createFolderAction);
-    }
-
-    QLinkedListIterator<QAction*> fileGrouptIt(dolphin->fileGroupActions());
-    while (fileGrouptIt.hasNext()) {
-        createNewMenu->addAction(fileGrouptIt.next());
-    }
-
-    popup->addMenu(createNewMenu);
+    KNewMenu* newMenu = dolphin->newMenu();
+    newMenu->slotCheckUpToDate();
+    newMenu->setPopupFiles(m_dolphinView->url());
+    popup->addMenu(newMenu->menu());
     popup->addSeparator();
 
     QAction* pasteAction = dolphin->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
@@ -114,12 +97,12 @@ void DolphinContextMenu::openViewportContextMenu()
     popup->addMenu(viewModeMenu);
     popup->addSeparator();
 
-    QAction* bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
+    QAction* bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark this folder"));
     popup->addSeparator();
 
     QAction* propertiesAction = popup->addAction(i18n("Properties..."));
 
-    QAction* activatedAction = popup->exec(m_pos);
+    QAction* activatedAction = popup->exec(QCursor::pos());
     if (activatedAction == propertiesAction) {
         new KPropertiesDialog(dolphin->activeView()->url());
     }
@@ -142,11 +125,6 @@ void DolphinContextMenu::openViewportContextMenu()
 
 void DolphinContextMenu::openItemContextMenu()
 {
-    // Parts of the following code have been taken
-    // from the class KonqOperations located in
-    // libkonq/konq_operations.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>)
-
     assert(m_fileInfo != 0);
 
     KMenu* popup = new KMenu(m_dolphinView);
@@ -173,13 +151,20 @@ void DolphinContextMenu::openItemContextMenu()
     QAction* renameAction = dolphin->actionCollection()->action("rename");
     popup->addAction(renameAction);
 
-    // insert 'Move to Trash' for local Urls, otherwise insert 'Delete'
+    // insert 'Move to Trash' and (optionally) 'Delete'
+    const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals);
+    const KConfigGroup kdeConfig(globalConfig, "KDE");
+    bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
     const KUrl& url = dolphin->activeView()->url();
     if (url.isLocalFile()) {
         QAction* moveToTrashAction = dolphin->actionCollection()->action("move_to_trash");
         popup->addAction(moveToTrashAction);
     }
     else {
+        showDeleteCommand = true;
+    }
+
+    if (showDeleteCommand) {
         QAction* deleteAction = dolphin->actionCollection()->action("delete");
         popup->addAction(deleteAction);
     }
@@ -189,7 +174,7 @@ void DolphinContextMenu::openItemContextMenu()
     // urls contains only one item, i.e. no multiple selection made
     QAction* bookmarkAction = 0;
     if (m_fileInfo->isDir() && (urls.count() == 1)) {
-        bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
+        bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark this folder"));
     }
 
     // Insert 'Open With...' sub menu
@@ -205,7 +190,7 @@ void DolphinContextMenu::openItemContextMenu()
     QAction* propertiesAction = dolphin->actionCollection()->action("properties");
     popup->addAction(propertiesAction);
 
-    QAction* activatedAction = popup->exec(m_pos);
+    QAction* activatedAction = popup->exec(QCursor::pos());
 
     if ((bookmarkAction!= 0) && (activatedAction == bookmarkAction)) {
         const KUrl selectedUrl(m_fileInfo->url());
@@ -246,6 +231,11 @@ void DolphinContextMenu::openItemContextMenu()
 QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
                                                         QVector<KService::Ptr>& openWithVector)
 {
+    // Parts of the following code have been taken
+    // from the class KonqOperations located in
+    // libqonq/konq_operations.h of Konqueror.
+    // (Copyright (C) 2000  David Faure <faure@kde.org>)
+
     // Prepare 'Open With' sub menu. Usually a sub menu is created, where all applications
     // are listed which are registered to open the item. As last entry "Other..." will be
     // attached which allows to select a custom application. If no applications are registered
@@ -314,6 +304,11 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
 QList<QAction*> DolphinContextMenu::insertActionItems(KMenu* popup,
                                                       QVector<KDEDesktopMimeType::Service>& actionsVector)
 {
+    // Parts of the following code have been taken
+    // from the class KonqOperations located in
+    // libqonq/konq_operations.h of Konqueror.
+    // (Copyright (C) 2000  David Faure <faure@kde.org>)
+
     KMenu* actionsMenu = new KMenu(i18n("Actions"));
 
     QList<QAction*> serviceActions;
@@ -329,8 +324,7 @@ QList<QAction*> DolphinContextMenu::insertActionItems(KMenu* popup,
         QStringList entries = dir.entryList(QDir::Files);
 
         for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) {
-            KSimpleConfig cfg(*dirIt + *entryIt, true);
-            cfg.setDesktopGroup();
+            KConfigGroup cfg(KSharedConfig::openConfig( *dirIt + *entryIt, KConfig::OnlyLocal), "Desktop Entry" );
             if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) {
                 //const QStringList types = cfg.readListEntry("ServiceTypes");
                 QStringList types;