┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kitemviews/kfileitemmodel.cpp23
-rw-r--r--src/kitemviews/kfileitemmodel.h29
-rw-r--r--src/views/dolphinview.cpp28
-rw-r--r--src/views/dolphinviewactionhandler.cpp142
-rw-r--r--src/views/dolphinviewactionhandler.h22
5 files changed, 153 insertions, 91 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 428587e73..0fef47787 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1977,15 +1977,24 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
{ "name", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), 0, 0 },
{ "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), 0, 0 },
{ "date", DateRole, I18N_NOOP2_NOSTRIP("@label", "Date"), 0, 0 },
- { "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), 0, 0 },
- { "owner", OwnerRole, I18N_NOOP2_NOSTRIP("@label", "Owner"), 0, 0 },
- { "group", GroupRole, I18N_NOOP2_NOSTRIP("@label", "Group"), 0, 0 },
{ "type", TypeRole, I18N_NOOP2_NOSTRIP("@label", "Type"), 0, 0 },
- { "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), 0, 0 },
- { "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), 0, 0 },
- { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), 0, 0 },
+ { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), 0, 0 },
{ "tags", TagsRole, I18N_NOOP2_NOSTRIP("@label", "Tags"), 0, 0 },
- { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), 0, 0 }
+ { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), 0, 0 },
+ { "wordCount", WordCountRole, I18N_NOOP2_NOSTRIP("@label", "Word Count"), I18N_NOOP2_NOSTRIP("@label", "Document") },
+ { "lineCount", LineCountRole, I18N_NOOP2_NOSTRIP("@label", "Line Count"), I18N_NOOP2_NOSTRIP("@label", "Document") },
+ { "imageSize", ImageSizeRole, I18N_NOOP2_NOSTRIP("@label", "Image Size"), I18N_NOOP2_NOSTRIP("@label", "Image") },
+ { "orientation", OrientationRole, I18N_NOOP2_NOSTRIP("@label", "Orientation"), I18N_NOOP2_NOSTRIP("@label", "Image") },
+ { "artist", ArtistRole, I18N_NOOP2_NOSTRIP("@label", "Artist"), I18N_NOOP2_NOSTRIP("@label", "Music") },
+ { "album", AlbumRole, I18N_NOOP2_NOSTRIP("@label", "Album"), I18N_NOOP2_NOSTRIP("@label", "Music") },
+ { "duration", DurationRole, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Music") },
+ { "track", TrackRole, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Music") },
+ { "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other") },
+ { "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other") },
+ { "copiedFrom", CopiedFromRole, I18N_NOOP2_NOSTRIP("@label", "Copied From"), I18N_NOOP2_NOSTRIP("@label", "Other") },
+ { "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other") },
+ { "owner", OwnerRole, I18N_NOOP2_NOSTRIP("@label", "Owner"), I18N_NOOP2_NOSTRIP("@label", "Other") },
+ { "group", GroupRole, I18N_NOOP2_NOSTRIP("@label", "Group"), I18N_NOOP2_NOSTRIP("@label", "Other") },
};
count = sizeof(rolesInfoMap) / sizeof(RoleInfoMap);
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 5d7a7fc8b..d48f600df 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -201,24 +201,17 @@ private slots:
private:
enum RoleType {
- NoRole,
- NameRole,
- SizeRole,
- DateRole,
- PermissionsRole,
- OwnerRole,
- GroupRole,
- TypeRole,
- DestinationRole,
- PathRole,
- CommentRole,
- TagsRole,
- RatingRole,
- IsDirRole,
- IsExpandedRole,
- IsExpandableRole,
- ExpandedParentsCountRole,
- RolesCount // Mandatory last entry
+ // User visible roles:
+ NoRole, NameRole, SizeRole, DateRole, PermissionsRole, OwnerRole,
+ GroupRole, TypeRole, DestinationRole, PathRole,
+ // User visible roles available with Nepomuk:
+ CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
+ WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
+ CopiedFromRole,
+ // Non-visible roles:
+ IsDirRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
+ // Mandatory last entry:
+ RolesCount
};
struct ItemData
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 890a39d89..29a132184 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -779,17 +779,33 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
KItemListView* view = m_container->controller()->view();
const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
+ QString groupName;
+ QMenu* groupMenu = 0;
+
// Add all roles to the menu that can be shown or hidden by the user
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
- if (info.role != "name") {
- const QString text = fileItemModel()->roleDescription(info.role);
+ if (info.role == "name") {
+ // It should not be possible to hide the "name" role
+ continue;
+ }
+
+ const QString text = fileItemModel()->roleDescription(info.role);
+ QAction* action = 0;
+ if (info.group.isEmpty()) {
+ action = menu.data()->addAction(text);
+ } else {
+ if (!groupMenu || info.group != groupName) {
+ groupName = info.group;
+ groupMenu = menu.data()->addMenu(groupName);
+ }
- QAction* action = menu.data()->addAction(text);
- action->setCheckable(true);
- action->setChecked(visibleRolesSet.contains(info.role));
- action->setData(info.role);
+ action = groupMenu->addAction(text);
}
+
+ action->setCheckable(true);
+ action->setChecked(visibleRolesSet.contains(info.role));
+ action->setData(info.role);
}
QAction* action = menu.data()->exec(pos.toPoint());
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index d87e57532..aead11d25 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (C) 2008 by David Faure <[email protected]> *
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
* *
* 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 *
@@ -27,9 +28,9 @@
#include <KAction>
#include <KActionCollection>
#include <KActionMenu>
-#include <KFileItemDelegate>
#include <kitemviews/kfileitemmodel.h>
#include <KLocale>
+#include <KMenu>
#include <KNewFileMenu>
#include <KSelectAction>
#include <KToggleAction>
@@ -38,10 +39,12 @@
#include <KDebug>
-DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent)
- : QObject(parent),
- m_actionCollection(collection),
- m_currentView(0)
+DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
+ QObject(parent),
+ m_actionCollection(collection),
+ m_currentView(0),
+ m_sortByActions(),
+ m_visibleRoles()
{
Q_ASSERT(m_actionCollection);
createActions();
@@ -167,8 +170,7 @@ void DolphinViewActionHandler::createActions()
connect(sortFoldersFirst, SIGNAL(triggered()), this, SLOT(toggleSortFoldersFirst()));
// View -> Sort By
- QActionGroup* sortByActionGroup = createSortByActionGroup();
- connect(sortByActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSortTriggered(QAction*)));
+ QActionGroup* sortByActionGroup = createFileItemRolesActionGroup("sort_by_");
KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>("sort");
sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
@@ -182,14 +184,14 @@ void DolphinViewActionHandler::createActions()
sortByActionMenu->addAction(sortFoldersFirst);
// View -> Additional Information
- QActionGroup* additionalInfoGroup = createAdditionalInformationActionGroup();
- connect(additionalInfoGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*)));
+ QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup("show_");
- KActionMenu* additionalInfoMenu = m_actionCollection->add<KActionMenu>("additional_info");
- additionalInfoMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
- additionalInfoMenu->setDelayed(false);
- foreach (QAction* action, additionalInfoGroup->actions()) {
- additionalInfoMenu->addAction(action);
+ KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>("additional_info");
+ visibleRolesMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
+ visibleRolesMenu->setDelayed(false);
+
+ foreach (QAction* action, visibleRolesGroup->actions()) {
+ visibleRolesMenu->addAction(action);
}
KToggleAction* showInGroups = m_actionCollection->add<KToggleAction>("show_in_groups");
@@ -207,47 +209,70 @@ void DolphinViewActionHandler::createActions()
connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(slotAdjustViewProperties()));
}
-QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup()
+QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
{
- QActionGroup* additionalInfoGroup = new QActionGroup(m_actionCollection);
- additionalInfoGroup->setExclusive(false);
+ const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
+ Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
+
+ QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
+ rolesActionGroup->setExclusive(isSortGroup);
+ if (isSortGroup) {
+ connect(rolesActionGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(slotSortTriggered(QAction*)));
+ } else {
+ connect(rolesActionGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(toggleVisibleRole(QAction*)));
+ }
- KActionMenu* showInformationMenu = m_actionCollection->add<KActionMenu>("additional_info");
- showInformationMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
- showInformationMenu->setDelayed(false);
+ QString groupName;
+ KActionMenu* groupMenu = 0;
+ QActionGroup* groupMenuGroup = 0;
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
- if (info.role == "name") {
+ if (!isSortGroup && info.role == "name") {
// It should not be possible to hide the "name" role
continue;
}
- const QString name = QLatin1String("show_") + info.role;
- KToggleAction* action = m_actionCollection->add<KToggleAction>(name);
- action->setText(info.translation);
- action->setData(info.role);
- action->setActionGroup(additionalInfoGroup);
- }
+ KToggleAction* action = 0;
+ const QString name = groupPrefix + info.role;
+ if (info.group.isEmpty()) {
+ action = m_actionCollection->add<KToggleAction>(name);
+ action->setActionGroup(rolesActionGroup);
+ } else {
+ if (!groupMenu || info.group != groupName) {
+ groupName = info.group;
+ groupMenu = m_actionCollection->add<KActionMenu>(groupName);
+ groupMenu->setText(groupName);
+ groupMenu->setActionGroup(rolesActionGroup);
- return additionalInfoGroup;
-}
+ groupMenuGroup = new QActionGroup(groupMenu);
+ groupMenuGroup->setExclusive(isSortGroup);
+ if (isSortGroup) {
+ connect(groupMenuGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(slotSortTriggered(QAction*)));
+ } else {
+ connect(groupMenuGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(toggleVisibleRole(QAction*)));
+ }
+ }
-QActionGroup* DolphinViewActionHandler::createSortByActionGroup()
-{
- QActionGroup* sortByActionGroup = new QActionGroup(m_actionCollection);
- sortByActionGroup->setExclusive(true);
-
- const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
- foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
- const QString name = QLatin1String("sort_by_") + info.role;
- KToggleAction* action = m_actionCollection->add<KToggleAction>(name);
+ action = new KToggleAction(groupMenu);
+ action->setActionGroup(groupMenuGroup);
+ groupMenu->addAction(action);
+ }
action->setText(info.translation);
action->setData(info.role);
- sortByActionGroup->addAction(action);
+
+ if (isSortGroup) {
+ m_sortByActions.insert(info.role, action);
+ } else {
+ m_visibleRoles.insert(info.role, action);
+ }
}
- return sortByActionGroup;
+ return rolesActionGroup;
}
void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
@@ -383,7 +408,7 @@ void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
m_actionCollection->action("folders_first")->setChecked(foldersFirst);
}
-void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action)
+void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
{
emit actionBeingHandled();
@@ -411,13 +436,12 @@ void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>&
Q_UNUSED(previous);
const QSet<QByteArray> checkedRoles = current.toSet();
- const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
- foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
- const QString name = QLatin1String("show_") + info.role;
- QAction* action = m_actionCollection->action(name);
- if (action) {
- action->setChecked(checkedRoles.contains(info.role));
- }
+ QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
+ while (it.hasNext()) {
+ it.next();
+ const QByteArray& role = it.key();
+ KToggleAction* action = it.value();
+ action->setChecked(checkedRoles.contains(role));
}
}
@@ -479,8 +503,7 @@ KToggleAction* DolphinViewActionHandler::detailsModeAction()
void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
{
- const QString name = QLatin1String("sort_by_") + role;
- QAction* action = m_actionCollection->action(name);
+ KToggleAction* action = m_sortByActions.value(role);
if (action) {
action->setChecked(true);
@@ -506,6 +529,25 @@ void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous)
void DolphinViewActionHandler::slotSortTriggered(QAction* action)
{
+ // The radiobuttons of the "Sort By"-menu are split between the main-menu
+ // and several sub-menus. Because of this they don't have a common
+ // action-group that assures an exclusive toggle-state between the main-menu
+ // actions and the sub-menu-actions. If an action gets checked, it must
+ // be assured that all other actions get unchecked.
+ QAction* sortByMenu = m_actionCollection->action("sort");
+ foreach (QAction* groupAction, sortByMenu->menu()->actions()) {
+ KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
+ if (actionMenu) {
+ foreach (QAction* subAction, actionMenu->menu()->actions()) {
+ subAction->setChecked(false);
+ }
+ } else if (groupAction->actionGroup()) {
+ groupAction->setChecked(false);
+ }
+ }
+ action->setChecked(true);
+
+ // Apply the activated sort-role to the view
const QByteArray role = action->data().toByteArray();
m_currentView->setSortRole(role);
}
diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h
index ff72d9530..edbe41b90 100644
--- a/src/views/dolphinviewactionhandler.h
+++ b/src/views/dolphinviewactionhandler.h
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (C) 2008 by David Faure <[email protected]> *
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
* *
* 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 *
@@ -162,7 +163,7 @@ private Q_SLOTS:
* Switches on or off the displaying of additional information
* as specified by \a action.
*/
- void toggleAdditionalInfo(QAction* action);
+ void toggleVisibleRole(QAction* action);
/**
* Changes the sorting of the current view.
@@ -217,16 +218,14 @@ private:
void createActions();
/**
- * Creates an action group with all the "show additional information" actions in it.
- * Helper method for createActions();
- */
- QActionGroup* createAdditionalInformationActionGroup();
-
- /**
- * Creates an action group with all the "sort by" actions in it.
- * Helper method for createActions();
+ * Creates an action-group out of all roles from KFileItemModel.
+ * Dependent on the group-prefix either a radiobutton-group is
+ * created for sorting (prefix is "sort_by_") or a checkbox-group
+ * is created for additional information (prefix is "show_").
+ * The changes of actions are reported to slotSortTriggered() or
+ * toggleAdditionalInfo().
*/
- QActionGroup* createSortByActionGroup();
+ QActionGroup* createFileItemRolesActionGroup(const QString& groupPrefix);
/**
* Returns the "switch to icons mode" action.
@@ -248,6 +247,9 @@ private:
KActionCollection* m_actionCollection;
DolphinView* m_currentView;
+
+ QHash<QByteArray, KToggleAction*> m_sortByActions;
+ QHash<QByteArray, KToggleAction*> m_visibleRoles;
};
#endif /* DOLPHINVIEWACTIONHANDLER_H */