m_searchBox = new DolphinSearchBox(this);
m_searchBox->hide();
connect(m_searchBox, SIGNAL(closeRequest()), this, SLOT(closeSearchBox()));
- connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(startSearching(QString)));
+ connect(m_searchBox, SIGNAL(searchRequest()), this, SLOT(startSearching()));
connect(m_searchBox, SIGNAL(returnPressed(QString)), this, SLOT(requestFocus()));
m_messageWidget = new KMessageWidget(this);
}
}
-void DolphinViewContainer::startSearching(const QString &text)
+void DolphinViewContainer::startSearching()
{
- Q_UNUSED(text);
const KUrl url = m_searchBox->urlForSearching();
if (url.isValid() && !url.isEmpty()) {
m_urlNavigator->setLocationUrl(url);
/**
* Gets the search URL from the searchbox and starts searching.
- * @param text Text the user has entered into the searchbox.
*/
- void startSearching(const QString& text);
+ void startSearching();
void closeSearchBox();
/**
#include "dolphinfacetswidget.h"
#include <KLocale>
+#include <QButtonGroup>
#include <QCheckBox>
+#include <QDate>
#include <QRadioButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
+#ifdef HAVE_NEPOMUK
+ #include <Nepomuk/Query/AndTerm>
+ #include <Nepomuk/Query/ComparisonTerm>
+ #include <Nepomuk/Query/LiteralTerm>
+ #include <Nepomuk/Query/OrTerm>
+ #include <Nepomuk/Query/Query>
+ #include <Nepomuk/Query/ResourceTypeTerm>
+ #include <Nepomuk/Vocabulary/NFO>
+ #include <Nepomuk/Vocabulary/NIE>
+ #include <Soprano/Vocabulary/NAO>
+#endif
+
DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) :
QWidget(parent),
m_documents(0),
m_fourOrMore(0),
m_maxRating(0)
{
- m_documents = new QCheckBox(i18nc("@option:check", "Documents"));
- m_images = new QCheckBox(i18nc("@option:check", "Images"));
- m_audio = new QCheckBox(i18nc("@option:check", "Audio"));
- m_videos = new QCheckBox(i18nc("@option:check", "Videos"));
+ m_documents = createCheckBox(i18nc("@option:check", "Documents"));
+ m_images = createCheckBox(i18nc("@option:check", "Images"));
+ m_audio = createCheckBox(i18nc("@option:check", "Audio"));
+ m_videos = createCheckBox(i18nc("@option:check", "Videos"));
QVBoxLayout* typeLayout = new QVBoxLayout();
typeLayout->setSpacing(0);
typeLayout->addWidget(m_videos);
typeLayout->addStretch();
- m_anytime = new QRadioButton(i18nc("@option:option", "Anytime"));
- m_today = new QRadioButton(i18nc("@option:option", "Today"));
- m_yesterday = new QRadioButton(i18nc("@option:option", "Yesterday"));
- m_thisWeek = new QRadioButton(i18nc("@option:option", "This Week"));
- m_thisMonth = new QRadioButton(i18nc("@option:option", "This Month"));
- m_thisYear = new QRadioButton(i18nc("@option:option", "This Year"));
+ QButtonGroup* timespanGroup = new QButtonGroup(this);
+ m_anytime = createRadioButton(i18nc("@option:option", "Anytime"), timespanGroup);
+ m_today = createRadioButton(i18nc("@option:option", "Today"), timespanGroup);
+ m_yesterday = createRadioButton(i18nc("@option:option", "Yesterday"), timespanGroup);
+ m_thisWeek = createRadioButton(i18nc("@option:option", "This Week"), timespanGroup);
+ m_thisMonth = createRadioButton(i18nc("@option:option", "This Month"), timespanGroup);
+ m_thisYear = createRadioButton(i18nc("@option:option", "This Year"), timespanGroup);
QVBoxLayout* timespanLayout = new QVBoxLayout();
timespanLayout->setSpacing(0);
timespanLayout->addWidget(m_thisYear);
timespanLayout->addStretch();
- m_anyRating = new QRadioButton(i18nc("@option:option", "Any Rating"));
- m_oneOrMore = new QRadioButton(i18nc("@option:option", "1 or more"));
- m_twoOrMore = new QRadioButton(i18nc("@option:option", "2 or more"));
- m_threeOrMore = new QRadioButton(i18nc("@option:option", "3 or more"));
- m_fourOrMore = new QRadioButton(i18nc("@option:option", "4 or more"));
- m_maxRating = new QRadioButton(i18nc("@option:option", "Maximum Rating"));
+ QButtonGroup* ratingGroup = new QButtonGroup(this);
+ m_anyRating = createRadioButton(i18nc("@option:option", "Any Rating"), ratingGroup);
+ m_oneOrMore = createRadioButton(i18nc("@option:option", "1 or more"), ratingGroup);
+ m_twoOrMore = createRadioButton(i18nc("@option:option", "2 or more"), ratingGroup);
+ m_threeOrMore = createRadioButton(i18nc("@option:option", "3 or more"), ratingGroup);
+ m_fourOrMore = createRadioButton(i18nc("@option:option", "4 or more"), ratingGroup);
+ m_maxRating = createRadioButton(i18nc("@option:option", "Maximum Rating"), ratingGroup);
QVBoxLayout* ratingLayout = new QVBoxLayout();
ratingLayout->setSpacing(0);
topLayout->addLayout(ratingLayout);
topLayout->addStretch();
- // TODO:
m_anytime->setChecked(true);
m_anyRating->setChecked(true);
}
{
}
+#ifdef HAVE_NEPOMUK
+Nepomuk::Query::Term DolphinFacetsWidget::facetsTerm() const
+{
+ Nepomuk::Query::AndTerm andTerm;
+
+ const bool hasTypeFilter = m_documents->isChecked() ||
+ m_images->isChecked() ||
+ m_audio->isChecked() ||
+ m_videos->isChecked();
+ if (hasTypeFilter) {
+ Nepomuk::Query::OrTerm orTerm;
+
+ if (m_documents->isChecked()) {
+ orTerm.addSubTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Document()));
+ }
+
+ if (m_images->isChecked()) {
+ orTerm.addSubTerm(Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::Image()));
+ }
+
+ if (m_audio->isChecked()) {
+ orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(),
+ Nepomuk::Query::LiteralTerm("audio")));
+ }
+
+ if (m_videos->isChecked()) {
+ orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(),
+ Nepomuk::Query::LiteralTerm("video")));
+ }
+
+ andTerm.addSubTerm(orTerm);
+ }
+
+ if (!m_anyRating->isChecked()) {
+ int stars = 1; // represents m_oneOrMore
+ if (m_twoOrMore->isChecked()) {
+ stars = 2;
+ } else if (m_threeOrMore->isChecked()) {
+ stars = 3;
+ } else if (m_fourOrMore->isChecked()) {
+ stars = 4;
+ } else if (m_maxRating->isChecked()) {
+ stars = 5;
+ }
+
+ const int rating = stars * 2;
+ Nepomuk::Query::ComparisonTerm term(Soprano::Vocabulary::NAO::numericRating(),
+ Nepomuk::Query::LiteralTerm(rating),
+ Nepomuk::Query::ComparisonTerm::GreaterOrEqual);
+ andTerm.addSubTerm(term);
+ }
+
+ if (!m_anytime->isChecked()) {
+ QDate date = QDate::currentDate(); // represents m_today
+ if (m_yesterday->isChecked()) {
+ date.addDays(-1);
+ } else if (m_thisWeek->isChecked()) {
+ date.addDays(1 - date.dayOfWeek());
+ } else if (m_thisMonth->isChecked()) {
+ date.addDays(1 - date.day());
+ } else if (m_thisYear->isChecked()) {
+ date.addDays(1 - date.dayOfYear());
+ }
+
+ Nepomuk::Query::ComparisonTerm term(Nepomuk::Vocabulary::NIE::lastModified(),
+ Nepomuk::Query::LiteralTerm(QDateTime(date)),
+ Nepomuk::Query::ComparisonTerm::GreaterOrEqual);
+ andTerm.addSubTerm(term);
+ }
+
+ return andTerm;
+}
+#endif
+
+QCheckBox* DolphinFacetsWidget::createCheckBox(const QString& text)
+{
+ QCheckBox* checkBox = new QCheckBox(text);
+ connect(checkBox, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
+ return checkBox;
+}
+
+QRadioButton* DolphinFacetsWidget::createRadioButton(const QString& text,
+ QButtonGroup* group)
+{
+ QRadioButton* button = new QRadioButton(text);
+ connect(button, SIGNAL(clicked()), this, SIGNAL(facetChanged()));
+ group->addButton(button);
+ return button;
+}
+
#include "dolphinfacetswidget.moc"
#include <QWidget>
+#include <config-nepomuk.h>
+#ifdef HAVE_NEPOMUK
+ #include <Nepomuk/Query/Term>
+#endif
+
+class QButtonGroup;
class QCheckBox;
class QRadioButton;
* @brief Allows to filter search-queries by facets.
*
* TODO: The current implementation is a temporary
- * workaround for the 4.10 release and represents no
+ * workaround for the 4.9 release and represents no
* real facets-implementation yet: There have been
* some Dolphin specific user-interface and interaction
* issues since 4.6 by embedding the Nepomuk facet-widget
explicit DolphinFacetsWidget(QWidget* parent = 0);
virtual ~DolphinFacetsWidget();
+#ifdef HAVE_NEPOMUK
+ Nepomuk::Query::Term facetsTerm() const;
+#endif
+
+signals:
+ void facetChanged();
+
+private:
+ /**
+ * @return New checkbox which is connected to the
+ * slotFacedChanged() slot whenever it has
+ * been toggled.
+ */
+ QCheckBox* createCheckBox(const QString& text);
+
+ /**
+ * @return New radiobutton which is connected to the
+ * slotFacedChanged() slot whenever it has
+ * been toggled.
+ */
+ QRadioButton* createRadioButton(const QString& text,
+ QButtonGroup* group);
+
private:
QCheckBox* m_documents;
QCheckBox* m_images;
#include <config-nepomuk.h>
#ifdef HAVE_NEPOMUK
+ #include <Nepomuk/Query/AndTerm>
#include <Nepomuk/Query/FileQuery>
#include <Nepomuk/Query/LiteralTerm>
#include <Nepomuk/Query/OrTerm>
}
}
-void DolphinSearchBox::emitSearchSignal()
+void DolphinSearchBox::emitSearchRequest()
{
m_startSearchTimer->stop();
m_startedSearching = true;
- emit search(m_searchInput->text());
+ emit searchRequest();
}
-void DolphinSearchBox::slotSearchLocationChanged()
+void DolphinSearchBox::emitCloseRequest()
{
- emit searchLocationChanged(m_fromHereButton->isChecked() ? SearchFromHere : SearchEverywhere);
-}
-
-void DolphinSearchBox::slotSearchContextChanged()
-{
- emit searchContextChanged(m_fileNameButton->isChecked() ? SearchFileName : SearchContent);
+ m_startSearchTimer->stop();
+ m_startedSearching = false;
+ emit closeRequest();
}
void DolphinSearchBox::slotConfigurationChanged()
{
saveSettings();
if (m_startedSearching) {
- emitSearchSignal();
+ emitSearchRequest();
}
}
void DolphinSearchBox::slotSearchTextChanged(const QString& text)
{
- m_startSearchTimer->start();
+ if (text.isEmpty()) {
+ m_startSearchTimer->stop();
+ } else {
+ m_startSearchTimer->start();
+ }
emit searchTextChanged(text);
}
void DolphinSearchBox::slotReturnPressed(const QString& text)
{
- emitSearchSignal();
+ emitSearchRequest();
emit returnPressed(text);
}
updateFacetsToggleButtonIcon();
}
+void DolphinSearchBox::slotFacetChanged()
+{
+ m_startedSearching = true;
+ m_startSearchTimer->stop();
+ emit searchRequest();
+}
+
void DolphinSearchBox::initButton(QToolButton* button)
{
button->setAutoExclusive(true);
closeButton->setAutoRaise(true);
closeButton->setIcon(KIcon("dialog-close"));
closeButton->setToolTip(i18nc("@info:tooltip", "Quit searching"));
- connect(closeButton, SIGNAL(clicked()), SIGNAL(closeRequest()));
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(emitCloseRequest()));
// Create search label
m_searchLabel = new QLabel(this);
QButtonGroup* searchLocationGroup = new QButtonGroup(this);
searchLocationGroup->addButton(m_fromHereButton);
searchLocationGroup->addButton(m_everywhereButton);
- connect(m_fromHereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged()));
- connect(m_everywhereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged()));
// Create "Facets" widgets
m_facetsToggleButton = new QToolButton(this);
m_facetsWidget = new DolphinFacetsWidget(this);
m_facetsWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+ connect(m_facetsWidget, SIGNAL(facetChanged()), this, SLOT(slotFacetChanged()));
// Apply layout for the options
QHBoxLayout* optionsLayout = new QHBoxLayout();
m_startSearchTimer = new QTimer(this);
m_startSearchTimer->setSingleShot(true);
m_startSearchTimer->setInterval(1000);
- connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal()));
+ connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchRequest()));
updateFacetsToggleButtonIcon();
applyReadOnlyState();
KUrl DolphinSearchBox::nepomukUrlForSearching() const
{
#ifdef HAVE_NEPOMUK
- Nepomuk::Query::Term term;
-
+ // Create the term for the text from the input-field
+ // dependent on whether a searching for content or
+ // filename is done
const QString text = m_searchInput->text();
-
+ Nepomuk::Query::Term searchLabelTerm;
if (m_contentButton->isChecked()) {
// Let Nepomuk parse the query
- term = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern).term();
- }
- else {
+ searchLabelTerm = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern).term();
+ } else {
// Search the text in the filename only
QString regex = QRegExp::escape(text);
regex.replace("\\*", QLatin1String(".*"));
regex.replace("\\?", QLatin1String("."));
regex.replace("\\", "\\\\");
- term = Nepomuk::Query::ComparisonTerm(
- Nepomuk::Vocabulary::NFO::fileName(),
- Nepomuk::Query::LiteralTerm(regex),
- Nepomuk::Query::ComparisonTerm::Regexp);
+ searchLabelTerm = Nepomuk::Query::ComparisonTerm(
+ Nepomuk::Vocabulary::NFO::fileName(),
+ Nepomuk::Query::LiteralTerm(regex),
+ Nepomuk::Query::ComparisonTerm::Regexp);
}
+ // Get the term from the facets and merge it with the
+ // created term from the input-field.
+ Nepomuk::Query::Term facetsTerm = m_facetsWidget->facetsTerm();
+
Nepomuk::Query::FileQuery fileQuery;
fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFilesAndFolders);
- fileQuery.setTerm(term);
+ if (facetsTerm.isValid()) {
+ Nepomuk::Query::AndTerm andTerm;
+ andTerm.addSubTerm(searchLabelTerm);
+ andTerm.addSubTerm(facetsTerm);
+ fileQuery.setTerm(andTerm);
+ } else {
+ fileQuery.setTerm(searchLabelTerm);
+ }
+
if (m_fromHereButton->isChecked()) {
const bool recursive = true;
fileQuery.addIncludeFolder(m_searchPath, recursive);
Q_OBJECT
public:
- enum SearchContext {
- SearchFileName,
- SearchContent
- };
-
- enum SearchLocation {
- SearchFromHere,
- SearchEverywhere
- };
-
explicit DolphinSearchBox(QWidget* parent = 0);
virtual ~DolphinSearchBox();
signals:
/**
- * Is emitted when a searching should be triggered
- * and provides the text that should be used as input
- * for searching.
+ * Is emitted when a searching should be triggered.
*/
- void search(const QString& text);
+ void searchRequest();
/**
* Is emitted when the user has changed a character of
void returnPressed(const QString& text);
- /**
- * Is emitted if the search location has been changed by the user.
- */
- void searchLocationChanged(SearchLocation location);
-
- /**
- * Is emitted if the search context has been changed by the user.
- */
- void searchContextChanged(SearchContext context);
-
/**
* Emitted as soon as the search box should get closed.
*/
void closeRequest();
private slots:
- void emitSearchSignal();
- void slotSearchLocationChanged();
- void slotSearchContextChanged();
+ void emitSearchRequest();
+ void emitCloseRequest();
void slotConfigurationChanged();
void slotSearchTextChanged(const QString& text);
void slotReturnPressed(const QString& text);
void slotFacetsButtonToggled();
+ void slotFacetChanged();
private:
void initButton(QToolButton* button);