Skip to content

Commit

Permalink
Store opened search tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
glassez committed Jan 14, 2025
1 parent 99adb16 commit 2d82b6d
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 27 deletions.
51 changes: 39 additions & 12 deletions src/gui/search/searchjobwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ namespace
}
}

SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *app, QWidget *parent)
SearchJobWidget::SearchJobWidget(const QString &id, IGUIApplication *app, QWidget *parent)
: GUIApplicationComponent(app, parent)
, m_ui {new Ui::SearchJobWidget}
, m_nameFilteringMode {u"Search/FilteringMode"_s}
, m_id {id}
, m_ui {new Ui::SearchJobWidget}
{
m_ui->setupUi(this);

Expand Down Expand Up @@ -153,8 +154,6 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *
fillFilterComboBoxes();
setStatusTip(statusText(m_status));

assignSearchHandler(searchHandler);

m_lineEditSearchResultsFilter = new LineEdit(this);
m_lineEditSearchResultsFilter->setPlaceholderText(tr("Filter search results..."));
m_lineEditSearchResultsFilter->setContextMenuPolicy(Qt::CustomContextMenu);
Expand Down Expand Up @@ -186,19 +185,44 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *
connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &SearchJobWidget::onUIThemeChanged);
}

SearchJobWidget::SearchJobWidget(const QString &id, const QString &searchPattern
, const QList<SearchResult> &searchResults, IGUIApplication *app, QWidget *parent)
: SearchJobWidget(id, app, parent)
{
m_status = Status::Finished;

m_searchPattern = searchPattern;
m_proxyModel->setNameFilter(m_searchPattern);
updateFilter();

appendSearchResults(searchResults);
}

SearchJobWidget::SearchJobWidget(const QString &id, SearchHandler *searchHandler, IGUIApplication *app, QWidget *parent)
: SearchJobWidget(id, app, parent)
{
assignSearchHandler(searchHandler);
}

SearchJobWidget::~SearchJobWidget()
{
saveSettings();
delete m_ui;
}

QString SearchJobWidget::id() const
{
return m_id;
}

QString SearchJobWidget::searchPattern() const
{
Q_ASSERT(m_searchHandler);
if (!m_searchHandler) [[unlikely]]
return {};
return m_searchPattern;
}

return m_searchHandler->pattern();
QList<SearchResult> SearchJobWidget::searchResults() const
{
return m_searchResults;
}

void SearchJobWidget::onItemDoubleClicked(const QModelIndex &index)
Expand Down Expand Up @@ -264,6 +288,7 @@ void SearchJobWidget::assignSearchHandler(SearchHandler *searchHandler)
if (!searchHandler) [[unlikely]]
return;

m_searchResults.clear();
m_searchListModel->removeRows(0, m_searchListModel->rowCount());
delete m_searchHandler;

Expand All @@ -273,16 +298,17 @@ void SearchJobWidget::assignSearchHandler(SearchHandler *searchHandler)
connect(m_searchHandler, &SearchHandler::searchFinished, this, &SearchJobWidget::searchFinished);
connect(m_searchHandler, &SearchHandler::searchFailed, this, &SearchJobWidget::searchFailed);

m_proxyModel->setNameFilter(m_searchHandler->pattern());
m_searchPattern = m_searchHandler->pattern();

m_proxyModel->setNameFilter(m_searchPattern);
updateFilter();

setStatus(Status::Ongoing);
}

void SearchJobWidget::cancelSearch()
{
Q_ASSERT(m_searchHandler);
if (!m_searchHandler) [[unlikely]]
if (!m_searchHandler)
return;

m_searchHandler->cancelSearch();
Expand Down Expand Up @@ -363,7 +389,7 @@ void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex, const AddTorr
}
else
{
SearchDownloadHandler *downloadHandler = m_searchHandler->manager()->downloadTorrent(engineName, torrentUrl);
SearchDownloadHandler *downloadHandler = SearchPluginManager::instance()->downloadTorrent(engineName, torrentUrl);
connect(downloadHandler, &SearchDownloadHandler::downloadFinished
, this, [this, option](const QString &source) { addTorrentToSession(source, option); });
connect(downloadHandler, &SearchDownloadHandler::downloadFinished, downloadHandler, &SearchDownloadHandler::deleteLater);
Expand Down Expand Up @@ -605,6 +631,7 @@ void SearchJobWidget::appendSearchResults(const QList<SearchResult> &results)
setModelData(SearchSortModel::PUB_DATE, QLocale().toString(result.pubDate.toLocalTime(), QLocale::ShortFormat), result.pubDate);
}

m_searchResults.append(results);
updateResultsCount();
}

Expand Down
14 changes: 11 additions & 3 deletions src/gui/search/searchjobwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ class SearchJobWidget final : public GUIApplicationComponent<QWidget>
NoResults
};

SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *app, QWidget *parent = nullptr);
SearchJobWidget(const QString &id, const QString &searchPattern, const QList<SearchResult> &searchResults, IGUIApplication *app, QWidget *parent = nullptr);
SearchJobWidget(const QString &id, SearchHandler *searchHandler, IGUIApplication *app, QWidget *parent = nullptr);
~SearchJobWidget() override;

QString id() const;
QString searchPattern() const;
QList<SearchResult> searchResults() const;
Status status() const;
int visibleResultsCount() const;
LineEdit *lineEditSearchResultsFilter() const;
Expand All @@ -98,6 +101,8 @@ private slots:
void displayColumnHeaderMenu();

private:
SearchJobWidget(const QString &id, IGUIApplication *app, QWidget *parent);

void loadSettings();
void saveSettings() const;
void updateFilter();
Expand Down Expand Up @@ -127,15 +132,18 @@ private slots:
void copyTorrentNames() const;
void copyField(int column) const;

SettingValue<NameFilteringMode> m_nameFilteringMode;

QString m_id;
QString m_searchPattern;
QList<SearchResult> m_searchResults;
Ui::SearchJobWidget *m_ui = nullptr;
SearchHandler *m_searchHandler = nullptr;
QStandardItemModel *m_searchListModel = nullptr;
SearchSortModel *m_proxyModel = nullptr;
LineEdit *m_lineEditSearchResultsFilter = nullptr;
Status m_status = Status::Ongoing;
bool m_noSearchResults = true;

SettingValue<NameFilteringMode> m_nameFilteringMode;
};

Q_DECLARE_METATYPE(SearchJobWidget::NameFilteringMode)
Loading

0 comments on commit 2d82b6d

Please sign in to comment.