]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / views / dolphinview.cpp
index 0237a1dca37b7036533032e47b3a48cff0ebef67..c2e998e5a4f976c448bb155f8e3bd4cdee2ae7c7 100644 (file)
@@ -41,7 +41,6 @@
 #include <kjob.h>
 #include <kmenu.h>
 #include <kmessagebox.h>
-#include <kmimetyperesolver.h>
 #include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
 #include <konqmimedata.h>
@@ -83,7 +82,6 @@ DolphinView::DolphinView(QWidget* parent,
     m_viewModeController(0),
     m_viewAccessor(proxyModel),
     m_selectionChangedTimer(0),
-    m_rootUrl(),
     m_activeItemUrl(),
     m_restoredContentsPosition(),
     m_createdItemUrl(),
@@ -127,14 +125,6 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_dolphinViewController, SIGNAL(urlChangeRequested(KUrl)),
             m_viewModeController, SLOT(setUrl(KUrl)));
 
-    KDirLister* dirLister = m_viewAccessor.dirLister();
-    connect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
-            this, SLOT(slotRedirection(KUrl,KUrl)));
-    connect(dirLister, SIGNAL(completed()),
-            this, SLOT(slotDirListerCompleted()));
-    connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
-            this, SLOT(slotRefreshItems()));
-
     // 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:
@@ -279,18 +269,9 @@ bool DolphinView::supportsCategorizedSorting() const
     return m_viewAccessor.supportsCategorizedSorting();
 }
 
-bool DolphinView::hasSelection() const
+KFileItemList DolphinView::items() const
 {
-    const QAbstractItemView* view = m_viewAccessor.itemView();
-    return (view != 0) && view->selectionModel()->hasSelection();
-}
-
-void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
-{
-    foreach (const KUrl& url, urls) {
-        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
-        m_selectedItems.append(item);
-    }
+    return m_viewAccessor.dirLister()->items();
 }
 
 KFileItemList DolphinView::selectedItems() const
@@ -324,9 +305,21 @@ int DolphinView::selectedItemsCount() const
     return view->selectionModel()->selectedIndexes().count();
 }
 
-QItemSelectionModel* DolphinView::selectionModel() const
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
+{
+    foreach (const KUrl& url, urls) {
+        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+        m_selectedItems.append(item);
+    }
+}
+
+void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
 {
-    return m_viewAccessor.itemView()->selectionModel();
+    const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern);
+    const QItemSelectionModel::SelectionFlags command = enabled
+                                                      ? QItemSelectionModel::Select
+                                                      : QItemSelectionModel::Deselect;
+    m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);
 }
 
 void DolphinView::setZoomLevel(int level)
@@ -525,12 +518,10 @@ void DolphinView::setUrl(const KUrl& url)
         return;
     }
 
-    // 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.
     const bool hadSelection = hasSelection();
-    QAbstractItemView* view = m_viewAccessor.itemView();
-    disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
-               this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+
+    // The selection model and directory lister might change in the case of the column view:
+    disconnectViewAccessor();
 
     m_newFileNames.clear();
 
@@ -545,10 +536,9 @@ void DolphinView::setUrl(const KUrl& url)
 
     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)));
+    // Reconnect to the (probably) new selection model and directory lister
+    connectViewAccessor();
+
     if (hadSelection || hasSelection()) {
         emitSelectionChangedSignal();
     }
@@ -699,40 +689,6 @@ void DolphinView::setCategorizedSorting(bool categorized)
     emit categorizedSortingChanged();
 }
 
-void DolphinView::toggleSortOrder()
-{
-    const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ?
-                                Qt::DescendingOrder :
-                                Qt::AscendingOrder;
-    setSortOrder(order);
-}
-
-void DolphinView::toggleSortFoldersFirst()
-{
-    setSortFoldersFirst(!sortFoldersFirst());
-}
-
-void DolphinView::toggleAdditionalInfo(QAction* action)
-{
-    const KFileItemDelegate::Information info =
-        static_cast<KFileItemDelegate::Information>(action->data().toInt());
-
-    KFileItemDelegate::InformationList list = additionalInfo();
-
-    const bool show = action->isChecked();
-
-    const int index = list.indexOf(info);
-    const bool containsInfo = (index >= 0);
-    if (show && !containsInfo) {
-        list.append(info);
-        setAdditionalInfo(list);
-    } else if (!show && containsInfo) {
-        list.removeAt(index);
-        setAdditionalInfo(list);
-        Q_ASSERT(list.indexOf(info) < 0);
-    }
-}
-
 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
 {
     QWidget::mouseReleaseEvent(event);
@@ -935,13 +891,18 @@ bool DolphinView::itemsExpandable() const
 
 void DolphinView::restoreState(QDataStream& stream)
 {
-    // current item
+    // Restore the URL of the current item that had the keyboard focus
     stream >> m_activeItemUrl;
 
-    // view position
+    // Restore the root URL
+    KUrl rootUrl;
+    stream >> rootUrl;
+    m_viewAccessor.setRootUrl(rootUrl);
+
+    // Restore the view position
     stream >> m_restoredContentsPosition;
 
-    // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
+    // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
     QSet<KUrl> urlsToExpand;
     stream >> urlsToExpand;
     const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand);
@@ -956,7 +917,7 @@ void DolphinView::restoreState(QDataStream& stream)
 
 void DolphinView::saveState(QDataStream& stream)
 {
-    // current item
+    // Save the URL of the current item that has the keyboard focus
     KFileItem currentItem;
     const QAbstractItemView* view = m_viewAccessor.itemView();
 
@@ -966,22 +927,31 @@ void DolphinView::saveState(QDataStream& stream)
         currentItem = m_viewAccessor.dirModel()->itemForIndex(dirModelIndex);
     }
 
-    KUrl currentUrl;
+    KUrl currentItemUrl;
     if (!currentItem.isNull()) {
-        currentUrl = currentItem.url();
+        currentItemUrl = currentItem.url();
     }
 
-    stream << currentUrl;
+    stream << currentItemUrl;
+
+    // Save the root URL
+    stream << m_viewAccessor.rootUrl();
 
-    // view position
+    // Save view position
     const int x = view->horizontalScrollBar()->value();
     const int y = view->verticalScrollBar()->value();
     stream << QPoint(x, y);
 
-    // expanded folders (only relevant for the details view - the set will be empty in other view modes)
+    // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
     stream << m_viewAccessor.expandedUrls();
 }
 
