From: Peter Penz Date: Sun, 5 Oct 2008 18:11:46 +0000 (+0000) Subject: update the statusbar and provide a progress information within the Dolphin KPart... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/224f471a9f04605f15f807fdb5d35f46d104de7f update the statusbar and provide a progress information within the Dolphin KPart, so that Konqueror shows the same information as Dolphin (thanks to Simon St James for the patch!) CCMAIL: faure@kde.org svn path=/trunk/KDE/kdebase/apps/; revision=868210 --- diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 45fc99115..85ca9e473 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -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" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index e21141b12..d1c5b3c7f 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -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, diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index b3be62252..4e8b565bf 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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 KFileItem& item, 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()) diff --git a/src/dolphinview.h b/src/dolphinview.h index 6546c457e..910e324ea 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -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. diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index c5ec69959..5ec6522e7 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -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) { diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 7c81384d2..f3ac48471 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -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;