diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -23,6 +23,7 @@ #include "dolphin_directoryviewpropertysettings.h" #include "dolphin_generalsettings.h" #include "dolphindebug.h" +#include #include @@ -69,35 +70,45 @@ } else if (url.isLocalFile()) { m_filePath = url.toLocalFile(); - 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 (m_filePath == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) { + useDownloadsView = true; } - if (useDestinationDir) { + const bool usedToUseDestinationDir = !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(':')); + // 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; - } + m_filePath = destinationDir(QStringLiteral("local")) + m_filePath; - if (m_filePath == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) { - useDownloadsView = true; + // In case the viewproperty file was not located in destinationDir already prior to fixing 322922 + // After a few versions we can remove this code block and most users won't be affected anymore by the change + if (!usedToUseDestinationDir) { + + const QString oldViewPropertyFile = url.toLocalFile() + QDir::separator() + ViewPropertiesFileName; + const QString newViewPropertyFile = m_filePath + QDir::separator() + ViewPropertiesFileName; + + // In case there is no viewproperty file at the current Location but that an old .directory file was saved + // Attempt to move it to the new path in destination Dir + if (!QFile::exists(newViewPropertyFile) && QFile::exists(oldViewPropertyFile)) { + const QUrl oldUrl = QUrl::fromLocalFile(oldViewPropertyFile); + const QUrl newUrl = QUrl::fromLocalFile(newViewPropertyFile); + + // qDebug() << "Moving " << oldViewPropertyFile << " to " << newViewPropertyFile; + KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo)->exec(); + } } } else { m_filePath = destinationDir(QStringLiteral("remote")) + m_filePath; } - const QString file = m_filePath + QDir::separator() + ViewPropertiesFileName; - m_node = new ViewPropertySettings(KSharedConfig::openConfig(file)); + const QString viewPropertyFile = m_filePath + QDir::separator() + ViewPropertiesFileName; + m_node = new ViewPropertySettings(KSharedConfig::openConfig(viewPropertyFile)); // If the .directory file does not exist or the timestamp is too old, // use default values instead. const bool useDefaultProps = (!useGlobalViewProps || useDetailsViewWithPath) && - (!QFile::exists(file) || + (!QFile::exists(viewPropertyFile) || (m_node->timestamp() < settings->viewPropsTimestamp())); if (useDefaultProps) { if (useDetailsViewWithPath) {