]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* allow to filter the search result by images or text-documents
authorPeter Penz <peter.penz19@gmail.com>
Sat, 12 Dec 2009 05:59:45 +0000 (05:59 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 12 Dec 2009 05:59:45 +0000 (05:59 +0000)
* minor cleanups

svn path=/trunk/KDE/kdebase/apps/; revision=1061550

src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/search/dolphinsearchoptionsconfigurator.cpp
src/search/dolphinsearchoptionsconfigurator.h
src/search/searchcriterionselector.cpp

index 2b7a60e4f216cb6801addfab801111dd7b0b0143..c41d7f9cccba081c8eca51b5e3daa757398d7d75 100644 (file)
@@ -180,6 +180,8 @@ if(Nepomuk_FOUND)
     )
 endif(Nepomuk_FOUND)
 
     )
 endif(Nepomuk_FOUND)
 
+soprano_add_ontology(dolphin_SRCS "${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nfo.trig" "NFO" "Nepomuk::Vocabulary" "trig")
+
 if(NOT WIN32)
    set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalpanel.cpp)
 endif(NOT WIN32)
 if(NOT WIN32)
    set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalpanel.cpp)
 endif(NOT WIN32)
index ebc8dc2683f5106a476328476526de730947555c..7291a1117ddb38acf5b8ed7defdd847127badb9d 100644 (file)
@@ -1011,8 +1011,8 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
 void DolphinMainWindow::searchItems()
 {
 #ifdef HAVE_NEPOMUK
 void DolphinMainWindow::searchItems()
 {
 #ifdef HAVE_NEPOMUK
-    const KUrl nepomukUrl = m_searchOptionsConfigurator->nepomukUrl();
-    m_activeViewContainer->setUrl(nepomukUrl);
+    const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
+    m_activeViewContainer->setUrl(nepomukSearchUrl);
 #endif
 }
 
 #endif
 }
 
index 006ac73028bf875883e1d3996e6035ef81c6cae6..9fd07f6cb73672220622eb5420f7f884aa782139 100644 (file)
 
 #define DISABLE_NEPOMUK_LEGACY
 #include <nepomuk/andterm.h>
 
 #define DISABLE_NEPOMUK_LEGACY
 #include <nepomuk/andterm.h>
-#include <nepomuk/query.h>
+#include <nepomuk/orterm.h>
 #include <nepomuk/queryparser.h>
 #include <nepomuk/queryparser.h>
+#include <nepomuk/resourcetypeterm.h>
 #include <nepomuk/term.h>
 
 #include <nepomuk/term.h>
 
+#include "nfo.h"
+
 #include <kcombobox.h>
 #include <kdialog.h>
 #include <kfileplacesmodel.h>
 #include <kcombobox.h>
 #include <kdialog.h>
 #include <kfileplacesmodel.h>
@@ -111,6 +114,7 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare
     for (unsigned int i = 0; i < sizeof(g_whatItems) / sizeof(SettingsItem); ++i) {
         m_whatBox->addItem(g_whatItems[i].text);
     }
     for (unsigned int i = 0; i < sizeof(g_whatItems) / sizeof(SettingsItem); ++i) {
         m_whatBox->addItem(g_whatItems[i].text);
     }
+    connect(m_whatBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons()));
 
     // add "Add selector" button
     m_addSelectorButton = new QPushButton(this);
 
     // add "Add selector" button
     m_addSelectorButton = new QPushButton(this);
@@ -180,35 +184,16 @@ DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
     SearchSettings::self()->writeConfig();
 }
 
     SearchSettings::self()->writeConfig();
 }
 
-KUrl DolphinSearchOptionsConfigurator::nepomukUrl() const
+KUrl DolphinSearchOptionsConfigurator::nepomukSearchUrl() const
 {
 {
-    Nepomuk::Query::Query query;
-    if (m_criteria.size() == 1) {
-        query.setTerm(m_criteria.first()->queryTerm());
-    } else {
-        Nepomuk::Query::AndTerm andTerm;
-        foreach (const SearchCriterionSelector* criterion, m_criteria) {
-            const Nepomuk::Query::Term term = criterion->queryTerm();
-            andTerm.addSubTerm(term);
-        }
-        query.setTerm(andTerm);
-    }
-
-    Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(m_customSearchQuery);
-    if (customQuery.isValid()) {
-        query.setTerm(Nepomuk::Query::AndTerm(query.term(), customQuery.term()));
-    }
-
-    return query.toSearchUrl();
+    const Nepomuk::Query::Query query = nepomukQuery();
+    return query.isValid() ? query.toSearchUrl() : KUrl();
 }
 
 void DolphinSearchOptionsConfigurator::setCustomSearchQuery(const QString& searchQuery)
 {
     m_customSearchQuery = searchQuery.simplified();
 }
 
 void DolphinSearchOptionsConfigurator::setCustomSearchQuery(const QString& searchQuery)
 {
     m_customSearchQuery = searchQuery.simplified();
-
-    const bool enabled = hasSearchParameters();
-    m_searchButton->setEnabled(enabled);
-    m_saveButton->setEnabled(enabled);
+    updateButtons();
 }
 
 void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
 }
 
 void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
