#define DISABLE_NEPOMUK_LEGACY
#include <nepomuk/andterm.h>
-#include <nepomuk/query.h>
+#include <nepomuk/orterm.h>
#include <nepomuk/queryparser.h>
+#include <nepomuk/resourcetypeterm.h>
#include <nepomuk/term.h>
+#include "nfo.h"
+
#include <kcombobox.h>
#include <kdialog.h>
#include <kfileplacesmodel.h>
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);
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();
-
- const bool enabled = hasSearchParameters();
- m_searchButton->setEnabled(enabled);
- m_saveButton->setEnabled(enabled);
+ updateButtons();
}
void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
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());
criterion->deleteLater();
- updateSelectorButton();
-}
-
-void DolphinSearchOptionsConfigurator::updateSelectorButton()
-{
- const int selectors = m_vBoxLayout->count() - 1;
- m_addSelectorButton->setEnabled(selectors < 10);
+ updateButtons();
}
void DolphinSearchOptionsConfigurator::saveQuery()
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;
}
+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()));
- 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);
- updateSelectorButton();
+ updateButtons();
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"
#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
#include <kurl.h>
+#define DISABLE_NEPOMUK_LEGACY
+#include <nepomuk/query.h>
#include <QList>
#include <QString>
#include <QWidget>
/**
* 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()
*/
- KUrl nepomukUrl() const;
+ KUrl nepomukSearchUrl() const;
public slots:
/**
private slots:
void slotAddSelectorButtonClicked();
- void slotCriterionChanged();
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:
/**
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;