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 238 Lines • ▼ Show 20 Line(s) | 263 | { | |||
270 | 267 | | |||
271 | // Let's put some places in there if it's empty. | 268 | // Let's put some places in there if it's empty. | ||
272 | KBookmarkGroup root = d->bookmarkManager->root(); | 269 | KBookmarkGroup root = d->bookmarkManager->root(); | ||
273 | 270 | | |||
274 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | 271 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | ||
275 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | 272 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | ||
276 | }; | 273 | }; | ||
277 | 274 | | |||
278 | if (root.first().isNull() || !QFile::exists(file)) { | 275 | const static QString fsBookmarks = QStringLiteral("KFile System Bookmarks"); | ||
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 | 276 | | |||
277 | if (root.first().isNull() || !QFile::exists(file)) { | ||||
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(fsBookmarks, QStringLiteral("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(fsBookmarks, QStringLiteral("Desktop")), | ||
293 | QUrl::fromLocalFile(desktopFolder), QStringLiteral("user-desktop")); | 291 | QUrl::fromLocalFile(desktopFolder), QStringLiteral("user-desktop")); | ||
294 | } | 292 | } | ||
295 | const QString documentsFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | 293 | const QString documentsFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | ||
296 | if (QDir(documentsFolder).exists()) { | 294 | if (QDir(documentsFolder).exists()) { | ||
297 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 295 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
298 | I18NC_NOOP("KFile System Bookmarks", "Documents"), | 296 | I18NC_NOOP(fsBookmarks, QStringLiteral("Documents")), | ||
299 | QUrl::fromLocalFile(documentsFolder), QStringLiteral("folder-documents")); | 297 | QUrl::fromLocalFile(documentsFolder), QStringLiteral("folder-documents")); | ||
300 | } | 298 | } | ||
301 | const QString downloadFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | 299 | const QString downloadFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | ||
302 | if (QDir(downloadFolder).exists()) { | 300 | if (QDir(downloadFolder).exists()) { | ||
303 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 301 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
304 | I18NC_NOOP("KFile System Bookmarks", "Downloads"), | 302 | I18NC_NOOP(fsBookmarks, QStringLiteral("Downloads")), | ||
305 | QUrl::fromLocalFile(downloadFolder), QStringLiteral("folder-downloads")); | 303 | QUrl::fromLocalFile(downloadFolder), QStringLiteral("folder-downloads")); | ||
306 | } | 304 | } | ||
307 | 305 | | |||
308 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 306 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
309 | I18NC_NOOP("KFile System Bookmarks", "Network"), | 307 | I18NC_NOOP(fsBookmarks, QStringLiteral("Network")), | ||
310 | QUrl(QStringLiteral("remote:/")), QStringLiteral("folder-network")); | 308 | QUrl(QStringLiteral("remote:/")), QStringLiteral("folder-network")); | ||
311 | 309 | | |||
312 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 310 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
313 | I18NC_NOOP("KFile System Bookmarks", "Trash"), | 311 | I18NC_NOOP(fsBookmarks, QStringLiteral("Trash")), | ||
314 | QUrl(QStringLiteral("trash:/")), QStringLiteral("user-trash")); | 312 | QUrl(QStringLiteral("trash:/")), QStringLiteral("user-trash")); | ||
315 | 313 | | |||
316 | setDefaultMetadataItemForGroup(PlacesType); | 314 | setDefaultMetadataItemForGroup(PlacesType); | ||
317 | setDefaultMetadataItemForGroup(RemoteType); | 315 | setDefaultMetadataItemForGroup(RemoteType); | ||
318 | setDefaultMetadataItemForGroup(DevicesType); | 316 | setDefaultMetadataItemForGroup(DevicesType); | ||
319 | setDefaultMetadataItemForGroup(RemovableDevicesType); | 317 | setDefaultMetadataItemForGroup(RemovableDevicesType); | ||
320 | setDefaultMetadataItemForGroup(TagsType); | 318 | setDefaultMetadataItemForGroup(TagsType); | ||
321 | 319 | | |||
322 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | 320 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | ||
323 | // will always return false, which opening/closing all the time the open/save dialog would case the | 321 | // will always return false, which opening/closing all the time the open/save dialog would case the | ||
324 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | 322 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | ||
325 | d->bookmarkManager->saveAs(file); | 323 | d->bookmarkManager->saveAs(file); | ||
326 | } | 324 | } | ||
327 | 325 | | |||
328 | // Add a Recently Used entry if available (it comes from kio-extras) | 326 | // Add a Recently Used entry if available (it comes from kio-extras) | ||
329 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | 327 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | ||
330 | root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { | 328 | root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { | ||
331 | 329 | | |||
332 | root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); | 330 | root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); | ||
333 | 331 | | |||
334 | KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 332 | KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
335 | I18NC_NOOP("KFile System Bookmarks", "Recent Files"), | 333 | I18NC_NOOP(fsBookmarks, QStringLiteral("Recent Files")), | ||
336 | QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); | 334 | QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); | ||
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(fsBookmarks, QStringLiteral("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 | | |||
354 | // if baloo is enabled, add new urls even if the bookmark file is not empty | 352 | // if baloo is enabled, add new urls even if the bookmark file is not empty | ||
355 | if (d->fileIndexingEnabled && | 353 | if (d->fileIndexingEnabled && | ||
356 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | 354 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | ||
357 | 355 | | |||
358 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | 356 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | ||
359 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 357 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
360 | I18NC_NOOP("KFile System Bookmarks", "Modified Today"), | 358 | I18NC_NOOP(fsBookmarks, QStringLiteral("Modified Today")), | ||
361 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | 359 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | ||
362 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 360 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
363 | I18NC_NOOP("KFile System Bookmarks", "Modified Yesterday"), | 361 | I18NC_NOOP(fsBookmarks, QStringLiteral("Modified Yesterday")), | ||
364 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | 362 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | ||
365 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 363 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
366 | I18NC_NOOP("KFile System Bookmarks", "Documents"), | 364 | I18NC_NOOP(fsBookmarks, QStringLiteral("Documents")), | ||
367 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | 365 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | ||
368 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 366 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
369 | I18NC_NOOP("KFile System Bookmarks", "Images"), | 367 | I18NC_NOOP(fsBookmarks, QStringLiteral("Images")), | ||
370 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | 368 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | ||
371 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 369 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
372 | I18NC_NOOP("KFile System Bookmarks", "Audio"), | 370 | I18NC_NOOP(fsBookmarks, QStringLiteral("Audio")), | ||
373 | QUrl(QStringLiteral("search:/audio")), QStringLiteral("folder-sound")); | 371 | QUrl(QStringLiteral("search:/audio")), QStringLiteral("folder-sound")); | ||
374 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 372 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
375 | I18NC_NOOP("KFile System Bookmarks", "Videos"), | 373 | I18NC_NOOP(fsBookmarks, QStringLiteral("Videos")), | ||
376 | QUrl(QStringLiteral("search:/videos")), QStringLiteral("folder-videos")); | 374 | QUrl(QStringLiteral("search:/videos")), QStringLiteral("folder-videos")); | ||
377 | 375 | | |||
378 | setDefaultMetadataItemForGroup(SearchForType); | 376 | setDefaultMetadataItemForGroup(SearchForType); | ||
379 | setDefaultMetadataItemForGroup(RecentlySavedType); | 377 | setDefaultMetadataItemForGroup(RecentlySavedType); | ||
380 | 378 | | |||
381 | d->bookmarkManager->save(); | 379 | d->bookmarkManager->save(); | ||
382 | } | 380 | } | ||
383 | 381 | | |||
▲ Show 20 Lines • Show All 1001 Lines • Show Last 20 Lines |
This is more commonly written as "static const"