]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
fixed krazy string warning
[dolphin.git] / src / dolphinview.cpp
index 48df3e20f7073510c74e60271b7a5fd7a6408eda..5cea1bde0fa859624c2642a897c46773651beb97 100644 (file)
@@ -67,6 +67,8 @@
 #include "viewproperties.h"
 #include "zoomlevelinfo.h"
 
+#include <kdebug.h>
+
 /**
  * Helper function for sorting items with qSort() in
  * DolphinView::renameSelectedItems().
@@ -107,6 +109,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_currentItemUrl(),
     m_createdItemUrl(),
     m_selectedItems(),
+    m_newFileNames(),
     m_expandedDragSource(0)
 {
     m_topLayout = new QVBoxLayout(this);
@@ -147,7 +150,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()));
 
@@ -606,7 +609,9 @@ QString DolphinView::statusBarText() const
 
 void DolphinView::setUrl(const KUrl& url)
 {
-    // remember current item candidate (see restoreCurrentItem())
+    m_newFileNames.clear();
+
+    // remember current item candidate (see slotDirListerCompleted())
     m_currentItemUrl = url;
     updateView(url, KUrl());
 }
@@ -643,16 +648,19 @@ void DolphinView::renameSelectedItems()
     if (itemCount > 1) {
         // More than one item has been selected for renaming. Open
         // a rename dialog and rename all items afterwards.
-        RenameDialog dialog(this, items);
-        if (dialog.exec() == QDialog::Rejected) {
+        QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+        if (dialog->exec() == QDialog::Rejected) {
+            delete dialog;
             return;
         }
 
-        const QString newName = dialog.newName();
+        const QString newName = dialog->newName();
         if (newName.isEmpty()) {
-            emit errorMessage(dialog.errorString());
+            emit errorMessage(dialog->errorString());
+            delete dialog;
             return;
         }
+        delete dialog;
 
         // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
         // as one operation instead of n rename operations like it is done now...
@@ -691,16 +699,19 @@ void DolphinView::renameSelectedItems()
     } else {
         Q_ASSERT(itemCount == 1);
 
-        RenameDialog dialog(this, items);
-        if (dialog.exec() == QDialog::Rejected) {
+        QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+        if (dialog->exec() == QDialog::Rejected) {
+            delete dialog;
             return;
         }
 
-        const QString& newName = dialog.newName();
+        const QString newName = dialog->newName();
         if (newName.isEmpty()) {
-            emit errorMessage(dialog.errorString());
+            emit errorMessage(dialog->errorString());
+            delete dialog;
             return;
         }
+        delete dialog;
 
         const KUrl& oldUrl = items.first().url();
         KUrl newUrl = oldUrl;
@@ -979,6 +990,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
                            const KUrl& destPath,
                            QDropEvent* event)
 {
+    addNewFileNames(event->mimeData());
     DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
 }
 
@@ -1179,9 +1191,10 @@ void DolphinView::slotRequestUrlChange(const KUrl& url)
     m_controller->setUrl(url);
 }
 
-void DolphinView::restoreCurrentItem()
+void DolphinView::slotDirListerCompleted()
 {
     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);
@@ -1194,6 +1207,23 @@ void DolphinView::restoreCurrentItem()
         }
         m_currentItemUrl.clear();
     }
+
+    if (!m_newFileNames.isEmpty()) {
+        // select all newly added items created by a paste operation or
+        // a drag & drop operation
+        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 (m_newFileNames.contains(url.fileName())) {
+                selectionModel->select(proxyIndex, QItemSelectionModel::Select);
+            }
+        }
+
+        m_newFileNames.clear();
+    }
 }
 
 void DolphinView::slotRefreshItems()
@@ -1470,26 +1500,9 @@ 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)
 {
+    addNewFileNames(QApplication::clipboard()->mimeData());
     KonqOperations::doPaste(this, url);
 }
 
@@ -1523,5 +1536,12 @@ QMimeData* DolphinView::selectionMimeData() const
     return m_dolphinModel->mimeData(selection.indexes());
 }
 
+void DolphinView::addNewFileNames(const QMimeData* mimeData)
+{
+    const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+    foreach (const KUrl& url, urls) {
+        m_newFileNames.insert(url.fileName());
+    }
+}
 
 #include "dolphinview.moc"