]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
assure that no expensive operations are done when the Information Panel has been...
[dolphin.git] / src / dolphinview.cpp
index 3e1cddfdac683f7445a24e2aa08cad4b6a6af3fd..9eadcecb206c9a95701257ed6c1ee67752ae90d8 100644 (file)
@@ -33,6 +33,7 @@
 #include <kdirlister.h>
 #include <kfilepreviewgenerator.h>
 #include <kiconeffect.h>
+#include <kfileitem.h>
 #include <klocale.h>
 #include <kio/deletejob.h>
 #include <kio/netaccess.h>
@@ -44,6 +45,7 @@
 #include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
 #include <konqmimedata.h>
+#include <kstringhandler.h>
 #include <ktoggleaction.h>
 #include <kurl.h>
 
 #include "viewproperties.h"
 #include "zoomlevelinfo.h"
 
+/**
+ * Helper function for sorting items with qSort() in
+ * DolphinView::renameSelectedItems().
+ */
+bool lessThan(const KFileItem& item1, const KFileItem& item2)
+{
+    return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0;
+}
+
 DolphinView::DolphinView(QWidget* parent,
                          const KUrl& url,
                          KDirLister* dirLister,
@@ -222,7 +233,11 @@ void DolphinView::setMode(Mode mode)
     }
 
     emit modeChanged();
+    
     updateZoomLevel(oldZoomLevel);
+    if (m_showPreview) {
+        loadDirectory(viewPropsUrl);
+    }
 }
 
 DolphinView::Mode DolphinView::mode() const
@@ -487,32 +502,36 @@ void DolphinView::setNameFilter(const QString& nameFilter)
     }
 }
 
-void DolphinView::calculateItemCount(int& fileCount, int& folderCount) const
+void DolphinView::calculateItemCount(int& fileCount,
+                                     int& folderCount,
+                                     KIO::filesize_t& totalFileSize) const
 {
     foreach (const KFileItem& item, m_dirLister->items()) {
         if (item.isDir()) {
             ++folderCount;
         } else {
             ++fileCount;
+            totalFileSize += item.size();
         }
     }
 }
 
 QString DolphinView::statusBarText() const
-{    
+{
+    QString text;
+    int folderCount = 0;
+    int fileCount = 0;
+    KIO::filesize_t totalFileSize = 0;
+    
     if (hasSelection()) {
         // give a summary of the status of the selected files
-        QString text;
         const KFileItemList list = selectedItems();
         if (list.isEmpty()) {
             // when an item is triggered, it is temporary selected but selectedItems()
             // will return an empty list
-            return QString();
+            return text;
         }
 
-        int fileCount = 0;
-        int folderCount = 0;
-        KIO::filesize_t byteSize = 0;
         KFileItemList::const_iterator it = list.begin();
         const KFileItemList::const_iterator end = list.end();
         while (it != end) {
@@ -521,33 +540,39 @@ QString DolphinView::statusBarText() const
                 ++folderCount;
             } else {
                 ++fileCount;
-                byteSize += item.size();
+                totalFileSize += item.size();
             }
             ++it;
         }
-
-        if (folderCount > 0) {
-            text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
-            if (fileCount > 0) {
-                text += ", ";
+        
+        if (folderCount + fileCount == 1) {
+            // if only one item is selected, show the filename
+            const QString name = list.first().name();
+            text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
+                                        i18nc("@info:status", "<filename>%1</filename> selected (%2)",
+                                              name, KIO::convertSize(totalFileSize));                                            
+        } else {
+            // at least 2 items are selected
+            const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
+            const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
+            if ((folderCount > 0) && (fileCount > 0)) {
+                text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
+                             foldersText, filesText, KIO::convertSize(totalFileSize));
+            } else if (fileCount > 0) {
+                text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize));
+            } else {
+                Q_ASSERT(folderCount > 0);
+                text = foldersText;
             }
         }
-
-        if (fileCount > 0) {
-            const QString sizeText(KIO::convertSize(byteSize));
-            text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
-        }
-        return text;
     } else {
-        // Give a summary of the status of the current folder.
-        int folderCount = 0;
-        int fileCount = 0;
-        calculateItemCount(fileCount, folderCount);
-        return KIO::itemsSummaryString(fileCount + folderCount,
-                                       fileCount,
-                                       folderCount,
-                                       0, false);
+        calculateItemCount(fileCount, folderCount, totalFileSize);
+        text = KIO::itemsSummaryString(fileCount + folderCount,
+                                       fileCount, folderCount,
+                                       totalFileSize, true);
     }
+
+    return text;
 }
 
 void DolphinView::setUrl(const KUrl& url)
@@ -580,7 +605,7 @@ void DolphinView::changeSelection(const KFileItemList& selection)
 
 void DolphinView::renameSelectedItems()
 {
-    const KFileItemList items = selectedItems();
+    KFileItemList items = selectedItems();
     const int itemCount = items.count();
     if (itemCount < 1) {
         return;
@@ -601,10 +626,14 @@ void DolphinView::renameSelectedItems()
             // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
             // as one operation instead of n rename operations like it is done now...
             Q_ASSERT(newName.contains('#'));
+            
+            // currently the items are sorted by the selection order, resort
+            // them by the file name
+            qSort(items.begin(), items.end(), lessThan);
 
             // iterate through all selected items and rename them...
             int index = 1;
-            foreach (const KFileItem &item, items) {
+            foreach (const KFileItemitem, items) {
                 const KUrl& oldUrl = item.url();
                 QString number;
                 number.setNum(index++);
@@ -829,6 +858,13 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
             deleteExpandedViews();
         }
         break;
+        
+    case QEvent::DragEnter:
+        if (watched == itemView()->viewport()) {
+            setActive(true);
+        }
+        break;
+        
     default:
         break;
     }
@@ -892,7 +928,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
                            const KUrl& destPath,
                            QDropEvent* event)
 {
-    DragAndDropHelper::dropUrls(destItem, destPath, event, this);
+    DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
@@ -1284,6 +1320,10 @@ void DolphinView::deleteView()
         m_topLayout->removeWidget(view);
         view->close();
         
+        disconnect(view);
+        m_controller->disconnect(view);
+        view->disconnect();
+        
         bool deleteView = true;
         foreach (const QAbstractItemView* expandedView, m_expandedViews) {
             if (view == expandedView) {