]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Merge remote-tracking branch 'origin/KDE/4.9' into KDE/4.10
[dolphin.git] / src / views / dolphinview.cpp
index 9051d9827a8667338d5b1c66f150c09ff5334805..f0fad1976e81122444ed912a2c9c5ecc19faee4d 100644 (file)
@@ -101,6 +101,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
     m_scrollToCurrentItem(false),
     m_restoredContentsPosition(),
     m_selectedUrls(),
+    m_clearSelectionBeforeSelectingNewItems(false),
     m_versionControlObserver(0)
 {
     m_topLayout = new QVBoxLayout(this);
@@ -154,6 +155,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
 
     connect(m_model, SIGNAL(directoryLoadingStarted()),       this, SLOT(slotDirectoryLoadingStarted()));
     connect(m_model, SIGNAL(directoryLoadingCompleted()),     this, SLOT(slotDirectoryLoadingCompleted()));
+    connect(m_model, SIGNAL(directoryLoadingCanceled()),      this, SIGNAL(directoryLoadingCanceled()));
     connect(m_model, SIGNAL(directoryLoadingProgress(int)),   this, SIGNAL(directoryLoadingProgress(int)));
     connect(m_model, SIGNAL(directorySortingProgress(int)),   this, SIGNAL(directorySortingProgress(int)));
     connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
@@ -341,10 +343,12 @@ int DolphinView::itemsCount() const
 KFileItemList DolphinView::selectedItems() const
 {
     const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
-    const QSet<int> selectedIndexes = selectionManager->selectedItems();
+    QList<int> selectedIndexes = selectionManager->selectedItems().toList();
+
+    qSort(selectedIndexes);
 
     KFileItemList selectedItems;
-    QSetIterator<int> it(selectedIndexes);
+    QListIterator<int> it(selectedIndexes);
     while (it.hasNext()) {
         const int index = it.next();
         selectedItems.append(m_model->fileItem(index));
@@ -598,6 +602,8 @@ void DolphinView::setUrl(const KUrl& url)
         return;
     }
 
+    clearSelection();
+
     emit urlAboutToBeChanged(url);
     m_url = url;
 
@@ -628,31 +634,32 @@ void DolphinView::invertSelection()
 
 void DolphinView::clearSelection()
 {
+    m_selectedUrls.clear();
     m_container->controller()->selectionManager()->clearSelection();
 }
 
 void DolphinView::renameSelectedItems()
 {
     const KFileItemList items = selectedItems();
-     if (items.isEmpty()) {
-         return;
-     }
-
-     if (items.count() == 1 && GeneralSettings::renameInline()) {
-         const int index = m_model->index(items.first());
-         m_view->editRole(index, "text");
-     } else {
-         RenameDialog* dialog = new RenameDialog(this, items);
-         dialog->setAttribute(Qt::WA_DeleteOnClose);
-         dialog->show();
-         dialog->raise();
-         dialog->activateWindow();
-     }
-
-     // Assure that the current index remains visible when KFileItemModel
-     // will notify the view about changed items (which might result in
-     // a changed sorting).
-     m_assureVisibleCurrentIndex = true;
+    if (items.isEmpty()) {
+        return;
+    }
+
+    if (items.count() == 1 && GeneralSettings::renameInline()) {
+        const int index = m_model->index(items.first());
+        m_view->editRole(index, "text");
+    } else {
+        RenameDialog* dialog = new RenameDialog(this, items);
+        dialog->setAttribute(Qt::WA_DeleteOnClose);
+        dialog->show();
+        dialog->raise();
+        dialog->activateWindow();
+    }
+
+    // Assure that the current index remains visible when KFileItemModel
+    // will notify the view about changed items (which might result in
+    // a changed sorting).
+    m_assureVisibleCurrentIndex = true;
 }
 
 void DolphinView::trashSelectedItems()
@@ -787,29 +794,34 @@ void DolphinView::slotItemsActivated(const QSet<int>& indexes)
 {
     Q_ASSERT(indexes.count() >= 2);
 
-    KFileItemList items;
-
-    QSetIterator<int> it(indexes);
-    while (it.hasNext()) {
-        const int index = it.next();
-        items.append(m_model->fileItem(index));
-    }
-
-    if (items.count() > 5) {
-        QString question = QString("Are you sure you want to open %1 items?").arg(items.count());
+    if (indexes.count() > 5) {
+        QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count());
         const int answer = KMessageBox::warningYesNo(this, question);
         if (answer != KMessageBox::Yes) {
             return;
         }
     }
 
-    foreach (const KFileItem& item, items) {
-        if (item.isDir()) {
+    KFileItemList items;
+    items.reserve(indexes.count());
+
+    QSetIterator<int> it(indexes);
+    while (it.hasNext()) {
+        const int index = it.next();
+        KFileItem item = m_model->fileItem(index);
+
+        if (item.isDir()) { // Open folders in new tabs
             emit tabRequested(item.url());
         } else {
-            emit itemActivated(item);
+            items.append(item);
         }
     }
+
+    if (items.count() == 1) {
+        emit itemActivated(items.first());
+    } else if (items.count() > 1) {
+        emit itemsActivated(items);
+    }
 }
 
 void DolphinView::slotItemMiddleClicked(int index)
@@ -846,7 +858,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     nepomukRunning = (Nepomuk2::ResourceManager::instance()->initialized());
     if (nepomukRunning) {
         KConfig config("nepomukserverrc");
-        indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", false);
+        indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", true);
     }
 #endif
 
@@ -1178,8 +1190,11 @@ QString DolphinView::viewPropertiesContext() const
 
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
-    markUrlAsCurrent(url);
-    markUrlsAsSelected(QList<KUrl>() << url);
+    if (m_active) {
+        clearSelection();
+        markUrlAsCurrent(url);
+        markUrlsAsSelected(QList<KUrl>() << url);
+    }
 }
 
 void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
@@ -1219,20 +1234,27 @@ void DolphinView::updateViewState()
     }
 
     if (!m_selectedUrls.isEmpty()) {
-        clearSelection();
-
         KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+
+        if (m_clearSelectionBeforeSelectingNewItems) {
+            selectionManager->clearSelection();
+            m_clearSelectionBeforeSelectingNewItems = false;
+        }
+
         QSet<int> selectedItems = selectionManager->selectedItems();
 
-        foreach (const KUrl& url, m_selectedUrls) {
-            const int index = m_model->index(url);
+        QList<KUrl>::iterator it = m_selectedUrls.begin();
+        while (it != m_selectedUrls.end()) {
+            const int index = m_model->index(*it);
             if (index >= 0) {
                 selectedItems.insert(index);
+                it = m_selectedUrls.erase(it);
+            } else {
+                 ++it;
             }
         }
 
         selectionManager->setSelectedItems(selectedItems);
-        m_selectedUrls.clear();
     }
 }
 
@@ -1356,9 +1378,18 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
         if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
             const KUrl oldUrl = oldItem.url();
 
-            QHash<QByteArray, QVariant> data;
-            data.insert(role, value);
-            m_model->setData(index, data);
+            const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
+            const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+            if (!newNameExistsAlready) {
+                // Only change the data in the model if no item with the new name
+                // is in the model yet. If there is an item with the new name
+                // already, calling KonqOperations::rename() will open a dialog
+                // asking for a new name, and KFileItemModel will update the
+                // data when the dir lister signals that the file name has changed.
+                QHash<QByteArray, QVariant> data;
+                data.insert(role, value);
+                m_model->setData(index, data);
+            }
 
             KonqOperations::rename(this, oldUrl, newName);
         }
@@ -1530,6 +1561,7 @@ void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData)
         destUrls << destination;
     }
     markUrlsAsSelected(destUrls);
+    m_clearSelectionBeforeSelectingNewItems = true;
 }
 
 void DolphinView::updateWritableState()