Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add date column to the built-in search engine #20703

Merged
merged 2 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/base/search/searchhandler.cpp
Expand Up @@ -55,6 +55,7 @@ namespace
PL_LEECHS,
PL_ENGINE_URL,
PL_DESC_LINK,
PL_PUB_DATE,
NB_PLUGIN_COLUMNS
};
}
Expand Down Expand Up @@ -176,7 +177,7 @@ bool SearchHandler::parseSearchResult(const QStringView line, SearchResult &sear
const QList<QStringView> parts = line.split(u'|');
const int nbFields = parts.size();

if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional
if (nbFields <= PL_ENGINE_URL) return false; // Anything after ENGINE_URL is optional

searchResult = SearchResult();
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed().toString(); // download URL
Expand All @@ -194,9 +195,17 @@ bool SearchHandler::parseSearchResult(const QStringView line, SearchResult &sear
searchResult.nbLeechers = -1;

searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed().toString(); // Search site URL
if (nbFields == NB_PLUGIN_COLUMNS)

if (nbFields > PL_DESC_LINK)
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed().toString(); // Description Link

if (nbFields > PL_PUB_DATE)
{
const qint64 secs = parts.at(PL_PUB_DATE).trimmed().toLongLong(&ok);
if (ok && (secs > 0))
searchResult.pubDate = QDateTime::fromSecsSinceEpoch(secs); // Date
}

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/base/search/searchhandler.h
Expand Up @@ -30,6 +30,7 @@
#pragma once

#include <QByteArray>
#include <QDateTime>
#include <QList>
#include <QObject>
#include <QString>
Expand All @@ -47,6 +48,7 @@ struct SearchResult
qlonglong nbLeechers = 0;
QString siteUrl;
QString descrLink;
QDateTime pubDate;
};

class SearchPluginManager;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/search/searchjobwidget.cpp
Expand Up @@ -71,6 +71,7 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
m_searchListModel->setHeaderData(SearchSortModel::PUB_DATE, Qt::Horizontal, tr("Published On"));
// Set columns text alignment
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
Expand Down Expand Up @@ -533,6 +534,7 @@ void SearchJobWidget::appendSearchResults(const QVector<SearchResult> &results)
setModelData(SearchSortModel::SIZE, Utils::Misc::friendlyUnit(result.fileSize), result.fileSize, (Qt::AlignRight | Qt::AlignVCenter));
setModelData(SearchSortModel::SEEDS, QString::number(result.nbSeeders), result.nbSeeders, (Qt::AlignRight | Qt::AlignVCenter));
setModelData(SearchSortModel::LEECHES, QString::number(result.nbLeechers), result.nbLeechers, (Qt::AlignRight | Qt::AlignVCenter));
setModelData(SearchSortModel::PUB_DATE, QLocale().toString(result.pubDate.toLocalTime(), QLocale::ShortFormat), result.pubDate);
}

updateResultsCount();
Expand Down
1 change: 1 addition & 0 deletions src/gui/search/searchsortmodel.h
Expand Up @@ -45,6 +45,7 @@ class SearchSortModel final : public QSortFilterProxyModel
SEEDS,
LEECHES,
ENGINE_URL,
PUB_DATE,
DL_LINK,
DESC_LINK,
NB_SEARCH_COLUMNS
Expand Down
18 changes: 11 additions & 7 deletions src/searchengine/nova3/novaprinter.py
@@ -1,4 +1,4 @@
#VERSION: 1.47
#VERSION: 1.48

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -26,12 +26,16 @@


def prettyPrinter(dictionary):
dictionary['size'] = anySizeToBytes(dictionary['size'])
outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "),
str(dictionary["size"]), str(dictionary["seeds"]),
str(dictionary["leech"]), dictionary["engine_url"]))
if 'desc_link' in dictionary:
outtext = "|".join((outtext, dictionary["desc_link"]))
outtext = "|".join((
dictionary["link"],
ducalex marked this conversation as resolved.
Show resolved Hide resolved
dictionary["name"].replace("|", " "),
str(anySizeToBytes(dictionary['size'])),
str(dictionary["seeds"]),
str(dictionary["leech"]),
dictionary["engine_url"],
dictionary.get("desc_link", ""), # Optional
str(dictionary.get("pub_date", -1)), # Optional
))

# fd 1 is stdout
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
Expand Down
5 changes: 4 additions & 1 deletion src/webui/api/searchcontroller.cpp
Expand Up @@ -39,6 +39,7 @@
#include "base/global.h"
#include "base/logger.h"
#include "base/search/searchhandler.h"
#include "base/utils/datetime.h"
#include "base/utils/foreignapps.h"
#include "base/utils/random.h"
#include "base/utils/string.h"
Expand Down Expand Up @@ -301,6 +302,7 @@ int SearchController::generateSearchId() const
* - "nbLeechers"
* - "siteUrl"
* - "descrLink"
* - "pubDate"
*/
QJsonObject SearchController::getResults(const QList<SearchResult> &searchResults, const bool isSearchActive, const int totalResults) const
{
Expand All @@ -315,7 +317,8 @@ QJsonObject SearchController::getResults(const QList<SearchResult> &searchResult
{u"nbSeeders"_s, searchResult.nbSeeders},
{u"nbLeechers"_s, searchResult.nbLeechers},
{u"siteUrl"_s, searchResult.siteUrl},
{u"descrLink"_s, searchResult.descrLink}
{u"descrLink"_s, searchResult.descrLink},
{u"pubDate"_s, Utils::DateTime::toSecsSinceEpoch(searchResult.pubDate)}
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/webui/www/private/scripts/dynamicTable.js
Expand Up @@ -1684,6 +1684,7 @@ window.qBittorrent.DynamicTable = (function() {
this.newColumn('nbSeeders', '', 'QBT_TR(Seeders)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
this.newColumn('nbLeechers', '', 'QBT_TR(Leechers)QBT_TR[CONTEXT=SearchResultsTable]', 100, true);
this.newColumn('siteUrl', '', 'QBT_TR(Search engine)QBT_TR[CONTEXT=SearchResultsTable]', 250, true);
this.newColumn('pubDate', '', 'QBT_TR(Published On)QBT_TR[CONTEXT=SearchResultsTable]', 200, true);

this.initColumnsFunctions();
},
Expand All @@ -1700,10 +1701,17 @@ window.qBittorrent.DynamicTable = (function() {
td.set('text', formattedValue);
td.set('title', formattedValue);
};
const displayDate = function(td, row) {
const value = this.getRowValue(row) * 1000;
const formattedValue = (isNaN(value) || (value <= 0)) ? "" : (new Date(value).toLocaleString());
td.set('text', formattedValue);
td.set('title', formattedValue);
};

this.columns['fileSize'].updateTd = displaySize;
this.columns['nbSeeders'].updateTd = displayNum;
this.columns['nbLeechers'].updateTd = displayNum;
this.columns['pubDate'].updateTd = displayDate;
},

getFilteredAndSortedRows: function() {
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/views/search.html
Expand Up @@ -961,6 +961,7 @@
nbLeechers: result.nbLeechers,
nbSeeders: result.nbSeeders,
siteUrl: result.siteUrl,
pubDate: result.pubDate,
};

newRows.push(row);
Expand Down