@@ -254,13 +239,6 @@ void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
     addCriterion(selector);
 }
 
     addCriterion(selector);
 }
 
-void DolphinSearchOptionsConfigurator::slotCriterionChanged()
-{
-    const bool enabled = hasSearchParameters();
-    m_searchButton->setEnabled(enabled);
-    m_saveButton->setEnabled(enabled);
-}
-
 void DolphinSearchOptionsConfigurator::removeCriterion()
 {
     SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
 void DolphinSearchOptionsConfigurator::removeCriterion()
 {
     SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
@@ -272,13 +250,7 @@ void DolphinSearchOptionsConfigurator::removeCriterion()
 
     criterion->deleteLater();
 
 
     criterion->deleteLater();
 
-    updateSelectorButton();
-}
-
-void DolphinSearchOptionsConfigurator::updateSelectorButton()
-{
-    const int selectors = m_vBoxLayout->count() - 1;
-    m_addSelectorButton->setEnabled(selectors < 10);
+    updateButtons();
 }
 
 void DolphinSearchOptionsConfigurator::saveQuery()
 }
 
 void DolphinSearchOptionsConfigurator::saveQuery()
@@ -309,32 +281,70 @@ void DolphinSearchOptionsConfigurator::saveQuery()
     dialog->restoreDialogSize(dialogConfig);
     if ((dialog->exec() == QDialog::Accepted) && !lineEdit->text().isEmpty()) {
         KFilePlacesModel* model = DolphinSettings::instance().placesModel();
     dialog->restoreDialogSize(dialogConfig);
     if ((dialog->exec() == QDialog::Accepted) && !lineEdit->text().isEmpty()) {
         KFilePlacesModel* model = DolphinSettings::instance().placesModel();
-        model->addPlace(lineEdit->text(), nepomukUrl());
+        model->addPlace(lineEdit->text(), nepomukSearchUrl());
     }
     delete dialog;
 }
 
     }
     delete dialog;
 }
 
+void DolphinSearchOptionsConfigurator::updateButtons()
+{
+    const bool enable = nepomukQuery().isValid();
+    m_searchButton->setEnabled(enable);
+    m_saveButton->setEnabled(enable);
+
+    const int selectors = m_vBoxLayout->count() - 1;
+    m_addSelectorButton->setEnabled(selectors < 10);
+}
+
 void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
 {
     connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
 void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
 {
     connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
-    connect(criterion, SIGNAL(criterionChanged()), this, SLOT(slotCriterionChanged()));
+    connect(criterion, SIGNAL(criterionChanged()), this, SLOT(updateButtons()));
 
     // insert the new selector before the KSeparator at the bottom
     const int index = m_vBoxLayout->count() - 1;
     m_vBoxLayout->insertWidget(index, criterion);
 
     // insert the new selector before the KSeparator at the bottom
     const int index = m_vBoxLayout->count() - 1;
     m_vBoxLayout->insertWidget(index, criterion);
-    updateSelectorButton();
+    updateButtons();
 
     m_criteria.append(criterion);
 }
 
 
     m_criteria.append(criterion);
 }
 
-bool DolphinSearchOptionsConfigurator::hasSearchParameters() const
+Nepomuk::Query::Query DolphinSearchOptionsConfigurator::nepomukQuery() const
 {
 {
-    if (!m_customSearchQuery.isEmpty()) {
-        // performance optimization: if a custom search query is defined,
-        // there is no need to call the (quite expensive) method nepomukUrl()
-        return true;
+    Nepomuk::Query::AndTerm andTerm;
+
+    // add search criterion terms
+    foreach (const SearchCriterionSelector* criterion, m_criteria) {
+        const Nepomuk::Query::Term term = criterion->queryTerm();
+        andTerm.addSubTerm(term);
+    }
+
+    // add custom query term from the searchbar
+    const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(m_customSearchQuery);
+    if (customQuery.isValid()) {
+        andTerm.addSubTerm(customQuery.term());
+    }
+
+    // filter result by the "What" filter
+    switch (m_whatBox->currentIndex()) {
+    case 1: {
+        // Image
+        const Nepomuk::Query::ResourceTypeTerm image(Nepomuk::Vocabulary::NFO::Image());
+        andTerm.addSubTerm(image);
+        break;
     }
     }
-    return true; //nepomukUrl().path() != QLatin1String("/");
+    case 2: {
+        // Text
+        const Nepomuk::Query::ResourceTypeTerm textDocument(Nepomuk::Vocabulary::NFO::TextDocument());
+        andTerm.addSubTerm(textDocument);
+        break;
+    }
+    default: break;
+    }
+
+    Nepomuk::Query::Query query;
+    query.setTerm(andTerm);
+    return query;
 }
 
 #include "dolphinsearchoptionsconfigurator.moc"
 }
 
 #include "dolphinsearchoptionsconfigurator.moc"
