]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix issue that the enabled state of the "Create New..." menu is not updated correctly...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 15 Dec 2010 18:40:08 +0000 (18:40 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 15 Dec 2010 18:40:08 +0000 (18:40 +0000)
BUG: 258534
FIXED-IN: 4.6.0

svn path=/trunk/KDE/kdebase/apps/; revision=1206749

src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h
src/views/dolphinview.cpp
src/views/dolphinview.h

index 06682202d746c45c09d0ce372ee8f1c222a0f38b..8f934d163278bbf4431c7eb3384c5097f3d6ee41 100644 (file)
@@ -38,7 +38,6 @@
 #include <kmenu.h>
 #include <knewmenu.h>
 #include <konqmimedata.h>
-#include <kfileitemlistproperties.h>
 #include <konq_operations.h>
 #include <kshell.h>
 #include <kurl.h>
@@ -65,7 +64,6 @@
 
 DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
     QWidget(parent),
-    m_isFolderWritable(false),
     m_topLayout(0),
     m_urlNavigator(0),
     m_searchBox(0),
@@ -155,6 +153,8 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
             this, SLOT(slotStartedPathLoading()));
     connect(m_view, SIGNAL(finishedPathLoading(KUrl)),
             this, SLOT(slotFinishedPathLoading()));
+    connect(m_view, SIGNAL(writeStateChanged(bool)),
+            this, SIGNAL(writeStateChanged(bool)));
 
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
             this, SLOT(slotUrlNavigatorLocationChanged(const KUrl&)));
@@ -209,9 +209,6 @@ void DolphinViewContainer::setActive(bool active)
 {
     m_urlNavigator->setActive(active);
     m_view->setActive(active);
-    if (active) {
-        emit writeStateChanged(m_isFolderWritable);
-    }
 }
 
 bool DolphinViewContainer::isActive() const
@@ -291,14 +288,6 @@ void DolphinViewContainer::setUrl(const KUrl& newUrl)
 {
     if (newUrl != m_urlNavigator->locationUrl()) {
         m_urlNavigator->setLocationUrl(newUrl);
-
-        // Temporary disable the 'File'->'Create New...' menu until
-        // the write permissions can be checked in a fast way at
-        // DolphinViewContainer::slotDirListerCompleted().
-        m_isFolderWritable = false;
-        if (isActive()) {
-            emit writeStateChanged(false);
-        }
     }
 }
 
@@ -389,21 +378,6 @@ void DolphinViewContainer::slotFinishedPathLoading()
     } else {
         updateStatusBar();
     }
-
-    // Enable the 'File'->'Create New...' menu only if the directory
-    // supports writing.
-    KFileItem item = m_dirLister->rootItem();
-    if (item.isNull()) {
-        // it is unclear whether writing is supported
-        m_isFolderWritable = true;
-    } else {
-        KFileItemListProperties capabilities(KFileItemList() << item);
-        m_isFolderWritable = capabilities.supportsWriting();
-    }
-
-    if (isActive()) {
-        emit writeStateChanged(m_isFolderWritable);
-    }
 }
 
 void DolphinViewContainer::showItemInfo(const KFileItem& item)
index 337452e5cc83e4693bb3c2037600b0314ac89f3e..7586dc13fb29c5f4c19de1e59a2375efbb078f50 100644 (file)
@@ -265,8 +265,6 @@ private:
     bool isSearchUrl(const KUrl& url) const;
 
 private:
-    bool m_isFolderWritable;
-
     QVBoxLayout* m_topLayout;
     KUrlNavigator* m_urlNavigator;
     DolphinSearchBox* m_searchBox;
index 46f7acf1304fdc7ecb256c77e6d6dec2824bdcce..1e97d6864930adca8d65edd8249c776fdf9dc185 100644 (file)
@@ -34,6 +34,7 @@
 #include <kdirlister.h>
 #include <kiconeffect.h>
 #include <kfileitem.h>
