]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Remove RolesInfoAccessor
authorPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2012 15:26:16 +0000 (16:26 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2012 15:29:45 +0000 (16:29 +0100)
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.

src/CMakeLists.txt
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/settings/additionalinfodialog.cpp
src/settings/additionalinfodialog.h
src/settings/viewpropertiesdialog.cpp
src/views/dolphinview.cpp
src/views/dolphinviewactionhandler.cpp
src/views/rolesaccessor.cpp [deleted file]
src/views/rolesaccessor.h [deleted file]
src/views/viewproperties.cpp

index 90a1f9e44fccb7a7fdbdd4ff5b31dbd38d5590b6..39fd94aa07b9a93c3e7f249182ca777f8236b3ce 100644 (file)
@@ -57,7 +57,6 @@ set(dolphinprivate_LIB_SRCS
     views/dolphinviewactionhandler.cpp
     views/draganddrophelper.cpp
     views/renamedialog.cpp
-    views/rolesaccessor.cpp
     views/tooltips/filemetadatatooltip.cpp
     views/tooltips/tooltipmanager.cpp
     views/versioncontrol/updateitemstatesthread.cpp
index 23cd7cd75f0babf0fe2a8d14e974b4afeb10793a..428587e734ec2214ecd8a9cd5a3ca1d3e1d70ca4 100644 (file)
@@ -257,34 +257,21 @@ int KFileItemModel::indexForKeyboardSearch(const QString& text, int startFromInd
 bool KFileItemModel::supportsDropping(int index) const
 {
     const KFileItem item = fileItem(index);
-    return item.isNull() ? false : item.isDir() || item.isDesktopFile();
+    return !item.isNull() && (item.isDir() || item.isDesktopFile());
 }
 
 QString KFileItemModel::roleDescription(const QByteArray& role) const
 {
-    QString descr;
-
-    switch (roleIndex(role)) {
-    case NameRole:        descr = i18nc("@item:intable", "Name"); break;
-    case SizeRole:        descr = i18nc("@item:intable", "Size"); break;
-    case DateRole:        descr = i18nc("@item:intable", "Date"); break;
-    case PermissionsRole: descr = i18nc("@item:intable", "Permissions"); break;
-    case OwnerRole:       descr = i18nc("@item:intable", "Owner"); break;
-    case GroupRole:       descr = i18nc("@item:intable", "Group"); break;
-    case TypeRole:        descr = i18nc("@item:intable", "Type"); break;
-    case DestinationRole: descr = i18nc("@item:intable", "Destination"); break;
-    case PathRole:        descr = i18nc("@item:intable", "Path"); break;
-    case CommentRole:     descr = i18nc("@item:intable", "Comment"); break;
-    case TagsRole:        descr = i18nc("@item:intable", "Tags"); break;
-    case RatingRole:      descr = i18nc("@item:intable", "Rating"); break;
-    case NoRole:          break;
-    case IsDirRole:       break;
-    case IsExpandedRole:  break;
-    case ExpandedParentsCountRole: break;
-    default:                 Q_ASSERT(false); break;
+    static QHash<QByteArray, QString> description;
+    if (description.isEmpty()) {
+        int count = 0;
+        const RoleInfoMap* map = rolesInfoMap(count);
+        for (int i = 0; i < count; ++i) {
+            description.insert(map[i].role, map[i].roleTranslation);
+        }
     }
 
-    return descr;
+    return description.value(role);
 }
 
 QList<QPair<int, QVariant> > KFileItemModel::groups() const
@@ -294,7 +281,7 @@ QList<QPair<int, QVariant> > KFileItemModel::groups() const
         QElapsedTimer timer;
         timer.start();
 #endif
-        switch (roleIndex(sortRole())) {
+        switch (typeForRole(sortRole())) {
         case NameRole:        m_groups = nameRoleGroups(); break;
         case SizeRole:        m_groups = sizeRoleGroups(); break;
         case DateRole:        m_groups = dateRoleGroups(); break;
@@ -393,7 +380,7 @@ void KFileItemModel::setRoles(const QSet<QByteArray>& roles)
     QSetIterator<QByteArray> it(roles);
     while (it.hasNext()) {
         const QByteArray& role = it.next();
-        m_requestRole[roleIndex(role)] = true;
+        m_requestRole[typeForRole(role)] = true;
     }
 
     if (count() > 0) {
@@ -571,6 +558,26 @@ QString KFileItemModel::nameFilter() const
     return m_filter.pattern();
 }
 
+QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation()
+{
+    static QList<RoleInfo> rolesInfo;
+    if (rolesInfo.isEmpty()) {
+        int count = 0;
+        const RoleInfoMap* map = rolesInfoMap(count);
+        for (int i = 0; i < count; ++i) {
+            if (map[i].roleType != NoRole) {
+                RoleInfo info;
+                info.role = map[i].role;
+                info.translation = map[i].roleTranslation;
+                info.group = map[i].groupTranslation;
+                rolesInfo.append(info);
+            }
+        }
+    }
+
+    return rolesInfo;
+}
+
 void KFileItemModel::onGroupedSortingChanged(bool current)
 {
     Q_UNUSED(current);
@@ -580,7 +587,7 @@ void KFileItemModel::onGroupedSortingChanged(bool current)
 void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous)
 {
     Q_UNUSED(previous);
-    m_sortRole = roleIndex(current);
+    m_sortRole = typeForRole(current);
 
 #ifdef KFILEITEMMODEL_DEBUG
     if (!m_requestRole[m_sortRole]) {
@@ -1110,52 +1117,54 @@ void KFileItemModel::resetRoles()
     }
 }
 
-KFileItemModel::Role KFileItemModel::roleIndex(const QByteArray& role) const
-{
-    static QHash<QByteArray, Role> rolesHash;
-    if (rolesHash.isEmpty()) {
-        rolesHash.insert("name", NameRole);
-        rolesHash.insert("size", SizeRole);
-        rolesHash.insert("date", DateRole);
-        rolesHash.insert("permissions", PermissionsRole);
-        rolesHash.insert("owner", OwnerRole);
-        rolesHash.insert("group", GroupRole);
-        rolesHash.insert("type", TypeRole);
-        rolesHash.insert("destination", DestinationRole);
-        rolesHash.insert("path", PathRole);
-        rolesHash.insert("comment", CommentRole);
-        rolesHash.insert("tags", TagsRole);
-        rolesHash.insert("rating", RatingRole);
-        rolesHash.insert("isDir", IsDirRole);
-        rolesHash.insert("isExpanded", IsExpandedRole);
-        rolesHash.insert("isExpandable", IsExpandableRole);
-        rolesHash.insert("expandedParentsCount", ExpandedParentsCountRole);
-    }
-    return rolesHash.value(role, NoRole);
-}
-
-QByteArray KFileItemModel::roleByteArray(Role role) const
-{
-    static const char* const roles[RolesCount] = {
-        0, // NoRole
-        "name",
-        "size",
-        "date",
-        "permissions",
-        "owner",
-        "group",
-        "type",
-        "destination",
-        "path",
-        "comment",
-        "tags",
-        "rating",
-        "isDir",
-        "isExpanded",
-        "isExpandable",
-        "expandedParentsCount"
+KFileItemModel::RoleType KFileItemModel::typeForRole(const QByteArray& role) const
+{
+    static QHash<QByteArray, RoleType> roles;
+    if (roles.isEmpty()) {
+        // Insert user visible roles that can be accessed with
+        // KFileItemModel::roleInformation()
+        int count = 0;
+        const RoleInfoMap* map = rolesInfoMap(count);
+        for (int i = 0; i < count; ++i) {
+            roles.insert(map[i].role, map[i].roleType);
+        }
+
+        // Insert internal roles (take care to synchronize the implementation
+        // with KFileItemModel::roleForType() in case if a change is done).
+        roles.insert("isDir", IsDirRole);
+        roles.insert("isExpanded", IsExpandedRole);
+        roles.insert("isExpandable", IsExpandableRole);
+        roles.insert("expandedParentsCount", ExpandedParentsCountRole);
+
+        Q_ASSERT(roles.count() == RolesCount);
+    }
+
+    return roles.value(role, NoRole);
+}
+
+QByteArray KFileItemModel::roleForType(RoleType roleType) const
+{
+    static QHash<RoleType, QByteArray> roles;
+    if (roles.isEmpty()) {
+        // Insert user visible roles that can be accessed with
+        // KFileItemModel::roleInformation()
+        int count = 0;
+        const RoleInfoMap* map = rolesInfoMap(count);
+        for (int i = 0; i < count; ++i) {
+            roles.insert(map[i].roleType, map[i].role);
+        }
+
+        // Insert internal roles (take care to synchronize the implementation
+        // with KFileItemModel::typeForRole() in case if a change is done).
+        roles.insert(IsDirRole, "isDir");
+        roles.insert(IsExpandedRole, "isExpanded");
+        roles.insert(IsExpandableRole, "isExpandable");
+        roles.insert(ExpandedParentsCountRole, "expandedParentsCount");
+
+        Q_ASSERT(roles.count() == RolesCount);
     };
-    return roles[role];
+
+    return roles.value(roleType);
 }
 
 QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item) const
@@ -1364,7 +1373,7 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
     case PathRole:
     case CommentRole:
     case TagsRole: {
-        const QByteArray role = roleByteArray(m_sortRole);
+        const QByteArray role = roleForType(m_sortRole);
         result = QString::compare(a->values.value(role).toString(),
                                   b->values.value(role).toString());
         break;
@@ -1960,4 +1969,27 @@ KFileItemList KFileItemModel::childItems(const KFileItem& item) const
     return items;
 }
 
+const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
+{
+    static const RoleInfoMap rolesInfoMap[] = {
+    //    role           roleType         role translation                                  group translation
+        { 0,             NoRole,          0, 0,                                             0, 0 },
+        { "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 },
+        { "tags",        TagsRole,        I18N_NOOP2_NOSTRIP("@label", "Tags"),             0, 0 },
+        { "rating",      RatingRole,      I18N_NOOP2_NOSTRIP("@label", "Rating"),           0, 0 }
+    };
+
+    count = sizeof(rolesInfoMap) / sizeof(RoleInfoMap);
+    return rolesInfoMap;
+}
+
 #include "kfileitemmodel.moc"
index bb77003c3a8fdc3a2ac4faaaaa69547ac95138ba..5d7a7fc8b6044e319b50b1aaaaa5113497364219 100644 (file)
@@ -90,7 +90,7 @@ public:
     virtual bool supportsDropping(int index) const;
 
     /** @reimp */
-    virtual QString roleDescription(const QByteArray& role) const;
+    virtual QString roleDescription(const QByteArray& typeForRole) const;
 
     /** @reimp */
     virtual QList<QPair<int, QVariant> > groups() const;
@@ -158,6 +158,14 @@ public:
     void setNameFilter(const QString& nameFilter);
     QString nameFilter() const;
 
+    struct RoleInfo
+    {   QByteArray role;
+        QString translation;
+        QString group;
+    };
+
+    static QList<RoleInfo> rolesInformation();
+
 signals:
     /**
      * Is emitted after the loading of a directory has been completed or new
@@ -192,7 +200,7 @@ private slots:
     void dispatchPendingItemsToInsert();
 
 private:
-    enum Role {
+    enum RoleType {
         NoRole,
         NameRole,
         SizeRole,
@@ -239,16 +247,16 @@ private:
     void resetRoles();
 
     /**
-     * @return Role-index for the given role byte-array.
+     * @return Role-type for the given role.
      *         Runtime complexity is O(1).
      */
-    Role roleIndex(const QByteArray& role) const;
+    RoleType typeForRole(const QByteArray& role) const;
 
     /**
-     * @return Role-byte-array for the given role-index.
+     * @return Role-byte-array for the given role-type.
      *         Runtime complexity is O(1).
      */
-    QByteArray roleByteArray(Role role) const;
+    QByteArray roleForType(RoleType roleType) const;
 
     QHash<QByteArray, QVariant> retrieveData(const KFileItem& item) const;
 
@@ -314,7 +322,7 @@ private:
     QList<QPair<int, QVariant> > dateRoleGroups() const;
     QList<QPair<int, QVariant> > permissionRoleGroups() const;
     QList<QPair<int, QVariant> > ratingRoleGroups() const;
-    QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& role) const;
+    QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const;
 
     /**
      * Helper method for all xxxRoleGroups() methods to check whether the
@@ -331,13 +339,32 @@ private:
      */
     KFileItemList childItems(const KFileItem& item) const;
 
+    /**
+     * Maps the QByteArray-roles to RoleTypes and provides translation- and
+     * group-contexts.
+     */
+    struct RoleInfoMap
+    {
+        const char* const role;
+        const RoleType roleType;
+        const char* const roleTranslationContext;
+        const char* const roleTranslation;
+        const char* const groupTranslationContext;
+        const char* const groupTranslation;
+    };
+
+    /**
+     * @return Map of user visible roles that are accessible by KFileItemModel::rolesInformation().
+     */
+    static const RoleInfoMap* rolesInfoMap(int& count);
+
 private:
     QWeakPointer<KDirLister> m_dirLister;
 
     bool m_naturalSorting;
     bool m_sortFoldersFirst;
 
-    Role m_sortRole;
+    RoleType m_sortRole;
     QSet<QByteArray> m_roles;
     Qt::CaseSensitivity m_caseSensitivity;
 
index 6bcee4a1b480ad57f09d7f0aab7e37b748283eb5..9e5f170dae36882d31c2244d2ab1f8af1d184574 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at)                  *
+ *   Copyright (C) 2007-2012 by Peter Penz <peter.penz19@gmail.com>        *
  *                                                                         *
  *   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  *
 #include "additionalinfodialog.h"
 
 #include <KLocale>
-
+#include "kitemviews/kfileitemmodel.h"
 #include <QCheckBox>
 #include <QLabel>
 #include <QVBoxLayout>
 
-#include "views/rolesaccessor.h"
-
 AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
                                            const QList<QByteArray>& visibleRoles) :
     KDialog(parent),
     m_visibleRoles(visibleRoles),
-    m_checkBoxes()
+    m_listWidget(0)
 {
     setCaption(i18nc("@title:window", "Additional Information"));
     setButtons(Ok | Cancel);
@@ -39,30 +37,29 @@ AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
 
     QWidget* mainWidget = new QWidget(this);
     mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
-    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
 
     // Add header
     QLabel* header = new QLabel(mainWidget);
     header->setText(i18nc("@label", "Select which additional information should be shown:"));
     header->setWordWrap(true);
-    layout->addWidget(header);
 
     // Add checkboxes
-    const RolesAccessor& rolesAccessor = RolesAccessor::instance();
-    const QList<QByteArray> roles = rolesAccessor.roles();
-    foreach (const QByteArray& role, roles) {
-        QCheckBox* checkBox = new QCheckBox(rolesAccessor.translation(role), mainWidget);
-        checkBox->setChecked(visibleRoles.contains(role));
-        layout->addWidget(checkBox);
-        m_checkBoxes.append(checkBox);
+    m_listWidget = new QListWidget(mainWidget);
+    m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
+    const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+        QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
+        item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
     }
 
+    QVBoxLayout* layout = new QVBoxLayout(mainWidget);
+    layout->addWidget(header);
+    layout->addWidget(m_listWidget);
     layout->addStretch(1);
 
     setMainWidget(mainWidget);
 
-    const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
-                                    "AdditionalInfoDialog");
+    const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
     restoreDialogSize(dialogConfig);
 
     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
@@ -70,8 +67,7 @@ AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
 
 AdditionalInfoDialog::~AdditionalInfoDialog()
 {
-    KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
-                              "AdditionalInfoDialog");
+    KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
     saveDialogSize(dialogConfig, KConfigBase::Persistent);
 }
 
@@ -84,11 +80,12 @@ void AdditionalInfoDialog::slotOk()
 {
     m_visibleRoles.clear();
 
-    const QList<QByteArray> roles = RolesAccessor::instance().roles();
     int index = 0;
-    foreach (const QByteArray& role, roles) {
-        if (m_checkBoxes[index]->isChecked()) {
-            m_visibleRoles.append(role);
+    const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+        const QListWidgetItem* item = m_listWidget->item(index);
+        if (item->checkState() == Qt::Checked) {
+            m_visibleRoles.append(info.role);
         }
         ++index;
     }
index 9048489ccca98aa37c9c2c4957bf93a5fa571844..dd51768e5bda456fa7d27d94260211862276ab13 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at)                  *
+ *   Copyright (C) 2007-2012 by Peter Penz <peter.penz19@gmail.com>        *
  *                                                                         *
  *   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  *
@@ -22,6 +22,7 @@
 
 #include <KDialog>
 #include <QList>
+#include <QListWidget>
 
 class QCheckBox;
 
@@ -42,7 +43,7 @@ private slots:
 
 private:
     QList<QByteArray> m_visibleRoles;
-    QList<QCheckBox*> m_checkBoxes;
+    QListWidget* m_listWidget;
 };
 
 #endif
index 420daec8da3c0f50388bf3ef6d51f8e3318b986c..20461a394eef5a17c07f5c6ea4e141de23bf6135 100644 (file)
@@ -21,7 +21,7 @@
 #include "viewpropertiesdialog.h"
 
 #include "additionalinfodialog.h"
-#include "views/rolesaccessor.h"
+#include "kitemviews/kfileitemmodel.h"
 #include "views/dolphinview.h"
 #include "dolphin_generalsettings.h"
 #include "dolphin_iconsmodesettings.h"
@@ -107,10 +107,9 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending"));
 
     m_sorting = new KComboBox(sortingBox);
-    const RolesAccessor& rolesAccessor = RolesAccessor::instance();
-    const QList<QByteArray> roles = rolesAccessor.roles();
-    foreach (const QByteArray& role, roles) {
-        m_sorting->addItem(rolesAccessor.translation(role), role);
+    const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+        m_sorting->addItem(info.translation, info.role);
     }
 
     m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first"));
@@ -393,8 +392,15 @@ void ViewPropertiesDialog::loadSettings()
     const int sortOrderIndex = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1;
     m_sortOrder->setCurrentIndex(sortOrderIndex);
 
-    const QList<QByteArray> roles = RolesAccessor::instance().roles();
-    const int sortRoleIndex = roles.indexOf(m_viewProps->sortRole());
+    const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+    int sortRoleIndex = 0;
+    for (int i = 0; i < rolesInfo.count(); ++i)
+    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+        if (info.role == m_viewProps->sortRole()) {
+            sortRoleIndex = i;
+            break;
+        }
+    }
     m_sorting->setCurrentIndex(sortRoleIndex);
 
     m_sortFoldersFirst->setChecked(m_viewProps->sortFoldersFirst());
index e945b00eb7bee7a7fceebde181a0e37de853658c..890a39d898f574ea72d0e0a5298baaa7d214fe29 100644 (file)
@@ -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);
         }
index f6bc1374a0e6026628c5bb3689f23faef6c21866..d87e5753204f55e13d6599f19329c9a3788dacc9 100644 (file)
@@ -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 (file)
index 3309f0e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   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 (file)
index 3c95541..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   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
-
index 19aca458311ae33be207c49a3980ca3c2ed9a52e..10e420c859b06a77e18c8d65e7680171a33b90d8 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "viewproperties.h"
 
-#include "rolesaccessor.h"
 #include "dolphin_directoryviewpropertysettings.h"
 #include "dolphin_generalsettings.h"