From cb9669d71cf10e73305c6a60fe0d832f4eb0ac7a Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 13 May 2010 22:06:10 +0000 Subject: 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/viewproperties.cpp | 85 ++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 58 deletions(-) (limited to 'src/viewproperties.cpp') 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: -- cgit v1.3