From adde3d4e3cd21d35be78c6a827b4b69a05d6e10c Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 15 Dec 2010 18:40:08 +0000 Subject: [PATCH] Fix issue that the enabled state of the "Create New..." menu is not updated correctly in the column-view. BUG: 258534 FIXED-IN: 4.6.0 svn path=/trunk/KDE/kdebase/apps/; revision=1206749 --- src/dolphinviewcontainer.cpp | 30 +----------- src/dolphinviewcontainer.h | 2 - src/views/dolphinview.cpp | 94 +++++++++++++++++++++++++----------- src/views/dolphinview.h | 23 +++++++++ 4 files changed, 91 insertions(+), 58 deletions(-) diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 06682202d..8f934d163 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -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) diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 337452e5c..7586dc13f 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -265,8 +265,6 @@ private: bool isSearchUrl(const KUrl& url) const; private: - bool m_isFolderWritable; - QVBoxLayout* m_topLayout; KUrlNavigator* m_urlNavigator; DolphinSearchBox* m_searchBox; diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 46f7acf13..1e97d6864 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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>&)), @@ -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>&)), @@ -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" diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index bb6108e1a..91909710f 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -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; -- 2.47.3