From 431da0482caa72f90a6a04785383eb1d133f678e Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 7 Oct 2010 14:09:30 +0000 Subject: [PATCH] Internal cleanup for panels: Let the panel-implementations decide whether they accept an URL or not. svn path=/trunk/KDE/kdebase/apps/; revision=1183480 --- src/panels/folders/folderspanel.cpp | 15 +++----- src/panels/folders/folderspanel.h | 9 ++--- src/panels/information/informationpanel.cpp | 37 ++++++++++--------- src/panels/information/informationpanel.h | 6 +-- .../information/informationpanelcontent.cpp | 4 +- .../information/informationpanelcontent.h | 9 ++--- src/panels/panel.cpp | 13 ++++++- src/panels/panel.h | 16 ++++++-- src/panels/terminal/terminalpanel.cpp | 22 +++++------ src/panels/terminal/terminalpanel.h | 5 ++- 10 files changed, 75 insertions(+), 61 deletions(-) diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 134d8ba7e..fae7ca6a1 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -103,23 +103,20 @@ void FoldersPanel::rename(const KFileItem& item) } } -void FoldersPanel::setUrl(const KUrl& url) +bool FoldersPanel::urlChanged() { - if (!url.isValid() || (url == Panel::url())) { - return; - } - - if (url.protocol().contains("search")) { + if (!url().isValid() || url().protocol().contains("search")) { // Skip results shown by a search, as possible identical // directory names are useless without parent-path information. - return; + return false; } - Panel::setUrl(url); if (m_dirLister != 0) { m_setLeafVisible = true; - loadTree(url); + loadTree(url()); } + + return true; } void FoldersPanel::showEvent(QShowEvent* event) diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h index 438a9ee68..972dc13a7 100644 --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -59,13 +59,10 @@ signals: */ void changeUrl(const KUrl& url, Qt::MouseButtons buttons); -public slots: - /** - * Changes the current selection inside the tree to \a url. - */ - virtual void setUrl(const KUrl& url); - protected: + /** @see Panel::urlChanged() */ + virtual bool urlChanged(); + /** @see QWidget::showEvent() */ virtual void showEvent(QShowEvent* event); diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index c18cc7fdb..d45974a48 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -52,24 +52,6 @@ QSize InformationPanel::sizeHint() const return size; } -void InformationPanel::setUrl(const KUrl& url) -{ - Panel::setUrl(url); - if (!url.isValid() || isEqualToShownUrl(url)) { - return; - } - - m_shownUrl = url; - if (isVisible()) { - cancelRequest(); - // Update the content with a delay. This gives - // the directory lister the chance to show the content - // before expensive operations are done to show - // meta information. - m_urlChangedTimer->start(); - } -} - void InformationPanel::setSelection(const KFileItemList& selection) { if (!isVisible()) { @@ -126,6 +108,25 @@ void InformationPanel::requestDelayedItemInfo(const KFileItem& item) } } +bool InformationPanel::urlChanged() +{ + if (!url().isValid() || isEqualToShownUrl(url())) { + return false; + } + + m_shownUrl = url(); + if (isVisible()) { + cancelRequest(); + // Update the content with a delay. This gives + // the directory lister the chance to show the content + // before expensive operations are done to show + // meta information. + m_urlChangedTimer->start(); + } + + return true; +} + void InformationPanel::showEvent(QShowEvent* event) { Panel::showEvent(event); diff --git a/src/panels/information/informationpanel.h b/src/panels/information/informationpanel.h index e0768bc1b..abd7ed811 100644 --- a/src/panels/information/informationpanel.h +++ b/src/panels/information/informationpanel.h @@ -42,9 +42,6 @@ signals: void urlActivated(const KUrl& url); public slots: - /** @see Panel::setUrl() */ - virtual void setUrl(const KUrl& url); - /** * This is invoked to inform the panel that the user has selected a new * set of items. @@ -60,6 +57,9 @@ public slots: void requestDelayedItemInfo(const KFileItem& item); protected: + /** @see Panel::urlChanged() */ + virtual bool urlChanged(); + /** @see QWidget::showEvent() */ virtual void showEvent(QShowEvent* event); diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 3b9a17960..b6a41ca3d 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -55,7 +55,7 @@ #include "pixmapviewer.h" InformationPanelContent::InformationPanelContent(QWidget* parent) : - Panel(parent), + QWidget(parent), m_item(), m_pendingPreview(false), m_outdatedPreviewTimer(0), @@ -262,7 +262,7 @@ bool InformationPanelContent::eventFilter(QObject* obj, QEvent* event) break; } - return Panel::eventFilter(obj, event); + return QWidget::eventFilter(obj, event); } void InformationPanelContent::configureSettings() diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h index cb712627d..f918b8582 100644 --- a/src/panels/information/informationpanelcontent.h +++ b/src/panels/information/informationpanelcontent.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Peter Penz * + * Copyright (C) 2009-2010 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 * @@ -20,13 +20,12 @@ #ifndef INFORMATIONPANELCONTENT_H #define INFORMATIONPANELCONTENT_H -#include - #include +#include #include #include -class KFileItem; +class KFileItemList; class KFileMetaDataWidget; class PhononWidget; class PixmapViewer; @@ -39,7 +38,7 @@ class QScrollArea; * @brief Manages the widgets that display the meta information * for file items of the Information Panel. */ -class InformationPanelContent : public Panel +class InformationPanelContent : public QWidget { Q_OBJECT diff --git a/src/panels/panel.cpp b/src/panels/panel.cpp index 9e7ff4ff3..6d11422d8 100644 --- a/src/panels/panel.cpp +++ b/src/panels/panel.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006-2010 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 * @@ -31,14 +31,23 @@ Panel::~Panel() { } -const KUrl& Panel::url() const +KUrl Panel::url() const { return m_url; } void Panel::setUrl(const KUrl& url) { + if (url.equals(m_url, KUrl::CompareWithoutTrailingSlash)) { + return; + } + + const KUrl oldUrl = m_url; m_url = url; + const bool accepted = urlChanged(); + if (!accepted) { + m_url = oldUrl; + } } #include "panel.moc" diff --git a/src/panels/panel.h b/src/panels/panel.h index b056ca1cb..11558e2de 100644 --- a/src/panels/panel.h +++ b/src/panels/panel.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006-2010 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 * @@ -37,14 +37,24 @@ public: virtual ~Panel(); /** Returns the current set URL of the active Dolphin view. */ - const KUrl& url() const; + KUrl url() const; public slots: /** * This is invoked every time the folder being displayed in the * active Dolphin view changes. */ - virtual void setUrl(const KUrl& url); + void setUrl(const KUrl& url); + +protected: + /** + * Must be implemented by derived classes and is invoked when + * the URL has been changed (see Panel::setUrl()). + * @return True, if the new URL will get accepted by the derived + * class. If false is returned, + * the URL will be reset to the previous URL. + */ + virtual bool urlChanged() = 0; private: KUrl m_url; diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp index d6b370329..12b319f3c 100644 --- a/src/panels/terminal/terminalpanel.cpp +++ b/src/panels/terminal/terminalpanel.cpp @@ -52,26 +52,26 @@ QSize TerminalPanel::sizeHint() const return size; } -void TerminalPanel::setUrl(const KUrl& url) +void TerminalPanel::terminalExited() { - if (!url.isValid() || (url == Panel::url())) { - return; - } + emit hideTerminalPanel(); + m_terminal = 0; +} - Panel::setUrl(url); +bool TerminalPanel::urlChanged() +{ + if (!url().isValid()) { + return false; + } const bool sendInput = (m_terminal != 0) && (m_terminal->foregroundProcessId() == -1) && isVisible(); if (sendInput) { - changeDir(url); + changeDir(url()); } -} -void TerminalPanel::terminalExited() -{ - emit hideTerminalPanel(); - m_terminal = 0; + return true; } void TerminalPanel::showEvent(QShowEvent* event) diff --git a/src/panels/terminal/terminalpanel.h b/src/panels/terminal/terminalpanel.h index 91a75a989..b9508279e 100644 --- a/src/panels/terminal/terminalpanel.h +++ b/src/panels/terminal/terminalpanel.h @@ -46,14 +46,15 @@ public: virtual QSize sizeHint() const; public slots: - /** @see Panel::setUrl(). */ - virtual void setUrl(const KUrl& url); void terminalExited(); signals: void hideTerminalPanel(); protected: + /** @see Panel::urlChanged() */ + virtual bool urlChanged(); + /** @see QWidget::showEvent() */ virtual void showEvent(QShowEvent* event); -- 2.47.3