]> cloud.milkyroute.net Git - dolphin.git/commitdiff
update the statusbar and provide a progress information within the Dolphin KPart...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 18:11:46 +0000 (18:11 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 18:11:46 +0000 (18:11 +0000)
CCMAIL: faure@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=868210

src/dolphinpart.cpp
src/dolphinpart.h
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index 45fc9911593e93de654f8ab51558bd396818cb83..85ca9e473d229ed8787e06daa00aad867ebb9c7a 100644 (file)
@@ -67,6 +67,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
     //connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotStarted()));
     connect(m_dirLister, SIGNAL(completed(KUrl)), this, SLOT(slotCompleted(KUrl)));
     connect(m_dirLister, SIGNAL(canceled(KUrl)), this, SLOT(slotCanceled(KUrl)));
+    connect(m_dirLister, SIGNAL(percent(int)), this, SLOT(updateProgress(int)));
 
     m_dolphinModel = new DolphinModel(this);
     m_dolphinModel->setDirLister(m_dirLister);
@@ -106,6 +107,14 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
             this, SLOT(slotRequestUrlChange(KUrl)));
     connect(m_view, SIGNAL(modeChanged()),
             this, SIGNAL(viewModeChanged())); // relay signal
+    
+    // Watch for changes that should result in updates to the
+    // status bar text.
+    connect(m_dirLister, SIGNAL(deleteItem(const KFileItem&)),
+            this, SLOT(updateStatusBar()));
+    connect(m_dirLister, SIGNAL(clear()),
+            this, SLOT(updateStatusBar()));
+
 
     m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
     m_actionHandler->setCurrentView(m_view);
@@ -293,6 +302,11 @@ void DolphinPart::slotErrorMessage(const QString& msg)
 void DolphinPart::slotRequestItemInfo(const KFileItem& item)
 {
     emit m_extension->mouseOverInfo(item);
+    if (item.isNull()) {
+        updateStatusBar();
+    } else {
+        ReadOnlyPart::setStatusBarText(item.getStatusBarInfo());
+    }
 }
 
 void DolphinPart::slotItemTriggered(const KFileItem& item)
@@ -488,4 +502,14 @@ void DolphinPart::updateNewMenu()
     m_newMenu->setPopupFiles(url());
 }
 
+void DolphinPart::updateStatusBar()
+{
+    emit ReadOnlyPart::setStatusBarText(m_view->statusBarText());
+}
+
+void DolphinPart::updateProgress(int percent)
+{
+    m_extension->loadingProgress(percent);
+}
+
 #include "dolphinpart.moc"
index e21141b1294f70f536ca845fa192aa0a1784611d..d1c5b3c7fe9a76e29b9d36e56ea6f4873dcd4c29 100644 (file)
@@ -178,6 +178,18 @@ private Q_SLOTS:
      */
     void updateNewMenu();
 
+    /**
+     * Updates the number of items (= number of files + number of
+     * directories) in the statusbar. If files are selected, the number
+     * of selected files and the sum of the filesize is shown.
+     */
+    void updateStatusBar();
+
+   /**
+    * Notify container of folder loading progress.
+    */
+    void updateProgress(int percent);
+
 private:
     void createActions();
     void createGoAction(const char* name, const char* iconName,
index b3be62252762e470580759d2d5c1a9a4579e9f2b..4e8b565bf1b663bfd5a80c30df617a9ce85df815 100644 (file)
@@ -481,9 +481,9 @@ void DolphinView::setNameFilter(const QString& nameFilter)
     }
 }
 
-void DolphinView::calculateItemCount(int& fileCount, int& folderCount)
+void DolphinView::calculateItemCount(int& fileCount, int& folderCount) const
 {
-    foreach (const KFileItem &item, m_dirLister->items()) {
+    foreach (const KFileItemitem, m_dirLister->items()) {
         if (item.isDir()) {
             ++folderCount;
         } else {
@@ -492,6 +492,58 @@ void DolphinView::calculateItemCount(int& fileCount, int& folderCount)
     }
 }
 
+QString DolphinView::statusBarText() const
+{    
+    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();
+        }
+
+        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) {
+            const KFileItem& item = *it;
+            if (item.isDir()) {
+                ++folderCount;
+            } else {
+                ++fileCount;
+                byteSize += item.size();
+            }
+            ++it;
+        }
+
+        if (folderCount > 0) {
+            text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
+            if (fileCount > 0) {
+                text += ", ";
+            }
+        }
+
+        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);
+    }
+}
+
 void DolphinView::setUrl(const KUrl& url)
 {
     // remember current item candidate (see restoreCurrentItem())
index 6546c457ed5ab9878abec090aed7eee6c63a35a5..910e324ea6724cd240d67379889921960481af63 100644 (file)
@@ -305,7 +305,13 @@ public:
      * directory lister or the model directly, as it takes
      * filtering and hierarchical previews into account.
      */
-    void calculateItemCount(int& fileCount, int& folderCount);
+    void calculateItemCount(int& fileCount, int& folderCount) const;
+    
+    /**
+     * Returns a textual representation of the state of the current
+     * folder or selected items, suitable for use in the status bar.
+     */
+    QString statusBarText() const;
 
     /**
      * Updates the state of the 'Additional Information' actions in \a collection.
index c5ec6995997558642f15a5710a4832f03bdc4c55..5ec6522e770160a12d67c168112edde565c060e1 100644 (file)
@@ -284,58 +284,6 @@ void DolphinViewContainer::closeFilterBar()
     emit showFilterBarChanged(false);
 }
 
-QString DolphinViewContainer::defaultStatusBarText() const
-{
-    int folderCount = 0;
-    int fileCount = 0;
-    m_view->calculateItemCount(fileCount, folderCount);
-    return KIO::itemsSummaryString(fileCount + folderCount,
-                                   fileCount,
-                                   folderCount,
-                                   0, false);
-}
-
-QString DolphinViewContainer::selectionStatusBarText() const
-{
-    QString text;
-    const KFileItemList list = m_view->selectedItems();
-    if (list.isEmpty()) {
-        // when an item is triggered, it is temporary selected but selectedItems()
-        // will return an empty list
-        return QString();
-    }
-
-    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) {
-        const KFileItem& item = *it;
-        if (item.isDir()) {
-            ++folderCount;
-        } else {
-            ++fileCount;
-            byteSize += item.size();
-        }
-        ++it;
-    }
-
-    if (folderCount > 0) {
-        text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
-        if (fileCount > 0) {
-            text += ", ";
-        }
-    }
-
-    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;
-}
-
 void DolphinViewContainer::showFilterBar(bool show)
 {
     Q_ASSERT(m_filterBar != 0);
@@ -357,7 +305,7 @@ void DolphinViewContainer::updateStatusBar()
                                      (m_statusBar->type() == DolphinStatusBar::Information)) &&
                                     (m_statusBar->progress() == 100);
 
-    const QString text(m_view->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
+    const QString text(m_view->statusBarText());
     m_statusBar->setDefaultText(text);
 
     if (updateStatusBarMsg) {
index 7c81384d2be019e99c768a2507e11d9206d4eed6..f3ac48471e439baf65a5ce2a1f8fafa93746689b 100644 (file)
@@ -208,19 +208,6 @@ private slots:
      */
     void dropUrls(const KUrl& destination, QDropEvent* event);
 
-private:
-    /**
-     * Returns the default text of the status bar, if no item is
-     * selected.
-     */
-    QString defaultStatusBarText() const;
-
-    /**
-     * Returns the text for the status bar, if at least one item
-     * is selected.
-     */
-    QString selectionStatusBarText() const;
-
 private:
     bool m_showProgress;