]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / dolphinview.cpp
index 696caa04e2114d4ec30b944df62c34dec16d42e5..0450eb460a61cede4428994e5fc8760fbc6ed3cd 100644 (file)
@@ -90,6 +90,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_isContextMenuOpen(false),
     m_ignoreViewProperties(false),
     m_assureVisibleCurrentIndex(false),
+    m_selectClipboardItems(false),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_controller(0),
@@ -106,6 +107,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_rootUrl(),
     m_currentItemUrl(),
     m_createdItemUrl(),
+    m_selectedItems(),
     m_expandedDragSource(0)
 {
     m_topLayout = new QVBoxLayout(this);
@@ -128,6 +130,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
             this, SLOT(updateSortOrder(Qt::SortOrder)));
+    connect(m_controller, SIGNAL(sortFoldersFirstChanged(bool)),
+            this, SLOT(updateSortFoldersFirst(bool)));
     connect(m_controller, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
             this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
     connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
@@ -144,7 +148,7 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
             this, SIGNAL(redirection(KUrl, KUrl)));
     connect(m_dirLister, SIGNAL(completed()),
-            this, SLOT(restoreCurrentItem()));
+            this, SLOT(slotDirListerCompleted()));
     connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
             this, SLOT(slotRefreshItems()));
 
@@ -154,6 +158,10 @@ DolphinView::DolphinView(QWidget* parent,
     connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
             this, SLOT(observeCreatedItem(const KUrl&)));
 
+    // when a copy/move-operation has been finished, the pasted items should get selected
+    connect(KIO::FileUndoManager::self(), SIGNAL(jobRecordingFinished(CommandType)),
+           this, SLOT(slotJobRecordingFinished(CommandType)));
+
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
 }
@@ -184,10 +192,6 @@ void DolphinView::setActive(bool active)
 
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (active) {
-        // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
-        // bypasses the problem when having a split view and changing the active view to
-        // update the some URL dependent states. A nicer approach should be no big deal...
-        emit urlChanged(url());
         emit selectionChanged(selectedItems());
     } else {
         color.setAlpha(150);
@@ -408,7 +412,7 @@ void DolphinView::setZoomLevel(int level)
 
     if (level != zoomLevel()) {
         m_controller->setZoomLevel(level);
-        m_previewGenerator->updatePreviews();
+        m_previewGenerator->updateIcons();
         emit zoomLevelChanged(level);
     }
 }
@@ -442,6 +446,18 @@ Qt::SortOrder DolphinView::sortOrder() const
     return m_proxyModel->sortOrder();
 }
 
+void DolphinView::setSortFoldersFirst(bool foldersFirst)
+{
+    if (sortFoldersFirst() != foldersFirst) {
+        updateSortFoldersFirst(foldersFirst);
+    }
+}
+
+bool DolphinView::sortFoldersFirst() const
+{
+    return m_proxyModel->sortFoldersFirst();
+}
+
 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
 {
     const KUrl viewPropsUrl = viewPropertiesUrl();
@@ -595,7 +611,8 @@ QString DolphinView::statusBarText() const
 
 void DolphinView::setUrl(const KUrl& url)
 {
-    // remember current item candidate (see restoreCurrentItem())
+    // remember current item candidate (see slotDirListerCompleted())
+    m_selectClipboardItems = false;
     m_currentItemUrl = url;
     updateView(url, KUrl());
 }
@@ -817,6 +834,11 @@ void DolphinView::toggleSortOrder()
     setSortOrder(order);
 }
 
+void DolphinView::toggleSortFoldersFirst()
+{
+    setSortFoldersFirst(!sortFoldersFirst());
+}
+
 void DolphinView::toggleAdditionalInfo(QAction* action)
 {
     const KFileItemDelegate::Information info =
@@ -986,6 +1008,16 @@ void DolphinView::updateSortOrder(Qt::SortOrder order)
     emit sortOrderChanged(order);
 }
 
+void DolphinView::updateSortFoldersFirst(bool foldersFirst)
+{
+    ViewProperties props(viewPropertiesUrl());
+    props.setSortFoldersFirst(foldersFirst);
+
+    m_proxyModel->setSortFoldersFirst(foldersFirst);
+
+    emit sortFoldersFirstChanged(foldersFirst);
+}
+
 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info)
 {
     ViewProperties props(viewPropertiesUrl());
@@ -1109,6 +1141,21 @@ void DolphinView::selectAndScrollToCreatedItem()
     m_createdItemUrl = KUrl();
 }
 