+#include <kfileitemlistproperties.h>
 #include <klocale.h>
 #include <kio/deletejob.h>
 #include <kio/netaccess.h>
@@ -76,6 +77,8 @@ DolphinView::DolphinView(QWidget* parent,
     m_tabsForFiles(false),
     m_isContextMenuOpen(false),
     m_assureVisibleCurrentIndex(false),
+    m_expanderActive(false),
+    m_isFolderWritable(true),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_dolphinViewController(0),
@@ -123,7 +126,7 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_dolphinViewController, SIGNAL(viewportEntered()),
             this, SLOT(clearHoverInformation()));
     connect(m_dolphinViewController, SIGNAL(urlChangeRequested(KUrl)),
-            m_viewModeController, SLOT(setUrl(KUrl)));
+            this, SLOT(slotUrlChangeRequested(KUrl)));
 
     // When a new item has been created by the "Create New..." menu, the item should
     // get selected and it must be assured that the item will get visible. As the
@@ -169,9 +172,7 @@ void DolphinView::setActive(bool active)
     m_active = active;
 
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
-    if (active) {
-        emitSelectionChangedSignal();
-    } else {
+    if (!active) {
         color.setAlpha(150);
     }
 
@@ -185,6 +186,8 @@ void DolphinView::setActive(bool active)
     if (active) {
         m_viewAccessor.itemView()->setFocus();
         emit activated();
+        emitSelectionChangedSignal();
+        emit writeStateChanged(m_isFolderWritable);
     }
 
     m_viewModeController->indicateActivationChange(active);
@@ -970,6 +973,34 @@ void DolphinView::selectAndScrollToCreatedItem()
     m_createdItemUrl = KUrl();
 }
 
+void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
+{
+    if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
+        emit redirection(oldUrl, newUrl);
+        m_viewModeController->redirectToUrl(newUrl); // #186947
+    }
+}
+
+void DolphinView::restoreContentsPosition()
+{
+    if (!m_restoredContentsPosition.isNull()) {
+        const int x = m_restoredContentsPosition.x();
+        const int y = m_restoredContentsPosition.y();
+        m_restoredContentsPosition = QPoint();
+
+        QAbstractItemView* view = m_viewAccessor.itemView();
+        Q_ASSERT(view != 0);
+        view->horizontalScrollBar()->setValue(x);
+        view->verticalScrollBar()->setValue(y);
+    }
+}
+
+void DolphinView::slotUrlChangeRequested(const KUrl& url)
+{
+    m_viewModeController->setUrl(url);
+    updateWritableState();
+}
+
 void DolphinView::showHoverInformation(const KFileItem& item)
 {
     emit requestItemInfo(item);
@@ -989,6 +1020,18 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
+void DolphinView::slotDirListerStarted(const KUrl& url)
+{
+    // Disable the writestate temporary until it can be determined in a fast way
+    // in DolphinView::slotDirListerCompleted()
+    if (m_isFolderWritable) {
+        m_isFolderWritable = false;
+        emit writeStateChanged(m_isFolderWritable);
+    }
+
+    emit startedPathLoading(url);
+}
+
 void DolphinView::slotDirListerCompleted()
 {
     if (!m_expanderActive) {
@@ -1013,6 +1056,8 @@ void DolphinView::slotDirListerCompleted()
 
         m_newFileNames.clear();
     }
+
+    updateWritableState();
 }
 
 void DolphinView::slotLoadingCompleted()
@@ -1277,7 +1322,7 @@ void DolphinView::connectViewAccessor()
     connect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
             this, SLOT(slotRedirection(KUrl,KUrl)));
     connect(dirLister, SIGNAL(started(KUrl)),
-            this, SIGNAL(startedPathLoading(KUrl)));
+            this, SLOT(slotDirListerStarted(KUrl)));
     connect(dirLister, SIGNAL(completed()),
             this, SLOT(slotDirListerCompleted()));
     connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
