]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* move classes for searching into an own folder (new classes will be added soon)
authorPeter Penz <peter.penz19@gmail.com>
Sat, 17 Oct 2009 15:05:50 +0000 (15:05 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 17 Oct 2009 15:05:50 +0000 (15:05 +0000)
* Postpone the creation of the searchcompleter, until the editor gets focused. This improves the startup time of Dolphin (reading all available tags is an expensive operation).

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

src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/search/dolphinsearchbox.cpp [moved from src/dolphinsearchbox.cpp with 92% similarity]
src/search/dolphinsearchbox.h [moved from src/dolphinsearchbox.h with 96% similarity]
src/search/dolphinsearchcommands.desktop [moved from src/dolphinsearchcommands.desktop with 100% similarity]

index 3186489b4394486da44d7eb8a60f5e3751d636c4..180170fbdd320baed2130743b24d3ce9ddb24a9a 100644 (file)
@@ -105,7 +105,6 @@ set(dolphin_SRCS
     dolphinmainwindow.cpp
     dolphinnewmenu.cpp
     dolphinviewcontainer.cpp
-    dolphinsearchbox.cpp
     dolphindirlister.cpp
     dolphincontextmenu.cpp
     filterbar.cpp
@@ -122,6 +121,7 @@ set(dolphin_SRCS
     panels/folders/treeviewcontextmenu.cpp
     panels/folders/folderspanel.cpp
     panels/folders/paneltreeview.cpp
+    search/dolphinsearchbox.cpp
     settings/behaviorsettingspage.cpp
     settings/columnviewsettingspage.cpp
     settings/contextmenusettingspage.cpp
@@ -256,7 +256,7 @@ install(TARGETS kcm_dolphingeneral DESTINATION ${PLUGIN_INSTALL_DIR} )
 install( FILES  dolphin.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
 install( FILES  settings/dolphin_directoryviewpropertysettings.kcfg settings/dolphin_generalsettings.kcfg settings/dolphin_columnmodesettings.kcfg settings/dolphin_iconsmodesettings.kcfg settings/dolphin_detailsmodesettings.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
 install( FILES  dolphinui.rc DESTINATION ${DATA_INSTALL_DIR}/dolphin )
-install( FILES  dolphinsearchcommands.desktop DESTINATION ${DATA_INSTALL_DIR}/dolphin )
+install( FILES  search/dolphinsearchcommands.desktop DESTINATION ${DATA_INSTALL_DIR}/dolphin )
 install( FILES kcm/kcmdolphinviewmodes.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
 install( FILES kcm/kcmdolphinnavigation.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
 install( FILES kcm/kcmdolphinservices.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
index f491ea8e03b05000e09101b0696ff11ff4a3c9f5..6134632aecaecb47223299016df6b9fdb1a737e0 100644 (file)
@@ -27,9 +27,9 @@
 
 #include "dolphinapplication.h"
 #include "dolphinnewmenu.h"
+#include "search/dolphinsearchbox.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
-#include "dolphinsearchbox.h"
 #include "dolphinviewcontainer.h"
 #include "panels/folders/folderspanel.h"
 #include "panels/places/placespanel.h"
similarity index 92%
rename from src/dolphinsearchbox.cpp
rename to src/search/dolphinsearchbox.cpp
index d9a82ccd6f6912c46078c92e3ebb747f772e9cae..d224575eab301c52071f9f485433b065522cc10a 100644 (file)
@@ -40,8 +40,7 @@
 #ifdef HAVE_NEPOMUK
 #include <Nepomuk/ResourceManager>
 #include <Nepomuk/Tag>
-#endif //HAVE_NEPOMUK
-
+#endif
 
 DolphinSearchCompleter::DolphinSearchCompleter(KLineEdit* linedit) :
     QObject(0),
@@ -50,10 +49,6 @@ DolphinSearchCompleter::DolphinSearchCompleter(KLineEdit* linedit) :
     m_completionModel(0),
     m_wordStart(-1),
     m_wordEnd(-1)
-{
-}
-
-void DolphinSearchCompleter::init()
 {
     m_completionModel = new QStandardItemModel(this);
 
@@ -73,7 +68,7 @@ void DolphinSearchCompleter::init()
     }
 #endif //HAVE_NEPOMUK
 
-    //load the completions stored in the desktop file
+    // load the completions stored in the desktop file
     KDesktopFile file(KStandardDirs::locate("data", "dolphin/dolphinsearchcommands.desktop"));
     foreach (const QString &group, file.groupList()) {
         KConfigGroup cg(&file, group);
@@ -139,7 +134,7 @@ void DolphinSearchCompleter::findText(int* wordStart, int* wordEnd, QString* new
     *wordStart = -1;
     *wordEnd = -1;
 
-    //the word might contain "" and thus maybe spaces
+    // the word might contain "" and thus maybe spaces
     if (input.contains('\"')) {
         int tempStart = -1;
         int tempEnd = -1;
@@ -264,13 +259,13 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
     m_searchInput->setClearButtonShown(true);
     m_searchInput->setMinimumWidth(150);
     m_searchInput->setClickMessage(i18nc("@label:textbox", "Search..."));
+    m_searchInput->installEventFilter(this);
     hLayout->addWidget(m_searchInput);
+    connect(m_searchInput, SIGNAL(textEdited(const QString&)),
+            this, SLOT(slotTextEdited(const QString&)));
     connect(m_searchInput, SIGNAL(returnPressed()),
             this, SLOT(emitSearchSignal()));
 
-    m_completer = new DolphinSearchCompleter(m_searchInput);
-    m_completer->init();
-
     m_searchButton = new QToolButton(this);
     m_searchButton->setAutoRaise(true);
     m_searchButton->setIcon(KIcon("edit-find"));
@@ -282,7 +277,6 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
 
 DolphinSearchBox::~DolphinSearchBox()
 {
-    delete m_completer;
 }
 
 bool DolphinSearchBox::event(QEvent* event)
@@ -297,9 +291,28 @@ bool DolphinSearchBox::event(QEvent* event)
     return QWidget::event(event);
 }
 
+bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
+{
+    if ((watched == m_searchInput) && (event->type() == QEvent::FocusIn)) {
+        // Postpone the creation of the search completer until
+        // the search box is used. This decreases the startup time
+        // of Dolphin.
+        Q_ASSERT(m_completer == 0);
+        m_completer = new DolphinSearchCompleter(m_searchInput);
+        m_searchInput->removeEventFilter(this);
+    }
+
+    return QWidget::eventFilter(watched, event);
+}
+
+
 void DolphinSearchBox::emitSearchSignal()
 {
     emit search(KUrl("nepomuksearch:/" + m_searchInput->text()));
 }
 
+void DolphinSearchBox::slotTextEdited(const QString& text)
+{
+}
+
 #include "dolphinsearchbox.moc"
similarity index 96%
rename from src/dolphinsearchbox.h
rename to src/search/dolphinsearchbox.h
index c518d6a1d71fa7fdf69c50881b3e24701496e818..93c033bb8e6caef48fea249ed55e76aeb9dcc5f0 100644 (file)
@@ -40,8 +40,6 @@ class DolphinSearchCompleter : public QObject
     public:
         DolphinSearchCompleter(KLineEdit *linedit);
 
-        void init();
-
     public slots:
         void highlighted(const QModelIndex& index);
         void activated(const QModelIndex& index);
@@ -74,6 +72,7 @@ public:
 
 protected:
     virtual bool event(QEvent* event);
+    virtual bool eventFilter(QObject* watched, QEvent* event);
 
 signals:
     /**
@@ -85,9 +84,7 @@ signals:
 
 private slots:
     void emitSearchSignal();
-
-
-
+    void slotTextEdited(const QString& text);
 
 private:
     KLineEdit* m_searchInput;