]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Allow compiling Dolphin with KF5
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 88f1c8248b09bf88786842aada4358cf8e866d54..aebb215e5ba748693221eac988d5182c83103e43 100644 (file)
 
 #include "dolphinviewactionhandler.h"
 
-#include <config-nepomuk.h>
+#include <config-baloo.h>
 
 #include "settings/viewpropertiesdialog.h"
 #include "views/dolphinview.h"
 #include "views/zoomlevelinfo.h"
 #include <konq_operations.h>
 
+#include <QPointer>
+
 #include <KAction>
 #include <KActionCollection>
 #include <KActionMenu>
 #include <KPropertiesDialog>
 #include <KIcon>
 
-#ifdef HAVE_NEPOMUK
-    #include <Nepomuk2/ResourceManager>
-#endif
-
 #include <KDebug>
 
+#ifdef HAVE_BALOO
+    #include <baloo/indexerconfig.h>
+#endif
+
 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
     QObject(parent),
     m_actionCollection(collection),
@@ -84,6 +86,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, SLOT(slotSortRoleChanged(QByteArray)));
     connect(view, SIGNAL(zoomLevelChanged(int,int)),
             this, SLOT(slotZoomLevelChanged(int,int)));
+    connect(view, SIGNAL(writeStateChanged(bool)),
+            this, SLOT(slotWriteStateChanged(bool)));
 }
 
 DolphinView* DolphinViewActionHandler::currentView()
@@ -95,28 +99,29 @@ void DolphinViewActionHandler::createActions()
 {
     // This action doesn't appear in the GUI, it's for the shortcut only.
     // KNewFileMenu takes care of the GUI stuff.
-    KAction* newDirAction = m_actionCollection->addAction("create_dir");
+    QAction* newDirAction = m_actionCollection->addAction("create_dir");
     newDirAction->setText(i18nc("@action", "Create Folder..."));
     newDirAction->setShortcut(Qt::Key_F10);
     newDirAction->setIcon(KIcon("folder-new"));
+    newDirAction->setEnabled(false);    // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
     connect(newDirAction, SIGNAL(triggered()), this, SIGNAL(createDirectory()));
 
     // File menu
 
-    KAction* rename = m_actionCollection->addAction("rename");
+    QAction* rename = m_actionCollection->addAction("rename");
     rename->setText(i18nc("@action:inmenu File", "Rename..."));
     rename->setShortcut(Qt::Key_F2);
     rename->setIcon(KIcon("edit-rename"));
     connect(rename, SIGNAL(triggered()), this, SLOT(slotRename()));
 
-    KAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
+    QAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
     moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
     moveToTrash->setIcon(KIcon("user-trash"));
     moveToTrash->setShortcut(QKeySequence::Delete);
     connect(moveToTrash, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)),
             this, SLOT(slotTrashActivated(Qt::MouseButtons,Qt::KeyboardModifiers)));
 
-    KAction* deleteAction = m_actionCollection->addAction("delete");
+    QAction* deleteAction = m_actionCollection->addAction("delete");
     deleteAction->setIcon(KIcon("edit-delete"));
     deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
     deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
@@ -126,14 +131,14 @@ void DolphinViewActionHandler::createActions()
     // disabled and "delete" is enabled (e.g. non-local files), so that Key_Del
     // can be used for deleting the file (#76016). It needs to be a separate action
     // so that the Edit menu isn't affected.
-    KAction* deleteWithTrashShortcut = m_actionCollection->addAction("delete_shortcut");
+    QAction* deleteWithTrashShortcut = m_actionCollection->addAction("delete_shortcut");
     // The descriptive text is just for the shortcuts editor.
     deleteWithTrashShortcut->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
     deleteWithTrashShortcut->setShortcut(QKeySequence::Delete);
     deleteWithTrashShortcut->setEnabled(false);
     connect(deleteWithTrashShortcut, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
 
-    KAction *propertiesAction = m_actionCollection->addAction( "properties" );
+    QAction *propertiesAction = m_actionCollection->addAction( "properties" );
     // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
     propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
     propertiesAction->setIcon(KIcon("document-properties"));
@@ -210,7 +215,7 @@ void DolphinViewActionHandler::createActions()
     showHiddenFiles->setShortcuts(QList<QKeySequence>() << Qt::ALT + Qt::Key_Period << Qt::Key_F8);
     connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool)));
 
-    KAction* adjustViewProps = m_actionCollection->addAction("view_properties");
+    QAction* adjustViewProps = m_actionCollection->addAction("view_properties");
     adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
     connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(slotAdjustViewProperties()));
 }
@@ -234,14 +239,10 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
     KActionMenu* groupMenu = 0;
     QActionGroup* groupMenuGroup = 0;
 
-    bool nepomukRunning = false;
     bool indexingEnabled = false;
-#ifdef HAVE_NEPOMUK
-    nepomukRunning = (Nepomuk2::ResourceManager::instance()->initialized());
-    if (nepomukRunning) {
-        KConfig config("nepomukserverrc");
-        indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", false);
-    }
+#ifdef HAVE_BALOO
+    Baloo::IndexerConfig config;
+    indexingEnabled = config.fileIndexingEnabled();
 #endif
 
     const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
@@ -281,8 +282,8 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
         action->setText(info.translation);
         action->setData(info.role);
 
-        const bool enable = (!info.requiresNepomuk && !info.requiresIndexer) ||
-                            (info.requiresNepomuk && nepomukRunning) ||
+        const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
+                            (info.requiresBaloo) ||
                             (info.requiresIndexer && indexingEnabled);
         action->setEnabled(enable);
 
@@ -314,14 +315,7 @@ void DolphinViewActionHandler::slotRename()
 void DolphinViewActionHandler::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers)
 {
     emit actionBeingHandled();
-    // Note: kde3's konq_mainwindow.cpp used to check
-    // reason == KAction::PopupMenuActivation && ...
-    // but this isn't supported anymore
-    if (modifiers & Qt::ShiftModifier) {
-        m_currentView->deleteSelectedItems();
-    } else {
-        m_currentView->trashSelectedItems();
-    }
+    m_currentView->trashSelectedItems();
 }
 
 void DolphinViewActionHandler::slotDeleteItems()
@@ -489,6 +483,11 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
     showHiddenFilesAction->setChecked(shown);
 }
 
+void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
+{
+    m_actionCollection->action("create_dir")->setEnabled(isFolderWritable);
+}
+
 KToggleAction* DolphinViewActionHandler::iconsModeAction()
 {
     KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("icons");
@@ -528,8 +527,10 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
     if (action) {
         action->setChecked(true);
 
-        QAction* sortByMenu =  m_actionCollection->action("sort");
-        sortByMenu->setIcon(KIcon(action->icon()));
+        if (!action->icon().isNull()) {
+            QAction* sortByMenu = m_actionCollection->action("sort");
+            sortByMenu->setIcon(KIcon(action->icon()));
+        }
     }
 }