@@ -1294,7 +1339,7 @@ void DolphinView::disconnectViewAccessor()
     disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
                this, SLOT(slotRedirection(KUrl,KUrl)));
     disconnect(dirLister, SIGNAL(started(KUrl)),
-               this, SIGNAL(startedPathLoading(KUrl)));
+               this, SLOT(slotDirListerStarted(KUrl)));
     disconnect(dirLister, SIGNAL(completed()),
                this, SLOT(slotDirListerCompleted()));
     disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
@@ -1305,6 +1350,21 @@ void DolphinView::disconnectViewAccessor()
                this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
 }
 
+void DolphinView::updateWritableState()
+{
+    const bool wasFolderWritable = m_isFolderWritable;
+    m_isFolderWritable = true;
+
+    const KFileItem item = m_viewAccessor.dirLister()->rootItem();
+    if (!item.isNull()) {
+        KFileItemListProperties capabilities(KFileItemList() << item);
+        m_isFolderWritable = capabilities.supportsWriting();
+    }
+    if (m_isFolderWritable != wasFolderWritable) {
+        emit writeStateChanged(m_isFolderWritable);
+    }
+}
+
 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) :
     m_rootUrl(),
     m_iconsView(0),
@@ -1503,26 +1563,4 @@ KDirLister* DolphinView::ViewAccessor::dirLister() const
     return dirModel()->dirLister();
 }
 
-void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
-{
-    if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
-        emit redirection(oldUrl, newUrl);
-        m_viewModeController->redirectToUrl(newUrl); // #186947
-    }
-}
-
-void DolphinView::restoreContentsPosition()
-{
-    if (!m_restoredContentsPosition.isNull()) {
-        const int x = m_restoredContentsPosition.x();
-        const int y = m_restoredContentsPosition.y();
-        m_restoredContentsPosition = QPoint();
-
-        QAbstractItemView* view = m_viewAccessor.itemView();
-        Q_ASSERT(view != 0);
-        view->horizontalScrollBar()->setValue(x);
-        view->verticalScrollBar()->setValue(y);
-    }
-}
-
 #include "dolphinview.moc"
index bb6108e1a305f5d2799bdcaaa5f880e74e43f659..91909710fa7da59f42ae8c1f51574187029da589 100644 (file)
@@ -529,6 +529,13 @@ signals:
      */
     void redirection(const KUrl& oldUrl, const KUrl& newUrl);
 
+    /**
+     * Is emitted when the write state of the folder has been changed. The application
+     * should disable all actions like "Create New..." that depend on the write
+     * state.
+     */
+    void writeStateChanged(bool isFolderWritable);
+
 protected:
     /** @see QWidget::mouseReleaseEvent */
     virtual void mouseReleaseEvent(QMouseEvent* event);
@@ -623,6 +630,12 @@ private slots:
      */
     void slotDeleteFileFinished(KJob* job);
 
+    /**
+     * Invoked when the directory lister has been started the
+     * loading of \a url.
+     */
+    void slotDirListerStarted(const KUrl& url);
+
     /**
      * Invoked when the directory lister has completed the loading of
      * items. Assures that pasted items and renamed items get seleced.
@@ -666,6 +679,8 @@ private slots:
      */
     void restoreContentsPosition();
 
+    void slotUrlChangeRequested(const KUrl& url);
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
@@ -726,6 +741,13 @@ private:
     void connectViewAccessor();
     void disconnectViewAccessor();
 
+    /**
+     * Updates m_isFolderWritable dependent on whether the folder represented by
+     * the current URL is writable. If the state has changed, the signal
+     * writeableStateChanged() will be emitted.
+     */
+    void updateWritableState();
+
 private:
     /**
      * Abstracts the access to the different view implementations
@@ -795,6 +817,7 @@ private:
     bool m_isContextMenuOpen : 1;   // TODO: workaround for Qt-issue 207192
     bool m_assureVisibleCurrentIndex : 1;
     bool m_expanderActive : 1;
+    bool m_isFolderWritable : 1;
 
     Mode m_mode;