]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Use K_GLOBAL_STATIC for the previously committed workaround to bypass a X11-issue...
[dolphin.git] / src / views / dolphinview.cpp
index 73a0c63c3072761c1091775a37268f798ec7122a..d4f489615cfc6853c5f5e4850b2a3e7f7015032b 100644 (file)
@@ -55,7 +55,7 @@
 #include "dolphinviewcontroller.h"
 #include "dolphindetailsview.h"
 #include "dolphinfileitemdelegate.h"
-#include "dolphinnewmenuobserver.h"
+#include "dolphinnewfilemenuobserver.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphin_detailsmodesettings.h"
 #include "dolphiniconsview.h"
@@ -86,14 +86,12 @@ DolphinView::DolphinView(QWidget* parent,
     m_storedCategorizedSorting(false),
     m_tabsForFiles(false),
     m_isContextMenuOpen(false),
-    m_ignoreViewProperties(false),
     m_assureVisibleCurrentIndex(false),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_dolphinViewController(0),
     m_viewModeController(0),
     m_viewAccessor(proxyModel),
-    m_selectionModel(0),
     m_selectionChangedTimer(0),
     m_rootUrl(),
     m_activeItemUrl(),
@@ -150,7 +148,7 @@ DolphinView::DolphinView(QWidget* parent,
     // 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
     // creation is done asynchronously, several signals must be checked:
-    connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
+    connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
             this, SLOT(observeCreatedItem(const KUrl&)));
 
     m_selectionChangedTimer = new QTimer(this);
@@ -441,8 +439,6 @@ void DolphinView::reload()
 
 void DolphinView::refresh()
 {
-    m_ignoreViewProperties = false;
-
     const bool oldActivationState = m_active;
     const int oldZoomLevel = m_viewModeController->zoomLevel();
     m_active = true;
@@ -540,30 +536,33 @@ QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) c
 
 void DolphinView::setUrl(const KUrl& url)
 {
-    if (m_viewModeController->url() != url) {
-        m_newFileNames.clear();
+    if (m_viewModeController->url() == url) {
+        return;
+    }
 
-        m_viewModeController->setUrl(url); // emits urlChanged, which we forward
-        m_viewAccessor.prepareUrlChange(url);
-        applyViewProperties();
-        loadDirectory(url);
+    // The selection model might change in the case of the column view. Disconnect
+    // from the current selection model and reconnect later after the URL switch.
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+               this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
 
-        // When changing the URL there is no need to keep the version
-        // data of the previous URL.
-        m_viewAccessor.dirModel()->clearVersionData();
+    m_newFileNames.clear();
 
-        emit startedPathLoading(url);
-    }
+    m_viewModeController->setUrl(url); // emits urlChanged, which we forward
+    m_viewAccessor.prepareUrlChange(url);
+    applyViewProperties();
+    loadDirectory(url);
 
-    // the selection model might have changed in the case of a column view
-    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
-    if (m_selectionModel != selectionModel) {
-        disconnect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
-                   this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
-        m_selectionModel = selectionModel;
-        connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
-                this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
-    }
+    // When changing the URL there is no need to keep the version
+    // data of the previous URL.
+    m_viewAccessor.dirModel()->clearVersionData();
+
+    emit startedPathLoading(url);
+
+    // Reconnect to the (probably) new selection model
+    view = m_viewAccessor.itemView();
+    connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+            this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
 }
 
 void DolphinView::selectAll()
@@ -974,18 +973,18 @@ void DolphinView::updateAdditionalInfoActions(KActionCollection* collection)
 {
     const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
 
-    const KFileItemDelegate::InformationList checkedInfos = m_viewAccessor.itemDelegate()->showInformation();
-    const KFileItemDelegate::InformationList infos = infoAccessor.keys();
+    const KFileItemDelegate::InformationList checkedInfo = m_viewAccessor.itemDelegate()->showInformation();
+    const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys();
 
     const bool enable = (m_mode == DolphinView::DetailsView) ||
                         (m_mode == DolphinView::IconsView);
 
-    foreach (const KFileItemDelegate::Information& info, infos) {
+    foreach (const KFileItemDelegate::Information& info, infoKeys) {
         const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::AdditionalInfoType);
         QAction* action = collection->action(name);
         Q_ASSERT(action != 0);
         action->setEnabled(enable);
-        action->setChecked(checkedInfos.contains(info));
+        action->setChecked(checkedInfo.contains(info));
     }
 }
 
@@ -1190,10 +1189,6 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload)
 
 void DolphinView::applyViewProperties()
 {
-    if (m_ignoreViewProperties) {
-        return;
-    }
-
     const ViewProperties props(rootUrl());
 
     const Mode mode = props.viewMode();
@@ -1260,39 +1255,32 @@ void DolphinView::applyViewProperties()
         // the used zoom level of the controller must be adjusted manually:
         updateZoomLevel(oldZoomLevel);
     }
-
-    if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
-        // During the lifetime of a DolphinView instance the global view properties
-        // should not be changed. This allows e. g. to split a view and use different
-        // view properties for each view.
-        m_ignoreViewProperties = true;
-    }
 }
 
 void DolphinView::createView()
 {
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    if ((view != 0) && (view->selectionModel() != 0)) {
+        disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+                   this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+    }
+
     deleteView();
 
     Q_ASSERT(m_viewAccessor.itemView() == 0);
     m_viewAccessor.createView(this, m_dolphinViewController, m_viewModeController, m_mode);
 
-    QAbstractItemView* view = m_viewAccessor.itemView();
+    view = m_viewAccessor.itemView();
     Q_ASSERT(view != 0);
     view->installEventFilter(this);
     view->viewport()->installEventFilter(this);
 
     m_dolphinViewController->setItemView(view);
 
-    // When changing the view mode, the selection is lost due to reinstantiating
-    // a new item view with a custom selection model. Pass the ownership of the
-    // selection model to DolphinView, so that it can be shared by all item views.
-    if (m_selectionModel != 0) {
-        view->setSelectionModel(m_selectionModel);
-    } else {
-        m_selectionModel = view->selectionModel();
-    }
-    m_selectionModel->setParent(this);
-    connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+    const int zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(view->iconSize());
+    m_viewModeController->setZoomLevel(zoomLevel);
+
+    connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
             this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
 
     setFocusProxy(m_viewAccessor.layoutTarget());