From cb9669d71cf10e73305c6a60fe0d832f4eb0ac7a Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 13 May 2010 22:06:10 +0000 Subject: [PATCH] If an information entry will be added to KFileItemDelegate (like done recently), adjusting the corresponding code in Dolphin is a real pain, as the new information will be shown in Dolphin the following way: - As additional columns in the details view - As additional lines in the icons view - As menu entries in the "Sort By" and "Additional Information" groups - As popup menu entries in the details view header popup - As checkable entries in the View Properties dialog To prevent similar painful transitions in future, the class AdditionalInfoManager has been introduced. All parts in Dolphin that access/show/store additional information, use the AdditionalInfoManager now. If a new information entry will be added in KFileItemDelegate in future, only a small adjustment in AdditionalInfoManager will be required. Still open currently: - AdditionalInfoDialog does not use AdditionalInfoManager yet - DolphinView::Sorting should be replaced by KFileItemDelegate::Information, so that the sorting can also be done in a generic way. - The data for KFileItemDelegate::PathOrUrl is not determined The open issues will get fixed during the next days. Kudos to the brave warriors Sebastian and Frank, that tried to add a new information ;-) CCMAIL: sebastian@trueg.de CCMAIL: frank78ac@googlemail.com svn path=/trunk/KDE/kdebase/apps/; revision=1126410 --- src/CMakeLists.txt | 3 +- src/additionalinfomanager.cpp | 107 +++++++++++++++++++++++++++ src/additionalinfomanager.h | 88 ++++++++++++++++++++++ src/dolphindetailsview.cpp | 38 ++++------ src/dolphinmodel.cpp | 42 ++++------- src/dolphinmodel.h | 7 +- src/dolphinview.cpp | 61 +++------------ src/dolphinviewactionhandler.cpp | 89 ++++++---------------- src/panels/folders/paneltreeview.cpp | 13 +--- src/viewproperties.cpp | 85 +++++++-------------- src/viewproperties.h | 14 +--- 11 files changed, 295 insertions(+), 252 deletions(-) create mode 100644 src/additionalinfomanager.cpp create mode 100644 src/additionalinfomanager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 724852205..c2b0fca80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,9 @@ endif (Nepomuk_FOUND) ########### next target ############### set(dolphinprivate_LIB_SRCS + additionalinfomanager.cpp dolphindetailsview.cpp + dolphindetailsviewexpander.cpp dolphiniconsview.cpp dolphincolumnview.cpp dolphincolumnviewcontainer.cpp @@ -31,7 +33,6 @@ set(dolphinprivate_LIB_SRCS dolphinviewautoscroller.cpp dolphinviewcontroller.cpp dolphinremoteencoding.cpp - dolphindetailsviewexpander.cpp draganddrophelper.cpp folderexpander.cpp renamedialog.cpp diff --git a/src/additionalinfomanager.cpp b/src/additionalinfomanager.cpp new file mode 100644 index 000000000..e27bcd262 --- /dev/null +++ b/src/additionalinfomanager.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2010 by Peter Penz * + * * + * 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 "additionalinfomanager.h" + +#include "dolphinmodel.h" +#include +#include + +class AdditionalInfoManagerSingleton +{ +public: + AdditionalInfoManager instance; +}; +K_GLOBAL_STATIC(AdditionalInfoManagerSingleton, s_additionalInfoManager) + +AdditionalInfoManager& AdditionalInfoManager::instance() +{ + return s_additionalInfoManager->instance; +} + +KFileItemDelegate::InformationList AdditionalInfoManager::keys() const +{ + return m_informations; +} + +KFileItemDelegate::Information AdditionalInfoManager::keyForColumn(int columnIndex) const +{ + KFileItemDelegate::Information info = KFileItemDelegate::NoInformation; + + switch (columnIndex) { + case DolphinModel::Size: info = KFileItemDelegate::Size; break; + case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break; + case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break; + case DolphinModel::Owner: info = KFileItemDelegate::Owner; break; + case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break; + case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break; + case DolphinModel::LinkDest: info = KFileItemDelegate::LinkDest; break; + case DolphinModel::LocalPathOrUrl: info = KFileItemDelegate::LocalPathOrUrl; break; + default: break; + } + + return info; +} + +QString AdditionalInfoManager::actionCollectionName(KFileItemDelegate::Information info) const +{ + return QLatin1String(m_map[info]->actionCollectionName); +} + +QString AdditionalInfoManager::translation(KFileItemDelegate::Information info) const +{ + return i18n(m_map[info]->translation); +} + +int AdditionalInfoManager::bitValue(KFileItemDelegate::Information info) const +{ + return m_map[info]->bitValue; +} + +AdditionalInfoManager::AdditionalInfoManager() : + m_informations(), + m_map() +{ + static const AdditionalInfoManager::AdditionalInfo additionalInfos[] = { + { "size", I18N_NOOP2("@label", "Size"), 1 }, + { "date", I18N_NOOP2("@label", "Date"), 2 }, + { "permissions", I18N_NOOP2("@label", "Permissions"), 4 }, + { "owner", I18N_NOOP2("@label", "Owner"), 8 }, + { "group", I18N_NOOP2("@label", "Group"), 16 }, + { "type", I18N_NOOP2("@label", "Type"), 32 }, + { "destination", I18N_NOOP2("@label", "Destination"), 64 }, + { "path", I18N_NOOP2("@label", "Path"), 128 } + }; + + m_map.insert(KFileItemDelegate::Size, &additionalInfos[0]); + m_map.insert(KFileItemDelegate::ModificationTime, &additionalInfos[1]); + m_map.insert(KFileItemDelegate::Permissions, &additionalInfos[2]); + m_map.insert(KFileItemDelegate::Owner, &additionalInfos[3]); + m_map.insert(KFileItemDelegate::OwnerAndGroup, &additionalInfos[4]); + m_map.insert(KFileItemDelegate::FriendlyMimeType, &additionalInfos[5]); + m_map.insert(KFileItemDelegate::LinkDest, &additionalInfos[6]); + m_map.insert(KFileItemDelegate::LocalPathOrUrl, &additionalInfos[7]); + + m_informations = m_map.keys(); +} + +AdditionalInfoManager::~AdditionalInfoManager() +{ +} + diff --git a/src/additionalinfomanager.h b/src/additionalinfomanager.h new file mode 100644 index 000000000..83b62c158 --- /dev/null +++ b/src/additionalinfomanager.h @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2010 by Peter Penz * + * * + * 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 ADDITIONALINFOMANAGER_H +#define ADDITIONALINFOMANAGER_H + +#include +#include + +#include +#include + +/** + * @brief Manages the information that is available by KFileItemDelegate::Information. + * + * The information that is available by KFileItemDelegate::Information will be shown + * in Dolphin the following way: + * - As additional columns in the details view + * - As additional lines in the icons view + * - As menu entries in the "Sort By" and "Additional Information" groups + * - As popup menu entries in the details view header popup + * - As checkable entries in the View Properties dialog + * + * The AdditionalInfoManager provides a central place to get all available keys, + * the corresponding translations, action names, etc., so that modifications or + * extensions in KFileItemDelegate only require adjustments in the implementation + * of this class. + */ +class LIBDOLPHINPRIVATE_EXPORT AdditionalInfoManager +{ +public: + static AdditionalInfoManager& instance(); + + /** + * @return List of all available information entries of KFileItemDelegate. + * All entries of this list are keys for accessing the corresponding + * data (see actionCollectionName(), translation(), bitValue()). + */ + KFileItemDelegate::InformationList keys() const; + + /** + * @return Key for the model column with the index \p columnIndex. + */ + KFileItemDelegate::Information keyForColumn(int columnIndex) const; + + QString actionCollectionName(KFileItemDelegate::Information info) const; + + QString translation(KFileItemDelegate::Information info) const; + + /** + * @return Bitvalue for \p info that is stored in a ViewProperties instance. + */ + int bitValue(KFileItemDelegate::Information info) const; + +protected: + AdditionalInfoManager(); + virtual ~AdditionalInfoManager(); + friend class AdditionalInfoManagerSingleton; + +private: + struct AdditionalInfo { + const char* const actionCollectionName; + const char* const translation; + const int bitValue; + }; + + KFileItemDelegate::InformationList m_informations; + QMap m_map; +}; + +#endif + diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 5545a6ede..130c9e9b3 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -20,6 +20,7 @@ #include "dolphindetailsview.h" +#include "additionalinfomanager.h" #include "dolphinmodel.h" #include "dolphinviewcontroller.h" #include "dolphinfileitemdelegate.h" @@ -607,11 +608,13 @@ void DolphinDetailsView::configureSettings(const QPoint& pos) for (int i = 0; i < columns; ++i) { const int logicalIndex = headerView->logicalIndex(i); const QString text = model()->headerData(logicalIndex, Qt::Horizontal).toString(); - QAction* action = popup.addAction(text); - action->setCheckable(true); - action->setChecked(!headerView->isSectionHidden(logicalIndex)); - action->setData(logicalIndex); - action->setEnabled(logicalIndex != DolphinModel::Name); + if (!text.isEmpty()) { + QAction* action = popup.addAction(text); + action->setCheckable(true); + action->setChecked(!headerView->isSectionHidden(logicalIndex)); + action->setData(logicalIndex); + action->setEnabled(logicalIndex != DolphinModel::Name); + } } popup.addSeparator(); @@ -989,20 +992,7 @@ void DolphinDetailsView::updateDecorationSize(bool showPreview) KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const { - KFileItemDelegate::Information info = KFileItemDelegate::NoInformation; - - switch (columnIndex) { - case DolphinModel::Size: info = KFileItemDelegate::Size; break; - case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break; - case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break; - case DolphinModel::Owner: info = KFileItemDelegate::Owner; break; - case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break; - case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break; - case DolphinModel::LinkDestination: info = KFileItemDelegate::LinkDest; break; - default: break; - } - - return info; + return AdditionalInfoManager::instance().keyForColumn(columnIndex); } void DolphinDetailsView::resizeColumns() @@ -1017,14 +1007,12 @@ void DolphinDetailsView::resizeColumns() QFontMetrics fontMetrics(viewport()->font()); int columnWidth[DolphinModel::ExtraColumnCount]; + const int defaultWidth = fontMetrics.width("xxxxxxxxxx"); + for (int i = 0; i < DolphinModel::ExtraColumnCount; ++i) { + columnWidth[i] = defaultWidth; + } columnWidth[DolphinModel::Size] = fontMetrics.width("00000 Items"); columnWidth[DolphinModel::ModifiedTime] = fontMetrics.width("0000-00-00 00:00"); - columnWidth[DolphinModel::Permissions] = fontMetrics.width("xxxxxxxxxx"); - columnWidth[DolphinModel::Owner] = fontMetrics.width("xxxxxxxxxx"); - columnWidth[DolphinModel::Group] = fontMetrics.width("xxxxxxxxxx"); - columnWidth[DolphinModel::Type] = fontMetrics.width("XXXX Xxxxxxx"); - columnWidth[DolphinModel::Version] = fontMetrics.width("xxxxxxxx"); - columnWidth[DolphinModel::LinkDestination] = fontMetrics.width("xxxxxxxx"); int requiredWidth = 0; for (int i = KDirModel::Size; i <= KDirModel::Type; ++i) { diff --git a/src/dolphinmodel.cpp b/src/dolphinmodel.cpp index d81e0c38b..7e0986485 100644 --- a/src/dolphinmodel.cpp +++ b/src/dolphinmodel.cpp @@ -94,31 +94,17 @@ QVariant DolphinModel::data(const QModelIndex& index, int role) const break; case Qt::DisplayRole: - if (index.column() == DolphinModel::Version) { - switch (m_revisionHash.value(index, KVersionControlPlugin::UnversionedVersion)) { - case KVersionControlPlugin::NormalVersion: - return i18nc("@item::intable", "Normal"); - case KVersionControlPlugin::UpdateRequiredVersion: - return i18nc("@item::intable", "Update required"); - case KVersionControlPlugin::LocallyModifiedVersion: - return i18nc("@item::intable", "Locally modified"); - case KVersionControlPlugin::AddedVersion: - return i18nc("@item::intable", "Added"); - case KVersionControlPlugin::RemovedVersion: - return i18nc("@item::intable", "Removed"); - case KVersionControlPlugin::ConflictingVersion: - return i18nc("@item::intable", "Conflicting"); - case KVersionControlPlugin::UnversionedVersion: - default: - return i18nc("@item::intable", "Unversioned"); - } + switch (index.column()) { + case DolphinModel::LinkDest: { + const KDirModel *dirModel = qobject_cast(index.model()); + const KFileItem item = dirModel->itemForIndex(index); + return item.linkDest(); + } + + case DolphinModel::LocalPathOrUrl: + // TODO: + break; } - else if (index.column() == DolphinModel::LinkDestination) { - const KDirModel *dirModel = qobject_cast(index.model()); - KFileItem item = dirModel->itemForIndex(index); - return item.linkDest(); - } - break; default: @@ -132,10 +118,10 @@ QVariant DolphinModel::headerData(int section, Qt::Orientation orientation, int { if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) { switch (section) { - case DolphinModel::Version: - return i18nc("@title::column", "Version"); - case DolphinModel::LinkDestination: - return i18nc("@title::column", "Link Destination"); + case DolphinModel::LinkDest: + return i18nc("@title::column", "Destination"); + case DolphinModel::LocalPathOrUrl: + return i18nc("@title::column", "Path"); default: return KDirModel::headerData(section, orientation, role); } diff --git a/src/dolphinmodel.h b/src/dolphinmodel.h index 5c43028c8..6f1b00c75 100644 --- a/src/dolphinmodel.h +++ b/src/dolphinmodel.h @@ -35,15 +35,16 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinModel : public KDirModel public: enum AdditionalColumns { Version = KDirModel::ColumnCount, - LinkDestination, - ExtraColumnCount + LinkDest, + LocalPathOrUrl, + ExtraColumnCount // Mandatory last entry }; DolphinModel(QObject* parent = 0); virtual ~DolphinModel(); virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 5ad77f726..3cfeccfde 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -49,6 +49,7 @@ #include #include +#include "additionalinfomanager.h" #include "dolphinmodel.h" #include "dolphincolumnviewcontainer.h" #include "dolphinviewcontroller.h" @@ -971,59 +972,19 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) { + const AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + + const KFileItemDelegate::InformationList checkedInfos = m_viewAccessor.itemDelegate()->showInformation(); + const KFileItemDelegate::InformationList infos = infoManager.keys(); + 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"); - QAction* showPathOrUrlInfo = collection->action("show_path_or_url_info"); - - showSizeInfo->setChecked(false); - showDateInfo->setChecked(false); - showPermissionsInfo->setChecked(false); - showOwnerInfo->setChecked(false); - showGroupInfo->setChecked(false); - showMimeInfo->setChecked(false); - showPathOrUrlInfo->setChecked(false); - - showSizeInfo->setEnabled(enable); - showDateInfo->setEnabled(enable); - showPermissionsInfo->setEnabled(enable); - showOwnerInfo->setEnabled(enable); - showGroupInfo->setEnabled(enable); - showMimeInfo->setEnabled(enable); - showPathOrUrlInfo->setEnabled(enable); - - foreach (KFileItemDelegate::Information info, m_viewAccessor.itemDelegate()->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; - case KFileItemDelegate::LocalPathOrUrl: - showPathOrUrlInfo->setChecked(true); - break; - default: - break; - } + foreach (const KFileItemDelegate::Information& info, infos) { + QAction* action = collection->action(infoManager.actionCollectionName(info)); + Q_ASSERT(action != 0); + action->setEnabled(enable); + action->setChecked(checkedInfos.contains(info)); } } diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp index ab28dca26..62dd4fcfa 100644 --- a/src/dolphinviewactionhandler.cpp +++ b/src/dolphinviewactionhandler.cpp @@ -19,6 +19,7 @@ #include "dolphinviewactionhandler.h" +#include "additionalinfomanager.h" #include "settings/viewpropertiesdialog.h" #include "dolphinview.h" #include "zoomlevelinfo.h" @@ -27,9 +28,10 @@ #include #include #include -#include +#include #include #include +#include #include #include #include @@ -219,40 +221,16 @@ QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup() showInformationMenu->setText(i18nc("@action:inmenu View", "Additional Information")); showInformationMenu->setDelayed(false); - KToggleAction* showSizeInfo = m_actionCollection->add("show_size_info"); - showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); - showSizeInfo->setData(KFileItemDelegate::Size); - showSizeInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showDateInfo = m_actionCollection->add("show_date_info"); - showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); - showDateInfo->setData(KFileItemDelegate::ModificationTime); - showDateInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showPermissionsInfo = m_actionCollection->add("show_permissions_info"); - showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); - showPermissionsInfo->setData(KFileItemDelegate::Permissions); - showPermissionsInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showOwnerInfo = m_actionCollection->add("show_owner_info"); - showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); - showOwnerInfo->setData(KFileItemDelegate::Owner); - showOwnerInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showGroupInfo = m_actionCollection->add("show_group_info"); - showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); - showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); - showGroupInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showMimeInfo = m_actionCollection->add("show_mime_info"); - showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); - showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); - showMimeInfo->setActionGroup(additionalInfoGroup); - - KToggleAction* showPathOrUrlInfo = m_actionCollection->add("show_path_or_url_info"); - showPathOrUrlInfo->setText(i18nc("@action:inmenu Additional information", "Path")); - showPathOrUrlInfo->setData(KFileItemDelegate::LocalPathOrUrl); - showPathOrUrlInfo->setActionGroup(additionalInfoGroup); + const AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + + const KFileItemDelegate::InformationList infos = infoManager.keys(); + foreach (KFileItemDelegate::Information info, infos) { + const QString name = infoManager.actionCollectionName(info); + KToggleAction* action = m_actionCollection->add(name); + action->setText(infoManager.translation(info)); + action->setData(info); + action->setActionGroup(additionalInfoGroup); + } return additionalInfoGroup; } @@ -264,40 +242,21 @@ QActionGroup* DolphinViewActionHandler::createSortByActionGroup() QActionGroup* sortByActionGroup = new QActionGroup(m_actionCollection); sortByActionGroup->setExclusive(true); - KToggleAction* sortByName = m_actionCollection->add("sort_by_name"); + KToggleAction* sortByName = m_actionCollection->add("name"); sortByName->setText(i18nc("@action:inmenu Sort By", "Name")); sortByName->setData(QVariant::fromValue(DolphinView::SortByName)); sortByActionGroup->addAction(sortByName); - KToggleAction* sortBySize = m_actionCollection->add("sort_by_size"); - sortBySize->setText(i18nc("@action:inmenu Sort By", "Size")); - sortBySize->setData(QVariant::fromValue(DolphinView::SortBySize)); - sortByActionGroup->addAction(sortBySize); - - KToggleAction* sortByDate = m_actionCollection->add("sort_by_date"); - sortByDate->setText(i18nc("@action:inmenu Sort By", "Date")); - sortByDate->setData(QVariant::fromValue(DolphinView::SortByDate)); - sortByActionGroup->addAction(sortByDate); - - KToggleAction* sortByPermissions = m_actionCollection->add("sort_by_permissions"); - sortByPermissions->setText(i18nc("@action:inmenu Sort By", "Permissions")); - sortByPermissions->setData(QVariant::fromValue(DolphinView::SortByPermissions)); - sortByActionGroup->addAction(sortByPermissions); - - KToggleAction* sortByOwner = m_actionCollection->add("sort_by_owner"); - sortByOwner->setText(i18nc("@action:inmenu Sort By", "Owner")); - sortByOwner->setData(QVariant::fromValue(DolphinView::SortByOwner)); - sortByActionGroup->addAction(sortByOwner); - - KToggleAction* sortByGroup = m_actionCollection->add("sort_by_group"); - sortByGroup->setText(i18nc("@action:inmenu Sort By", "Group")); - sortByGroup->setData(QVariant::fromValue(DolphinView::SortByGroup)); - sortByActionGroup->addAction(sortByGroup); - - KToggleAction* sortByType = m_actionCollection->add("sort_by_type"); - sortByType->setText(i18nc("@action:inmenu Sort By", "Type")); - sortByType->setData(QVariant::fromValue(DolphinView::SortByType)); - sortByActionGroup->addAction(sortByType); + const AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + const KFileItemDelegate::InformationList infos = infoManager.keys(); + foreach (KFileItemDelegate::Information info, infos) { + const QString name = infoManager.actionCollectionName(info); + KToggleAction* action = m_actionCollection->add(name); + action->setText(infoManager.translation(info)); + // TODO: replace DolphinView::Sorting by KFileItemDelegate::Information! + action->setData(QVariant::fromValue(DolphinView::SortByName)); + sortByActionGroup->addAction(action); + } return sortByActionGroup; } diff --git a/src/panels/folders/paneltreeview.cpp b/src/panels/folders/paneltreeview.cpp index 646115037..58866d6c3 100644 --- a/src/panels/folders/paneltreeview.cpp +++ b/src/panels/folders/paneltreeview.cpp @@ -69,15 +69,10 @@ bool PanelTreeView::event(QEvent* event) { switch (event->type()) { case QEvent::Polish: - // hide all columns except of the 'Name' column - hideColumn(DolphinModel::Size); - hideColumn(DolphinModel::ModifiedTime); - hideColumn(DolphinModel::Permissions); - hideColumn(DolphinModel::Owner); - hideColumn(DolphinModel::Group); - hideColumn(DolphinModel::Type); - hideColumn(DolphinModel::Version); - hideColumn(DolphinModel::LinkDestination); + // Hide all columns except of the 'Name' column + for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) { + hideColumn(i); + } header()->hide(); break; diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp index d78fdd4f5..d153e5427 100644 --- a/src/viewproperties.cpp +++ b/src/viewproperties.cpp @@ -20,6 +20,7 @@ #include "viewproperties.h" +#include "additionalinfomanager.h" #include "settings/dolphinsettings.h" #include "dolphin_directoryviewpropertysettings.h" #include "dolphin_generalsettings.h" @@ -33,8 +34,6 @@ #include #include -#define FILE_NAME "/.directory" - ViewProperties::ViewProperties(const KUrl& url) : m_changedProps(false), m_autoSave(true), @@ -44,8 +43,10 @@ ViewProperties::ViewProperties(const KUrl& url) : cleanUrl.cleanPath(); m_filepath = cleanUrl.toLocalFile(); + const QLatin1String fileName("/.directory"); + if ((m_filepath.length() < 1) || (!QDir::isAbsolutePath(m_filepath))) { - const QString file = destinationDir("global") + FILE_NAME; + const QString file = destinationDir("global") + fileName; m_node = new ViewPropertySettings(KSharedConfig::openConfig(file)); return; } @@ -66,7 +67,7 @@ ViewProperties::ViewProperties(const KUrl& url) : m_filepath = destinationDir("remote") + m_filepath; } - const QString file = m_filepath + FILE_NAME; + const QString file = m_filepath + fileName; m_node = new ViewPropertySettings(KSharedConfig::openConfig(file)); const bool useDefaultProps = !useGlobalViewProps && @@ -189,38 +190,16 @@ bool ViewProperties::sortFoldersFirst() const return m_node->sortFoldersFirst(); } -void ViewProperties::setAdditionalInfo(KFileItemDelegate::InformationList list) +void ViewProperties::setAdditionalInfo(const KFileItemDelegate::InformationList& list) { - int info = NoInfo; + AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + + int infoMask = 0; foreach (KFileItemDelegate::Information currentInfo, list) { - switch (currentInfo) { - case KFileItemDelegate::Size: - info = info | SizeInfo; - break; - case KFileItemDelegate::ModificationTime: - info = info | DateInfo; - break; - case KFileItemDelegate::Permissions: - info = info | PermissionsInfo; - break; - case KFileItemDelegate::Owner: - info = info | OwnerInfo; - break; - case KFileItemDelegate::OwnerAndGroup: - info = info | GroupInfo; - break; - case KFileItemDelegate::FriendlyMimeType: - info = info | TypeInfo; - break; - case KFileItemDelegate::LocalPathOrUrl: - info = info | PathOrUrlInfo; - break; - default: - break; - } + infoMask = infoMask | infoManager.bitValue(currentInfo); } - const int encodedInfo = encodedAdditionalInfo(info); + const int encodedInfo = encodedAdditionalInfo(infoMask); if (m_node->additionalInfo() != encodedInfo) { m_node->setAdditionalInfo(encodedInfo); updateTimeStamp(); @@ -229,32 +208,20 @@ void ViewProperties::setAdditionalInfo(KFileItemDelegate::InformationList list) KFileItemDelegate::InformationList ViewProperties::additionalInfo() const { - const int info = decodedAdditionalInfo(); + KFileItemDelegate::InformationList usedInfos; - KFileItemDelegate::InformationList list; - if (info & SizeInfo) { - list.append(KFileItemDelegate::Size); - } - if (info & DateInfo) { - list.append(KFileItemDelegate::ModificationTime); - } - if (info & PermissionsInfo) { - list.append(KFileItemDelegate::Permissions); - } - if (info & OwnerInfo) { - list.append(KFileItemDelegate::Owner); - } - if (info & GroupInfo) { - list.append(KFileItemDelegate::OwnerAndGroup); - } - if (info & TypeInfo) { - list.append(KFileItemDelegate::FriendlyMimeType); - } - if (info & PathOrUrlInfo) { - list.append(KFileItemDelegate::LocalPathOrUrl); + const int decodedInfo = decodedAdditionalInfo(); + + AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + const KFileItemDelegate::InformationList infos = infoManager.keys(); + + foreach (const KFileItemDelegate::Information info, infos) { + if (decodedInfo & infoManager.bitValue(info)) { + usedInfos.append(info); + } } - return list; + return usedInfos; } @@ -334,10 +301,12 @@ int ViewProperties::decodedAdditionalInfo() const switch (viewMode()) { case DolphinView::DetailsView: decodedInfo = decodedInfo & 0xFF; - if (decodedInfo == NoInfo) { - // a details view without any additional info makes no sense, hence + if (decodedInfo == 0) { + // A details view without any additional info makes no sense, hence // provide at least a size-info and date-info as fallback - decodedInfo = SizeInfo | DateInfo; + AdditionalInfoManager& infoManager = AdditionalInfoManager::instance(); + decodedInfo = infoManager.bitValue(KFileItemDelegate::Size) | + infoManager.bitValue(KFileItemDelegate::ModificationTime); } break; case DolphinView::IconsView: diff --git a/src/viewproperties.h b/src/viewproperties.h index 696358726..c1fa19162 100644 --- a/src/viewproperties.h +++ b/src/viewproperties.h @@ -79,7 +79,7 @@ public: * Note that the additional-info property is the only property where * the value is dependent from another property (in this case the view-mode). */ - void setAdditionalInfo(KFileItemDelegate::InformationList info); + void setAdditionalInfo(const KFileItemDelegate::InformationList& info); /** * Returns the additional information for the current set view-mode. @@ -154,18 +154,6 @@ private: Q_DISABLE_COPY(ViewProperties) private: - enum AdditionalInfoValues - { - NoInfo = 0, - SizeInfo = 1, - DateInfo = 2, - PermissionsInfo = 4, - OwnerInfo = 8, - GroupInfo = 16, - TypeInfo = 32, - PathOrUrlInfo = 64 - }; - bool m_changedProps; bool m_autoSave; QString m_filepath; -- 2.47.3