* allow to filter the search result by images or text-documents

* minor cleanups

svn path=/trunk/KDE/kdebase/apps/; revision=1061550
This commit is contained in:
Peter Penz 2009-12-12 05:59:45 +00:00
parent f5deeadebb
commit a960935b00
5 changed files with 76 additions and 68 deletions

View file

@ -180,6 +180,8 @@ if(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)

View file

@ -1011,8 +1011,8 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
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
}

View file

@ -24,10 +24,13 @@
#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>
@ -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);
}
connect(m_whatBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons()));
// add "Add selector" button
m_addSelectorButton = new QPushButton(this);
@ -180,35 +184,16 @@ DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
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)
@ -254,13 +239,6 @@ void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
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());
@ -272,13 +250,7 @@ void DolphinSearchOptionsConfigurator::removeCriterion()
criterion->deleteLater();
updateSelectorButton();
}
void DolphinSearchOptionsConfigurator::updateSelectorButton()
{
const int selectors = m_vBoxLayout->count() - 1;
m_addSelectorButton->setEnabled(selectors < 10);
updateButtons();
}
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();
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);
}
return true; //nepomukUrl().path() != QLatin1String("/");
// 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;
}
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"

View file

@ -21,6 +21,8 @@
#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
#include <kurl.h>
#define DISABLE_NEPOMUK_LEGACY
#include <nepomuk/query.h>
#include <QList>
#include <QString>
#include <QWidget>
@ -43,10 +45,11 @@ public:
/**
* 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:
/**
@ -65,20 +68,19 @@ protected:
private slots:
void slotAddSelectorButtonClicked();
void slotCriterionChanged();
void removeCriterion();
/**
* Updates the 'enabled' property of the selector button
* dependent from the number of existing selectors.
*/
void updateSelectorButton();
/**
* Saves the current query by adding it as Places entry.
*/
void saveQuery();
/**
* Enables the enabled property of the search-, save-button and the
* add-selector button.
*/
void updateButtons();
private:
/**
* Adds the new search description selector to the bottom
@ -87,10 +89,11 @@ 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;

View file

@ -38,8 +38,6 @@
#include <kicon.h>
#include <klocale.h>
#include <kdebug.h>
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();
}
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);
kDebug() << "term: " << term;
return term;
}