mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 00:11:21 +00:00
* 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:
parent
f5deeadebb
commit
a960935b00
|
@ -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)
|
if(NOT WIN32)
|
||||||
set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalpanel.cpp)
|
set(dolphin_SRCS ${dolphin_SRCS} panels/terminal/terminalpanel.cpp)
|
||||||
endif(NOT WIN32)
|
endif(NOT WIN32)
|
||||||
|
|
|
@ -1011,8 +1011,8 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
|
||||||
void DolphinMainWindow::searchItems()
|
void DolphinMainWindow::searchItems()
|
||||||
{
|
{
|
||||||
#ifdef HAVE_NEPOMUK
|
#ifdef HAVE_NEPOMUK
|
||||||
const KUrl nepomukUrl = m_searchOptionsConfigurator->nepomukUrl();
|
const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
|
||||||
m_activeViewContainer->setUrl(nepomukUrl);
|
m_activeViewContainer->setUrl(nepomukSearchUrl);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,13 @@
|
||||||
|
|
||||||
#define DISABLE_NEPOMUK_LEGACY
|
#define DISABLE_NEPOMUK_LEGACY
|
||||||
#include <nepomuk/andterm.h>
|
#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 <kcombobox.h>
|
||||||
#include <kdialog.h>
|
#include <kdialog.h>
|
||||||
#include <kfileplacesmodel.h>
|
#include <kfileplacesmodel.h>
|
||||||
|
@ -111,6 +114,7 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare
|
||||||
for (unsigned int i = 0; i < sizeof(g_whatItems) / sizeof(SettingsItem); ++i) {
|
for (unsigned int i = 0; i < sizeof(g_whatItems) / sizeof(SettingsItem); ++i) {
|
||||||
m_whatBox->addItem(g_whatItems[i].text);
|
m_whatBox->addItem(g_whatItems[i].text);
|
||||||
}
|
}
|
||||||
|
connect(m_whatBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons()));
|
||||||
|
|
||||||
// add "Add selector" button
|
// add "Add selector" button
|
||||||
m_addSelectorButton = new QPushButton(this);
|
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;
|
const Nepomuk::Query::Query query = nepomukQuery();
|
||||||
if (m_criteria.size() == 1) {
|
return query.isValid() ? query.toSearchUrl() : KUrl();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinSearchOptionsConfigurator::setCustomSearchQuery(const QString& searchQuery)
|
void DolphinSearchOptionsConfigurator::setCustomSearchQuery(const QString& searchQuery)
|
||||||
{
|
{
|
||||||
m_customSearchQuery = searchQuery.simplified();
|
m_customSearchQuery = searchQuery.simplified();
|
||||||
|
updateButtons();
|
||||||
const bool enabled = hasSearchParameters();
|
|
||||||
m_searchButton->setEnabled(enabled);
|
|
||||||
m_saveButton->setEnabled(enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
void DolphinSearchOptionsConfigurator::removeCriterion()
|
||||||
{
|
{
|
||||||
SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
|
SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
|
||||||
|
@ -272,13 +250,7 @@ void DolphinSearchOptionsConfigurator::removeCriterion()
|
||||||
|
|
||||||
criterion->deleteLater();
|
criterion->deleteLater();
|
||||||
|
|
||||||
updateSelectorButton();
|
updateButtons();
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinSearchOptionsConfigurator::updateSelectorButton()
|
|
||||||
{
|
|
||||||
const int selectors = m_vBoxLayout->count() - 1;
|
|
||||||
m_addSelectorButton->setEnabled(selectors < 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinSearchOptionsConfigurator::saveQuery()
|
void DolphinSearchOptionsConfigurator::saveQuery()
|
||||||
|
@ -309,32 +281,70 @@ void DolphinSearchOptionsConfigurator::saveQuery()
|
||||||
dialog->restoreDialogSize(dialogConfig);
|
dialog->restoreDialogSize(dialogConfig);
|
||||||
if ((dialog->exec() == QDialog::Accepted) && !lineEdit->text().isEmpty()) {
|
if ((dialog->exec() == QDialog::Accepted) && !lineEdit->text().isEmpty()) {
|
||||||
KFilePlacesModel* model = DolphinSettings::instance().placesModel();
|
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)
|
void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
|
||||||
{
|
{
|
||||||
connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
|
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
|
// insert the new selector before the KSeparator at the bottom
|
||||||
const int index = m_vBoxLayout->count() - 1;
|
const int index = m_vBoxLayout->count() - 1;
|
||||||
m_vBoxLayout->insertWidget(index, criterion);
|
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()) {
|
Nepomuk::Query::AndTerm andTerm;
|
||||||
// performance optimization: if a custom search query is defined,
|
|
||||||
// there is no need to call the (quite expensive) method nepomukUrl()
|
// add search criterion terms
|
||||||
return true;
|
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"
|
#include "dolphinsearchoptionsconfigurator.moc"
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
|
#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
|
||||||
|
|
||||||
#include <kurl.h>
|
#include <kurl.h>
|
||||||
|
#define DISABLE_NEPOMUK_LEGACY
|
||||||
|
#include <nepomuk/query.h>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QWidget>
|
#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,20 +68,19 @@ protected:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotAddSelectorButtonClicked();
|
void slotAddSelectorButtonClicked();
|
||||||
void slotCriterionChanged();
|
|
||||||
void removeCriterion();
|
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.
|
* Saves the current query by adding it as Places entry.
|
||||||
*/
|
*/
|
||||||
void saveQuery();
|
void saveQuery();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the enabled property of the search-, save-button and the
|
||||||
|
* add-selector button.
|
||||||
|
*/
|
||||||
|
void updateButtons();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Adds the new search description selector to the bottom
|
* Adds the new search description selector to the bottom
|
||||||
|
@ -87,10 +89,11 @@ private:
|
||||||
void addCriterion(SearchCriterionSelector* selector);
|
void addCriterion(SearchCriterionSelector* selector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true, DolphinSearchOptionsConfigurator::nepomukUrl()
|
* Returns the sum of the configured options and the
|
||||||
* contains at least 1 search parameter.
|
* custom search query as Nepomuk confrom query.
|
||||||
|
* @see DolphinSearchOptionsConfigurator::setCustomSearchQuery()
|
||||||
*/
|
*/
|
||||||
bool hasSearchParameters() const;
|
Nepomuk::Query::Query nepomukQuery() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
|
|
|
@ -38,8 +38,6 @@
|
||||||
#include <kicon.h>
|
#include <kicon.h>
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
|
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) :
|
SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
m_layout(0),
|
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(),
|
const Nepomuk::Query::ComparisonTerm term(descr.identifier(),
|
||||||
m_valueWidget->value(),
|
m_valueWidget->value(),
|
||||||
comp.value);
|
comp.value);
|
||||||
kDebug() << "term: " << term;
|
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue