diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 02:37:40 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 02:37:40 +0000 |
commit | 9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch) | |
tree | d088b5210e77d9fa91d954d8550e00e372b47378 /plugins/search | |
download | ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.tar.gz ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.zip |
Updated to final KDE3 ktorrent release (2.2.6)
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'plugins/search')
-rw-r--r-- | plugins/search/Makefile.am | 28 | ||||
-rw-r--r-- | plugins/search/htmlpart.cpp | 198 | ||||
-rw-r--r-- | plugins/search/htmlpart.h | 72 | ||||
-rw-r--r-- | plugins/search/ktsearchplugin.desktop | 60 | ||||
-rw-r--r-- | plugins/search/ktsearchplugin.kcfg | 30 | ||||
-rw-r--r-- | plugins/search/searchbar.ui | 99 | ||||
-rw-r--r-- | plugins/search/searchenginelist.cpp | 134 | ||||
-rw-r--r-- | plugins/search/searchenginelist.h | 60 | ||||
-rw-r--r-- | plugins/search/searchplugin.cpp | 157 | ||||
-rw-r--r-- | plugins/search/searchplugin.h | 66 | ||||
-rw-r--r-- | plugins/search/searchpluginsettings.kcfgc | 7 | ||||
-rw-r--r-- | plugins/search/searchpref.ui | 320 | ||||
-rw-r--r-- | plugins/search/searchprefpage.cpp | 289 | ||||
-rw-r--r-- | plugins/search/searchprefpage.h | 78 | ||||
-rw-r--r-- | plugins/search/searchtab.cpp | 169 | ||||
-rw-r--r-- | plugins/search/searchtab.h | 77 | ||||
-rw-r--r-- | plugins/search/searchwidget.cpp | 272 | ||||
-rw-r--r-- | plugins/search/searchwidget.h | 89 |
18 files changed, 2205 insertions, 0 deletions
diff --git a/plugins/search/Makefile.am b/plugins/search/Makefile.am new file mode 100644 index 0000000..af57f30 --- /dev/null +++ b/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_KHTML) $(LIB_KPARTS) $(LIB_QT) \ + $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KFILE) + +# 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/plugins/search/htmlpart.cpp b/plugins/search/htmlpart.cpp new file mode 100644 index 0000000..b1c6b23 --- /dev/null +++ b/plugins/search/htmlpart.cpp @@ -0,0 +1,198 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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 <kmessagebox.h> +#include <kio/job.h> +#include <kio/jobclasses.h> +//#include <qfile.h> +#include <qclipboard.h> +#include <qapplication.h> +#include <kio/netaccess.h> +#include <klocale.h> +#include <kfiledialog.h> +#include <kparts/browserextension.h> +#include <util/constants.h> +#include <khtmlview.h> +#include "htmlpart.h" + +using namespace bt; + +namespace kt +{ + + HTMLPart::HTMLPart(QWidget *parent) + : KHTMLPart(parent) + { + setJScriptEnabled(true); + setJavaEnabled(true); + setMetaRefreshEnabled(true); + setPluginsEnabled(false); + setStatusMessagesEnabled(false); + KParts::BrowserExtension* ext = this->browserExtension(); + connect(ext,SIGNAL(openURLRequest(const KURL&,const KParts::URLArgs&)), + this,SLOT(openURLRequest(const KURL&, const KParts::URLArgs& ))); + + ext->enableAction("copy",true); + ext->enableAction("paste",true); + active_job = 0; + } + + + HTMLPart::~HTMLPart() + {} + + void HTMLPart::copy() + { + QString txt = selectedText(); + QClipboard *cb = QApplication::clipboard(); + // Copy text into the clipboard + if (cb) + cb->setText(txt,QClipboard::Clipboard); + } + + void HTMLPart::openURLRequest(const KURL &u,const KParts::URLArgs &) + { + if (active_job) + { + active_job->kill(true); + active_job = 0; + } + + KIO::TransferJob* j = KIO::get(u,false,false); + connect(j,SIGNAL(data(KIO::Job*,const QByteArray &)), + this,SLOT(dataRecieved(KIO::Job*, const QByteArray& ))); + connect(j,SIGNAL(result(KIO::Job*)),this,SLOT(jobDone(KIO::Job* ))); + connect(j,SIGNAL(mimetype(KIO::Job*, const QString &)), + this,SLOT(mimetype(KIO::Job*, const QString& ))); + + active_job = j; + curr_data.resize(0); + mime_type = QString::null; + 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(KIO::Job* job,const QByteArray & 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(KIO::Job* job,const QString & mt) + { + if (job != active_job) + { + job->kill(true); + return; + } + + mime_type = mt; + } + + void HTMLPart::jobDone(KIO::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"),"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(KIO::buildErrorString(job->error(),job->errorText()));/*,&curr_url));**/ + end(); + } + active_job = 0; + curr_data.resize(0); + curr_url = KURL(); + mime_type = QString::null; + } +} + +#include "htmlpart.moc" diff --git a/plugins/search/htmlpart.h b/plugins/search/htmlpart.h new file mode 100644 index 0000000..f5b78ee --- /dev/null +++ b/plugins/search/htmlpart.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ +#ifndef HTMLPART_H +#define HTMLPART_H + +#include <khtml_part.h> + +namespace KIO +{ + class Job; +} + + +namespace kt +{ + + /** + @author Joris Guisson + */ + class HTMLPart : public KHTMLPart + { + Q_OBJECT + public: + HTMLPart(QWidget *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(KIO::Job* job,const QByteArray & data); + void mimetype(KIO::Job* job,const QString & mt); + void jobDone(KIO::Job* job); + + + signals: + void backAvailable(bool yes); + void openTorrent(const KURL & url); + void saveTorrent(const KURL & url); + void searchFinished(); + + private: + KURL::List history; + KIO::Job* active_job; + QByteArray curr_data; + QString mime_type; + KURL curr_url; + }; +} + +#endif diff --git a/plugins/search/ktsearchplugin.desktop b/plugins/search/ktsearchplugin.desktop new file mode 100644 index 0000000..0210135 --- /dev/null +++ b/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 搜尋外掛程式 +ServiceTypes=KTorrent/Plugin +Type=Service +X-KDE-Library=ktsearchplugin diff --git a/plugins/search/ktsearchplugin.kcfg b/plugins/search/ktsearchplugin.kcfg new file mode 100644 index 0000000..fdcc141 --- /dev/null +++ b/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/plugins/search/searchbar.ui b/plugins/search/searchbar.ui new file mode 100644 index 0000000..2b91ea0 --- /dev/null +++ b/plugins/search/searchbar.ui @@ -0,0 +1,99 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>SearchBar</class> +<widget class="QWidget"> + <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="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Search engine:</string> + </property> + </widget> + <widget class="KComboBox"> + <property name="name"> + <cstring>m_search_engine</cstring> + </property> + </widget> + </hbox> +</widget> +<customwidgets> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kcombobox.h</includehint> +</includehints> +</UI> diff --git a/plugins/search/searchenginelist.cpp b/plugins/search/searchenginelist.cpp new file mode 100644 index 0000000..cf7a11b --- /dev/null +++ b/plugins/search/searchenginelist.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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 <qfile.h> +#include <qtextstream.h> +#include <qstringlist.h> +#include "searchenginelist.h" + +using namespace bt; + +namespace kt +{ + + SearchEngineList::SearchEngineList() + {} + + + SearchEngineList::~SearchEngineList() + {} + + void SearchEngineList::save(const QString& file) + { + QFile fptr(file); + if (!fptr.open(IO_WriteOnly)) + return; + + QTextStream out(&fptr); + out << "# PLEASE DO NOT MODIFY THIS FILE. Use KTorrent configuration dialog for adding new search engines." << ::endl; + out << "# SEARCH ENGINES list" << ::endl; + + QValueList<SearchEngine>::iterator i = m_search_engines.begin(); + while (i != m_search_engines.end()) + { + SearchEngine & e = *i; + + // replace spaces by %20 + QString name = e.name; + name = name.replace(" ","%20"); + QString u = e.url.prettyURL(); + u = u.replace(" ","%20"); + out << name << " " << u << ::endl; + i++; + } + } + + void SearchEngineList::load(const QString& file) + { + m_search_engines.clear(); + + QFile fptr(file); + + if(!fptr.exists()) + makeDefaultFile(file); + + if (!fptr.open(IO_ReadOnly)) + return; + + QTextStream in(&fptr); + + int id = 0; + + while (!in.atEnd()) + { + QString line = in.readLine(); + + if(line.startsWith("#") || line.startsWith(" ") || line.isEmpty() ) continue; + + QStringList tokens = QStringList::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 QString& file) + { + QFile fptr(file); + if (!fptr.open(IO_WriteOnly)) + return; + + QTextStream 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 << "KTorrents http://www.ktorrents.com/search.php?lg=0&sourceid=ktorrent&q=FOOBAR&f=0" << ::endl; + out << "bittorrent.com http://www.bittorrent.com/search_result.myt?search=FOOBAR" << ::endl; + out << "isohunt.com http://isohunt.com/torrents.php?ihq=FOOBAR&op=and" << ::endl; + out << "mininova.org http://www.mininova.org/search.php?search=FOOBAR" << ::endl; + out << "thepiratebay.org http://thepiratebay.org/search.php?q=FOOBAR" << ::endl; + out << "bitoogle.com http://bitoogle.com/search.php?q=FOOBAR" << ::endl; + out << "bytenova.org http://www.bitenova.org/search.php?search=FOOBAR&start=0&start=0&ie=utf-8&oe=utf-8" << ::endl; + out << "torrentspy.com http://torrentspy.com/search.asp?query=FOOBAR" << ::endl; + out << "torrentz.com http://www.torrentz.com/search_FOOBAR" << ::endl; + } + + KURL SearchEngineList::getSearchURL(bt::Uint32 engine) const + { + if (engine >= m_search_engines.count()) + return KURL(); + else + return m_search_engines[engine].url; + } + + QString SearchEngineList::getEngineName(bt::Uint32 engine) const + { + if (engine >= m_search_engines.count()) + return QString::null; + else + return m_search_engines[engine].name; + } + +} diff --git a/plugins/search/searchenginelist.h b/plugins/search/searchenginelist.h new file mode 100644 index 0000000..236b8eb --- /dev/null +++ b/plugins/search/searchenginelist.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ +#ifndef KTSEARCHENGINELIST_H +#define KTSEARCHENGINELIST_H + +#include <kurl.h> +#include <qvaluelist.h> +#include <util/constants.h> + +namespace kt +{ + + + /** + @author Joris Guisson <[email protected]> + */ + class SearchEngineList + { + struct SearchEngine + { + QString name; + KURL url; + }; + + QValueList<SearchEngine> m_search_engines; + public: + SearchEngineList(); + virtual ~SearchEngineList(); + + void save(const QString& file); + void load(const QString& file); + void makeDefaultFile(const QString& file); + + KURL getSearchURL(bt::Uint32 engine) const; + QString getEngineName(bt::Uint32 engine) const; + + /// Get the number of engines + bt::Uint32 getNumEngines() const {return m_search_engines.count();} + }; + +} + +#endif diff --git a/plugins/search/searchplugin.cpp b/plugins/search/searchplugin.cpp new file mode 100644 index 0000000..c674369 --- /dev/null +++ b/plugins/search/searchplugin.cpp @@ -0,0 +1,157 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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 <kgenericfactory.h> +#include <kglobal.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kstdaction.h> +#include <kpopupmenu.h> +#include <kapplication.h> +#include <kstandarddirs.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(QObject* parent, const char* name, const QStringList& 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(KGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines"); + KToolBar* tb = getGUI()->addToolBar("search"); + tab = new SearchTab(tb); + connect(tab,SIGNAL(search( const QString&, int, bool )), + this,SLOT(search( const QString&, 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 QString & text,int engine,bool external) + { + if(external) + { + const SearchEngineList& sl = getSearchEngineList(); + + if (engine < 0 || engine >= sl.getNumEngines()) + engine = 0; + + QString s_url = sl.getSearchURL(engine).prettyURL(); + s_url.replace("FOOBAR", KURL::encode_string(text), true); + KURL url = KURL::fromPathOrURL(s_url); + + if(SearchPluginSettings::useDefaultBrowser()) + kapp->invokeBrowser(url.url()); + else + KRun::runCommand(QString("%1 \"%2\"").arg(SearchPluginSettings::customBrowser()).arg(url.url()), SearchPluginSettings::customBrowser(), "viewmag" ); + + return; + } + + KIconLoader* iload = KGlobal::iconLoader(); + + SearchWidget* search = new SearchWidget(this); + getGUI()->addTabPage(search,iload->loadIconSet("viewmag", KIcon::Small),text,this); + + KAction* copy_act = KStdAction::copy(search,SLOT(copy()),actionCollection()); + copy_act->plug(search->rightClickMenu(),0); + searches.append(search); + + search->updateSearchEngines(engines); + search->search(text,engine); + } + + void SearchPlugin::preferencesUpdated() + { + engines.load(KGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines"); + if (tab) + tab->updateSearchEngines(engines); + + for (QPtrList<SearchWidget>::iterator i = searches.begin(); i != searches.end();i++) + { + SearchWidget* w = *i; + w->updateSearchEngines(engines); + } + } + + void SearchPlugin::tabCloseRequest(kt::GUIInterface* gui,QWidget* tab) + { + if (searches.contains((SearchWidget*)tab)) + { + searches.remove((SearchWidget*)tab); + gui->removeTabPage(tab); + tab->deleteLater(); + } + } + + bool SearchPlugin::versionCheck(const QString & version) const + { + return version == KT_VERSION_MACRO; + } +} +#include "searchplugin.moc" diff --git a/plugins/search/searchplugin.h b/plugins/search/searchplugin.h new file mode 100644 index 0000000..ce65499 --- /dev/null +++ b/plugins/search/searchplugin.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ +#ifndef KTSEARCHPLUGIN_H +#define KTSEARCHPLUGIN_H + +#include <qptrlist.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 + { + Q_OBJECT + public: + SearchPlugin(QObject* parent, const char* name, const QStringList& args); + virtual ~SearchPlugin(); + + virtual void load(); + virtual void unload(); + virtual bool versionCheck(const QString& version) const; + + void preferencesUpdated(); + + const SearchEngineList & getSearchEngineList() const {return engines;} + private slots: + void search(const QString & text,int engine,bool external); + + private: + virtual void tabCloseRequest(kt::GUIInterface* gui,QWidget* tab); + + private: + SearchPrefPage* pref; + SearchTab* tab; + SearchEngineList engines; + QPtrList<SearchWidget> searches; + }; + +} + +#endif diff --git a/plugins/search/searchpluginsettings.kcfgc b/plugins/search/searchpluginsettings.kcfgc new file mode 100644 index 0000000..8b3488b --- /dev/null +++ b/plugins/search/searchpluginsettings.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +File=ktsearchplugin.kcfg +ClassName=SearchPluginSettings +Namespace=kt +Singleton=true +Mutators=true +# will create the necessary code for setting those variables diff --git a/plugins/search/searchpref.ui b/plugins/search/searchpref.ui new file mode 100644 index 0000000..8c8c026 --- /dev/null +++ b/plugins/search/searchpref.ui @@ -0,0 +1,320 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>SEPreferences</class> +<widget class="QWidget"> + <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="QButtonGroup"> + <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="QCheckBox"> + <property name="name"> + <cstring>openExternal</cstring> + </property> + <property name="text"> + <string>Open searches in external browser</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>useDefaultBrowser</cstring> + </property> + <property name="text"> + <string>Use default browser</string> + </property> + <property name="accel"> + <string></string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout29</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>useCustomBrowser</cstring> + </property> + <property name="text"> + <string>Custom browser path:</string> + </property> + <property name="accel"> + <string></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="QGroupBox"> + <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="QLayoutWidget"> + <property name="name"> + <cstring>layout22</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <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="QLayoutWidget"> + <property name="name"> + <cstring>layout23</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <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="QPushButton"> + <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>&Add</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QListView"> + <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="QLayoutWidget"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>btnRemove</cstring> + </property> + <property name="text"> + <string>&Remove</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>btnRemoveAll</cstring> + </property> + <property name="text"> + <string>R&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="QPushButton"> + <property name="name"> + <cstring>btn_add_default</cstring> + </property> + <property name="text"> + <string>Add Defau&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"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>kactivelabel.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/plugins/search/searchprefpage.cpp b/plugins/search/searchprefpage.cpp new file mode 100644 index 0000000..2285ead --- /dev/null +++ b/plugins/search/searchprefpage.cpp @@ -0,0 +1,289 @@ +/*************************************************************************** + * 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 <kurl.h> +#include <qtooltip.h> +#include <qfile.h> +#include <klocale.h> +#include <kglobal.h> +#include <kstandarddirs.h> +#include <kiconloader.h> +#include <kactivelabel.h> +#include <kpushbutton.h> +#include <klistview.h> +#include <klineedit.h> +#include <kmessagebox.h> +#include <kio/netaccess.h> +#include <klineedit.h> + +#include <qlabel.h> +#include <qcheckbox.h> +#include <qradiobutton.h> + +#include <util/constants.h> +#include "searchprefpage.h" +#include "searchplugin.h" +#include "searchenginelist.h" +#include "searchpluginsettings.h" + +using namespace bt; + +namespace kt +{ + SearchPrefPageWidget::SearchPrefPageWidget(QWidget *parent) : SEPreferences(parent) + { + QString 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"); + QString 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); + QToolTip::add(m_infoLabel,info); + QToolTip::add(m_engine_name,info); + + connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClicked())); + connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClicked())); + connect(btn_add_default, SIGNAL(clicked()), this, SLOT(addDefaultClicked())); + connect(btnRemoveAll, SIGNAL(clicked()), this, SLOT(removeAllClicked())); + + connect(useCustomBrowser, SIGNAL(toggled(bool)), this, 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 QListViewItem(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() + { + QFile fptr(KGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines"); + if (!fptr.open(IO_WriteOnly)) + return; + QTextStream out(&fptr); + out << "# PLEASE DO NOT MODIFY THIS FILE. Use KTorrent configuration dialog for adding new search engines." << ::endl; + out << "# SEARCH ENGINES list" << ::endl; + + QListViewItemIterator itr(m_engines); + while (itr.current()) + { + QListViewItem* item = itr.current(); + QString u = item->text(1); + QString 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 QListViewItem(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; + + QListViewItem* item = m_engines->selectedItem(); + m_engines->takeItem(item); + delete item; + } + + void SearchPrefPageWidget::addDefaultClicked() + { + QListViewItem* se = new QListViewItem(m_engines, "KTorrents", "http://www.ktorrents.com/search.php?lg=0&sourceid=ktorrent&q=FOOBAR&f=0"); + + se = new QListViewItem(m_engines, "bittorrent.com", "http://search.bittorrent.com/search.jsp?query=FOOBAR"); + + se = new QListViewItem(m_engines, "isohunt.com", "http://isohunt.com/torrents.php?ihq=FOOBAR&op=and"); + + se = new QListViewItem(m_engines, "mininova.org", "http://www.mininova.org/search.php?search=FOOBAR"); + + se = new QListViewItem(m_engines, "thepiratebay.org", "http://thepiratebay.org/search.php?q=FOOBAR"); + + se = new QListViewItem(m_engines, "bitoogle.com", "http://bitoogle.com/search.php?q=FOOBAR"); + + se = new QListViewItem(m_engines, "bytenova.org", "http://www.bitenova.org/search.php?search=FOOBAR&start=0&start=0&ie=utf-8&oe=utf-8"); + + se = new QListViewItem(m_engines, "torrentspy.com", "http://torrentspy.com/search.asp?query=FOOBAR"); + + se = new QListViewItem(m_engines, "torrentz.com", "http://www.torrentz.com/search_FOOBAR"); + } + + void SearchPrefPageWidget::removeAllClicked() + { + m_engines->clear(); + } + + void SearchPrefPageWidget::btnUpdate_clicked() + { + QString fn = KGlobal::dirs()->saveLocation("data","ktorrent") + "search_engines.tmp"; + KURL source("http://www.ktorrent.org/downloads/search_engines"); + + if (KIO::NetAccess::download(source,fn,NULL)) + { + //list successfully downloaded, remove temporary file + updateList(fn); + saveSearchEngines(); + KIO::NetAccess::removeTempFile(fn); + } + } + + void SearchPrefPageWidget::updateList(QString& source) + { + QFile fptr(source); + + if (!fptr.open(IO_ReadOnly)) + return; + + QTextStream in(&fptr); + + QMap<QString,KURL> engines; + + while (!in.atEnd()) + { + QString line = in.readLine(); + + if(line.startsWith("#") || line.startsWith(" ") || line.isEmpty() ) + continue; + + QStringList tokens = QStringList::split(" ", line); + QString 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); + } + + QMap<QString,KURL>::iterator i = engines.begin(); + while (i != engines.end()) + { + QListViewItem* 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 QListViewItem(m_engines,i.key(),i.data().prettyURL()); + + i++; + } + } + + //////////////////////////////////////////////////////////////////////////////////////////// + + + SearchPrefPage::SearchPrefPage(SearchPlugin* plugin) + : PrefPageInterface(i18n("a noun", "Search"), i18n("Search Engine Options"), + KGlobal::iconLoader()->loadIcon("viewmag",KIcon::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(QWidget* 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/plugins/search/searchprefpage.h b/plugins/search/searchprefpage.h new file mode 100644 index 0000000..a8d647d --- /dev/null +++ b/plugins/search/searchprefpage.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ +#ifndef KTSEARCHPREFPAGE_H +#define KTSEARCHPREFPAGE_H + + +#include <interfaces/prefpageinterface.h> +#include "searchpref.h" + +#include <qstring.h> + +namespace kt +{ + class SearchPlugin; + class SearchEngineList; + + class SearchPrefPageWidget : public SEPreferences + { + Q_OBJECT + public: + SearchPrefPageWidget(QWidget *parent = 0); + + bool apply(); + void saveSearchEngines(); + void updateList(QString& 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(QWidget* parent); + virtual void updateData(); + virtual void deleteWidget(); + + private: + SearchPrefPageWidget* widget; + SearchPlugin* m_plugin; + }; + +} + +#endif diff --git a/plugins/search/searchtab.cpp b/plugins/search/searchtab.cpp new file mode 100644 index 0000000..1beaa6a --- /dev/null +++ b/plugins/search/searchtab.cpp @@ -0,0 +1,169 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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 <qfile.h> +#include <qtextstream.h> +#include <qapplication.h> +#include <qlistbox.h> +#include <qcheckbox.h> +#include <kglobal.h> +#include <kpushbutton.h> +#include <kiconloader.h> +#include <kcombobox.h> +#include <kcompletion.h> +#include <qlabel.h> +#include <klocale.h> +#include "searchtab.h" +#include "searchenginelist.h" +#include "searchpluginsettings.h" +#include "functions.h" + +using namespace bt; + +namespace kt +{ + + SearchTab::SearchTab(KToolBar* 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(QApplication::reverseLayout() ? "clear_left" : "locationbar_erase")); + m_clear_button->setEnabled(false); + + connect(m_search_new_tab,SIGNAL(clicked()),this,SLOT(searchNewTabPressed())); + connect(m_search_text,SIGNAL(returnPressed(const QString&)),this,SLOT(searchBoxReturn( const QString& ))); + connect(m_search_text,SIGNAL(textChanged(const QString &)),this,SLOT(textChanged( const QString& ))); + connect(m_clear_button,SIGNAL(clicked()),this,SLOT(clearButtonPressed())); + m_search_text->setMaxCount(20); + m_search_new_tab->setEnabled(false); + m_search_text->setInsertionPolicy(QComboBox::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 QLabel(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 QString & str) + { + KCompletion *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 QString & str) + { + m_search_new_tab->setEnabled(str.length() > 0); + m_clear_button->setEnabled(str.length() > 0); + } + + void SearchTab::loadSearchHistory() + { + QFile fptr(kt::DataDir() + "search_history"); + if (!fptr.open(IO_ReadOnly)) + return; + + KCompletion *comp = m_search_text->completionObject(); + + Uint32 cnt = 0; + QTextStream in(&fptr); + while (!in.atEnd() && cnt < 50) + { + QString 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() + { + QFile fptr(kt::DataDir() + "search_history"); + if (!fptr.open(IO_WriteOnly)) + return; + + QTextStream out(&fptr); + KCompletion *comp = m_search_text->completionObject(); + QStringList items = comp->items(); + for (QStringList::iterator i = items.begin();i != items.end();i++) + { + out << *i << endl; + } + } +} + +#include "searchtab.moc" + diff --git a/plugins/search/searchtab.h b/plugins/search/searchtab.h new file mode 100644 index 0000000..c392de9 --- /dev/null +++ b/plugins/search/searchtab.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ + +#ifndef SEARCHTAB_H +#define SEARCHTAB_H + +#include <ktoolbar.h> + +class KComboBox; +class KPushButton; + +namespace kt +{ + class SearchEngineList; + + /** + Holds all widgets of the toolbar of the search plugin. + */ + class SearchTab : public QObject + { + Q_OBJECT + + public: + SearchTab(KToolBar* toolbar); + virtual ~SearchTab(); + + /// Get the tool bar + KToolBar* 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 QString & str); + void textChanged(const QString & str); + + signals: + /// Emitted when the user presses enter or clicks search + void search(const QString & text,int engine,bool external); + + private: + void loadSearchHistory(); + void saveSearchHistory(); + + private: + KToolBar* m_tool_bar; + KComboBox* m_search_text; + KComboBox* m_search_engine; + KPushButton* m_clear_button; + KPushButton* m_search_new_tab; + }; +} + +#endif + diff --git a/plugins/search/searchwidget.cpp b/plugins/search/searchwidget.cpp new file mode 100644 index 0000000..2ed19e8 --- /dev/null +++ b/plugins/search/searchwidget.cpp @@ -0,0 +1,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 <qlayout.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qstring.h> +#include <qstringlist.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) + { + QVBoxLayout* layout = new QVBoxLayout(this); + layout->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(QApplication::reverseLayout() + ? "forward" : "back",KIcon::Small), + i18n("Back"),html_part,SLOT(back())); + right_click_menu->insertItem( + KGlobal::iconLoader()->loadIconSet("reload",KIcon::Small), + i18n("Reload"),html_part,SLOT(reload())); + + right_click_menu->setItemEnabled(back_id,false); + sbar->m_back->setEnabled(false); + connect(sbar->m_search_button,SIGNAL(clicked()),this,SLOT(searchPressed())); + connect(sbar->m_clear_button,SIGNAL(clicked()),this,SLOT(clearPressed())); + connect(sbar->m_search_text,SIGNAL(returnPressed()),this,SLOT(searchPressed())); + connect(sbar->m_back,SIGNAL(clicked()),html_part,SLOT(back())); + connect(sbar->m_reload,SIGNAL(clicked()),html_part,SLOT(reload())); + + sbar->m_clear_button->setIconSet( + KGlobal::iconLoader()->loadIconSet(QApplication::reverseLayout() + ? "clear_left" : "locationbar_erase",KIcon::Small)); + sbar->m_back->setIconSet( + KGlobal::iconLoader()->loadIconSet(QApplication::reverseLayout() + ? "forward" : "back", KIcon::Small)); + sbar->m_reload->setIconSet( + KGlobal::iconLoader()->loadIconSet("reload",KIcon::Small)); + + + connect(html_part,SIGNAL(backAvailable(bool )), + this,SLOT(onBackAvailable(bool ))); + connect(html_part,SIGNAL(onURL(const QString& )), + this,SLOT(onURLHover(const QString& ))); + connect(html_part,SIGNAL(openTorrent(const KURL& )), + this,SLOT(onOpenTorrent(const KURL& ))); + connect(html_part,SIGNAL(popupMenu(const QString&, const QPoint& )), + this,SLOT(showPopupMenu(const QString&, const QPoint& ))); + connect(html_part,SIGNAL(searchFinished()),this,SLOT(onFinished())); + connect(html_part,SIGNAL(saveTorrent(const KURL& )), + this,SLOT(onSaveTorrent(const KURL& ))); + + KParts::PartManager* pman = html_part->partManager(); + connect(pman,SIGNAL(partAdded(KParts::Part*)),this,SLOT(onFrameAdded(KParts::Part* ))); + + connect(html_part->browserExtension(),SIGNAL(loadingProgress(int)),this,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,SIGNAL(popupMenu(const QString&, const QPoint& )), + this,SLOT(showPopupMenu(const QString&, const QPoint& ))); + } + } + + void SearchWidget::copy() + { + if (!html_part) + return; + html_part->copy(); + } + + void SearchWidget::search(const QString & 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(); + + QString 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 QString & url) + { + statusBarMsg(url); + } + + void SearchWidget::onFinished() + { + } + + void SearchWidget::onOpenTorrent(const KURL & url) + { + openTorrent(url); + } + + void SearchWidget::onSaveTorrent(const KURL & url) + { + KFileDialog fdlg(QString::null,"*.torrent | " + i18n("torrent files"),this,0,true); + fdlg.setSelection(url.fileName()); + fdlg.setOperationMode(KFileDialog::Saving); + if (fdlg.exec() == QDialog::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 QString & url,const QPoint & 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 QString & 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/plugins/search/searchwidget.h b/plugins/search/searchwidget.h new file mode 100644 index 0000000..36fb73e --- /dev/null +++ b/plugins/search/searchwidget.h @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [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. * + ***************************************************************************/ +#ifndef BTSEARCHWIDGET_H +#define BTSEARCHWIDGET_H + +#include <qwidget.h> +#include <qvaluevector.h> +#include <kurl.h> + +class SearchBar; +class KProgress; +class KPopupMenu; + +namespace KParts +{ + class Part; +} + +namespace kt +{ + class HTMLPart; + class SearchPlugin; + class SearchEngineList; + + + /** + @author Joris Guisson + + Widget which shows a KHTML window with the users search in it + */ + class SearchWidget : public QWidget + { + Q_OBJECT + public: + SearchWidget(SearchPlugin* sp); + virtual ~SearchWidget(); + + KPopupMenu* rightClickMenu(); + + void updateSearchEngines(const SearchEngineList & sl); + + public slots: + void search(const QString & text,int engine = 0); + void copy(); + void onShutDown(); + + private slots: + void searchPressed(); + void clearPressed(); + void onURLHover(const QString & url); + void onFinished(); + void onOpenTorrent(const KURL & url); + void onSaveTorrent(const KURL & url); + void showPopupMenu(const QString & s,const QPoint & p); + void onBackAvailable(bool available); + void onFrameAdded(KParts::Part* p); + void statusBarMsg(const QString & url); + void openTorrent(const KURL & url); + void loadingProgress(int perc); + + private: + HTMLPart* html_part; + SearchBar* sbar; + KPopupMenu* right_click_menu; + int back_id; + SearchPlugin* sp; + KProgress* prog; + }; + +} + +#endif |