Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesmodel.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Line(s) | 266 | { | |||
---|---|---|---|---|---|
272 | KBookmarkGroup root = d->bookmarkManager->root(); | 272 | KBookmarkGroup root = d->bookmarkManager->root(); | ||
273 | 273 | | |||
274 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | 274 | const auto setDefaultMetadataItemForGroup = [&root](KFilePlacesModel::GroupType type) { | ||
275 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | 275 | root.setMetaDataItem(stateNameForGroupType(type), QStringLiteral("false")); | ||
276 | }; | 276 | }; | ||
277 | 277 | | |||
278 | if (root.first().isNull() || !QFile::exists(file)) { | 278 | if (root.first().isNull() || !QFile::exists(file)) { | ||
279 | 279 | | |||
280 | // NOTE: The context for these I18N_NOOP2 calls has to be "KFile System Bookmarks". | 280 | // 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. | 281 | // The real i18nc call is made later, with this context, so the two must match. | ||
282 | // | 282 | // createSystemBookmark actually does nothing with its second argument, the context, | ||
283 | // createSystemBookmark actually does nothing with its third argument, | | |||
284 | // but we have to give it something so the I18N_NOOP2 calls stay here for now. | | |||
285 | // | | |||
286 | // (coles, 13th May 2009) | | |||
287 | | ||||
288 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 283 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
289 | QStringLiteral("Home"), I18N_NOOP2("KFile System Bookmarks", "Home"), | 284 | I18NC_NOOP("KFile System Bookmarks", "Home"), | ||
290 | QUrl::fromLocalFile(QDir::homePath()), QStringLiteral("user-home")); | 285 | QUrl::fromLocalFile(QDir::homePath()), QStringLiteral("user-home")); | ||
291 | 286 | | |||
292 | // Some distros may not create various standard XDG folders by default | 287 | // Some distros may not create various standard XDG folders by default | ||
293 | // so check for their existence before adding bookmarks for them | 288 | // so check for their existence before adding bookmarks for them | ||
294 | const QString desktopFolder = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | 289 | const QString desktopFolder = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | ||
295 | if (QDir(desktopFolder).exists()) { | 290 | if (QDir(desktopFolder).exists()) { | ||
296 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 291 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
297 | QStringLiteral("Desktop"), I18N_NOOP2("KFile System Bookmarks", "Desktop"), | 292 | I18NC_NOOP("KFile System Bookmarks", "Desktop"), | ||
298 | QUrl::fromLocalFile(desktopFolder), QStringLiteral("user-desktop")); | 293 | QUrl::fromLocalFile(desktopFolder), QStringLiteral("user-desktop")); | ||
299 | } | 294 | } | ||
300 | const QString documentsFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | 295 | const QString documentsFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | ||
301 | if (QDir(documentsFolder).exists()) { | 296 | if (QDir(documentsFolder).exists()) { | ||
302 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 297 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
303 | QStringLiteral("Documents"), I18N_NOOP2("KFile System Bookmarks", "Documents"), | 298 | I18NC_NOOP("KFile System Bookmarks", "Documents"), | ||
304 | QUrl::fromLocalFile(documentsFolder), QStringLiteral("folder-documents")); | 299 | QUrl::fromLocalFile(documentsFolder), QStringLiteral("folder-documents")); | ||
305 | } | 300 | } | ||
306 | const QString downloadFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | 301 | const QString downloadFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | ||
307 | if (QDir(downloadFolder).exists()) { | 302 | if (QDir(downloadFolder).exists()) { | ||
308 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 303 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
309 | QStringLiteral("Downloads"), I18N_NOOP2("KFile System Bookmarks", "Downloads"), | 304 | I18NC_NOOP("KFile System Bookmarks", "Downloads"), | ||
310 | QUrl::fromLocalFile(downloadFolder), QStringLiteral("folder-downloads")); | 305 | QUrl::fromLocalFile(downloadFolder), QStringLiteral("folder-downloads")); | ||
311 | } | 306 | } | ||
312 | 307 | | |||
313 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 308 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
314 | QStringLiteral("Network"), I18N_NOOP2("KFile System Bookmarks", "Network"), | 309 | I18NC_NOOP("KFile System Bookmarks", "Network"), | ||
315 | QUrl(QStringLiteral("remote:/")), QStringLiteral("folder-network")); | 310 | QUrl(QStringLiteral("remote:/")), QStringLiteral("folder-network")); | ||
316 | 311 | | |||
317 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 312 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
318 | QStringLiteral("Trash"), I18N_NOOP2("KFile System Bookmarks", "Trash"), | 313 | I18NC_NOOP("KFile System Bookmarks", "Trash"), | ||
319 | QUrl(QStringLiteral("trash:/")), QStringLiteral("user-trash")); | 314 | QUrl(QStringLiteral("trash:/")), QStringLiteral("user-trash")); | ||
320 | 315 | | |||
321 | setDefaultMetadataItemForGroup(PlacesType); | 316 | setDefaultMetadataItemForGroup(PlacesType); | ||
322 | setDefaultMetadataItemForGroup(RemoteType); | 317 | setDefaultMetadataItemForGroup(RemoteType); | ||
323 | setDefaultMetadataItemForGroup(DevicesType); | 318 | setDefaultMetadataItemForGroup(DevicesType); | ||
324 | setDefaultMetadataItemForGroup(RemovableDevicesType); | 319 | setDefaultMetadataItemForGroup(RemovableDevicesType); | ||
325 | setDefaultMetadataItemForGroup(TagsType); | 320 | setDefaultMetadataItemForGroup(TagsType); | ||
326 | 321 | | |||
327 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | 322 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | ||
328 | // will always return false, which opening/closing all the time the open/save dialog would case the | 323 | // will always return false, which opening/closing all the time the open/save dialog would case the | ||
329 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | 324 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | ||
330 | d->bookmarkManager->saveAs(file); | 325 | d->bookmarkManager->saveAs(file); | ||
331 | } | 326 | } | ||
332 | 327 | | |||
333 | // Add a Recently Used entry if available (it comes from kio-extras) | 328 | // Add a Recently Used entry if available (it comes from kio-extras) | ||
334 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | 329 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | ||
335 | root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { | 330 | root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { | ||
336 | 331 | | |||
337 | root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); | 332 | root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); | ||
338 | 333 | | |||
339 | KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 334 | KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
340 | QStringLiteral("Recent Files"), I18N_NOOP2("KFile System Bookmarks", "Recent Files"), | 335 | I18NC_NOOP("KFile System Bookmarks", "Recent Files"), | ||
341 | QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); | 336 | QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); | ||
342 | 337 | | |||
343 | KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 338 | KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
344 | QStringLiteral("Recent Locations"), I18N_NOOP2("KFile System Bookmarks", "Recent Locations"), | 339 | I18NC_NOOP("KFile System Bookmarks", "Recent Locations"), | ||
345 | QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); | 340 | QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); | ||
346 | 341 | | |||
347 | setDefaultMetadataItemForGroup(RecentlySavedType); | 342 | setDefaultMetadataItemForGroup(RecentlySavedType); | ||
348 | 343 | | |||
349 | // Move The recently used bookmarks below the trash, making it the first element in the Recent group | 344 | // Move The recently used bookmarks below the trash, making it the first element in the Recent group | ||
350 | KBookmark trashBookmark = bookmarkForUrl(QUrl("trash:/")); | 345 | KBookmark trashBookmark = bookmarkForUrl(QUrl("trash:/")); | ||
351 | if (!trashBookmark.isNull()) { | 346 | if (!trashBookmark.isNull()) { | ||
352 | root.moveBookmark(recentFilesBookmark, trashBookmark); | 347 | root.moveBookmark(recentFilesBookmark, trashBookmark); | ||
353 | root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); | 348 | root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); | ||
354 | } | 349 | } | ||
355 | 350 | | |||
356 | d->bookmarkManager->save(); | 351 | d->bookmarkManager->save(); | ||
357 | } | 352 | } | ||
358 | 353 | | |||
359 | // if baloo is enabled, add new urls even if the bookmark file is not empty | 354 | // if baloo is enabled, add new urls even if the bookmark file is not empty | ||
360 | if (d->fileIndexingEnabled && | 355 | if (d->fileIndexingEnabled && | ||
361 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | 356 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | ||
362 | 357 | | |||
363 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | 358 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | ||
364 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 359 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
365 | QStringLiteral("Modified Today"), I18N_NOOP2("KFile System Bookmarks", "Today"), | 360 | I18NC_NOOP("KFile System Bookmarks", "Modified Today"), | ||
366 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | 361 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | ||
367 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 362 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
368 | QStringLiteral("Modified Yesterday"), I18N_NOOP2("KFile System Bookmarks", "Yesterday"), | 363 | I18NC_NOOP("KFile System Bookmarks", "Modified Yesterday"), | ||
369 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | 364 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | ||
370 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 365 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
371 | QStringLiteral("Documents"), I18N_NOOP2("KFile System Bookmarks", "Documents"), | 366 | I18NC_NOOP("KFile System Bookmarks", "Documents"), | ||
372 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | 367 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | ||
373 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 368 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
374 | QStringLiteral("Images"), I18N_NOOP2("KFile System Bookmarks", "Images"), | 369 | I18NC_NOOP("KFile System Bookmarks", "Images"), | ||
375 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | 370 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | ||
376 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 371 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
377 | QStringLiteral("Audio"), I18N_NOOP2("KFile System Bookmarks", "Audio"), | 372 | I18NC_NOOP("KFile System Bookmarks", "Audio"), | ||
378 | QUrl(QStringLiteral("search:/audio")), QStringLiteral("folder-sound")); | 373 | QUrl(QStringLiteral("search:/audio")), QStringLiteral("folder-sound")); | ||
379 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 374 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
380 | QStringLiteral("Videos"), I18N_NOOP2("KFile System Bookmarks", "Videos"), | 375 | I18NC_NOOP("KFile System Bookmarks", "Videos"), | ||
381 | QUrl(QStringLiteral("search:/videos")), QStringLiteral("folder-videos")); | 376 | QUrl(QStringLiteral("search:/videos")), QStringLiteral("folder-videos")); | ||
382 | 377 | | |||
383 | setDefaultMetadataItemForGroup(SearchForType); | 378 | setDefaultMetadataItemForGroup(SearchForType); | ||
384 | setDefaultMetadataItemForGroup(RecentlySavedType); | 379 | setDefaultMetadataItemForGroup(RecentlySavedType); | ||
385 | 380 | | |||
386 | d->bookmarkManager->save(); | 381 | d->bookmarkManager->save(); | ||
387 | } | 382 | } | ||
388 | 383 | | |||
▲ Show 20 Lines • Show All 1001 Lines • Show Last 20 Lines |