+ PlacesItem* shownItem = placesItem(index);
+ if (!shownItem) {
+ return;
+ }
+
+ shownItem->setHidden(true);
+ if (m_hiddenItemsShown) {
+ // Removing items from the model is not allowed if all hidden
+ // items should be shown.
+ return;
+ }
+
+ const int newIndex = bookmarkIndex(index);
+ if (newIndex >= 0) {
+ const KBookmark hiddenBookmark = shownItem->bookmark();
+ PlacesItem* hiddenItem = new PlacesItem(hiddenBookmark);
+
+ const PlacesItem* previousItem = placesItem(index - 1);
+ KBookmark previousBookmark;
+ if (previousItem) {
+ previousBookmark = previousItem->bookmark();
+ }
+
+ const bool updateBookmark = (m_bookmarkManager->root().indexOf(hiddenBookmark) >= 0);
+ removeItem(index);
+
+ if (updateBookmark) {
+ // removeItem() also removed the bookmark from m_bookmarkManager in
+ // PlacesItemModel::onItemRemoved(). However for hidden items the
+ // bookmark should still be remembered, so readd it again:
+ m_bookmarkManager->root().addBookmark(hiddenBookmark);
+ m_bookmarkManager->root().moveBookmark(hiddenBookmark, previousBookmark);
+ triggerBookmarksSaving();
+ }
+
+ m_bookmarkedItems.insert(newIndex, hiddenItem);
+ }
+}
+
+void PlacesItemModel::triggerBookmarksSaving()
+{
+ if (m_saveBookmarksTimer) {
+ m_saveBookmarksTimer->start();
+ }
+}
+
+QString PlacesItemModel::internalMimeType() const
+{
+ return "application/x-dolphinplacesmodel-" +
+ QString::number((qptrdiff)this);
+}
+
+int PlacesItemModel::groupedDropIndex(int index, const PlacesItem* item) const
+{
+ Q_ASSERT(item);
+
+ int dropIndex = index;
+ const PlacesItem::GroupType type = item->groupType();
+
+ const int itemCount = count();
+ if (index < 0) {
+ dropIndex = itemCount;
+ }
+
+ // Search nearest previous item with the same group
+ int previousIndex = -1;
+ for (int i = dropIndex - 1; i >= 0; --i) {
+ if (placesItem(i)->groupType() == type) {
+ previousIndex = i;
+ break;
+ }
+ }
+
+ // Search nearest next item with the same group
+ int nextIndex = -1;
+ for (int i = dropIndex; i < count(); ++i) {
+ if (placesItem(i)->groupType() == type) {
+ nextIndex = i;
+ break;
+ }
+ }
+
+ // Adjust the drop-index to be inserted to the
+ // nearest item with the same group.
+ if (previousIndex >= 0 && nextIndex >= 0) {
+ dropIndex = (dropIndex - previousIndex < nextIndex - dropIndex) ?
+ previousIndex + 1 : nextIndex;
+ } else if (previousIndex >= 0) {
+ dropIndex = previousIndex + 1;
+ } else if (nextIndex >= 0) {
+ dropIndex = nextIndex;
+ }
+
+ return dropIndex;
+}
+
+bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark& b1, const KBookmark& b2)
+{
+ const QString udi1 = b1.metaDataItem("UDI");
+ const QString udi2 = b2.metaDataItem("UDI");
+ if (!udi1.isEmpty() && !udi2.isEmpty()) {
+ return udi1 == udi2;
+ } else {
+ return b1.metaDataItem("ID") == b2.metaDataItem("ID");
+ }
+}
+
+QUrl PlacesItemModel::createTimelineUrl(const QUrl& url)
+{
+ // TODO: Clarify with the Baloo-team whether it makes sense
+ // provide default-timeline-URLs like 'yesterday', 'this month'
+ // and 'last month'.
+ QUrl timelineUrl;
+
+ const QString path = url.toDisplayString(QUrl::PreferLocalFile);
+ if (path.endsWith(QLatin1String("yesterday"))) {
+ const QDate date = QDate::currentDate().addDays(-1);
+ const int year = date.year();
+ const int month = date.month();
+ const int day = date.day();
+ timelineUrl = "timeline:/" + timelineDateString(year, month) +
+ '/' + timelineDateString(year, month, day);
+ } else if (path.endsWith(QLatin1String("thismonth"))) {
+ const QDate date = QDate::currentDate();
+ timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
+ } else if (path.endsWith(QLatin1String("lastmonth"))) {
+ const QDate date = QDate::currentDate().addMonths(-1);
+ timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
+ } else {
+ Q_ASSERT(path.endsWith(QLatin1String("today")));
+ timelineUrl= url;
+ }
+
+ return timelineUrl;
+}
+
+QString PlacesItemModel::timelineDateString(int year, int month, int day)
+{
+ QString date = QString::number(year) + '-';
+ if (month < 10) {
+ date += '0';
+ }
+ date += QString::number(month);
+
+ if (day >= 1) {
+ date += '-';
+ if (day < 10) {
+ date += '0';
+ }
+ date += QString::number(day);
+ }
+
+ return date;