|
|
@ -33,6 +33,7 @@ |
|
|
|
#include <QStandardItemModel> |
|
|
|
#include <QStandardItemModel> |
|
|
|
#include <QHeaderView> |
|
|
|
#include <QHeaderView> |
|
|
|
#include <QSettings> |
|
|
|
#include <QSettings> |
|
|
|
|
|
|
|
#include <QSortFilterProxyModel> |
|
|
|
|
|
|
|
|
|
|
|
#include "SearchTab.h" |
|
|
|
#include "SearchTab.h" |
|
|
|
#include "SearchListDelegate.h" |
|
|
|
#include "SearchListDelegate.h" |
|
|
@ -45,7 +46,7 @@ |
|
|
|
#define SEARCH_LEECHERS 3 |
|
|
|
#define SEARCH_LEECHERS 3 |
|
|
|
#define SEARCH_ENGINE 4 |
|
|
|
#define SEARCH_ENGINE 4 |
|
|
|
|
|
|
|
|
|
|
|
SearchTab::SearchTab(SearchEngine *parent) : QWidget() |
|
|
|
SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
box=new QVBoxLayout(); |
|
|
|
box=new QVBoxLayout(); |
|
|
|
results_lbl=new QLabel(); |
|
|
|
results_lbl=new QLabel(); |
|
|
@ -62,17 +63,22 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget() |
|
|
|
SearchListModel->setHeaderData(SEARCH_SEEDERS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); |
|
|
|
SearchListModel->setHeaderData(SEARCH_SEEDERS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); |
|
|
|
SearchListModel->setHeaderData(SEARCH_LEECHERS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); |
|
|
|
SearchListModel->setHeaderData(SEARCH_LEECHERS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); |
|
|
|
SearchListModel->setHeaderData(SEARCH_ENGINE, Qt::Horizontal, tr("Search engine")); |
|
|
|
SearchListModel->setHeaderData(SEARCH_ENGINE, Qt::Horizontal, tr("Search engine")); |
|
|
|
resultsBrowser->setModel(SearchListModel); |
|
|
|
|
|
|
|
resultsBrowser->hideColumn(URL_COLUMN); // Hide url column
|
|
|
|
resultsBrowser->hideColumn(URL_COLUMN); // Hide url column
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proxyModel = new QSortFilterProxyModel(); |
|
|
|
|
|
|
|
proxyModel->setDynamicSortFilter(true); |
|
|
|
|
|
|
|
proxyModel->setSourceModel(SearchListModel); |
|
|
|
|
|
|
|
resultsBrowser->setModel(proxyModel); |
|
|
|
|
|
|
|
|
|
|
|
SearchDelegate = new SearchListDelegate(); |
|
|
|
SearchDelegate = new SearchListDelegate(); |
|
|
|
resultsBrowser->setItemDelegate(SearchDelegate); |
|
|
|
resultsBrowser->setItemDelegate(SearchDelegate); |
|
|
|
// Make search list header clickable for sorting
|
|
|
|
|
|
|
|
resultsBrowser->header()->setClickable(true); |
|
|
|
resultsBrowser->setRootIsDecorated(false); |
|
|
|
resultsBrowser->header()->setSortIndicatorShown(true); |
|
|
|
resultsBrowser->setAllColumnsShowFocus(true); |
|
|
|
|
|
|
|
resultsBrowser->setSortingEnabled(true); |
|
|
|
|
|
|
|
|
|
|
|
// Connect signals to slots (search part)
|
|
|
|
// Connect signals to slots (search part)
|
|
|
|
connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), parent, SLOT(downloadSelectedItem(const QModelIndex&))); |
|
|
|
connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); |
|
|
|
connect(resultsBrowser->header(), SIGNAL(sectionPressed(int)), this, SLOT(sortSearchList(int))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load last columns width for search results list
|
|
|
|
// Load last columns width for search results list
|
|
|
|
if(!loadColWidthResultsList()){ |
|
|
|
if(!loadColWidthResultsList()){ |
|
|
@ -80,9 +86,19 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SearchTab::downloadSelectedItem(const QModelIndex& index) { |
|
|
|
|
|
|
|
QString engine_url = proxyModel->data(proxyModel->index(index.row(), ENGINE_URL_COLUMN)).toString(); |
|
|
|
|
|
|
|
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), URL_COLUMN)).toString(); |
|
|
|
|
|
|
|
setRowColor(index.row(), "red"); |
|
|
|
|
|
|
|
parent->downloadTorrent(engine_url, torrent_url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SearchTab::~SearchTab() { |
|
|
|
SearchTab::~SearchTab() { |
|
|
|
|
|
|
|
delete box; |
|
|
|
|
|
|
|
delete results_lbl; |
|
|
|
delete resultsBrowser; |
|
|
|
delete resultsBrowser; |
|
|
|
delete SearchListModel; |
|
|
|
delete SearchListModel; |
|
|
|
|
|
|
|
delete proxyModel; |
|
|
|
delete SearchDelegate; |
|
|
|
delete SearchDelegate; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -122,65 +138,9 @@ QStandardItemModel* SearchTab::getCurrentSearchListModel() |
|
|
|
|
|
|
|
|
|
|
|
// Set the color of a row in data model
|
|
|
|
// Set the color of a row in data model
|
|
|
|
void SearchTab::setRowColor(int row, QString color){ |
|
|
|
void SearchTab::setRowColor(int row, QString color){ |
|
|
|
for(int i=0; i<SearchListModel->columnCount(); ++i){ |
|
|
|
for(int i=0; i<proxyModel->columnCount(); ++i){ |
|
|
|
SearchListModel->setData(SearchListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); |
|
|
|
proxyModel->setData(proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SearchTab::sortSearchList(int index){ |
|
|
|
|
|
|
|
static Qt::SortOrder sortOrder = Qt::AscendingOrder; |
|
|
|
|
|
|
|
if(resultsBrowser->header()->sortIndicatorSection() == index){ |
|
|
|
|
|
|
|
sortOrder = (sortOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; ; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resultsBrowser->header()->setSortIndicator(index, sortOrder); |
|
|
|
|
|
|
|
switch(index){ |
|
|
|
|
|
|
|
case SEEDERS: |
|
|
|
|
|
|
|
case LEECHERS: |
|
|
|
|
|
|
|
case SIZE: |
|
|
|
|
|
|
|
sortSearchListInt(index, sortOrder); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
sortSearchListString(index, sortOrder); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SearchTab::sortSearchListInt(int index, Qt::SortOrder sortOrder){ |
|
|
|
|
|
|
|
QList<QPair<int, qlonglong> > lines; |
|
|
|
|
|
|
|
// Insertion sorting
|
|
|
|
|
|
|
|
for(int i=0; i<SearchListModel->rowCount(); ++i){ |
|
|
|
|
|
|
|
misc::insertSort(lines, QPair<int,qlonglong>(i, SearchListModel->data(SearchListModel->index(i, index)).toLongLong()), sortOrder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Insert items in new model, in correct order
|
|
|
|
|
|
|
|
int nbRows_old = lines.size(); |
|
|
|
|
|
|
|
for(int row=0; row<lines.size(); ++row){ |
|
|
|
|
|
|
|
SearchListModel->insertRow(SearchListModel->rowCount()); |
|
|
|
|
|
|
|
int sourceRow = lines[row].first; |
|
|
|
|
|
|
|
for(int col=0; col<6; ++col){ |
|
|
|
|
|
|
|
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col))); |
|
|
|
|
|
|
|
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Remove old rows
|
|
|
|
|
|
|
|
SearchListModel->removeRows(0, nbRows_old); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SearchTab::sortSearchListString(int index, Qt::SortOrder sortOrder){ |
|
|
|
|
|
|
|
QList<QPair<int, QString> > lines; |
|
|
|
|
|
|
|
// Insetion sorting
|
|
|
|
|
|
|
|
for(int i=0; i<SearchListModel->rowCount(); ++i){ |
|
|
|
|
|
|
|
misc::insertSortString(lines, QPair<int, QString>(i, SearchListModel->data(SearchListModel->index(i, index)).toString()), sortOrder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Insert items in new model, in correct order
|
|
|
|
|
|
|
|
int nbRows_old = lines.size(); |
|
|
|
|
|
|
|
for(int row=0; row<nbRows_old; ++row){ |
|
|
|
|
|
|
|
SearchListModel->insertRow(SearchListModel->rowCount()); |
|
|
|
|
|
|
|
int sourceRow = lines[row].first; |
|
|
|
|
|
|
|
for(int col=0; col<6; ++col){ |
|
|
|
|
|
|
|
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col))); |
|
|
|
|
|
|
|
SearchListModel->setData(SearchListModel->index(nbRows_old+row, col), SearchListModel->data(SearchListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Remove old rows
|
|
|
|
|
|
|
|
SearchListModel->removeRows(0, nbRows_old); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|