]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Merge remote-tracking branch 'origin/KDE/4.10'
[dolphin.git] / src / views / dolphinview.cpp
index 70a7394274a65c3a8be9808e6993b8c4cfbffac8..9575ffba702f33de6cea6df8962135b147b1c181 100644 (file)
@@ -73,7 +73,7 @@
 #include "zoomlevelinfo.h"
 
 #ifdef HAVE_NEPOMUK
-    #include <Nepomuk/ResourceManager>
+    #include <Nepomuk2/ResourceManager>
 #endif
 
 namespace {
@@ -155,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>)),
@@ -342,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));
@@ -638,25 +641,25 @@ void DolphinView::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()
@@ -791,21 +794,34 @@ void DolphinView::slotItemsActivated(const QSet<int>& indexes)
 {
     Q_ASSERT(indexes.count() >= 2);
 
+    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;
+        }
+    }
+
     KFileItemList items;
+    items.reserve(indexes.count());
 
     QSetIterator<int> it(indexes);
     while (it.hasNext()) {
         const int index = it.next();
-        items.append(m_model->fileItem(index));
-    }
+        KFileItem item = m_model->fileItem(index);
 
-    foreach (const KFileItem& item, items) {
-        if (item.isDir()) {
+        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)
@@ -839,10 +855,10 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     bool nepomukRunning = false;
     bool indexingEnabled = false;
 #ifdef HAVE_NEPOMUK
-    nepomukRunning = (Nepomuk::ResourceManager::instance()->initialized());
+    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
 
@@ -1007,14 +1023,16 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
                          event->buttons(),
                          event->modifiers());
 
-    const QString error = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent);
+    QString error;
+    KonqOperations* op = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent, error);
     if (!error.isEmpty()) {
         emit errorMessage(error);
     }
 
-    if (destUrl == url()) {
+    if (op && destUrl == url()) {
         // Mark the dropped urls as selected.
-        markPastedUrlsAsSelected(event->mimeData());
+        m_clearSelectionBeforeSelectingNewItems = true;
+        connect(op, SIGNAL(urlPasted(KUrl)), this, SLOT(slotUrlPasted(KUrl)));
     }
 }
 
@@ -1050,6 +1068,11 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons
     }
 }
 
+void DolphinView::slotAboutToCreate(const KUrl::List& urls)
+{
+    m_selectedUrls << urls;
+}
+
 void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
 {
     const int currentCount = current.count();
@@ -1227,11 +1250,14 @@ void DolphinView::updateViewState()
 
         QSet<int> selectedItems = selectionManager->selectedItems();
 
-        for (QList<KUrl>::iterator it = m_selectedUrls.begin(); it != m_selectedUrls.end(); ++it) {
+        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);
-                m_selectedUrls.erase(it);
+                it = m_selectedUrls.erase(it);
+            } else {
+                 ++it;
             }
         }
 
@@ -1504,8 +1530,11 @@ void DolphinView::applyModeToView()
 
 void DolphinView::pasteToUrl(const KUrl& url)
 {
-    markPastedUrlsAsSelected(QApplication::clipboard()->mimeData());
-    KonqOperations::doPaste(this, url);
+    KonqOperations* op = KonqOperations::doPasteV2(this, url);
+    if (op) {
+        m_clearSelectionBeforeSelectingNewItems = true;
+        connect(op, SIGNAL(aboutToCreate(KUrl::List)), this, SLOT(slotAboutToCreate(KUrl::List)));
+    }
 }
 
 KUrl::List DolphinView::simplifiedSelectedUrls() const
@@ -1533,18 +1562,6 @@ QMimeData* DolphinView::selectionMimeData() const
     return m_model->createMimeData(selectedIndexes);
 }
 
-void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData)
-{
-    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-    KUrl::List destUrls;
-    foreach (const KUrl& source, sourceUrls) {
-        KUrl destination(url().url() + '/' + source.fileName());
-        destUrls << destination;
-    }
-    markUrlsAsSelected(destUrls);
-    m_clearSelectionBeforeSelectingNewItems = true;
-}
-
 void DolphinView::updateWritableState()
 {
     const bool wasFolderWritable = m_isFolderWritable;