From bafaf9496cc439c461e249057e5d913e9aa734fc Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 6 May 2007 17:25:50 +0000 Subject: [PATCH] some cleanups for the sidebar pages (move protected members to private section etc.) svn path=/trunk/KDE/kdebase/apps/; revision=661815 --- src/infosidebarpage.cpp | 19 ++++++++++--------- src/infosidebarpage.h | 9 +++------ src/sidebarpage.cpp | 23 ++++++++++++++++++----- src/sidebarpage.h | 15 ++++++++++----- src/treeviewsidebarpage.cpp | 8 ++++---- src/treeviewsidebarpage.h | 2 +- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index 7de4d882e5..530d1fb307 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -54,7 +54,6 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_multipleSelection(false), //TODO: check if I'm needed m_pendingPreview(false), m_timer(0), - m_currentSelection(KFileItemList()), m_preview(0), m_name(0), m_infos(0), @@ -126,8 +125,8 @@ void InfoSidebarPage::setUrl(const KUrl& url) void InfoSidebarPage::setSelection(const KFileItemList& selection) { cancelRequest(); - m_currentSelection = selection; - m_multipleSelection = (m_currentSelection.size() > 1); + SidebarPage::setSelection(selection); + m_multipleSelection = (selection.size() > 1); showItemInfo(); } @@ -146,7 +145,8 @@ void InfoSidebarPage::showItemInfo() { cancelRequest(); - KFileItemList selectedItems = m_currentSelection; + const KFileItemList& selectedItems = selection(); + KUrl file; if (selectedItems.count() == 0) { file = m_shownUrl; @@ -246,7 +246,8 @@ void InfoSidebarPage::cancelRequest() void InfoSidebarPage::createMetaInfo() { beginInfoLines(); - if (m_currentSelection.size() == 0) { + const KFileItemList& selectedItems = selection(); + if (selectedItems.size() == 0) { KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); fileItem.refresh(); @@ -256,8 +257,8 @@ void InfoSidebarPage::createMetaInfo() if (MetaDataWidget::metaDataAvailable()) { m_metadataWidget->setFile(fileItem.url()); } - } else if (m_currentSelection.count() == 1) { - KFileItem* fileItem = m_currentSelection.at(0); + } else if (selectedItems.count() == 1) { + KFileItem* fileItem = selectedItems.at(0); addInfoLine(i18n("Type:"), fileItem->mimeComment()); QString sizeText(KIO::convertSize(fileItem->size())); @@ -279,11 +280,11 @@ void InfoSidebarPage::createMetaInfo() } } else { if (MetaDataWidget::metaDataAvailable()) { - m_metadataWidget->setFiles(m_currentSelection.urlList()); + m_metadataWidget->setFiles(selectedItems.urlList()); } unsigned long int totSize = 0; - foreach(KFileItem* item, m_currentSelection) { + foreach(KFileItem* item, selectedItems) { totSize += item->size(); //FIXME what to do with directories ? (same with the one-item-selected-code), item->size() does not return the size of the content : not very instinctive for users } addInfoLine(i18n("Total size:"), KIO::convertSize(totSize)); diff --git a/src/infosidebarpage.h b/src/infosidebarpage.h index 8d84512e99..ffa18d4971 100644 --- a/src/infosidebarpage.h +++ b/src/infosidebarpage.h @@ -49,9 +49,7 @@ class PixmapViewer; class MetaDataWidget; /** - * @brief Prototype for a information sidebar. - * - * Will be exchanged in future releases by pluggable sidebar pages... + * @brief Sidebar for showing meta information of one ore more selected items. */ class InfoSidebarPage : public SidebarPage { @@ -62,8 +60,8 @@ public: virtual ~InfoSidebarPage(); public slots: - void setUrl(const KUrl& url); - void setSelection(const KFileItemList& selection); + virtual void setUrl(const KUrl& url); + virtual void setSelection(const KFileItemList& selection); private slots: /** @@ -130,7 +128,6 @@ private: QTimer* m_timer; KUrl m_shownUrl; KUrl m_urlCandidate; - KFileItemList m_currentSelection; PixmapViewer* m_preview; QLabel* m_name; diff --git a/src/sidebarpage.cpp b/src/sidebarpage.cpp index c6c120f0e1..479bfcad0e 100644 --- a/src/sidebarpage.cpp +++ b/src/sidebarpage.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2006 by Cvetoslav Ludmiloff * + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -23,13 +24,25 @@ #include SidebarPage::SidebarPage(QWidget* parent) : - QWidget(parent), - m_url(KUrl()), - m_currentSelection(KFileItemList()) -{} + QWidget(parent), + m_url(KUrl()), + m_currentSelection(KFileItemList()) +{ +} SidebarPage::~SidebarPage() -{} +{ +} + +const KUrl& SidebarPage::url() const +{ + return m_url; +} + +const KFileItemList& SidebarPage::selection() const +{ + return m_currentSelection; +} void SidebarPage::setUrl(const KUrl& url) { diff --git a/src/sidebarpage.h b/src/sidebarpage.h index 587e435c14..cf9704bca3 100644 --- a/src/sidebarpage.h +++ b/src/sidebarpage.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * Copyright (C) 2006 by Peter Penz + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -27,7 +27,6 @@ /** * @brief Base widget for all pages that can be embedded into the Sidebar. - * */ class SidebarPage : public QWidget { @@ -36,16 +35,22 @@ public: explicit SidebarPage(QWidget* parent = 0); virtual ~SidebarPage(); + /** Returns the current set URL of the active Dolphin view. */ + const KUrl& url() const; + + /** Returns the current selected items of the active Dolphin view. */ + const KFileItemList& selection() const; + public slots: /** * This is invoked every time the folder being displayed in the - * file-management views changes. + * active Dolphin view changes. */ virtual void setUrl(const KUrl& url); /** * This is invoked to inform the sidebar that the user has selected a new - * set of files. + * set of items. */ virtual void setSelection(const KFileItemList& selection); @@ -73,7 +78,7 @@ signals: */ void urlsDropped(const KUrl::List& urls, const KUrl& destination); -protected: +private: KUrl m_url; KFileItemList m_currentSelection; }; diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index ef75baf952..28fc93397e 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -81,11 +81,11 @@ TreeViewSidebarPage::~TreeViewSidebarPage() void TreeViewSidebarPage::setUrl(const KUrl& url) { - if (!url.isValid() || (url == m_url)) { + if (!url.isValid() || (url == SidebarPage::url())) { return; } - m_url = url; + SidebarPage::setUrl(url); // adjust the root of the tree to the base bookmark KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); @@ -156,7 +156,7 @@ void TreeViewSidebarPage::expandSelectionParent() this, SLOT(expandSelectionParent())); // expand the parent folder of the selected item - KUrl parentUrl = m_url.upUrl(); + KUrl parentUrl = url().upUrl(); if (!m_dirLister->url().isParentOf(parentUrl)) { return; } @@ -167,7 +167,7 @@ void TreeViewSidebarPage::expandSelectionParent() m_treeView->setExpanded(proxyIndex, true); // select the item and assure that the item is visible - index = m_dirModel->indexForUrl(m_url); + index = m_dirModel->indexForUrl(url()); if (index.isValid()) { proxyIndex = m_proxyModel->mapFromSource(index); m_treeView->scrollTo(proxyIndex); diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h index badc944841..b7c5e25ff7 100644 --- a/src/treeviewsidebarpage.h +++ b/src/treeviewsidebarpage.h @@ -49,7 +49,7 @@ public slots: /** * Changes the current selection inside the tree to \a url. */ - void setUrl(const KUrl& url); + virtual void setUrl(const KUrl& url); protected: /** @see QWidget::showEvent() */