┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/views/viewproperties.cpp15
-rw-r--r--src/views/viewproperties.h5
2 files changed, 19 insertions, 1 deletions
diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp
index d6d5bfd94..d5330ffaa 100644
--- a/src/views/viewproperties.cpp
+++ b/src/views/viewproperties.cpp
@@ -61,7 +61,7 @@ ViewProperties::ViewProperties(const KUrl& url) :
} else if (url.isLocalFile()) {
m_filePath = url.toLocalFile();
const QFileInfo info(m_filePath);
- if (!info.isWritable()) {
+ if (!info.isWritable() || !isPartOfHome(m_filePath)) {
m_filePath = destinationDir("local") + m_filePath;
}
} else {
@@ -432,3 +432,16 @@ QString ViewProperties::viewModePrefix() const
return prefix;
}
+
+bool ViewProperties::isPartOfHome(const QString& filePath)
+{
+ // For performance reasons cache the path in a static QString
+ // (see QDir::homePath() for more details)
+ static QString homePath;
+ if (homePath.isEmpty()) {
+ homePath = QDir::homePath();
+ Q_ASSERT(!homePath.isEmpty());
+ }
+
+ return filePath.startsWith(homePath);
+}
diff --git a/src/views/viewproperties.h b/src/views/viewproperties.h
index 2db67c0f3..787122d35 100644
--- a/src/views/viewproperties.h
+++ b/src/views/viewproperties.h
@@ -149,6 +149,11 @@ private:
*/
QString viewModePrefix() const;
+ /**
+ * Returns true, if \a filePath is part of the home-path (see QDir::homePath()).
+ */
+ static bool isPartOfHome(const QString& filePath);
+
Q_DISABLE_COPY(ViewProperties)
private: