canDecode = KUrl::List::canDecode(event->mimeData());
}
-void DolphinMainWindow::searchItems(const KUrl& url)
+void DolphinMainWindow::searchItems()
{
- m_activeViewContainer->setUrl(url);
+ const QString searchOptions = m_searchOptionsConfigurator->options();
- // The Nepomuk IO-slave does not provide any progress information. Give
- // an immediate hint to the user that a searching is done:
- DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
- statusBar->setProgressText(i18nc("@info", "Searching..."));
- statusBar->setProgress(-1);
+ QString searchString = m_searchBox->text();
+ if (!searchString.isEmpty() && !searchOptions.isEmpty()) {
+ searchString += ' ' + searchOptions;
+ } else if (!searchOptions.isEmpty()) {
+ searchString += searchOptions;
+ }
+
+ if (!searchString.isEmpty()) {
+ m_activeViewContainer->setUrl(KUrl("nepomuksearch:/" + searchString));
+ }
}
void DolphinMainWindow::slotTabMoved(int from, int to)
#ifdef HAVE_NEPOMUK
m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
m_searchOptionsConfigurator->hide();
+ connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged(QString)),
+ this, SLOT(searchItems()));
#endif
m_tabBar = new KTabBar(this);
// 'Search' toolbar
m_searchBox = new DolphinSearchBox(this);
- connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl)));
+ connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems()));
KAction* search = new KAction(this);
actionCollection()->addAction("search_bar", search);
void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
/**
- * Is connected with the Dolphin search box and searchs items that
- * match to the text entered in the search bar.
+ * Is connected with the Dolphin search box and the search configurator
+ * and triggers a Nepomuk search.
*/
- void searchItems(const KUrl& url);
+ void searchItems();
/**
* Is connected to the QTabBar signal tabMoved(int from, int to).
m_proxyModel->setSourceModel(m_dolphinModel);
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ connect(m_dirLister, SIGNAL(started(KUrl)),
+ this, SLOT(initializeProgress()));
connect(m_dirLister, SIGNAL(clear()),
this, SLOT(delayedStatusBarUpdate()));
connect(m_dirLister, SIGNAL(percent(int)),
// - shows already the item count information or
// - shows only a not very important information
// - if any progress is given don't show the item count info at all
- const QString msg(m_statusBar->message());
+ const QString msg = m_statusBar->message();
const bool updateStatusBarMsg = (msg.isEmpty()
|| (msg == m_statusBar->defaultText())
|| (m_statusBar->type() == DolphinStatusBar::Information))
}
}
+void DolphinViewContainer::initializeProgress()
+{
+ if (m_view->url().protocol() == "nepomuksearch") {
+ // The Nepomuk IO-slave does not provide any progress information. Give
+ // an immediate hint to the user that a searching is done:
+ m_statusBar->setProgressText(i18nc("@info", "Searching..."));
+ m_statusBar->setProgress(-1);
+ }
+ }
+
void DolphinViewContainer::updateProgress(int percent)
{
if (m_statusBar->progressText().isEmpty()) {
"Protocol not supported by Dolphin, Konqueror has been launched"));
}
- QString secureUrl = KShell::quoteArg(url.pathOrUrl());
+ const QString secureUrl = KShell::quoteArg(url.pathOrUrl());
const QString command = app + ' ' + secureUrl;
KRun::runCommand(command, app, app, this);
} else {
*/
void updateStatusBar();
+ void initializeProgress();
+
void updateProgress(int percent);
/**
m_pendingPreview = false;
const KUrl itemUrl = item.url();
+ const bool isNepomukSearchUrl = (itemUrl.protocol() == "nepomuksearch") && item.nepomukUri().isEmpty();
if (!applyPlace(itemUrl)) {
- // try to get a preview pixmap from the item...
- m_pendingPreview = true;
-
- // Mark the currently shown preview as outdated. This is done
- // with a small delay to prevent a flickering when the next preview
- // can be shown within a short timeframe. This timer is not started
- // for directories, as directory previews might fail and return the
- // same icon.
- if (!item.isDir()) {
- m_outdatedPreviewTimer->start();
- }
+ if (isNepomukSearchUrl) {
+ // in the case of a Nepomuk query-URL the URL is not readable for humans
+ // (at least not useful to show in the Information Panel)
+ KIconLoader iconLoader;
+ QPixmap icon = iconLoader.loadIcon("nepomuk",
+ KIconLoader::NoGroup,
+ KIconLoader::SizeEnormous);
+ m_preview->setPixmap(icon);
+ setNameLabelText(QString());
+ } else {
+ // try to get a preview pixmap from the item...
+ m_pendingPreview = true;
+
+ // Mark the currently shown preview as outdated. This is done
+ // with a small delay to prevent a flickering when the next preview
+ // can be shown within a short timeframe. This timer is not started
+ // for directories, as directory previews might fail and return the
+ // same icon.
+ if (!item.isDir()) {
+ m_outdatedPreviewTimer->start();
+ }
- KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item,
- m_preview->width(),
- m_preview->height(),
- 0,
- 0,
- false,
- true);
+ KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item,
+ m_preview->width(),
+ m_preview->height(),
+ 0,
+ 0,
+ false,
+ true);
- connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
- this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
- connect(job, SIGNAL(failed(const KFileItem&)),
- this, SLOT(showIcon(const KFileItem&)));
+ connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
+ this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
+ connect(job, SIGNAL(failed(const KFileItem&)),
+ this, SLOT(showIcon(const KFileItem&)));
- setNameLabelText(itemUrl.fileName());
+ setNameLabelText(itemUrl.fileName());
+ }
}
if (m_metaDataWidget != 0) {
- m_metaDataWidget->setItem(item);
+ if (isNepomukSearchUrl) {
+ m_metaDataWidget->hide();
+ } else {
+ m_metaDataWidget->show();
+ m_metaDataWidget->setItem(item);
+ }
}
if (InformationPanelSettings::showPreview()) {
{
}
+QString DolphinSearchBox::text() const
+{
+ return m_searchInput->text();
+}
+
bool DolphinSearchBox::event(QEvent* event)
{
if (event->type() == QEvent::Polish) {
void DolphinSearchBox::emitSearchSignal()
{
- emit search(KUrl("nepomuksearch:/" + m_searchInput->text()));
+ emit search(m_searchInput->text());
}
#include "dolphinsearchbox.moc"
DolphinSearchBox(QWidget* parent = 0);
virtual ~DolphinSearchBox();
+ /**
+ * Returns the text that should be used as input
+ * for searching.
+ */
+ QString text() const;
+
protected:
virtual bool event(QEvent* event);
virtual bool eventFilter(QObject* watched, QEvent* event);
signals:
/**
* Is emitted when the user pressed Return or Enter
- * and provides the Nepomuk URL that should be used
+ * and provides the text that should be used as input
* for searching.
*/
- void search(const KUrl& url);
+ void search(const QString& text);
+ /**
+ * Is emitted if the search box gets the focus and
+ * requests the need for a UI that allows to adjust
+ * search options. It is up to the application to ignore
+ * this request.
+ */
void requestSearchOptions();
private slots:
private:
KLineEdit* m_searchInput;
-
DolphinSearchCompleter* m_completer;
};
#include <QShowEvent>
#include <QVBoxLayout>
-#include <kdebug.h>
-
DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
QWidget(parent),
m_initialized(false),
searchButton->setIcon(KIcon("edit-find"));
searchButton->setText(i18nc("@action:button", "Search"));
searchButton->setToolTip(i18nc("@info", "Start searching"));
+ connect(searchButton, SIGNAL(clicked()), this, SLOT(emitSearchOptionsChanged()));
// add button "Save"
QPushButton* saveButton = new QPushButton(this);
{
}
+QString DolphinSearchOptionsConfigurator::options() const
+{
+ QString searchOptions;
+ foreach (const SearchCriterionSelector* criterion, m_criterions) {
+ const QString criterionString = criterion->toString();
+ if (!criterionString.isEmpty()) {
+ if (!searchOptions.isEmpty()) {
+ searchOptions += ' ';
+ }
+ searchOptions += criterionString;
+ }
+ }
+ return searchOptions;
+}
+
void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
{
if (!event->spontaneous() && !m_initialized) {
addCriterion(selector);
}
-void DolphinSearchOptionsConfigurator::slotCriterionChanged()
+void DolphinSearchOptionsConfigurator::emitSearchOptionsChanged()
{
- QString searchOptions;
- foreach (const SearchCriterionSelector* criterion, m_criterions) {
- searchOptions += criterion->queryString() + ' ';
- }
- kDebug() << "Search option string:" << searchOptions;
- emit searchOptionsChanged(searchOptions);
+ emit searchOptionsChanged(options());
}
void DolphinSearchOptionsConfigurator::removeCriterion()
void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
{
- connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
- connect(criterion, SIGNAL(criterionChanged()), this, SLOT(slotCriterionChanged()));
+ connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ // TODO: It is unclear yet whether changing a criterion should also result in triggering
+ // a searchOptionsChanged() signal. This mainly depends on the performance achievable with
+ // Nepomuk. Currently the searchOptionsChanged() signal is only emitted when the search-button
+ // has been triggered by the user.
+ // connect(criterion, SIGNAL(criterionChanged()), this, SLOT(emitSearchOptionsChanged()));
// insert the new selector before the lastLineLayout and the KSeparator at the bottom
const int index = m_vBoxLayout->count() - 2;
DolphinSearchOptionsConfigurator(QWidget* parent = 0);
virtual ~DolphinSearchOptionsConfigurator();
+ /**
+ * Returns the configured options as compliant
+ * string that may be used as input for a nepomuk:/-URI.
+ */
+ QString options() const;
+
signals:
void searchOptionsChanged(const QString& options);
private slots:
void slotAddSelectorButtonClicked();
- void slotCriterionChanged();
+ void emitSearchOptionsChanged();
void removeCriterion();
{
}
-QString SearchCriterionSelector::queryString() const
+QString SearchCriterionSelector::toString() const
{
if (m_valueWidget == 0) {
return QString();
const int compIndex = m_comparatorBox->currentIndex();
const SearchCriterionDescription::Comparator& comp = descr.comparators()[compIndex];
+ if (comp.operation.isEmpty()) {
+ return QString();
+ }
- return comp.prefix + descr.identifier() + comp.operation +
- '"' + m_valueWidget->value() + '"';
+ QString criterion = comp.prefix + descr.identifier() + comp.operation;
+ if (!m_valueWidget->value().isEmpty()) {
+ criterion += '"' + m_valueWidget->value() + '"';
+ }
+ return criterion;
}
void SearchCriterionSelector::slotDescriptionChanged(int index)
SearchCriterionSelector(Type type, QWidget* parent = 0);
virtual ~SearchCriterionSelector();
- QString queryString() const;
+ /**
+ * Converts the string representation of the criterion.
+ * The string is conform to get added to a nepomuk:/-URI.
+ */
+ QString toString() const;
signals:
/**