Changeset View
Changeset View
Standalone View
Standalone View
src/imagefoldermodel.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 75 | { | |||
---|---|---|---|---|---|
76 | return dirLister()->url().toString(); | 76 | return dirLister()->url().toString(); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | void ImageFolderModel::setUrl(QString& url) | 79 | void ImageFolderModel::setUrl(QString& url) | ||
80 | { | 80 | { | ||
81 | Q_ASSERT( QUrl(url).isLocalFile()); | 81 | Q_ASSERT( QUrl(url).isLocalFile()); | ||
82 | url = QUrl(url).path(); | 82 | url = QUrl(url).path(); | ||
83 | 83 | | |||
84 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | | |||
85 | if (url.isEmpty()) { | 84 | if (url.isEmpty()) { | ||
85 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | ||||
86 | Q_ASSERT(locations.size() > 1); | 86 | Q_ASSERT(locations.size() > 1); | ||
87 | url = locations.first().append("/"); | 87 | url = locations.first().append("/"); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | QString directoryUrl; | 90 | url = QUrl::fromLocalFile(url).toString(); | ||
91 | | ||||
92 | if (QDir(url).exists()) { | | |||
93 | directoryUrl = QUrl::fromLocalFile(url).toString(); | | |||
94 | } else { | | |||
95 | m_imagePath = url; | | |||
96 | directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); | | |||
97 | } | | |||
98 | | ||||
99 | /** | | |||
100 | * Sets the url to ~/Pictures if the path is ~/Pictures path | | |||
101 | * and leave it as it is, if it is foreign path | | |||
102 | */ | | |||
103 | if (directoryUrl.contains(QUrl::fromLocalFile(locations.first()).toString())) { | | |||
104 | directoryUrl = QUrl::fromLocalFile(locations.first()).toString(); | | |||
105 | } | | |||
106 | 91 | | |||
107 | if (dirLister()->url().path() == directoryUrl) { | 92 | if (dirLister()->url().path() == QUrl(url).path()) { | ||
108 | dirLister()->updateDirectory(QUrl(directoryUrl)); | 93 | dirLister()->updateDirectory(QUrl(url)); | ||
109 | return; | 94 | return; | ||
110 | } | 95 | } | ||
111 | 96 | | |||
112 | beginResetModel(); | 97 | beginResetModel(); | ||
113 | dirLister()->openUrl(QUrl(directoryUrl)); | 98 | dirLister()->openUrl(QUrl(url)); | ||
114 | endResetModel(); | 99 | endResetModel(); | ||
115 | emit urlChanged(); | 100 | emit urlChanged(); | ||
116 | } | 101 | } | ||
117 | 102 | | |||
118 | int ImageFolderModel::indexForUrl(const QString &url) const | 103 | int ImageFolderModel::indexForUrl(const QString &url) const | ||
119 | { | 104 | { | ||
120 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | 105 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | ||
121 | return index.row(); | 106 | return index.row(); | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |