2007-03-27 22:49:29 +04:00
|
|
|
/*
|
2015-08-27 14:25:14 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
|
|
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
|
|
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
2007-03-27 22:49:29 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* 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.
|
2007-03-27 22:49:29 +04:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
2007-03-27 22:49:29 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
#include <iostream>
|
2007-11-30 13:48:00 +03:00
|
|
|
#include <QTimer>
|
2008-06-25 23:29:29 +04:00
|
|
|
#include <QDir>
|
2009-07-12 10:42:38 +04:00
|
|
|
#include <QMenu>
|
2009-07-12 11:12:43 +04:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QMimeData>
|
2009-10-25 02:49:10 +04:00
|
|
|
#include <QSortFilterProxyModel>
|
2010-05-30 21:51:40 +04:00
|
|
|
#include <QFileDialog>
|
2010-12-26 12:51:37 +03:00
|
|
|
#include <QDesktopServices>
|
2015-01-07 00:40:49 +03:00
|
|
|
#include <QClipboard>
|
2015-08-27 14:25:14 +03:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QDebug>
|
2010-05-30 21:51:40 +04:00
|
|
|
|
2013-09-21 11:59:58 +04:00
|
|
|
#ifdef Q_OS_WIN
|
2010-05-30 21:51:40 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
2007-03-27 22:49:29 +04:00
|
|
|
|
2015-09-25 11:10:05 +03:00
|
|
|
#include "base/bittorrent/session.h"
|
|
|
|
#include "base/utils/fs.h"
|
|
|
|
#include "base/utils/misc.h"
|
|
|
|
#include "base/preferences.h"
|
2015-08-27 14:25:14 +03:00
|
|
|
#include "base/searchengine.h"
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "searchlistdelegate.h"
|
2010-11-14 00:15:52 +03:00
|
|
|
#include "mainwindow.h"
|
2015-04-19 18:17:47 +03:00
|
|
|
#include "addnewtorrentdialog.h"
|
|
|
|
#include "guiiconprovider.h"
|
2012-08-26 11:10:50 +04:00
|
|
|
#include "lineedit.h"
|
2015-08-26 20:05:57 +03:00
|
|
|
#include "searchwidget.h"
|
2007-03-27 22:49:29 +04:00
|
|
|
|
|
|
|
#define SEARCHHISTORY_MAXSIZE 50
|
|
|
|
|
2008-06-25 23:04:42 +04:00
|
|
|
/*SEARCH ENGINE START*/
|
2015-08-26 20:05:57 +03:00
|
|
|
SearchWidget::SearchWidget(MainWindow* parent)
|
2015-07-28 23:55:40 +03:00
|
|
|
: QWidget(parent)
|
2015-11-07 07:34:52 +03:00
|
|
|
, search_pattern(new LineEdit(this))
|
2015-07-28 23:55:40 +03:00
|
|
|
, mp_mainWindow(parent)
|
2012-08-26 11:10:50 +04:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
setupUi(this);
|
|
|
|
searchBarLayout->insertWidget(0, search_pattern);
|
|
|
|
connect(search_pattern, SIGNAL(returnPressed()), search_button, SLOT(click()));
|
|
|
|
// Icons
|
2015-04-19 18:17:47 +03:00
|
|
|
search_button->setIcon(GuiIconProvider::instance()->getIcon("edit-find"));
|
|
|
|
download_button->setIcon(GuiIconProvider::instance()->getIcon("download"));
|
|
|
|
goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl"));
|
2015-08-27 14:25:14 +03:00
|
|
|
pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network"));
|
2015-01-07 00:40:49 +03:00
|
|
|
copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy"));
|
2014-10-31 00:14:44 +03:00
|
|
|
tabWidget->setTabsClosable(true);
|
|
|
|
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
2015-08-27 14:25:14 +03:00
|
|
|
|
|
|
|
m_searchEngine = new SearchEngine;
|
|
|
|
connect(m_searchEngine, SIGNAL(searchStarted()), SLOT(searchStarted()));
|
|
|
|
connect(m_searchEngine, SIGNAL(newSearchResults(QList<SearchResult>)), SLOT(appendSearchResults(QList<SearchResult>)));
|
|
|
|
connect(m_searchEngine, SIGNAL(searchFinished(bool)), SLOT(searchFinished(bool)));
|
|
|
|
connect(m_searchEngine, SIGNAL(searchFailed()), SLOT(searchFailed()));
|
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
// Fill in category combobox
|
|
|
|
fillCatCombobox();
|
2015-08-27 14:25:14 +03:00
|
|
|
fillPluginComboBox();
|
2014-10-31 00:14:44 +03:00
|
|
|
|
|
|
|
connect(search_pattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString)));
|
2015-08-27 14:25:14 +03:00
|
|
|
connect(selectPlugin, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &)));
|
2008-06-25 23:04:42 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::fillCatCombobox()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
comboCategory->clear();
|
2015-08-27 14:25:14 +03:00
|
|
|
comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all"));
|
|
|
|
QStringList supported_cat = m_searchEngine->supportedCategories();
|
2014-10-31 00:14:44 +03:00
|
|
|
foreach (QString cat, supported_cat) {
|
|
|
|
qDebug("Supported category: %s", qPrintable(cat));
|
2015-08-27 14:25:14 +03:00
|
|
|
comboCategory->addItem(SearchEngine::categoryFullName(cat), QVariant(cat));
|
2015-07-28 23:55:40 +03:00
|
|
|
}
|
2009-08-25 06:31:36 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
void SearchWidget::fillPluginComboBox()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
selectPlugin->clear();
|
|
|
|
selectPlugin->addItem(tr("All enabled"), QVariant("enabled"));
|
|
|
|
selectPlugin->addItem(tr("All plugins"), QVariant("all"));
|
|
|
|
foreach (QString name, m_searchEngine->enabledPlugins())
|
|
|
|
selectPlugin->addItem(name, QVariant(name));
|
|
|
|
selectPlugin->addItem(tr("Multiple..."), QVariant("multi"));
|
2014-10-31 00:14:44 +03:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
QString SearchWidget::selectedCategory() const
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
return comboCategory->itemData(comboCategory->currentIndex()).toString();
|
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
QString SearchWidget::selectedEngine() const
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
return selectPlugin->itemData(selectPlugin->currentIndex()).toString();
|
2009-08-25 06:31:36 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
SearchWidget::~SearchWidget()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
qDebug("Search destruction");
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
delete search_pattern;
|
2015-08-27 14:25:14 +03:00
|
|
|
delete m_searchEngine;
|
2008-06-25 23:04:42 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::tab_changed(int t)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
|
|
|
//when we switch from a tab that is not empty to another that is empty the download button
|
|
|
|
//doesn't have to be available
|
|
|
|
if (t > -1) {
|
|
|
|
//-1 = no more tab
|
2015-04-11 15:00:03 +03:00
|
|
|
currentSearchTab = all_tab.at(tabWidget->currentIndex());
|
|
|
|
if (currentSearchTab->getCurrentSearchListModel()->rowCount()) {
|
2014-10-31 00:14:44 +03:00
|
|
|
download_button->setEnabled(true);
|
|
|
|
goToDescBtn->setEnabled(true);
|
2015-01-07 00:40:49 +03:00
|
|
|
copyURLBtn->setEnabled(true);
|
2014-10-31 00:14:44 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
download_button->setEnabled(false);
|
|
|
|
goToDescBtn->setEnabled(false);
|
2015-01-07 00:40:49 +03:00
|
|
|
copyURLBtn->setEnabled(false);
|
2014-10-31 00:14:44 +03:00
|
|
|
}
|
2015-04-11 15:00:03 +03:00
|
|
|
search_status->setText(currentSearchTab->status);
|
2008-06-26 15:24:08 +04:00
|
|
|
}
|
2014-10-31 00:14:44 +03:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::selectMultipleBox(const QString &text)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
if (text == tr("Multiple...")) on_pluginsButton_clicked();
|
2008-06-26 15:24:08 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
void SearchWidget::on_pluginsButton_clicked()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
PluginSelectDlg *dlg = new PluginSelectDlg(m_searchEngine, this);
|
|
|
|
connect(dlg, SIGNAL(pluginsChanged()), this, SLOT(fillCatCombobox()));
|
|
|
|
connect(dlg, SIGNAL(pluginsChanged()), this, SLOT(fillPluginComboBox()));
|
2008-06-25 23:04:42 +04:00
|
|
|
}
|
2007-03-27 22:49:29 +04:00
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::searchTextEdited(QString)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
// Enable search button
|
|
|
|
search_button->setText(tr("Search"));
|
2015-08-02 14:51:41 +03:00
|
|
|
newQueryString = true;
|
2010-01-30 21:15:25 +03:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::giveFocusToSearchInput()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
search_pattern->setFocus();
|
2010-07-19 22:49:53 +04:00
|
|
|
}
|
|
|
|
|
2007-03-27 22:49:29 +04:00
|
|
|
// Function called when we click on search button
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::on_search_button_clicked()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-02-27 16:00:00 +03:00
|
|
|
if (Utils::Misc::pythonVersion() < 0) {
|
|
|
|
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
if (m_searchEngine->isActive()) {
|
|
|
|
m_searchEngine->cancelSearch();
|
2015-07-29 00:34:29 +03:00
|
|
|
|
2015-08-02 14:51:41 +03:00
|
|
|
if (!newQueryString) {
|
2014-10-31 00:14:44 +03:00
|
|
|
search_button->setText(tr("Search"));
|
|
|
|
return;
|
|
|
|
}
|
2009-08-25 06:31:36 +04:00
|
|
|
}
|
2015-07-29 00:34:29 +03:00
|
|
|
|
2015-08-02 14:51:41 +03:00
|
|
|
newQueryString = false;
|
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
const QString pattern = search_pattern->text().trimmed();
|
|
|
|
// No search pattern entered
|
|
|
|
if (pattern.isEmpty()) {
|
|
|
|
QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first"));
|
|
|
|
return;
|
2010-01-30 21:15:25 +03:00
|
|
|
}
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
// Tab Addition
|
|
|
|
currentSearchTab = new SearchTab(this);
|
2015-04-11 15:00:03 +03:00
|
|
|
activeSearchTab = currentSearchTab;
|
2015-02-12 19:23:24 +03:00
|
|
|
connect(currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth()));
|
2014-10-31 00:14:44 +03:00
|
|
|
all_tab.append(currentSearchTab);
|
|
|
|
QString tabName = pattern;
|
|
|
|
tabName.replace(QRegExp("&{1}"), "&&");
|
|
|
|
tabWidget->addTab(currentSearchTab, tabName);
|
|
|
|
tabWidget->setCurrentWidget(currentSearchTab);
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
QStringList plugins;
|
|
|
|
if (selectedEngine() == "all") plugins = m_searchEngine->allPlugins();
|
|
|
|
else if (selectedEngine() == "enabled") plugins = m_searchEngine->enabledPlugins();
|
|
|
|
else if (selectedEngine() == "multi") plugins = m_searchEngine->enabledPlugins();
|
|
|
|
else plugins << selectedEngine();
|
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
qDebug("Search with category: %s", qPrintable(selectedCategory()));
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
// Update SearchEngine widgets
|
|
|
|
no_search_results = true;
|
|
|
|
nb_search_results = 0;
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2015-05-04 02:09:30 +03:00
|
|
|
// Changing the text of the current label
|
2015-07-29 02:27:54 +03:00
|
|
|
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(0));
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
// Launch search
|
2015-08-27 14:25:14 +03:00
|
|
|
m_searchEngine->startSearch(pattern, selectedCategory(), plugins);
|
2007-03-27 22:49:29 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::saveResultsColumnsWidth()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-02-12 19:23:24 +03:00
|
|
|
if (all_tab.isEmpty())
|
|
|
|
return;
|
|
|
|
QTreeView* treeview = all_tab.first()->getCurrentTreeView();
|
|
|
|
Preferences* const pref = Preferences::instance();
|
|
|
|
QStringList new_width_list;
|
|
|
|
short nbColumns = all_tab.first()->getCurrentSearchListModel()->columnCount();
|
2015-07-28 23:55:40 +03:00
|
|
|
for (short i = 0; i < nbColumns; ++i)
|
2015-02-12 19:23:24 +03:00
|
|
|
if (treeview->columnWidth(i) > 0)
|
|
|
|
new_width_list << QString::number(treeview->columnWidth(i));
|
|
|
|
// Don't save the width of the last column (auto column width)
|
|
|
|
new_width_list.removeLast();
|
|
|
|
pref->setSearchColsWidth(new_width_list.join(" "));
|
2009-03-10 00:24:40 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
void SearchWidget::downloadTorrent(QString url)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
if (Preferences::instance()->useAdditionDialog())
|
|
|
|
AddNewTorrentDialog::show(url, this);
|
|
|
|
else
|
|
|
|
BitTorrent::Session::instance()->addTorrent(url);
|
2009-03-28 01:11:41 +03:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::searchStarted()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
// Update SearchEngine widgets
|
2015-04-11 15:00:03 +03:00
|
|
|
activeSearchTab->status = tr("Searching...");
|
2015-07-29 00:34:29 +03:00
|
|
|
search_status->setText(currentSearchTab->status);
|
2014-10-31 00:14:44 +03:00
|
|
|
search_status->repaint();
|
|
|
|
search_button->setText(tr("Stop"));
|
2007-03-27 22:49:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Slot called when search is Finished
|
|
|
|
// Search can be finished for 3 reasons :
|
|
|
|
// Error | Stopped by user | Finished normally
|
2015-08-27 14:25:14 +03:00
|
|
|
void SearchWidget::searchFinished(bool cancelled)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
bool useNotificationBalloons = Preferences::instance()->useProgramNotification();
|
2015-07-28 23:55:40 +03:00
|
|
|
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this)
|
2014-10-31 00:14:44 +03:00
|
|
|
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
|
2015-07-29 00:34:29 +03:00
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
if (activeSearchTab.isNull()) return; // The active tab was closed
|
2015-07-29 00:34:29 +03:00
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
if (cancelled)
|
2015-04-11 15:00:03 +03:00
|
|
|
activeSearchTab->status = tr("Search aborted");
|
2015-08-27 14:25:14 +03:00
|
|
|
else if (no_search_results)
|
|
|
|
activeSearchTab->status = tr("Search returned no results");
|
|
|
|
else
|
|
|
|
activeSearchTab->status = tr("Search has finished");
|
|
|
|
|
2015-07-29 00:34:29 +03:00
|
|
|
search_status->setText(currentSearchTab->status);
|
2015-07-28 23:55:40 +03:00
|
|
|
activeSearchTab = 0;
|
2014-10-31 00:14:44 +03:00
|
|
|
search_button->setText(tr("Search"));
|
2007-03-27 22:49:29 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:25:14 +03:00
|
|
|
void SearchWidget::searchFailed()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-08-27 14:25:14 +03:00
|
|
|
bool useNotificationBalloons = Preferences::instance()->useProgramNotification();
|
|
|
|
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this)
|
|
|
|
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed"));
|
|
|
|
|
|
|
|
if (activeSearchTab.isNull()) return; // The active tab was closed
|
|
|
|
|
2015-07-29 12:29:41 +03:00
|
|
|
#ifdef Q_OS_WIN
|
2015-08-27 14:25:14 +03:00
|
|
|
activeSearchTab->status = tr("Search aborted");
|
2015-07-29 12:29:41 +03:00
|
|
|
#else
|
2015-08-27 14:25:14 +03:00
|
|
|
activeSearchTab->status = tr("An error occurred during search...");
|
2015-07-29 12:29:41 +03:00
|
|
|
#endif
|
2015-08-27 14:25:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SLOT to append one line to search results list
|
|
|
|
void SearchWidget::appendSearchResults(const QList<SearchResult> &results)
|
|
|
|
{
|
|
|
|
if (activeSearchTab.isNull()) {
|
|
|
|
m_searchEngine->cancelSearch();
|
2014-10-31 00:14:44 +03:00
|
|
|
return;
|
2009-12-28 23:52:21 +03:00
|
|
|
}
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2015-04-11 15:00:03 +03:00
|
|
|
Q_ASSERT(activeSearchTab);
|
2015-08-27 14:25:14 +03:00
|
|
|
|
2015-04-11 15:00:03 +03:00
|
|
|
QStandardItemModel* cur_model = activeSearchTab->getCurrentSearchListModel();
|
2014-10-31 00:14:44 +03:00
|
|
|
Q_ASSERT(cur_model);
|
2015-08-27 14:25:14 +03:00
|
|
|
|
|
|
|
foreach (const SearchResult &result, results) {
|
|
|
|
// Add item to search result list
|
|
|
|
int row = cur_model->rowCount();
|
|
|
|
cur_model->insertRow(row);
|
|
|
|
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::NAME), result.fileName); // Name
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::SIZE), result.fileSize); // Size
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), result.nbLeechers); // Leechers
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL
|
|
|
|
cur_model->setData(cur_model->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link
|
|
|
|
}
|
2014-10-31 00:14:44 +03:00
|
|
|
|
|
|
|
no_search_results = false;
|
2015-08-27 14:25:14 +03:00
|
|
|
nb_search_results += results.size();
|
|
|
|
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(nb_search_results));
|
|
|
|
|
2014-10-31 00:14:44 +03:00
|
|
|
// Enable clear & download buttons
|
|
|
|
download_button->setEnabled(true);
|
|
|
|
goToDescBtn->setEnabled(true);
|
2015-01-07 00:40:49 +03:00
|
|
|
copyURLBtn->setEnabled(true);
|
2007-03-27 22:49:29 +04:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::closeTab(int index)
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2015-04-11 15:00:03 +03:00
|
|
|
// Search is run for active tab so if user decided to close it, then stop search
|
2015-07-29 00:34:29 +03:00
|
|
|
if (!activeSearchTab.isNull() && index == tabWidget->indexOf(activeSearchTab)) {
|
2015-04-11 15:00:03 +03:00
|
|
|
qDebug("Closed active search Tab");
|
2015-08-27 14:25:14 +03:00
|
|
|
if (m_searchEngine->isActive())
|
|
|
|
m_searchEngine->cancelSearch();
|
2015-04-11 15:00:03 +03:00
|
|
|
activeSearchTab = 0;
|
2009-11-27 00:11:37 +03:00
|
|
|
}
|
2014-10-31 00:14:44 +03:00
|
|
|
delete all_tab.takeAt(index);
|
|
|
|
if (!all_tab.size()) {
|
|
|
|
download_button->setEnabled(false);
|
|
|
|
goToDescBtn->setEnabled(false);
|
2015-07-29 00:34:29 +03:00
|
|
|
search_status->setText(tr("Stopped"));
|
2015-01-07 00:40:49 +03:00
|
|
|
copyURLBtn->setEnabled(false);
|
2009-11-27 00:11:37 +03:00
|
|
|
}
|
|
|
|
}
|
2007-03-27 22:49:29 +04:00
|
|
|
|
|
|
|
// Download selected items in search results list
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::on_download_button_clicked()
|
2015-07-28 23:55:40 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
foreach (const QModelIndex &index, selectedIndexes) {
|
|
|
|
if (index.column() == SearchSortModel::NAME) {
|
|
|
|
// Get Item url
|
|
|
|
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
|
|
|
|
QString torrent_url = model->data(model->index(index.row(), URL_COLUMN)).toString();
|
2015-08-27 14:25:14 +03:00
|
|
|
downloadTorrent(torrent_url);
|
2015-06-28 15:38:17 +03:00
|
|
|
all_tab.at(tabWidget->currentIndex())->setRowColor(index.row(), "blue");
|
2014-10-31 00:14:44 +03:00
|
|
|
}
|
2007-03-27 22:49:29 +04:00
|
|
|
}
|
|
|
|
}
|
2010-12-26 12:51:37 +03:00
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::on_goToDescBtn_clicked()
|
2010-12-26 12:51:37 +03:00
|
|
|
{
|
2014-10-31 00:14:44 +03:00
|
|
|
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
foreach (const QModelIndex &index, selectedIndexes) {
|
|
|
|
if (index.column() == SearchSortModel::NAME) {
|
|
|
|
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
|
|
|
|
const QString desc_url = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
|
|
|
|
if (!desc_url.isEmpty())
|
|
|
|
QDesktopServices::openUrl(QUrl::fromEncoded(desc_url.toUtf8()));
|
|
|
|
}
|
2010-12-26 12:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 00:40:49 +03:00
|
|
|
|
2015-08-26 20:05:57 +03:00
|
|
|
void SearchWidget::on_copyURLBtn_clicked()
|
2015-01-07 00:40:49 +03:00
|
|
|
{
|
|
|
|
QStringList urls;
|
|
|
|
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
foreach (const QModelIndex &index, selectedIndexes) {
|
|
|
|
if (index.column() == SearchSortModel::NAME) {
|
|
|
|
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
|
|
|
|
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
|
|
|
|
if (!descUrl.isEmpty())
|
|
|
|
urls << descUrl.toUtf8();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!urls.empty()) {
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(urls.join("\n"));
|
|
|
|
}
|
|
|
|
}
|