From f37ecd6ecfab9bc1d2929504b4f6e4363f8137b9 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 14 Jan 2009 20:14:36 +0000 Subject: Cleanup panel related class names: The terms "sidebar"/"sidebarpage" are relicts from the KDE 3 version of Dolphin and are called "Panels" in the KDE 4 version of Dolphin. Yes, renaming classes may take more than 1 year ;-) svn path=/trunk/KDE/kdebase/apps/; revision=911089 --- src/CMakeLists.txt | 12 +- src/dolphinmainwindow.cpp | 64 +-- src/dolphinmainwindow.h | 6 +- src/dolphinview.h | 2 +- src/draganddrophelper.h | 2 +- src/folderexpander.h | 2 +- src/panels/folders/folderspanel.cpp | 279 +++++++++++++ src/panels/folders/folderspanel.h | 135 +++++++ src/panels/folders/paneltreeview.cpp | 147 +++++++ src/panels/folders/paneltreeview.h | 58 +++ src/panels/folders/sidebartreeview.cpp | 147 ------- src/panels/folders/sidebartreeview.h | 58 --- src/panels/folders/treeviewcontextmenu.cpp | 4 +- src/panels/folders/treeviewcontextmenu.h | 8 +- src/panels/folders/treeviewsidebarpage.cpp | 279 ------------- src/panels/folders/treeviewsidebarpage.h | 135 ------- src/panels/information/informationpanel.cpp | 587 ++++++++++++++++++++++++++++ src/panels/information/informationpanel.h | 194 +++++++++ src/panels/information/infosidebarpage.cpp | 587 ---------------------------- src/panels/information/infosidebarpage.h | 194 --------- src/panels/panel.cpp | 46 +++ src/panels/panel.h | 53 +++ src/panels/places/dolphinfileplacesview.cpp | 56 --- src/panels/places/dolphinfileplacesview.h | 51 --- src/panels/places/placespanel.cpp | 56 +++ src/panels/places/placespanel.h | 50 +++ src/panels/sidebarpage.cpp | 46 --- src/panels/sidebarpage.h | 53 --- src/panels/terminal/terminalpanel.cpp | 96 +++++ src/panels/terminal/terminalpanel.h | 62 +++ src/panels/terminal/terminalsidebarpage.cpp | 97 ----- src/panels/terminal/terminalsidebarpage.h | 62 --- 32 files changed, 1813 insertions(+), 1815 deletions(-) create mode 100644 src/panels/folders/folderspanel.cpp create mode 100644 src/panels/folders/folderspanel.h create mode 100644 src/panels/folders/paneltreeview.cpp create mode 100644 src/panels/folders/paneltreeview.h delete mode 100644 src/panels/folders/sidebartreeview.cpp delete mode 100644 src/panels/folders/sidebartreeview.h delete mode 100644 src/panels/folders/treeviewsidebarpage.cpp delete mode 100644 src/panels/folders/treeviewsidebarpage.h create mode 100644 src/panels/information/informationpanel.cpp create mode 100644 src/panels/information/informationpanel.h delete mode 100644 src/panels/information/infosidebarpage.cpp delete mode 100644 src/panels/information/infosidebarpage.h create mode 100644 src/panels/panel.cpp create mode 100644 src/panels/panel.h delete mode 100644 src/panels/places/dolphinfileplacesview.cpp delete mode 100644 src/panels/places/dolphinfileplacesview.h create mode 100644 src/panels/places/placespanel.cpp create mode 100644 src/panels/places/placespanel.h delete mode 100644 src/panels/sidebarpage.cpp delete mode 100644 src/panels/sidebarpage.h create mode 100644 src/panels/terminal/terminalpanel.cpp create mode 100644 src/panels/terminal/terminalpanel.h delete mode 100644 src/panels/terminal/terminalsidebarpage.cpp delete mode 100644 src/panels/terminal/terminalsidebarpage.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 708271d00..0a7602056 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,27 +102,27 @@ set(dolphin_SRCS dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp - panels/places/dolphinfileplacesview.cpp + panels/places/placespanel.cpp settings/dolphinsettingsdialog.cpp filterbar.cpp settings/generalsettingspage.cpp settings/generalviewsettingspage.cpp settings/iconsizegroupbox.cpp settings/iconsviewsettingspage.cpp - panels/information/infosidebarpage.cpp + panels/information/informationpanel.cpp panels/folders/ktreeview.cpp main.cpp panels/information/metadatawidget.cpp panels/information/metatextlabel.cpp pixmapviewer.cpp settings/settingspagebase.cpp - panels/sidebarpage.cpp + panels/panel.cpp settings/startupsettingspage.cpp statusbarspaceinfo.cpp statusbarmessagelabel.cpp panels/folders/treeviewcontextmenu.cpp - panels/folders/treeviewsidebarpage.cpp - panels/folders/sidebartreeview.cpp + panels/folders/folderspanel.cpp + panels/folders/paneltreeview.cpp settings/viewsettingspage.cpp settings/viewsettingspagebase.cpp zoomlevelinfo.cpp @@ -145,7 +145,7 @@ kde4_add_ui_files(dolphin_SRCS panels/information/newtagdialog.ui) endif(Nepomuk_FOUND) if(NOT WIN32) - set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalsidebarpage.cpp) + set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalpanel.cpp) endif(NOT WIN32) qt4_add_dbus_adaptor(dolphin_SRCS diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index c4d263bfd..a91584b8e 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,20 +25,20 @@ #include #include "dolphinapplication.h" -#include "panels/places/dolphinfileplacesview.h" #include "dolphinnewmenu.h" #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" #include "dolphinstatusbar.h" #include "dolphinviewcontainer.h" -#include "panels/information/infosidebarpage.h" +#include "panels/folders/folderspanel.h" +#include "panels/places/placespanel.h" +#include "panels/information/informationpanel.h" #include "panels/information/metadatawidget.h" #include "mainwindowadaptor.h" -#include "panels/folders/treeviewsidebarpage.h" #include "viewproperties.h" #ifndef Q_OS_WIN -#include "panels/terminal/terminalsidebarpage.h" +#include "panels/terminal/terminalpanel.h" #endif #include "dolphin_generalsettings.h" @@ -1110,8 +1110,8 @@ void DolphinMainWindow::setupDockWidgets() QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information")); infoDock->setObjectName("infoDock"); infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - SidebarPage* infoWidget = new InfoSidebarPage(infoDock); - infoDock->setWidget(infoWidget); + Panel* infoPanel = new InformationPanel(infoDock); + infoDock->setWidget(infoPanel); infoDock->toggleViewAction()->setText(i18nc("@title:window", "Information")); infoDock->toggleViewAction()->setShortcut(Qt::Key_F11); @@ -1119,29 +1119,29 @@ void DolphinMainWindow::setupDockWidgets() addDockWidget(Qt::RightDockWidgetArea, infoDock); connect(this, SIGNAL(urlChanged(KUrl)), - infoWidget, SLOT(setUrl(KUrl))); + infoPanel, SLOT(setUrl(KUrl))); connect(this, SIGNAL(selectionChanged(KFileItemList)), - infoWidget, SLOT(setSelection(KFileItemList))); + infoPanel, SLOT(setSelection(KFileItemList))); connect(this, SIGNAL(requestItemInfo(KFileItem)), - infoWidget, SLOT(requestDelayedItemInfo(KFileItem))); + infoPanel, SLOT(requestDelayedItemInfo(KFileItem))); // setup "Tree View" - QDockWidget* treeViewDock = new QDockWidget(i18nc("@title:window", "Folders")); - treeViewDock->setObjectName("treeViewDock"); - treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock); - treeViewDock->setWidget(treeWidget); + QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders")); + foldersDock->setObjectName("foldersDock"); + foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + FoldersPanel* foldersPanel = new FoldersPanel(foldersDock); + foldersDock->setWidget(foldersPanel); - treeViewDock->toggleViewAction()->setText(i18nc("@title:window", "Folders")); - treeViewDock->toggleViewAction()->setShortcut(Qt::Key_F7); - actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction()); + foldersDock->toggleViewAction()->setText(i18nc("@title:window", "Folders")); + foldersDock->toggleViewAction()->setShortcut(Qt::Key_F7); + actionCollection()->addAction("show_folders_panel", foldersDock->toggleViewAction()); - addDockWidget(Qt::LeftDockWidgetArea, treeViewDock); + addDockWidget(Qt::LeftDockWidgetArea, foldersDock); connect(this, SIGNAL(urlChanged(KUrl)), - treeWidget, SLOT(setUrl(KUrl))); - connect(treeWidget, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)), + foldersPanel, SLOT(setUrl(KUrl))); + connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)), this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons))); - connect(treeWidget, SIGNAL(changeSelection(KFileItemList)), + connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)), this, SLOT(changeSelection(KFileItemList))); // setup "Terminal" @@ -1149,10 +1149,10 @@ void DolphinMainWindow::setupDockWidgets() QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal")); terminalDock->setObjectName("terminalDock"); terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); - SidebarPage* terminalWidget = new TerminalSidebarPage(terminalDock); - terminalDock->setWidget(terminalWidget); + Panel* terminalPanel = new TerminalPanel(terminalDock); + terminalDock->setWidget(terminalPanel); - connect(terminalWidget, SIGNAL(hideTerminalSidebarPage()), terminalDock, SLOT(hide())); + connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide())); terminalDock->toggleViewAction()->setText(i18nc("@title:window Shell terminal", "Terminal")); terminalDock->toggleViewAction()->setShortcut(Qt::Key_F4); @@ -1160,12 +1160,12 @@ void DolphinMainWindow::setupDockWidgets() addDockWidget(Qt::BottomDockWidgetArea, terminalDock); connect(this, SIGNAL(urlChanged(KUrl)), - terminalWidget, SLOT(setUrl(KUrl))); + terminalPanel, SLOT(setUrl(KUrl))); #endif const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun(); if (firstRun) { - treeViewDock->hide(); + foldersDock->hide(); #ifndef Q_OS_WIN terminalDock->hide(); #endif @@ -1175,20 +1175,20 @@ void DolphinMainWindow::setupDockWidgets() placesDock->setObjectName("placesDock"); placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - DolphinFilePlacesView* placesView = new DolphinFilePlacesView(placesDock); - placesDock->setWidget(placesView); - placesView->setModel(DolphinSettings::instance().placesModel()); - placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + PlacesPanel* placesPanel = new PlacesPanel(placesDock); + placesDock->setWidget(placesPanel); + placesPanel->setModel(DolphinSettings::instance().placesModel()); + placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); placesDock->toggleViewAction()->setText(i18nc("@title:window", "Places")); placesDock->toggleViewAction()->setShortcut(Qt::Key_F9); actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, placesDock); - connect(placesView, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)), + connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)), this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons))); connect(this, SIGNAL(urlChanged(KUrl)), - placesView, SLOT(setUrl(KUrl))); + placesPanel, SLOT(setUrl(KUrl))); } void DolphinMainWindow::updateEditActions() diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index b1e1ea5d0..336b16363 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -23,7 +23,7 @@ #define DOLPHIN_MAINWINDOW_H #include "dolphinview.h" -#include "panels/sidebarpage.h" +#include "panels/panel.h" #include @@ -120,7 +120,7 @@ public slots: int getId() const; /** - * Inform all affected dolphin components (sidebars, views) of an URL + * Inform all affected dolphin components (panels, views) of an URL * change. */ void changeUrl(const KUrl& url); @@ -148,7 +148,7 @@ signals: void urlChanged(const KUrl& url); /** - * Is emitted if information of an item is requested to be shown e. g. in the sidebar. + * Is emitted if information of an item is requested to be shown e. g. in the panel. * If item is null, no item information request is pending. */ void requestItemInfo(const KFileItem& item); diff --git a/src/dolphinview.h b/src/dolphinview.h index d558b4c5a..9dd001c8e 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -481,7 +481,7 @@ signals: void zoomLevelChanged(int level); /** - * Is emitted if information of an item is requested to be shown e. g. in the sidebar. + * Is emitted if information of an item is requested to be shown e. g. in the panel. * If item is null, no item information request is pending. */ void requestItemInfo(const KFileItem& item); diff --git a/src/draganddrophelper.h b/src/draganddrophelper.h index bf8c0b79d..e362fd508 100644 --- a/src/draganddrophelper.h +++ b/src/draganddrophelper.h @@ -38,7 +38,7 @@ class QWidget; * @brief Helper class for having a common drag and drop behavior. * * The class is used by DolphinIconsView, DolphinDetailsView, - * DolphinColumnView and SidebarTreeView to have a consistent + * DolphinColumnView and PanelTreeView to have a consistent * drag and drop behavior between all views. */ class LIBDOLPHINPRIVATE_EXPORT DragAndDropHelper : public QObject diff --git a/src/folderexpander.h b/src/folderexpander.h index d8da29f17..57b8e9e55 100644 --- a/src/folderexpander.h +++ b/src/folderexpander.h @@ -20,7 +20,7 @@ #ifndef FOLDEREXPANDER_H #define FOLDEREXPANDER_H -// Needs to be exported as treesidebarpage uses it. +// Needs to be exported as FoldersPanel uses it. #include "libdolphin_export.h" #include diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp new file mode 100644 index 000000000..72d9a0952 --- /dev/null +++ b/src/panels/folders/folderspanel.cpp @@ -0,0 +1,279 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "folderspanel.h" + +#include "dolphinmodel.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphinview.h" +#include "settings/dolphinsettings.h" +#include "dolphin_folderspanelsettings.h" +#include "dolphin_generalsettings.h" +#include "draganddrophelper.h" +#include "folderexpander.h" +#include "renamedialog.h" +#include "paneltreeview.h" +#include "treeviewcontextmenu.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +FoldersPanel::FoldersPanel(QWidget* parent) : + Panel(parent), + m_setLeafVisible(false), + m_mouseButtons(Qt::NoButton), + m_dirLister(0), + m_dolphinModel(0), + m_proxyModel(0), + m_treeView(0), + m_leafDir() +{ + setLayoutDirection(Qt::LeftToRight); +} + +FoldersPanel::~FoldersPanel() +{ + FoldersPanelSettings::self()->writeConfig(); + + delete m_proxyModel; + m_proxyModel = 0; + delete m_dolphinModel; + m_dolphinModel = 0; + m_dirLister = 0; // deleted by m_dolphinModel +} + +QSize FoldersPanel::sizeHint() const +{ + return QSize(200, 400); +} + +void FoldersPanel::setShowHiddenFiles(bool show) +{ + FoldersPanelSettings::setShowHiddenFiles(show); + if (m_dirLister != 0) { + m_dirLister->setShowingDotFiles(show); + m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); + } +} + +bool FoldersPanel::showHiddenFiles() const +{ + return FoldersPanelSettings::showHiddenFiles(); +} + +void FoldersPanel::rename(const KFileItem& item) +{ + if (DolphinSettings::instance().generalSettings()->renameInline()) { + const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + m_treeView->edit(proxyIndex); + } else { + KFileItemList items; + items.append(item); + RenameDialog dialog(this, items); + if (dialog.exec() == QDialog::Accepted) { + const QString& newName = dialog.newName(); + if (!newName.isEmpty()) { + KUrl newUrl = item.url(); + newUrl.setFileName(newName); + KonqOperations::rename(this, item.url(), newUrl); + } + } + } +} + +void FoldersPanel::setUrl(const KUrl& url) +{ + if (!url.isValid() || (url == Panel::url())) { + return; + } + + Panel::setUrl(url); + if (m_dirLister != 0) { + m_setLeafVisible = true; + loadTree(url); + } +} + +void FoldersPanel::showEvent(QShowEvent* event) +{ + if (event->spontaneous()) { + Panel::showEvent(event); + return; + } + + if (m_dirLister == 0) { + // Postpone the creating of the dir lister to the first show event. + // This assures that no performance and memory overhead is given when the TreeView is not + // used at all (see FoldersPanel::setUrl()). + m_dirLister = new KDirLister(); + m_dirLister->setDirOnlyMode(true); + m_dirLister->setAutoUpdate(true); + m_dirLister->setMainWindow(window()); + m_dirLister->setDelayedMimeTypes(true); + m_dirLister->setAutoErrorHandlingEnabled(false, this); + m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); + + Q_ASSERT(m_dolphinModel == 0); + m_dolphinModel = new DolphinModel(this); + m_dolphinModel->setDirLister(m_dirLister); + m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); + connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), + this, SLOT(expandToDir(const QModelIndex&))); + + Q_ASSERT(m_proxyModel == 0); + m_proxyModel = new DolphinSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_dolphinModel); + + Q_ASSERT(m_treeView == 0); + m_treeView = new PanelTreeView(this); + m_treeView->setModel(m_proxyModel); + m_proxyModel->setSorting(DolphinView::SortByName); + m_proxyModel->setSortOrder(Qt::AscendingOrder); + + new FolderExpander(m_treeView, m_proxyModel); + + connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(updateActiveView(const QModelIndex&))); + connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), + this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); + connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), + this, SLOT(updateMouseButtons())); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->addWidget(m_treeView); + } + + loadTree(url()); + Panel::showEvent(event); +} + +void FoldersPanel::contextMenuEvent(QContextMenuEvent* event) +{ + Panel::contextMenuEvent(event); + + KFileItem item; + const QModelIndex index = m_treeView->indexAt(event->pos()); + if (index.isValid()) { + const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); + item = m_dolphinModel->itemForIndex(dolphinModelIndex); + emit changeSelection(KFileItemList()); + } + + TreeViewContextMenu contextMenu(this, item); + contextMenu.open(); +} + +void FoldersPanel::updateActiveView(const QModelIndex& index) +{ + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + const KFileItem item = m_dolphinModel->itemForIndex(dirIndex); + if (!item.isNull()) { + emit changeUrl(item.url(), m_mouseButtons); + } +} + +void FoldersPanel::dropUrls(const QModelIndex& index, QDropEvent* event) +{ + if (index.isValid()) { + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + KFileItem item = m_dolphinModel->itemForIndex(dirIndex); + Q_ASSERT(!item.isNull()); + if (item.isDir()) { + DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); + } + } +} + +void FoldersPanel::expandToDir(const QModelIndex& index) +{ + m_treeView->setExpanded(index, true); + selectLeafDirectory(); + m_treeView->resizeColumnToContents(DolphinModel::Name); +} + +void FoldersPanel::scrollToLeaf() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (proxyIndex.isValid()) { + m_treeView->scrollTo(proxyIndex); + } +} + +void FoldersPanel::updateMouseButtons() +{ + m_mouseButtons = QApplication::mouseButtons(); +} + +void FoldersPanel::loadTree(const KUrl& url) +{ + Q_ASSERT(m_dirLister != 0); + m_leafDir = url; + + KUrl baseUrl; + if (url.isLocalFile()) { + // use the root directory as base for local URLs (#150941) + baseUrl = QDir::rootPath(); + } else { + // clear the path for non-local URLs and use it as base + baseUrl = url; + baseUrl.setPath(QString('/')); + } + + if (m_dirLister->url() != baseUrl) { + m_dirLister->stop(); + m_dirLister->openUrl(baseUrl, KDirLister::Reload); + } + m_dolphinModel->expandToUrl(m_leafDir); +} + +void FoldersPanel::selectLeafDirectory() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (!proxyIndex.isValid()) { + return; + } + + if (m_setLeafVisible) { + // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by + // scrollToLeaf(). This assures that the scrolling is done after + // the horizontal scrollbar gets visible (otherwise the scrollbar + // might hide the leaf). + QTimer::singleShot(100, this, SLOT(scrollToLeaf())); + m_setLeafVisible = false; + } + + QItemSelectionModel* selModel = m_treeView->selectionModel(); + selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); +} + +#include "folderspanel.moc" diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h new file mode 100644 index 000000000..90f506fd0 --- /dev/null +++ b/src/panels/folders/folderspanel.h @@ -0,0 +1,135 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef FOLDERSPANEL_H +#define FOLDERSPANEL_H + +#include +#include + +class KDirLister; +class DolphinModel; + +class DolphinSortFilterProxyModel; +class PanelTreeView; +class QModelIndex; + +/** + * @brief Shows a tree view of the directories starting from + * the currently selected place. + * + * The tree view is always synchronized with the currently active view + * from the main window. + */ +class FoldersPanel : public Panel +{ + Q_OBJECT + +public: + FoldersPanel(QWidget* parent = 0); + virtual ~FoldersPanel(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + + void setShowHiddenFiles(bool show); + bool showHiddenFiles() const; + + void rename(const KFileItem& item); + +signals: + /** + * Is emitted if the an URL change is requested. + */ + void changeUrl(const KUrl& url, Qt::MouseButtons buttons); + + /** + * This signal is emitted when the panel requests a change in the + * current selection. The file-management view recieving this signal is + * not required to select all listed files, limiting the selection to + * e.g. the current folder. The new selection will be reported via the + * setSelection slot. + */ + void changeSelection(const KFileItemList& selection); + +public slots: + /** + * Changes the current selection inside the tree to \a url. + */ + virtual void setUrl(const KUrl& url); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + + /** @see QWidget::contextMenuEvent() */ + virtual void contextMenuEvent(QContextMenuEvent* event); + +private slots: + /** + * Updates the active view to the URL + * which is given by the item with the index \a index. + */ + void updateActiveView(const QModelIndex& index); + + /** + * Is emitted if URLs have been dropped + * to the index \a index. + */ + void dropUrls(const QModelIndex& index, QDropEvent* event); + + /** + * Expands the treeview to show the directory + * specified by \a index. + */ + void expandToDir(const QModelIndex& index); + + /** + * Assures that the leaf folder gets visible. + */ + void scrollToLeaf(); + + void updateMouseButtons(); + +private: + /** + * Initializes the base URL of the tree and expands all + * directories until \a url. + * @param url URL of the leaf directory that should get expanded. + */ + void loadTree(const KUrl& url); + + /** + * Selects the current leaf directory m_leafDir and assures + * that the directory is visible if the leaf has been set by + * FoldersPanel::setUrl(). + */ + void selectLeafDirectory(); + +private: + bool m_setLeafVisible; + Qt::MouseButtons m_mouseButtons; + KDirLister* m_dirLister; + DolphinModel* m_dolphinModel; + DolphinSortFilterProxyModel* m_proxyModel; + PanelTreeView* m_treeView; + KUrl m_leafDir; +}; + +#endif // FOLDERSPANEL_H diff --git a/src/panels/folders/paneltreeview.cpp b/src/panels/folders/paneltreeview.cpp new file mode 100644 index 000000000..b285789f0 --- /dev/null +++ b/src/panels/folders/paneltreeview.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "paneltreeview.h" + +#include "dolphincontroller.h" +#include "dolphinmodel.h" +#include "draganddrophelper.h" + +#include +#include +#include +#include +#include + +PanelTreeView::PanelTreeView(QWidget* parent) : + KTreeView(parent) +{ + setAcceptDrops(true); + setUniformRowHeights(true); + setSelectionMode(QAbstractItemView::SingleSelection); + setEditTriggers(QAbstractItemView::NoEditTriggers); + setSortingEnabled(true); + setFrameStyle(QFrame::NoFrame); + setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(false); + + setVerticalScrollMode(QListView::ScrollPerPixel); + setHorizontalScrollMode(QListView::ScrollPerPixel); + + viewport()->setAttribute(Qt::WA_Hover); + + // make the background transparent and apply the window-text color + // to the text color, so that enough contrast is given for all color + // schemes + QPalette p = palette(); + p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); + p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); + p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); + setPalette(p); + viewport()->setAutoFillBackground(false); + + KFileItemDelegate* delegate = new KFileItemDelegate(this); + setItemDelegate(delegate); +} + +PanelTreeView::~PanelTreeView() +{ +} + +bool PanelTreeView::event(QEvent* event) +{ + switch (event->type()) { + case QEvent::Polish: + // hide all columns except of the 'Name' column + hideColumn(DolphinModel::Size); + hideColumn(DolphinModel::ModifiedTime); + hideColumn(DolphinModel::Permissions); + hideColumn(DolphinModel::Owner); + hideColumn(DolphinModel::Group); + hideColumn(DolphinModel::Type); + hideColumn(DolphinModel::Rating); + hideColumn(DolphinModel::Tags); + header()->hide(); + break; + + case QEvent::Show: + // TODO: The opening/closing animation of subtrees flickers in combination with the + // panel when using the Oxygen style. As workaround the animation is turned off: + setAnimated(false); + break; + + case QEvent::UpdateRequest: + // a wheel movement will scroll 1 item + if (model()->rowCount() > 0) { + verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3); + } + break; + + default: + break; + } + + return KTreeView::event(event); +} + +void PanelTreeView::startDrag(Qt::DropActions supportedActions) +{ + DragAndDropHelper::instance().startDrag(this, supportedActions); +} + +void PanelTreeView::dragEnterEvent(QDragEnterEvent* event) +{ + KTreeView::dragEnterEvent(event); + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } +} + +void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event) +{ + KTreeView::dragLeaveEvent(event); + setDirtyRegion(m_dropRect); +} + +void PanelTreeView::dragMoveEvent(QDragMoveEvent* event) +{ + KTreeView::dragMoveEvent(event); + + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + const QModelIndex index = indexAt(event->pos()); + setDirtyRegion(m_dropRect); + m_dropRect = visualRect(index); + setDirtyRegion(m_dropRect); + + if (event->mimeData()->hasUrls()) { + // accept url drops, independently from the destination item + event->acceptProposedAction(); + } +} + +void PanelTreeView::dropEvent(QDropEvent* event) +{ + const QModelIndex index = indexAt(event->pos()); + if (index.isValid()) { + emit urlsDropped(index, event); + } + KTreeView::dropEvent(event); +} + +#include "paneltreeview.moc" diff --git a/src/panels/folders/paneltreeview.h b/src/panels/folders/paneltreeview.h new file mode 100644 index 000000000..0f0996875 --- /dev/null +++ b/src/panels/folders/paneltreeview.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef PANELTREEVIEW_H +#define PANELTREEVIEW_H + +#include +#include + +/** + * @brief Tree view widget which is used for the folders panel. + * + * @see FoldersPanel + */ +class PanelTreeView : public KTreeView +{ + Q_OBJECT + +public: + explicit PanelTreeView(QWidget* parent = 0); + virtual ~PanelTreeView(); + +signals: + /** + * Is emitted if the URL have been dropped to + * the index \a index. + */ + void urlsDropped(const QModelIndex& index, QDropEvent* event); + +protected: + virtual bool event(QEvent* event); + virtual void startDrag(Qt::DropActions supportedActions); + virtual void dragEnterEvent(QDragEnterEvent* event); + virtual void dragLeaveEvent(QDragLeaveEvent* event); + virtual void dragMoveEvent(QDragMoveEvent* event); + virtual void dropEvent(QDropEvent* event); + +private: + QRect m_dropRect; +}; + +#endif diff --git a/src/panels/folders/sidebartreeview.cpp b/src/panels/folders/sidebartreeview.cpp deleted file mode 100644 index a876ee6c3..000000000 --- a/src/panels/folders/sidebartreeview.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "sidebartreeview.h" - -#include "dolphincontroller.h" -#include "dolphinmodel.h" -#include "draganddrophelper.h" - -#include -#include -#include -#include -#include - -SidebarTreeView::SidebarTreeView(QWidget* parent) : - KTreeView(parent) -{ - setAcceptDrops(true); - setUniformRowHeights(true); - setSelectionMode(QAbstractItemView::SingleSelection); - setEditTriggers(QAbstractItemView::NoEditTriggers); - setSortingEnabled(true); - setFrameStyle(QFrame::NoFrame); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - - setVerticalScrollMode(QListView::ScrollPerPixel); - setHorizontalScrollMode(QListView::ScrollPerPixel); - - viewport()->setAttribute(Qt::WA_Hover); - - // make the background transparent and apply the window-text color - // to the text color, so that enough contrast is given for all color - // schemes - QPalette p = palette(); - p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); - p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); - p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); - setPalette(p); - viewport()->setAutoFillBackground(false); - - KFileItemDelegate* delegate = new KFileItemDelegate(this); - setItemDelegate(delegate); -} - -SidebarTreeView::~SidebarTreeView() -{ -} - -bool SidebarTreeView::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::Polish: - // hide all columns except of the 'Name' column - hideColumn(DolphinModel::Size); - hideColumn(DolphinModel::ModifiedTime); - hideColumn(DolphinModel::Permissions); - hideColumn(DolphinModel::Owner); - hideColumn(DolphinModel::Group); - hideColumn(DolphinModel::Type); - hideColumn(DolphinModel::Rating); - hideColumn(DolphinModel::Tags); - header()->hide(); - break; - - case QEvent::Show: - // TODO: The opening/closing animation of subtrees flickers in combination with the - // sidebar when using the Oxygen style. As workaround the animation is turned off: - setAnimated(false); - break; - - case QEvent::UpdateRequest: - // a wheel movement will scroll 1 item - if (model()->rowCount() > 0) { - verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3); - } - break; - - default: - break; - } - - return KTreeView::event(event); -} - -void SidebarTreeView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions); -} - -void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event) -{ - KTreeView::dragEnterEvent(event); - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } -} - -void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event) -{ - KTreeView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event) -{ - KTreeView::dragMoveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - const QModelIndex index = indexAt(event->pos()); - setDirtyRegion(m_dropRect); - m_dropRect = visualRect(index); - setDirtyRegion(m_dropRect); - - if (event->mimeData()->hasUrls()) { - // accept url drops, independently from the destination item - event->acceptProposedAction(); - } -} - -void SidebarTreeView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - if (index.isValid()) { - emit urlsDropped(index, event); - } - KTreeView::dropEvent(event); -} - -#include "sidebartreeview.moc" diff --git a/src/panels/folders/sidebartreeview.h b/src/panels/folders/sidebartreeview.h deleted file mode 100644 index a5e8b63ce..000000000 --- a/src/panels/folders/sidebartreeview.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef SIDEBARTREEVIEW_H -#define SIDEBARTREEVIEW_H - -#include -#include - -/** - * @brief Tree view widget which is used for the sidebar panel. - * - * @see TreeViewSidebarPage - */ -class SidebarTreeView : public KTreeView -{ - Q_OBJECT - -public: - explicit SidebarTreeView(QWidget* parent = 0); - virtual ~SidebarTreeView(); - -signals: - /** - * Is emitted if the URL have been dropped to - * the index \a index. - */ - void urlsDropped(const QModelIndex& index, QDropEvent* event); - -protected: - virtual bool event(QEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - -private: - QRect m_dropRect; -}; - -#endif diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 9e8638002..c63772a38 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -32,12 +32,12 @@ #include #include -#include "treeviewsidebarpage.h" +#include "folderspanel.h" #include #include -TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage* parent, +TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : QObject(parent), m_parent(parent), diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h index 20a603573..8da23721b 100644 --- a/src/panels/folders/treeviewcontextmenu.h +++ b/src/panels/folders/treeviewcontextmenu.h @@ -23,7 +23,7 @@ #include #include -class TreeViewSidebarPage; +class FoldersPanel; /** * @brief Represents the context menu which appears when doing a right @@ -35,13 +35,13 @@ class TreeViewContextMenu : public QObject public: /** - * @parent Pointer to the treeview sidebar page the context menu + * @parent Pointer to the folders panel the context menu * belongs to. * @fileInfo Pointer to the file item the context menu * is applied. If 0 is passed, the context menu * is above the viewport. */ - TreeViewContextMenu(TreeViewSidebarPage* parent, + TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo); virtual ~TreeViewContextMenu(); @@ -81,7 +81,7 @@ private: void populateMimeData(QMimeData* mimeData, bool cut); private: - TreeViewSidebarPage* m_parent; + FoldersPanel* m_parent; KFileItem m_fileInfo; }; diff --git a/src/panels/folders/treeviewsidebarpage.cpp b/src/panels/folders/treeviewsidebarpage.cpp deleted file mode 100644 index 7801a97cc..000000000 --- a/src/panels/folders/treeviewsidebarpage.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "treeviewsidebarpage.h" - -#include "dolphinmodel.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphinview.h" -#include "settings/dolphinsettings.h" -#include "dolphin_folderspanelsettings.h" -#include "dolphin_generalsettings.h" -#include "draganddrophelper.h" -#include "folderexpander.h" -#include "renamedialog.h" -#include "sidebartreeview.h" -#include "treeviewcontextmenu.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_setLeafVisible(false), - m_mouseButtons(Qt::NoButton), - m_dirLister(0), - m_dolphinModel(0), - m_proxyModel(0), - m_treeView(0), - m_leafDir() -{ - setLayoutDirection(Qt::LeftToRight); -} - -TreeViewSidebarPage::~TreeViewSidebarPage() -{ - FoldersPanelSettings::self()->writeConfig(); - - delete m_proxyModel; - m_proxyModel = 0; - delete m_dolphinModel; - m_dolphinModel = 0; - m_dirLister = 0; // deleted by m_dolphinModel -} - -QSize TreeViewSidebarPage::sizeHint() const -{ - return QSize(200, 400); -} - -void TreeViewSidebarPage::setShowHiddenFiles(bool show) -{ - FoldersPanelSettings::setShowHiddenFiles(show); - if (m_dirLister != 0) { - m_dirLister->setShowingDotFiles(show); - m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); - } -} - -bool TreeViewSidebarPage::showHiddenFiles() const -{ - return FoldersPanelSettings::showHiddenFiles(); -} - -void TreeViewSidebarPage::rename(const KFileItem& item) -{ - if (DolphinSettings::instance().generalSettings()->renameInline()) { - const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - m_treeView->edit(proxyIndex); - } else { - KFileItemList items; - items.append(item); - RenameDialog dialog(this, items); - if (dialog.exec() == QDialog::Accepted) { - const QString& newName = dialog.newName(); - if (!newName.isEmpty()) { - KUrl newUrl = item.url(); - newUrl.setFileName(newName); - KonqOperations::rename(this, item.url(), newUrl); - } - } - } -} - -void TreeViewSidebarPage::setUrl(const KUrl& url) -{ - if (!url.isValid() || (url == SidebarPage::url())) { - return; - } - - SidebarPage::setUrl(url); - if (m_dirLister != 0) { - m_setLeafVisible = true; - loadTree(url); - } -} - -void TreeViewSidebarPage::showEvent(QShowEvent* event) -{ - if (event->spontaneous()) { - SidebarPage::showEvent(event); - return; - } - - if (m_dirLister == 0) { - // Postpone the creating of the dir lister to the first show event. - // This assures that no performance and memory overhead is given when the TreeView is not - // used at all (see TreeViewSidebarPage::setUrl()). - m_dirLister = new KDirLister(); - m_dirLister->setDirOnlyMode(true); - m_dirLister->setAutoUpdate(true); - m_dirLister->setMainWindow(window()); - m_dirLister->setDelayedMimeTypes(true); - m_dirLister->setAutoErrorHandlingEnabled(false, this); - m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); - - Q_ASSERT(m_dolphinModel == 0); - m_dolphinModel = new DolphinModel(this); - m_dolphinModel->setDirLister(m_dirLister); - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(expandToDir(const QModelIndex&))); - - Q_ASSERT(m_proxyModel == 0); - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dolphinModel); - - Q_ASSERT(m_treeView == 0); - m_treeView = new SidebarTreeView(this); - m_treeView->setModel(m_proxyModel); - m_proxyModel->setSorting(DolphinView::SortByName); - m_proxyModel->setSortOrder(Qt::AscendingOrder); - - new FolderExpander(m_treeView, m_proxyModel); - - connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), - this, SLOT(updateActiveView(const QModelIndex&))); - connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), - this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); - connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateMouseButtons())); - - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(m_treeView); - } - - loadTree(url()); - SidebarPage::showEvent(event); -} - -void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event) -{ - SidebarPage::contextMenuEvent(event); - - KFileItem item; - const QModelIndex index = m_treeView->indexAt(event->pos()); - if (index.isValid()) { - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - item = m_dolphinModel->itemForIndex(dolphinModelIndex); - emit changeSelection(KFileItemList()); - } - - TreeViewContextMenu contextMenu(this, item); - contextMenu.open(); -} - -void TreeViewSidebarPage::updateActiveView(const QModelIndex& index) -{ - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - if (!item.isNull()) { - emit changeUrl(item.url(), m_mouseButtons); - } -} - -void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event) -{ - if (index.isValid()) { - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - Q_ASSERT(!item.isNull()); - if (item.isDir()) { - DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); - } - } -} - -void TreeViewSidebarPage::expandToDir(const QModelIndex& index) -{ - m_treeView->setExpanded(index, true); - selectLeafDirectory(); - m_treeView->resizeColumnToContents(DolphinModel::Name); -} - -void TreeViewSidebarPage::scrollToLeaf() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid()) { - m_treeView->scrollTo(proxyIndex); - } -} - -void TreeViewSidebarPage::updateMouseButtons() -{ - m_mouseButtons = QApplication::mouseButtons(); -} - -void TreeViewSidebarPage::loadTree(const KUrl& url) -{ - Q_ASSERT(m_dirLister != 0); - m_leafDir = url; - - KUrl baseUrl; - if (url.isLocalFile()) { - // use the root directory as base for local URLs (#150941) - baseUrl = QDir::rootPath(); - } else { - // clear the path for non-local URLs and use it as base - baseUrl = url; - baseUrl.setPath(QString('/')); - } - - if (m_dirLister->url() != baseUrl) { - m_dirLister->stop(); - m_dirLister->openUrl(baseUrl, KDirLister::Reload); - } - m_dolphinModel->expandToUrl(m_leafDir); -} - -void TreeViewSidebarPage::selectLeafDirectory() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (!proxyIndex.isValid()) { - return; - } - - if (m_setLeafVisible) { - // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by - // scrollToLeaf(). This assures that the scrolling is done after - // the horizontal scrollbar gets visible (otherwise the scrollbar - // might hide the leaf). - QTimer::singleShot(100, this, SLOT(scrollToLeaf())); - m_setLeafVisible = false; - } - - QItemSelectionModel* selModel = m_treeView->selectionModel(); - selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); -} - -#include "treeviewsidebarpage.moc" diff --git a/src/panels/folders/treeviewsidebarpage.h b/src/panels/folders/treeviewsidebarpage.h deleted file mode 100644 index 39f2323ad..000000000 --- a/src/panels/folders/treeviewsidebarpage.h +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef TREEVIEWSIDEBARPAGE_H -#define TREEVIEWSIDEBARPAGE_H - -#include -#include - -class KDirLister; -class DolphinModel; - -class DolphinSortFilterProxyModel; -class SidebarTreeView; -class QModelIndex; - -/** - * @brief Shows a tree view of the directories starting from - * the currently selected place. - * - * The tree view is always synchronized with the currently active view - * from the main window. - */ -class TreeViewSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - TreeViewSidebarPage(QWidget* parent = 0); - virtual ~TreeViewSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - - void setShowHiddenFiles(bool show); - bool showHiddenFiles() const; - - void rename(const KFileItem& item); - -signals: - /** - * Is emitted if the an URL change is requested. - */ - void changeUrl(const KUrl& url, Qt::MouseButtons buttons); - - /** - * This signal is emitted when the sidebar requests a change in the - * current selection. The file-management view recieving this signal is - * not required to select all listed files, limiting the selection to - * e.g. the current folder. The new selection will be reported via the - * setSelection slot. - */ - void changeSelection(const KFileItemList& selection); - -public slots: - /** - * Changes the current selection inside the tree to \a url. - */ - virtual void setUrl(const KUrl& url); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - - /** @see QWidget::contextMenuEvent() */ - virtual void contextMenuEvent(QContextMenuEvent* event); - -private slots: - /** - * Updates the active view to the URL - * which is given by the item with the index \a index. - */ - void updateActiveView(const QModelIndex& index); - - /** - * Is emitted if URLs have been dropped - * to the index \a index. - */ - void dropUrls(const QModelIndex& index, QDropEvent* event); - - /** - * Expands the treeview to show the directory - * specified by \a index. - */ - void expandToDir(const QModelIndex& index); - - /** - * Assures that the leaf folder gets visible. - */ - void scrollToLeaf(); - - void updateMouseButtons(); - -private: - /** - * Initializes the base URL of the tree and expands all - * directories until \a url. - * @param url URL of the leaf directory that should get expanded. - */ - void loadTree(const KUrl& url); - - /** - * Selects the current leaf directory m_leafDir and assures - * that the directory is visible if the leaf has been set by - * TreeViewSidebarPage::setUrl(). - */ - void selectLeafDirectory(); - -private: - bool m_setLeafVisible; - Qt::MouseButtons m_mouseButtons; - KDirLister* m_dirLister; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - SidebarTreeView* m_treeView; - KUrl m_leafDir; -}; - -#endif // TREEVIEWSIDEBARPAGE_H diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp new file mode 100644 index 000000000..a77a39908 --- /dev/null +++ b/src/panels/information/informationpanel.cpp @@ -0,0 +1,587 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "informationpanel.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "settings/dolphinsettings.h" +#include "metadatawidget.h" +#include "metatextlabel.h" +#include "pixmapviewer.h" + +InformationPanel::InformationPanel(QWidget* parent) : + Panel(parent), + m_initialized(false), + m_pendingPreview(false), + m_infoTimer(0), + m_outdatedPreviewTimer(0), + m_shownUrl(), + m_urlCandidate(), + m_fileItem(), + m_selection(), + m_nameLabel(0), + m_preview(0), + m_metaDataWidget(0), + m_metaTextLabel(0) +{ +} + +InformationPanel::~InformationPanel() +{ +} + +QSize InformationPanel::sizeHint() const +{ + QSize size = Panel::sizeHint(); + size.setWidth(minimumSizeHint().width()); + return size; +} + +void InformationPanel::setUrl(const KUrl& url) +{ + Panel::setUrl(url); + if (url.isValid() && !isEqualToShownUrl(url)) { + if (isVisible()) { + cancelRequest(); + m_shownUrl = url; + showItemInfo(); + } else { + m_shownUrl = url; + } + } +} + +void InformationPanel::setSelection(const KFileItemList& selection) +{ + if (!isVisible()) { + return; + } + + if ((selection.count() == 0) && (m_selection.count() == 0)) { + // The selection has not really changed, only the current index. + // QItemSelectionModel emits a signal in this case and it is less + // expensive doing the check this way instead of patching + // DolphinView::emitSelectionChanged(). + return; + } + + m_selection = selection; + + const int count = selection.count(); + if (count == 0) { + if (!isEqualToShownUrl(url())) { + m_shownUrl = url(); + showItemInfo(); + } + } else { + if ((count == 1) && !selection.first().url().isEmpty()) { + m_urlCandidate = selection.first().url(); + } + m_infoTimer->start(); + } +} + +void InformationPanel::requestDelayedItemInfo(const KFileItem& item) +{ + if (!isVisible()) { + return; + } + + cancelRequest(); + + m_fileItem = KFileItem(); + if (item.isNull()) { + // The cursor is above the viewport. If files are selected, + // show information regarding the selection. + if (m_selection.size() > 0) { + m_pendingPreview = false; + m_infoTimer->start(); + } + } else { + const KUrl url = item.url(); + if (url.isValid() && !isEqualToShownUrl(url)) { + m_urlCandidate = item.url(); + m_fileItem = item; + m_infoTimer->start(); + } + } +} + +void InformationPanel::showEvent(QShowEvent* event) +{ + Panel::showEvent(event); + if (!event->spontaneous()) { + if (!m_initialized) { + // do a delayed initialization so that no performance + // penalty is given when Dolphin is started with a closed + // Information Panel + init(); + } + showItemInfo(); + } +} + +void InformationPanel::resizeEvent(QResizeEvent* event) +{ + if (isVisible()) { + // If the text inside the name label or the info label cannot + // get wrapped, then the maximum width of the label is increased + // so that the width of the information panel gets increased. + // To prevent this, the maximum width is adjusted to + // the current width of the panel. + const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; + m_nameLabel->setMaximumWidth(maxWidth); + + // try to increase the preview as large as possible + m_preview->setSizeHint(QSize(maxWidth, maxWidth)); + m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done + m_infoTimer->start(); + } + + Panel::resizeEvent(event); +} + +void InformationPanel::showItemInfo() +{ + if (!isVisible()) { + return; + } + + cancelRequest(); + + if (showMultipleSelectionInfo()) { + KIconLoader iconLoader; + QPixmap icon = iconLoader.loadIcon("dialog-information", + KIconLoader::NoGroup, + KIconLoader::SizeEnormous); + m_preview->setPixmap(icon); + setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count())); + m_shownUrl = KUrl(); + } else { + const KFileItem item = fileItem(); + const KUrl itemUrl = item.url(); + if (!applyPlace(itemUrl)) { + // try to get a preview pixmap from the item... + m_pendingPreview = true; + + // Mark the currently shown preview as outdated. This is done + // with a small delay to prevent a flickering when the next preview + // can be shown within a short timeframe. + m_outdatedPreviewTimer->start(); + + KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, + m_preview->width(), + m_preview->height(), + 0, + 0, + false, + true); + + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(showPreview(const KFileItem&, const QPixmap&))); + connect(job, SIGNAL(failed(const KFileItem&)), + this, SLOT(showIcon(const KFileItem&))); + + setNameLabelText(itemUrl.fileName()); + } + } + + showMetaInfo(); +} + +void InformationPanel::slotInfoTimeout() +{ + m_shownUrl = m_urlCandidate; + showItemInfo(); +} + +void InformationPanel::markOutdatedPreview() +{ + KIconEffect iconEffect; + QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(), + KIconLoader::Desktop, + KIconLoader::DisabledState); + m_preview->setPixmap(disabledPixmap); +} + +void InformationPanel::showIcon(const KFileItem& item) +{ + m_outdatedPreviewTimer->stop(); + m_pendingPreview = false; + if (!applyPlace(item.url())) { + m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous)); + } +} + +void InformationPanel::showPreview(const KFileItem& item, + const QPixmap& pixmap) +{ + m_outdatedPreviewTimer->stop(); + + Q_UNUSED(item); + if (m_pendingPreview) { + m_preview->setPixmap(pixmap); + m_pendingPreview = false; + } +} + +void InformationPanel::slotFileRenamed(const QString& source, const QString& dest) +{ + if (m_shownUrl == KUrl(source)) { + // the currently shown file has been renamed, hence update the item information + // for the renamed file + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest)); + requestDelayedItemInfo(item); + } +} + +void InformationPanel::slotFilesAdded(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + // If the 'trash' icon changes because the trash has been emptied or got filled, + // the signal filesAdded("trash:/") will be emitted. + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); + requestDelayedItemInfo(item); + } +} + +void InformationPanel::slotFilesChanged(const QStringList& files) +{ + foreach (const QString& fileName, files) { + if (m_shownUrl == KUrl(fileName)) { + showItemInfo(); + break; + } + } +} + +void InformationPanel::slotFilesRemoved(const QStringList& files) +{ + foreach (const QString& fileName, files) { + if (m_shownUrl == KUrl(fileName)) { + // the currently shown item has been removed, show + // the parent directory as fallback + m_shownUrl = url(); + showItemInfo(); + break; + } + } +} + +void InformationPanel::slotEnteredDirectory(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); + requestDelayedItemInfo(item); + } +} + +void InformationPanel::slotLeftDirectory(const QString& directory) +{ + if (m_shownUrl == KUrl(directory)) { + // The signal 'leftDirectory' is also emitted when a media + // has been unmounted. In this case no directory change will be + // done in Dolphin, but the Information Panel must be updated to + // indicate an invalid directory. + m_shownUrl = url(); + showItemInfo(); + } +} + +bool InformationPanel::applyPlace(const KUrl& url) +{ + KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); + int count = placesModel->rowCount(); + + for (int i = 0; i < count; ++i) { + QModelIndex index = placesModel->index(i, 0); + + if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { + setNameLabelText(placesModel->text(index)); + m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); + return true; + } + } + + return false; +} + +void InformationPanel::cancelRequest() +{ + m_infoTimer->stop(); +} + +void InformationPanel::showMetaInfo() +{ + m_metaTextLabel->clear(); + + if (showMultipleSelectionInfo()) { + if (m_metaDataWidget != 0) { + KUrl::List urls; + foreach (const KFileItem& item, m_selection) { + urls.append(item.targetUrl()); + } + m_metaDataWidget->setFiles(urls); + } + + quint64 totalSize = 0; + foreach (const KFileItem& item, m_selection) { + // Only count the size of files, not dirs to match what + // DolphinViewContainer::selectionStatusBarText() does. + if (!item.isDir() && !item.isLink()) { + totalSize += item.size(); + } + } + m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); + } else { + const KFileItem item = fileItem(); + if (item.isDir()) { + m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); + m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); + } else { + m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment()); + + m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size())); + m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); + + if (item.isLocalFile()) { + // TODO: See convertMetaInfo below, find a way to display only interesting information + // in a readable way + const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | + KFileMetaInfo::TechnicalInfo | + KFileMetaInfo::ContentInfo; + const QString path = item.url().path(); + const KFileMetaInfo fileMetaInfo(path, QString(), flags); + if (fileMetaInfo.isValid()) { + const QHash& items = fileMetaInfo.items(); + QHash::const_iterator it = items.constBegin(); + const QHash::const_iterator end = items.constEnd(); + QString labelText; + while (it != end) { + const KFileMetaInfoItem& metaInfoItem = it.value(); + const QVariant& value = metaInfoItem.value(); + if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { + m_metaTextLabel->add(labelText, value.toString()); + } + ++it; + } + } + } + } + + if (m_metaDataWidget != 0) { + m_metaDataWidget->setFile(item.targetUrl()); + } + } +} + +bool InformationPanel::convertMetaInfo(const QString& key, QString& text) const +{ + struct MetaKey { + const char* key; + QString text; + }; + + // sorted list of keys, where its data should be shown + static const MetaKey keys[] = { + { "http://freedesktop.org/standards/xesam/1.0/core#album", i18nc("@label", "Album:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#artist", i18nc("@label", "Artist:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#genre", i18nc("@label", "Genre:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#lineCount", i18nc("@label", "Lines:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#title", i18nc("@label", "Title:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#type", i18nc("@label", "Type:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#trackNumber", i18nc("@label", "Track:") }, + { "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width:") } + }; + + // do a binary search for the key... + int top = 0; + int bottom = sizeof(keys) / sizeof(MetaKey) - 1; + while (top <= bottom) { + const int middle = (top + bottom) / 2; + const int result = key.compare(keys[middle].key); + if (result < 0) { + bottom = middle - 1; + } else if (result > 0) { + top = middle + 1; + } else { + text = keys[middle].text; + return true; + } + } + + return false; +} + +KFileItem InformationPanel::fileItem() const +{ + if (!m_fileItem.isNull()) { + return m_fileItem; + } + + if (!m_selection.isEmpty()) { + Q_ASSERT(m_selection.count() == 1); + return m_selection.first(); + } + + // no item is hovered and no selection has been done: provide + // an item for the directory represented by m_shownUrl + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); + item.refresh(); + return item; +} + +bool InformationPanel::showMultipleSelectionInfo() const +{ + return m_fileItem.isNull() && (m_selection.count() > 1); +} + +bool InformationPanel::isEqualToShownUrl(const KUrl& url) const +{ + return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash); +} + +void InformationPanel::setNameLabelText(const QString& text) +{ + QTextOption textOption; + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + + QTextLayout textLayout(text); + textLayout.setFont(m_nameLabel->font()); + textLayout.setTextOption(textOption); + + QString wrappedText; + wrappedText.reserve(text.length()); + + // wrap the text to fit into the width of m_nameLabel + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + while (line.isValid()) { + line.setLineWidth(m_nameLabel->width()); + wrappedText += text.mid(line.textStart(), line.textLength()); + + line = textLayout.createLine(); + if (line.isValid()) { + wrappedText += QChar::LineSeparator; + } + } + textLayout.endLayout(); + + m_nameLabel->setText(wrappedText); +} + +void InformationPanel::init() +{ + const int spacing = KDialog::spacingHint(); + + m_infoTimer = new QTimer(this); + m_infoTimer->setInterval(300); + m_infoTimer->setSingleShot(true); + connect(m_infoTimer, SIGNAL(timeout()), + this, SLOT(slotInfoTimeout())); + + // Initialize timer for disabling an outdated preview with a small + // delay. This prevents flickering if the new preview can be generated + // within a very small timeframe. + m_outdatedPreviewTimer = new QTimer(this); + m_outdatedPreviewTimer->setInterval(300); + m_outdatedPreviewTimer->setSingleShot(true); + connect(m_outdatedPreviewTimer, SIGNAL(timeout()), + this, SLOT(markOutdatedPreview())); + + QVBoxLayout* layout = new QVBoxLayout; + layout->setSpacing(spacing); + + // name + m_nameLabel = new QLabel(this); + QFont font = m_nameLabel->font(); + font.setBold(true); + m_nameLabel->setFont(font); + m_nameLabel->setAlignment(Qt::AlignHCenter); + m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + // preview + m_preview = new PixmapViewer(this); + m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); + m_preview->setMinimumHeight(KIconLoader::SizeEnormous); + + if (MetaDataWidget::metaDataAvailable()) { + // rating, comment and tags + m_metaDataWidget = new MetaDataWidget(this); + m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + } + + // general meta text information + m_metaTextLabel = new MetaTextLabel(this); + m_metaTextLabel->setMinimumWidth(spacing); + m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + layout->addWidget(m_nameLabel); + layout->addWidget(new KSeparator(this)); + layout->addWidget(m_preview); + layout->addWidget(new KSeparator(this)); + if (m_metaDataWidget != 0) { + layout->addWidget(m_metaDataWidget); + layout->addWidget(new KSeparator(this)); + } + layout->addWidget(m_metaTextLabel); + + // ensure that widgets in the information side bar are aligned towards the top + layout->addStretch(1); + setLayout(layout); + + org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(), + QDBusConnection::sessionBus(), this); + connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString))); + connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString))); + connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList))); + connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList))); + connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString))); + connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString))); + + m_initialized = true; +} + +#include "informationpanel.moc" diff --git a/src/panels/information/informationpanel.h b/src/panels/information/informationpanel.h new file mode 100644 index 000000000..527148ae8 --- /dev/null +++ b/src/panels/information/informationpanel.h @@ -0,0 +1,194 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef INFORMATIONPANEL_H +#define INFORMATIONPANEL_H + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +class QPixmap; +class QString; +class KFileItem; +class QLabel; +class PixmapViewer; +class MetaDataWidget; +class MetaTextLabel; + +/** + * @brief Panel for showing meta information of one ore more selected items. + */ +class InformationPanel : public Panel +{ + Q_OBJECT + +public: + explicit InformationPanel(QWidget* parent = 0); + virtual ~InformationPanel(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + +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. + */ + void setSelection(const KFileItemList& selection); + + /** + * Does a delayed request of information for the item \a item. + * If within this delay InformationPanel::setUrl() or InformationPanel::setSelection() + * are invoked, then the request will be skipped. Requesting a delayed item information + * makes sense when hovering items. + */ + void requestDelayedItemInfo(const KFileItem& item); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + + /** @see QWidget::resizeEvent() */ + virtual void resizeEvent(QResizeEvent* event); + +private slots: + /** + * Shows the information for the item of the URL which has been provided by + * InformationPanel::requestItemInfo() and provides default actions. + */ + void showItemInfo(); + + /** + * Triggered if the request for item information has timed out. + * @see InformationPanel::requestDelayedItemInfo() + */ + void slotInfoTimeout(); + + /** + * Marks the currently shown preview as outdated + * by greying the content. + */ + void markOutdatedPreview(); + + /** + * Is invoked if no preview is available for the item. In this + * case the icon will be shown. + */ + void showIcon(const KFileItem& item); + + /** + * Is invoked if a preview is available for the item. The preview + * \a pixmap is shown inside the info page. + */ + void showPreview(const KFileItem& item, const QPixmap& pixmap); + + void slotFileRenamed(const QString& source, const QString& dest); + void slotFilesAdded(const QString& directory); + void slotFilesChanged(const QStringList& files); + void slotFilesRemoved(const QStringList& files); + void slotEnteredDirectory(const QString& directory); + void slotLeftDirectory(const QString& directory); + +private: + /** + * Checks whether the an URL is repesented by a place. If yes, + * then the place icon and name are shown instead of a preview. + * @return True, if the URL represents exactly a place. + * @param url The url to check. + */ + bool applyPlace(const KUrl& url); + + /** Assures that any pending item information request is cancelled. */ + void cancelRequest(); + + /** + * Shows the meta information for the current shown item inside + * a label. + */ + void showMetaInfo(); + + /** + * Converts the meta key \a key to a readable format into \a text. + * Returns true, if the string \a key represents a meta information + * that should be shown. If false is returned, \a text is not modified. + */ + bool convertMetaInfo(const QString& key, QString& text) const; + + /** + * Returns the item for file where the preview and meta information + * should be received, if InformationPanel::showMultipleSelectionInfo() + * returns false. + */ + KFileItem fileItem() const; + + /** + * Returns true, if the meta information should be shown for + * the multiple selected items that are stored in + * m_selection. If true is returned, it is assured that + * m_selection.count() > 1. If false is returned, the meta + * information should be shown for the file + * InformationPanel::fileUrl(); + */ + bool showMultipleSelectionInfo() const; + + /** + * Returns true, if \a url is equal to the shown URL m_shownUrl. + */ + bool isEqualToShownUrl(const KUrl& url) const; + + /** + * Sets the text for the label \a m_nameLabel and assures that the + * text is split in a way that it can be wrapped within the + * label width (QLabel::setWordWrap() does not work if the + * text represents one extremely long word). + */ + void setNameLabelText(const QString& text); + + void init(); + +private: + bool m_initialized; + bool m_pendingPreview; + QTimer* m_infoTimer; + QTimer* m_outdatedPreviewTimer; + KUrl m_shownUrl; // URL that is shown as info + KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay + KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null) + KFileItemList m_selection; + + QLabel* m_nameLabel; + PixmapViewer* m_preview; + MetaDataWidget* m_metaDataWidget; + MetaTextLabel* m_metaTextLabel; +}; + +#endif // INFORMATIONPANEL_H diff --git a/src/panels/information/infosidebarpage.cpp b/src/panels/information/infosidebarpage.cpp deleted file mode 100644 index 9eb35bc8d..000000000 --- a/src/panels/information/infosidebarpage.cpp +++ /dev/null @@ -1,587 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "infosidebarpage.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "settings/dolphinsettings.h" -#include "metadatawidget.h" -#include "metatextlabel.h" -#include "pixmapviewer.h" - -InfoSidebarPage::InfoSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_initialized(false), - m_pendingPreview(false), - m_infoTimer(0), - m_outdatedPreviewTimer(0), - m_shownUrl(), - m_urlCandidate(), - m_fileItem(), - m_selection(), - m_nameLabel(0), - m_preview(0), - m_metaDataWidget(0), - m_metaTextLabel(0) -{ -} - -InfoSidebarPage::~InfoSidebarPage() -{ -} - -QSize InfoSidebarPage::sizeHint() const -{ - QSize size = SidebarPage::sizeHint(); - size.setWidth(minimumSizeHint().width()); - return size; -} - -void InfoSidebarPage::setUrl(const KUrl& url) -{ - SidebarPage::setUrl(url); - if (url.isValid() && !isEqualToShownUrl(url)) { - if (isVisible()) { - cancelRequest(); - m_shownUrl = url; - showItemInfo(); - } else { - m_shownUrl = url; - } - } -} - -void InfoSidebarPage::setSelection(const KFileItemList& selection) -{ - if (!isVisible()) { - return; - } - - if ((selection.count() == 0) && (m_selection.count() == 0)) { - // The selection has not really changed, only the current index. - // QItemSelectionModel emits a signal in this case and it is less - // expensive doing the check this way instead of patching - // DolphinView::emitSelectionChanged(). - return; - } - - m_selection = selection; - - const int count = selection.count(); - if (count == 0) { - if (!isEqualToShownUrl(url())) { - m_shownUrl = url(); - showItemInfo(); - } - } else { - if ((count == 1) && !selection.first().url().isEmpty()) { - m_urlCandidate = selection.first().url(); - } - m_infoTimer->start(); - } -} - -void InfoSidebarPage::requestDelayedItemInfo(const KFileItem& item) -{ - if (!isVisible()) { - return; - } - - cancelRequest(); - - m_fileItem = KFileItem(); - if (item.isNull()) { - // The cursor is above the viewport. If files are selected, - // show information regarding the selection. - if (m_selection.size() > 0) { - m_pendingPreview = false; - m_infoTimer->start(); - } - } else { - const KUrl url = item.url(); - if (url.isValid() && !isEqualToShownUrl(url)) { - m_urlCandidate = item.url(); - m_fileItem = item; - m_infoTimer->start(); - } - } -} - -void InfoSidebarPage::showEvent(QShowEvent* event) -{ - SidebarPage::showEvent(event); - if (!event->spontaneous()) { - if (!m_initialized) { - // do a delayed initialization so that no performance - // penalty is given when Dolphin is started with a closed - // Information Panel - init(); - } - showItemInfo(); - } -} - -void InfoSidebarPage::resizeEvent(QResizeEvent* event) -{ - if (isVisible()) { - // If the text inside the name label or the info label cannot - // get wrapped, then the maximum width of the label is increased - // so that the width of the information sidebar gets increased. - // To prevent this, the maximum width is adjusted to - // the current width of the sidebar. - const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; - m_nameLabel->setMaximumWidth(maxWidth); - - // try to increase the preview as large as possible - m_preview->setSizeHint(QSize(maxWidth, maxWidth)); - m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done - m_infoTimer->start(); - } - - SidebarPage::resizeEvent(event); -} - -void InfoSidebarPage::showItemInfo() -{ - if (!isVisible()) { - return; - } - - cancelRequest(); - - if (showMultipleSelectionInfo()) { - KIconLoader iconLoader; - QPixmap icon = iconLoader.loadIcon("dialog-information", - KIconLoader::NoGroup, - KIconLoader::SizeEnormous); - m_preview->setPixmap(icon); - setNameLabelText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count())); - m_shownUrl = KUrl(); - } else { - const KFileItem item = fileItem(); - const KUrl itemUrl = item.url(); - if (!applyPlace(itemUrl)) { - // try to get a preview pixmap from the item... - m_pendingPreview = true; - - // Mark the currently shown preview as outdated. This is done - // with a small delay to prevent a flickering when the next preview - // can be shown within a short timeframe. - m_outdatedPreviewTimer->start(); - - KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, - m_preview->width(), - m_preview->height(), - 0, - 0, - false, - true); - - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(showPreview(const KFileItem&, const QPixmap&))); - connect(job, SIGNAL(failed(const KFileItem&)), - this, SLOT(showIcon(const KFileItem&))); - - setNameLabelText(itemUrl.fileName()); - } - } - - showMetaInfo(); -} - -void InfoSidebarPage::slotInfoTimeout() -{ - m_shownUrl = m_urlCandidate; - showItemInfo(); -} - -void InfoSidebarPage::markOutdatedPreview() -{ - KIconEffect iconEffect; - QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(), - KIconLoader::Desktop, - KIconLoader::DisabledState); - m_preview->setPixmap(disabledPixmap); -} - -void InfoSidebarPage::showIcon(const KFileItem& item) -{ - m_outdatedPreviewTimer->stop(); - m_pendingPreview = false; - if (!applyPlace(item.url())) { - m_preview->setPixmap(item.pixmap(KIconLoader::SizeEnormous)); - } -} - -void InfoSidebarPage::showPreview(const KFileItem& item, - const QPixmap& pixmap) -{ - m_outdatedPreviewTimer->stop(); - - Q_UNUSED(item); - if (m_pendingPreview) { - m_preview->setPixmap(pixmap); - m_pendingPreview = false; - } -} - -void InfoSidebarPage::slotFileRenamed(const QString& source, const QString& dest) -{ - if (m_shownUrl == KUrl(source)) { - // the currently shown file has been renamed, hence update the item information - // for the renamed file - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotFilesAdded(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - // If the 'trash' icon changes because the trash has been emptied or got filled, - // the signal filesAdded("trash:/") will be emitted. - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotFilesChanged(const QStringList& files) -{ - foreach (const QString& fileName, files) { - if (m_shownUrl == KUrl(fileName)) { - showItemInfo(); - break; - } - } -} - -void InfoSidebarPage::slotFilesRemoved(const QStringList& files) -{ - foreach (const QString& fileName, files) { - if (m_shownUrl == KUrl(fileName)) { - // the currently shown item has been removed, show - // the parent directory as fallback - m_shownUrl = url(); - showItemInfo(); - break; - } - } -} - -void InfoSidebarPage::slotEnteredDirectory(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(directory)); - requestDelayedItemInfo(item); - } -} - -void InfoSidebarPage::slotLeftDirectory(const QString& directory) -{ - if (m_shownUrl == KUrl(directory)) { - // The signal 'leftDirectory' is also emitted when a media - // has been unmounted. In this case no directory change will be - // done in Dolphin, but the Information Panel must be updated to - // indicate an invalid directory. - m_shownUrl = url(); - showItemInfo(); - } -} - -bool InfoSidebarPage::applyPlace(const KUrl& url) -{ - KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); - int count = placesModel->rowCount(); - - for (int i = 0; i < count; ++i) { - QModelIndex index = placesModel->index(i, 0); - - if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { - setNameLabelText(placesModel->text(index)); - m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); - return true; - } - } - - return false; -} - -void InfoSidebarPage::cancelRequest() -{ - m_infoTimer->stop(); -} - -void InfoSidebarPage::showMetaInfo() -{ - m_metaTextLabel->clear(); - - if (showMultipleSelectionInfo()) { - if (m_metaDataWidget != 0) { - KUrl::List urls; - foreach (const KFileItem& item, m_selection) { - urls.append(item.targetUrl()); - } - m_metaDataWidget->setFiles(urls); - } - - quint64 totalSize = 0; - foreach (const KFileItem& item, m_selection) { - // Only count the size of files, not dirs to match what - // DolphinViewContainer::selectionStatusBarText() does. - if (!item.isDir() && !item.isLink()) { - totalSize += item.size(); - } - } - m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); - } else { - const KFileItem item = fileItem(); - if (item.isDir()) { - m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); - m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); - } else { - m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment()); - - m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size())); - m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); - - if (item.isLocalFile()) { - // TODO: See convertMetaInfo below, find a way to display only interesting information - // in a readable way - const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | - KFileMetaInfo::TechnicalInfo | - KFileMetaInfo::ContentInfo; - const QString path = item.url().path(); - const KFileMetaInfo fileMetaInfo(path, QString(), flags); - if (fileMetaInfo.isValid()) { - const QHash& items = fileMetaInfo.items(); - QHash::const_iterator it = items.constBegin(); - const QHash::const_iterator end = items.constEnd(); - QString labelText; - while (it != end) { - const KFileMetaInfoItem& metaInfoItem = it.value(); - const QVariant& value = metaInfoItem.value(); - if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { - m_metaTextLabel->add(labelText, value.toString()); - } - ++it; - } - } - } - } - - if (m_metaDataWidget != 0) { - m_metaDataWidget->setFile(item.targetUrl()); - } - } -} - -bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const -{ - struct MetaKey { - const char* key; - QString text; - }; - - // sorted list of keys, where its data should be shown - static const MetaKey keys[] = { - { "http://freedesktop.org/standards/xesam/1.0/core#album", i18nc("@label", "Album:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#artist", i18nc("@label", "Artist:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#genre", i18nc("@label", "Genre:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#lineCount", i18nc("@label", "Lines:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#title", i18nc("@label", "Title:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#type", i18nc("@label", "Type:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#trackNumber", i18nc("@label", "Track:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width:") } - }; - - // do a binary search for the key... - int top = 0; - int bottom = sizeof(keys) / sizeof(MetaKey) - 1; - while (top <= bottom) { - const int middle = (top + bottom) / 2; - const int result = key.compare(keys[middle].key); - if (result < 0) { - bottom = middle - 1; - } else if (result > 0) { - top = middle + 1; - } else { - text = keys[middle].text; - return true; - } - } - - return false; -} - -KFileItem InfoSidebarPage::fileItem() const -{ - if (!m_fileItem.isNull()) { - return m_fileItem; - } - - if (!m_selection.isEmpty()) { - Q_ASSERT(m_selection.count() == 1); - return m_selection.first(); - } - - // no item is hovered and no selection has been done: provide - // an item for the directory represented by m_shownUrl - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); - item.refresh(); - return item; -} - -bool InfoSidebarPage::showMultipleSelectionInfo() const -{ - return m_fileItem.isNull() && (m_selection.count() > 1); -} - -bool InfoSidebarPage::isEqualToShownUrl(const KUrl& url) const -{ - return m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash); -} - -void InfoSidebarPage::setNameLabelText(const QString& text) -{ - QTextOption textOption; - textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - - QTextLayout textLayout(text); - textLayout.setFont(m_nameLabel->font()); - textLayout.setTextOption(textOption); - - QString wrappedText; - wrappedText.reserve(text.length()); - - // wrap the text to fit into the width of m_nameLabel - textLayout.beginLayout(); - QTextLine line = textLayout.createLine(); - while (line.isValid()) { - line.setLineWidth(m_nameLabel->width()); - wrappedText += text.mid(line.textStart(), line.textLength()); - - line = textLayout.createLine(); - if (line.isValid()) { - wrappedText += QChar::LineSeparator; - } - } - textLayout.endLayout(); - - m_nameLabel->setText(wrappedText); -} - -void InfoSidebarPage::init() -{ - const int spacing = KDialog::spacingHint(); - - m_infoTimer = new QTimer(this); - m_infoTimer->setInterval(300); - m_infoTimer->setSingleShot(true); - connect(m_infoTimer, SIGNAL(timeout()), - this, SLOT(slotInfoTimeout())); - - // Initialize timer for disabling an outdated preview with a small - // delay. This prevents flickering if the new preview can be generated - // within a very small timeframe. - m_outdatedPreviewTimer = new QTimer(this); - m_outdatedPreviewTimer->setInterval(300); - m_outdatedPreviewTimer->setSingleShot(true); - connect(m_outdatedPreviewTimer, SIGNAL(timeout()), - this, SLOT(markOutdatedPreview())); - - QVBoxLayout* layout = new QVBoxLayout; - layout->setSpacing(spacing); - - // name - m_nameLabel = new QLabel(this); - QFont font = m_nameLabel->font(); - font.setBold(true); - m_nameLabel->setFont(font); - m_nameLabel->setAlignment(Qt::AlignHCenter); - m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - // preview - m_preview = new PixmapViewer(this); - m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); - m_preview->setMinimumHeight(KIconLoader::SizeEnormous); - - if (MetaDataWidget::metaDataAvailable()) { - // rating, comment and tags - m_metaDataWidget = new MetaDataWidget(this); - m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - } - - // general meta text information - m_metaTextLabel = new MetaTextLabel(this); - m_metaTextLabel->setMinimumWidth(spacing); - m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - layout->addWidget(m_nameLabel); - layout->addWidget(new KSeparator(this)); - layout->addWidget(m_preview); - layout->addWidget(new KSeparator(this)); - if (m_metaDataWidget != 0) { - layout->addWidget(m_metaDataWidget); - layout->addWidget(new KSeparator(this)); - } - layout->addWidget(m_metaTextLabel); - - // ensure that widgets in the information side bar are aligned towards the top - layout->addStretch(1); - setLayout(layout); - - org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(), - QDBusConnection::sessionBus(), this); - connect(dirNotify, SIGNAL(FileRenamed(QString, QString)), SLOT(slotFileRenamed(QString, QString))); - connect(dirNotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString))); - connect(dirNotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList))); - connect(dirNotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList))); - connect(dirNotify, SIGNAL(enteredDirectory(QString)), SLOT(slotEnteredDirectory(QString))); - connect(dirNotify, SIGNAL(leftDirectory(QString)), SLOT(slotLeftDirectory(QString))); - - m_initialized = true; -} - -#include "infosidebarpage.moc" diff --git a/src/panels/information/infosidebarpage.h b/src/panels/information/infosidebarpage.h deleted file mode 100644 index 879a245ad..000000000 --- a/src/panels/information/infosidebarpage.h +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef INFOSIDEBARPAGE_H -#define INFOSIDEBARPAGE_H - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -class QPixmap; -class QString; -class KFileItem; -class QLabel; -class PixmapViewer; -class MetaDataWidget; -class MetaTextLabel; - -/** - * @brief Sidebar for showing meta information of one ore more selected items. - */ -class InfoSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - explicit InfoSidebarPage(QWidget* parent = 0); - virtual ~InfoSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - -public slots: - /** @see SidebarPage::setUrl() */ - virtual void setUrl(const KUrl& url); - - /** - * This is invoked to inform the sidebar that the user has selected a new - * set of items. - */ - void setSelection(const KFileItemList& selection); - - /** - * Does a delayed request of information for the item \a item. - * If within this delay InfoSidebarPage::setUrl() or InfoSidebarPage::setSelection() - * are invoked, then the request will be skipped. Requesting a delayed item information - * makes sense when hovering items. - */ - void requestDelayedItemInfo(const KFileItem& item); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - - /** @see QWidget::resizeEvent() */ - virtual void resizeEvent(QResizeEvent* event); - -private slots: - /** - * Shows the information for the item of the URL which has been provided by - * InfoSidebarPage::requestItemInfo() and provides default actions. - */ - void showItemInfo(); - - /** - * Triggered if the request for item information has timed out. - * @see InfoSidebarPage::requestDelayedItemInfo() - */ - void slotInfoTimeout(); - - /** - * Marks the currently shown preview as outdated - * by greying the content. - */ - void markOutdatedPreview(); - - /** - * Is invoked if no preview is available for the item. In this - * case the icon will be shown. - */ - void showIcon(const KFileItem& item); - - /** - * Is invoked if a preview is available for the item. The preview - * \a pixmap is shown inside the info page. - */ - void showPreview(const KFileItem& item, const QPixmap& pixmap); - - void slotFileRenamed(const QString& source, const QString& dest); - void slotFilesAdded(const QString& directory); - void slotFilesChanged(const QStringList& files); - void slotFilesRemoved(const QStringList& files); - void slotEnteredDirectory(const QString& directory); - void slotLeftDirectory(const QString& directory); - -private: - /** - * Checks whether the an URL is repesented by a place. If yes, - * then the place icon and name are shown instead of a preview. - * @return True, if the URL represents exactly a place. - * @param url The url to check. - */ - bool applyPlace(const KUrl& url); - - /** Assures that any pending item information request is cancelled. */ - void cancelRequest(); - - /** - * Shows the meta information for the current shown item inside - * a label. - */ - void showMetaInfo(); - - /** - * Converts the meta key \a key to a readable format into \a text. - * Returns true, if the string \a key represents a meta information - * that should be shown. If false is returned, \a text is not modified. - */ - bool convertMetaInfo(const QString& key, QString& text) const; - - /** - * Returns the item for file where the preview and meta information - * should be received, if InfoSidebarPage::showMultipleSelectionInfo() - * returns false. - */ - KFileItem fileItem() const; - - /** - * Returns true, if the meta information should be shown for - * the multiple selected items that are stored in - * m_selection. If true is returned, it is assured that - * m_selection.count() > 1. If false is returned, the meta - * information should be shown for the file - * InfosidebarPage::fileUrl(); - */ - bool showMultipleSelectionInfo() const; - - /** - * Returns true, if \a url is equal to the shown URL m_shownUrl. - */ - bool isEqualToShownUrl(const KUrl& url) const; - - /** - * Sets the text for the label \a m_nameLabel and assures that the - * text is split in a way that it can be wrapped within the - * label width (QLabel::setWordWrap() does not work if the - * text represents one extremely long word). - */ - void setNameLabelText(const QString& text); - - void init(); - -private: - bool m_initialized; - bool m_pendingPreview; - QTimer* m_infoTimer; - QTimer* m_outdatedPreviewTimer; - KUrl m_shownUrl; // URL that is shown as info - KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay - KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null) - KFileItemList m_selection; - - QLabel* m_nameLabel; - PixmapViewer* m_preview; - MetaDataWidget* m_metaDataWidget; - MetaTextLabel* m_metaTextLabel; -}; - -#endif // INFOSIDEBARPAGE_H diff --git a/src/panels/panel.cpp b/src/panels/panel.cpp new file mode 100644 index 000000000..e8f5c8277 --- /dev/null +++ b/src/panels/panel.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "panel.h" +#include +#include +#include + +Panel::Panel(QWidget* parent) : + QWidget(parent), + m_url(KUrl()) +{ +} + +Panel::~Panel() +{ +} + +const KUrl& Panel::url() const +{ + return m_url; +} + +void Panel::setUrl(const KUrl& url) +{ + m_url = url; +} + +#include "panel.moc" diff --git a/src/panels/panel.h b/src/panels/panel.h new file mode 100644 index 000000000..b056ca1cb --- /dev/null +++ b/src/panels/panel.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef PANEL_H +#define PANEL_H + +#include +#include +#include + +/** + * @brief Base widget for all panels that can be docked on the window borders. + */ +class Panel : public QWidget +{ + Q_OBJECT + +public: + explicit Panel(QWidget* parent = 0); + virtual ~Panel(); + + /** Returns the current set URL of the active Dolphin view. */ + 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); + +private: + KUrl m_url; +}; + +#endif // PANEL_H diff --git a/src/panels/places/dolphinfileplacesview.cpp b/src/panels/places/dolphinfileplacesview.cpp deleted file mode 100644 index df3e6fd87..000000000 --- a/src/panels/places/dolphinfileplacesview.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinfileplacesview.h" -#include "draganddrophelper.h" -#include -#include - -DolphinFilePlacesView::DolphinFilePlacesView(QWidget* parent) : - KFilePlacesView(parent), - m_mouseButtons(Qt::NoButton) -{ - setDropOnPlaceEnabled(true); - connect(this, SIGNAL(urlsDropped(const KUrl&, QDropEvent*, QWidget*)), - this, SLOT(slotUrlsDropped(const KUrl&, QDropEvent*, QWidget*))); - connect(this, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(emitExtendedUrlChangedSignal(const KUrl&))); -} - -DolphinFilePlacesView::~DolphinFilePlacesView() -{ -} - -void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event) -{ - m_mouseButtons = event->buttons(); - KFilePlacesView::mousePressEvent(event); -} - -void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) -{ - DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent); -} - -void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url) -{ - emit urlChanged(url, m_mouseButtons); -} - -#include "dolphinfileplacesview.moc" diff --git a/src/panels/places/dolphinfileplacesview.h b/src/panels/places/dolphinfileplacesview.h deleted file mode 100644 index 46d574606..000000000 --- a/src/panels/places/dolphinfileplacesview.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINFILEPLACESVIEW_H -#define DOLPHINFILEPLACESVIEW_H - -#include - -/** - * @brief Combines bookmarks and mounted devices as list which is - * embedded as panel. - */ -class DolphinFilePlacesView : public KFilePlacesView -{ - Q_OBJECT - -public: - DolphinFilePlacesView(QWidget* parent); - virtual ~DolphinFilePlacesView(); - -signals: - void urlChanged(const KUrl& url, Qt::MouseButtons buttons); - -protected: - virtual void mousePressEvent(QMouseEvent* event); - -private slots: - void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); - void emitExtendedUrlChangedSignal(const KUrl& url); - -private: - Qt::MouseButtons m_mouseButtons; -}; - -#endif // DOLPHINFILEPLACESVIEW_H diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp new file mode 100644 index 000000000..e1e63ba9b --- /dev/null +++ b/src/panels/places/placespanel.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2008 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "placespanel.h" +#include "draganddrophelper.h" +#include +#include + +PlacesPanel::PlacesPanel(QWidget* parent) : + KFilePlacesView(parent), + m_mouseButtons(Qt::NoButton) +{ + setDropOnPlaceEnabled(true); + connect(this, SIGNAL(urlsDropped(const KUrl&, QDropEvent*, QWidget*)), + this, SLOT(slotUrlsDropped(const KUrl&, QDropEvent*, QWidget*))); + connect(this, SIGNAL(urlChanged(const KUrl&)), + this, SLOT(emitExtendedUrlChangedSignal(const KUrl&))); +} + +PlacesPanel::~PlacesPanel() +{ +} + +void PlacesPanel::mousePressEvent(QMouseEvent* event) +{ + m_mouseButtons = event->buttons(); + KFilePlacesView::mousePressEvent(event); +} + +void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) +{ + DragAndDropHelper::instance().dropUrls(KFileItem(), dest, event, parent); +} + +void PlacesPanel::emitExtendedUrlChangedSignal(const KUrl& url) +{ + emit urlChanged(url, m_mouseButtons); +} + +#include "placespanel.moc" diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h new file mode 100644 index 000000000..1b6681af8 --- /dev/null +++ b/src/panels/places/placespanel.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2008 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef PLACESPANEL_H +#define PLACESPANEL_H + +#include + +/** + * @brief Combines bookmarks and mounted devices as list. + */ +class PlacesPanel : public KFilePlacesView +{ + Q_OBJECT + +public: + PlacesPanel(QWidget* parent); + virtual ~PlacesPanel(); + +signals: + void urlChanged(const KUrl& url, Qt::MouseButtons buttons); + +protected: + virtual void mousePressEvent(QMouseEvent* event); + +private slots: + void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); + void emitExtendedUrlChangedSignal(const KUrl& url); + +private: + Qt::MouseButtons m_mouseButtons; +}; + +#endif // PLACESPANEL_H diff --git a/src/panels/sidebarpage.cpp b/src/panels/sidebarpage.cpp deleted file mode 100644 index 594f59f24..000000000 --- a/src/panels/sidebarpage.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "sidebarpage.h" -#include -#include -#include - -SidebarPage::SidebarPage(QWidget* parent) : - QWidget(parent), - m_url(KUrl()) -{ -} - -SidebarPage::~SidebarPage() -{ -} - -const KUrl& SidebarPage::url() const -{ - return m_url; -} - -void SidebarPage::setUrl(const KUrl& url) -{ - m_url = url; -} - -#include "sidebarpage.moc" diff --git a/src/panels/sidebarpage.h b/src/panels/sidebarpage.h deleted file mode 100644 index 20a44758e..000000000 --- a/src/panels/sidebarpage.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef _SIDEBARPAGE_H_ -#define _SIDEBARPAGE_H_ - -#include -#include -#include - -/** - * @brief Base widget for all pages that can be embedded into the Sidebar. - */ -class SidebarPage : public QWidget -{ - Q_OBJECT - -public: - explicit SidebarPage(QWidget* parent = 0); - virtual ~SidebarPage(); - - /** Returns the current set URL of the active Dolphin view. */ - 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); - -private: - KUrl m_url; -}; - -#endif // _SIDEBARPAGE_H_ diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp new file mode 100644 index 000000000..cc3b85318 --- /dev/null +++ b/src/panels/terminal/terminalpanel.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * Copyright (C) 2007 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "terminalpanel.h" + +#include +#include +#include +#include + +#include +#include + +TerminalPanel::TerminalPanel(QWidget* parent) : + Panel(parent), + m_layout(0), + m_terminal(0), + m_terminalWidget(0) +{ + m_layout = new QVBoxLayout(this); + m_layout->setMargin(0); +} + +TerminalPanel::~TerminalPanel() +{ +} + +QSize TerminalPanel::sizeHint() const +{ + QSize size = Panel::sizeHint(); + size.setHeight(200); + return size; +} + +void TerminalPanel::setUrl(const KUrl& url) +{ + if (!url.isValid() || (url == Panel::url())) { + return; + } + + Panel::setUrl(url); + if ((m_terminal != 0) && isVisible() && url.isLocalFile()) { + m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n'); + } +} + +void TerminalPanel::terminalExited() +{ + emit hideTerminalPanel(); + m_terminal = 0; +} + +void TerminalPanel::showEvent(QShowEvent* event) +{ + if (event->spontaneous()) { + Panel::showEvent(event); + return; + } + + if (m_terminal == 0) { + KPluginFactory* factory = KPluginLoader("libkonsolepart").factory(); + KParts::ReadOnlyPart* part = factory ? (factory->create(this)) : 0; + if (part != 0) { + connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited())); + m_terminalWidget = part->widget(); + m_layout->addWidget(m_terminalWidget); + m_terminal = qobject_cast(part); + m_terminal->showShellInDir(url().path()); + } + } + if (m_terminal != 0) { + m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n'); + m_terminal->sendInput("clear\n"); + m_terminalWidget->setFocus(); + } + + Panel::showEvent(event); +} + +#include "terminalpanel.moc" diff --git a/src/panels/terminal/terminalpanel.h b/src/panels/terminal/terminalpanel.h new file mode 100644 index 000000000..672938c32 --- /dev/null +++ b/src/panels/terminal/terminalpanel.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2007 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef TERMINALPANEL_H +#define TERMINALPANEL_H + +#include + +class TerminalInterface; +class QVBoxLayout; +class QWidget; + +/** + * @brief Shows the terminal which is synchronized with the URL of the + * active view. + */ +class TerminalPanel : public Panel +{ + Q_OBJECT + +public: + TerminalPanel(QWidget* parent = 0); + virtual ~TerminalPanel(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + +public slots: + /** @see Panel::setUrl(). */ + virtual void setUrl(const KUrl& url); + void terminalExited(); + +signals: + void hideTerminalPanel(); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + +private: + QVBoxLayout* m_layout; + TerminalInterface* m_terminal; + QWidget* m_terminalWidget; +}; + +#endif // TERMINALPANEL_H diff --git a/src/panels/terminal/terminalsidebarpage.cpp b/src/panels/terminal/terminalsidebarpage.cpp deleted file mode 100644 index 4749e7714..000000000 --- a/src/panels/terminal/terminalsidebarpage.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "terminalsidebarpage.h" - -#include -#include -#include -#include - -#include -#include - -TerminalSidebarPage::TerminalSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_layout(0), - m_terminal(0), - m_terminalWidget(0) -{ - m_layout = new QVBoxLayout(this); - m_layout->setMargin(0); -} - -TerminalSidebarPage::~TerminalSidebarPage() -{ -} - -QSize TerminalSidebarPage::sizeHint() const -{ - QSize size = SidebarPage::sizeHint(); - size.setHeight(200); - return size; -} - -void TerminalSidebarPage::setUrl(const KUrl& url) -{ - if (!url.isValid() || (url == SidebarPage::url())) { - return; - } - - SidebarPage::setUrl(url); - if ((m_terminal != 0) && isVisible() && url.isLocalFile()) { - m_terminal->sendInput("cd " + KShell::quoteArg(url.path()) + '\n'); - } -} - -void TerminalSidebarPage::terminalExited() -{ - emit hideTerminalSidebarPage(); - - m_terminal = 0; -} - -void TerminalSidebarPage::showEvent(QShowEvent* event) -{ - if (event->spontaneous()) { - SidebarPage::showEvent(event); - return; - } - - if (m_terminal == 0) { - KPluginFactory* factory = KPluginLoader("libkonsolepart").factory(); - KParts::ReadOnlyPart* part = factory ? (factory->create(this)) : 0; - if (part != 0) { - connect(part, SIGNAL(destroyed(QObject*)), this, SLOT(terminalExited())); - m_terminalWidget = part->widget(); - m_layout->addWidget(m_terminalWidget); - m_terminal = qobject_cast(part); - m_terminal->showShellInDir(url().path()); - } - } - if (m_terminal != 0) { - m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n'); - m_terminal->sendInput("clear\n"); - m_terminalWidget->setFocus(); - } - - SidebarPage::showEvent(event); -} - -#include "terminalsidebarpage.moc" diff --git a/src/panels/terminal/terminalsidebarpage.h b/src/panels/terminal/terminalsidebarpage.h deleted file mode 100644 index 4e8c40593..000000000 --- a/src/panels/terminal/terminalsidebarpage.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef TERMINALSIDEBARPAGE_H -#define TERMINALSIDEBARPAGE_H - -#include - -class TerminalInterface; -class QVBoxLayout; -class QWidget; - -/** - * @brief Shows the terminal which is synchronized with the URL of the - * active view. - */ -class TerminalSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - TerminalSidebarPage(QWidget* parent = 0); - virtual ~TerminalSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - -public slots: - /** @see SidebarPage::setUrl(). */ - virtual void setUrl(const KUrl& url); - void terminalExited(); - -signals: - void hideTerminalSidebarPage(); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - -private: - QVBoxLayout* m_layout; - TerminalInterface* m_terminal; - QWidget* m_terminalWidget; -}; - -#endif // TERMINALSIDEBARPAGE_H -- cgit v1.3