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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/***************************************************************************
* Copyright (C) 2005 by Joris Guisson, Ivan Vasic *
* [email protected] *
* [email protected] *
* *
* 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; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <kapplication.h>
#include <khtmlview.h>
#include <tqlayout.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kglobal.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <kcombobox.h>
#include <kpopupmenu.h>
#include <kparts/partmanager.h>
#include <kio/job.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <kprogress.h>
#include <util/log.h>
#include <torrent/globals.h>
#include <interfaces/guiinterface.h>
#include <interfaces/coreinterface.h>
#include "searchwidget.h"
#include "searchbar.h"
#include "htmlpart.h"
#include "searchplugin.h"
#include "searchenginelist.h"
using namespace bt;
namespace kt
{
SearchWidget::SearchWidget(SearchPlugin* sp) : html_part(0),sp(sp)
{
TQVBoxLayout* tqlayout = new TQVBoxLayout(this);
tqlayout->setAutoAdd(true);
sbar = new SearchBar(this);
html_part = new HTMLPart(this);
right_click_menu = new KPopupMenu(this);
right_click_menu->insertSeparator();
back_id = right_click_menu->insertItem(
KGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
? "forward" : "back",KIcon::Small),
i18n("Back"),html_part,TQT_SLOT(back()));
right_click_menu->insertItem(
KGlobal::iconLoader()->loadIconSet("reload",KIcon::Small),
i18n("Reload"),html_part,TQT_SLOT(reload()));
right_click_menu->setItemEnabled(back_id,false);
sbar->m_back->setEnabled(false);
connect(sbar->m_search_button,TQT_SIGNAL(clicked()),this,TQT_SLOT(searchPressed()));
connect(sbar->m_clear_button,TQT_SIGNAL(clicked()),this,TQT_SLOT(clearPressed()));
connect(sbar->m_search_text,TQT_SIGNAL(returnPressed()),this,TQT_SLOT(searchPressed()));
connect(sbar->m_back,TQT_SIGNAL(clicked()),html_part,TQT_SLOT(back()));
connect(sbar->m_reload,TQT_SIGNAL(clicked()),html_part,TQT_SLOT(reload()));
sbar->m_clear_button->setIconSet(
KGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
? "clear_left" : "locationbar_erase",KIcon::Small));
sbar->m_back->setIconSet(
KGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
? "forward" : "back", KIcon::Small));
sbar->m_reload->setIconSet(
KGlobal::iconLoader()->loadIconSet("reload",KIcon::Small));
connect(html_part,TQT_SIGNAL(backAvailable(bool )),
this,TQT_SLOT(onBackAvailable(bool )));
connect(html_part,TQT_SIGNAL(onURL(const TQString& )),
this,TQT_SLOT(onURLHover(const TQString& )));
connect(html_part,TQT_SIGNAL(openTorrent(const KURL& )),
this,TQT_SLOT(onOpenTorrent(const KURL& )));
connect(html_part,TQT_SIGNAL(popupMenu(const TQString&, const TQPoint& )),
this,TQT_SLOT(showPopupMenu(const TQString&, const TQPoint& )));
connect(html_part,TQT_SIGNAL(searchFinished()),this,TQT_SLOT(onFinished()));
connect(html_part,TQT_SIGNAL(saveTorrent(const KURL& )),
this,TQT_SLOT(onSaveTorrent(const KURL& )));
KParts::PartManager* pman = html_part->partManager();
connect(pman,TQT_SIGNAL(partAdded(KParts::Part*)),this,TQT_SLOT(onFrameAdded(KParts::Part* )));
connect(html_part->browserExtension(),TQT_SIGNAL(loadingProgress(int)),this,TQT_SLOT(loadingProgress(int)));
prog = 0;
}
SearchWidget::~SearchWidget()
{
if (prog)
{
sp->getGUI()->removeProgressBarFromStatusBar(prog);
prog = 0;
}
}
void SearchWidget::updateSearchEngines(const SearchEngineList & sl)
{
int ci = sbar->m_search_engine->currentItem();
sbar->m_search_engine->clear();
for (Uint32 i = 0;i < sl.getNumEngines();i++)
{
sbar->m_search_engine->insertItem(sl.getEngineName(i));
}
sbar->m_search_engine->setCurrentItem(ci);
}
void SearchWidget::onBackAvailable(bool available)
{
sbar->m_back->setEnabled(available);
right_click_menu->setItemEnabled(back_id,available);
}
void SearchWidget::onFrameAdded(KParts::Part* p)
{
KHTMLPart* frame = dynamic_cast<KHTMLPart*>(p);
if (frame)
{
connect(frame,TQT_SIGNAL(popupMenu(const TQString&, const TQPoint& )),
this,TQT_SLOT(showPopupMenu(const TQString&, const TQPoint& )));
}
}
void SearchWidget::copy()
{
if (!html_part)
return;
html_part->copy();
}
void SearchWidget::search(const TQString & text,int engine)
{
if (!html_part)
return;
if (sbar->m_search_text->text() != text)
sbar->m_search_text->setText(text);
if (sbar->m_search_engine->currentItem() != engine)
sbar->m_search_engine->setCurrentItem(engine);
const SearchEngineList & sl = sp->getSearchEngineList();
if (engine < 0 || (Uint32)engine >= sl.getNumEngines())
engine = sbar->m_search_engine->currentItem();
TQString s_url = sl.getSearchURL(engine).prettyURL();
s_url.tqreplace("FOOBAR", KURL::encode_string(text), true);
KURL url = KURL::fromPathOrURL(s_url);
statusBarMsg(i18n("Searching for %1...").tqarg(text));
//html_part->openURL(url);
html_part->openURLRequest(url,KParts::URLArgs());
}
void SearchWidget::searchPressed()
{
search(sbar->m_search_text->text(),sbar->m_search_engine->currentItem());
}
void SearchWidget::clearPressed()
{
sbar->m_search_text->clear();
}
void SearchWidget::onURLHover(const TQString & url)
{
statusBarMsg(url);
}
void SearchWidget::onFinished()
{
}
void SearchWidget::onOpenTorrent(const KURL & url)
{
openTorrent(url);
}
void SearchWidget::onSaveTorrent(const KURL & url)
{
KFileDialog fdlg(TQString(),"*.torrent | " + i18n("torrent files"),this,0,true);
fdlg.setSelection(url.fileName());
fdlg.setOperationMode(KFileDialog::Saving);
if (fdlg.exec() == TQDialog::Accepted)
{
KURL save_url = fdlg.selectedURL();
// start a copy job
KIO::Job* j = KIO::file_copy(url,save_url,-1,true);
// let it deal with the errors
j->setAutoErrorHandlingEnabled(true,0);
}
}
void SearchWidget::showPopupMenu(const TQString & url,const TQPoint & p)
{
right_click_menu->popup(p);
}
KPopupMenu* SearchWidget::rightClickMenu()
{
return right_click_menu;
}
void SearchWidget::onShutDown()
{
delete html_part;
html_part = 0;
}
void SearchWidget::statusBarMsg(const TQString & url)
{
sp->getGUI()->changeStatusbar(url);
}
void SearchWidget::openTorrent(const KURL & url)
{
sp->getCore()->load(url);
}
void SearchWidget::loadingProgress(int perc)
{
if (perc < 100 && !prog)
{
prog = sp->getGUI()->addProgressBarToStatusBar();
if (prog)
prog->setValue(perc);
}
else if (prog && perc < 100)
{
prog->setValue(perc);
}
else if (perc == 100)
{
if (prog)
{
sp->getGUI()->removeProgressBarFromStatusBar(prog);
prog = 0;
}
statusBarMsg(i18n("Search finished"));
}
}
}
#include "searchwidget.moc"
|