]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
remember which service menus should be shown in the context menu
[dolphin.git] / src / dolphinviewcontainer.cpp
index 1b64f980343b3d25263878c260f3516727dca442..95b16448a3b553d34aeb94a98ecbb514b287c9a3 100644 (file)
@@ -42,6 +42,7 @@
 #include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
 #include <kurl.h>
+#include <kurlcombobox.h>
 #include <krun.h>
 
 #include "dolphinmodel.h"
@@ -58,7 +59,7 @@
 #include "filterbar.h"
 #include "kurlnavigator.h"
 #include "viewproperties.h"
-#include "dolphinsettings.h"
+#include "settings/dolphinsettings.h"
 #include "dolphin_generalsettings.h"
 
 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
@@ -66,6 +67,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
                                            const KUrl& url) :
     QWidget(parent),
     m_showProgress(false),
+    m_isFolderWritable(false),
     m_mainWindow(mainWindow),
     m_topLayout(0),
     m_urlNavigator(0),
@@ -86,11 +88,15 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(dropUrls(const KUrl&, QDropEvent*)));
     connect(m_urlNavigator, SIGNAL(activated()),
             this, SLOT(activate()));
+    connect(m_urlNavigator->editor(), SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
+            this, SLOT(saveUrlCompletionMode(KGlobalSettings::Completion)));
 
     const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
     m_urlNavigator->setUrlEditable(settings->editableUrl());
     m_urlNavigator->setShowFullPath(settings->showFullPath());
     m_urlNavigator->setHomeUrl(settings->homeUrl());
+    KUrlComboBox* editor = m_urlNavigator->editor();
+    editor->setCompletionMode(KGlobalSettings::Completion(settings->urlCompletionMode()));
 
     m_dirLister = new DolphinDirLister();
     m_dirLister->setAutoUpdate(true);
@@ -127,8 +133,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
                              m_proxyModel);
     connect(m_view, SIGNAL(urlChanged(const KUrl&)),
             m_urlNavigator, SLOT(setUrl(const KUrl&)));
-    connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)),
-            this, SLOT(openContextMenu(KFileItem, const KUrl&)));
+    connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
+            this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
     connect(m_view, SIGNAL(contentsMoved(int, int)),
             this, SLOT(saveContentsPos(int, int)));
     connect(m_view, SIGNAL(requestItemInfo(KFileItem)),
@@ -157,6 +163,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(setNameFilter(const QString&)));
     connect(m_filterBar, SIGNAL(closeRequest()),
             this, SLOT(closeFilterBar()));
+    connect(m_view, SIGNAL(urlChanged(const KUrl&)),
+            m_filterBar, SLOT(clear()));
 
     m_topLayout->addWidget(m_urlNavigator);
     m_topLayout->addWidget(m_view);
@@ -182,7 +190,10 @@ void DolphinViewContainer::setUrl(const KUrl& newUrl)
         // Temporary disable the 'File'->'Create New...' menu until
         // the write permissions can be checked in a fast way at
         // DolphinViewContainer::slotDirListerCompleted().
-        m_mainWindow->newMenu()->menu()->setEnabled(false);
+        m_isFolderWritable = false;
+        if (isActive()) {
+            m_mainWindow->newMenu()->menu()->setEnabled(false);
+        }
     }
 }
 
@@ -195,6 +206,9 @@ void DolphinViewContainer::setActive(bool active)
 {
     m_urlNavigator->setActive(active);
     m_view->setActive(active);
+    if (active) {
+        m_mainWindow->newMenu()->menu()->setEnabled(m_isFolderWritable);
+    }
 }
 
 bool DolphinViewContainer::isActive() const
@@ -262,14 +276,17 @@ void DolphinViewContainer::slotDirListerCompleted()
 
     // Enable the 'File'->'Create New...' menu only if the directory
     // supports writing.
-    KMenu* createNew = m_mainWindow->newMenu()->menu();
     KFileItem item = m_dirLister->rootItem();
     if (item.isNull()) {
         // it is unclear whether writing is supported
-        createNew->setEnabled(true);
+        m_isFolderWritable = true;
     } else {
         KonqFileItemCapabilities capabilities(KFileItemList() << item);
-        createNew->setEnabled(capabilities.supportsWriting());
+        m_isFolderWritable = capabilities.supportsWriting();
+    }
+
+    if (isActive()) {
+        m_mainWindow->newMenu()->menu()->setEnabled(m_isFolderWritable);
     }
 }
 
@@ -335,9 +352,11 @@ void DolphinViewContainer::setNameFilter(const QString& nameFilter)
 }
 
 void DolphinViewContainer::openContextMenu(const KFileItem& item,
-                                           const KUrl& url)
+                                           const KUrl& url,
+                                           const QList<QAction*>& customActions)
 {
     DolphinContextMenu contextMenu(m_mainWindow, item, url);
+    contextMenu.setCustomActions(customActions);
     contextMenu.open();
 }
 
@@ -363,6 +382,16 @@ void DolphinViewContainer::restoreView(const KUrl& url)
 {
     if (KProtocolManager::supportsListing(url)) {
         m_view->updateView(url, m_urlNavigator->savedRootUrl());
+        if (isActive()) {
+            // When an URL has been entered, the view should get the focus.
+            // The focus must be requested asynchronously, as changing the URL might create
+            // a new view widget. Using QTimer::singleShow() works reliable, however
+            // QMetaObject::invokeMethod() with a queued connection does not work, which might
+            // indicate that we should pass a hint to DolphinView::updateView()
+            // regarding the focus instead. To test: Enter an URL and press CTRL+Enter.
+            // Expected result: The view should get the focus.
+            QTimer::singleShot(0, this, SLOT(requestFocus()));
+        }
     } else if (KProtocolManager::isSourceProtocol(url)) {
         QString app = "konqueror";
         if (url.protocol().startsWith(QLatin1String("http"))) {
@@ -382,17 +411,6 @@ void DolphinViewContainer::restoreView(const KUrl& url)
     } else {
         showErrorMessage(i18nc("@info:status", "Invalid protocol"));
     }
-
-    if (isActive()) {
-        // When an URL has been entered, the view should get the focus.
-        // The focus must be requested asynchronously, as changing the URL might create
-        // a new view widget. Using QTimer::singleShow() works reliable, however
-        // QMetaObject::invokeMethod() with a queued connection does not work, which might
-        // indicate that we should pass a hint to DolphinView::updateView()
-        // regarding the focus instead. To test: Enter an URL and press CTRL+Enter.
-        // Expected result: The view should get the focus.
-        QTimer::singleShot(0, this, SLOT(requestFocus()));
-    }
 }
 
 void DolphinViewContainer::saveRootUrl(const KUrl& url)
@@ -420,6 +438,13 @@ void DolphinViewContainer::requestFocus()
     m_view->setFocus();
 }
 
+void DolphinViewContainer::saveUrlCompletionMode(KGlobalSettings::Completion completion)
+{
+    DolphinSettings& settings = DolphinSettings::instance();
+    settings.generalSettings()->setUrlCompletionMode(completion);
+    settings.save();
+}
+
 void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
 {
     KUrl url = item.targetUrl();