diff options
| author | Peter Penz <[email protected]> | 2012-03-12 15:18:02 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-03-12 15:19:20 +0100 |
| commit | 6c60bf0ad54258976d9dcbd6586b26c65d8d4b78 (patch) | |
| tree | 3739a86de6c9f23f63cb45593194e34ff23962e2 /src | |
| parent | 2ba5c2cfc2cea534cccd860f94a7198530b83594 (diff) | |
Provide backward compatibility with older .directory versions
When upgrading to Dolphin 2.1 the obsolete additionalInfo-property
must be converted to the visibleRoles-property.
Diffstat (limited to 'src')
| -rw-r--r-- | src/settings/dolphin_directoryviewpropertysettings.kcfg | 9 | ||||
| -rw-r--r-- | src/views/viewproperties.cpp | 46 | ||||
| -rw-r--r-- | src/views/viewproperties.h | 7 |
3 files changed, 59 insertions, 3 deletions
diff --git a/src/settings/dolphin_directoryviewpropertysettings.kcfg b/src/settings/dolphin_directoryviewpropertysettings.kcfg index db1a5cdc0..3f2c46a9c 100644 --- a/src/settings/dolphin_directoryviewpropertysettings.kcfg +++ b/src/settings/dolphin_directoryviewpropertysettings.kcfg @@ -18,8 +18,7 @@ <entry name="Version" type="Int" > <label context="@label">Version</label> <whatsthis context="@info:whatsthis">This option defines the used version of the view properties.</whatsthis> - <default>2</default> - <min>1</min> + <default>-1</default> </entry> <entry name="ViewMode" type="Int" > @@ -67,6 +66,12 @@ <label context="@label">Properties last changed</label> <whatsthis context="@info:whatsthis">The last time these properties were changed by the user.</whatsthis> </entry> + + <!-- Obsolete - replaced by VisibleRoles --> + <entry name="AdditionalInfo" type="StringList"> + <label context="@label">Additional Information</label> + <default></default> + </entry> </group> </kcfg> diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index e7b0f9c55..19aca4583 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -34,6 +34,9 @@ #include <QFileInfo> namespace { + const int CurrentViewPropertiesVersion = 2; + const int AdditionalInfoViewPropertiesVersion = 1; + // String representation to mark the additional properties of // the details view as customized by the user. See // ViewProperties::visibleRoles() for more information. @@ -256,7 +259,14 @@ QList<QByteArray> ViewProperties::visibleRoles() const // the curren view mode. const QString prefix = viewModePrefix(); const int prefixLength = prefix.length(); - const QStringList visibleRoles = m_node->visibleRoles(); + + QStringList visibleRoles = m_node->visibleRoles(); + if (visibleRoles.isEmpty() && m_node->version() <= AdditionalInfoViewPropertiesVersion) { + // Convert the obsolete additionalInfo-property from older versions into the + // visibleRoles-property + visibleRoles = const_cast<ViewProperties*>(this)->convertAdditionalInfo(); + } + foreach (const QString& visibleRole, visibleRoles) { if (visibleRole.startsWith(prefix)) { const QByteArray role = visibleRole.right(visibleRole.length() - prefixLength).toLatin1(); @@ -310,6 +320,7 @@ void ViewProperties::update() void ViewProperties::save() { KStandardDirs::makeDir(m_filePath); + m_node->setVersion(CurrentViewPropertiesVersion); m_node->writeConfig(); m_changedProps = false; } @@ -342,6 +353,39 @@ QString ViewProperties::viewModePrefix() const return prefix; } +QStringList ViewProperties::convertAdditionalInfo() +{ + QStringList visibleRoles; + + const QStringList additionalInfo = m_node->additionalInfo(); + if (!additionalInfo.isEmpty()) { + // Convert the obsolete values like Icons_Size, Details_Date, ... + // to Icons_size, Details_date, ... where the suffix just represents + // the internal role. One special-case must be handled: "LinkDestination" + // has been used for "destination". + visibleRoles.reserve(additionalInfo.count()); + foreach (const QString& info, additionalInfo) { + QString visibleRole = info; + int index = visibleRole.indexOf('_'); + if (index >= 0 && index + 1 < visibleRole.length()) { + ++index; + if (visibleRole[index] == QLatin1Char('L')) { + visibleRole.replace("LinkDestination", "destination"); + } else { + visibleRole[index] = visibleRole[index].toLower(); + } + } + visibleRoles.append(visibleRole); + } + } + + m_node->setAdditionalInfo(QStringList()); + m_node->setVisibleRoles(visibleRoles); + update(); + + return visibleRoles; +} + bool ViewProperties::isPartOfHome(const QString& filePath) { // For performance reasons cache the path in a static QString diff --git a/src/views/viewproperties.h b/src/views/viewproperties.h index b46249eb2..96a5515ef 100644 --- a/src/views/viewproperties.h +++ b/src/views/viewproperties.h @@ -138,6 +138,13 @@ private: QString viewModePrefix() const; /** + * Provides backward compatibility with .directory files created with + * Dolphin < 2.1: Converts the old additionalInfo-property into + * the visibleRoles-property and clears the additionalInfo-property. + */ + QStringList convertAdditionalInfo(); + + /** * Returns true, if \a filePath is part of the home-path (see QDir::homePath()). */ static bool isPartOfHome(const QString& filePath); |
