diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 43c55448..5758ad8d 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,52 +1,52 @@
MACRO (MACRO_KT_PLUGIN _option _name _dir)
option(${_option} "Whether to build the ${_name} plugin or not" true)
if (${_option})
message(STATUS "Building ${_name} plugin (-D${_option}=false to disable)")
add_subdirectory(${_dir})
else (${_option})
message(STATUS "Not building ${_name} plugin (-D${_option}=true to enable)")
endif (${_option})
ENDMACRO (MACRO_KT_PLUGIN)
find_package(Taglib)
#find_package(Qt5 ${QT_MIN_VERSION} OPTIONAL_COMPONENTS Multimedia MultimediaWidgets)
find_package(Phonon4Qt5)
find_package(KF5 5.15 OPTIONAL_COMPONENTS WebKit IconThemes DNSSD Plotting)
find_package(KF5 OPTIONAL_COMPONENTS Syndication)
find_package(LibKWorkspace CONFIG)
set_package_properties(LibKWorkspace
PROPERTIES
TYPE OPTIONAL
PURPOSE "Required for KTorrent's shutdown plugin"
)
macro_kt_plugin(ENABLE_LOGVIEWER_PLUGIN logviewer logviewer)
macro_kt_plugin(ENABLE_INFOWIDGET_PLUGIN infowidget infowidget)
macro_kt_plugin(ENABLE_UPNP_PLUGIN upnp upnp)
if (KF5_WebKit_FOUND AND KF5_IconThemes_FOUND)
-# macro_kt_plugin(ENABLE_SEARCH_PLUGIN search search)
+ macro_kt_plugin(ENABLE_SEARCH_PLUGIN search search)
endif()
#macro_kt_plugin(ENABLE_WEBINTERFACE_PLUGIN webinterface webinterface)
macro_kt_plugin(ENABLE_SCANFOLDER_PLUGIN scanfolder scanfolder)
macro_kt_plugin(ENABLE_IPFILTER_PLUGIN ipfilter ipfilter)
macro_kt_plugin(ENABLE_STATS_PLUGIN stats stats)
macro_kt_plugin(ENABLE_BWSCHEDULER_PLUGIN bwscheduler bwscheduler)
if (TAGLIB_FOUND AND PHONON_FOUND_EXPERIMENTAL) #AND Qt5Multimedia_FOUND)
macro_kt_plugin(ENABLE_MEDIAPLAYER_PLUGIN mediaplayer mediaplayer)
endif()
macro_kt_plugin(ENABLE_SCRIPTING_PLUGIN scripting scripting)
if (KF5_Syndication_FOUND AND KF5_WebKit_FOUND)
macro_kt_plugin(ENABLE_SYNDICATION_PLUGIN syndication syndication)
endif()
macro_kt_plugin(ENABLE_DOWNLOADORDER_PLUGIN downloadorder downloadorder)
if (LibKWorkspace_FOUND)
macro_kt_plugin(ENABLE_SHUTDOWN_PLUGIN shutdown shutdown)
endif()
if (KF5_DNSSD_FOUND)
macro_kt_plugin(ENABLE_ZEROCONF_PLUGIN zeroconf zeroconf)
endif()
macro_kt_plugin(ENABLE_MAGNETGENERATOR_PLUGIN magnetgenerator magnetgenerator)
#macro_kt_plugin(ENABLE_STREAMING_PLUGIN streaming streaming)
diff --git a/plugins/search/CMakeLists.txt b/plugins/search/CMakeLists.txt
index 9238cad5..06e71a95 100644
--- a/plugins/search/CMakeLists.txt
+++ b/plugins/search/CMakeLists.txt
@@ -1,34 +1,35 @@
set(ktsearchplugin_SRC
webview.cpp
localfilenetworkreply.cpp
buffernetworkreply.cpp
searchenginelist.cpp
searchprefpage.cpp
searchwidget.cpp
searchtoolbar.cpp
searchplugin.cpp
searchengine.cpp
opensearchdownloadjob.cpp
- searchactivity.cpp)
+ searchactivity.cpp
+ proxy_helper.cpp)
ki18n_wrap_ui(ktsearchplugin_SRC searchpref.ui)
kconfig_add_kcfg_files(ktsearchplugin_SRC searchpluginsettings.kcfgc)
add_library(ktorrent_search MODULE ${ktsearchplugin_SRC})
kcoreaddons_desktop_to_json(ktorrent_search ktorrent_search.desktop)
target_link_libraries(
ktorrent_search
ktcore
KF5::Torrent
Qt5::WebKitWidgets
KF5::Parts
KF5::WebKit
KF5::IconThemes
KF5::Notifications
)
install(TARGETS ktorrent_search DESTINATION ${KTORRENT_PLUGIN_INSTALL_DIR} )
install(FILES ktorrent_searchui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktorrent )
add_subdirectory(opensearch)
add_subdirectory(home)
diff --git a/plugins/search/ktsearchplugin.kcfg b/plugins/search/ktsearchplugin.kcfg
index 7326da23..09868200 100644
--- a/plugins/search/ktsearchplugin.kcfg
+++ b/plugins/search/ktsearchplugin.kcfg
@@ -1,33 +1,36 @@
0
-
+
+
+ true
+ truefalse/usr/bin/firefoxfalsefalse
diff --git a/plugins/search/opensearch/CMakeLists.txt b/plugins/search/opensearch/CMakeLists.txt
index 4fb202fa..2c7957d9 100644
--- a/plugins/search/opensearch/CMakeLists.txt
+++ b/plugins/search/opensearch/CMakeLists.txt
@@ -1,7 +1,8 @@
-install(FILES bitenova/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/bitenova )
-install(FILES bittorrent/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/bittorrent )
-install(FILES btjunkie/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/btjunkie )
-install(FILES ktorrents/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/ktorrents )
-install(FILES mininova/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/mininova )
-install(FILES thepiratebay/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/thepiratebay )
-install(FILES legittorrents/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/legittorrents )
\ No newline at end of file
+install(FILES btdb.in/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/btdb.in )
+install(FILES btdb.in/favicon.ico DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/btdb.in )
+install(FILES btdig.com/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/btdig.com )
+install(FILES btdig.com/favicon.ico DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/btdig.com )
+install(FILES duckduckgo.com/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/duckduckgo.com )
+install(FILES duckduckgo.com/favicon.ico DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/duckduckgo.com )
+install(FILES torrentproject.se/opensearch.xml DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/torrentproject.se )
+install(FILES torrentproject.se/favicon.ico DESTINATION ${DATA_INSTALL_DIR}/ktorrent/opensearch/torrentproject.se )
diff --git a/plugins/search/opensearch/bitenova/opensearch.xml b/plugins/search/opensearch/bitenova/opensearch.xml
deleted file mode 100644
index d93dec53..00000000
--- a/plugins/search/opensearch/bitenova/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- Bitenova
- Bitenova Search Engine
-
- http://www.bitenova.org/favicon.ico
-
diff --git a/plugins/search/opensearch/bittorrent/opensearch.xml b/plugins/search/opensearch/bittorrent/opensearch.xml
deleted file mode 100644
index 8a54bc55..00000000
--- a/plugins/search/opensearch/bittorrent/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- BitTorrent
- BitTorrent Search Engine
-
- http://www.bittorrent.com/favicon.ico
-
diff --git a/plugins/search/opensearch/btdb.in/favicon.ico b/plugins/search/opensearch/btdb.in/favicon.ico
new file mode 100644
index 00000000..ada4ced5
Binary files /dev/null and b/plugins/search/opensearch/btdb.in/favicon.ico differ
diff --git a/plugins/search/opensearch/btdb.in/opensearch.xml b/plugins/search/opensearch/btdb.in/opensearch.xml
new file mode 100644
index 00000000..5fc73e2f
--- /dev/null
+++ b/plugins/search/opensearch/btdb.in/opensearch.xml
@@ -0,0 +1,19 @@
+
+
+ http://btdb.in/
+ BTDB
+ BTDB.in torrent search
+ BTDB.in torrent search Firefox extension helps you search and download TV series, movies, music, ebooks and games. BTDB.in is a fast growing torrent search engine. 10 millions torrents, friendly community.
+ http://btdb.in/favicon.ico
+ bittorrent.db@gmail.com
+
+
+
+
+ BTDB.in
+ UTF-8
+ UTF-8
+ en-us
+ open
+ true
+
diff --git a/plugins/search/opensearch/btdig.com/favicon.ico b/plugins/search/opensearch/btdig.com/favicon.ico
new file mode 100644
index 00000000..125e72d3
Binary files /dev/null and b/plugins/search/opensearch/btdig.com/favicon.ico differ
diff --git a/plugins/search/opensearch/btdig.com/opensearch.xml b/plugins/search/opensearch/btdig.com/opensearch.xml
new file mode 100644
index 00000000..1ea647e4
--- /dev/null
+++ b/plugins/search/opensearch/btdig.com/opensearch.xml
@@ -0,0 +1,9 @@
+
+
+ BTDigg
+ Search in BTDigg
+
+ http://btdig.com/favicon.ico
+ BTDigg
+ UTF-8
+
diff --git a/plugins/search/opensearch/btjunkie/opensearch.xml b/plugins/search/opensearch/btjunkie/opensearch.xml
deleted file mode 100644
index 3dd6393e..00000000
--- a/plugins/search/opensearch/btjunkie/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- BTJunkie
- BTJunkie Search Engine
-
- http://www.btjunkie.org/favicon.ico
-
diff --git a/plugins/search/opensearch/duckduckgo.com/favicon.ico b/plugins/search/opensearch/duckduckgo.com/favicon.ico
new file mode 100644
index 00000000..d093082c
Binary files /dev/null and b/plugins/search/opensearch/duckduckgo.com/favicon.ico differ
diff --git a/plugins/search/opensearch/duckduckgo.com/opensearch.xml b/plugins/search/opensearch/duckduckgo.com/opensearch.xml
new file mode 100644
index 00000000..7bdd869b
--- /dev/null
+++ b/plugins/search/opensearch/duckduckgo.com/opensearch.xml
@@ -0,0 +1,9 @@
+
+
+DuckDuckGo
+Search DuckDuckGo
+UTF-8
+DuckDuckGo Search
+https://duckduckgo.com/favicon.ico
+
+
diff --git a/plugins/search/opensearch/ktorrents/opensearch.xml b/plugins/search/opensearch/ktorrents/opensearch.xml
deleted file mode 100644
index f1eba55e..00000000
--- a/plugins/search/opensearch/ktorrents/opensearch.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- KTorrents
- KTorrents Search Engine
-
- http://ktorrents.com/favicon.ico
-
-
diff --git a/plugins/search/opensearch/legittorrents/opensearch.xml b/plugins/search/opensearch/legittorrents/opensearch.xml
deleted file mode 100644
index c45f8422..00000000
--- a/plugins/search/opensearch/legittorrents/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- Legit Torrents
- 100% legally free media
-
- http://www.legittorrents.info/favicon.ico
-
\ No newline at end of file
diff --git a/plugins/search/opensearch/mininova/opensearch.xml b/plugins/search/opensearch/mininova/opensearch.xml
deleted file mode 100644
index 7b449ec8..00000000
--- a/plugins/search/opensearch/mininova/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- Mininova
- Mininova Search Engine
-
- http://www.mininova.org/favicon.ico
-
diff --git a/plugins/search/opensearch/thepiratebay/opensearch.xml b/plugins/search/opensearch/thepiratebay/opensearch.xml
deleted file mode 100644
index 9fd0a2ef..00000000
--- a/plugins/search/opensearch/thepiratebay/opensearch.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- The Pirate Bay
- The Pirate Bay Search Engine
-
- http://thepiratebay.org/favicon.ico
-
diff --git a/plugins/search/opensearch/torrentproject.se/favicon.ico b/plugins/search/opensearch/torrentproject.se/favicon.ico
new file mode 100644
index 00000000..2270bb1e
Binary files /dev/null and b/plugins/search/opensearch/torrentproject.se/favicon.ico differ
diff --git a/plugins/search/opensearch/torrentproject.se/opensearch.xml b/plugins/search/opensearch/torrentproject.se/opensearch.xml
new file mode 100644
index 00000000..b64fb3e9
--- /dev/null
+++ b/plugins/search/opensearch/torrentproject.se/opensearch.xml
@@ -0,0 +1,10 @@
+
+
+ Torrent Project
+ Torrent search engine
+ torrent bittorrent search engine
+
+
+ https://torrentproject.se/favicon.ico
+ UTF-8
+
diff --git a/plugins/search/opensearchdownloadjob.cpp b/plugins/search/opensearchdownloadjob.cpp
index 6afc9f96..3ee45f3f 100644
--- a/plugins/search/opensearchdownloadjob.cpp
+++ b/plugins/search/opensearchdownloadjob.cpp
@@ -1,130 +1,163 @@
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
#include
#include
#include "opensearchdownloadjob.h"
using namespace bt;
namespace kt
{
- OpenSearchDownloadJob::OpenSearchDownloadJob(const QUrl &url, const QString& dir) : url(url), dir(dir)
+ OpenSearchDownloadJob::OpenSearchDownloadJob(const QUrl &url, const QString& dir, ProxyHelper *proxy) : url(url), dir(dir), m_proxy(proxy)
{
}
OpenSearchDownloadJob::~OpenSearchDownloadJob()
{
}
void OpenSearchDownloadJob::start()
{
// first try to download the html page
KIO::StoredTransferJob* j = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo);
+
+ KIO::MetaData metadata = j->metaData();
+ m_proxy->ApplyProxy(metadata);
+ j->setMetaData(metadata);
+
connect(j, SIGNAL(result(KJob*)), this, SLOT(getFinished(KJob*)));
}
+ void OpenSearchDownloadJob::startDefault()
+ {
+ // second try to access the xml file
+ url.setPath(QLatin1String("/opensearch.xml"));
+ start();
+ }
+
void OpenSearchDownloadJob::getFinished(KJob* j)
{
if (j->error())
{
setError(j->error());
emitResult();
return;
}
QString str = QString(((KIO::StoredTransferJob*)j)->data());
- // try to find the link tags
- QRegExp rx(QLatin1String("]*)"), Qt::CaseInsensitive);
- int pos = 0;
+ if (url.path() != QLatin1String("/opensearch.xml")) {
+ // try to find the link tags
+ QRegExp rx(QLatin1String("]*)"), Qt::CaseInsensitive);
+ int pos = 0;
- while ((pos = rx.indexIn(str, pos)) != -1)
- {
- QString link_tag = rx.cap(1);
- // exit when we find the description
- if (checkLinkTagContent(link_tag))
- return;
+ while ((pos = rx.indexIn(str, pos)) != -1)
+ {
+ QString link_tag = rx.cap(1);
+ // exit when we find the description
+ if (checkLinkTagContent(link_tag))
+ return;
- pos += rx.matchedLength();
+ pos += rx.matchedLength();
+ }
}
+ else {
+ if (str.contains(""))
+ {
+ if (startXMLDownload(url))
+ return;
+ }
+ setError(KIO::ERR_INTERNAL);
+ emitResult();
+ return;
+ }
- // no link tag found emit error
- setError(KIO::ERR_INTERNAL);
- emitResult();
+ // no link to openSearch xml found in html.
+ // make last attempt to access it by :///opensearch.xml
+ startDefault();
}
- bool OpenSearchDownloadJob::checkLinkTagContent(const QString& content)
+ bool OpenSearchDownloadJob::startXMLDownload(const QUrl& url)
{
- if (htmlParam("type", content) != QLatin1String("application/opensearchdescription+xml"))
- return false;
-
- QString href = htmlParam("href", content);
- if (href.isEmpty())
- return false;
-
- if (href.startsWith('/'))
- href = url.scheme() + QLatin1String("://") + url.host() + href;
-
if (!bt::Exists(dir))
{
try
{
bt::MakeDir(dir);
}
catch (...)
{
return false;
}
}
// href is the opensearch description, so lets try to download it
- KIO::Job* j = KIO::copy(QUrl(href), QUrl::fromLocalFile(dir + QLatin1String("opensearch.xml")), KIO::HideProgressInfo);
+ KIO::Job* j = KIO::copy(url, QUrl::fromLocalFile(dir + QLatin1String("opensearch.xml")), KIO::HideProgressInfo);
connect(j, SIGNAL(result(KJob*)), this, SLOT(xmlFileDownloadFinished(KJob*)));
return true;
}
+ bool OpenSearchDownloadJob::checkLinkTagContent(const QString& content)
+ {
+ if (htmlParam("type", content) != QLatin1String("application/opensearchdescription+xml"))
+ return false;
+
+ QString href = htmlParam("href", content);
+ if (href.isEmpty())
+ return false;
+
+ if (href.startsWith("//")) { // href may point to other domain without protocol like "//not_here.com/search.xml"
+ href = url.scheme() + QLatin1String(":") + href;
+ }
+ else if (href.startsWith('/')) {
+ href = url.scheme() + QLatin1String("://") + url.host() + href;
+ }
+
+ return startXMLDownload(QUrl(href));
+ }
+
QString OpenSearchDownloadJob::htmlParam(const QString& param, const QString& content)
{
QRegExp rx(QString::fromLatin1("%1=\"?([^\">< ]*)[\" ]").arg(param), Qt::CaseInsensitive);
if (rx.indexIn(content, 0) == -1)
return QString();
return rx.cap(1);
}
void OpenSearchDownloadJob::xmlFileDownloadFinished(KJob* j)
{
if (j->error())
{
setError(j->error());
emitResult();
}
else
{
setError(0);
emitResult();
}
}
}
diff --git a/plugins/search/opensearchdownloadjob.h b/plugins/search/opensearchdownloadjob.h
index 1ab11514..0c4b90cf 100644
--- a/plugins/search/opensearchdownloadjob.h
+++ b/plugins/search/opensearchdownloadjob.h
@@ -1,65 +1,72 @@
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 KTOPENSEARCHDOWNLOADJOB_H
#define KTOPENSEARCHDOWNLOADJOB_H
#include
#include
+#include "proxy_helper.h"
+
namespace kt
{
/**
Job which tries to find an opensearch xml description on a website and
download that to a directory.
*/
class OpenSearchDownloadJob : public KIO::Job
{
Q_OBJECT
public:
- OpenSearchDownloadJob(const QUrl &url, const QString& dir);
+ OpenSearchDownloadJob(const QUrl &url, const QString& dir, ProxyHelper *proxy);
virtual ~OpenSearchDownloadJob();
/// Start the job
void start();
+ /// Start the job. Try to get file by default url
+ void startDefault();
+
/// Get the directory
QString directory() const {return dir;}
/// Get the hostname
QString hostname() const {return url.host();}
private slots:
void getFinished(KJob* j);
void xmlFileDownloadFinished(KJob* j);
private:
bool checkLinkTagContent(const QString& content);
QString htmlParam(const QString& param, const QString& content);
+ bool startXMLDownload(const QUrl& url);
private:
QUrl url;
QString dir;
+ ProxyHelper* m_proxy;
};
}
#endif
diff --git a/plugins/search/searchplugin.h b/plugins/search/proxy_helper.cpp
similarity index 56%
copy from plugins/search/searchplugin.h
copy to plugins/search/proxy_helper.cpp
index 8923c6af..83d39fe1 100644
--- a/plugins/search/searchplugin.h
+++ b/plugins/search/proxy_helper.cpp
@@ -1,62 +1,58 @@
/***************************************************************************
- * Copyright (C) 2005-2007 by Joris Guisson *
- * joris.guisson@gmail.com *
+ * Copyright (C) 2017 by Alexander Trufanov *
+ * trufanovan@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
-#include
-#include
-#include "searchenginelist.h"
+#include "proxy_helper.h"
namespace kt
{
- class SearchPrefPage;
- class SearchActivity;
- /**
- @author Joris Guisson
- */
- class SearchPlugin : public Plugin
- {
- Q_OBJECT
- public:
- SearchPlugin(QObject* parent, const QVariantList& args);
- virtual ~SearchPlugin();
+ProxyHelper::ProxyHelper(DBusSettings* settings): m_settings(settings)
+{
- virtual void load();
- virtual void unload();
- virtual bool versionCheck(const QString& version) const;
+}
- SearchEngineList* getSearchEngineList() const {return engines;}
- SearchActivity* getSearchActivity() const {return activity;}
+bool ProxyHelper::ApplyProxy(KIO::MetaData& metadata) const
+{
+ if (!SearchPluginSettings::openInExternal() &&
+ SearchPluginSettings::useProxySettings() &&
+ m_settings)
+ {
+ if (!m_settings->useKDEProxySettings() &&
+ !m_settings->httpProxy().trimmed().isEmpty())
+ {
+ QString p = QString("%1:%2").arg(m_settings->httpProxy()).arg(m_settings->httpProxyPort());
+ if (!p.startsWith("http://"))
+ p = "http://" + p;
+
+ if (!QUrl(p).isValid()) {
+ p = QString("");
+ }
- private slots:
- void search(const QString& text, int engine, bool external);
- void preferencesUpdated();
+ metadata["UseProxy"] = p;
+ metadata["ProxyUrls"] = p;
+ }
- private:
- SearchActivity* activity;
- SearchPrefPage* pref;
- SearchEngineList* engines;
- };
+ return true;
+ }
+ return false;
}
-#endif
+}
diff --git a/plugins/search/searchplugin.h b/plugins/search/proxy_helper.h
similarity index 57%
copy from plugins/search/searchplugin.h
copy to plugins/search/proxy_helper.h
index 8923c6af..44685486 100644
--- a/plugins/search/searchplugin.h
+++ b/plugins/search/proxy_helper.h
@@ -1,62 +1,47 @@
/***************************************************************************
- * Copyright (C) 2005-2007 by Joris Guisson *
- * joris.guisson@gmail.com *
+ * Copyright (C) 2017 by Alexander Trufanov *
+ * trufanovan@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
-#include
-#include
-#include "searchenginelist.h"
-namespace kt
-{
- class SearchPrefPage;
- class SearchActivity;
- /**
- @author Joris Guisson
- */
- class SearchPlugin : public Plugin
- {
- Q_OBJECT
- public:
- SearchPlugin(QObject* parent, const QVariantList& args);
- virtual ~SearchPlugin();
+#ifndef KT_PROXY_HELPER_H
+#define KT_PROXY_HELPER_H
- virtual void load();
- virtual void unload();
- virtual bool versionCheck(const QString& version) const;
+#include
- SearchEngineList* getSearchEngineList() const {return engines;}
- SearchActivity* getSearchActivity() const {return activity;}
+#include
+#include
- private slots:
- void search(const QString& text, int engine, bool external);
- void preferencesUpdated();
+#include "searchpluginsettings.h"
- private:
- SearchActivity* activity;
- SearchPrefPage* pref;
- SearchEngineList* engines;
+namespace kt
+{
+
+ class ProxyHelper
+ {
+ DBusSettings* m_settings;
+ public:
+ ProxyHelper(DBusSettings* settings);
+ void setSettings(DBusSettings* settings) {m_settings = settings;}
+ bool ApplyProxy (KIO::MetaData& metadata) const;
};
}
-#endif
+#endif // KT_HOMEPAGE_H
diff --git a/plugins/search/searchengine.cpp b/plugins/search/searchengine.cpp
index b4d83767..4477fa5c 100644
--- a/plugins/search/searchengine.cpp
+++ b/plugins/search/searchengine.cpp
@@ -1,154 +1,166 @@
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
#include
#include
#include
#include
+#include
#include "searchengine.h"
using namespace bt;
namespace kt
{
class OpenSearchHandler : public QXmlDefaultHandler
{
public:
OpenSearchHandler(SearchEngine* engine) : engine(engine)
{
}
virtual ~OpenSearchHandler()
{
}
virtual bool characters(const QString& ch)
{
tmp += ch;
return true;
}
virtual bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts)
{
Q_UNUSED(namespaceURI);
Q_UNUSED(qName);
tmp = QString();
if (localName == QLatin1String("Url"))
{
if (atts.value(QLatin1String("type")) == QLatin1String("text/html"))
engine->url = atts.value(QLatin1String("template"));
}
return true;
}
virtual bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName)
{
Q_UNUSED(namespaceURI);
Q_UNUSED(qName);
if (localName == QLatin1String("ShortName"))
engine->name = tmp;
else if (localName == QLatin1String("Description"))
engine->description = tmp;
else if (localName == QLatin1String("Image"))
engine->icon_url = tmp;
return true;
}
SearchEngine* engine;
QString tmp;
};
SearchEngine::SearchEngine(const QString& data_dir) : data_dir(data_dir)
{
}
SearchEngine::~SearchEngine()
{
}
bool SearchEngine::load(const QString& xml_file)
{
QXmlSimpleReader xml_reader;
QFile fptr(xml_file);
QXmlInputSource source(&fptr);
OpenSearchHandler hdlr(this);
xml_reader.setErrorHandler(&hdlr);
xml_reader.setContentHandler(&hdlr);
if (!xml_reader.parse(&source))
{
Out(SYS_SRC | LOG_NOTICE) << "Failed to parse opensearch description !" << endl;
return false;
}
// check if icon file is present in data_dir
// if not, download it
if (!icon_url.isEmpty())
{
QString icon_name = QUrl(icon_url).fileName();
- if (!bt::Exists(data_dir + icon_name))
+ QString icon_filename = data_dir + icon_name;
+ bool found = false;
+ found = bt::Exists(icon_filename);
+ if (!found) {
+ // if there is an icon in xml file folder - use it
+ // xml file folder might not be equal to data_dir
+ icon_filename = QFileInfo(fptr).absolutePath() + '/' + icon_name;
+ found = bt::Exists(icon_filename);
+ }
+
+
+ if (!found)
{
KJob* j = KIO::storedGet(QUrl(icon_url), KIO::Reload, KIO::HideProgressInfo);
connect(j, SIGNAL(result(KJob*)), this, SLOT(iconDownloadFinished(KJob*)));
}
else
{
// load the icon
- icon = QIcon(data_dir + icon_name);
+ icon = QIcon(icon_filename);
}
}
return true;
}
QUrl SearchEngine::search(const QString& terms)
{
QString r = url;
r = r.replace(QLatin1String("{searchTerms}"), terms);
return QUrl(r);
}
void SearchEngine::iconDownloadFinished(KJob* job)
{
if (!job->error())
{
QString icon_name = QUrl(icon_url).fileName();
KIO::StoredTransferJob* j = (KIO::StoredTransferJob*)job;
QFile fptr(data_dir + icon_name);
if (!fptr.open(QIODevice::WriteOnly))
{
Out(SYS_SRC | LOG_NOTICE) << "Failed to save icon: " << fptr.errorString() << endl;
return;
}
fptr.write(j->data());
fptr.close();
// load the icon
icon = QIcon(data_dir + icon_name);
}
}
}
diff --git a/plugins/search/searchenginelist.cpp b/plugins/search/searchenginelist.cpp
index 284ad10d..4e2ad654 100644
--- a/plugins/search/searchenginelist.cpp
+++ b/plugins/search/searchenginelist.cpp
@@ -1,392 +1,393 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
+#include
#include "searchenginelist.h"
#include "opensearchdownloadjob.h"
using namespace bt;
namespace kt
{
- QString DataDir();
- SearchEngineList::SearchEngineList(const QString& data_dir) : data_dir(data_dir)
+ SearchEngineList::SearchEngineList(ProxyHelper *proxy, const QString& data_dir) : m_proxy(proxy), data_dir(data_dir)
{
- default_opensearch_urls << QUrl(QLatin1String("http://www.torrentz.com")) << QUrl(QLatin1String("http://isohunt.com"));
- default_urls << QUrl(QLatin1String("http://www.ktorrents.com"))
- << QUrl(QLatin1String("http://www.bittorrent.com"))
- << QUrl(QLatin1String("http://www.mininova.org"))
- << QUrl(QLatin1String("http://thepiratebay.org"))
- << QUrl(QLatin1String("http://www.bitenova.org"))
- << QUrl(QLatin1String("http://btjunkie.org"));
+ // default_opensearch_urls << QUrl(QLatin1String("https://torrentproject.com"));
+ default_urls << QUrl(QLatin1String("http://btdig.com"))
+ << QUrl(QLatin1String("http://btdb.in"))
+ << QUrl(QLatin1String("https://torrentproject.se"))
+ << QUrl(QLatin1String("http://duckduckgo.com"));
}
SearchEngineList::~SearchEngineList()
{
qDeleteAll(engines);
}
void SearchEngineList::loadEngines()
{
if (!bt::Exists(data_dir))
{
if (bt::Exists(kt::DataDir() + QLatin1String("search_engines")))
{
try
{
if (!bt::Exists(data_dir))
bt::MakeDir(data_dir);
}
catch (...)
{
return;
}
convertSearchEnginesFile();
}
else
{
Out(SYS_SRC | LOG_DEBUG) << "Setting up default engines" << endl;
addDefaults();
}
}
else
{
- QStringList subdirs = QDir(data_dir).entryList(QDir::Dirs);
+ QStringList subdirs = QDir(data_dir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (const QString& sd, subdirs)
{
- if (sd == QLatin1String("..") || sd == QLatin1String("."))
- continue;
// Load only if there is an opensearch.xml file and not a removed file
if (bt::Exists(data_dir + sd + QLatin1String("/opensearch.xml")) && !bt::Exists(data_dir + sd + QLatin1String("/removed")))
{
Out(SYS_SRC | LOG_DEBUG) << "Loading " << sd << endl;
SearchEngine* se = new SearchEngine(data_dir + sd + '/');
if (!se->load(data_dir + sd + QLatin1String("/opensearch.xml")))
delete se;
else
engines.append(se);
}
}
// check if new engines have been added
loadDefault(false);
}
}
void SearchEngineList::convertSearchEnginesFile()
{
QFile fptr(kt::DataDir() + QLatin1String("search_engines"));
if (!fptr.open(QIODevice::ReadOnly))
{
addDefaults();
return;
}
QTextStream in(&fptr);
while (!in.atEnd())
{
QString line = in.readLine();
if (line.startsWith('#') || line.startsWith(' ') || line.isEmpty()) continue;
QStringList tokens = line.split(' ');
QString name = tokens[0];
name = name.replace(QLatin1String("%20"), QLatin1String(" "));
QUrl url = QUrl(tokens[1]);
for (Uint32 i = 2; i < (Uint32)tokens.count(); ++i)
url.addQueryItem(tokens[i].section('=', 0, 0), tokens[i].section('=', 1, 1));
try
{
QString dir = data_dir + name;
if (!dir.endsWith('/'))
dir += '/';
bt::MakeDir(dir);
addEngine(dir, url.toDisplayString().replace(QLatin1String("FOOBAR"), QLatin1String("{searchTerms}")));
}
catch (bt::Error& err)
{
Out(SYS_SRC | LOG_NOTICE) << err.toString() << endl;
}
}
}
QUrl SearchEngineList::search(bt::Uint32 engine, const QString& terms)
{
QUrl u;
if (engine < (Uint32)engines.count())
u = engines[engine]->search(terms);
Out(SYS_SRC | LOG_NOTICE) << "Searching " << u.toDisplayString() << endl;
return u;
}
QString SearchEngineList::getEngineName(bt::Uint32 engine) const
{
if (engine >= (Uint32)engines.count())
return QString::null;
else
return engines[engine]->engineName();
}
void SearchEngineList::openSearchDownloadJobFinished(KJob* j)
{
OpenSearchDownloadJob* osdj = (OpenSearchDownloadJob*)j;
- if (osdj->error())
- bt::Delete(osdj->directory(), true);
-
- SearchEngine* se = new SearchEngine(osdj->directory());
- if (!se->load(osdj->directory() + QLatin1String("opensearch.xml")))
+ if (!osdj->error())
{
- delete se;
+ SearchEngine* se = new SearchEngine(osdj->directory());
+ if (!se->load(osdj->directory() + QLatin1String("opensearch.xml")))
+ {
+ delete se;
+ bt::Delete(osdj->directory(), true);
+ }
+ else {
+ engines.append(se);
+ insertRow(engines.count() - 1);
+ }
+ }
+ else {
bt::Delete(osdj->directory(), true);
}
- else
- engines.append(se);
-
- insertRow(engines.count() - 1);
}
void SearchEngineList::addEngine(OpenSearchDownloadJob* j)
{
openSearchDownloadJobFinished(j);
}
void SearchEngineList::addEngine(const QString& dir, const QString& url)
{
QFile fptr(dir + QLatin1String("opensearch.xml"));
if (!fptr.open(QIODevice::WriteOnly))
throw bt::Error(i18n("Cannot open %1: %2", dir + QLatin1String("opensearch.xml"), fptr.errorString()));
QUrl kurl(url);
QTextStream out(&fptr);
QString xml_template = QLatin1String("\n"
"\n"
"%1\n"
"\n"
"%3/favicon.ico\n"
"\n");
QString base = kurl.scheme() + QLatin1String("://") + kurl.host();
if (kurl.port() > 0)
base += QString::fromLatin1(":%1").arg(kurl.port());
QString tmp = url;
tmp = tmp.replace('&', QLatin1String("&"));
out << xml_template.arg(kurl.host()).arg(tmp).arg(base) << endl;
SearchEngine* se = new SearchEngine(dir);
if (!se->load(dir + QLatin1String("opensearch.xml")))
{
delete se;
throw bt::Error(i18n("Failed to parse %1", dir + QLatin1String("opensearch.xml")));
}
engines.append(se);
insertRow(engines.count() - 1);
}
void SearchEngineList::removeEngines(const QModelIndexList& sel)
{
QList to_remove;
foreach (const QModelIndex& idx, sel)
{
if (idx.isValid() && idx.row() >= 0 && idx.row() < engines.count())
to_remove.append(engines.at(idx.row()));
}
foreach (SearchEngine* se, to_remove)
{
bt::Touch(se->engineDir() + QLatin1String("removed"));
engines.removeAll(se);
delete se;
}
reset();
}
void SearchEngineList::removeAllEngines()
{
removeRows(0, engines.count(), QModelIndex());
engines.clear();
reset();
}
void SearchEngineList::addDefaults()
{
// data dir does not exist yet so create it and add the default list
try
{
if (!bt::Exists(data_dir))
bt::MakeDir(data_dir);
}
catch (...)
{
return;
}
foreach (const QUrl &u, default_opensearch_urls)
{
Out(SYS_SRC | LOG_DEBUG) << "Setting up default engine " << u.toDisplayString() << endl;
QString dir = data_dir + u.host() + '/';
if (!bt::Exists(dir))
{
- OpenSearchDownloadJob* j = new OpenSearchDownloadJob(u, dir);
+ OpenSearchDownloadJob* j = new OpenSearchDownloadJob(u, dir, m_proxy);
connect(j, SIGNAL(result(KJob*)), this, SLOT(openSearchDownloadJobFinished(KJob*)));
j->start();
}
else
{
loadEngine(dir, dir, true);
}
}
// also add the engines which don't have an opensearch description
loadDefault(true);
reset();
}
void SearchEngineList::loadEngine(const QString& global_dir, const QString& user_dir, bool load_removed)
{
if (!bt::Exists(user_dir))
{
// create directory to store icons
bt::MakeDir(user_dir);
}
if (bt::Exists(user_dir + QLatin1String("removed")))
{
// if the removed file is there don't load, if we are not allowed
if (!load_removed)
return;
else
bt::Delete(user_dir + QLatin1String("removed"));
}
if (!alreadyLoaded(user_dir))
{
SearchEngine* se = new SearchEngine(user_dir);
if (!se->load(global_dir + QLatin1String("opensearch.xml")))
delete se;
else
engines.append(se);
}
}
void SearchEngineList::loadDefault(bool removed_to)
{
- QStringList dir_list = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("ktorrent/opensearch"));
+ QStringList dir_list = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("ktorrent/opensearch"), QStandardPaths::LocateDirectory);
+ if (dir_list.isEmpty())
+ dir_list = QStandardPaths::locateAll(QStandardPaths::DataLocation, QLatin1String("ktorrent/opensearch"), QStandardPaths::LocateDirectory);
+ if (dir_list.isEmpty())
+ dir_list = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QLatin1String("ktorrent/opensearch"), QStandardPaths::LocateDirectory);
+
foreach (const QString& dir, dir_list)
{
- QStringList subdirs = QDir(dir).entryList(QDir::Dirs);
+ QStringList subdirs = QDir(dir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (const QString& sd, subdirs)
{
- if (sd == QLatin1String("..") || sd == QLatin1String("."))
- continue;
-
- loadEngine(dir + sd + '/', data_dir + sd + '/', removed_to);
+ loadEngine(QDir::cleanPath(dir) + '/' + sd + '/', data_dir + sd + '/', removed_to);
}
}
}
bool SearchEngineList::alreadyLoaded(const QString& user_dir)
{
foreach (const SearchEngine* se, engines)
{
if (se->engineDir() == user_dir)
return true;
}
return false;
}
int SearchEngineList::rowCount(const QModelIndex& parent) const
{
if (!parent.isValid())
return engines.count();
else
return 0;
}
QVariant SearchEngineList::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
SearchEngine* se = engines.at(index.row());
if (!se)
return QVariant();
if (role == Qt::DisplayRole)
{
return se->engineName();
}
else if (role == Qt::DecorationRole)
{
return se->engineIcon();
}
else if (role == Qt::ToolTipRole)
{
return i18n("URL: %1", se->engineUrl());
}
return QVariant();
}
bool SearchEngineList::insertRows(int row, int count, const QModelIndex& parent)
{
Q_UNUSED(parent);
beginInsertRows(QModelIndex(), row, row + count - 1);
endInsertRows();
return true;
}
bool SearchEngineList::removeRows(int row, int count, const QModelIndex& parent)
{
Q_UNUSED(parent);
beginRemoveRows(QModelIndex(), row, row + count - 1);
for (int i = 0; i < count; i++)
{
SearchEngine* se = engines.takeAt(row);
bt::Touch(se->engineDir() + QLatin1String("removed"));
delete se;
}
endRemoveRows();
return true;
}
}
diff --git a/plugins/search/searchenginelist.h b/plugins/search/searchenginelist.h
index 4d611ae8..18c34860 100644
--- a/plugins/search/searchenginelist.h
+++ b/plugins/search/searchenginelist.h
@@ -1,106 +1,108 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
#include
#include
#include "searchengine.h"
+#include "proxy_helper.h"
namespace kt
{
class OpenSearchDownloadJob;
/**
@author Joris Guisson
*/
class SearchEngineList : public QAbstractListModel
{
Q_OBJECT
QList engines;
QList default_opensearch_urls;
QList default_urls;
+ ProxyHelper* m_proxy;
QString data_dir;
public:
- SearchEngineList(const QString& data_dir);
+ SearchEngineList(ProxyHelper* proxy, const QString& data_dir);
virtual ~SearchEngineList();
/// Load all engines
void loadEngines();
/// Search with an engine
QUrl search(bt::Uint32 engine, const QString& terms);
/// Get the name of an engine
QString getEngineName(bt::Uint32 engine) const;
/// Get the number of engines
bt::Uint32 getNumEngines() const {return engines.count();}
virtual int rowCount(const QModelIndex& parent) const;
virtual QVariant data(const QModelIndex& index, int role) const;
virtual bool insertRows(int row, int count, const QModelIndex& parent);
virtual bool removeRows(int row, int count, const QModelIndex& parent);
/**
* Remove all engines in a list
* @param sel The list
*/
void removeEngines(const QModelIndexList& sel);
/**
* Remove all engines
*/
void removeAllEngines();
/**
* Add all defaults engines (if they are not added yet)
*/
void addDefaults();
/**
* Add an engine from an OpenSearchDownloadJob
* @param j The OpenSearchDownloadJob
*/
void addEngine(OpenSearchDownloadJob* j);
/**
* Add an engine from a search URL
* @param dir The directory to use
* @param url The url
*/
void addEngine(const QString& dir, const QString& url);
private:
void convertSearchEnginesFile();
void loadDefault(bool removed_to);
bool alreadyLoaded(const QString& user_dir);
void loadEngine(const QString& global_dir, const QString& user_dir, bool load_removed);
private slots:
void openSearchDownloadJobFinished(KJob* j);
};
}
#endif
diff --git a/plugins/search/searchplugin.cpp b/plugins/search/searchplugin.cpp
index a773824a..9cd50a88 100644
--- a/plugins/search/searchplugin.cpp
+++ b/plugins/search/searchplugin.cpp
@@ -1,129 +1,133 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 "searchplugin.h"
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
+#include
#include "searchwidget.h"
#include "searchprefpage.h"
#include "searchtoolbar.h"
#include "searchpluginsettings.h"
#include "searchenginelist.h"
#include "searchactivity.h"
K_PLUGIN_FACTORY_WITH_JSON(ktorrent_search, "ktorrent_search.json", registerPlugin();)
using namespace bt;
namespace kt
{
SearchPlugin::SearchPlugin(QObject* parent, const QVariantList& args) : Plugin(parent), engines(0)
{
Q_UNUSED(args);
pref = 0;
}
SearchPlugin::~SearchPlugin()
{}
void SearchPlugin::load()
{
LogSystemManager::instance().registerSystem(i18nc("plugin name", "Search"), SYS_SRC);
- engines = new SearchEngineList(kt::DataDir() + "searchengines/");
+ proxy = new ProxyHelper((DBusSettings*) getCore()->getExternalInterface()->settings());
+ engines = new SearchEngineList(proxy, kt::DataDir() + "searchengines/");
engines->loadEngines();
pref = new SearchPrefPage(this, engines, 0);
getGUI()->addPrefPage(pref);
connect(getCore(), SIGNAL(settingsChanged()), this, SLOT(preferencesUpdated()));
activity = new SearchActivity(this, 0);
getGUI()->addActivity(activity);
activity->loadCurrentSearches();
activity->loadState(KSharedConfig::openConfig());
connect(pref, SIGNAL(clearSearchHistory()), activity, SLOT(clearSearchHistory()));
}
void SearchPlugin::unload()
{
LogSystemManager::instance().unregisterSystem(i18nc("plugin name", "Search"));
getGUI()->removeActivity(activity);
activity->saveCurrentSearches();
activity->saveState(KSharedConfig::openConfig());
getGUI()->removePrefPage(pref);
delete pref;
pref = 0;
disconnect(getCore(), SIGNAL(settingsChanged()), this, SLOT(preferencesUpdated()));
delete engines;
engines = 0;
delete activity;
activity = 0;
+ delete proxy;
+ proxy = 0;
}
void SearchPlugin::search(const QString& text, int engine, bool external)
{
if (external)
{
if (engine < 0 || engine >= (int)engines->getNumEngines())
engine = 0;
QUrl url = engines->search(engine, text);
if (SearchPluginSettings::useDefaultBrowser())
new KRun(url, QApplication::activeWindow());
else
KRun::runCommand(SearchPluginSettings::customBrowser() + ' ' + KShell::quoteArg(url.toDisplayString()), 0);
}
else
{
activity->search(text, engine);
getGUI()->setCurrentActivity(activity);
}
}
void SearchPlugin::preferencesUpdated()
{
}
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
index 8923c6af..4feaccfd 100644
--- a/plugins/search/searchplugin.h
+++ b/plugins/search/searchplugin.h
@@ -1,62 +1,65 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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
#include
#include
#include "searchenginelist.h"
+#include "proxy_helper.h"
namespace kt
{
class SearchPrefPage;
class SearchActivity;
/**
@author Joris Guisson
*/
class SearchPlugin : public Plugin
{
Q_OBJECT
public:
SearchPlugin(QObject* parent, const QVariantList& args);
virtual ~SearchPlugin();
virtual void load();
virtual void unload();
virtual bool versionCheck(const QString& version) const;
SearchEngineList* getSearchEngineList() const {return engines;}
SearchActivity* getSearchActivity() const {return activity;}
+ ProxyHelper* getProxy() const {return proxy;}
private slots:
void search(const QString& text, int engine, bool external);
void preferencesUpdated();
private:
SearchActivity* activity;
SearchPrefPage* pref;
SearchEngineList* engines;
+ ProxyHelper* proxy;
};
}
#endif
diff --git a/plugins/search/searchpref.ui b/plugins/search/searchpref.ui
index 9e6d7521..9963f47c 100644
--- a/plugins/search/searchpref.ui
+++ b/plugins/search/searchpref.ui
@@ -1,218 +1,228 @@
SearchPref0056936400500350Search PreferencesClear the search history combo boxes.Clear Search HistoryReset the default action taken when a torrent is downloaded.Reset Default Torrent ActionQt::Horizontal4020Restore all the active searches of the last sessionRestore previous searchesWhether or not to open searches in an external browser.Open searches in external browser
+
+
+
+ Whether or not to use the HTTP proxy settings for search.
+
+
+ Use proxy settings for search
+
+
+ Use the default browser configured in the system settings.Use default browserUse a custom browser.Custom browser path:Path of the custom browser.Qt::HorizontalQSizePolicy::Expanding4020Search EnginesQAbstractItemView::ExtendedSelectionAdd a new search engine.AddRemove all selected search engines.&RemoveRemove all search engines.R&emove AllQt::Vertical2040Add all default search engines.Add Defau<qPixmapFromMimeSource
diff --git a/plugins/search/searchprefpage.cpp b/plugins/search/searchprefpage.cpp
index 82709032..2d068f21 100644
--- a/plugins/search/searchprefpage.cpp
+++ b/plugins/search/searchprefpage.cpp
@@ -1,216 +1,217 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson, Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 "searchprefpage.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "searchplugin.h"
#include "searchenginelist.h"
#include "searchpluginsettings.h"
#include "opensearchdownloadjob.h"
using namespace bt;
namespace kt
{
SearchPrefPage::SearchPrefPage(SearchPlugin* plugin, SearchEngineList* sl, QWidget* parent)
: PrefPageInterface(SearchPluginSettings::self(), i18nc("plugin name", "Search"), QStringLiteral("edit-find"), parent), plugin(plugin), engines(sl)
{
setupUi(this);
m_engines->setModel(sl);
connect(m_add, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(m_remove, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(m_add_default, SIGNAL(clicked()), this, SLOT(addDefaultClicked()));
connect(m_remove_all, SIGNAL(clicked()), this, SLOT(removeAllClicked()));
connect(m_clear_history, SIGNAL(clicked()), this, SLOT(clearHistory()));
connect(m_engines->selectionModel(), SIGNAL(selectionChanged(const QItemSelection& , const QItemSelection&)),
this, SLOT(selectionChanged(const QItemSelection&, const QItemSelection&)));
connect(m_reset_default_action, SIGNAL(clicked()), this, SLOT(resetDefaultAction()));
connect(kcfg_useCustomBrowser, SIGNAL(toggled(bool)), this, SLOT(customToggled(bool)));
connect(kcfg_openInExternal, SIGNAL(toggled(bool)), this, SLOT(openInExternalToggled(bool)));
QButtonGroup* bg = new QButtonGroup(this);
bg->addButton(kcfg_useCustomBrowser);
bg->addButton(kcfg_useDefaultBrowser);
m_remove_all->setEnabled(sl->rowCount(QModelIndex()) > 0);
m_remove->setEnabled(false);
}
SearchPrefPage::~SearchPrefPage()
{}
void SearchPrefPage::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
Q_UNUSED(deselected);
m_remove->setEnabled(selected.count() > 0);
}
void SearchPrefPage::loadSettings()
{
openInExternalToggled(SearchPluginSettings::openInExternal());
}
void SearchPrefPage::loadDefaults()
{
loadSettings();
}
void SearchPrefPage::addClicked()
{
QString name = QInputDialog::getText(this, i18n("Add a Search Engine"),
i18n("Enter the hostname of the search engine (for example www.google.com):"));
if (name.isEmpty())
return;
if (!name.startsWith(QLatin1String("http://")) || !name.startsWith(QLatin1String("https://")))
name = QLatin1String("http://") + name;
QUrl url(name);
QString dir = kt::DataDir() + QLatin1String("searchengines/") + url.host();
int idx = 1;
while (bt::Exists(dir))
{
dir += QString::number(idx++);
}
dir += '/';
try
{
bt::MakeDir(dir, false);
}
catch (bt::Error& err)
{
KMessageBox::error(this, err.toString());
return;
}
- OpenSearchDownloadJob* j = new OpenSearchDownloadJob(url, dir);
+ OpenSearchDownloadJob* j = new OpenSearchDownloadJob(url, dir, plugin->getProxy());
connect(j, SIGNAL(result(KJob*)), this, SLOT(downloadJobFinished(KJob*)));
j->start();
}
void SearchPrefPage::downloadJobFinished(KJob* j)
{
OpenSearchDownloadJob* osdj = (OpenSearchDownloadJob*)j;
if (osdj->error())
{
QString msg = i18n("Opensearch is not supported by %1, you will need to enter the search URL manually. "
"The URL should contain {searchTerms}, ktorrent will replace this by the thing you are searching for.", osdj->hostname());
QString url = QInputDialog::getText(this, i18n("Add a Search Engine"), msg);
if (!url.isEmpty())
{
if (!url.contains(QLatin1String("{searchTerms}")))
{
KMessageBox::error(this, i18n("The URL %1 does not contain {searchTerms}.", url));
}
else
{
try
{
engines->addEngine(osdj->directory(), url);
}
catch (bt::Error& err)
{
KMessageBox::error(this, err.toString());
bt::Delete(osdj->directory(), true);
}
}
}
}
else
{
engines->addEngine(osdj);
}
}
void SearchPrefPage::removeClicked()
{
QModelIndexList sel = m_engines->selectionModel()->selectedRows();
engines->removeEngines(sel);
m_remove_all->setEnabled(engines->rowCount(QModelIndex()) > 0);
m_remove->setEnabled(m_engines->selectionModel()->selectedRows().count() > 0);
}
void SearchPrefPage::addDefaultClicked()
{
engines->addDefaults();
m_remove_all->setEnabled(engines->rowCount(QModelIndex()) > 0);
m_remove->setEnabled(m_engines->selectionModel()->selectedRows().count() > 0);
}
void SearchPrefPage::removeAllClicked()
{
engines->removeAllEngines();
m_remove_all->setEnabled(engines->rowCount(QModelIndex()) > 0);
m_remove->setEnabled(m_engines->selectionModel()->selectedRows().count() > 0);
}
void SearchPrefPage::customToggled(bool toggled)
{
kcfg_customBrowser->setEnabled(toggled);
}
void SearchPrefPage::openInExternalToggled(bool on)
{
kcfg_useCustomBrowser->setEnabled(on);
+ kcfg_useProxySettings->setEnabled(!on);
kcfg_customBrowser->setEnabled(on && SearchPluginSettings::useCustomBrowser());
kcfg_useDefaultBrowser->setEnabled(on);
}
void SearchPrefPage::clearHistory()
{
emit clearSearchHistory();
}
void SearchPrefPage::resetDefaultAction()
{
KMessageBox::enableMessage(":TorrentDownloadFinishedQuestion");
}
}
diff --git a/plugins/search/searchwidget.cpp b/plugins/search/searchwidget.cpp
index e4d77492..f2554572 100644
--- a/plugins/search/searchwidget.cpp
+++ b/plugins/search/searchwidget.cpp
@@ -1,283 +1,288 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Joris Guisson, Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 "searchwidget.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "searchplugin.h"
#include "searchenginelist.h"
#include "webview.h"
#include "searchactivity.h"
using namespace bt;
namespace kt
{
SearchWidget::SearchWidget(SearchPlugin* sp) : webview(0), sp(sp), prog(0), torrent_download(0)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
- webview = new WebView(this);
+ webview = new WebView(this, sp->getProxy());
KActionCollection* ac = sp->getSearchActivity()->part()->actionCollection();
sbar = new KToolBar(this);
sbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
sbar->addAction(webview->pageAction(QWebPage::Back));
sbar->addAction(webview->pageAction(QWebPage::Forward));
sbar->addAction(webview->pageAction(QWebPage::Reload));
sbar->addAction(ac->action(QStringLiteral("search_home")));
search_text = new QLineEdit(sbar);
sbar->addWidget(search_text);
sbar->addAction(ac->action(QStringLiteral("search_tab_search")));
- sbar->addWidget(new QLabel(i18n(" Engine:")));
+ sbar->addWidget(new QLabel(i18n(" Engine: "))); // same i18n string as in SearchToolBar()
search_engine = new KComboBox(sbar);
search_engine->setModel(sp->getSearchEngineList());
sbar->addWidget(search_engine);
connect(search_text, SIGNAL(returnPressed()), this, SLOT(search()));;
layout->addWidget(sbar);
layout->addWidget(webview);
search_text->setClearButtonEnabled(true);
connect(webview, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(webview, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
connect(webview, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
connect(webview->page(), SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(unsupportedContent(QNetworkReply*)));
connect(webview, SIGNAL(linkMiddleOrCtrlClicked(QUrl)), this, SIGNAL(openNewTab(QUrl)));
connect(webview, SIGNAL(iconChanged()), this, SLOT(iconChanged()));
connect(webview, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString)));
}
SearchWidget::~SearchWidget()
{
if (prog)
{
sp->getGUI()->getStatusBar()->removeProgressBar(prog);
prog = 0;
}
}
void SearchWidget::iconChanged()
{
changeIcon(this, webview->icon());
}
void SearchWidget::titleChanged(const QString& text)
{
- changeTitle(this, text);
+ if (!text.isEmpty()) {
+ changeTitle(this, text);
+ }
+ else { // no empty tab titles allowed
+ changeTitle(this, webview->url().toString(QUrl::FullyDecoded));
+ }
}
QUrl SearchWidget::getCurrentUrl() const
{
return webview->url();
}
QString SearchWidget::getSearchBarText() const
{
return search_text->text();
}
int SearchWidget::getSearchBarEngine() const
{
return search_engine->currentIndex();
}
void SearchWidget::restore(const QUrl &url, const QString& text, const QString& sb_text, int engine)
{
Q_UNUSED(text);
if (url.scheme() == QLatin1String("home"))
webview->home();
else
webview->openUrl(url);
search_text->setText(sb_text);
search_engine->setCurrentIndex(engine);
}
void SearchWidget::search(const QString& text, int engine)
{
if (search_text->text() != text)
search_text->setText(text);
if (search_engine->currentIndex() != engine)
search_engine->setCurrentIndex(engine);
QUrl url = sp->getSearchEngineList()->search(engine, text);
webview->openUrl(url);
}
QUrl SearchWidget::searchUrl(const QString& search_text)
{
return sp->getSearchEngineList()->search(search_engine->currentIndex(), search_text);
}
void SearchWidget::setSearchBarEngine(int engine)
{
search_engine->setCurrentIndex(engine);
}
void SearchWidget::loadProgress(int perc)
{
if (!prog)
prog = sp->getGUI()->getStatusBar()->createProgressBar();
if (prog)
prog->setValue(perc);
}
void SearchWidget::loadStarted()
{
if (!prog)
{
prog = sp->getGUI()->getStatusBar()->createProgressBar();
if (prog)
prog->setValue(0);
}
}
void SearchWidget::loadFinished(bool ok)
{
Q_UNUSED(ok);
if (prog)
{
sp->getGUI()->getStatusBar()->removeProgressBar(prog);
prog = 0;
}
}
void SearchWidget::magnetUrl(const QUrl& magnet_url)
{
MagnetLinkLoadOptions options;
options.silently = false;
sp->getCore()->load(bt::MagnetLink(magnet_url.toString()), options);
QString msg = i18n("Downloading: %1", magnet_url.toString());
KNotification::event("MagnetLinkDownloadStarted", msg, QPixmap(), sp->getGUI()->getMainWindow());
}
void SearchWidget::unsupportedContent(QNetworkReply* r)
{
if (r->url().scheme() == QLatin1String("magnet"))
{
magnetUrl(r->url());
}
else if (r->header(QNetworkRequest::ContentTypeHeader).toString() == QLatin1String("application/x-bittorrent") ||
r->url().path().endsWith(QLatin1String(".torrent")))
{
torrent_download = r;
if (!r->isFinished())
connect(r, SIGNAL(finished()), this, SLOT(torrentDownloadFinished()));
else
torrentDownloadFinished();
}
else
{
webview->downloadResponse(r);
}
}
void SearchWidget::torrentDownloadFinished()
{
if (!torrent_download)
return;
if (torrent_download->error() != QNetworkReply::NoError)
{
KMessageBox::error(this, torrent_download->errorString());
torrent_download = 0;
return;
}
int ret = KMessageBox::questionYesNoCancel(0,
i18n("Do you want to download or save the torrent?"),
i18n("Download Torrent"),
KGuiItem(i18n("Download"), "ktorrent"),
KStandardGuiItem::save(),
KStandardGuiItem::cancel(),
":TorrentDownloadFinishedQuestion");
if (ret == KMessageBox::Yes)
sp->getCore()->load(torrent_download->readAll(), torrent_download->url(), QString(), QString());
else if (ret == KMessageBox::No)
webview->downloadResponse(torrent_download);
torrent_download = 0;
}
void SearchWidget::search()
{
search(search_text->text(), search_engine->currentIndex());
}
QWebView* SearchWidget::newTab()
{
return sp->getSearchActivity()->newTab()->webview;
}
void SearchWidget::home()
{
webview->home();
}
bool SearchWidget::backAvailable() const
{
return webview->pageAction(QWebPage::Back)->isEnabled();
}
}
diff --git a/plugins/search/webview.cpp b/plugins/search/webview.cpp
index 3b2bb689..bc1e0edd 100644
--- a/plugins/search/webview.cpp
+++ b/plugins/search/webview.cpp
@@ -1,215 +1,215 @@
/***************************************************************************
* Copyright (C) 2009 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 "webview.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "buffernetworkreply.h"
#include "localfilenetworkreply.h"
-
using namespace bt;
namespace kt
{
class NetworkAccessManager : public KIO::AccessManager
{
public:
NetworkAccessManager(WebView* parent) : KIO::AccessManager(parent), webview(parent)
{
+ webview->getProxy()->ApplyProxy(sessionMetaData());
}
virtual ~NetworkAccessManager()
{}
virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest& req, QIODevice* outgoingData)
{
if (req.url().scheme() == QLatin1String("magnet"))
{
webview->handleMagnetUrl(req.url());
- return QNetworkAccessManager::createRequest(op, req, outgoingData);
+ return KIO::AccessManager::createRequest(op, req, outgoingData);
}
else if (req.url().host() == QLatin1String("ktorrent.searchplugin"))
{
QString search_text = req.url().queryItemValue(QLatin1String("search_text"));
if (!search_text.isEmpty())
{
QUrl url(webview->searchUrl(search_text));
QNetworkRequest request(url);
- webview->setUrl(url);
return KIO::AccessManager::createRequest(op, request, outgoingData);
}
else if (req.url().path() == QLatin1String("/"))
{
return new BufferNetworkReply(webview->homePageData().toLocal8Bit(), QLatin1String("text/html"), this);
}
else
{
return new LocalFileNetworkReply(webview->homePageBaseDir() + req.url().path(), this);
}
}
return KIO::AccessManager::createRequest(op, req, outgoingData);
}
WebView* webview;
};
//////////////////////////////////////////////////////
- WebView::WebView(kt::WebViewClient* client, QWidget* parentWidget)
- : KWebView(parentWidget), client(client)
+ WebView::WebView(kt::WebViewClient* client, ProxyHelper* proxy, QWidget* parentWidget)
+ : KWebView(parentWidget), client(client), m_proxy(proxy)
{
page()->setNetworkAccessManager(new NetworkAccessManager(this));
page()->setForwardUnsupportedContent(true);
connect(page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest)));
}
WebView::~WebView()
{
}
void WebView::handleMagnetUrl(const QUrl& magnet_url)
{
if (client)
client->magnetUrl(magnet_url);
}
void WebView::openUrl(const QUrl &url)
{
if (url.host() == QLatin1String("ktorrent.searchplugin"))
home();
else
load(url);
}
void WebView::home()
{
if (home_page_html.isEmpty())
loadHomePage();
load(QUrl(QLatin1String("http://ktorrent.searchplugin/")));
}
QString WebView::homePageData()
{
if (home_page_html.isEmpty())
loadHomePage();
return home_page_html;
}
void WebView::loadHomePage()
{
QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "ktorrent/search/home/home.html");
QFile fptr(file);
if (fptr.open(QIODevice::ReadOnly))
{
Out(SYS_SRC | LOG_DEBUG) << "Loading home page from " << file << endl;
home_page_base_url = file.left(file.lastIndexOf('/') + 1);
home_page_html = QTextStream(&fptr).readAll();
// %1
home_page_html = home_page_html.arg(QLatin1String("ktorrent_infopage.css"));
// %2
if (qApp->layoutDirection() == Qt::RightToLeft)
{
QString link = "";
link = link.arg(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdeui/about/kde_infopage_rtl.css"));
home_page_html = home_page_html.arg(link);
}
else
home_page_html = home_page_html.arg(QString());
KIconLoader* iconloader = KIconLoader::global();
int icon_size = iconloader->currentSize(KIconLoader::Desktop);
home_page_html = home_page_html
.arg(i18n("Home")) // %3 Title
.arg(i18n("KTorrent")) // %4
.arg(i18nc("KDE 4 tag line, see http://kde.org/img/kde40.png", "Be free.")) // %5
.arg(i18n("Search the web for torrents.")) // %6
.arg(i18n("Search")) // %7
.arg("search_text") // %8
.arg(icon_size).arg(icon_size); // %9 and %10
}
else
{
Out(SYS_SRC | LOG_IMPORTANT) << "Failed to load " << file << " : " << fptr.errorString() << endl;
}
}
QUrl WebView::searchUrl(const QString& search_text)
{
if (client)
return client->searchUrl(search_text);
else
- return QUrl("http://google.be");
+ // client is broken -> browse to home
+ return QUrl(QLatin1String("http://ktorrent.searchplugin/"));
}
QWebView* WebView::createWindow(QWebPage::WebWindowType type)
{
Q_UNUSED(type);
return client->newTab();
}
void WebView::downloadRequested(const QNetworkRequest& req)
{
QString filename = QFileInfo(req.url().path()).fileName();
QString path = QFileDialog::getExistingDirectory(this, i18n("Save %1 to"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
if (!path.isEmpty())
KIO::copy(req.url(), QUrl(path));
}
void WebView::downloadResponse(QNetworkReply* reply)
{
KWebPage* p = (KWebPage*)page();
p->downloadResponse(reply);
}
}
diff --git a/plugins/search/webview.h b/plugins/search/webview.h
index 59b34a07..ab80fdfa 100644
--- a/plugins/search/webview.h
+++ b/plugins/search/webview.h
@@ -1,113 +1,116 @@
/***************************************************************************
* Copyright (C) 2009 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 KT_WEBVIEW_H
#define KT_WEBVIEW_H
#include
#include
#include
+#include "proxy_helper.h"
namespace kt
{
class WebViewClient
{
public:
virtual ~WebViewClient() {}
/// Get a search url for a search text
virtual QUrl searchUrl(const QString& search_text) = 0;
/// Create a new tab
virtual QWebView* newTab() = 0;
/// Handle magnet urls
virtual void magnetUrl(const QUrl& magnet_url) = 0;
};
/**
WebView provides a webkit view which supports for the ktorrent homepage.
*/
class WebView : public KWebView
{
Q_OBJECT
public:
- WebView(WebViewClient* client, QWidget* parentWidget = 0);
+ WebView(WebViewClient* client, ProxyHelper* proxy, QWidget* parentWidget = 0);
virtual ~WebView();
/**
* Open a url
* @param url The QUrl
*/
void openUrl(const QUrl &url);
/**
* Show the home page
*/
void home();
/**
* Get a search url for a search text
* @param search_text The text to search
* @return A QUrl to load
*/
QUrl searchUrl(const QString& search_text);
/**
* Download a response using KIO
* @param reply The QNetworkReply to download
*/
void downloadResponse(QNetworkReply* reply);
/// Get the html code of the homepage
QString homePageData();
/// Get the home page base directory
QString homePageBaseDir() const {return home_page_base_url;}
/// Handle magnet url
void handleMagnetUrl(const QUrl& magnet_url);
+ /// Get heloper object that applies proxy settings
+ ProxyHelper* getProxy() const {return m_proxy;}
protected:
void loadHomePage();
virtual QWebView* createWindow(QWebPage::WebWindowType type);
public slots:
/**
* Download a netwerk request
* @param req The request
*/
void downloadRequested(const QNetworkRequest& req);
-
private:
QString home_page_html;
QString home_page_base_url;
WebViewClient* client;
QUrl clicked_url;
QUrl image_url;
+ ProxyHelper* m_proxy;
};
}
#endif // KT_HOMEPAGE_H