]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
Provide default view properties for system-places
[dolphin.git] / src / panels / places / placespanel.cpp
index bc639c0fb6fbee9434088d850d263657096c52c7..0229d3cac23115781d5573177120a1e404d144a6 100644 (file)
 #include <QVBoxLayout>
 #include <QShowEvent>
 
-#ifdef HAVE_NEPOMUK
-    #include <Nepomuk/Query/ComparisonTerm>
-    #include <Nepomuk/Query/LiteralTerm>
-    #include <Nepomuk/Query/Query>
-    #include <Nepomuk/Query/ResourceTypeTerm>
-    #include <Nepomuk/Vocabulary/NFO>
-    #include <Nepomuk/Vocabulary/NIE>
-#endif
-
 PlacesPanel::PlacesPanel(QWidget* parent) :
     Panel(parent),
     m_controller(0),
@@ -117,7 +108,7 @@ void PlacesPanel::slotItemActivated(int index)
 {
     const KUrl url = m_model->data(index).value("url").value<KUrl>();
     if (!url.isEmpty()) {
-        emit placeActivated(convertedUrl(url));
+        emit placeActivated(PlacesItemModel::convertedUrl(url));
     }
 }
 
@@ -125,7 +116,7 @@ void PlacesPanel::slotItemMiddleClicked(int index)
 {
     const KUrl url = m_model->data(index).value("url").value<KUrl>();
     if (!url.isEmpty()) {
-        emit placeMiddleClicked(convertedUrl(url));
+        emit placeMiddleClicked(PlacesItemModel::convertedUrl(url));
     }
 }
 
@@ -217,10 +208,8 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
             editEntry(index);
         } else if (action == removeAction) {
             m_model->removeItem(index);
-            m_model->save();
         } else if (action == hideAction) {
             item->setHidden(hideAction->isChecked());
-            m_model->save();
         } else if (action == openInNewTabAction) {
             const KUrl url = m_model->item(index)->dataValue("url").value<KUrl>();
             emit placeMiddleClicked(url);
@@ -314,17 +303,17 @@ void PlacesPanel::addEntry()
     dialog->setAllowGlobal(true);
     dialog->setUrl(url);
     if (dialog->exec() == QDialog::Accepted) {
-        KStandardItem* item = createStandardItemFromDialog(dialog);
+        PlacesItem* item = m_model->createPlacesItem(dialog->text(), dialog->url(), dialog->icon());
 
         // Insert the item as last item of the corresponding group.
         int i = 0;
-        while (i < m_model->count() && m_model->item(i)->group() != item->group()) {
+        while (i < m_model->count() && m_model->placesItem(i)->group() != item->group()) {
             ++i;
         }
 
         bool inserted = false;
         while (!inserted && i < m_model->count()) {
-            if (m_model->item(i)->group() != item->group()) {
+            if (m_model->placesItem(i)->group() != item->group()) {
                 m_model->insertItem(i, item);
                 inserted = true;
             }
@@ -337,8 +326,6 @@ void PlacesPanel::addEntry()
     }
 
     delete dialog;
-
-    m_model->save();
 }
 
 void PlacesPanel::editEntry(int index)
@@ -352,20 +339,15 @@ void PlacesPanel::editEntry(int index)
     dialog->setUrl(data.value("url").value<KUrl>());
     dialog->setAllowGlobal(true);
     if (dialog->exec() == QDialog::Accepted) {
-        KStandardItem* oldItem = m_model->item(index);
+        PlacesItem* oldItem = m_model->placesItem(index);
         if (oldItem) {
-            KStandardItem* item = createStandardItemFromDialog(dialog);
-            // Although the user might have changed the URL of the item in a way
-            // that another group should be assigned, we still apply the old
-            // group to keep the same position for the item.
-            item->setGroup(oldItem->group());
-            m_model->changeItem(index, item);
+            oldItem->setText(dialog->text());
+            oldItem->setUrl(dialog->url());
+            oldItem->setIcon(dialog->icon());
         }
     }
 
     delete dialog;
-
-    m_model->save();
 }
 
 void PlacesPanel::selectClosestItem()
@@ -377,112 +359,4 @@ void PlacesPanel::selectClosestItem()
     selectionManager->setSelected(index);
 }
 
-KStandardItem* PlacesPanel::createStandardItemFromDialog(PlacesItemEditDialog* dialog) const
-{
-    Q_ASSERT(dialog);
-
-    const KUrl newUrl = dialog->url();
-    KStandardItem* item = new KStandardItem();
-    item->setIcon(dialog->icon());
-    item->setText(dialog->text());
-    item->setDataValue("url", newUrl);
-    item->setGroup(m_model->groupName(newUrl));
-
-    return item;
-}
-
-KUrl PlacesPanel::convertedUrl(const KUrl& url)
-{
-    KUrl newUrl = url;
-    if (url.protocol() == QLatin1String("timeline")) {
-        newUrl = createTimelineUrl(url);
-    } else if (url.protocol() == QLatin1String("search")) {
-        newUrl = createSearchUrl(url);
-    }
-
-    return newUrl;
-}
-
-KUrl PlacesPanel::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("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("thismonth")) {
-        const QDate date = QDate::currentDate();
-        timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
-    } else if (path.endsWith("lastmonth")) {
-        const QDate date = QDate::currentDate().addMonths(-1);
-        timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month());
-    } else {
-        Q_ASSERT(path.endsWith("today"));
-        timelineUrl= url;
-    }
-
-    return timelineUrl;
-}
-
-QString PlacesPanel::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 PlacesPanel::createSearchUrl(const KUrl& url)
-{
-    KUrl searchUrl;
-
-#ifdef HAVE_NEPOMUK
-    const QString path = url.pathOrUrl();
-    if (path.endsWith("documents")) {
-        searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Document()));
-    } else if (path.endsWith("images")) {
-        searchUrl = searchUrlForTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Image()));
-    } else if (path.endsWith("audio")) {
-        searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(),
-                                                                    Nepomuk::Query::LiteralTerm("audio")));
-    } else if (path.endsWith("videos")) {
-        searchUrl = searchUrlForTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(),
-                                                                    Nepomuk::Query::LiteralTerm("video")));
-    } else {
-        Q_ASSERT(false);
-    }
-#else
-    Q_UNUSED(url);
-#endif
-
-    return searchUrl;
-}
-
-#ifdef HAVE_NEPOMUK
-KUrl PlacesPanel::searchUrlForTerm(const Nepomuk::Query::Term& term)
-{
-    const Nepomuk::Query::Query query(term);
-    return query.toSearchUrl();
-}
-#endif
-
 #include "placespanel.moc"