Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesmodel.cpp
Show All 12 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | 18 | | |||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | // TODO: remove me | | |||
22 | #undef QT_NO_CAST_FROM_ASCII | | |||
23 | | ||||
24 | #include "kfileplacesmodel.h" | 21 | #include "kfileplacesmodel.h" | ||
25 | #include "kfileplacesitem_p.h" | 22 | #include "kfileplacesitem_p.h" | ||
26 | 23 | | |||
27 | #ifdef _WIN32_WCE | 24 | #ifdef _WIN32_WCE | ||
28 | #include "Windows.h" | 25 | #include "Windows.h" | ||
29 | #include "WinBase.h" | 26 | #include "WinBase.h" | ||
30 | #endif | 27 | #endif | ||
31 | 28 | | |||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 172 | if(tags.isEmpty()) { | |||
179 | KBookmark bookmark = root.first(); | 176 | KBookmark bookmark = root.first(); | ||
180 | 177 | | |||
181 | while (!bookmark.isNull()) { | 178 | while (!bookmark.isNull()) { | ||
182 | existingBookmarks.append(bookmark.url()); | 179 | existingBookmarks.append(bookmark.url()); | ||
183 | bookmark = root.next(bookmark); | 180 | bookmark = root.next(bookmark); | ||
184 | } | 181 | } | ||
185 | 182 | | |||
186 | if (!existingBookmarks.contains(QUrl(tagsUrlBase))) { | 183 | if (!existingBookmarks.contains(QUrl(tagsUrlBase))) { | ||
187 | KBookmark alltags = KFilePlacesItem::createSystemBookmark(bookmarkManager, QStringLiteral("All tags"), i18n("All tags"), QUrl(tagsUrlBase), QStringLiteral("tag")); | 184 | KBookmark alltags = KFilePlacesItem::createSystemBookmark(bookmarkManager, "All tags" | ||
185 | , i18n("All tags").toUtf8().data() | ||||
186 | , QUrl(tagsUrlBase), QStringLiteral("tag")); | ||||
188 | } | 187 | } | ||
189 | } | 188 | } | ||
190 | 189 | | |||
191 | for (const KFileItem &item: items) { | 190 | for (const KFileItem &item: items) { | ||
192 | const QString name = item.name(); | 191 | const QString name = item.name(); | ||
193 | 192 | | |||
194 | if (!tags.contains(name)) { | 193 | if (!tags.contains(name)) { | ||
195 | tags.append(name); | 194 | tags.append(name); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 265 | { | |||
270 | 269 | | |||
271 | // Let's put some places in there if it's empty. | 270 | // Let's put some places in there if it's empty. | ||
272 | KBookmarkGroup root = d->bookmarkManager->root(); | 271 | KBookmarkGroup root = d->bookmarkManager->root(); | ||
273 | 272 | | |||
274 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | 273 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | ||
275 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | 274 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | ||
276 | }; | 275 | }; | ||
277 | 276 | | |||
278 | if (root.first().isNull() || !QFile::exists(file)) { | 277 | if (root.first().isNull() || !QFile::exists(file)) { | ||
dfaure: This is more commonly written as "static const" | |||||
This does not work. Our translation system cannot extract from something like I18NC_NOOP(fsBookmarks, QStringLiteral("Desktop")) all the strings below with I18NC_NOOP should be left as is. Thanks. yurchor: This does not work. Our translation system cannot extract from something like
I18NC_NOOP… | |||||
dfaure: Oh, right, indeed. Duplication FTW :-) | |||||
ahmadsamir: Fixed (and noted for the future). Thanks. | |||||
279 | | ||||
280 | // NOTE: The context for these I18NC_NOOP calls has to be "KFile System Bookmarks". | 278 | // NOTE: The context for these I18NC_NOOP calls has to be "KFile System Bookmarks". | ||
281 | // The real i18nc call is made later, with this context, so the two must match. | 279 | // The real i18nc call is made later, with this context, so the two must match. | ||
282 | // createSystemBookmark actually does nothing with its second argument, the context, | 280 | // createSystemBookmark actually does nothing with its second argument, the context, | ||
283 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 281 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
284 | I18NC_NOOP("KFile System Bookmarks", "Home"), | 282 | I18NC_NOOP("KFile System Bookmarks", "Home"), | ||
The QStringLiteral here might create trouble for the translation extraction scripts? I think the proper fix is to change the signature of createSystemBookmark to take two QByteArray arguments. Or you could even keep const char* for the context (the first one of the two) since it's dropped, no point in creating a QByteArray out of it. dfaure: The QStringLiteral here might create trouble for the translation extraction scripts?
I think… | |||||
285 | QUrl::fromLocalFile(QDir::homePath()), QStringLiteral("user-home")); | 283 | QUrl::fromLocalFile(QDir::homePath()), QStringLiteral("user-home")); | ||
286 | 284 | | |||
287 | // Some distros may not create various standard XDG folders by default | 285 | // Some distros may not create various standard XDG folders by default | ||
288 | // so check for their existence before adding bookmarks for them | 286 | // so check for their existence before adding bookmarks for them | ||
289 | const QString desktopFolder = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | 287 | const QString desktopFolder = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | ||
290 | if (QDir(desktopFolder).exists()) { | 288 | if (QDir(desktopFolder).exists()) { | ||
291 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 289 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
292 | I18NC_NOOP("KFile System Bookmarks", "Desktop"), | 290 | I18NC_NOOP("KFile System Bookmarks", "Desktop"), | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 327 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | |||
337 | 335 | | |||
338 | KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 336 | KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
339 | I18NC_NOOP("KFile System Bookmarks", "Recent Locations"), | 337 | I18NC_NOOP("KFile System Bookmarks", "Recent Locations"), | ||
340 | QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); | 338 | QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); | ||
341 | 339 | | |||
342 | setDefaultMetadataItemForGroup(RecentlySavedType); | 340 | setDefaultMetadataItemForGroup(RecentlySavedType); | ||
343 | 341 | | |||
344 | // Move The recently used bookmarks below the trash, making it the first element in the Recent group | 342 | // Move The recently used bookmarks below the trash, making it the first element in the Recent group | ||
345 | KBookmark trashBookmark = bookmarkForUrl(QUrl("trash:/")); | 343 | KBookmark trashBookmark = bookmarkForUrl(QUrl(QStringLiteral("trash:/"))); | ||
346 | if (!trashBookmark.isNull()) { | 344 | if (!trashBookmark.isNull()) { | ||
347 | root.moveBookmark(recentFilesBookmark, trashBookmark); | 345 | root.moveBookmark(recentFilesBookmark, trashBookmark); | ||
348 | root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); | 346 | root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); | ||
349 | } | 347 | } | ||
350 | 348 | | |||
351 | d->bookmarkManager->save(); | 349 | d->bookmarkManager->save(); | ||
352 | } | 350 | } | ||
353 | 351 | | |||
▲ Show 20 Lines • Show All 1031 Lines • Show Last 20 Lines |
This is more commonly written as "static const"