]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/search/dolphinsearchbox.cpp
Fix loop of FocusIn events
[dolphin.git] / src / search / dolphinsearchbox.cpp
index 60678eb45bff9f233e7dc5ae55d5a2d50e55929f..61f5c2db4f8e341ed22fe0ef079a27a554d10c48 100644 (file)
 
 #include "dolphin_searchsettings.h"
 #include "dolphinfacetswidget.h"
+#include "panels/places/placesitemmodel.h"
 
-#include <panels/places/placesitemmodel.h>
-
-#include <QIcon>
-#include <QLineEdit>
 #include <KLocalizedString>
-#include <KSeparator>
 #include <KNS3/KMoreToolsMenuFactory>
+#include <KSeparator>
+#include <config-baloo.h>
+#ifdef HAVE_BALOO
+#include <Baloo/Query>
+#include <Baloo/IndexerConfig>
+#endif
 
 #include <QButtonGroup>
 #include <QDir>
-#include <QEvent>
+#include <QFontDatabase>
 #include <QHBoxLayout>
-#include <QKeyEvent>
+#include <QIcon>
 #include <QLabel>
+#include <QLineEdit>
 #include <QScrollArea>
 #include <QTimer>
 #include <QToolButton>
-#include <QVBoxLayout>
 #include <QUrlQuery>
 
-#include <config-baloo.h>
-#ifdef HAVE_BALOO
-    #include <Baloo/Query>
-    #include <Baloo/IndexerConfig>
-#endif
-#include <QFontDatabase>
-
 DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
     QWidget(parent),
     m_startedSearching(false),
@@ -236,10 +231,14 @@ bool DolphinSearchBox::eventFilter(QObject* obj, QEvent* event)
         // #379135: we get the FocusIn event when we close a tab but we don't want to emit
         // the activated() signal before the removeTab() call in DolphinTabWidget::closeTab() returns.
         // To avoid this issue, we delay the activation of the search box.
-        QTimer::singleShot(0, this, [this] {
-            setActive(true);
-            setFocus();
-        });
+        // We also don't want to schedule the activation process if we are already active,
+        // otherwise we can enter in a loop of FocusIn/FocusOut events with the searchbox of another tab.
+        if (!isActive()) {
+            QTimer::singleShot(0, this, [this] {
+                setActive(true);
+                setFocus();
+            });
+        }
         break;
 
     default:
@@ -310,11 +309,9 @@ void DolphinSearchBox::slotSearchSaved()
     if (searchURL.isValid()) {
         PlacesItemModel model;
         const QString label = i18n("Search for %1 in %2", text(), searchPath().fileName());
-        PlacesItem* item = model.createPlacesItem(label,
-                                                  searchURL,
-                                                  QStringLiteral("folder-saved-search-symbolic"));
-        model.appendItemToGroup(item);
-        model.saveBookmarks();
+        model.createPlacesItem(label,
+                               searchURL,
+                               QStringLiteral("folder-saved-search-symbolic"));
     }
 }