┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-03-13 16:26:16 +0100
committerPeter Penz <[email protected]>2012-03-13 16:29:45 +0100
commitf041099904d809b5370285185fbbb2303c40b953 (patch)
tree5070608d5c19033a119bec98b9466d889bd8bd7c /src/views
parent6c60bf0ad54258976d9dcbd6586b26c65d8d4b78 (diff)
Remove RolesInfoAccessor
Now KFileItemModel provides a way to access the available roles including their translations. Note that the 3 roles "comments", "rating" and "tags" have not been implemented yet in KFileItemModel and turning them on does not work currently.
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinview.cpp17
-rw-r--r--src/views/dolphinviewactionhandler.cpp38
-rw-r--r--src/views/rolesaccessor.cpp72
-rw-r--r--src/views/rolesaccessor.h64
-rw-r--r--src/views/viewproperties.cpp1
5 files changed, 23 insertions, 169 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index e945b00eb..890a39d89 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -56,7 +56,6 @@
#include <KToggleAction>
#include <KUrl>
-#include "rolesaccessor.h"
#include "dolphindirlister.h"
#include "dolphinnewfilemenuobserver.h"
#include "dolphin_detailsmodesettings.h"
@@ -781,16 +780,15 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
// Add all roles to the menu that can be shown or hidden by the user
- const RolesAccessor& rolesAccessor = RolesAccessor::instance();
- const QList<QByteArray> roles = rolesAccessor.roles();
- foreach (const QByteArray& role, roles) {
- if (role != "name") {
- const QString text = fileItemModel()->roleDescription(role);
+ const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+ foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+ if (info.role != "name") {
+ const QString text = fileItemModel()->roleDescription(info.role);
QAction* action = menu.data()->addAction(text);
action->setCheckable(true);
- action->setChecked(visibleRolesSet.contains(role));
- action->setData(role);
+ action->setChecked(visibleRolesSet.contains(info.role));
+ action->setData(info.role);
}
}
@@ -802,8 +800,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
ViewProperties props(url());
QList<QByteArray> visibleRoles = view->visibleRoles();
if (action->isChecked()) {
- const int index = roles.indexOf(selectedRole) + 1;
- visibleRoles.insert(index, selectedRole);
+ visibleRoles.append(selectedRole);
} else {
visibleRoles.removeOne(selectedRole);
}
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index f6bc1374a..d87e57532 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -19,7 +19,6 @@
#include "dolphinviewactionhandler.h"
-#include "rolesaccessor.h"
#include "settings/viewpropertiesdialog.h"
#include "views/dolphinview.h"
#include "views/zoomlevelinfo.h"
@@ -29,6 +28,7 @@
#include <KActionCollection>
#include <KActionMenu>
#include <KFileItemDelegate>
+#include <kitemviews/kfileitemmodel.h>
#include <KLocale>
#include <KNewFileMenu>
#include <KSelectAction>
@@ -216,19 +216,17 @@ QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup()
showInformationMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
showInformationMenu->setDelayed(false);
- const RolesAccessor& rolesAccessor = RolesAccessor::instance();
-
- const QList<QByteArray> roles = rolesAccessor.roles();
- foreach (const QByteArray& role, roles) {
- if (role == "name") {
+ const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+ foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+ if (info.role == "name") {
// It should not be possible to hide the "name" role
continue;
}
- const QString name = QLatin1String("show_") + role;
+ const QString name = QLatin1String("show_") + info.role;
KToggleAction* action = m_actionCollection->add<KToggleAction>(name);
- action->setText(rolesAccessor.translation(role));
- action->setData(role);
+ action->setText(info.translation);
+ action->setData(info.role);
action->setActionGroup(additionalInfoGroup);
}
@@ -240,13 +238,12 @@ QActionGroup* DolphinViewActionHandler::createSortByActionGroup()
QActionGroup* sortByActionGroup = new QActionGroup(m_actionCollection);
sortByActionGroup->setExclusive(true);
- const RolesAccessor& rolesAccessor = RolesAccessor::instance();
- const QList<QByteArray> roles = rolesAccessor.roles();
- foreach (const QByteArray& role, roles) {
- const QString name = QLatin1String("sort_by_") + role;
+ 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->setText(rolesAccessor.translation(role));
- action->setData(role);
+ action->setText(info.translation);
+ action->setData(info.role);
sortByActionGroup->addAction(action);
}
@@ -413,16 +410,13 @@ void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>&
{
Q_UNUSED(previous);
- const RolesAccessor& rolesAccessor = RolesAccessor::instance();
-
const QSet<QByteArray> checkedRoles = current.toSet();
- const QList<QByteArray> roles = rolesAccessor.roles();
-
- foreach (const QByteArray& role, roles) {
- const QString name = QLatin1String("show_") + role;
+ 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(role));
+ action->setChecked(checkedRoles.contains(info.role));
}
}
}
diff --git a/src/views/rolesaccessor.cpp b/src/views/rolesaccessor.cpp
deleted file mode 100644
index 3309f0eff..000000000
--- a/src/views/rolesaccessor.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2010 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 *
- * 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 "rolesaccessor.h"
-
-#include <KGlobal>
-#include <KLocale>
-
-class RolesAccessorSingleton
-{
-public:
- RolesAccessor instance;
-};
-K_GLOBAL_STATIC(RolesAccessorSingleton, s_rolesAccessor)
-
-RolesAccessor& RolesAccessor::instance()
-{
- return s_rolesAccessor->instance;
-}
-
-QList<QByteArray> RolesAccessor::roles() const
-{
- return m_roles;
-}
-
-QString RolesAccessor::translation(const QByteArray& role) const
-{
- return i18nc(m_translation[role]->roleTranslationContext, m_translation[role]->roleTranslation);
-}
-
-RolesAccessor::RolesAccessor() :
- m_roles(),
- m_translation()
-{
- static const RolesAccessor::Translation translations[] = {
- // role roleTranslationContext roleTranslation
- { "name", I18N_NOOP2_NOSTRIP("@label", "Name") },
- { "size", I18N_NOOP2_NOSTRIP("@label", "Size") },
- { "date", I18N_NOOP2_NOSTRIP("@label", "Date") },
- { "permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions") },
- { "owner", I18N_NOOP2_NOSTRIP("@label", "Owner") },
- { "group", I18N_NOOP2_NOSTRIP("@label", "Group") },
- { "type", I18N_NOOP2_NOSTRIP("@label", "Type") },
- { "destination", I18N_NOOP2_NOSTRIP("@label", "Link Destination") },
- { "path", I18N_NOOP2_NOSTRIP("@label", "Path") }
- };
-
- for (unsigned int i = 0; i < sizeof(translations) / sizeof(Translation); ++i) {
- m_translation.insert(translations[i].role, &translations[i]);
- m_roles.append(translations[i].role);
- }
-}
-
-RolesAccessor::~RolesAccessor()
-{
-}
diff --git a/src/views/rolesaccessor.h b/src/views/rolesaccessor.h
deleted file mode 100644
index 3c95541d8..000000000
--- a/src/views/rolesaccessor.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2010 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 *
- * 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 ROLESACCESSOR_H
-#define ROLESACCESSOR_H
-
-#include <libdolphin_export.h>
-
-#include <QList>
-#include <QHash>
-
-/**
- * @brief Allows to access the available roles that can be shown in a view.
- */
-class LIBDOLPHINPRIVATE_EXPORT RolesAccessor
-{
-public:
- static RolesAccessor& instance();
-
- /**
- * @return List of all available roles.
- */
- QList<QByteArray> roles() const;
-
- /**
- * @return Translation of the role that can be shown e.g. in the header
- * of a view or as menu-entry.
- */
- QString translation(const QByteArray& role) const;
-
-protected:
- RolesAccessor();
- virtual ~RolesAccessor();
- friend class RolesAccessorSingleton;
-
-private:
- struct Translation {
- const char* const role;
- const char* const roleTranslationContext;
- const char* const roleTranslation;
- };
-
- QList<QByteArray> m_roles;
- QHash<QByteArray, const Translation*> m_translation;
-};
-
-#endif
-
diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp
index 19aca4583..10e420c85 100644
--- a/src/views/viewproperties.cpp
+++ b/src/views/viewproperties.cpp
@@ -20,7 +20,6 @@
#include "viewproperties.h"
-#include "rolesaccessor.h"
#include "dolphin_directoryviewpropertysettings.h"
#include "dolphin_generalsettings.h"