summaryrefslogtreecommitdiffstats
path: root/konq-plugins/searchbar/searchbar.h
blob: 3bd7ba7dec2e09d233543f6ac8dbcbafe99a6c7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* This file is part of the KDE project
   Copyright (C) 2005 by Tobi Vollebregt <tobivollebregt@gmail.com>
   Copyright (C) 2004 by Vinay Khaitan <vkhaitan@iitk.ac.in>
   Copyright (C) 2004 Arend van Beelen jr. <arend@auton.nl>

   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 the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef SEARCHBAR_PLUGIN
#define SEARCHBAR_PLUGIN

#include <kcombobox.h>
#include <klibloader.h>
#include <kparts/plugin.h>
#include <kparts/mainwindow.h>

#include <tqguardedptr.h>
#include <tqpixmap.h>
#include <tqstring.h>

class KHTMLPart;
class KProcess;
class TQPopupMenu;
class TQTimer;

/**
 * Combo box which catches mouse clicks on the pixmap.
 */
class SearchBarCombo : public KHistoryCombo
{
	Q_OBJECT
  

	public:
		/**
		 * Constructor.
		 */
		SearchBarCombo(TQWidget *parent, const char *name);

		/**
		 * Returns the icon currently displayed in the combo box.
		 */
		const TQPixmap &icon() const;

		/**
		 * Sets the icon displayed in the combo box.
		 */
		void setIcon(const TQPixmap &icon);

		/**
		 * Finds a history item by its text.
		 * @return The item number, or -1 if the item is not found.
		 */
		int findHistoryItem(const TQString &text);

		/**
		 * Sets whether the plugin is active. It can be inactive
		 * in case the current Konqueror part isn't a KHTML part.
		 */
		void setPluginActive(bool pluginActive);

	public slots:
		virtual void show();

	signals:
		/**
		 * Emitted when the icon was clicked.
		 */
		void iconClicked();

	protected:
		/**
		 * Captures mouse clicks and emits iconClicked() if the icon
		 * was clicked.
		 */
		virtual void mousePressEvent(TQMouseEvent *e);

	private slots:
		void historyCleared();

	private:
		TQPixmap m_icon;
		bool    m_pluginActive;
};

/**
 * Plugin that provides a search bar for Konqueror. This search bar is located
 * next to the location bar and will show a small icon indicating the search
 * provider it will use.
 *
 * @author Arend van Beelen jr. <arend@auton.nl>
 * @version $Id$
 */
class SearchBarPlugin : public KParts::Plugin
{
	Q_OBJECT
  

	public:
		/** Possible search modes */
		enum SearchModes { FindInThisPage = 0, UseSearchProvider };

		SearchBarPlugin(TQObject *parent, const char *name,
		                const TQStringList &);
		virtual ~SearchBarPlugin();

	protected:
		bool eventFilter(TQObject *o, TQEvent *e);

	private slots:
		/**
		 * Starts a search by putting the query URL from the selected
		 * search provider in the locationbar and calling goURL()
		 */
		void startSearch(const TQString &search);

		/**
		 * Sets the icon to indicate which search engine is used.
		 */
		void setIcon();

		/**
		 * Opens the selection menu.
		 */
		void showSelectionMenu();

		void useFindInThisPage();
		void useSearchProvider(int);
		void selectSearchEngines();
		void searchEnginesSelected(KProcess *process);
		void configurationChanged();

		/**
		 * We keep track of part activations to know when to show or hide ourselves
		 */
		void partChanged(KParts::Part *newPart);

		/**
		 * Show or hide the combo box
		 */
		void updateComboVisibility();

		void focusSearchbar();

		// Google Suggest private slots
		void selectGoogleSuggestMode();
		void gsStartDelay();
		void gsMakeCompletionList();
		void gsDataArrived(KIO::Job*, const TQByteArray& data);
		void gsJobFinished(KIO::Job* job);
		void gsSetCompletedText(const TQString& text);
		void gsPutTextInBox(const TQString& text);

	signals:

		// Google Suggest signals

		void gsCompleteDelayed();

	private:
		void nextSearchEntry();
		void previousSearchEntry();

		TQGuardedPtr<KHTMLPart> m_part;
		SearchBarCombo        *m_searchCombo;
                KWidgetAction         *m_searchComboAction;
		TQPopupMenu            *m_popupMenu;
		KSelectAction         *m_googleMenu;
		TQPixmap                m_searchIcon;
		SearchModes            m_searchMode;
		TQString                m_providerName;
		bool                   m_urlEnterLock;
		TQString                m_currentEngine;
		TQStringList            m_searchEngines;

		// Google Suggest private members

		TQTimer                 m_gsTimer;
		TQString                m_gsData;
		enum GoogleMode        {GoogleOnly,ForAll,Never};
		GoogleMode             m_googleMode;
};

#endif // SEARCHBAR_PLUGIN