]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/search/dolphinsearchbox.h
Use capitalized KDE includes
[dolphin.git] / src / search / dolphinsearchbox.h
index 93c033bb8e6caef48fea249ed55e76aeb9dcc5f0..09d2233558f4c13c19aa5e340bfc4651f86fa864 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
- *   Copyright (C) 2009 by Matthias Fuchs <mat69@gmx.net>                  *
+ *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   Free Software Foundation, Inc.,                                       *
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
+
 #ifndef DOLPHINSEARCHBOX_H
 #define DOLPHINSEARCHBOX_H
 
+#include <KUrl>
+#include <QList>
 #include <QWidget>
 
-#include <KIcon>
-
+class AbstractSearchFilterWidget;
 class KLineEdit;
-class KUrl;
-class QCompleter;
-class QModelIndex;
-class QStandardItemModel;
-class QToolButton;
+class KSeparator;
+class QFormLayout;
+class QPushButton;
+class QVBoxLayout;
 
 /**
- * @brief used for completition for the DolphinSearchBox
+ * @brief Input box for searching files with or without Nepomuk.
+ *
+ * The widget allows to specify:
+ * - Where to search: Everywhere or below the current directory
+ * - What to search: Filenames or content
+ *
+ * If Nepomuk is available and the current folder is indexed, further
+ * options are offered.
  */
-class DolphinSearchCompleter : public QObject
-{
-    Q_OBJECT
-    public:
-        DolphinSearchCompleter(KLineEdit *linedit);
-
-    public slots:
-        void highlighted(const QModelIndex& index);
-        void activated(const QModelIndex& index);
-        void slotTextEdited(const QString &text);
-
-    private:
-        void addCompletionItem(const QString& displayed, const QString& usedForCompletition, const QString& description = QString(), const QString& toolTip = QString(), const KIcon& icon = KIcon());
-
-        void findText(int* wordStart, int* wordEnd, QString* newWord, int cursorPos, const QString &input);
-
-    private:
-        KLineEdit* q;
-        QCompleter* m_completer;
-        QStandardItemModel* m_completionModel;
-        QString m_userText;
-        int m_wordStart;
-        int m_wordEnd;
-};
-
-/**
- * @brief Input box for searching files with Nepomuk.
- */
-class DolphinSearchBox : public QWidget
-{
+class DolphinSearchBox : public QWidget {
     Q_OBJECT
 
 public:
-    DolphinSearchBox(QWidget* parent = 0);
+    explicit DolphinSearchBox(QWidget* parent = 0);
     virtual ~DolphinSearchBox();
 
+    /**
+     * Returns the text that should be used as input
+     * for searching.
+     */
+    QString text() const;
+
+    /**
+     * Sets the current path that is used as root for
+     * searching files, if "From Here" has been selected.
+     */
+    void setSearchPath(const KUrl& url);
+    KUrl searchPath() const;
+
+    /** @return URL that will start the searching of files. */
+    KUrl urlForSearching() const;
+
+    /**
+     * Selects the whole text of the search box.
+     */
+    void selectAll();
+
 protected:
     virtual bool event(QEvent* event);
-    virtual bool eventFilter(QObject* watched, QEvent* event);
+    virtual void showEvent(QShowEvent* event);
+    virtual void keyReleaseEvent(QKeyEvent* event);
 
 signals:
     /**
-     * Is emitted when the user pressed Return or Enter
-     * and provides the Nepomuk URL that should be used
+     * Is emitted when a searching should be triggered
+     * and provides the text that should be used as input
      * for searching.
      */
-    void search(const KUrl& url);
+    void search(const QString& text);
+
+    /**
+     * Is emitted when the user has changed a character of
+     * the text that should be used as input for searching.
+     */
+    void searchTextChanged(const QString& text);
+
+    void returnPressed(const QString& text);
+
+    /**
+     * Emitted as soon as the search box should get closed.
+     */
+    void closeRequest();
 
 private slots:
     void emitSearchSignal();
-    void slotTextEdited(const QString& text);
+    void slotConfigurationChanged();
+    void slotSearchTextChanged(const QString& text);
+    void slotReturnPressed(const QString& text);
 
 private:
+    void initButton(QPushButton* button);
+    void loadSettings();
+    void saveSettings();
+    void init();
+
+    /**
+     * @return URL that represents the Nepomuk query for starting the search.
+     */
+    KUrl nepomukUrlForSearching() const;
+
+private:
+    bool m_startedSearching;
+    bool m_nepomukActivated;
+
+    QVBoxLayout* m_topLayout;
+
     KLineEdit* m_searchInput;
-    QToolButton* m_searchButton;
+    QPushButton* m_fileNameButton;
+    QPushButton* m_contentButton;
+    KSeparator* m_separator;
+    QPushButton* m_fromHereButton;
+    QPushButton* m_everywhereButton;
+
+    KUrl m_searchPath;
 
-    DolphinSearchCompleter* m_completer;
+    QTimer* m_startSearchTimer;
 };
 
 #endif