#include <KIcon>
#include <KLineEdit>
#include <KLocale>
-#include <kseparator.h>
+#include <KSeparator>
#include <QButtonGroup>
#include <QDir>
#include <config-nepomuk.h>
#ifdef HAVE_NEPOMUK
- #include <Nepomuk/Query/AndTerm>
#include <Nepomuk/Query/FileQuery>
#include <Nepomuk/Query/LiteralTerm>
+ #include <Nepomuk/Query/OrTerm>
#include <Nepomuk/Query/Query>
#include <Nepomuk/Query/QueryParser>
#include <Nepomuk/Query/ResourceTypeTerm>
m_startedSearching(false),
m_readOnly(false),
m_topLayout(0),
+ m_searchLabel(0),
m_searchInput(0),
+ m_optionsScrollArea(0),
m_fileNameButton(0),
m_contentButton(0),
m_separator(0),
m_fromHereButton(0),
m_everywhereButton(0),
- m_infoLabel(0),
m_searchPath(),
+ m_readOnlyQuery(),
m_startSearchTimer(0)
{
}
const QString elidedLocation = metrics.elidedText(location, Qt::ElideMiddle, maxWidth);
m_fromHereButton->setText(i18nc("action:button", "From Here (%1)", elidedLocation));
- const bool showSearchFromButtons = url.isLocalFile();
+ const bool showSearchFromButtons = url.isLocalFile() && !m_readOnly;
m_separator->setVisible(showSearchFromButtons);
m_fromHereButton->setVisible(showSearchFromButtons);
m_everywhereButton->setVisible(showSearchFromButtons);
m_searchInput->selectAll();
}
-void DolphinSearchBox::setReadOnly(bool readOnly)
+void DolphinSearchBox::setReadOnly(bool readOnly, const KUrl& query)
{
if (m_readOnly != readOnly) {
m_readOnly = readOnly;
+ m_readOnlyQuery = query;
applyReadOnlyState();
}
}
emit search(m_searchInput->text());
}
+void DolphinSearchBox::slotSearchLocationChanged()
+{
+ emit searchLocationChanged(m_fromHereButton->isChecked() ? SearchFromHere : SearchEverywhere);
+}
+
+void DolphinSearchBox::slotSearchContextChanged()
+{
+ emit searchContextChanged(m_fileNameButton->isChecked() ? SearchFileName : SearchContent);
+}
+
void DolphinSearchBox::slotConfigurationChanged()
{
+ saveSettings();
if (m_startedSearching) {
emitSearchSignal();
}
void DolphinSearchBox::slotSearchTextChanged(const QString& text)
{
- if (text.isEmpty()) {
- m_startSearchTimer->stop();
- } else {
- m_startSearchTimer->start();
- }
+ m_startSearchTimer->start();
emit searchTextChanged(text);
}
button->setAutoExclusive(true);
button->setFlat(true);
button->setCheckable(true);
- connect(button, SIGNAL(toggled(bool)), this, SLOT(slotConfigurationChanged()));
+ connect(button, SIGNAL(clicked(bool)), this, SLOT(slotConfigurationChanged()));
}
void DolphinSearchBox::loadSettings()
connect(closeButton, SIGNAL(clicked()), SIGNAL(closeRequest()));
// Create search label
- QLabel* searchLabel = new QLabel(i18nc("@label:textbox", "Find:"), this);
+ m_searchLabel = new QLabel(this);
// Create search box
m_searchInput = new KLineEdit(this);
connect(m_searchInput, SIGNAL(textChanged(QString)),
this, SLOT(slotSearchTextChanged(QString)));
- // Create information label
- m_infoLabel = new QLabel("TODO: Provide information about the current query", this);
-
// Apply layout for the search input
QHBoxLayout* searchInputLayout = new QHBoxLayout();
searchInputLayout->setMargin(0);
searchInputLayout->addWidget(closeButton);
- searchInputLayout->addWidget(searchLabel);
+ searchInputLayout->addWidget(m_searchLabel);
searchInputLayout->addWidget(m_searchInput);
- searchInputLayout->addWidget(m_infoLabel);
// Create "Filename" and "Content" button
m_fileNameButton = new QPushButton(this);
QButtonGroup* searchWhatGroup = new QButtonGroup(this);
searchWhatGroup->addButton(m_fileNameButton);
searchWhatGroup->addButton(m_contentButton);
+ connect(m_fileNameButton, SIGNAL(clicked()), this, SLOT(slotSearchContextChanged()));
+ connect(m_contentButton, SIGNAL(clicked()), this, SLOT(slotSearchContextChanged()));
m_separator = new KSeparator(Qt::Vertical, 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()));
// Apply layout for the options
QHBoxLayout* optionsLayout = new QHBoxLayout();
// in case that not enough width for the options is available.
QWidget* optionsContainer = new QWidget(this);
optionsContainer->setLayout(optionsLayout);
- QScrollArea* optionsScrollArea = new QScrollArea(this);
- optionsScrollArea->setFrameShape(QFrame::NoFrame);
- optionsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- optionsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- optionsScrollArea->setMaximumHeight(optionsContainer->sizeHint().height());
- optionsScrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
- optionsScrollArea->setWidget(optionsContainer);
- optionsScrollArea->setWidgetResizable(true);
+
+ m_optionsScrollArea = new QScrollArea(this);
+ m_optionsScrollArea->setFrameShape(QFrame::NoFrame);
+ m_optionsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_optionsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_optionsScrollArea->setMaximumHeight(optionsContainer->sizeHint().height());
+ m_optionsScrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ m_optionsScrollArea->setWidget(optionsContainer);
+ m_optionsScrollArea->setWidgetResizable(true);
m_topLayout = new QVBoxLayout(this);
+ m_topLayout->setMargin(0);
m_topLayout->addLayout(searchInputLayout);
- m_topLayout->addWidget(optionsScrollArea);
+ m_topLayout->addWidget(m_optionsScrollArea);
- searchLabel->setBuddy(m_searchInput);
loadSettings();
// The searching should be started automatically after the user did not change
KUrl DolphinSearchBox::nepomukUrlForSearching() const
{
#ifdef HAVE_NEPOMUK
- Nepomuk::Query::AndTerm andTerm;
+ Nepomuk::Query::OrTerm orTerm;
- // Add input from search filter
const QString text = m_searchInput->text();
- if (!text.isEmpty()) {
- if (m_fileNameButton->isChecked()) {
- QString regex = QRegExp::escape(text);
- regex.replace("\\*", QLatin1String(".*"));
- regex.replace("\\?", QLatin1String("."));
- regex.replace("\\", "\\\\");
- andTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
- Nepomuk::Vocabulary::NFO::fileName(),
- Nepomuk::Query::LiteralTerm(regex),
- Nepomuk::Query::ComparisonTerm::Regexp));
- } else {
- const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern);
- if (customQuery.isValid()) {
- andTerm.addSubTerm(customQuery.term());
- }
+
+ // Search the text in the filename in any case
+ QString regex = QRegExp::escape(text);
+ regex.replace("\\*", QLatin1String(".*"));
+ regex.replace("\\?", QLatin1String("."));
+ regex.replace("\\", "\\\\");
+ orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
+ Nepomuk::Vocabulary::NFO::fileName(),
+ Nepomuk::Query::LiteralTerm(regex),
+ Nepomuk::Query::ComparisonTerm::Regexp));
+
+ if (m_contentButton->isChecked()) {
+ // Search the text also in the content of the files
+ const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern);
+ if (customQuery.isValid()) {
+ orTerm.addSubTerm(customQuery.term());
}
}
Nepomuk::Query::FileQuery fileQuery;
fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFilesAndFolders);
- fileQuery.setTerm(andTerm);
+ fileQuery.setTerm(orTerm);
if (m_fromHereButton->isChecked()) {
const bool recursive = true;
fileQuery.addIncludeFolder(m_searchPath, recursive);
void DolphinSearchBox::applyReadOnlyState()
{
- // TODO: This is just an early draft to indicate that a state change
- // has been done
+#ifdef HAVE_NEPOMUK
+ if (m_readOnly) {
+ m_searchLabel->setText(Nepomuk::Query::Query::titleFromQueryUrl(m_readOnlyQuery));
+ } else {
+#else
+ {
+#endif
+ m_searchLabel->setText(i18nc("@label:textbox", "Find:"));
+ }
+
m_searchInput->setVisible(!m_readOnly);
- m_infoLabel->setVisible(m_readOnly);
- m_fileNameButton->setEnabled(!m_readOnly);
- m_contentButton->setEnabled(!m_readOnly);
- m_fromHereButton->setEnabled(!m_readOnly);
- m_everywhereButton->setEnabled(!m_readOnly);
+ m_optionsScrollArea->setVisible(!m_readOnly);
}
#include "dolphinsearchbox.moc"