]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Automatically start the searching if the user did not change the search-text for...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 10 Oct 2010 16:13:24 +0000 (16:13 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 10 Oct 2010 16:13:24 +0000 (16:13 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1184510

src/dolphinviewcontainer.cpp
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h

index 45490e363bc06322333cc2c578778e5413b5faec..aa20409baef04b2f848964b0a77b282adc44768b 100644 (file)
@@ -102,6 +102,7 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
     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(returnPressed(QString)), this, SLOT(requestFocus()));
 
     m_dirLister = new DolphinDirLister();
     m_dirLister->setAutoUpdate(true);
@@ -431,7 +432,7 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
         }
 
         m_view->setUrl(url);
-        if (isActive()) {
+        if (isActive() && !isSearchUrl(url)) {
             // When an URL has been entered, the view should get the focus.
             // The focus must be requested asynchronously, as changing the URL might create
             // a new view widget.
index 64473695293190187d01a5ab714fb7560999c010..f12df73f3cd3500f912a7e1d2df7b5e358c037fa 100644 (file)
@@ -34,6 +34,7 @@
 #include <QKeyEvent>
 #include <QLabel>
 #include <QPushButton>
+#include <QTimer>
 #include <QToolButton>
 #include <QVBoxLayout>
 
@@ -66,7 +67,8 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
     m_filterButton(0),
     m_filterWidgetsLayout(0),
     m_filterWidgets(),
-    m_searchPath()
+    m_searchPath(),
+    m_startSearchTimer(0)
 {
 }
 
@@ -156,6 +158,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent* event)
 
 void DolphinSearchBox::emitSearchSignal()
 {
+    m_startSearchTimer->stop();
     m_startedSearching = true;
     emit search(m_searchInput->text());
 }
@@ -167,6 +170,22 @@ void DolphinSearchBox::slotConfigurationChanged()
     }
 }
 
+void DolphinSearchBox::slotSearchTextChanged(const QString& text)
+{
+    if (text.isEmpty()) {
+        m_startSearchTimer->stop();
+    } else {
+        m_startSearchTimer->start();
+    }
+    emit searchTextChanged(text);
+}
+
+void DolphinSearchBox::slotReturnPressed(const QString& text)
+{
+    emitSearchSignal();
+    emit returnPressed(text);
+}
+
 void DolphinSearchBox::setFilterWidgetsVisible(bool visible)
 {
 #ifdef HAVE_NEPOMUK
@@ -241,10 +260,10 @@ void DolphinSearchBox::init()
     m_searchInput = new KLineEdit(this);
     m_searchInput->setClearButtonShown(true);
     m_searchInput->setFont(KGlobalSettings::generalFont());
-    connect(m_searchInput, SIGNAL(returnPressed()),
-            this, SLOT(emitSearchSignal()));
+    connect(m_searchInput, SIGNAL(returnPressed(QString)),
+            this, SLOT(slotReturnPressed(QString)));
     connect(m_searchInput, SIGNAL(textChanged(QString)),
-            this, SIGNAL(searchTextChanged(QString)));
+            this, SLOT(slotSearchTextChanged(QString)));
 
     // Apply layout for the search input
     QHBoxLayout* searchInputLayout = new QHBoxLayout();
@@ -304,6 +323,13 @@ void DolphinSearchBox::init()
 
     searchLabel->setBuddy(m_searchInput);
     loadSettings();
+
+    // The searching should be started automatically after the user did not change
+    // the text within one second
+    m_startSearchTimer = new QTimer(this);
+    m_startSearchTimer->setSingleShot(true);
+    m_startSearchTimer->setInterval(1000);
+    connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal()));
 }
 
 bool DolphinSearchBox::isSearchPathIndexed() const
index f0ec73def21eeb4bcde69224092dd1cb1e039209..f88fc43f49d6ea13ee3190b12e65fce9186b8cd6 100644 (file)
@@ -71,7 +71,7 @@ protected:
 
 signals:
     /**
-     * Is emitted when the user pressed Return or Enter
+     * Is emitted when a searching should be triggered
      * and provides the text that should be used as input
      * for searching.
      */
@@ -83,6 +83,8 @@ signals:
      */
     void searchTextChanged(const QString& text);
 
+    void returnPressed(const QString& text);
+
     /**
      * Emitted as soon as the search box should get closed.
      */
@@ -91,6 +93,8 @@ signals:
 private slots:
     void emitSearchSignal();
     void slotConfigurationChanged();
+    void slotSearchTextChanged(const QString& text);
+    void slotReturnPressed(const QString& text);
     void setFilterWidgetsVisible(bool visible);
 
 private:
@@ -127,6 +131,8 @@ private:
     QList<AbstractSearchFilterWidget*> m_filterWidgets;
 
     KUrl m_searchPath;
+
+    QTimer* m_startSearchTimer;
 };
 
 #endif