From c00478bbc1001d10dcfc04e9b0ea251620837e85 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 21 Jan 2008 19:08:52 +0000 Subject: Revert the moving of the action to the DolphinView instance, this doesn't work with splitted views. (Each view would need its own action collection, but then DolphinView would have to become a KXMLGUIClient, and the GUI would flicker when switching views). Instead, use the same solution as the other shared actions: static method in DolphinView (for now), slot in the mainwindow (and for the more complex actions than this one, shared code in DolphinView) svn path=/branches/KDE/4.0/kdebase/apps/; revision=764429 --- src/dolphinmainwindow.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 2048de1a5..1da9377c7 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -422,6 +423,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group) } } +void DolphinMainWindow::createDir() +{ + const KUrl& url = m_activeViewContainer->view()->url(); + KonqOperations::newDir(this, url); +} + void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); @@ -985,6 +992,9 @@ void DolphinMainWindow::setupActions() connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); + KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); + connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); + KAction* newWindow = actionCollection()->addAction("new_window"); newWindow->setIcon(KIcon("window-new")); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); -- cgit v1.3 From af333d9c7a8f344ed7f2a5cae02b383a5d0ee792 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 21 Jan 2008 19:42:16 +0000 Subject: Make sort/descending available in dolphinpart svn path=/branches/KDE/4.0/kdebase/apps/; revision=764444 --- src/dolphinmainwindow.cpp | 9 ++------- src/dolphinpart.cpp | 16 ++++++++++++++++ src/dolphinpart.h | 3 +++ src/dolphinview.cpp | 15 +++++++++++++++ src/dolphinview.h | 9 +++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 1da9377c7..407ec16b4 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -650,11 +650,7 @@ void DolphinMainWindow::sortByTags() void DolphinMainWindow::toggleSortOrder() { - DolphinView* view = m_activeViewContainer->view(); - const Qt::SortOrder order = (view->sortOrder() == Qt::AscendingOrder) ? - Qt::DescendingOrder : - Qt::AscendingOrder; - view->setSortOrder(order); + m_activeViewContainer->view()->toggleSortOrder(); } void DolphinMainWindow::toggleSortCategorization() @@ -1126,8 +1122,7 @@ void DolphinMainWindow::setupActions() //sortGroup->addAction(sortByRating); //sortGroup->addAction(sortByTags); - KToggleAction* sortDescending = actionCollection()->add("descending"); - sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); KToggleAction* showInGroups = actionCollection()->add("show_in_groups"); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 2c4c1eaa3..e7c919ad8 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -93,6 +93,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -144,6 +146,13 @@ void DolphinPart::createActions() propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return); connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties())); + // View menu + + // TODO sort_by_* + + KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); + connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder())); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -431,4 +440,11 @@ void DolphinPart::createDir() KonqOperations::newDir(m_view, url()); } +void DolphinPart::slotSortOrderChanged(Qt::SortOrder order) +{ + KToggleAction* descending = static_cast(actionCollection()->action("descending")); + const bool sortDescending = (order == Qt::DescendingOrder); + descending->setChecked(sortDescending); +} + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 04161b6be..883cf9456 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -136,6 +136,9 @@ private Q_SLOTS: */ void createDir(); + /** Updates the state of the 'Sort Ascending/Descending' action. */ + void slotSortOrderChanged(Qt::SortOrder); + private: void createActions(); void createGoAction(const char* name, const char* iconName, diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 138971360..cccbd36b9 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -794,6 +794,14 @@ void DolphinView::updateSortOrder(Qt::SortOrder order) emit sortOrderChanged(order); } +void DolphinView::toggleSortOrder() +{ + const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ? + Qt::DescendingOrder : + Qt::AscendingOrder; + setSortOrder(order); +} + void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info) { ViewProperties props(viewPropertiesUrl()); @@ -1257,4 +1265,11 @@ KAction* DolphinView::createNewDirAction(KActionCollection* collection) return newDirAction; } +KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) +{ + KToggleAction* sortDescending = collection->add("descending"); + sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + return sortDescending; +} + #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 8076a62f0..80430ca77 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -368,6 +368,12 @@ public: */ static KAction* createNewDirAction(KActionCollection* collection); + /** + * Creates the "sort descending" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createSortDescendingAction(KActionCollection* collection); + /** * Returns the action name corresponding to the current view mode */ @@ -423,6 +429,9 @@ public slots: /** Pastes the clipboard data to this view. */ void paste(); + /** Switches between an ascending and descending sorting order. */ + void toggleSortOrder(); + signals: /** * Is emitted if the view has been activated by e. g. a mouse click. -- cgit v1.3 From d34f1d1b466a8163a2274fa6763e1049233f00bb Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 22 Jan 2008 00:39:52 +0000 Subject: Use a QActionGroup and save 6 slots (and the duplication of the action names in the code). svn path=/branches/KDE/4.0/kdebase/apps/; revision=764537 --- src/dolphinmainwindow.cpp | 63 ++++++----------------------------------------- src/dolphinmainwindow.h | 30 ++++------------------ src/dolphinview.cpp | 37 ++++++++++++++++++++++++++++ src/dolphinview.h | 7 ++++++ 4 files changed, 56 insertions(+), 81 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 407ec16b4..ce13796ac 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -660,36 +660,6 @@ void DolphinMainWindow::toggleSortCategorization() view->setCategorizedSorting(!categorizedSorting); } -void DolphinMainWindow::toggleSizeInfo() -{ - toggleAdditionalInfo("show_size_info", KFileItemDelegate::Size); -} - -void DolphinMainWindow::toggleDateInfo() -{ - toggleAdditionalInfo("show_date_info", KFileItemDelegate::ModificationTime); -} - -void DolphinMainWindow::togglePermissionsInfo() -{ - toggleAdditionalInfo("show_permissions_info", KFileItemDelegate::Permissions); -} - -void DolphinMainWindow::toggleOwnerInfo() -{ - toggleAdditionalInfo("show_owner_info", KFileItemDelegate::Owner); -} - -void DolphinMainWindow::toggleGroupInfo() -{ - toggleAdditionalInfo("show_group_info", KFileItemDelegate::OwnerAndGroup); -} - -void DolphinMainWindow::toggleMimeInfo() -{ - toggleAdditionalInfo("show_mime_info", KFileItemDelegate::FriendlyMimeType); -} - void DolphinMainWindow::toggleSplitView() { if (m_viewContainer[SecondaryView] == 0) { @@ -1129,29 +1099,8 @@ void DolphinMainWindow::setupActions() showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); connect(showInGroups, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); - KToggleAction* showSizeInfo = actionCollection()->add("show_size_info"); - showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); - connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(toggleSizeInfo())); - - KToggleAction* showDateInfo = actionCollection()->add("show_date_info"); - showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); - connect(showDateInfo, SIGNAL(triggered()), this, SLOT(toggleDateInfo())); - - KToggleAction* showPermissionsInfo = actionCollection()->add("show_permissions_info"); - showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); - connect(showPermissionsInfo, SIGNAL(triggered()), this, SLOT(togglePermissionsInfo())); - - KToggleAction* showOwnerInfo = actionCollection()->add("show_owner_info"); - showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); - connect(showOwnerInfo, SIGNAL(triggered()), this, SLOT(toggleOwnerInfo())); - - KToggleAction* showGroupInfo = actionCollection()->add("show_group_info"); - showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); - connect(showGroupInfo, SIGNAL(triggered()), this, SLOT(toggleGroupInfo())); - - KToggleAction* showMimeInfo = actionCollection()->add("show_mime_info"); - showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); - connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(toggleMimeInfo())); + QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); + connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); KToggleAction* showPreview = actionCollection()->add("show_preview"); showPreview->setText(i18nc("@action:intoolbar", "Preview")); @@ -1472,15 +1421,17 @@ void DolphinMainWindow::updateSplitAction() } } -void DolphinMainWindow::toggleAdditionalInfo(const char* actionName, - KFileItemDelegate::Information info) +void DolphinMainWindow::toggleAdditionalInfo(QAction* action) { clearStatusBar(); + const KFileItemDelegate::Information info = + static_cast(action->data().toInt()); + DolphinView* view = m_activeViewContainer->view(); KFileItemDelegate::InformationList list = view->additionalInfo(); - const bool show = actionCollection()->action(actionName)->isChecked(); + const bool show = action->isChecked(); const int index = list.indexOf(info); const bool containsInfo = (index >= 0); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index e99add896..ab96cd155 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -273,23 +273,11 @@ private slots: /** Switches between sorting by categories or not. */ void toggleSortCategorization(); - /** Switches between showing the size as additional information for the item or not. */ - void toggleSizeInfo(); - - /** Switchtes between showing the date as additional information for the item or not. */ - void toggleDateInfo(); - - /** Switchtes between showing the permissions as additional information for the item or not. */ - void togglePermissionsInfo(); - - /** Switchtes between showing the owner as additional information for the item or not. */ - void toggleOwnerInfo(); - - /** Switchtes between showing the group as additional information for the item or not. */ - void toggleGroupInfo(); - - /** Switches between showing the MIME type as additional information for the item or not. */ - void toggleMimeInfo(); + /** + * Applies \a info dependent from the current checked state of the action + * \a actionName to the file item delegate. + */ + void toggleAdditionalInfo(QAction* action); /** * Switches between one and two views: @@ -453,14 +441,6 @@ private: */ void updateSplitAction(); - /** - * Helper method for the slots toggleDateInfo(), toggleSizeInfo() - * and toggleMimeInfo(). Applies \a info dependent from the current - * checked state of the action \a actionName to the file item delegate. - */ - void toggleAdditionalInfo(const char* actionName, - KFileItemDelegate::Information info); - private: /** * DolphinMainWindow supports up to two views beside each other. diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index cccbd36b9..de57aa00d 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -1272,4 +1272,41 @@ KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) return sortDescending; } +QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) +{ + QActionGroup* showInformationGroup = new QActionGroup(collection); + + KToggleAction* showSizeInfo = collection->add("show_size_info"); + showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); + showSizeInfo->setData(KFileItemDelegate::Size); + showSizeInfo->setActionGroup(showInformationGroup); + + KToggleAction* showDateInfo = collection->add("show_date_info"); + showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); + showDateInfo->setData(KFileItemDelegate::ModificationTime); + showDateInfo->setActionGroup(showInformationGroup); + + KToggleAction* showPermissionsInfo = collection->add("show_permissions_info"); + showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); + showPermissionsInfo->setData(KFileItemDelegate::Permissions); + showPermissionsInfo->setActionGroup(showInformationGroup); + + KToggleAction* showOwnerInfo = collection->add("show_owner_info"); + showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); + showOwnerInfo->setData(KFileItemDelegate::Owner); + showOwnerInfo->setActionGroup(showInformationGroup); + + KToggleAction* showGroupInfo = collection->add("show_group_info"); + showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); + showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); + showGroupInfo->setActionGroup(showInformationGroup); + + KToggleAction* showMimeInfo = collection->add("show_mime_info"); + showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); + showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); + showMimeInfo->setActionGroup(showInformationGroup); + + return showInformationGroup; +} + #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 80430ca77..e69f0bbc6 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -38,6 +38,7 @@ #include #include +class QActionGroup; class KAction; class KToggleAction; class DolphinController; @@ -374,6 +375,12 @@ public: */ static KAction* createSortDescendingAction(KActionCollection* collection); + /** + * Creates an action group with all the "show additional information" actions in it. + * This code is here to share it between the mainwindow and the part + */ + static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); + /** * Returns the action name corresponding to the current view mode */ -- cgit v1.3 From 13706a2952a7e8b9af6a9cf33d43200c3d360c41 Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 22 Jan 2008 01:22:56 +0000 Subject: Move the code handling the additional-info-actions to DolphinView; simplify signal from DolphinView (it has the info anyway). The fact that the last additional-info doesn't show up in the icon view is in fact a KFileItemDelegate bug, not a bug in this code :) svn path=/branches/KDE/4.0/kdebase/apps/; revision=764544 --- src/dolphindetailsview.cpp | 2 +- src/dolphiniconsview.cpp | 11 ++++--- src/dolphiniconsview.h | 2 +- src/dolphinmainwindow.cpp | 82 +++++----------------------------------------- src/dolphinmainwindow.h | 6 ++-- src/dolphinview.cpp | 80 +++++++++++++++++++++++++++++++++++++++++--- src/dolphinview.h | 15 +++++++-- 7 files changed, 108 insertions(+), 90 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 4fdb76e1a..2861c134f 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -101,7 +101,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr this, SLOT(zoomIn())); connect(controller, SIGNAL(zoomOut()), this, SLOT(zoomOut())); - connect(controller->dolphinView(), SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), + connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()), this, SLOT(updateColumnVisibility())); // apply the details mode settings to the widget diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 553cdcfe6..d3d485f1a 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -78,8 +78,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle const DolphinView* view = controller->dolphinView(); connect(view, SIGNAL(showPreviewChanged()), this, SLOT(slotShowPreviewChanged())); - connect(view, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), - this, SLOT(slotAdditionalInfoChanged(const KFileItemDelegate::InformationList&))); + connect(view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); connect(this, SIGNAL(entered(const QModelIndex&)), this, SLOT(slotEntered(const QModelIndex&))); @@ -301,10 +301,11 @@ void DolphinIconsView::slotShowPreviewChanged() updateGridSize(view->showPreview(), additionalInfoCount()); } -void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info) +void DolphinIconsView::slotAdditionalInfoChanged() { - const bool showPreview = m_controller->dolphinView()->showPreview(); - updateGridSize(showPreview, info.count()); + const DolphinView* view = m_controller->dolphinView(); + const bool showPreview = view->showPreview(); + updateGridSize(showPreview, view->additionalInfo().count()); } void DolphinIconsView::zoomIn() diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 06c417868..af65bbda8 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -67,7 +67,7 @@ private slots: void triggerItem(const QModelIndex& index); void slotEntered(const QModelIndex& index); void slotShowPreviewChanged(); - void slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info); + void slotAdditionalInfoChanged(); void zoomIn(); void zoomOut(); diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ce13796ac..44a44efa2 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -256,58 +256,10 @@ void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) descending->setChecked(sortDescending); } -void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::InformationList list) -{ - QAction* showSizeInfo = actionCollection()->action("show_size_info"); - QAction* showDateInfo = actionCollection()->action("show_date_info"); - QAction* showPermissionsInfo = actionCollection()->action("show_permissions_info"); - QAction* showOwnerInfo = actionCollection()->action("show_owner_info"); - QAction* showGroupInfo = actionCollection()->action("show_group_info"); - QAction* showMimeInfo = actionCollection()->action("show_mime_info"); - - showSizeInfo->setChecked(false); - showDateInfo->setChecked(false); - showPermissionsInfo->setChecked(false); - showOwnerInfo->setChecked(false); - showGroupInfo->setChecked(false); - showMimeInfo->setChecked(false); - - const DolphinView* view = m_activeViewContainer->view(); - - const bool enable = (view->mode() == DolphinView::DetailsView) || - (view->mode() == DolphinView::IconsView); - - showSizeInfo->setEnabled(enable); - showDateInfo->setEnabled(enable); - showPermissionsInfo->setEnabled(enable); - showOwnerInfo->setEnabled(enable); - showGroupInfo->setEnabled(enable); - showMimeInfo->setEnabled(enable); - - foreach (KFileItemDelegate::Information info, list) { - switch (info) { - case KFileItemDelegate::Size: - showSizeInfo->setChecked(true); - break; - case KFileItemDelegate::ModificationTime: - showDateInfo->setChecked(true); - break; - case KFileItemDelegate::Permissions: - showPermissionsInfo->setChecked(true); - break; - case KFileItemDelegate::Owner: - showOwnerInfo->setChecked(true); - break; - case KFileItemDelegate::OwnerAndGroup: - showGroupInfo->setChecked(true); - break; - case KFileItemDelegate::FriendlyMimeType: - showMimeInfo->setChecked(true); - break; - default: - break; - } - } +void DolphinMainWindow::slotAdditionalInfoChanged() +{ + DolphinView* view = m_activeViewContainer->view(); + view->updateAdditionalInfoActions(actionCollection()); } void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) @@ -1333,7 +1285,7 @@ void DolphinMainWindow::updateViewActions() slotSortingChanged(view->sorting()); slotSortOrderChanged(view->sortOrder()); slotCategorizedSortingChanged(); - slotAdditionalInfoChanged(view->additionalInfo()); + slotAdditionalInfoChanged(); KToggleAction* showFilterBarAction = static_cast(actionCollection()->action("show_filter_bar")); @@ -1386,8 +1338,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) this, SLOT(slotSortingChanged(DolphinView::Sorting))); connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::InformationList)), - this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::InformationList))); + connect(view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); connect(view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(slotSelectionChanged(KFileItemList))); connect(view, SIGNAL(requestItemInfo(KFileItem)), @@ -1424,25 +1376,7 @@ void DolphinMainWindow::updateSplitAction() void DolphinMainWindow::toggleAdditionalInfo(QAction* action) { clearStatusBar(); - - const KFileItemDelegate::Information info = - static_cast(action->data().toInt()); - - DolphinView* view = m_activeViewContainer->view(); - KFileItemDelegate::InformationList list = view->additionalInfo(); - - const bool show = action->isChecked(); - - const int index = list.indexOf(info); - const bool containsInfo = (index >= 0); - if (show && !containsInfo) { - list.append(info); - view->setAdditionalInfo(list); - } else if (!show && containsInfo) { - list.removeAt(index); - view->setAdditionalInfo(list); - Q_ASSERT(list.indexOf(info) < 0); - } + m_activeViewContainer->view()->toggleAdditionalInfo(action); } DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index ab96cd155..444a4a946 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -274,8 +274,8 @@ private slots: void toggleSortCategorization(); /** - * Applies \a info dependent from the current checked state of the action - * \a actionName to the file item delegate. + * Switches on or off the displaying of additional information + * as specified by \a action. */ void toggleAdditionalInfo(QAction* action); @@ -376,7 +376,7 @@ private slots: void slotSortOrderChanged(Qt::SortOrder order); /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(KFileItemDelegate::InformationList info); + void slotAdditionalInfoChanged(); /** * Updates the state of the 'Edit' menu actions and emits diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 575af51bd..4aeabb265 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -215,7 +215,7 @@ void DolphinView::setMode(Mode mode) // additional information manually const KFileItemDelegate::InformationList infoList = props.additionalInfo(); m_fileItemDelegate->setShowInformation(infoList); - emit additionalInfoChanged(infoList); + emit additionalInfoChanged(); // Not all view modes support categorized sorting. Adjust the sorting model // if changing the view mode results in a change of the categorized sorting @@ -467,7 +467,7 @@ void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info) props.setAdditionalInfo(info); m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(info); + emit additionalInfoChanged(); if (itemView() != m_detailsView) { // the details view requires no reloading of the directory, as it maps @@ -708,7 +708,7 @@ void DolphinView::applyViewProperties(const KUrl& url) KFileItemDelegate::InformationList info = props.additionalInfo(); if (info != m_fileItemDelegate->showInformation()) { m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(info); + emit additionalInfoChanged(); } const bool showPreview = props.showPreview(); @@ -810,8 +810,80 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(info); + emit additionalInfoChanged(); // will call updateAdditionalInfoActions just below +} + +void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) +{ + const bool enable = (m_mode == DolphinView::DetailsView) || + (m_mode == DolphinView::IconsView); + + QAction* showSizeInfo = collection->action("show_size_info"); + QAction* showDateInfo = collection->action("show_date_info"); + QAction* showPermissionsInfo = collection->action("show_permissions_info"); + QAction* showOwnerInfo = collection->action("show_owner_info"); + QAction* showGroupInfo = collection->action("show_group_info"); + QAction* showMimeInfo = collection->action("show_mime_info"); + + showSizeInfo->setChecked(false); + showDateInfo->setChecked(false); + showPermissionsInfo->setChecked(false); + showOwnerInfo->setChecked(false); + showGroupInfo->setChecked(false); + showMimeInfo->setChecked(false); + + showSizeInfo->setEnabled(enable); + showDateInfo->setEnabled(enable); + showPermissionsInfo->setEnabled(enable); + showOwnerInfo->setEnabled(enable); + showGroupInfo->setEnabled(enable); + showMimeInfo->setEnabled(enable); + + foreach (KFileItemDelegate::Information info, m_fileItemDelegate->showInformation()) { + switch (info) { + case KFileItemDelegate::Size: + showSizeInfo->setChecked(true); + break; + case KFileItemDelegate::ModificationTime: + showDateInfo->setChecked(true); + break; + case KFileItemDelegate::Permissions: + showPermissionsInfo->setChecked(true); + break; + case KFileItemDelegate::Owner: + showOwnerInfo->setChecked(true); + break; + case KFileItemDelegate::OwnerAndGroup: + showGroupInfo->setChecked(true); + break; + case KFileItemDelegate::FriendlyMimeType: + showMimeInfo->setChecked(true); + break; + default: + break; + } + } +} + +void DolphinView::toggleAdditionalInfo(QAction* action) +{ + const KFileItemDelegate::Information info = + static_cast(action->data().toInt()); + + KFileItemDelegate::InformationList list = additionalInfo(); + const bool show = action->isChecked(); + + const int index = list.indexOf(info); + const bool containsInfo = (index >= 0); + if (show && !containsInfo) { + list.append(info); + setAdditionalInfo(list); + } else if (!show && containsInfo) { + list.removeAt(index); + setAdditionalInfo(list); + Q_ASSERT(list.indexOf(info) < 0); + } } void DolphinView::emitContentsMoved() diff --git a/src/dolphinview.h b/src/dolphinview.h index e69f0bbc6..a85c184ef 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -381,6 +381,11 @@ public: */ static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); + /** + * Updates the state of the 'Additional Information' actions in \a collection. + */ + void updateAdditionalInfoActions(KActionCollection* collection); + /** * Returns the action name corresponding to the current view mode */ @@ -439,6 +444,12 @@ public slots: /** Switches between an ascending and descending sorting order. */ void toggleSortOrder(); + /** + * Switches on or off the displaying of additional information + * as specified by \a action. + */ + void toggleAdditionalInfo(QAction* action); + signals: /** * Is emitted if the view has been activated by e. g. a mouse click. @@ -474,8 +485,8 @@ signals: /** Is emitted if the sort order (ascending or descending) has been changed. */ void sortOrderChanged(Qt::SortOrder order); - /** Is emitted if the additional information for an item has been changed. */ - void additionalInfoChanged(const KFileItemDelegate::InformationList& info); + /** Is emitted if the additional information shown for this view has been changed. */ + void additionalInfoChanged(); /** * Is emitted if information of an item is requested to be shown e. g. in the sidebar. -- cgit v1.3 From cdc40d4398510878e5ff5926be3f87e6ac5108c9 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 28 Jan 2008 11:33:49 +0000 Subject: Centralize three more actions so that they are available in DolphinPart: 'Show preview' 'Show hidden files' 'Categorized sorting' Found a way of sharing the actions with even less code duplication, discussed it with Peter, but this will be for after 4.0.1 svn path=/branches/KDE/4.0/kdebase/apps/; revision=767566 --- src/dolphinmainwindow.cpp | 78 ++++++++++++++++------------------------------- src/dolphinmainwindow.h | 14 ++++----- src/dolphinpart.cpp | 38 ++++++++++++++++++++++- src/dolphinpart.h | 9 ++++++ src/dolphinview.cpp | 23 ++++++++++++++ src/dolphinview.h | 74 +++++++++++++++++++++++++++++--------------- 6 files changed, 150 insertions(+), 86 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 44a44efa2..2ed59279f 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -191,16 +191,14 @@ void DolphinMainWindow::slotShowPreviewChanged() void DolphinMainWindow::slotShowHiddenFilesChanged() { - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); const DolphinView* view = m_activeViewContainer->view(); showHiddenFilesAction->setChecked(view->showHiddenFiles()); } void DolphinMainWindow::slotCategorizedSortingChanged() { - KToggleAction* showInGroupsAction = - static_cast(actionCollection()->action("show_in_groups")); + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); const DolphinView* view = m_activeViewContainer->view(); showInGroupsAction->setChecked(view->categorizedSorting()); showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); @@ -244,14 +242,13 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) } if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } } void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) { - KToggleAction* descending = static_cast(actionCollection()->action("descending")); + QAction* descending = actionCollection()->action("descending"); const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); } @@ -297,8 +294,7 @@ void DolphinMainWindow::slotHistoryChanged() void DolphinMainWindow::updateFilterBarAction(bool show) { - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(show); } @@ -605,11 +601,10 @@ void DolphinMainWindow::toggleSortOrder() m_activeViewContainer->view()->toggleSortOrder(); } -void DolphinMainWindow::toggleSortCategorization() +void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) { DolphinView* view = m_activeViewContainer->view(); - const bool categorizedSorting = view->categorizedSorting(); - view->setCategorizedSorting(!categorizedSorting); + view->setCategorizedSorting(categorizedSorting); } void DolphinMainWindow::toggleSplitView() @@ -657,31 +652,20 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::togglePreview() +void DolphinMainWindow::togglePreview(bool show) { clearStatusBar(); - - const KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); - const bool show = showPreviewAction->isChecked(); m_activeViewContainer->view()->setShowPreview(show); } -void DolphinMainWindow::toggleShowHiddenFiles() +void DolphinMainWindow::toggleShowHiddenFiles(bool show) { clearStatusBar(); - - const KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - const bool show = showHiddenFilesAction->isChecked(); m_activeViewContainer->view()->setShowHiddenFiles(show); } -void DolphinMainWindow::toggleFilterBarVisibility() +void DolphinMainWindow::toggleFilterBarVisibility(bool show) { - const KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - const bool show = showFilterBarAction->isChecked(); m_activeViewContainer->showFilterBar(show); } @@ -701,11 +685,9 @@ void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); - KToggleAction* action = static_cast(actionCollection()->action("editable_location")); - - bool editOrBrowse = action->isChecked(); + QAction* action = actionCollection()->action("editable_location"); KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); - urlNavigator->setUrlEditable(editOrBrowse); + urlNavigator->setUrlEditable(action->isChecked()); } void DolphinMainWindow::editLocation() @@ -979,6 +961,8 @@ void DolphinMainWindow::setupActions() viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + // TODO use a QActionGroup + KToggleAction* sortByName = actionCollection()->add("sort_by_name"); sortByName->setText(i18nc("@action:inmenu Sort By", "Name")); connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); @@ -1047,22 +1031,17 @@ void DolphinMainWindow::setupActions() KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - KToggleAction* showInGroups = actionCollection()->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - connect(showInGroups, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - KToggleAction* showPreview = actionCollection()->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview())); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - KToggleAction* showHiddenFiles = actionCollection()->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles())); + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); @@ -1117,7 +1096,7 @@ void DolphinMainWindow::setupActions() KToggleAction* showFilterBar = actionCollection()->add("show_filter_bar"); showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar")); showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(toggleFilterBarVisibility())); + connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool))); KAction* compareFiles = actionCollection()->addAction("compare_files"); compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files")); @@ -1278,8 +1257,7 @@ void DolphinMainWindow::updateViewActions() QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } slotSortingChanged(view->sorting()); @@ -1287,22 +1265,18 @@ void DolphinMainWindow::updateViewActions() slotCategorizedSortingChanged(); slotAdditionalInfoChanged(); - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); + QAction* showPreviewAction = actionCollection()->action("show_preview"); showPreviewAction->setChecked(view->showPreview()); - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); showHiddenFilesAction->setChecked(view->showHiddenFiles()); updateSplitAction(); - KToggleAction* editableLocactionAction = - static_cast(actionCollection()->action("editable_location")); + QAction* editableLocactionAction = actionCollection()->action("editable_location"); const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); editableLocactionAction->setChecked(urlNavigator->isUrlEditable()); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 444a4a946..37cdcb43e 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -271,7 +271,7 @@ private slots: void toggleSortOrder(); /** Switches between sorting by categories or not. */ - void toggleSortCategorization(); + void toggleSortCategorization(bool); /** * Switches on or off the displaying of additional information @@ -293,19 +293,17 @@ private slots: void stopLoading(); /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(); + void togglePreview(bool); /** - * Switches between showing and hiding of hidden marked files dependent - * from the current state of the 'Show Hidden Files' menu toggle action. + * Switches between showing and hiding of hidden marked files */ - void toggleShowHiddenFiles(); + void toggleShowHiddenFiles(bool); /** - * Toggles between showing and hiding of the filter bar dependent - * from the current state of the 'Show Filter Bar' menu toggle action. + * Toggles between showing and hiding of the filter bar */ - void toggleFilterBarVisibility(); + void toggleFilterBarVisibility(bool show); /** Increases the size of the current set view mode. */ void zoomIn(); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index f144109cb..4d2eebcc6 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -93,6 +93,13 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + connect(m_view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(m_view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(m_view, SIGNAL(categorizedSortingChanged()), + this, SLOT(slotCategorizedSortingChanged())); + // TODO slotSortingChanged connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); connect(m_view, SIGNAL(additionalInfoChanged()), @@ -110,7 +117,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi // [Q_PROPERTY introspection?] // TODO sort_by_* actions - // TODO show_*_info actions // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror // (sort of spacial navigation) @@ -158,6 +164,15 @@ void DolphinPart::createActions() QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), m_view, SLOT(setShowPreview(bool))); + + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), m_view, SLOT(setCategorizedSorting(bool))); + + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), m_view, SLOT(setShowHiddenFiles(bool))); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -457,4 +472,25 @@ void DolphinPart::slotAdditionalInfoChanged() m_view->updateAdditionalInfoActions(actionCollection()); } +void DolphinPart::slotShowPreviewChanged() +{ + updateViewActions(); // see DolphinMainWindow +} + +void DolphinPart::slotShowHiddenFilesChanged() +{ + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_view->showHiddenFiles()); +} + +void DolphinPart::slotCategorizedSortingChanged() +{ + // Duplicated from DolphinMainWindow too. + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); + showInGroupsAction->setChecked(m_view->categorizedSorting()); + showInGroupsAction->setEnabled(m_view->supportsCategorizedSorting()); +} + +// TODO a DolphinViewActionHandler for reducing the duplication in the action handling + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 3d9ec0306..797c34d71 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -136,6 +136,15 @@ private Q_SLOTS: */ void createDir(); + /** Updates the state of the 'Show preview' menu action. */ + void slotShowPreviewChanged(); + + /** Updates the state of the 'Show hidden files' menu action. */ + void slotShowHiddenFilesChanged(); + + /** Updates the state of the 'Categorized sorting' menu action. */ + void slotCategorizedSortingChanged(); + /** Updates the state of the 'Sort Ascending/Descending' action. */ void slotSortOrderChanged(Qt::SortOrder); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4aeabb265..530508fb7 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -1344,6 +1344,29 @@ KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) return sortDescending; } +KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) +{ + KToggleAction* showPreview = collection->add("show_preview"); + showPreview->setText(i18nc("@action:intoolbar", "Preview")); + showPreview->setIcon(KIcon("view-preview")); + return showPreview; +} + +KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) +{ + KToggleAction* showInGroups = collection->add("show_in_groups"); + showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); + return showInGroups; +} + +KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) +{ + KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); + showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); + showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); + return showHiddenFiles; +} + QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) { QActionGroup* showInformationGroup = new QActionGroup(collection); diff --git a/src/dolphinview.h b/src/dolphinview.h index a85c184ef..0c0bbcd2e 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -166,39 +166,18 @@ public: * Changes the view mode for the current directory to \a mode. * If the view properties should be remembered for each directory * (GeneralSettings::globalViewProps() returns false), then the - * changed view mode will be be stored automatically. + * changed view mode will be stored automatically. */ void setMode(Mode mode); Mode mode() const; - /** - * Turns on the file preview for the all files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * preview setting will be be stored automatically. - */ - void setShowPreview(bool show); + /** See setShowPreview */ bool showPreview() const; - /** - * Shows all hidden files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * show hidden file setting will be be stored automatically. - */ - void setShowHiddenFiles(bool show); + /** See setShowHiddenFiles */ bool showHiddenFiles() const; - /** - * Summarizes all sorted items by their category \a categorized - * is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * categorized sorting setting will be be stored automatically. - */ - void setCategorizedSorting(bool categorized); + /** See setCategorizedSorting */ bool categorizedSorting() const; /** @@ -381,6 +360,24 @@ public: */ static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); + /** + * Creates the "show preview" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowPreviewAction(KActionCollection* collection); + + /** + * Creates the "show in groups" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowInGroupsAction(KActionCollection* collection); + + /** + * Creates the "show hidden files" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowHiddenFilesAction(KActionCollection* collection); + /** * Updates the state of the 'Additional Information' actions in \a collection. */ @@ -441,6 +438,33 @@ public slots: /** Pastes the clipboard data to this view. */ void paste(); + /** + * Turns on the file preview for the all files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * preview setting will be stored automatically. + */ + void setShowPreview(bool show); + + /** + * Shows all hidden files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * show hidden file setting will be stored automatically. + */ + void setShowHiddenFiles(bool show); + + /** + * Summarizes all sorted items by their category \a categorized + * is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * categorized sorting setting will be stored automatically. + */ + void setCategorizedSorting(bool categorized); + /** Switches between an ascending and descending sorting order. */ void toggleSortOrder(); -- cgit v1.3 From 45a1074b0a38f38cfebde8bb65d5a6520b2db3e8 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 11 Feb 2008 12:34:48 +0000 Subject: Factorize all the view-related action handling to DolphinViewActionHandler, to remove code duplication between mainwindow and part, and to remove my code-splitting with the static createFooAction methods in the view. svn path=/branches/KDE/4.0/kdebase/apps/; revision=773570 --- src/CMakeLists.txt | 1 + src/dolphinmainwindow.cpp | 200 +++------------------------ src/dolphinmainwindow.h | 63 +-------- src/dolphinpart.cpp | 103 ++------------ src/dolphinpart.h | 28 +--- src/dolphinview.cpp | 106 +-------------- src/dolphinview.h | 54 -------- src/dolphinviewactionhandler.cpp | 286 +++++++++++++++++++++++++++++++++++++++ src/dolphinviewactionhandler.h | 165 ++++++++++++++++++++++ 9 files changed, 488 insertions(+), 518 deletions(-) create mode 100644 src/dolphinviewactionhandler.cpp create mode 100644 src/dolphinviewactionhandler.h (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9902dc66..b2cdfd582 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ set(dolphinprivate_LIB_SRCS dolphinsortfilterproxymodel.cpp renamedialog.cpp dolphinview.cpp + dolphinviewactionhandler.cpp ratingpainter.cpp dolphindropcontroller.cpp ) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 2ed59279f..c1d6cef39 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -20,6 +20,7 @@ ***************************************************************************/ #include "dolphinmainwindow.h" +#include "dolphinviewactionhandler.h" #include "dolphindropcontroller.h" #include @@ -60,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -182,28 +182,6 @@ void DolphinMainWindow::slotViewModeChanged() updateViewActions(); } -void DolphinMainWindow::slotShowPreviewChanged() -{ - // It is not enough to update the 'Show Preview' action, also - // the 'Zoom In' and 'Zoom Out' actions must be adapted. - updateViewActions(); -} - -void DolphinMainWindow::slotShowHiddenFilesChanged() -{ - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - const DolphinView* view = m_activeViewContainer->view(); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); -} - -void DolphinMainWindow::slotCategorizedSortingChanged() -{ - QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); - const DolphinView* view = m_activeViewContainer->view(); - showInGroupsAction->setChecked(view->categorizedSorting()); - showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); -} - void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) { QAction* action = 0; @@ -246,19 +224,6 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) } } -void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) -{ - QAction* descending = actionCollection()->action("descending"); - const bool sortDescending = (order == Qt::DescendingOrder); - descending->setChecked(sortDescending); -} - -void DolphinMainWindow::slotAdditionalInfoChanged() -{ - DolphinView* view = m_activeViewContainer->view(); - view->updateAdditionalInfoActions(actionCollection()); -} - void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { updateEditActions(); @@ -371,43 +336,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group) } } -void DolphinMainWindow::createDir() -{ - const KUrl& url = m_activeViewContainer->view()->url(); - KonqOperations::newDir(this, url); -} - void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); m_newMenu->setPopupFiles(activeViewContainer()->url()); } -void DolphinMainWindow::rename() -{ - clearStatusBar(); - m_activeViewContainer->view()->renameSelectedItems(); -} - -void DolphinMainWindow::moveToTrash() -{ - clearStatusBar(); - - DolphinView* view = m_activeViewContainer->view(); - - if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { - view->deleteSelectedItems(); - } else { - view->trashSelectedItems(); - } -} - -void DolphinMainWindow::deleteItems() -{ - clearStatusBar(); - m_activeViewContainer->view()->deleteSelectedItems(); -} - void DolphinMainWindow::properties() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); @@ -596,17 +530,6 @@ void DolphinMainWindow::sortByTags() #endif } -void DolphinMainWindow::toggleSortOrder() -{ - m_activeViewContainer->view()->toggleSortOrder(); -} - -void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) -{ - DolphinView* view = m_activeViewContainer->view(); - view->setCategorizedSorting(categorizedSorting); -} - void DolphinMainWindow::toggleSplitView() { if (m_viewContainer[SecondaryView] == 0) { @@ -639,7 +562,7 @@ void DolphinMainWindow::toggleSplitView() setActiveViewContainer(m_viewContainer[PrimaryView]); updateViewActions(); - emit activeViewChanged(); + emit activeViewChanged(); // TODO unused; remove? } void DolphinMainWindow::reloadView() @@ -652,35 +575,11 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::togglePreview(bool show) -{ - clearStatusBar(); - m_activeViewContainer->view()->setShowPreview(show); -} - -void DolphinMainWindow::toggleShowHiddenFiles(bool show) -{ - clearStatusBar(); - m_activeViewContainer->view()->setShowHiddenFiles(show); -} - void DolphinMainWindow::toggleFilterBarVisibility(bool show) { m_activeViewContainer->showFilterBar(show); } -void DolphinMainWindow::zoomIn() -{ - m_activeViewContainer->view()->zoomIn(); - updateViewActions(); -} - -void DolphinMainWindow::zoomOut() -{ - m_activeViewContainer->view()->zoomOut(); - updateViewActions(); -} - void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); @@ -820,6 +719,8 @@ void DolphinMainWindow::init() const KUrl& homeUrl = settings.generalSettings()->homeUrl(); setCaption(homeUrl.fileName()); + m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); + connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar())); ViewProperties props(homeUrl); m_viewContainer[PrimaryView] = new DolphinViewContainer(this, m_splitter, @@ -827,8 +728,10 @@ void DolphinMainWindow::init() m_activeViewContainer = m_viewContainer[PrimaryView]; connectViewSignals(PrimaryView); - m_viewContainer[PrimaryView]->view()->reload(); + DolphinView* view = m_viewContainer[PrimaryView]->view(); + view->reload(); m_viewContainer[PrimaryView]->show(); + m_actionHandler->setCurrentView(view); setCentralWidget(m_splitter); setupDockWidgets(); @@ -858,16 +761,16 @@ void DolphinMainWindow::init() emit urlChanged(homeUrl); } -void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* view) +void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { - Q_ASSERT(view != 0); - Q_ASSERT((view == m_viewContainer[PrimaryView]) || (view == m_viewContainer[SecondaryView])); - if (m_activeViewContainer == view) { + Q_ASSERT(viewContainer != 0); + Q_ASSERT((viewContainer == m_viewContainer[PrimaryView]) || (viewContainer == m_viewContainer[SecondaryView])); + if (m_activeViewContainer == viewContainer) { return; } m_activeViewContainer->setActive(false); - m_activeViewContainer = view; + m_activeViewContainer = viewContainer; m_activeViewContainer->setActive(true); updateHistory(); @@ -878,7 +781,9 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* view) const KUrl& url = m_activeViewContainer->url(); setCaption(url.fileName()); - emit activeViewChanged(); + m_actionHandler->setCurrentView(viewContainer->view()); + + emit activeViewChanged(); // TODO unused; remove? emit urlChanged(url); } @@ -892,24 +797,12 @@ void DolphinMainWindow::setupActions() connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); - KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - KAction* newWindow = actionCollection()->addAction("new_window"); newWindow->setIcon(KIcon("window-new")); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); newWindow->setShortcut(Qt::CTRL | Qt::Key_N); connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); - KAction* rename = DolphinView::createRenameAction(actionCollection()); - connect(rename, SIGNAL(triggered()), this, SLOT(rename())); - - KAction* moveToTrash = DolphinView::createMoveToTrashAction(actionCollection()); - connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); - - KAction* deleteAction = DolphinView::createDeleteAction(actionCollection()); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); - KAction* properties = actionCollection()->addAction("properties"); properties->setText(i18nc("@action:inmenu File", "Properties")); properties->setShortcut(Qt::ALT | Qt::Key_Return); @@ -942,14 +835,6 @@ void DolphinMainWindow::setupActions() connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); // setup 'View' menu - KStandardAction::zoomIn(this, - SLOT(zoomIn()), - actionCollection()); - - KStandardAction::zoomOut(this, - SLOT(zoomOut()), - actionCollection()); - KToggleAction* iconsView = DolphinView::iconsModeAction(actionCollection()); KToggleAction* detailsView = DolphinView::detailsModeAction(actionCollection()); @@ -961,6 +846,9 @@ void DolphinMainWindow::setupActions() viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + //QActionGroup* sortActionGroup = DolphinView::createSortActionGroup(actionCollection()); + //connect(sortActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(sortActionGroupTriggered(QAction*))); + // TODO use a QActionGroup KToggleAction* sortByName = actionCollection()->add("sort_by_name"); @@ -1028,21 +916,6 @@ void DolphinMainWindow::setupActions() //sortGroup->addAction(sortByRating); //sortGroup->addAction(sortByTags); - KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); - connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - - KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); - connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); - - QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); - connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - - KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); - connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - - KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); - connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); - KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); updateSplitAction(); @@ -1244,36 +1117,19 @@ void DolphinMainWindow::updateEditActions() void DolphinMainWindow::updateViewActions() { - const DolphinView* view = m_activeViewContainer->view(); - QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn)); - if (zoomInAction != 0) { - zoomInAction->setEnabled(view->isZoomInPossible()); - } - - QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut)); - if (zoomOutAction != 0) { - zoomOutAction->setEnabled(view->isZoomOutPossible()); - } + m_actionHandler->updateViewActions(); + const DolphinView* view = m_activeViewContainer->view(); QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { action->setChecked(true); } slotSortingChanged(view->sorting()); - slotSortOrderChanged(view->sortOrder()); - slotCategorizedSortingChanged(); - slotAdditionalInfoChanged(); QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - QAction* showPreviewAction = actionCollection()->action("show_preview"); - showPreviewAction->setChecked(view->showPreview()); - - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); - updateSplitAction(); QAction* editableLocactionAction = actionCollection()->action("editable_location"); @@ -1302,18 +1158,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) DolphinView* view = container->view(); connect(view, SIGNAL(modeChanged()), this, SLOT(slotViewModeChanged())); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(slotSortingChanged(DolphinView::Sorting))); - connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); connect(view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(slotSelectionChanged(KFileItemList))); connect(view, SIGNAL(requestItemInfo(KFileItem)), @@ -1347,12 +1193,6 @@ void DolphinMainWindow::updateSplitAction() } } -void DolphinMainWindow::toggleAdditionalInfo(QAction* action) -{ - clearStatusBar(); - m_activeViewContainer->view()->toggleAdditionalInfo(action); -} - DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : KonqFileUndoManager::UiInterface(mainWin), m_mainWin(mainWin) diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 37cdcb43e..b1694c323 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -34,6 +34,7 @@ #include +class DolphinViewActionHandler; class DolphinApplication; class DolphinViewContainer; class KNewMenu; @@ -163,27 +164,11 @@ protected: virtual void readProperties(const KConfigGroup& group); private slots: - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); + void clearStatusBar(); /** Updates the 'Create New...' sub menu. */ void updateNewMenu(); - /** - * Let the user input a name for the selected item(s) and trigger - * a renaming afterwards. - */ - void rename(); - - /** Moves the selected items of the active view to the trash. */ - void moveToTrash(); - - /** Deletes the selected items of the active view. */ - void deleteItems(); - /** * Opens the properties window for the selected items of the * active view. The properties windows shows information @@ -267,18 +252,6 @@ private slots: /** The sorting of the current view should be done by tags. */ void sortByTags(); - /** Switches between an ascending and descending sorting order. */ - void toggleSortOrder(); - - /** Switches between sorting by categories or not. */ - void toggleSortCategorization(bool); - - /** - * Switches on or off the displaying of additional information - * as specified by \a action. - */ - void toggleAdditionalInfo(QAction* action); - /** * Switches between one and two views: * If one view is visible, it will get split into two views. @@ -292,25 +265,11 @@ private slots: /** Stops the loading process for the current active view. */ void stopLoading(); - /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(bool); - - /** - * Switches between showing and hiding of hidden marked files - */ - void toggleShowHiddenFiles(bool); - /** * Toggles between showing and hiding of the filter bar */ void toggleFilterBarVisibility(bool show); - /** Increases the size of the current set view mode. */ - void zoomIn(); - - /** Decreases the size of the current set view mode. */ - void zoomOut(); - /** * Toggles between edit and brose mode of the navigation bar. */ @@ -358,24 +317,9 @@ private slots: /** Updates the state of all 'View' menu actions. */ void slotViewModeChanged(); - /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); - /** Updates the state of the 'Sort by' actions. */ void slotSortingChanged(DolphinView::Sorting sorting); - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder order); - - /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); - /** * Updates the state of the 'Edit' menu actions and emits * the signal selectionChanged(). @@ -421,7 +365,6 @@ private: void updateEditActions(); void updateViewActions(); void updateGoActions(); - void clearStatusBar(); /** * Connects the signals from the created DolphinView with @@ -473,6 +416,8 @@ private: DolphinViewContainer* m_viewContainer[SecondaryView + 1]; + DolphinViewActionHandler* m_actionHandler; + /// remember pending undo operations until they are finished QList m_undoCommandTypes; }; diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 4d2eebcc6..b6f2698c3 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -18,14 +18,15 @@ */ #include "dolphinpart.h" -#include -#include +#include "dolphinviewactionhandler.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinmodel.h" #include +#include +#include #include #include #include @@ -93,17 +94,10 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); - connect(m_view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(m_view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(m_view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); // TODO slotSortingChanged - connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(m_view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); + + m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); + m_actionHandler->setCurrentView(m_view); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -135,16 +129,6 @@ void DolphinPart::createActions() viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection())); connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); - KAction* renameAction = DolphinView::createRenameAction(actionCollection()); - connect(renameAction, SIGNAL(triggered()), m_view, SLOT(renameSelectedItems())); - - KAction* moveToTrashAction = DolphinView::createMoveToTrashAction(actionCollection()); - connect(moveToTrashAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), - this, SLOT(slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers))); - - KAction* deleteAction = DolphinView::createDeleteAction(actionCollection()); - connect(deleteAction, SIGNAL(triggered()), m_view, SLOT(deleteSelectedItems())); - KAction *editMimeTypeAction = actionCollection()->addAction( "editMimeType" ); editMimeTypeAction->setText( i18nc("@action:inmenu Edit", "&Edit File Type..." ) ); connect(editMimeTypeAction, SIGNAL(triggered()), SLOT(slotEditMimeType())); @@ -154,30 +138,10 @@ void DolphinPart::createActions() propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return); connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties())); - // View menu - - // TODO sort_by_* - - KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); - connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder())); - - QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); - connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); - - KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); - connect(showPreview, SIGNAL(triggered(bool)), m_view, SLOT(setShowPreview(bool))); - - KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); - connect(showInGroups, SIGNAL(triggered(bool)), m_view, SLOT(setCategorizedSorting(bool))); - - KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); - connect(showHiddenFiles, SIGNAL(triggered(bool)), m_view, SLOT(setShowHiddenFiles(bool))); + // View menu: all done by DolphinViewActionHandler // Go menu - KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - QActionGroup* goActionGroup = new QActionGroup(this); connect(goActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotGoTriggered(QAction*))); @@ -248,10 +212,10 @@ void DolphinPart::updatePasteAction() void DolphinPart::updateViewActions() { + m_actionHandler->updateViewActions(); QAction* action = actionCollection()->action(m_view->currentViewModeActionName()); if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } } @@ -427,17 +391,6 @@ void DolphinPartBrowserExtension::paste() //// -void DolphinPart::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers) -{ - // Note: kde3's konq_mainwindow.cpp used to check - // reason == KAction::PopupMenuActivation && ... - // but this isn't supported anymore - if (modifiers & Qt::ShiftModifier) - m_view->deleteSelectedItems(); - else - m_view->trashSelectedItems(); -} - void DolphinPart::slotEditMimeType() { const KFileItemList items = m_view->selectedItems(); @@ -455,42 +408,4 @@ void DolphinPart::slotProperties() } } -void DolphinPart::createDir() -{ - KonqOperations::newDir(m_view, url()); -} - -void DolphinPart::slotSortOrderChanged(Qt::SortOrder order) -{ - KToggleAction* descending = static_cast(actionCollection()->action("descending")); - const bool sortDescending = (order == Qt::DescendingOrder); - descending->setChecked(sortDescending); -} - -void DolphinPart::slotAdditionalInfoChanged() -{ - m_view->updateAdditionalInfoActions(actionCollection()); -} - -void DolphinPart::slotShowPreviewChanged() -{ - updateViewActions(); // see DolphinMainWindow -} - -void DolphinPart::slotShowHiddenFilesChanged() -{ - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - showHiddenFilesAction->setChecked(m_view->showHiddenFiles()); -} - -void DolphinPart::slotCategorizedSortingChanged() -{ - // Duplicated from DolphinMainWindow too. - QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); - showInGroupsAction->setChecked(m_view->categorizedSorting()); - showInGroupsAction->setEnabled(m_view->supportsCategorizedSorting()); -} - -// TODO a DolphinViewActionHandler for reducing the duplication in the action handling - #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 797c34d71..795a7b194 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -22,6 +22,7 @@ #include #include +class DolphinViewActionHandler; class QActionGroup; class KAction; class KFileItemList; @@ -110,11 +111,6 @@ private Q_SLOTS: */ void updatePasteAction(); - /** - * Connected to the "move_to_trash" action; adds "shift means del" handling. - */ - void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers); - /** * Connected to all "Go" menu actions provided by DolphinPart */ @@ -130,27 +126,6 @@ private Q_SLOTS: */ void slotProperties(); - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); - - /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); - - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder); - - /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); - private: void createActions(); void createGoAction(const char* name, const char* iconName, @@ -159,6 +134,7 @@ private: private: DolphinView* m_view; + DolphinViewActionHandler* m_actionHandler; KDirLister* m_dirLister; DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 530508fb7..7979b06c3 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -810,7 +810,7 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(); // will call updateAdditionalInfoActions just below + emit additionalInfoChanged(); } void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) @@ -1301,108 +1301,4 @@ QPair DolphinView::pasteInfo() const return ret; } -KAction* DolphinView::createRenameAction(KActionCollection* collection) -{ - KAction* rename = collection->addAction("rename"); - rename->setText(i18nc("@action:inmenu File", "Rename...")); - rename->setShortcut(Qt::Key_F2); - return rename; -} - -KAction* DolphinView::createMoveToTrashAction(KActionCollection* collection) -{ - KAction* moveToTrash = collection->addAction("move_to_trash"); - moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash")); - moveToTrash->setIcon(KIcon("user-trash")); - moveToTrash->setShortcut(QKeySequence::Delete); - return moveToTrash; -} - -KAction* DolphinView::createDeleteAction(KActionCollection* collection) -{ - KAction* deleteAction = collection->addAction("delete"); - deleteAction->setIcon(KIcon("edit-delete")); - deleteAction->setText(i18nc("@action:inmenu File", "Delete")); - deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete); - return deleteAction; -} - -KAction* DolphinView::createNewDirAction(KActionCollection* collection) -{ - // This action doesn't appear in the GUI, it's for the shortcut only. - // KNewMenu takes care of the GUI stuff. - KAction* newDirAction = collection->addAction("create_dir"); - newDirAction->setText(i18n("Create Folder...")); - newDirAction->setShortcut(Qt::Key_F10); - return newDirAction; -} - -KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) -{ - KToggleAction* sortDescending = collection->add("descending"); - sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); - return sortDescending; -} - -KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) -{ - KToggleAction* showPreview = collection->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - return showPreview; -} - -KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) -{ - KToggleAction* showInGroups = collection->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - return showInGroups; -} - -KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) -{ - KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - return showHiddenFiles; -} - -QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) -{ - QActionGroup* showInformationGroup = new QActionGroup(collection); - showInformationGroup->setExclusive(false); - - KToggleAction* showSizeInfo = collection->add("show_size_info"); - showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); - showSizeInfo->setData(KFileItemDelegate::Size); - showSizeInfo->setActionGroup(showInformationGroup); - - KToggleAction* showDateInfo = collection->add("show_date_info"); - showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); - showDateInfo->setData(KFileItemDelegate::ModificationTime); - showDateInfo->setActionGroup(showInformationGroup); - - KToggleAction* showPermissionsInfo = collection->add("show_permissions_info"); - showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); - showPermissionsInfo->setData(KFileItemDelegate::Permissions); - showPermissionsInfo->setActionGroup(showInformationGroup); - - KToggleAction* showOwnerInfo = collection->add("show_owner_info"); - showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); - showOwnerInfo->setData(KFileItemDelegate::Owner); - showOwnerInfo->setActionGroup(showInformationGroup); - - KToggleAction* showGroupInfo = collection->add("show_group_info"); - showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); - showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); - showGroupInfo->setActionGroup(showInformationGroup); - - KToggleAction* showMimeInfo = collection->add("show_mime_info"); - showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); - showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); - showMimeInfo->setActionGroup(showInformationGroup); - - return showInformationGroup; -} - #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 0c0bbcd2e..6f0289f62 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -324,60 +324,6 @@ public: */ static KToggleAction* columnsModeAction(KActionCollection* collection); - /** - * Creates the rename action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createRenameAction(KActionCollection* collection); - - /** - * Creates the "move to trash" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createMoveToTrashAction(KActionCollection* collection); - - /** - * Creates the delete action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createDeleteAction(KActionCollection* collection); - - /** - * Creates the "new directory" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createNewDirAction(KActionCollection* collection); - - /** - * Creates the "sort descending" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createSortDescendingAction(KActionCollection* collection); - - /** - * Creates an action group with all the "show additional information" actions in it. - * This code is here to share it between the mainwindow and the part - */ - static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); - - /** - * Creates the "show preview" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowPreviewAction(KActionCollection* collection); - - /** - * Creates the "show in groups" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowInGroupsAction(KActionCollection* collection); - - /** - * Creates the "show hidden files" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowHiddenFilesAction(KActionCollection* collection); - /** * Updates the state of the 'Additional Information' actions in \a collection. */ diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp new file mode 100644 index 000000000..6cd539d36 --- /dev/null +++ b/src/dolphinviewactionhandler.cpp @@ -0,0 +1,286 @@ +/*************************************************************************** + * Copyright (C) 2008 by David Faure * + * * + * 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 "dolphinviewactionhandler.h" + +#include "dolphinview.h" + +#include + +#include +#include +#include +#include + +DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) + : QObject(parent), + m_actionCollection(collection), + m_currentView(0) +{ + Q_ASSERT(m_actionCollection); + createActions(); +} + +void DolphinViewActionHandler::setCurrentView(DolphinView* view) +{ + Q_ASSERT(view); + + if (m_currentView) + disconnect(m_currentView, 0, this, 0); + + m_currentView = view; + + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); + connect(view, SIGNAL(categorizedSortingChanged()), + this, SLOT(slotCategorizedSortingChanged())); + connect(view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); +} + +void DolphinViewActionHandler::createActions() +{ + // This action doesn't appear in the GUI, it's for the shortcut only. + // KNewMenu takes care of the GUI stuff. + KAction* newDirAction = m_actionCollection->addAction("create_dir"); + newDirAction->setText(i18n("Create Folder...")); + newDirAction->setShortcut(Qt::Key_F10); + connect(newDirAction, SIGNAL(triggered()), SLOT(slotCreateDir())); + + // Edit menu + + KAction* rename = m_actionCollection->addAction("rename"); + rename->setText(i18nc("@action:inmenu File", "Rename...")); + rename->setShortcut(Qt::Key_F2); + connect(rename, SIGNAL(triggered()), this, SLOT(slotRename())); + + KAction* moveToTrash = m_actionCollection->addAction("move_to_trash"); + moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash")); + moveToTrash->setIcon(KIcon("user-trash")); + moveToTrash->setShortcut(QKeySequence::Delete); + connect(moveToTrash, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), + this, SLOT(slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers))); + + KAction* deleteAction = m_actionCollection->addAction("delete"); + deleteAction->setIcon(KIcon("edit-delete")); + deleteAction->setText(i18nc("@action:inmenu File", "Delete")); + deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDeleteItems())); + + // View menu + + KStandardAction::zoomIn(this, + SLOT(zoomIn()), + m_actionCollection); + + KStandardAction::zoomOut(this, + SLOT(zoomOut()), + m_actionCollection); + + KToggleAction* showPreview = m_actionCollection->add("show_preview"); + showPreview->setText(i18nc("@action:intoolbar", "Preview")); + showPreview->setIcon(KIcon("view-preview")); + connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); + + KToggleAction* sortDescending = m_actionCollection->add("descending"); + sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); + + QActionGroup* showInformationActionGroup = createAdditionalInformationActionGroup(); + connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); + + KToggleAction* showInGroups = m_actionCollection->add("show_in_groups"); + showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); + connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); + + KToggleAction* showHiddenFiles = m_actionCollection->add("show_hidden_files"); + showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); + showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); + connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); + +} + +QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup() +{ + QActionGroup* showInformationGroup = new QActionGroup(m_actionCollection); + showInformationGroup->setExclusive(false); + + KToggleAction* showSizeInfo = m_actionCollection->add("show_size_info"); + showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); + showSizeInfo->setData(KFileItemDelegate::Size); + showSizeInfo->setActionGroup(showInformationGroup); + + KToggleAction* showDateInfo = m_actionCollection->add("show_date_info"); + showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); + showDateInfo->setData(KFileItemDelegate::ModificationTime); + showDateInfo->setActionGroup(showInformationGroup); + + KToggleAction* showPermissionsInfo = m_actionCollection->add("show_permissions_info"); + showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); + showPermissionsInfo->setData(KFileItemDelegate::Permissions); + showPermissionsInfo->setActionGroup(showInformationGroup); + + KToggleAction* showOwnerInfo = m_actionCollection->add("show_owner_info"); + showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); + showOwnerInfo->setData(KFileItemDelegate::Owner); + showOwnerInfo->setActionGroup(showInformationGroup); + + KToggleAction* showGroupInfo = m_actionCollection->add("show_group_info"); + showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); + showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); + showGroupInfo->setActionGroup(showInformationGroup); + + KToggleAction* showMimeInfo = m_actionCollection->add("show_mime_info"); + showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); + showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); + showMimeInfo->setActionGroup(showInformationGroup); + + return showInformationGroup; +} + +void DolphinViewActionHandler::slotCreateDir() +{ + Q_ASSERT(m_currentView); + KonqOperations::newDir(m_currentView, m_currentView->url()); +} + +void DolphinViewActionHandler::slotRename() +{ + emit actionBeingHandled(); + m_currentView->renameSelectedItems(); +} + +void DolphinViewActionHandler::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers) +{ + emit actionBeingHandled(); + // Note: kde3's konq_mainwindow.cpp used to check + // reason == KAction::PopupMenuActivation && ... + // but this isn't supported anymore + if (modifiers & Qt::ShiftModifier) + m_currentView->deleteSelectedItems(); + else + m_currentView->trashSelectedItems(); +} + +void DolphinViewActionHandler::slotDeleteItems() +{ + emit actionBeingHandled(); + m_currentView->deleteSelectedItems(); +} + +void DolphinViewActionHandler::togglePreview(bool show) +{ + emit actionBeingHandled(); + m_currentView->setShowPreview(show); +} + +void DolphinViewActionHandler::slotShowPreviewChanged() +{ + // It is not enough to update the 'Show Preview' action, also + // the 'Zoom In' and 'Zoom Out' actions must be adapted. + updateViewActions(); +} + +void DolphinViewActionHandler::updateViewActions() +{ + QAction* zoomInAction = m_actionCollection->action(KStandardAction::stdName(KStandardAction::ZoomIn)); + if (zoomInAction != 0) { + zoomInAction->setEnabled(m_currentView->isZoomInPossible()); + } + + QAction* zoomOutAction = m_actionCollection->action(KStandardAction::stdName(KStandardAction::ZoomOut)); + if (zoomOutAction != 0) { + zoomOutAction->setEnabled(m_currentView->isZoomOutPossible()); + } + + QAction* showPreviewAction = m_actionCollection->action("show_preview"); + showPreviewAction->setChecked(m_currentView->showPreview()); + + slotSortOrderChanged(m_currentView->sortOrder()); + slotAdditionalInfoChanged(); + slotCategorizedSortingChanged(); + + QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); + +} + +void DolphinViewActionHandler::zoomIn() +{ + m_currentView->zoomIn(); + updateViewActions(); +} + +void DolphinViewActionHandler::zoomOut() +{ + m_currentView->zoomOut(); + updateViewActions(); +} + +void DolphinViewActionHandler::toggleSortOrder() +{ + m_currentView->toggleSortOrder(); +} + +void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) +{ + QAction* descending = m_actionCollection->action("descending"); + const bool sortDescending = (order == Qt::DescendingOrder); + descending->setChecked(sortDescending); +} + +void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action) +{ + emit actionBeingHandled(); + m_currentView->toggleAdditionalInfo(action); +} + +void DolphinViewActionHandler::slotAdditionalInfoChanged() +{ + m_currentView->updateAdditionalInfoActions(m_actionCollection); +} + +void DolphinViewActionHandler::toggleSortCategorization(bool categorizedSorting) +{ + m_currentView->setCategorizedSorting(categorizedSorting); +} + +void DolphinViewActionHandler::slotCategorizedSortingChanged() +{ + QAction* showInGroupsAction = m_actionCollection->action("show_in_groups"); + showInGroupsAction->setChecked(m_currentView->categorizedSorting()); + showInGroupsAction->setEnabled(m_currentView->supportsCategorizedSorting()); +} + +void DolphinViewActionHandler::toggleShowHiddenFiles(bool show) +{ + emit actionBeingHandled(); + m_currentView->setShowHiddenFiles(show); +} + +void DolphinViewActionHandler::slotShowHiddenFilesChanged() +{ + QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); +} + diff --git a/src/dolphinviewactionhandler.h b/src/dolphinviewactionhandler.h new file mode 100644 index 000000000..a11d19bb1 --- /dev/null +++ b/src/dolphinviewactionhandler.h @@ -0,0 +1,165 @@ +/*************************************************************************** + * Copyright (C) 2008 by David Faure * + * * + * 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 DOLPHINVIEWACTIONHANDLER_H +#define DOLPHINVIEWACTIONHANDLER_H + +#include "libdolphin_export.h" +#include +class QAction; +class QActionGroup; +class DolphinView; +class KActionCollection; + +/** + * @short Handles all actions for DolphinView + * + * The action handler owns all the actions and slots related to DolphinView, + * but can the view that is acts upon can be switched to another one + * (this is used in the case of split views). + * + * The purpose of this class is also to share this code between DolphinMainWindow + * and DolphinPart. + * + * @see DolphinView + * @see DolphinMainWindow + * @see DolphinPart + */ +class LIBDOLPHINPRIVATE_EXPORT DolphinViewActionHandler : public QObject +{ + Q_OBJECT + +public: + explicit DolphinViewActionHandler(KActionCollection* collection, QObject* parent); + + /** + * Sets the view that this action handler should work on. + */ + void setCurrentView(DolphinView* view); + + /** + * Update all actions in the 'View' menu, i.e. those that depend on the + * settings in the current view. + */ + void updateViewActions(); + +Q_SIGNALS: + /** + * Emitted by DolphinViewActionHandler when the user triggered an action. + * This is only used for clearining the statusbar in DolphinMainWindow. + */ + void actionBeingHandled(); + +private Q_SLOTS: + /** + * Opens the dialog for creating a directory. Is connected + * with the key shortcut for "new directory" (F10). + */ + void slotCreateDir(); + + /** + * Let the user input a name for the selected item(s) and trigger + * a renaming afterwards. + */ + void slotRename(); + + /** + * Moves the selected items of the active view to the trash. + * This methods adds "shift means del" handling. + */ + void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers); + + /** + * Deletes the selected items of the active view. + */ + void slotDeleteItems(); + + /** + * Switches between showing a preview of the file content and showing the icon. + */ + void togglePreview(bool); + + /** Updates the state of the 'Show preview' menu action. */ + void slotShowPreviewChanged(); + + /** Increases the size of the current set view mode. */ + void zoomIn(); + + /** Decreases the size of the current set view mode. */ + void zoomOut(); + + /** Switches between an ascending and descending sorting order. */ + void toggleSortOrder(); + + /** + * Updates the state of the 'Sort Ascending/Descending' action. + */ + void slotSortOrderChanged(Qt::SortOrder order); + + /** + * Switches on or off the displaying of additional information + * as specified by \a action. + */ + void toggleAdditionalInfo(QAction* action); + + /** + * Updates the state of the 'Additional Information' actions. + */ + void slotAdditionalInfoChanged(); + + /** + * Switches between sorting by categories or not. + */ + void toggleSortCategorization(bool); + + /** + * Updates the state of the 'Categorized sorting' menu action. + */ + void slotCategorizedSortingChanged(); + + /** + * Switches between showing and hiding of hidden marked files + */ + void toggleShowHiddenFiles(bool); + + /** + * Updates the state of the 'Show hidden files' menu action. + */ + void slotShowHiddenFilesChanged(); + +private: + /** + * Create all the actions. + * This is called only once (by the constructor) + */ + void createActions(); + /** + * Creates an action group with all the "show additional information" actions in it. + * Helper method for createActions(); + */ + QActionGroup* createAdditionalInformationActionGroup(); + + KActionCollection* m_actionCollection; + DolphinView* m_currentView; +}; + + +#endif /* DOLPHINVIEWACTIONHANDLER_H */ + -- cgit v1.3