]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Fixed issue in method naturalCompare: strings having numbers with the same amount...
[dolphin.git] / src / dolphinview.cpp
index d66cfd9246a9be523ceee5d39d18a14ef21b97f1..c0c18f90e85014d5860ffcd55e68b29eb853c3f4 100644 (file)
@@ -31,7 +31,7 @@
 #include <kurl.h>
 #include <klocale.h>
 #include <kio/netaccess.h>
-#include <kio/renamedlg.h>
+#include <kio/renamedialog.h>
 #include <kmimetyperesolver.h>
 #include <assert.h>
 
@@ -105,11 +105,12 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
 
     m_dirModel = new KDirModel();
     m_dirModel->setDirLister(m_dirLister);
+    m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory);
 
     m_proxyModel = new DolphinSortFilterProxyModel(this);
     m_proxyModel->setSourceModel(m_dirModel);
 
-    m_iconsView->setModel(m_dirModel);   // TODO: using m_proxyModel crashes when clicking on an item
+    m_iconsView->setModel(m_proxyModel);
 
     KFileItemDelegate* delegate = new KFileItemDelegate(this);
     delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
@@ -137,7 +138,7 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
     connect(m_iconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
             this, SLOT(emitSelectionChangedSignal()));
 
-    startDirLister(m_urlNavigator->url());
+    loadDirectory(m_urlNavigator->url());
 }
 
 DolphinView::~DolphinView()
@@ -480,21 +481,24 @@ bool DolphinView::hasSelection() const
 
 KFileItemList DolphinView::selectedItems() const
 {
-    QItemSelectionModel* selModel = m_iconsView->selectionModel();
-    assert(selModel != 0);
+    // Our view has a selection, we will map them back to the DirModel
+    // and then fill the KFileItemList.
+    assert(m_iconsView && m_iconsView->selectionModel());
 
+    const QItemSelection selection = m_proxyModel->mapSelectionToSource(m_iconsView->selectionModel()->selection());
     KFileItemList itemList;
-    if (selModel->hasSelection()) {
-       const QModelIndexList indexList = selModel->selectedIndexes();
-
-        QModelIndexList::const_iterator end = indexList.end();
-        for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
-           KFileItem* item = m_dirModel->itemForIndex(*it);
-           if (item != 0) {
-               itemList.append(item);
-           }
+
+    const QModelIndexList indexList = selection.indexes();
+    QModelIndexList::const_iterator end = indexList.end();
+    for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
+        assert((*it).isValid());
+
+        KFileItem* item = m_dirModel->itemForIndex(*it);
+        if (item != 0) {
+            itemList.append(item);
         }
     }
+
     return itemList;
 }
 
@@ -542,11 +546,11 @@ void DolphinView::rename(const KUrl& source, const QString& newName)
     if (destExists) {
         // the destination already exists, hence ask the user
         // how to proceed...
-        KIO::RenameDlg renameDialog(this,
-                                    i18n("File Already Exists"),
-                                    source.path(),
-                                    dest.path(),
-                                    KIO::M_OVERWRITE);
+        KIO::RenameDialog renameDialog(this,
+                                       i18n("File Already Exists"),
+                                       source.path(),
+                                       dest.path(),
+                                       KIO::M_OVERWRITE);
         switch (renameDialog.exec()) {
             case KIO::R_OVERWRITE:
                 // the destination should be overwritten
@@ -660,7 +664,7 @@ void DolphinView::loadDirectory(const KUrl& url)
 
 void DolphinView::triggerItem(const QModelIndex& index)
 {
-    KFileItem* item = m_dirModel->itemForIndex(index);
+    KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
     if (item == 0) {
         return;
     }
@@ -963,8 +967,18 @@ void DolphinView::slotChangeNameFilter(const QString& nameFilter)
     adjustedFilter.insert(0, '*');
     adjustedFilter.append('*');
 
+    // Use the ProxyModel to filter:
+    // This code is #ifdefed as setNameFilter behaves
+    // slightly different than the QSortFilterProxyModel
+    // as it will not remove directories. I will ask
+    // our beloved usability experts for input
+    // -- z.
+#if 0
     m_dirLister->setNameFilter(adjustedFilter);
     m_dirLister->emitChanges();
+#else
+    m_proxyModel->setFilterRegExp( nameFilter );
+#endif
 }
 
 void DolphinView::applyModeToView()