From 8d4fb3608927960d9e45e672ce1cbe1fa3a548f9 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 10 Oct 2007 23:01:35 +0000 Subject: DolphinPart: provide a way to switch between view modes in konqueror. Factorized those actions between dolphinmainwindow and dolphinpart (see new methods in dolphinview), and simplified mainwindow code by using the signal from the action group and the QVariant data of the actions (standard Qt4 solution for a group of actions). svn path=/trunk/KDE/kdebase/apps/; revision=723871 --- src/dolphinpart.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 092d2e14a..31cde2931 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -18,6 +18,9 @@ */ #include "dolphinpart.h" +#include +#include +#include #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinmodel.h" @@ -67,6 +70,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi m_proxyModel); setWidget(m_view); + setXMLFile("dolphinpart.rc"); + connect(m_view, SIGNAL(infoMessage(QString)), this, SLOT(slotInfoMessage(QString))); connect(m_view, SIGNAL(errorMessage(QString)), @@ -81,7 +86,11 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi connect(m_view, SIGNAL(requestItemInfo(KFileItem)), this, SLOT(slotRequestItemInfo(KFileItem))); - // TODO provide a way to switch from iconview to listview (and others) + createActions(); + updateViewActions(); + + // TODO provide these actions in the menu, merged with the existing view-mode-actions somehow + // [Q_PROPERTY introspection?] // TODO connect to urlsDropped @@ -102,6 +111,24 @@ DolphinPart::~DolphinPart() delete m_dirLister; } +void DolphinPart::createActions() +{ + QActionGroup* viewModeActions = new QActionGroup(this); + viewModeActions->addAction(DolphinView::iconsModeAction(actionCollection())); + viewModeActions->addAction(DolphinView::detailsModeAction(actionCollection())); + viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection())); + connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); +} + +void DolphinPart::updateViewActions() +{ + QAction* action = actionCollection()->action(m_view->currentViewModeActionName()); + if (action != 0) { + KToggleAction* toggleAction = static_cast(action); + toggleAction->setChecked(true); + } +} + KAboutData* DolphinPart::createAboutData() { return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1"); @@ -191,4 +218,10 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&) emit m_extension->popupMenu( QCursor::pos(), items, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags ); } +void DolphinPart::slotViewModeActionTriggered(QAction* action) +{ + const DolphinView::Mode mode = action->data().value(); + m_view->setMode(mode); +} + #include "dolphinpart.moc" -- cgit v1.3