X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5593c252e8d9638c86dcc2bb9edd394ea14f8ba1..b610ce5913ef3172f3cf15c0a1d93c255ea0da4f:/src/views/viewproperties.cpp diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index 597baa293..d7c6abd65 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -22,20 +22,15 @@ #include "dolphin_directoryviewpropertysettings.h" #include "dolphin_generalsettings.h" - -#include #include "dolphindebug.h" #include -#include -#include -#include -#include namespace { const int AdditionalInfoViewPropertiesVersion = 1; const int NameRolePropertiesVersion = 2; - const int CurrentViewPropertiesVersion = 3; + const int DateRolePropertiesVersion = 4; + const int CurrentViewPropertiesVersion = 4; // String representation to mark the additional properties of // the details view as customized by the user. See @@ -49,7 +44,7 @@ namespace { ViewProperties::ViewProperties(const QUrl& url) : m_changedProps(false), m_autoSave(true), - m_node(0) + m_node(nullptr) { GeneralSettings* settings = GeneralSettings::self(); const bool useGlobalViewProps = settings->globalViewProps() || url.isEmpty(); @@ -68,17 +63,19 @@ ViewProperties::ViewProperties(const QUrl& url) : useDetailsViewWithPath = true; } else if (url.isLocalFile()) { m_filePath = url.toLocalFile(); - const QFileInfo dirInfo(m_filePath); - const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName); - // Check if the directory is writable and check if the ".directory" file exists and - // is read- and writable. - if (!dirInfo.isWritable() - || (fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable())) - || !isPartOfHome(m_filePath)) { -#ifdef Q_OS_WIN - // m_filePath probably begins with C:/ - the colon is not a valid character for paths though - m_filePath = QDir::separator() + m_filePath.remove(QLatin1Char(':')); -#endif + + bool useDestinationDir = !isPartOfHome(m_filePath); + if (!useDestinationDir) { + const QFileInfo dirInfo(m_filePath); + const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName); + useDestinationDir = !dirInfo.isWritable() || (dirInfo.size() > 0 && fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable())); + } + + if (useDestinationDir) { + #ifdef Q_OS_WIN + // m_filePath probably begins with C:/ - the colon is not a valid character for paths though + m_filePath = QDir::separator() + m_filePath.remove(QLatin1Char(':')); + #endif m_filePath = destinationDir(QStringLiteral("local")) + m_filePath; } } else { @@ -123,6 +120,11 @@ ViewProperties::ViewProperties(const QUrl& url) : Q_ASSERT(m_node->version() == NameRolePropertiesVersion); } + if (m_node->version() < DateRolePropertiesVersion) { + convertDateRoleToModificationTimeRole(); + Q_ASSERT(m_node->version() == DateRolePropertiesVersion); + } + m_node->setVersion(CurrentViewPropertiesVersion); } } @@ -134,7 +136,7 @@ ViewProperties::~ViewProperties() } delete m_node; - m_node = 0; + m_node = nullptr; } void ViewProperties::setViewMode(DolphinView::Mode mode) @@ -309,7 +311,7 @@ QList ViewProperties::visibleRoles() const && !visibleRoles.contains(CustomizedDetailsString); if (useDefaultValues) { roles.append("size"); - roles.append("date"); + roles.append("modificationtime"); } return roles; @@ -448,6 +450,27 @@ void ViewProperties::convertNameRoleToTextRole() update(); } +void ViewProperties::convertDateRoleToModificationTimeRole() +{ + QStringList visibleRoles = m_node->visibleRoles(); + for (int i = 0; i < visibleRoles.count(); ++i) { + if (visibleRoles[i].endsWith(QLatin1String("_date"))) { + const int leftLength = visibleRoles[i].length() - 5; + visibleRoles[i] = visibleRoles[i].left(leftLength) + "_modificationtime"; + } + } + + QString sortRole = m_node->sortRole(); + if (sortRole == QLatin1String("date")) { + sortRole = QStringLiteral("modificationtime"); + } + + m_node->setVisibleRoles(visibleRoles); + m_node->setSortRole(sortRole); + m_node->setVersion(DateRolePropertiesVersion); + update(); +} + bool ViewProperties::isPartOfHome(const QString& filePath) { // For performance reasons cache the path in a static QString