#include "dolphinsearchbox.h"
#include "dolphin_searchsettings.h"
+#include "dolphinsearchinformation.h"
-#include <kicon.h>
-#include <klineedit.h>
-#include <klocale.h>
-#include <kseparator.h>
+#include <KIcon>
+#include <KLineEdit>
+#include <KLocale>
+#include <KSeparator>
#include <QButtonGroup>
#include <QDir>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
+#include <QScrollArea>
#include <QTimer>
#include <QToolButton>
#include <QVBoxLayout>
#include <config-nepomuk.h>
#ifdef HAVE_NEPOMUK
- #include <nepomuk/andterm.h>
- #include <nepomuk/filequery.h>
- #include <nepomuk/literalterm.h>
- #include <nepomuk/query.h>
- #include <nepomuk/queryparser.h>
- #include <nepomuk/resourcemanager.h>
- #include <nepomuk/resourcetypeterm.h>
- #include <nepomuk/comparisonterm.h>
- #include <nepomuk/nfo.h>
+ #include <Nepomuk/Query/FileQuery>
+ #include <Nepomuk/Query/LiteralTerm>
+ #include <Nepomuk/Query/OrTerm>
+ #include <Nepomuk/Query/Query>
+ #include <Nepomuk/Query/QueryParser>
+ #include <Nepomuk/Query/ResourceTypeTerm>
+ #include <Nepomuk/Query/ComparisonTerm>
+ #include <Nepomuk/ResourceManager>
+ #include <Nepomuk/Vocabulary/NFO>
#endif
DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
QWidget(parent),
m_startedSearching(false),
- m_nepomukActivated(false),
+ m_readOnly(false),
m_topLayout(0),
m_searchInput(0),
m_fileNameButton(0),
m_separator(0),
m_fromHereButton(0),
m_everywhereButton(0),
+ m_infoLabel(0),
m_searchPath(),
m_startSearchTimer(0)
{
saveSettings();
}
+void DolphinSearchBox::setText(const QString& text)
+{
+ m_searchInput->setText(text);
+}
+
QString DolphinSearchBox::text() const
{
return m_searchInput->text();
KUrl DolphinSearchBox::urlForSearching() const
{
KUrl url;
- if (m_nepomukActivated && isSearchPathIndexed()) {
+ const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+ if (searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath)) {
url = nepomukUrlForSearching();
} else {
url.setProtocol("filenamesearch");
m_searchInput->selectAll();
}
+void DolphinSearchBox::setReadOnly(bool readOnly)
+{
+ if (m_readOnly != readOnly) {
+ m_readOnly = readOnly;
+ applyReadOnlyState();
+ }
+}
+
+bool DolphinSearchBox::isReadOnly() const
+{
+ return m_readOnly;
+}
+
bool DolphinSearchBox::event(QEvent* event)
{
if (event->type() == QEvent::Polish) {
void DolphinSearchBox::showEvent(QShowEvent* event)
{
if (!event->spontaneous()) {
-#ifdef HAVE_NEPOMUK
- m_nepomukActivated = (Nepomuk::ResourceManager::instance()->init() == 0);
-#endif
-
- m_searchInput->clear();
m_searchInput->setFocus();
m_startedSearching = false;
}
void DolphinSearchBox::keyReleaseEvent(QKeyEvent* event)
{
QWidget::keyReleaseEvent(event);
- if ((event->key() == Qt::Key_Escape)) {
+ if (event->key() == Qt::Key_Escape) {
if (m_searchInput->text().isEmpty()) {
emit closeRequest();
} else {
void DolphinSearchBox::slotSearchTextChanged(const QString& text)
{
- if (text.isEmpty()) {
- m_startSearchTimer->stop();
- } else {
- m_startSearchTimer->start();
- }
+ m_startSearchTimer->start();
emit searchTextChanged(text);
}
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_searchInput);
+ searchInputLayout->addWidget(m_infoLabel);
// Create "Filename" and "Content" button
m_fileNameButton = new QPushButton(this);
optionsLayout->addWidget(m_everywhereButton);
optionsLayout->addStretch(1);
+ // Put the options into a QScrollArea. This prevents increasing the view width
+ // 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_topLayout = new QVBoxLayout(this);
m_topLayout->addLayout(searchInputLayout);
- m_topLayout->addLayout(optionsLayout);
+ m_topLayout->addWidget(optionsScrollArea);
searchLabel->setBuddy(m_searchInput);
loadSettings();
m_startSearchTimer->setSingleShot(true);
m_startSearchTimer->setInterval(1000);
connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal()));
-}
-bool DolphinSearchBox::isSearchPathIndexed() const
-{
-#ifdef HAVE_NEPOMUK
- const QString path = m_searchPath.path();
-
- const KConfig strigiConfig("nepomukstrigirc");
- const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
-
- // Check whether the current search path is part of an indexed folder
- bool isIndexed = false;
- foreach (const QString& indexedFolder, indexedFolders) {
- if (path.startsWith(indexedFolder)) {
- isIndexed = true;
- break;
- }
- }
-
- if (isIndexed) {
- // The current search path is part of an indexed folder. Check whether no
- // excluded folder is part of the search path.
- const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
- foreach (const QString& excludedFolder, excludedFolders) {
- if (path.startsWith(excludedFolder)) {
- isIndexed = false;
- break;
- }
- }
- }
-
- return isIndexed;
-#else
- return false;
-#endif
+ applyReadOnlyState();
}
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::QueryFiles);
- fileQuery.setTerm(andTerm);
+ fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFilesAndFolders);
+ fileQuery.setTerm(orTerm);
if (m_fromHereButton->isChecked()) {
const bool recursive = true;
fileQuery.addIncludeFolder(m_searchPath, recursive);
#endif
}
+void DolphinSearchBox::applyReadOnlyState()
+{
+ // TODO: This is just an early draft to indicate that a state change
+ // has been done
+ 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);
+}
+
#include "dolphinsearchbox.moc"