+void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
+{
+ connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ 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);
+ updateButtons();
+
+ m_criteria.append(criterion);
+}
+
+Nepomuk::Query::Query DolphinSearchOptionsConfigurator::nepomukQuery() const
+{
+ Nepomuk::Query::AndTerm andTerm;
+
+ // add search criterion terms
+ foreach (const SearchCriterionSelector* criterion, m_criteria) {
+ const Nepomuk::Query::Term term = criterion->queryTerm();
+ andTerm.addSubTerm(term);
+ }
+
+ bool addCustomQuery = true;
+
+ // 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;
+ }
+ case 2: {
+ // Text
+ const Nepomuk::Query::ResourceTypeTerm textDocument(Nepomuk::Vocabulary::NFO::TextDocument());
+ andTerm.addSubTerm(textDocument);
+ break;
+ }
+ case 3: {
+ // Filenames
+ // trueg: Restriction to filename differs a bit from restriction to a type of file since it does not add a condition
+ // on the query but influences the text edited in the search bar directly.
+ // This is a bit tricky as we need to use the search bar text as plain text value for filename searches
+ // We do it the ugly way assuming the user only entered a literal value.
+ Nepomuk::Query::ComparisonTerm filenameTerm(Nepomuk::Vocabulary::NFO::fileName(), Nepomuk::Query::LiteralTerm(m_customSearchQuery));
+ andTerm.addSubTerm(filenameTerm);
+ addCustomQuery = false;
+ }
+ default: break;
+ }
+
+ if (addCustomQuery) {
+ // 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());
+ }
+ }
+
+ Nepomuk::Query::FileQuery fileQuery;
+ fileQuery.setFileMode( Nepomuk::Query::FileQuery::QueryFiles );
+ fileQuery.setTerm(andTerm);
+
+ if ((m_locationBox->currentIndex() == 1) && m_directory.isValid()) {
+ // "From Here" is selected as location filter
+ fileQuery.addIncludeFolder(m_directory);
+ }
+
+ return fileQuery;
+}
+