mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Use naturalSort in search.
This commit is contained in:
parent
09abc9d8b7
commit
f6e4ff1ab9
@ -539,26 +539,26 @@ void SearchEngine::appendSearchResult(const QString &line) {
|
||||
int row = cur_model->rowCount();
|
||||
cur_model->insertRow(row);
|
||||
|
||||
cur_model->setData(cur_model->index(row, DL_LINK), parts.at(PL_DL_LINK).trimmed()); // download URL
|
||||
cur_model->setData(cur_model->index(row, NAME), parts.at(PL_NAME).trimmed()); // Name
|
||||
cur_model->setData(cur_model->index(row, SIZE), parts.at(PL_SIZE).trimmed().toLongLong()); // Size
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::DL_LINK), parts.at(PL_DL_LINK).trimmed()); // download URL
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::NAME), parts.at(PL_NAME).trimmed()); // Name
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::SIZE), parts.at(PL_SIZE).trimmed().toLongLong()); // Size
|
||||
bool ok = false;
|
||||
qlonglong nb_seeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok);
|
||||
if (!ok || nb_seeders < 0) {
|
||||
cur_model->setData(cur_model->index(row, SEEDS), tr("Unknown")); // Seeders
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), tr("Unknown")); // Seeders
|
||||
} else {
|
||||
cur_model->setData(cur_model->index(row, SEEDS), nb_seeders); // Seeders
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), nb_seeders); // Seeders
|
||||
}
|
||||
qlonglong nb_leechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok);
|
||||
if (!ok || nb_leechers < 0) {
|
||||
cur_model->setData(cur_model->index(row, LEECHS), tr("Unknown")); // Leechers
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), tr("Unknown")); // Leechers
|
||||
} else {
|
||||
cur_model->setData(cur_model->index(row, LEECHS), nb_leechers); // Leechers
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), nb_leechers); // Leechers
|
||||
}
|
||||
cur_model->setData(cur_model->index(row, ENGINE_URL), parts.at(PL_ENGINE_URL).trimmed()); // Engine URL
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::ENGINE_URL), parts.at(PL_ENGINE_URL).trimmed()); // Engine URL
|
||||
// Description Link
|
||||
if (nb_fields == NB_PLUGIN_COLUMNS)
|
||||
cur_model->setData(cur_model->index(row, DESC_LINK), parts.at(PL_DESC_LINK).trimmed());
|
||||
cur_model->setData(cur_model->index(row, SearchSortModel::DESC_LINK), parts.at(PL_DESC_LINK).trimmed());
|
||||
|
||||
no_search_results = false;
|
||||
++nb_search_results;
|
||||
@ -591,7 +591,7 @@ void SearchEngine::on_download_button_clicked() {
|
||||
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
if (index.column() == NAME) {
|
||||
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();
|
||||
@ -606,9 +606,9 @@ void SearchEngine::on_goToDescBtn_clicked()
|
||||
{
|
||||
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
if (index.column() == NAME) {
|
||||
if (index.column() == SearchSortModel::NAME) {
|
||||
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
|
||||
const QString desc_url = model->data(model->index(index.row(), DESC_LINK)).toString();
|
||||
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()));
|
||||
}
|
||||
|
@ -54,8 +54,6 @@ class SearchEngine : public QWidget, public Ui::search_engine{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SearchEngine)
|
||||
|
||||
public:
|
||||
enum SearchColumn { NAME, SIZE, SEEDS, LEECHS, ENGINE_URL, DL_LINK, DESC_LINK, NB_SEARCH_COLUMNS };
|
||||
private:
|
||||
enum PluginColumn { PL_DL_LINK, PL_NAME, PL_SIZE, PL_SEEDS, PL_LEECHS, PL_ENGINE_URL, PL_DESC_LINK, NB_PLUGIN_COLUMNS };
|
||||
|
||||
|
@ -9,7 +9,8 @@ HEADERS += $$PWD/searchengine.h \
|
||||
$$PWD/engineselectdlg.h \
|
||||
$$PWD/pluginsource.h \
|
||||
$$PWD/searchlistdelegate.h \
|
||||
$$PWD/supportedengines.h
|
||||
$$PWD/supportedengines.h \
|
||||
$$PWD/searchsortmodel.h
|
||||
|
||||
SOURCES += $$PWD/searchengine.cpp \
|
||||
$$PWD/searchtab.cpp \
|
||||
|
@ -52,7 +52,7 @@ class SearchListDelegate: public QItemDelegate {
|
||||
painter->save();
|
||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||
switch(index.column()) {
|
||||
case SearchEngine::SIZE:
|
||||
case SearchSortModel::SIZE:
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
|
||||
break;
|
||||
|
35
src/searchengine/searchsortmodel.h
Normal file
35
src/searchengine/searchsortmodel.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef SEARCHSORTMODEL_H
|
||||
#define SEARCHSORTMODEL_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "misc.h"
|
||||
|
||||
class SearchSortModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum SearchColumn { NAME, SIZE, SEEDS, LEECHS, ENGINE_URL, DL_LINK, DESC_LINK, NB_SEARCH_COLUMNS };
|
||||
|
||||
SearchSortModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
protected:
|
||||
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||
if (sortColumn() == NAME || sortColumn() == ENGINE_URL) {
|
||||
QVariant vL = sourceModel()->data(left);
|
||||
QVariant vR = sourceModel()->data(right);
|
||||
if (!(vL.isValid() && vR.isValid()))
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
Q_ASSERT(vL.isValid());
|
||||
Q_ASSERT(vR.isValid());
|
||||
|
||||
bool res = false;
|
||||
if (misc::naturalSort(vL.toString(), vR.toString(), res))
|
||||
return res;
|
||||
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SEARCHSORTMODEL_H
|
@ -51,14 +51,14 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent)
|
||||
|
||||
setLayout(box);
|
||||
// Set Search results list model
|
||||
SearchListModel = new QStandardItemModel(0, SearchEngine::NB_SEARCH_COLUMNS);
|
||||
SearchListModel->setHeaderData(SearchEngine::NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
||||
SearchListModel->setHeaderData(SearchEngine::SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
||||
SearchListModel->setHeaderData(SearchEngine::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
||||
SearchListModel->setHeaderData(SearchEngine::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
||||
SearchListModel->setHeaderData(SearchEngine::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
|
||||
SearchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS);
|
||||
SearchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
||||
SearchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
||||
SearchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
|
||||
SearchListModel->setHeaderData(SearchSortModel::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
|
||||
SearchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
|
||||
|
||||
proxyModel = new QSortFilterProxyModel();
|
||||
proxyModel = new SearchSortModel();
|
||||
proxyModel->setDynamicSortFilter(true);
|
||||
proxyModel->setSourceModel(SearchListModel);
|
||||
resultsBrowser->setModel(proxyModel);
|
||||
@ -66,8 +66,8 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent)
|
||||
SearchDelegate = new SearchListDelegate();
|
||||
resultsBrowser->setItemDelegate(SearchDelegate);
|
||||
|
||||
resultsBrowser->hideColumn(SearchEngine::DL_LINK); // Hide url column
|
||||
resultsBrowser->hideColumn(SearchEngine::DESC_LINK);
|
||||
resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
|
||||
resultsBrowser->hideColumn(SearchSortModel::DESC_LINK);
|
||||
|
||||
resultsBrowser->setRootIsDecorated(false);
|
||||
resultsBrowser->setAllColumnsShowFocus(true);
|
||||
@ -82,12 +82,12 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent)
|
||||
}
|
||||
|
||||
// Sort by Seeds
|
||||
resultsBrowser->sortByColumn(SearchEngine::SEEDS, Qt::DescendingOrder);
|
||||
resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder);
|
||||
}
|
||||
|
||||
void SearchTab::downloadSelectedItem(const QModelIndex& index) {
|
||||
QString engine_url = proxyModel->data(proxyModel->index(index.row(), SearchEngine::ENGINE_URL)).toString();
|
||||
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), SearchEngine::DL_LINK)).toString();
|
||||
QString engine_url = proxyModel->data(proxyModel->index(index.row(), SearchSortModel::ENGINE_URL)).toString();
|
||||
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString();
|
||||
setRowColor(index.row(), "red");
|
||||
parent->downloadTorrent(engine_url, torrent_url);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
#define SEARCH_TAB_H
|
||||
|
||||
#include "ui_search.h"
|
||||
#include "searchsortmodel.h"
|
||||
|
||||
#define ENGINE_URL_COLUMN 4
|
||||
#define URL_COLUMN 5
|
||||
@ -43,7 +44,6 @@ QT_BEGIN_NAMESPACE
|
||||
class QTreeView;
|
||||
class QHeaderView;
|
||||
class QStandardItemModel;
|
||||
class QSortFilterProxyModel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class SearchTab: public QWidget, public Ui::search_engine {
|
||||
@ -54,7 +54,7 @@ private:
|
||||
QLabel *results_lbl;
|
||||
QTreeView *resultsBrowser;
|
||||
QStandardItemModel *SearchListModel;
|
||||
QSortFilterProxyModel *proxyModel;
|
||||
SearchSortModel *proxyModel;
|
||||
SearchListDelegate *SearchDelegate;
|
||||
SearchEngine *parent;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user