+bool DolphinView::hasSelection() const
+{
+    const QAbstractItemView* view = m_viewAccessor.itemView();
+    return (view != 0) && view->selectionModel()->hasSelection();
+}
+
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
     m_createdItemUrl = url;
@@ -1131,6 +1101,7 @@ void DolphinView::applyViewProperties()
     if (m_viewAccessor.itemView() == 0) {
         createView();
     }
+
     Q_ASSERT(m_viewAccessor.itemView() != 0);
     Q_ASSERT(m_viewAccessor.itemDelegate() != 0);
 
@@ -1202,8 +1173,7 @@ void DolphinView::createView()
     const int zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(view->iconSize());
     m_viewModeController->setZoomLevel(zoomLevel);
 
-    connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
-            this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+    connectViewAccessor();
 
     setFocusProxy(m_viewAccessor.layoutTarget());
     m_topLayout->insertWidget(1, m_viewAccessor.layoutTarget());
@@ -1216,10 +1186,7 @@ void DolphinView::deleteView()
     m_dolphinViewController->setItemView(0);
 
     if (view != 0) {
-        if (view->selectionModel() != 0) {
-            disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
-                       this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
-        }
+        disconnectViewAccessor();
 
         // It's important to set the keyboard focus to the parent
         // before deleting the view: Otherwise when having a split
@@ -1282,7 +1249,62 @@ void DolphinView::addNewFileNames(const QMimeData* mimeData)
     }
 }
 
+QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const
+{
+    QItemSelection matchingIndexes;
+    const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
+    const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
+
+    const int rowCount = proxyModel->rowCount(parent);
+
+    for (int row = 0; row < rowCount; ++row) {
+        QModelIndex index = proxyModel->index(row, 0, parent);
+        QModelIndex sourceIndex = proxyModel->mapToSource(index);
+
+        if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
+            matchingIndexes += QItemSelectionRange(index);
+        }
+
+        if (proxyModel->hasChildren(index)) {
+            matchingIndexes += childrenMatchingPattern(index, pattern);
+        }
+    }
+
+    return matchingIndexes;
+}
+
+void DolphinView::connectViewAccessor()
+{
+    KDirLister* dirLister = m_viewAccessor.dirLister();
+    connect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
+            this, SLOT(slotRedirection(KUrl,KUrl)));
+    connect(dirLister, SIGNAL(completed()),
+            this, SLOT(slotDirListerCompleted()));
+    connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+            this, SLOT(slotRefreshItems()));
+
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+            this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+}
+
+void DolphinView::disconnectViewAccessor()
+{
+    KDirLister* dirLister = m_viewAccessor.dirLister();
+    disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
+               this, SLOT(slotRedirection(KUrl,KUrl)));
+    disconnect(dirLister, SIGNAL(completed()),
+               this, SLOT(slotDirListerCompleted()));
+    disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+               this, SLOT(slotRefreshItems()));
+
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+               this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection)));
+}
+
 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) :
+    m_rootUrl(),
     m_iconsView(0),
     m_detailsView(0),
     m_columnsContainer(0),
@@ -1323,6 +1345,12 @@ void DolphinView::ViewAccessor::createView(QWidget* parent,
         m_columnsContainer = new DolphinColumnViewContainer(parent,
                                                             dolphinViewController,
                                                             viewModeController);
+        if (!m_rootUrl.isEmpty() && m_rootUrl.isParentOf(viewModeController->url())) {
+            // The column-view must show several columns starting with m_rootUrl as
+            // first column and viewModeController->url() as last column.
+            m_columnsContainer->showColumn(m_rootUrl);
+            m_columnsContainer->showColumn(viewModeController->url());
+        }
         break;
 
     default:
@@ -1366,7 +1394,6 @@ void DolphinView::ViewAccessor::deleteView()
     }
 }
 
-
 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url)
 {
     if (m_columnsContainer != 0) {
@@ -1404,9 +1431,14 @@ QWidget* DolphinView::ViewAccessor::layoutTarget() const
     return itemView();
 }
 
+void DolphinView::ViewAccessor::setRootUrl(const KUrl& rootUrl)
+{
+    m_rootUrl = rootUrl;
+}
+
 KUrl DolphinView::ViewAccessor::rootUrl() const
 {
-    return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : KUrl();
+    return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : m_rootUrl;
 }
 
 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
@@ -1419,7 +1451,6 @@ bool DolphinView::ViewAccessor::itemsExpandable() const
     return (m_detailsView != 0) && m_detailsView->itemsExpandable();
 }
 
-
 QSet<KUrl> DolphinView::ViewAccessor::expandedUrls() const
 {
     if (m_detailsView != 0) {