Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesmodel.cpp
| Show First 20 Lines • Show All 242 Lines • ▼ Show 20 Line(s) | 164 | public: | |||
|---|---|---|---|---|---|
| 243 | void _k_reloadBookmarks(); | 243 | void _k_reloadBookmarks(); | ||
| 244 | void _k_storageSetupDone(Solid::ErrorType error, const QVariant &errorData); | 244 | void _k_storageSetupDone(Solid::ErrorType error, const QVariant &errorData); | ||
| 245 | void _k_storageTeardownDone(Solid::ErrorType error, const QVariant &errorData); | 245 | void _k_storageTeardownDone(Solid::ErrorType error, const QVariant &errorData); | ||
| 246 | 246 | | |||
| 247 | private: | 247 | private: | ||
| 248 | bool isBalooUrl(const QUrl &url) const; | 248 | bool isBalooUrl(const QUrl &url) const; | ||
| 249 | }; | 249 | }; | ||
| 250 | 250 | | |||
| 251 | KBookmark KFilePlacesModel::bookmarkForUrl(const QUrl &searchUrl) | ||||
| 252 | { | ||||
| 253 | KBookmarkGroup root = d->bookmarkManager->root(); | ||||
| 254 | KBookmark current = root.first(); | ||||
| 255 | while (!current.isNull()) { | ||||
| 256 | if (current.url() == searchUrl) { | ||||
| 257 | return current; | ||||
| 258 | } | ||||
| 259 | current = root.next(current); | ||||
| 260 | } | ||||
| 261 | return KBookmark(); | ||||
| 262 | } | ||||
| 263 | | ||||
| 251 | KFilePlacesModel::KFilePlacesModel(const QString &alternativeApplicationName, QObject *parent) | 264 | KFilePlacesModel::KFilePlacesModel(const QString &alternativeApplicationName, QObject *parent) | ||
| 252 | : QAbstractItemModel(parent), d(new Private(this)) | 265 | : QAbstractItemModel(parent), d(new Private(this)) | ||
| 253 | { | 266 | { | ||
| 254 | const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/user-places.xbel"); | 267 | const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/user-places.xbel"); | ||
| 255 | d->bookmarkManager = KBookmarkManager::managerForExternalFile(file); | 268 | d->bookmarkManager = KBookmarkManager::managerForExternalFile(file); | ||
| 256 | d->alternativeApplicationName = alternativeApplicationName; | 269 | d->alternativeApplicationName = alternativeApplicationName; | ||
| 257 | 270 | | |||
| 258 | // Let's put some places in there if it's empty. | 271 | // Let's put some places in there if it's empty. | ||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 278 | if (root.first().isNull() || !QFile::exists(file)) { | |||
| 307 | 320 | | |||
| 308 | setDefaultMetadataItemForGroup(PlacesType); | 321 | setDefaultMetadataItemForGroup(PlacesType); | ||
| 309 | setDefaultMetadataItemForGroup(RemoteType); | 322 | setDefaultMetadataItemForGroup(RemoteType); | ||
| 310 | setDefaultMetadataItemForGroup(DevicesType); | 323 | setDefaultMetadataItemForGroup(DevicesType); | ||
| 311 | setDefaultMetadataItemForGroup(RemovableDevicesType); | 324 | setDefaultMetadataItemForGroup(RemovableDevicesType); | ||
| 312 | setDefaultMetadataItemForGroup(TagsType); | 325 | setDefaultMetadataItemForGroup(TagsType); | ||
| 313 | 326 | | |||
| 314 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | 327 | // Force bookmarks to be saved. If on open/save dialog and the bookmarks are not saved, QFile::exists | ||
| 315 | // will always return false, which opening/closing all the time the open/save dialog would case the | 328 | // will always return false, which opening/closing all the time the open/save dialog would case the | ||
meven: Should we add this to existing places settings ?
Like we do with `withBaloo` for instance… | |||||
| 316 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | 329 | // bookmarks to be added once each time, having lots of times each bookmark. (ereslibre) | ||
| 317 | d->bookmarkManager->saveAs(file); | 330 | d->bookmarkManager->saveAs(file); | ||
| 318 | } | 331 | } | ||
| 319 | 332 | | |||
| 333 | // Add a Recently Used entry if available (it comes from kio-extras) | ||||
| 334 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && | ||||
| 335 | root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { | ||||
| 336 | | ||||
| 337 | root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); | ||||
| 338 | | ||||
| 339 | KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||||
| 340 | QStringLiteral("Recent Files"), I18N_NOOP2("KFile System Bookmarks", "Recent Files"), | ||||
| 341 | QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); | ||||
| 342 | | ||||
| 343 | KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||||
| 344 | QStringLiteral("Recent Locations"), I18N_NOOP2("KFile System Bookmarks", "Recent Locations"), | ||||
| 345 | QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); | ||||
| 346 | | ||||
| 347 | setDefaultMetadataItemForGroup(RecentlySavedType); | ||||
| 348 | | ||||
| 349 | // Move The recently used bookmarks below the trash, making it the first element in the Recent group | ||||
| 350 | KBookmark trashBookmark = bookmarkForUrl(QUrl("trash:/")); | ||||
| 351 | if (!trashBookmark.isNull()) { | ||||
| 352 | root.moveBookmark(recentFilesBookmark, trashBookmark); | ||||
| 353 | root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); | ||||
| 354 | } | ||||
| 355 | | ||||
| 356 | d->bookmarkManager->save(); | ||||
| 357 | } | ||||
| 358 | | ||||
| 320 | // if baloo is enabled, add new urls even if the bookmark file is not empty | 359 | // if baloo is enabled, add new urls even if the bookmark file is not empty | ||
| 321 | if (d->fileIndexingEnabled && | 360 | if (d->fileIndexingEnabled && | ||
| 322 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | 361 | root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { | ||
| 323 | 362 | | |||
| 324 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | 363 | root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); | ||
| 325 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 364 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
| 326 | QStringLiteral("Today"), I18N_NOOP2("KFile System Bookmarks", "Today"), | 365 | QStringLiteral("Modified Today"), I18N_NOOP2("KFile System Bookmarks", "Today"), | ||
timeline protocol works on modification date, we should change this to "Modified Today". meven: timeline protocol works on modification date, we should change this to "Modified Today".
It is… | |||||
| 327 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | 366 | QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); | ||
| 328 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 367 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
| 329 | QStringLiteral("Yesterday"), I18N_NOOP2("KFile System Bookmarks", "Yesterday"), | 368 | QStringLiteral("Modified Yesterday"), I18N_NOOP2("KFile System Bookmarks", "Yesterday"), | ||
meven: same here | |||||
| 330 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | 369 | QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); | ||
| 331 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 370 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
| 332 | QStringLiteral("Documents"), I18N_NOOP2("KFile System Bookmarks", "Documents"), | 371 | QStringLiteral("Documents"), I18N_NOOP2("KFile System Bookmarks", "Documents"), | ||
| 333 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | 372 | QUrl(QStringLiteral("search:/documents")), QStringLiteral("folder-text")); | ||
| 334 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 373 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
| 335 | QStringLiteral("Images"), I18N_NOOP2("KFile System Bookmarks", "Images"), | 374 | QStringLiteral("Images"), I18N_NOOP2("KFile System Bookmarks", "Images"), | ||
| 336 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | 375 | QUrl(QStringLiteral("search:/images")), QStringLiteral("folder-images")); | ||
| 337 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | 376 | KFilePlacesItem::createSystemBookmark(d->bookmarkManager, | ||
| ▲ Show 20 Lines • Show All 1013 Lines • Show Last 20 Lines | |||||
Should we add this to existing places settings ?
Like we do with withBaloo for instance, adding it if it was not added before.