+void DolphinView::restoreSelection()
+{
+    disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
+    changeSelection(m_selectedItems);
+}
+
+void DolphinView::slotJobRecordingFinished(CommandType command)
+{
+    // Assure that the pasted items get selected. This must be done
+    // asynchronously in slotDirListerCompleted().
+    m_selectClipboardItems = ((command == KIO::FileUndoManager::Copy) ||
+                              (command == KIO::FileUndoManager::Move)) &&
+                             !hasSelection();
+}
+
 void DolphinView::emitContentsMoved()
 {
     // only emit the contents moved signal if:
@@ -1147,16 +1194,45 @@ void DolphinView::slotRequestUrlChange(const KUrl& url)
     m_controller->setUrl(url);
 }
 
-void DolphinView::restoreCurrentItem()
+void DolphinView::slotDirListerCompleted()
 {
-    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
-    if (dirIndex.isValid()) {
-        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-        QAbstractItemView* view = itemView();
-        const bool clearSelection = !hasSelection();
-        view->setCurrentIndex(proxyIndex);
-        if (clearSelection) {
-            view->clearSelection();
+    if (!m_currentItemUrl.isEmpty()) {
+        // assure that the current item remains visible
+        const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
+        if (dirIndex.isValid()) {
+            const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+            QAbstractItemView* view = itemView();
+            const bool clearSelection = !hasSelection();
+            view->setCurrentIndex(proxyIndex);
+            if (clearSelection) {
+                view->clearSelection();
+            }
+        }
+        m_currentItemUrl.clear();
+    }
+
+    if (m_selectClipboardItems) {
+        m_selectClipboardItems = false;
+
+        // select all items that have been pasted from the clipboard to
+        // the current directory
+        const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+        const KUrl::List copiedUrls = KUrl::List::fromMimeData(mimeData);
+
+        QSet<QString> fileNames;
+        foreach (const KUrl& url, copiedUrls) {
+            fileNames.insert(url.fileName());
+        }
+
+        QItemSelectionModel* selectionModel = itemView()->selectionModel();
+        const int rowCount = m_proxyModel->rowCount();
+        for (int row = 0; row < rowCount; ++row) {
+            const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
+            const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+            const KUrl url = m_dolphinModel->itemForIndex(dirIndex).url();
+            if (fileNames.contains(url.fileName())) {
+                selectionModel->select(proxyIndex, QItemSelectionModel::Select);
+            }
         }
     }
 }
@@ -1183,6 +1259,11 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload)
 
     m_loadingDirectory = true;
 
+    if (reload) {
+        m_selectedItems = selectedItems();
+        connect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
+    }
+
     m_dirLister->stop();
     m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
 
@@ -1262,6 +1343,12 @@ void DolphinView::applyViewProperties(const KUrl& url)
         emit sortOrderChanged(sortOrder);
     }
 
+    const bool sortFoldersFirst = props.sortFoldersFirst();
+    if (sortFoldersFirst != m_proxyModel->sortFoldersFirst()) {
+        m_proxyModel->setSortFoldersFirst(sortFoldersFirst);
+        emit sortFoldersFirstChanged(sortFoldersFirst);
+    }
+
     KFileItemDelegate::InformationList info = props.additionalInfo();
     if (info != m_fileItemDelegate->showInformation()) {
         m_fileItemDelegate->setShowInformation(info);
@@ -1424,24 +1511,6 @@ QAbstractItemView* DolphinView::itemView() const
     return m_iconsView;
 }
 
-bool DolphinView::isCutItem(const KFileItem& item) const
-{
-    const QMimeData* mimeData = QApplication::clipboard()->mimeData();
-    const KUrl::List cutUrls = KUrl::List::fromMimeData(mimeData);
-
-    const KUrl& itemUrl = item.url();
-    KUrl::List::const_iterator it = cutUrls.begin();
-    const KUrl::List::const_iterator end = cutUrls.end();
-    while (it != end) {
-        if (*it == itemUrl) {
-            return true;
-        }
-        ++it;
-    }
-
-    return false;
-}
-
 void DolphinView::pasteToUrl(const KUrl& url)
 {
     KonqOperations::doPaste(this, url);
@@ -1477,4 +1546,5 @@ QMimeData* DolphinView::selectionMimeData() const
     return m_dolphinModel->mimeData(selection.indexes());
 }
 
+
 #include "dolphinview.moc"