Changeset View
Changeset View
Standalone View
Standalone View
src/views/viewproperties.cpp
Show All 17 Lines | |||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "viewproperties.h" | 21 | #include "viewproperties.h" | ||
22 | 22 | | |||
23 | #include "dolphin_directoryviewpropertysettings.h" | 23 | #include "dolphin_directoryviewpropertysettings.h" | ||
24 | #include "dolphin_generalsettings.h" | 24 | #include "dolphin_generalsettings.h" | ||
25 | #include "dolphindebug.h" | 25 | #include "dolphindebug.h" | ||
26 | #include <KIO/CopyJob> | ||||
26 | 27 | | |||
27 | #include <QCryptographicHash> | 28 | #include <QCryptographicHash> | ||
28 | 29 | | |||
29 | namespace { | 30 | namespace { | ||
30 | const int AdditionalInfoViewPropertiesVersion = 1; | 31 | const int AdditionalInfoViewPropertiesVersion = 1; | ||
31 | const int NameRolePropertiesVersion = 2; | 32 | const int NameRolePropertiesVersion = 2; | ||
32 | const int DateRolePropertiesVersion = 4; | 33 | const int DateRolePropertiesVersion = 4; | ||
33 | const int CurrentViewPropertiesVersion = 4; | 34 | const int CurrentViewPropertiesVersion = 4; | ||
Show All 30 Lines | 64 | } else if (url.scheme() == QLatin1String("trash")) { | |||
64 | m_filePath = destinationDir(QStringLiteral("trash")); | 65 | m_filePath = destinationDir(QStringLiteral("trash")); | ||
65 | useDetailsViewWithPath = true; | 66 | useDetailsViewWithPath = true; | ||
66 | } else if (url.scheme() == QLatin1String("recentdocuments")) { | 67 | } else if (url.scheme() == QLatin1String("recentdocuments")) { | ||
67 | m_filePath = destinationDir(QStringLiteral("recentdocuments")); | 68 | m_filePath = destinationDir(QStringLiteral("recentdocuments")); | ||
68 | useRecentDocumentsView = true; | 69 | useRecentDocumentsView = true; | ||
69 | } else if (url.isLocalFile()) { | 70 | } else if (url.isLocalFile()) { | ||
70 | m_filePath = url.toLocalFile(); | 71 | m_filePath = url.toLocalFile(); | ||
71 | 72 | | |||
72 | bool useDestinationDir = !isPartOfHome(m_filePath); | 73 | if (m_filePath == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) { | ||
73 | if (!useDestinationDir) { | 74 | useDownloadsView = true; | ||
74 | const QFileInfo dirInfo(m_filePath); | | |||
75 | const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName); | | |||
76 | useDestinationDir = !dirInfo.isWritable() || (dirInfo.size() > 0 && fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable())); | | |||
77 | } | 75 | } | ||
78 | 76 | | |||
79 | if (useDestinationDir) { | 77 | const bool usedToUseDestinationDir = !isPartOfHome(m_filePath); | ||
80 | #ifdef Q_OS_WIN | 78 | #ifdef Q_OS_WIN | ||
81 | // m_filePath probably begins with C:/ - the colon is not a valid character for paths though | 79 | // m_filePath probably begins with C:/ - the colon is not a valid character for paths though | ||
82 | m_filePath = QDir::separator() + m_filePath.remove(QLatin1Char(':')); | 80 | m_filePath = QDir::separator() + m_filePath.remove(QLatin1Char(':')); | ||
83 | #endif | 81 | #endif | ||
84 | m_filePath = destinationDir(QStringLiteral("local")) + m_filePath; | 82 | m_filePath = destinationDir(QStringLiteral("local")) + m_filePath; | ||
85 | } | | |||
86 | 83 | | |||
87 | if (m_filePath == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) { | 84 | // In case the viewproperty file was not located in destinationDir already prior to fix to 322922 | ||
ngraham: `prior to fix to 322922` -> `prior to fixing 322922` | |||||
88 | useDownloadsView = true; | 85 | // After a few version we can remove this code block and most users won't be affected anymore by the change | ||
ngraham: `version` -> `versions` | |||||
86 | if (!usedToUseDestinationDir) { | ||||
87 | | ||||
88 | const QString oldViewPropertyFile = url.toLocalFile() + QDir::separator() + ViewPropertiesFileName; | ||||
89 | const QString newViewPropertyFile = m_filePath + QDir::separator() + ViewPropertiesFileName; | ||||
Don't use QDir::separator(); Qt automatically translates slashes as needed on Windows. ngraham: Don't use `QDir::separator()`; Qt automatically translates slashes as needed on Windows.
https… | |||||
90 | | ||||
91 | // In case there is no viewproperty file at the current Location but that an old .directory file was saved | ||||
92 | // Attempt to move it to the new path in destination Dir | ||||
93 | if (!QFile::exists(newViewPropertyFile) && QFile::exists(oldViewPropertyFile)) { | ||||
94 | const QUrl oldUrl = QUrl::fromLocalFile(oldViewPropertyFile); | ||||
95 | const QUrl newUrl = QUrl::fromLocalFile(newViewPropertyFile); | ||||
96 | | ||||
97 | // qDebug() << "Moving " << oldViewPropertyFile << " to " << newViewPropertyFile; | ||||
98 | KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo)->exec(); | ||||
99 | } | ||||
89 | } | 100 | } | ||
90 | } else { | 101 | } else { | ||
91 | m_filePath = destinationDir(QStringLiteral("remote")) + m_filePath; | 102 | m_filePath = destinationDir(QStringLiteral("remote")) + m_filePath; | ||
92 | } | 103 | } | ||
93 | 104 | | |||
94 | const QString file = m_filePath + QDir::separator() + ViewPropertiesFileName; | 105 | const QString viewPropertyFile = m_filePath + QDir::separator() + ViewPropertiesFileName; | ||
95 | m_node = new ViewPropertySettings(KSharedConfig::openConfig(file)); | 106 | m_node = new ViewPropertySettings(KSharedConfig::openConfig(viewPropertyFile)); | ||
96 | 107 | | |||
97 | // If the .directory file does not exist or the timestamp is too old, | 108 | // If the .directory file does not exist or the timestamp is too old, | ||
98 | // use default values instead. | 109 | // use default values instead. | ||
99 | const bool useDefaultProps = (!useGlobalViewProps || useDetailsViewWithPath) && | 110 | const bool useDefaultProps = (!useGlobalViewProps || useDetailsViewWithPath) && | ||
100 | (!QFile::exists(file) || | 111 | (!QFile::exists(viewPropertyFile) || | ||
101 | (m_node->timestamp() < settings->viewPropsTimestamp())); | 112 | (m_node->timestamp() < settings->viewPropsTimestamp())); | ||
102 | if (useDefaultProps) { | 113 | if (useDefaultProps) { | ||
103 | if (useDetailsViewWithPath) { | 114 | if (useDetailsViewWithPath) { | ||
104 | setViewMode(DolphinView::DetailsView); | 115 | setViewMode(DolphinView::DetailsView); | ||
105 | setVisibleRoles({"path"}); | 116 | setVisibleRoles({"path"}); | ||
106 | } else if (useRecentDocumentsView || useDownloadsView) { | 117 | } else if (useRecentDocumentsView || useDownloadsView) { | ||
107 | setSortRole(QByteArrayLiteral("modificationtime")); | 118 | setSortRole(QByteArrayLiteral("modificationtime")); | ||
108 | setSortOrder(Qt::DescendingOrder); | 119 | setSortOrder(Qt::DescendingOrder); | ||
▲ Show 20 Lines • Show All 405 Lines • Show Last 20 Lines |
prior to fix to 322922 -> prior to fixing 322922