summaryrefslogtreecommitdiffstats
path: root/src/plugins/search
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2025-03-02 18:37:22 +0900
committerMichele Calgaro <[email protected]>2025-03-06 12:31:12 +0900
commit44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8 (patch)
tree2b29e921a9bccea53444ed9bbed06a25a5fe20cc /src/plugins/search
parentd1f24dae035c506d945ca13f2be398aa0a4de8cc (diff)
downloadktorrent-master.tar.gz
ktorrent-master.zip
Restructure source files into 'src' subfolderHEADmaster
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/plugins/search')
-rw-r--r--src/plugins/search/Makefile.am28
-rw-r--r--src/plugins/search/htmlpart.cpp198
-rw-r--r--src/plugins/search/htmlpart.h73
-rw-r--r--src/plugins/search/ktsearchplugin.desktop60
-rw-r--r--src/plugins/search/ktsearchplugin.kcfg30
-rw-r--r--src/plugins/search/searchbar.ui110
-rw-r--r--src/plugins/search/searchenginelist.cpp137
-rw-r--r--src/plugins/search/searchenginelist.h60
-rw-r--r--src/plugins/search/searchplugin.cpp157
-rw-r--r--src/plugins/search/searchplugin.h67
-rw-r--r--src/plugins/search/searchpluginsettings.kcfgc7
-rw-r--r--src/plugins/search/searchpref.ui312
-rw-r--r--src/plugins/search/searchprefpage.cpp284
-rw-r--r--src/plugins/search/searchprefpage.h79
-rw-r--r--src/plugins/search/searchtab.cpp169
-rw-r--r--src/plugins/search/searchtab.h78
-rw-r--r--src/plugins/search/searchwidget.cpp272
-rw-r--r--src/plugins/search/searchwidget.h90
18 files changed, 2211 insertions, 0 deletions
diff --git a/src/plugins/search/Makefile.am b/src/plugins/search/Makefile.am
new file mode 100644
index 0000000..9e5b312
--- /dev/null
+++ b/src/plugins/search/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = -I$(srcdir)/../../libktorrent $(all_includes)
+METASOURCES = AUTO
+kde_module_LTLIBRARIES = ktsearchplugin.la
+noinst_HEADERS = searchplugin.h searchprefpage.h searchtab.h searchenginelist.h
+ktsearchplugin_la_SOURCES = searchplugin.cpp htmlpart.cpp searchbar.ui \
+ searchpref.ui searchwidget.cpp searchprefpage.cpp searchpluginsettings.kcfgc \
+ searchtab.cpp searchenginelist.cpp
+
+# Libs needed by the plugin
+ktsearchplugin_la_LIBADD = ../../libktorrent/libktorrent.la \
+ $(LIB_TDEHTML) $(LIB_TDEPARTS) $(LIB_TQT) \
+ $(LIB_TDECORE) $(LIB_TDEUI) $(LIB_TDEFILE)
+
+# LD flags for the plugin
+# -module says: this is a module, i.e. something you're going to dlopen
+# so e.g. it has no version number like a normal shared lib would have.
+ktsearchplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+# rc file containing the GUI for the plugin
+# pluginsdir = $(kde_datadir)/ktsearchplugin
+# plugins_DATA = ktsearchpluginui.rc
+
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = ktsearchplugin.desktop
+
+kde_kcfg_DATA = ktsearchplugin.kcfg
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/src/plugins/search/htmlpart.cpp b/src/plugins/search/htmlpart.cpp
new file mode 100644
index 0000000..1f3a50d
--- /dev/null
+++ b/src/plugins/search/htmlpart.cpp
@@ -0,0 +1,198 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <tdemessagebox.h>
+#include <tdeio/job.h>
+#include <tdeio/jobclasses.h>
+//#include <tqfile.h>
+#include <tqclipboard.h>
+#include <tqapplication.h>
+#include <tdeio/netaccess.h>
+#include <tdelocale.h>
+#include <tdefiledialog.h>
+#include <tdeparts/browserextension.h>
+#include <util/constants.h>
+#include <tdehtmlview.h>
+#include "htmlpart.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+ HTMLPart::HTMLPart(TQWidget *parent)
+ : TDEHTMLPart(parent)
+ {
+ setJScriptEnabled(true);
+ setJavaEnabled(true);
+ setMetaRefreshEnabled(true);
+ setPluginsEnabled(false);
+ setStatusMessagesEnabled(false);
+ KParts::BrowserExtension* ext = this->browserExtension();
+ connect(ext,TQ_SIGNAL(openURLRequest(const KURL&,const KParts::URLArgs&)),
+ this,TQ_SLOT(openURLRequest(const KURL&, const KParts::URLArgs& )));
+
+ ext->enableAction("copy",true);
+ ext->enableAction("paste",true);
+ active_job = 0;
+ }
+
+
+ HTMLPart::~HTMLPart()
+ {}
+
+ void HTMLPart::copy()
+ {
+ TQString txt = selectedText();
+ TQClipboard *cb = TQApplication::clipboard();
+ // Copy text into the clipboard
+ if (cb)
+ cb->setText(txt,TQClipboard::Clipboard);
+ }
+
+ void HTMLPart::openURLRequest(const KURL &u,const KParts::URLArgs &)
+ {
+ if (active_job)
+ {
+ active_job->kill(true);
+ active_job = 0;
+ }
+
+ TDEIO::TransferJob* j = TDEIO::get(u,false,false);
+ connect(j,TQ_SIGNAL(data(TDEIO::Job*,const TQByteArray &)),
+ this,TQ_SLOT(dataRecieved(TDEIO::Job*, const TQByteArray& )));
+ connect(j,TQ_SIGNAL(result(TDEIO::Job*)),this,TQ_SLOT(jobDone(TDEIO::Job* )));
+ connect(j,TQ_SIGNAL(mimetype(TDEIO::Job*, const TQString &)),
+ this,TQ_SLOT(mimetype(TDEIO::Job*, const TQString& )));
+
+ active_job = j;
+ curr_data.resize(0);
+ mime_type = TQString();
+ curr_url = u;
+ }
+
+ void HTMLPart::back()
+ {
+ if (history.count() <= 1)
+ {
+ backAvailable(false);
+ }
+ else
+ {
+ history.pop_back();
+ KURL u = history.back();
+ openURL(u);
+ backAvailable(history.count() > 1 ? true : false);
+
+ }
+ }
+
+ void HTMLPart::addToHistory(const KURL & url)
+ {
+ history.append(url);
+ if (history.count() > 1)
+ backAvailable(true);
+ }
+
+ void HTMLPart::reload()
+ {
+ openURL(url());
+ }
+
+ void HTMLPart::dataRecieved(TDEIO::Job* job,const TQByteArray & data)
+ {
+ if (job != active_job)
+ {
+ job->kill(true);
+ return;
+ }
+
+ if (data.size() == 0)
+ return;
+
+ Uint32 off = curr_data.size();
+ curr_data.resize(curr_data.size() + data.size());
+ for (Uint32 i = 0;i < data.size();i++)
+ {
+ curr_data[i + off] = data[i];
+ }
+ }
+
+ void HTMLPart::mimetype(TDEIO::Job* job,const TQString & mt)
+ {
+ if (job != active_job)
+ {
+ job->kill(true);
+ return;
+ }
+
+ mime_type = mt;
+ }
+
+ void HTMLPart::jobDone(TDEIO::Job* job)
+ {
+ if (job != active_job)
+ {
+ job->kill(true);
+ return;
+ }
+
+ if (job->error() == 0)
+ {
+ bool is_bencoded_data = curr_data.size() > 0 &&
+ curr_data[0] == 'd' &&
+ curr_data[curr_data.size()-1] == 'e';
+
+ if (is_bencoded_data || mime_type == "application/x-bittorrent")
+ {
+ int ret = KMessageBox::questionYesNoCancel(0,
+ i18n("Do you want to download or save the torrent?"),
+ i18n("Download Torrent"),
+ KGuiItem(i18n("to download", "Download"),"go-down"),
+ KStdGuiItem::save());
+
+ if (ret == KMessageBox::Yes)
+ openTorrent(curr_url);
+ else if (ret == KMessageBox::No)
+ saveTorrent(curr_url);
+ }
+ else
+ {
+ addToHistory(curr_url);
+ begin(curr_url);
+ write(curr_data.data(),curr_data.size());
+ end();
+ view()->ensureVisible(0,0);
+ searchFinished();
+ }
+ }
+ else
+ {
+ begin(curr_url);
+ write(TDEIO::buildErrorString(job->error(),job->errorText()));/*,&curr_url));**/
+ end();
+ }
+ active_job = 0;
+ curr_data.resize(0);
+ curr_url = KURL();
+ mime_type = TQString();
+ }
+}
+
+#include "htmlpart.moc"
diff --git a/src/plugins/search/htmlpart.h b/src/plugins/search/htmlpart.h
new file mode 100644
index 0000000..5ed8f19
--- /dev/null
+++ b/src/plugins/search/htmlpart.h
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef HTMLPART_H
+#define HTMLPART_H
+
+#include <tdehtml_part.h>
+
+namespace TDEIO
+{
+ class Job;
+}
+
+
+namespace kt
+{
+
+ /**
+ @author Joris Guisson
+ */
+ class HTMLPart : public TDEHTMLPart
+ {
+ TQ_OBJECT
+
+ public:
+ HTMLPart(TQWidget *parent = 0);
+ virtual ~HTMLPart();
+
+ public slots:
+ void back();
+ void reload();
+ void copy();
+ void openURLRequest(const KURL &url, const KParts::URLArgs &args);
+
+ private slots:
+ void addToHistory(const KURL & url);
+ void dataRecieved(TDEIO::Job* job,const TQByteArray & data);
+ void mimetype(TDEIO::Job* job,const TQString & mt);
+ void jobDone(TDEIO::Job* job);
+
+
+ signals:
+ void backAvailable(bool yes);
+ void openTorrent(const KURL & url);
+ void saveTorrent(const KURL & url);
+ void searchFinished();
+
+ private:
+ KURL::List history;
+ TDEIO::Job* active_job;
+ TQByteArray curr_data;
+ TQString mime_type;
+ KURL curr_url;
+ };
+}
+
+#endif
diff --git a/src/plugins/search/ktsearchplugin.desktop b/src/plugins/search/ktsearchplugin.desktop
new file mode 100644
index 0000000..9feabe0
--- /dev/null
+++ b/src/plugins/search/ktsearchplugin.desktop
@@ -0,0 +1,60 @@
+[Desktop Entry]
+Name=SearchPlugin
+Name[bg]=Приставка за търсене
+Name[br]=Lugent klask
+Name[da]=SøgePlugin
+Name[de]=Suche-Modul
+Name[el]=Πρόσθετο αναζήτησης
+Name[es]=Complemento de búsqueda
+Name[et]=Otsimisplugin
+Name[fa]=وصلۀ جستجو
+Name[it]=Plugin di ricerca
+Name[nb]=Søkemodul
+Name[nds]=Söök-Moduul
+Name[nl]=Zoekplugin
+Name[pl]=Wtyczka wyszukiwania
+Name[pt]='Plugin' de Procura
+Name[pt_BR]=Plugin de Busca
+Name[sk]=Vyhľadávací Plugin
+Name[sr]=Прикључак претраге
+Name[sr@Latn]=Priključak pretrage
+Name[sv]=Sökinsticksprogram
+Name[tr]=Arama Eklentisi
+Name[uk]=Втулок пошуку
+Name[xx]=xxSearchPluginxx
+Name[zh_CN]=搜索插件
+Name[zh_TW]=搜尋外掛程式
+Comment=Search plugin for KTorrent
+Comment[ar]=قابس البحث لِــ KTorrent
+Comment[bg]=Приставка за търсене (KTorrent)
+Comment[br]=Lugent klask evit KTorrent
+Comment[ca]=Connector de cerca per a KTorrent
+Comment[cs]=Vyhledávací modul pro KTorrent
+Comment[da]=Søge-plugin for KTorrent
+Comment[de]=Suche-Modul für KTorrent
+Comment[el]=Πρόσθετο αναζήτησης για το KTorrent
+Comment[es]=Complemento de búsqueda para KTorrent
+Comment[et]=KTorrenti otsimisplugin
+Comment[fa]=وصلۀ جستجو برای KTorrent
+Comment[gl]=Plugin de procuras para KTorrent
+Comment[it]=Plugin di ricerca per KTorrent
+Comment[ja]=KTorrent のための検索プラグイン
+Comment[ka]=ძებნის მოდული KTorrent-თვის
+Comment[nb]=Søkemodul for KTorrent
+Comment[nds]=Söök-Moduul för KTorrent
+Comment[nl]=Zoekplugin voor KTorrent
+Comment[pl]=Wtyczka wyszukiwania dla KTorrent
+Comment[pt]='Plugin' de procura para o KTorrent
+Comment[pt_BR]=Busca de plug-in para o KTorrent
+Comment[sk]=Vyhľadávací plugin pre KTorrent
+Comment[sr]=Прикључак претраге за KTorrent
+Comment[sr@Latn]=Priključak pretrage za KTorrent
+Comment[sv]=Sökinsticksprogram för Ktorrent
+Comment[tr]=KTorrent için arama eklentisi
+Comment[uk]=Втулок пошуку для KTorrent
+Comment[xx]=xxSearch plugin for KTorrentxx
+Comment[zh_CN]=KTorrent 的搜索插件
+Comment[zh_TW]=KTorrent 搜尋外掛程式
+X-TDE-ServiceTypes=KTorrent/Plugin
+Type=Service
+X-TDE-Library=ktsearchplugin
diff --git a/src/plugins/search/ktsearchplugin.kcfg b/src/plugins/search/ktsearchplugin.kcfg
new file mode 100644
index 0000000..fdcc141
--- /dev/null
+++ b/src/plugins/search/ktsearchplugin.kcfg
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+
+ <kcfgfile name="ktsearchpluginrc"/>
+ <group name="general">
+ <entry name="searchEngine" type="Int">
+ <label>Current search engine</label>
+ <default>0</default>
+ </entry>
+
+ <entry name="useDefaultBrowser" type ="Bool">
+ <label>Use default browser</label>
+ <default>true</default>
+ </entry>
+ <entry name="useCustomBrowser" type ="Bool">
+ <label>Use custom browser</label>
+ <default>false</default>
+ </entry>
+ <entry name="customBrowser" type ="String">
+ <label>Custom browser executable path</label>
+ <default>/usr/bin/firefox</default>
+ </entry>
+ <entry name="openInExternal" type = "Bool">
+ <default>false</default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/src/plugins/search/searchbar.ui b/src/plugins/search/searchbar.ui
new file mode 100644
index 0000000..562a0dd
--- /dev/null
+++ b/src/plugins/search/searchbar.ui
@@ -0,0 +1,110 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>SearchBar</class>
+<widget class="TQWidget">
+ <property name="name">
+ <cstring>SearchBar</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>804</width>
+ <height>52</height>
+ </rect>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="KPushButton">
+ <property name="name">
+ <cstring>m_back</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KPushButton">
+ <property name="name">
+ <cstring>m_reload</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KPushButton">
+ <property name="name">
+ <cstring>m_clear_button</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KLineEdit">
+ <property name="name">
+ <cstring>m_search_text</cstring>
+ </property>
+ </widget>
+ <widget class="KPushButton">
+ <property name="name">
+ <cstring>m_search_button</cstring>
+ </property>
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Maximum</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>60</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Engine:</string>
+ </property>
+ </widget>
+ <widget class="KComboBox">
+ <property name="name">
+ <cstring>m_search_engine</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>150</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </hbox>
+</widget>
+<customwidgets>
+</customwidgets>
+<layoutdefaults spacing="6" margin="11"/>
+<includes>
+ <include location="global" impldecl="in implementation">kcombobox.h</include>
+ <include location="global" impldecl="in implementation">klineedit.h</include>
+ <include location="global" impldecl="in implementation">kpushbutton.h</include>
+</includes>
+</UI>
diff --git a/src/plugins/search/searchenginelist.cpp b/src/plugins/search/searchenginelist.cpp
new file mode 100644
index 0000000..3381bf0
--- /dev/null
+++ b/src/plugins/search/searchenginelist.cpp
@@ -0,0 +1,137 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <tqfile.h>
+#include <tqtextstream.h>
+#include <tqstringlist.h>
+#include "searchenginelist.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+ SearchEngineList::SearchEngineList()
+ {}
+
+
+ SearchEngineList::~SearchEngineList()
+ {}
+
+ void SearchEngineList::save(const TQString& file)
+ {
+ TQFile fptr(file);
+ if (!fptr.open(IO_WriteOnly))
+ return;
+
+ TQTextStream out(&fptr);
+ out << "# PLEASE DO NOT MODIFY THIS FILE. Use KTorrent configuration dialog for adding new search engines." << ::endl;
+ out << "# SEARCH ENGINES list" << ::endl;
+
+ TQValueList<SearchEngine>::iterator i = m_search_engines.begin();
+ while (i != m_search_engines.end())
+ {
+ SearchEngine & e = *i;
+
+ // replace spaces by %20
+ TQString name = e.name;
+ name = name.replace(" ","%20");
+ TQString u = e.url.prettyURL();
+ u = u.replace(" ","%20");
+ out << name << " " << u << ::endl;
+ i++;
+ }
+ }
+
+ void SearchEngineList::load(const TQString& file)
+ {
+ m_search_engines.clear();
+
+ TQFile fptr(file);
+
+ if(!fptr.exists())
+ makeDefaultFile(file);
+
+ if (!fptr.open(IO_ReadOnly))
+ return;
+
+ TQTextStream in(&fptr);
+
+ int id = 0;
+
+ while (!in.atEnd())
+ {
+ TQString line = in.readLine();
+
+ if(line.startsWith("#") || line.startsWith(" ") || line.isEmpty() ) continue;
+
+ TQStringList tokens = TQStringList::split(" ", line);
+
+ SearchEngine se;
+ se.name = tokens[0];
+ se.name = se.name.replace("%20"," ");
+ se.url = KURL::fromPathOrURL(tokens[1]);
+
+ for(Uint32 i=2; i<tokens.count(); ++i)
+ se.url.addQueryItem(tokens[i].section("=",0,0), tokens[i].section("=", 1, 1));
+
+ m_search_engines.append(se);
+ }
+ }
+
+ void SearchEngineList::makeDefaultFile(const TQString& file)
+ {
+ TQFile fptr(file);
+ if (!fptr.open(IO_WriteOnly))
+ return;
+
+ TQTextStream out(&fptr);
+ out << "# PLEASE DO NOT MODIFY THIS FILE. Use KTorrent configuration dialog for adding new search engines." << ::endl;
+ out << "# SEARCH ENGINES list" << ::endl;
+ out << "isohunt.to http://isohunt.to/torrents/?ihq=FOOBAR" << ::endl;
+ out << "mininova.org http://www.mininova.org/search.php?search=FOOBAR" << ::endl;
+ out << "thepiratebay.se http://thepiratebay.se/search.php?q=FOOBAR" << ::endl;
+ out << "kickass.to http://kickass.to/usearch/FOOBAR" << ::endl;
+ out << "torrentfunk.com http://www.torrentfunk.com/all/torrents/FOOBAR.html" << ::endl;
+ out << "yourbittorrent.com http://yourbittorrent.com/?q=FOOBAR" << ::endl;
+ out << "torlock.com http://www.torlock.com/all/torrents/FOOBAR.html" << ::endl;
+ out << "torrentz.eu http://torrentz.eu/search?f=FOOBAR" << ::endl;
+ out << "torrentcrazy.com http://torrentcrazy.com/s/FOOBAR" << ::endl;
+ out << "bitsnoop.com http://bitsnoop.com/search/all/FOOBAR/c/d/1/" << ::endl;
+ out << "torrents.net http://www.torrents.net/find/FOOBAR/" << ::endl;
+ out << "btmon.com http://www.btmon.com/torrent/?f=FOOBAR" << ::endl;
+ }
+
+ KURL SearchEngineList::getSearchURL(bt::Uint32 engine) const
+ {
+ if (engine >= m_search_engines.count())
+ return KURL();
+ else
+ return m_search_engines[engine].url;
+ }
+
+ TQString SearchEngineList::getEngineName(bt::Uint32 engine) const
+ {
+ if (engine >= m_search_engines.count())
+ return TQString();
+ else
+ return m_search_engines[engine].name;
+ }
+
+}
diff --git a/src/plugins/search/searchenginelist.h b/src/plugins/search/searchenginelist.h
new file mode 100644
index 0000000..4b4d68e
--- /dev/null
+++ b/src/plugins/search/searchenginelist.h
@@ -0,0 +1,60 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef KTSEARCHENGINELIST_H
+#define KTSEARCHENGINELIST_H
+
+#include <kurl.h>
+#include <tqvaluelist.h>
+#include <util/constants.h>
+
+namespace kt
+{
+
+
+ /**
+ @author Joris Guisson <[email protected]>
+ */
+ class SearchEngineList
+ {
+ struct SearchEngine
+ {
+ TQString name;
+ KURL url;
+ };
+
+ TQValueList<SearchEngine> m_search_engines;
+ public:
+ SearchEngineList();
+ virtual ~SearchEngineList();
+
+ void save(const TQString& file);
+ void load(const TQString& file);
+ void makeDefaultFile(const TQString& file);
+
+ KURL getSearchURL(bt::Uint32 engine) const;
+ TQString getEngineName(bt::Uint32 engine) const;
+
+ /// Get the number of engines
+ bt::Uint32 getNumEngines() const {return m_search_engines.count();}
+ };
+
+}
+
+#endif
diff --git a/src/plugins/search/searchplugin.cpp b/src/plugins/search/searchplugin.cpp
new file mode 100644
index 0000000..dc62c6c
--- /dev/null
+++ b/src/plugins/search/searchplugin.cpp
@@ -0,0 +1,157 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <kgenericfactory.h>
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kiconloader.h>
+#include <kstdaction.h>
+#include <tdepopupmenu.h>
+#include <tdeapplication.h>
+#include <tdestandarddirs.h>
+#include <krun.h>
+#include <interfaces/guiinterface.h>
+#include "searchplugin.h"
+#include "searchwidget.h"
+#include "searchprefpage.h"
+#include "searchtab.h"
+#include "searchpluginsettings.h"
+#include "searchenginelist.h"
+
+
+#define NAME "Search"
+#define AUTHOR "Joris Guisson"
+#define EMAIL "[email protected]"
+
+
+
+K_EXPORT_COMPONENT_FACTORY(ktsearchplugin,KGenericFactory<kt::SearchPlugin>("ktsearchplugin"))
+
+namespace kt
+{
+
+ SearchPlugin::SearchPlugin(TQObject* parent, const char* name, const TQStringList& args)
+ : Plugin(parent, name, args,NAME,i18n("Search"),AUTHOR,EMAIL,
+ i18n("Search for torrents on several popular torrent search engines"),"viewmag")
+ {
+ // setXMLFile("ktsearchpluginui.rc");
+ pref = 0;
+ tab = 0;
+ }
+
+
+ SearchPlugin::~SearchPlugin()
+ {}
+
+
+ void SearchPlugin::load()
+ {
+ engines.load(TDEGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines");
+ TDEToolBar* tb = getGUI()->addToolBar("search");
+ tab = new SearchTab(tb);
+ connect(tab,TQ_SIGNAL(search( const TQString&, int, bool )),
+ this,TQ_SLOT(search( const TQString&, int, bool )));
+
+ pref = new SearchPrefPage(this);
+ getGUI()->addPrefPage(pref);
+ pref->updateData();
+ tab->updateSearchEngines(engines);
+ }
+
+ void SearchPlugin::unload()
+ {
+ tab->saveSettings();
+ SearchWidget* s = 0;
+ while ((s = searches.first()) != 0)
+ {
+ getGUI()->removeTabPage(s);
+ searches.removeFirst();
+ delete s;
+ }
+ getGUI()->removeToolBar(tab->getToolBar());
+ getGUI()->removePrefPage(pref);
+ delete pref;
+ pref = 0;
+ delete tab;
+ tab = 0;
+ }
+
+ void SearchPlugin::search(const TQString & text,int engine,bool external)
+ {
+ if(external)
+ {
+ const SearchEngineList& sl = getSearchEngineList();
+
+ if (engine < 0 || engine >= sl.getNumEngines())
+ engine = 0;
+
+ TQString s_url = sl.getSearchURL(engine).prettyURL();
+ s_url.replace("FOOBAR", KURL::encode_string(text), true);
+ KURL url = KURL::fromPathOrURL(s_url);
+
+ if(SearchPluginSettings::useDefaultBrowser())
+ tdeApp->invokeBrowser(url.url());
+ else
+ KRun::runCommand(TQString("%1 \"%2\"").arg(SearchPluginSettings::customBrowser()).arg(url.url()), SearchPluginSettings::customBrowser(), "viewmag" );
+
+ return;
+ }
+
+ TDEIconLoader* iload = TDEGlobal::iconLoader();
+
+ SearchWidget* search = new SearchWidget(this);
+ getGUI()->addTabPage(search,iload->loadIconSet("viewmag", TDEIcon::Small),text,this);
+
+ TDEAction* copy_act = KStdAction::copy(search,TQ_SLOT(copy()),actionCollection());
+ copy_act->plug(search->rightClickMenu(),0);
+ searches.append(search);
+
+ search->updateSearchEngines(engines);
+ search->search(text,engine);
+ }
+
+ void SearchPlugin::preferencesUpdated()
+ {
+ engines.load(TDEGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines");
+ if (tab)
+ tab->updateSearchEngines(engines);
+
+ for (TQPtrList<SearchWidget>::iterator i = searches.begin(); i != searches.end();i++)
+ {
+ SearchWidget* w = *i;
+ w->updateSearchEngines(engines);
+ }
+ }
+
+ void SearchPlugin::tabCloseRequest(kt::GUIInterface* gui,TQWidget* tab)
+ {
+ if (searches.contains((SearchWidget*)tab))
+ {
+ searches.remove((SearchWidget*)tab);
+ gui->removeTabPage(tab);
+ tab->deleteLater();
+ }
+ }
+
+ bool SearchPlugin::versionCheck(const TQString & version) const
+ {
+ return version == KT_VERSION_MACRO;
+ }
+}
+#include "searchplugin.moc"
diff --git a/src/plugins/search/searchplugin.h b/src/plugins/search/searchplugin.h
new file mode 100644
index 0000000..f7f41e7
--- /dev/null
+++ b/src/plugins/search/searchplugin.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef KTSEARCHPLUGIN_H
+#define KTSEARCHPLUGIN_H
+
+#include <tqptrlist.h>
+#include <interfaces/plugin.h>
+#include <interfaces/guiinterface.h>
+#include "searchenginelist.h"
+
+namespace kt
+{
+ class SearchWidget;
+ class SearchPrefPage;
+ class SearchTab;
+
+ /**
+ @author Joris Guisson
+ */
+ class SearchPlugin : public Plugin, public kt::CloseTabListener
+ {
+ TQ_OBJECT
+
+ public:
+ SearchPlugin(TQObject* parent, const char* name, const TQStringList& args);
+ virtual ~SearchPlugin();
+
+ virtual void load();
+ virtual void unload();
+ virtual bool versionCheck(const TQString& version) const;
+
+ void preferencesUpdated();
+
+ const SearchEngineList & getSearchEngineList() const {return engines;}
+ private slots:
+ void search(const TQString & text,int engine,bool external);
+
+ private:
+ virtual void tabCloseRequest(kt::GUIInterface* gui,TQWidget* tab);
+
+ private:
+ SearchPrefPage* pref;
+ SearchTab* tab;
+ SearchEngineList engines;
+ TQPtrList<SearchWidget> searches;
+ };
+
+}
+
+#endif
diff --git a/src/plugins/search/searchpluginsettings.kcfgc b/src/plugins/search/searchpluginsettings.kcfgc
new file mode 100644
index 0000000..09cfd64
--- /dev/null
+++ b/src/plugins/search/searchpluginsettings.kcfgc
@@ -0,0 +1,7 @@
+# Code generation options for tdeconfig_compiler
+File=ktsearchplugin.kcfg
+ClassName=SearchPluginSettings
+Namespace=kt
+Singleton=true
+Mutators=true
+# will create the necessary code for setting those variables
diff --git a/src/plugins/search/searchpref.ui b/src/plugins/search/searchpref.ui
new file mode 100644
index 0000000..0c169bf
--- /dev/null
+++ b/src/plugins/search/searchpref.ui
@@ -0,0 +1,312 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>SEPreferences</class>
+<widget class="TQWidget">
+ <property name="name">
+ <cstring>SEPreferences</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>529</width>
+ <height>515</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>500</width>
+ <height>350</height>
+ </size>
+ </property>
+ <property name="caption">
+ <string>Search Preferences</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQButtonGroup">
+ <property name="name">
+ <cstring>buttonGroup1</cstring>
+ </property>
+ <property name="title">
+ <string>External Browser</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQCheckBox">
+ <property name="name">
+ <cstring>openExternal</cstring>
+ </property>
+ <property name="text">
+ <string>Open searches in external browser</string>
+ </property>
+ </widget>
+ <widget class="TQRadioButton">
+ <property name="name">
+ <cstring>useDefaultBrowser</cstring>
+ </property>
+ <property name="text">
+ <string>Use default browser</string>
+ </property>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>layout29</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQRadioButton">
+ <property name="name">
+ <cstring>useCustomBrowser</cstring>
+ </property>
+ <property name="text">
+ <string>Custom browser path:</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit">
+ <property name="name">
+ <cstring>customBrowser</cstring>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer20</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="TQGroupBox">
+ <property name="name">
+ <cstring>groupBox8</cstring>
+ </property>
+ <property name="title">
+ <string>Search Engines</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="KActiveLabel">
+ <property name="name">
+ <cstring>m_infoLabel</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>layout22</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>Search engine name:</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit">
+ <property name="name">
+ <cstring>m_engine_name</cstring>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>layout23</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel4</cstring>
+ </property>
+ <property name="text">
+ <string>URL:</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit">
+ <property name="name">
+ <cstring>m_engine_url</cstring>
+ </property>
+ </widget>
+ <widget class="TQPushButton">
+ <property name="name">
+ <cstring>btnAdd</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Add</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="TQListView">
+ <column>
+ <property name="text">
+ <string>Engines</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>URL</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <property name="name">
+ <cstring>m_engines</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>50</height>
+ </size>
+ </property>
+ <property name="resizeMode">
+ <enum>AllColumns</enum>
+ </property>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>layout5</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQPushButton">
+ <property name="name">
+ <cstring>btnRemove</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Remove</string>
+ </property>
+ </widget>
+ <widget class="TQPushButton">
+ <property name="name">
+ <cstring>btnRemoveAll</cstring>
+ </property>
+ <property name="text">
+ <string>R&amp;emove All</string>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer19</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Maximum</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>16</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="TQPushButton">
+ <property name="name">
+ <cstring>btn_add_default</cstring>
+ </property>
+ <property name="text">
+ <string>Add Defau&amp;lt</string>
+ </property>
+ </widget>
+ <widget class="KPushButton">
+ <property name="name">
+ <cstring>btnUpdate</cstring>
+ </property>
+ <property name="text">
+ <string>Update From Internet</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ </vbox>
+</widget>
+<customwidgets>
+</customwidgets>
+<connections>
+ <connection>
+ <sender>btnUpdate</sender>
+ <signal>clicked()</signal>
+ <receiver>SEPreferences</receiver>
+ <slot>btnUpdate_clicked()</slot>
+ </connection>
+</connections>
+<slots>
+ <slot>btnUpdate_clicked()</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+<includes>
+ <include location="global" impldecl="in implementation">kactivelabel.h</include>
+ <include location="global" impldecl="in implementation">klineedit.h</include>
+ <include location="global" impldecl="in implementation">kpushbutton.h</include>
+</includes>
+</UI>
diff --git a/src/plugins/search/searchprefpage.cpp b/src/plugins/search/searchprefpage.cpp
new file mode 100644
index 0000000..89246bc
--- /dev/null
+++ b/src/plugins/search/searchprefpage.cpp
@@ -0,0 +1,284 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson, Ivan Vasic *
+ * *
+ * 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 <kurl.h>
+#include <tqtooltip.h>
+#include <tqfile.h>
+#include <tdelocale.h>
+#include <tdeglobal.h>
+#include <tdestandarddirs.h>
+#include <kiconloader.h>
+#include <kactivelabel.h>
+#include <kpushbutton.h>
+#include <tdelistview.h>
+#include <klineedit.h>
+#include <tdemessagebox.h>
+#include <tdeio/netaccess.h>
+#include <klineedit.h>
+
+#include <tqlabel.h>
+#include <tqcheckbox.h>
+#include <tqradiobutton.h>
+
+#include <util/constants.h>
+#include "searchprefpage.h"
+#include "searchplugin.h"
+#include "searchenginelist.h"
+#include "searchpluginsettings.h"
+
+using namespace bt;
+
+namespace kt
+{
+ SearchPrefPageWidget::SearchPrefPageWidget(TQWidget *parent) : SEPreferences(parent)
+ {
+ TQString info = i18n("Use your web browser to search for the string %1"
+ " (capital letters) on the search engine you want to add. <br> "
+ "Then copy the URL in the addressbar after the search is finished, and paste it here.<br><br>Searching for %1"
+ " on Google for example, will result in http://www.google.com/search?q=FOOBAR&ie=UTF-8&oe=UTF-8. <br> "
+ "If you add this URL here, ktorrent can search using Google.").arg("FOOBAR").arg("FOOBAR");
+ TQString info_short = i18n("Use your web browser to search for the string %1 (capital letters) "
+ "on the search engine you want to add. Use the resulting URL below.").arg("FOOBAR");
+ m_infoLabel->setText(info_short);
+ TQToolTip::add(m_infoLabel,info);
+ TQToolTip::add(m_engine_name,info);
+
+ connect(btnAdd, TQ_SIGNAL(clicked()), this, TQ_SLOT(addClicked()));
+ connect(btnRemove, TQ_SIGNAL(clicked()), this, TQ_SLOT(removeClicked()));
+ connect(btn_add_default, TQ_SIGNAL(clicked()), this, TQ_SLOT(addDefaultClicked()));
+ connect(btnRemoveAll, TQ_SIGNAL(clicked()), this, TQ_SLOT(removeAllClicked()));
+
+ connect(useCustomBrowser, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(customToggled( bool )));
+
+ useCustomBrowser->setChecked(SearchPluginSettings::useCustomBrowser());
+ useDefaultBrowser->setChecked(SearchPluginSettings::useDefaultBrowser());
+ customBrowser->setText(SearchPluginSettings::customBrowser());
+
+ customBrowser->setEnabled(useCustomBrowser->isChecked());
+ openExternal->setChecked(SearchPluginSettings::openInExternal());
+ }
+
+ void SearchPrefPageWidget::updateSearchEngines(const SearchEngineList & se)
+ {
+ m_engines->clear();
+
+ for (Uint32 i = 0;i < se.getNumEngines();i++)
+ {
+ new TQListViewItem(m_engines,se.getEngineName(i),se.getSearchURL(i).prettyURL());
+ }
+ }
+
+ bool SearchPrefPageWidget::apply()
+ {
+ saveSearchEngines();
+
+ SearchPluginSettings::setUseCustomBrowser(useCustomBrowser->isChecked());
+ SearchPluginSettings::setUseDefaultBrowser(useDefaultBrowser->isChecked());
+ SearchPluginSettings::setCustomBrowser(customBrowser->text());
+ SearchPluginSettings::setOpenInExternal(openExternal->isChecked());
+ SearchPluginSettings::writeConfig();
+ return true;
+ }
+
+ void SearchPrefPageWidget::saveSearchEngines()
+ {
+ TQFile fptr(TDEGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines");
+ if (!fptr.open(IO_WriteOnly))
+ return;
+ TQTextStream out(&fptr);
+ out << "# PLEASE DO NOT MODIFY THIS FILE. Use KTorrent configuration dialog for adding new search engines." << ::endl;
+ out << "# SEARCH ENGINES list" << ::endl;
+
+ TQListViewItemIterator itr(m_engines);
+ while (itr.current())
+ {
+ TQListViewItem* item = itr.current();
+ TQString u = item->text(1);
+ TQString name = item->text(0);
+ out << name.replace(" ","%20") << " " << u.replace(" ","%20") << endl;
+ itr++;
+ }
+ }
+
+ void SearchPrefPageWidget::addClicked()
+ {
+ if ( m_engine_url->text().isEmpty() || m_engine_name->text().isEmpty() )
+ {
+ KMessageBox::error(this, i18n("You must enter the search engine's name and URL"));
+ }
+ else if ( m_engine_url->text().contains("FOOBAR") )
+ {
+ KURL url = KURL::fromPathOrURL(m_engine_url->text());
+ if ( !url.isValid() )
+ {
+ KMessageBox::error(this, i18n("Malformed URL."));
+ return;
+ }
+
+ if (m_engines->findItem(m_engine_name->text(), 0))
+ {
+ KMessageBox::error(this, i18n("A search engine with the same name already exists. Please use a different name.")); return;
+ }
+
+ new TQListViewItem(m_engines, m_engine_name->text(), m_engine_url->text());
+ m_engine_url->setText("");
+ m_engine_name->setText("");
+ }
+ else
+ {
+ KMessageBox::error(this, i18n("Bad URL. You should search for FOOBAR with your Internet browser and copy/paste the exact URL here."));
+ }
+ }
+
+ void SearchPrefPageWidget::removeClicked()
+ {
+ if ( m_engines->selectedItem() == 0 )
+ return;
+
+ TQListViewItem* item = m_engines->selectedItem();
+ m_engines->takeItem(item);
+ delete item;
+ }
+
+ void SearchPrefPageWidget::addDefaultClicked()
+ {
+ TQListViewItem* se = new TQListViewItem(m_engines, "isohunt.to", "http://isohunt.to/torrents/?ihq=FOOBAR");
+ se = new TQListViewItem(m_engines, "mininova.org", "http://www.mininova.org/search.php?search=FOOBAR");
+ se = new TQListViewItem(m_engines, "thepiratebay.se", "http://thepiratebay.se/search.php?q=FOOBAR");
+ se = new TQListViewItem(m_engines, "kickass.to", "http://kickass.to/usearch/FOOBAR");
+ se = new TQListViewItem(m_engines, "torrentfunk.com", "http://www.torrentfunk.com/all/torrents/FOOBAR.html");
+ se = new TQListViewItem(m_engines, "yourbittorrent.com", "http://yourbittorrent.com/?q=FOOBAR");
+ se = new TQListViewItem(m_engines, "torlock.com", "http://www.torlock.com/all/torrents/FOOBAR.html");
+ se = new TQListViewItem(m_engines, "torrentz.eu", "http://torrentz.eu/search?f=FOOBAR");
+ se = new TQListViewItem(m_engines, "torrentcrazy.com", "http://torrentcrazy.com/s/FOOBAR");
+ se = new TQListViewItem(m_engines, "bitsnoop.com", "http://bitsnoop.com/search/all/FOOBAR/c/d/1/");
+ se = new TQListViewItem(m_engines, "torrents.net", "http://www.torrents.net/find/FOOBAR/");
+ se = new TQListViewItem(m_engines, "btmon.com", "http://www.btmon.com/torrent/?f=FOOBAR");
+ }
+
+ void SearchPrefPageWidget::removeAllClicked()
+ {
+ m_engines->clear();
+ }
+
+ void SearchPrefPageWidget::btnUpdate_clicked()
+ {
+ TQString fn = TDEGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines.tmp";
+ KURL source("http://www.ktorrent.org/downloads/search_engines");
+
+ if (TDEIO::NetAccess::download(source,fn,NULL))
+ {
+ //list successfully downloaded, remove temporary file
+ updateList(fn);
+ saveSearchEngines();
+ TDEIO::NetAccess::removeTempFile(fn);
+ }
+ }
+
+ void SearchPrefPageWidget::updateList(TQString& source)
+ {
+ TQFile fptr(source);
+
+ if (!fptr.open(IO_ReadOnly))
+ return;
+
+ TQTextStream in(&fptr);
+
+ TQMap<TQString,KURL> engines;
+
+ while (!in.atEnd())
+ {
+ TQString line = in.readLine();
+
+ if(line.startsWith("#") || line.startsWith(" ") || line.isEmpty() )
+ continue;
+
+ TQStringList tokens = TQStringList::split(" ", line);
+ TQString name = tokens[0];
+ name = name.replace("%20"," ");
+
+ KURL url = KURL::fromPathOrURL(tokens[1]);
+ for(Uint32 i=2; i<tokens.count(); ++i)
+ url.addQueryItem(tokens[i].section("=",0,0), tokens[i].section("=", 1, 1));
+
+ engines.insert(name,url);
+ }
+
+ TQMap<TQString,KURL>::iterator i = engines.begin();
+ while (i != engines.end())
+ {
+ TQListViewItem* item = m_engines->findItem(i.key(),0);
+ // if we have found the item, replace it if not make a new one
+ if (item)
+ item->setText(1, i.data().prettyURL());
+ else
+ new TQListViewItem(m_engines,i.key(),i.data().prettyURL());
+
+ i++;
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////////////////
+
+
+ SearchPrefPage::SearchPrefPage(SearchPlugin* plugin)
+ : PrefPageInterface(i18n("a noun", "Search"), i18n("Search Engine Options"),
+ TDEGlobal::iconLoader()->loadIcon("viewmag",TDEIcon::NoGroup)), m_plugin(plugin)
+ {
+ widget = 0;
+ }
+
+
+ SearchPrefPage::~SearchPrefPage()
+ {}
+
+
+ bool SearchPrefPage::apply()
+ {
+ bool ret = widget->apply();
+ if(ret)
+ m_plugin->preferencesUpdated();
+
+ return ret;
+ }
+
+ void SearchPrefPage::createWidget(TQWidget* parent)
+ {
+ widget = new SearchPrefPageWidget(parent);
+ }
+
+ void SearchPrefPage::deleteWidget()
+ {
+ delete widget;
+ }
+
+ void SearchPrefPage::updateData()
+ {
+ widget->updateSearchEngines(m_plugin->getSearchEngineList());
+
+ }
+
+ void SearchPrefPageWidget::customToggled(bool toggled)
+ {
+ customBrowser->setEnabled(toggled);
+ }
+}
+
+#include "searchprefpage.moc"
diff --git a/src/plugins/search/searchprefpage.h b/src/plugins/search/searchprefpage.h
new file mode 100644
index 0000000..add87a9
--- /dev/null
+++ b/src/plugins/search/searchprefpage.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef KTSEARCHPREFPAGE_H
+#define KTSEARCHPREFPAGE_H
+
+
+#include <interfaces/prefpageinterface.h>
+#include "searchpref.h"
+
+#include <tqstring.h>
+
+namespace kt
+{
+ class SearchPlugin;
+ class SearchEngineList;
+
+ class SearchPrefPageWidget : public SEPreferences
+ {
+ TQ_OBJECT
+
+ public:
+ SearchPrefPageWidget(TQWidget *parent = 0);
+
+ bool apply();
+ void saveSearchEngines();
+ void updateList(TQString& source);
+
+ void updateSearchEngines(const SearchEngineList & se);
+
+ public slots:
+ virtual void btnUpdate_clicked();
+ void customToggled(bool toggled);
+
+ private slots:
+ void addClicked();
+ void removeClicked();
+ void addDefaultClicked();
+ void removeAllClicked();
+ };
+
+ /**
+ @author Joris Guisson
+ */
+ class SearchPrefPage : public PrefPageInterface
+ {
+ public:
+ SearchPrefPage(SearchPlugin* plugin);
+ virtual ~SearchPrefPage();
+
+ virtual bool apply();
+ virtual void createWidget(TQWidget* parent);
+ virtual void updateData();
+ virtual void deleteWidget();
+
+ private:
+ SearchPrefPageWidget* widget;
+ SearchPlugin* m_plugin;
+ };
+
+}
+
+#endif
diff --git a/src/plugins/search/searchtab.cpp b/src/plugins/search/searchtab.cpp
new file mode 100644
index 0000000..dc68dc4
--- /dev/null
+++ b/src/plugins/search/searchtab.cpp
@@ -0,0 +1,169 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <tqfile.h>
+#include <tqtextstream.h>
+#include <tqapplication.h>
+#include <tqlistbox.h>
+#include <tqcheckbox.h>
+#include <tdeglobal.h>
+#include <kpushbutton.h>
+#include <kiconloader.h>
+#include <kcombobox.h>
+#include <kcompletion.h>
+#include <tqlabel.h>
+#include <tdelocale.h>
+#include "searchtab.h"
+#include "searchenginelist.h"
+#include "searchpluginsettings.h"
+#include "functions.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+ SearchTab::SearchTab(TDEToolBar* tb) : m_tool_bar(tb)
+ {
+ m_search_text = new KComboBox(tb);
+ m_search_text->setEditable(true);
+
+ m_clear_button = new KPushButton(tb);
+ m_search_new_tab = new KPushButton(i18n("Search"),tb);
+ m_search_engine = new KComboBox(tb);
+
+ m_clear_button->setIconSet(SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"));
+ m_clear_button->setEnabled(false);
+
+ connect(m_search_new_tab,TQ_SIGNAL(clicked()),this,TQ_SLOT(searchNewTabPressed()));
+ connect(m_search_text,TQ_SIGNAL(returnPressed(const TQString&)),this,TQ_SLOT(searchBoxReturn( const TQString& )));
+ connect(m_search_text,TQ_SIGNAL(textChanged(const TQString &)),this,TQ_SLOT(textChanged( const TQString& )));
+ connect(m_clear_button,TQ_SIGNAL(clicked()),this,TQ_SLOT(clearButtonPressed()));
+ m_search_text->setMaxCount(20);
+ m_search_new_tab->setEnabled(false);
+ m_search_text->setInsertionPolicy(TQComboBox::NoInsertion);
+
+ tb->insertWidget(1,-1,m_clear_button);
+ tb->insertWidget(2,-1,m_search_text);
+ tb->insertWidget(3,-1,m_search_new_tab);
+ tb->insertWidget(4,-1,new TQLabel(i18n(" Engine: "),tb));
+ tb->insertWidget(5,-1,m_search_engine);
+ loadSearchHistory();
+ }
+
+ SearchTab::~SearchTab()
+ {
+ }
+
+ void SearchTab::saveSettings()
+ {
+ SearchPluginSettings::setSearchEngine(m_search_engine->currentItem());
+ SearchPluginSettings::writeConfig();
+ }
+
+ void SearchTab::updateSearchEngines(const SearchEngineList & sl)
+ {
+ int ci = 0;
+ if (m_search_engine->count() == 0)
+ ci = SearchPluginSettings::searchEngine();
+ else
+ ci = m_search_engine->currentItem();
+
+ m_search_engine->clear();
+ for (Uint32 i = 0;i < sl.getNumEngines();i++)
+ {
+ m_search_engine->insertItem(sl.getEngineName(i));
+ }
+ m_search_engine->setCurrentItem(ci);
+ }
+
+ void SearchTab::searchBoxReturn(const TQString & str)
+ {
+ TDECompletion *comp = m_search_text->completionObject();
+ if (!m_search_text->contains(str))
+ {
+ comp->addItem(str);
+ m_search_text->insertItem(str);
+ }
+ m_search_text->clearEdit();
+ saveSearchHistory();
+ search(str,m_search_engine->currentItem(),SearchPluginSettings::openInExternal());
+ }
+
+ void SearchTab::clearButtonPressed()
+ {
+ m_search_text->clearEdit();
+ }
+
+ void SearchTab::searchNewTabPressed()
+ {
+ searchBoxReturn(m_search_text->currentText());
+ }
+
+ void SearchTab::textChanged(const TQString & str)
+ {
+ m_search_new_tab->setEnabled(str.length() > 0);
+ m_clear_button->setEnabled(str.length() > 0);
+ }
+
+ void SearchTab::loadSearchHistory()
+ {
+ TQFile fptr(kt::DataDir() + "search_history");
+ if (!fptr.open(IO_ReadOnly))
+ return;
+
+ TDECompletion *comp = m_search_text->completionObject();
+
+ Uint32 cnt = 0;
+ TQTextStream in(&fptr);
+ while (!in.atEnd() && cnt < 50)
+ {
+ TQString line = in.readLine();
+ if (line.isNull())
+ break;
+
+ if (!m_search_text->contains(line))
+ {
+ comp->addItem(line);
+ m_search_text->insertItem(line);
+ }
+ cnt++;
+ }
+
+ m_search_text->clearEdit();
+ }
+
+ void SearchTab::saveSearchHistory()
+ {
+ TQFile fptr(kt::DataDir() + "search_history");
+ if (!fptr.open(IO_WriteOnly))
+ return;
+
+ TQTextStream out(&fptr);
+ TDECompletion *comp = m_search_text->completionObject();
+ TQStringList items = comp->items();
+ for (TQStringList::iterator i = items.begin();i != items.end();i++)
+ {
+ out << *i << endl;
+ }
+ }
+}
+
+#include "searchtab.moc"
+
diff --git a/src/plugins/search/searchtab.h b/src/plugins/search/searchtab.h
new file mode 100644
index 0000000..35fecfb
--- /dev/null
+++ b/src/plugins/search/searchtab.h
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef SEARCHTAB_H
+#define SEARCHTAB_H
+
+#include <tdetoolbar.h>
+
+class KComboBox;
+class KPushButton;
+
+namespace kt
+{
+ class SearchEngineList;
+
+ /**
+ Holds all widgets of the toolbar of the search plugin.
+ */
+ class SearchTab : public TQObject
+ {
+ TQ_OBJECT
+
+
+ public:
+ SearchTab(TDEToolBar* toolbar);
+ virtual ~SearchTab();
+
+ /// Get the tool bar
+ TDEToolBar* getToolBar() {return m_tool_bar;}
+
+ /// Update the search engine list
+ void updateSearchEngines(const SearchEngineList & sl);
+
+ /// Save settings like current search engine
+ void saveSettings();
+
+ protected slots:
+ void clearButtonPressed();
+ void searchNewTabPressed();
+ void searchBoxReturn(const TQString & str);
+ void textChanged(const TQString & str);
+
+ signals:
+ /// Emitted when the user presses enter or clicks search
+ void search(const TQString & text,int engine,bool external);
+
+ private:
+ void loadSearchHistory();
+ void saveSearchHistory();
+
+ private:
+ TDEToolBar* m_tool_bar;
+ KComboBox* m_search_text;
+ KComboBox* m_search_engine;
+ KPushButton* m_clear_button;
+ KPushButton* m_search_new_tab;
+ };
+}
+
+#endif
+
diff --git a/src/plugins/search/searchwidget.cpp b/src/plugins/search/searchwidget.cpp
new file mode 100644
index 0000000..39ec574
--- /dev/null
+++ b/src/plugins/search/searchwidget.cpp
@@ -0,0 +1,272 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson, Ivan Vasic *
+ * *
+ * 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 <tdeapplication.h>
+#include <tdehtmlview.h>
+#include <tqlayout.h>
+#include <tqfile.h>
+#include <tqtextstream.h>
+#include <tqstring.h>
+#include <tqstringlist.h>
+#include <klineedit.h>
+#include <kpushbutton.h>
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <tdestandarddirs.h>
+#include <kiconloader.h>
+#include <kcombobox.h>
+#include <tdepopupmenu.h>
+#include <tdeparts/partmanager.h>
+#include <tdeio/job.h>
+#include <tdemessagebox.h>
+#include <tdefiledialog.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* layout = new TQVBoxLayout(this);
+ layout->setAutoAdd(true);
+ sbar = new SearchBar(this);
+ html_part = new HTMLPart(this);
+
+ right_click_menu = new TDEPopupMenu(this);
+ right_click_menu->insertSeparator();
+ back_id = right_click_menu->insertItem(
+ TDEGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
+ ? "forward" : "back",TDEIcon::Small),
+ i18n("Back"),html_part,TQ_SLOT(back()));
+ right_click_menu->insertItem(
+ TDEGlobal::iconLoader()->loadIconSet("reload",TDEIcon::Small),
+ i18n("Reload"),html_part,TQ_SLOT(reload()));
+
+ right_click_menu->setItemEnabled(back_id,false);
+ sbar->m_back->setEnabled(false);
+ connect(sbar->m_search_button,TQ_SIGNAL(clicked()),this,TQ_SLOT(searchPressed()));
+ connect(sbar->m_clear_button,TQ_SIGNAL(clicked()),this,TQ_SLOT(clearPressed()));
+ connect(sbar->m_search_text,TQ_SIGNAL(returnPressed()),this,TQ_SLOT(searchPressed()));
+ connect(sbar->m_back,TQ_SIGNAL(clicked()),html_part,TQ_SLOT(back()));
+ connect(sbar->m_reload,TQ_SIGNAL(clicked()),html_part,TQ_SLOT(reload()));
+
+ sbar->m_clear_button->setIconSet(
+ TDEGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
+ ? "clear_left" : "locationbar_erase",TDEIcon::Small));
+ sbar->m_back->setIconSet(
+ TDEGlobal::iconLoader()->loadIconSet(TQApplication::reverseLayout()
+ ? "forward" : "back", TDEIcon::Small));
+ sbar->m_reload->setIconSet(
+ TDEGlobal::iconLoader()->loadIconSet("reload",TDEIcon::Small));
+
+
+ connect(html_part,TQ_SIGNAL(backAvailable(bool )),
+ this,TQ_SLOT(onBackAvailable(bool )));
+ connect(html_part,TQ_SIGNAL(onURL(const TQString& )),
+ this,TQ_SLOT(onURLHover(const TQString& )));
+ connect(html_part,TQ_SIGNAL(openTorrent(const KURL& )),
+ this,TQ_SLOT(onOpenTorrent(const KURL& )));
+ connect(html_part,TQ_SIGNAL(popupMenu(const TQString&, const TQPoint& )),
+ this,TQ_SLOT(showPopupMenu(const TQString&, const TQPoint& )));
+ connect(html_part,TQ_SIGNAL(searchFinished()),this,TQ_SLOT(onFinished()));
+ connect(html_part,TQ_SIGNAL(saveTorrent(const KURL& )),
+ this,TQ_SLOT(onSaveTorrent(const KURL& )));
+
+ KParts::PartManager* pman = html_part->partManager();
+ connect(pman,TQ_SIGNAL(partAdded(KParts::Part*)),this,TQ_SLOT(onFrameAdded(KParts::Part* )));
+
+ connect(html_part->browserExtension(),TQ_SIGNAL(loadingProgress(int)),this,TQ_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)
+ {
+ TDEHTMLPart* frame = dynamic_cast<TDEHTMLPart*>(p);
+ if (frame)
+ {
+ connect(frame,TQ_SIGNAL(popupMenu(const TQString&, const TQPoint& )),
+ this,TQ_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.replace("FOOBAR", KURL::encode_string(text), true);
+ KURL url = KURL::fromPathOrURL(s_url);
+
+ statusBarMsg(i18n("Searching for %1...").arg(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
+ TDEIO::Job* j = TDEIO::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);
+ }
+
+ TDEPopupMenu* 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"
diff --git a/src/plugins/search/searchwidget.h b/src/plugins/search/searchwidget.h
new file mode 100644
index 0000000..e556f10
--- /dev/null
+++ b/src/plugins/search/searchwidget.h
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef BTSEARCHWIDGET_H
+#define BTSEARCHWIDGET_H
+
+#include <tqwidget.h>
+#include <tqvaluevector.h>
+#include <kurl.h>
+
+class SearchBar;
+class KProgress;
+class TDEPopupMenu;
+
+namespace KParts
+{
+ class Part;
+}
+
+namespace kt
+{
+ class HTMLPart;
+ class SearchPlugin;
+ class SearchEngineList;
+
+
+ /**
+ @author Joris Guisson
+
+ Widget which shows a TDEHTML window with the users search in it
+ */
+ class SearchWidget : public TQWidget
+ {
+ TQ_OBJECT
+
+ public:
+ SearchWidget(SearchPlugin* sp);
+ virtual ~SearchWidget();
+
+ TDEPopupMenu* rightClickMenu();
+
+ void updateSearchEngines(const SearchEngineList & sl);
+
+ public slots:
+ void search(const TQString & text,int engine = 0);
+ void copy();
+ void onShutDown();
+
+ private slots:
+ void searchPressed();
+ void clearPressed();
+ void onURLHover(const TQString & url);
+ void onFinished();
+ void onOpenTorrent(const KURL & url);
+ void onSaveTorrent(const KURL & url);
+ void showPopupMenu(const TQString & s,const TQPoint & p);
+ void onBackAvailable(bool available);
+ void onFrameAdded(KParts::Part* p);
+ void statusBarMsg(const TQString & url);
+ void openTorrent(const KURL & url);
+ void loadingProgress(int perc);
+
+ private:
+ HTMLPart* html_part;
+ SearchBar* sbar;
+ TDEPopupMenu* right_click_menu;
+ int back_id;
+ SearchPlugin* sp;
+ KProgress* prog;
+ };
+
+}
+
+#endif