+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");
+ }
+}
+
+KUrl PlacesItemModel::createTimelineUrl(const KUrl& url)
+{
+ // TODO: Clarify with the Nepomuk-team whether it makes sense
+ // provide default-timeline-URLs like 'yesterday', 'this month'
+ // and 'last month'.
+ KUrl timelineUrl;
+
+ const QString path = url.pathOrUrl();
+ 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;
+}
+
+KUrl PlacesItemModel::createSearchUrl(const KUrl& url)
+{
+ KUrl searchUrl;
+
+#ifdef HAVE_NEPOMUK
+ const QString path = url.pathOrUrl();
+ if (path.endsWith(QLatin1String("documents"))) {
+ searchUrl = searchUrlForTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Document()));
+ } else if (path.endsWith(QLatin1String("images"))) {
+ searchUrl = searchUrlForTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Image()));
+ } else if (path.endsWith(QLatin1String("audio"))) {
+ searchUrl = searchUrlForTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
+ Nepomuk2::Query::LiteralTerm("audio")));
+ } else if (path.endsWith(QLatin1String("videos"))) {
+ searchUrl = searchUrlForTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
+ Nepomuk2::Query::LiteralTerm("video")));
+ } else {
+ Q_ASSERT(false);
+ }
+#else
+ Q_UNUSED(url);
+#endif
+
+ return searchUrl;
+}
+
+#ifdef HAVE_NEPOMUK
+KUrl PlacesItemModel::searchUrlForTerm(const Nepomuk2::Query::Term& term)
+{
+ const Nepomuk2::Query::FileQuery query(term);
+ return query.toSearchUrl();
+}
+#endif
+