]> cloud.milkyroute.net Git - dolphin.git/commitdiff
search finetuning:
authorPeter Penz <peter.penz19@gmail.com>
Fri, 13 Nov 2009 21:03:19 +0000 (21:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 13 Nov 2009 21:03:19 +0000 (21:03 +0000)
* trigger progress information when starting a search
* let the information panel hide the meta data for the search string
* get the search string from the configurator

svn path=/trunk/KDE/kdebase/apps/; revision=1048721

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h
src/panels/information/informationpanelcontent.cpp
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h
src/search/dolphinsearchoptionsconfigurator.cpp
src/search/dolphinsearchoptionsconfigurator.h
src/search/searchcriterionselector.cpp
src/search/searchcriterionselector.h

index ee5994955ae69f9322c938e8a69eff67ae05b228..10275ce8c6457b43446db2df388b4afd40c2502b 100644 (file)
@@ -1003,15 +1003,20 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
     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)
@@ -1070,6 +1075,8 @@ void DolphinMainWindow::init()
 #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);
@@ -1346,7 +1353,7 @@ void DolphinMainWindow::setupActions()
 
     // '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);
index f87e70dc4585dc71b83cc237bc0d2a7d1623ee9e..e9332194f544cc1e1b039036f9eec1e13c5b3e1a 100644 (file)
@@ -388,10 +388,10 @@ private slots:
     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).
index 7bb4b7bec3bfbfbf2474cd8ab5b4b5a4d8dea999..bdeaab25833a05e8d0d525dbaae7697fdb3adc96 100644 (file)
@@ -112,6 +112,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     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)),
@@ -266,7 +268,7 @@ void DolphinViewContainer::updateStatusBar()
     // - 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))
@@ -280,6 +282,16 @@ void DolphinViewContainer::updateStatusBar()
     }
 }
 
+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()) {
@@ -418,7 +430,7 @@ void DolphinViewContainer::restoreView(const KUrl& url)
                                    "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 {
index a691b278fd96cfa2215f574af3748ac711025cc1..6d4b9b1a455483fff06ebd620decd33042d196fd 100644 (file)
@@ -141,6 +141,8 @@ private slots:
      */
     void updateStatusBar();
 
+    void initializeProgress();
+
     void updateProgress(int percent);
 
     /**
index 828783e678c4159172c86ec0ae6f3044f121825e..16876e302570571ad05aa70c3d489fdca471a14c 100644 (file)
@@ -146,37 +146,54 @@ void InformationPanelContent::showItem(const KFileItem& item)
     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()) {
index 9f228140b544d801dea5c8a3932532bbc2b4fd34..4375974a419890c635df7bb64537feb1b41632c5 100644 (file)
@@ -256,6 +256,11 @@ DolphinSearchBox::~DolphinSearchBox()
 {
 }
 
+QString DolphinSearchBox::text() const
+{
+    return m_searchInput->text();
+}
+
 bool DolphinSearchBox::event(QEvent* event)
 {
     if (event->type() == QEvent::Polish) {
@@ -286,7 +291,7 @@ bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
 
 void DolphinSearchBox::emitSearchSignal()
 {
-    emit search(KUrl("nepomuksearch:/" + m_searchInput->text()));
+    emit search(m_searchInput->text());
 }
 
 #include "dolphinsearchbox.moc"
index fea7129b16caa82c03550455bdba838d4b165169..36bcb0e10c97869e670a9cfbf7c5e63e3f3b41d4 100644 (file)
@@ -69,6 +69,12 @@ public:
     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);
@@ -76,11 +82,17 @@ protected:
 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:
@@ -88,7 +100,6 @@ private slots:
 
 private:
     KLineEdit* m_searchInput;
-
     DolphinSearchCompleter* m_completer;
 };
 
index d0b7cace2b8f81ae0dbd4a54f4b557f475dafac2..db51f2c4276a9005fc8c73812e28193f243cb043 100644 (file)
@@ -35,8 +35,6 @@
 #include <QShowEvent>
 #include <QVBoxLayout>
 
-#include <kdebug.h>
-
 DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
     QWidget(parent),
     m_initialized(false),
@@ -69,6 +67,7 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare
     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);
@@ -115,6 +114,21 @@ DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator()
 {
 }
 
+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) {
@@ -143,14 +157,9 @@ void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
     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()
@@ -201,8 +210,12 @@ void DolphinSearchOptionsConfigurator::saveQuery()
 
 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;
index 46950e42256e2408faea96658a736860f689dbf2..5bceaceeac9efab4b09b7f33edb78a7c5aa50900 100644 (file)
@@ -39,6 +39,12 @@ public:
     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);
 
@@ -48,7 +54,7 @@ protected:
 private slots:
     void slotAddSelectorButtonClicked();
 
-    void slotCriterionChanged();
+    void emitSearchOptionsChanged();
 
     void removeCriterion();
 
index f685e50fcb4fc8d7005814a12edb8a71b7733912..4b6112b9caa4f5954aa84da340b5430bd57fcd22 100644 (file)
@@ -74,7 +74,7 @@ SearchCriterionSelector::~SearchCriterionSelector()
 {
 }
 
-QString SearchCriterionSelector::queryString() const
+QString SearchCriterionSelector::toString() const
 {
     if (m_valueWidget == 0) {
         return QString();
@@ -85,9 +85,15 @@ QString SearchCriterionSelector::queryString() const
 
     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)
index c6c3b22e09743d6e639b70025858c9f650123498..27cbb2e46e4b4590dd3efda31dc44eee1d461e13 100644 (file)
@@ -50,7 +50,11 @@ public:
     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:
     /**