some cleanups for the sidebar pages (move protected members to private section etc.)

svn path=/trunk/KDE/kdebase/apps/; revision=661815
This commit is contained in:
Peter Penz 2007-05-06 17:25:50 +00:00
parent 5f87a8130e
commit bafaf9496c
6 changed files with 46 additions and 30 deletions

View file

@ -54,7 +54,6 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) :
m_multipleSelection(false), //TODO: check if I'm needed m_multipleSelection(false), //TODO: check if I'm needed
m_pendingPreview(false), m_pendingPreview(false),
m_timer(0), m_timer(0),
m_currentSelection(KFileItemList()),
m_preview(0), m_preview(0),
m_name(0), m_name(0),
m_infos(0), m_infos(0),
@ -126,8 +125,8 @@ void InfoSidebarPage::setUrl(const KUrl& url)
void InfoSidebarPage::setSelection(const KFileItemList& selection) void InfoSidebarPage::setSelection(const KFileItemList& selection)
{ {
cancelRequest(); cancelRequest();
m_currentSelection = selection; SidebarPage::setSelection(selection);
m_multipleSelection = (m_currentSelection.size() > 1); m_multipleSelection = (selection.size() > 1);
showItemInfo(); showItemInfo();
} }
@ -146,7 +145,8 @@ void InfoSidebarPage::showItemInfo()
{ {
cancelRequest(); cancelRequest();
KFileItemList selectedItems = m_currentSelection; const KFileItemList& selectedItems = selection();
KUrl file; KUrl file;
if (selectedItems.count() == 0) { if (selectedItems.count() == 0) {
file = m_shownUrl; file = m_shownUrl;
@ -246,7 +246,8 @@ void InfoSidebarPage::cancelRequest()
void InfoSidebarPage::createMetaInfo() void InfoSidebarPage::createMetaInfo()
{ {
beginInfoLines(); beginInfoLines();
if (m_currentSelection.size() == 0) { const KFileItemList& selectedItems = selection();
if (selectedItems.size() == 0) {
KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl);
fileItem.refresh(); fileItem.refresh();
@ -256,8 +257,8 @@ void InfoSidebarPage::createMetaInfo()
if (MetaDataWidget::metaDataAvailable()) { if (MetaDataWidget::metaDataAvailable()) {
m_metadataWidget->setFile(fileItem.url()); m_metadataWidget->setFile(fileItem.url());
} }
} else if (m_currentSelection.count() == 1) { } else if (selectedItems.count() == 1) {
KFileItem* fileItem = m_currentSelection.at(0); KFileItem* fileItem = selectedItems.at(0);
addInfoLine(i18n("Type:"), fileItem->mimeComment()); addInfoLine(i18n("Type:"), fileItem->mimeComment());
QString sizeText(KIO::convertSize(fileItem->size())); QString sizeText(KIO::convertSize(fileItem->size()));
@ -279,11 +280,11 @@ void InfoSidebarPage::createMetaInfo()
} }
} else { } else {
if (MetaDataWidget::metaDataAvailable()) { if (MetaDataWidget::metaDataAvailable()) {
m_metadataWidget->setFiles(m_currentSelection.urlList()); m_metadataWidget->setFiles(selectedItems.urlList());
} }
unsigned long int totSize = 0; 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 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)); addInfoLine(i18n("Total size:"), KIO::convertSize(totSize));

View file

@ -49,9 +49,7 @@ class PixmapViewer;
class MetaDataWidget; class MetaDataWidget;
/** /**
* @brief Prototype for a information sidebar. * @brief Sidebar for showing meta information of one ore more selected items.
*
* Will be exchanged in future releases by pluggable sidebar pages...
*/ */
class InfoSidebarPage : public SidebarPage class InfoSidebarPage : public SidebarPage
{ {
@ -62,8 +60,8 @@ public:
virtual ~InfoSidebarPage(); virtual ~InfoSidebarPage();
public slots: public slots:
void setUrl(const KUrl& url); virtual void setUrl(const KUrl& url);
void setSelection(const KFileItemList& selection); virtual void setSelection(const KFileItemList& selection);
private slots: private slots:
/** /**
@ -130,7 +128,6 @@ private:
QTimer* m_timer; QTimer* m_timer;
KUrl m_shownUrl; KUrl m_shownUrl;
KUrl m_urlCandidate; KUrl m_urlCandidate;
KFileItemList m_currentSelection;
PixmapViewer* m_preview; PixmapViewer* m_preview;
QLabel* m_name; QLabel* m_name;

View file

@ -1,5 +1,6 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> * * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
@ -23,13 +24,25 @@
#include <kurl.h> #include <kurl.h>
SidebarPage::SidebarPage(QWidget* parent) : SidebarPage::SidebarPage(QWidget* parent) :
QWidget(parent), QWidget(parent),
m_url(KUrl()), m_url(KUrl()),
m_currentSelection(KFileItemList()) m_currentSelection(KFileItemList())
{} {
}
SidebarPage::~SidebarPage() SidebarPage::~SidebarPage()
{} {
}
const KUrl& SidebarPage::url() const
{
return m_url;
}
const KFileItemList& SidebarPage::selection() const
{
return m_currentSelection;
}
void SidebarPage::setUrl(const KUrl& url) void SidebarPage::setUrl(const KUrl& url)
{ {

View file

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> * * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * 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. * @brief Base widget for all pages that can be embedded into the Sidebar.
*
*/ */
class SidebarPage : public QWidget class SidebarPage : public QWidget
{ {
@ -36,16 +35,22 @@ public:
explicit SidebarPage(QWidget* parent = 0); explicit SidebarPage(QWidget* parent = 0);
virtual ~SidebarPage(); 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: public slots:
/** /**
* This is invoked every time the folder being displayed in the * 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); virtual void setUrl(const KUrl& url);
/** /**
* This is invoked to inform the sidebar that the user has selected a new * 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); virtual void setSelection(const KFileItemList& selection);
@ -73,7 +78,7 @@ signals:
*/ */
void urlsDropped(const KUrl::List& urls, const KUrl& destination); void urlsDropped(const KUrl::List& urls, const KUrl& destination);
protected: private:
KUrl m_url; KUrl m_url;
KFileItemList m_currentSelection; KFileItemList m_currentSelection;
}; };

View file

@ -81,11 +81,11 @@ TreeViewSidebarPage::~TreeViewSidebarPage()
void TreeViewSidebarPage::setUrl(const KUrl& url) void TreeViewSidebarPage::setUrl(const KUrl& url)
{ {
if (!url.isValid() || (url == m_url)) { if (!url.isValid() || (url == SidebarPage::url())) {
return; return;
} }
m_url = url; SidebarPage::setUrl(url);
// adjust the root of the tree to the base bookmark // adjust the root of the tree to the base bookmark
KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
@ -156,7 +156,7 @@ void TreeViewSidebarPage::expandSelectionParent()
this, SLOT(expandSelectionParent())); this, SLOT(expandSelectionParent()));
// expand the parent folder of the selected item // expand the parent folder of the selected item
KUrl parentUrl = m_url.upUrl(); KUrl parentUrl = url().upUrl();
if (!m_dirLister->url().isParentOf(parentUrl)) { if (!m_dirLister->url().isParentOf(parentUrl)) {
return; return;
} }
@ -167,7 +167,7 @@ void TreeViewSidebarPage::expandSelectionParent()
m_treeView->setExpanded(proxyIndex, true); m_treeView->setExpanded(proxyIndex, true);
// select the item and assure that the item is visible // select the item and assure that the item is visible
index = m_dirModel->indexForUrl(m_url); index = m_dirModel->indexForUrl(url());
if (index.isValid()) { if (index.isValid()) {
proxyIndex = m_proxyModel->mapFromSource(index); proxyIndex = m_proxyModel->mapFromSource(index);
m_treeView->scrollTo(proxyIndex); m_treeView->scrollTo(proxyIndex);

View file

@ -49,7 +49,7 @@ public slots:
/** /**
* Changes the current selection inside the tree to \a url. * Changes the current selection inside the tree to \a url.
*/ */
void setUrl(const KUrl& url); virtual void setUrl(const KUrl& url);
protected: protected:
/** @see QWidget::showEvent() */ /** @see QWidget::showEvent() */