index 338f4cd3f2737fca871fdc01e416581f8c054f7c..90adea7367abf9d48dc4b9b0b4a4dd9c5175b23e 100644 (file)
@@ -21,6 +21,8 @@
 #define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
 
 #include <kurl.h>
 #define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
 
 #include <kurl.h>
+#define DISABLE_NEPOMUK_LEGACY
+#include <nepomuk/query.h>
 #include <QList>
 #include <QString>
 #include <QWidget>
 #include <QList>
 #include <QString>
 #include <QWidget>
@@ -43,10 +45,11 @@ public:
 
     /**
      * Returns the sum of the configured options and the
 
     /**
      * Returns the sum of the configured options and the
-     * custom search query as Nepomuk URL.
+     * custom search query as Nepomuk conform search URL. If the
+     * query is invalid, an empty URL is returned.
      * @see DolphinSearchOptionsConfigurator::setCustomSearchQuery()
      */
      * @see DolphinSearchOptionsConfigurator::setCustomSearchQuery()
      */
-    KUrl nepomukUrl() const;
+    KUrl nepomukSearchUrl() const;
 
 public slots:
     /**
 
 public slots:
     /**
@@ -65,19 +68,18 @@ protected:
 
 private slots:
     void slotAddSelectorButtonClicked();
 
 private slots:
     void slotAddSelectorButtonClicked();
-    void slotCriterionChanged();
     void removeCriterion();
 
     /**
     void removeCriterion();
 
     /**
-     * Updates the 'enabled' property of the selector button
-     * dependent from the number of existing selectors.
+     * Saves the current query by adding it as Places entry.
      */
      */
-    void updateSelectorButton();
+    void saveQuery();
 
     /**
 
     /**
-     * Saves the current query by adding it as Places entry.
+     * Enables the enabled property of the search-, save-button and the
+     * add-selector button.
      */
      */
-    void saveQuery();
+    void updateButtons();
 
 private:
     /**
 
 private:
     /**
@@ -87,10 +89,11 @@ private:
     void addCriterion(SearchCriterionSelector* selector);
 
     /**
     void addCriterion(SearchCriterionSelector* selector);
 
     /**
-     * Returns true, DolphinSearchOptionsConfigurator::nepomukUrl()
-     * contains at least 1 search parameter.
+     * Returns the sum of the configured options and the
+     * custom search query as Nepomuk confrom query.
+     * @see DolphinSearchOptionsConfigurator::setCustomSearchQuery()
      */
      */
-    bool hasSearchParameters() const;
+    Nepomuk::Query::Query nepomukQuery() const;
 
 private:
     bool m_initialized;
 
 private:
     bool m_initialized;
index 641690536f2ec3e891e83b6d89ecd05ae24c869b..4b74a5dc145845655d2890ef0205d286c1c26975 100644 (file)
@@ -38,8 +38,6 @@
 #include <kicon.h>
 #include <klocale.h>
 
 #include <kicon.h>
 #include <klocale.h>
 
-#include <kdebug.h>
-
 SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) :
     QWidget(parent),
     m_layout(0),
 SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) :
     QWidget(parent),
     m_layout(0),
@@ -99,14 +97,9 @@ Nepomuk::Query::Term SearchCriterionSelector::queryTerm() const
         return Nepomuk::Query::Term();
     }
 
         return Nepomuk::Query::Term();
     }
 
-    kDebug() << "identifier:" << descr.identifier();
-    kDebug() << "value:" << m_valueWidget->value();
-    kDebug() << "comp:" << comp.value;
-
     const Nepomuk::Query::ComparisonTerm term(descr.identifier(),
                                               m_valueWidget->value(),
                                               comp.value);
     const Nepomuk::Query::ComparisonTerm term(descr.identifier(),
                                               m_valueWidget->value(),
                                               comp.value);
-    kDebug() << "term: " << term;
     return term;
 }
 
     return term;
 }