Changeset View
Changeset View
Standalone View
Standalone View
src/imagefoldermodel.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 64 | { | |||
---|---|---|---|---|---|
71 | }; | 71 | }; | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | QString ImageFolderModel::url() const | 74 | QString ImageFolderModel::url() const | ||
75 | { | 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(const QString& url) | ||
80 | { | 80 | { | ||
81 | Q_ASSERT( QUrl(url).isLocalFile()); | 81 | Q_ASSERT( QUrl(url).isLocalFile()); | ||
82 | url = QUrl(url).path(); | | |||
83 | 82 | | |||
84 | if (url.isEmpty()) { | 83 | if (url.isEmpty()) { | ||
85 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | 84 | return; | ||
86 | Q_ASSERT(locations.size() > 1); | 85 | } | ||
87 | url = locations.first().append("/"); | 86 | | ||
87 | if (dirLister()->url().path() == QUrl(url).path()) { | ||||
88 | dirLister()->updateDirectory(url); | ||||
89 | return; | ||||
90 | } | ||||
91 | | ||||
92 | beginResetModel(); | ||||
93 | dirLister()->openUrl(url); | ||||
94 | endResetModel(); | ||||
95 | emit urlChanged(); | ||||
96 | } | ||||
97 | | ||||
98 | QString ImageFolderModel::imagePath() const | ||||
99 | { | ||||
100 | return m_imagePath; | ||||
88 | } | 101 | } | ||
89 | 102 | | |||
103 | void ImageFolderModel::setImagePath(QString &url) | ||||
104 | { | ||||
105 | Q_ASSERT( QUrl(url).isLocalFile()); | ||||
106 | | ||||
107 | QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | ||||
108 | | ||||
109 | if(url.isEmpty()) { | ||||
110 | Q_ASSERT(picturesLocations.size() > 1); | ||||
111 | url = QUrl::fromLocalFile(picturesLocations.first().append("/")).toString(); | ||||
112 | } | ||||
113 | | ||||
114 | url = QUrl(url).path(); | ||||
115 | | ||||
90 | QString directoryUrl; | 116 | QString directoryUrl; | ||
117 | QStringList intermediateDirectories; | ||||
91 | 118 | | |||
92 | if( QDir(url).exists()) { | 119 | if( QDir(url).exists()) { | ||
93 | directoryUrl = QUrl::fromLocalFile(url).toString(); | 120 | directoryUrl = QUrl::fromLocalFile(url).toString(); | ||
94 | } else { | 121 | } else { | ||
95 | m_imagePath = url; | 122 | m_imagePath = url; | ||
96 | directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); | 123 | directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); | ||
97 | } | 124 | } | ||
98 | 125 | | |||
99 | if (dirLister()->url().path() == directoryUrl) { | 126 | // builds the logic here to find all the directory urls that it contains | ||
mart: this block should go away | |||||
100 | dirLister()->updateDirectory(QUrl(directoryUrl)); | 127 | if( directoryUrl.startsWith( QUrl::fromLocalFile(picturesLocations.first()).toString()) ) { | ||
101 | return; | 128 | /** | ||
129 | * after this @directoryUrl will now have the part after "~/Pictures/" | ||||
130 | */ | ||||
131 | directoryUrl.remove( QUrl::fromLocalFile(picturesLocations.first()).toString() ); | ||||
132 | intermediateDirectories = directoryUrl.split('/', QString::SkipEmptyParts); | ||||
133 | directoryUrl = QUrl::fromLocalFile(picturesLocations.first()).toString().append('/'); | ||||
102 | } | 134 | } | ||
135 | m_intermediateUrls.append(directoryUrl); | ||||
136 | setUrl(directoryUrl); // settting the first column of pageStack to ~/Pictures | ||||
103 | 137 | | |||
104 | beginResetModel(); | 138 | foreach( QString intermediateDirectory, intermediateDirectories) { | ||
105 | dirLister()->openUrl(QUrl(directoryUrl)); | 139 | directoryUrl.append( intermediateDirectory.append('/') ); | ||
106 | endResetModel(); | 140 | m_intermediateUrls.append(directoryUrl); | ||
107 | emit urlChanged(); | 141 | } | ||
142 | emit intermediateUrlsChanged(); | ||||
143 | } | ||||
144 | | ||||
145 | QStringList ImageFolderModel::intermediateUrls() const | ||||
146 | { | ||||
147 | return m_intermediateUrls; | ||||
108 | } | 148 | } | ||
109 | 149 | | |||
110 | int ImageFolderModel::indexForUrl(const QString &url) const | 150 | int ImageFolderModel::indexForUrl(const QString &url) const | ||
111 | { | 151 | { | ||
112 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | 152 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | ||
113 | return index.row(); | 153 | return index.row(); | ||
114 | } | 154 | } | ||
115 | 155 | | |||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
this block should go away