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 23, 2025
1 parent f8c4834 commit f485417
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 31 deletions.
26 changes: 26 additions & 0 deletions src/base/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,32 @@ void Preferences::setSearchEnabled(const bool enabled)
setValue(u"Preferences/Search/SearchEnabled"_s, enabled);
}

bool Preferences::storeOpenedSearchTabs() const
{
return value(u"Search/StoreOpenedSearchTabs"_s, false);
}

void Preferences::setStoreOpenedSearchTabs(const bool enabled)
{
if (enabled == storeOpenedSearchTabs())
return;

setValue(u"Search/StoreOpenedSearchTabs"_s, enabled);
}

bool Preferences::storeOpenedSearchTabResults() const
{
return value(u"Search/StoreOpenedSearchTabResults"_s, false);
}

void Preferences::setStoreOpenedSearchTabResults(const bool enabled)
{
if (enabled == storeOpenedSearchTabResults())
return;

setValue(u"Search/StoreOpenedSearchTabResults"_s, enabled);
}

bool Preferences::isWebUIEnabled() const
{
#ifdef DISABLE_GUI
Expand Down
6 changes: 6 additions & 0 deletions src/base/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class Preferences final : public QObject
bool isSearchEnabled() const;
void setSearchEnabled(bool enabled);

// Search UI
bool storeOpenedSearchTabs() const;
void setStoreOpenedSearchTabs(bool enabled);
bool storeOpenedSearchTabResults() const;
void setStoreOpenedSearchTabResults(bool enabled);

// HTTP Server
bool isWebUIEnabled() const;
void setWebUIEnabled(bool enabled);
Expand Down
22 changes: 22 additions & 0 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ OptionsDialog::OptionsDialog(IGUIApplication *app, QWidget *parent)
m_ui->tabSelection->item(TAB_DOWNLOADS)->setIcon(UIThemeManager::instance()->getIcon(u"download"_s, u"folder-download"_s));
m_ui->tabSelection->item(TAB_SPEED)->setIcon(UIThemeManager::instance()->getIcon(u"speedometer"_s, u"chronometer"_s));
m_ui->tabSelection->item(TAB_RSS)->setIcon(UIThemeManager::instance()->getIcon(u"application-rss"_s, u"application-rss+xml"_s));
m_ui->tabSelection->item(TAB_SEARCH)->setIcon(UIThemeManager::instance()->getIcon(u"edit-find"_s));
#ifdef DISABLE_WEBUI
m_ui->tabSelection->item(TAB_WEBUI)->setHidden(true);
#else
Expand All @@ -190,6 +191,7 @@ OptionsDialog::OptionsDialog(IGUIApplication *app, QWidget *parent)
loadSpeedTabOptions();
loadBittorrentTabOptions();
loadRSSTabOptions();
loadSearchTabOptions();
#ifndef DISABLE_WEBUI
loadWebUITabOptions();
#endif
Expand Down Expand Up @@ -1273,6 +1275,25 @@ void OptionsDialog::saveRSSTabOptions() const
autoDownloader->setDownloadRepacks(m_ui->checkSmartFilterDownloadRepacks->isChecked());
}

void OptionsDialog::loadSearchTabOptions()
{
const auto *pref = Preferences::instance();

m_ui->groupStoreOpenedTabs->setChecked(pref->storeOpenedSearchTabs());
m_ui->checkStoreTabsSearchResults->setChecked(pref->storeOpenedSearchTabResults());

connect(m_ui->groupStoreOpenedTabs, &QGroupBox::toggled, this, &OptionsDialog::enableApplyButton);
connect(m_ui->checkStoreTabsSearchResults, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
}

void OptionsDialog::saveSearchTabOptions() const
{
auto *pref = Preferences::instance();

pref->setStoreOpenedSearchTabs(m_ui->groupStoreOpenedTabs->isChecked());
pref->setStoreOpenedSearchTabResults(m_ui->checkStoreTabsSearchResults->isChecked());
}

#ifndef DISABLE_WEBUI
void OptionsDialog::loadWebUITabOptions()
{
Expand Down Expand Up @@ -1465,6 +1486,7 @@ void OptionsDialog::saveOptions() const
saveSpeedTabOptions();
saveBittorrentTabOptions();
saveRSSTabOptions();
saveSearchTabOptions();
#ifndef DISABLE_WEBUI
saveWebUITabOptions();
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/gui/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class OptionsDialog final : public GUIApplicationComponent<QDialog>
TAB_SPEED,
TAB_BITTORRENT,
TAB_RSS,
TAB_SEARCH,
TAB_WEBUI,
TAB_ADVANCED
};
Expand Down Expand Up @@ -136,6 +137,9 @@ private slots:
void loadRSSTabOptions();
void saveRSSTabOptions() const;

void loadSearchTabOptions();
void saveSearchTabOptions() const;

#ifndef DISABLE_WEBUI
void loadWebUITabOptions();
void saveWebUITabOptions() const;
Expand Down
84 changes: 84 additions & 0 deletions src/gui/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
<string>RSS</string>
</property>
</item>
<item>
<property name="text">
<string>Search</string>
</property>
</item>
<item>
<property name="text">
<string>WebUI</string>
Expand Down Expand Up @@ -3404,6 +3409,85 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSearchPage">
<layout class="QVBoxLayout" name="searchPageLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="searchPageScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="searchPageScrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>521</width>
<height>541</height>
</rect>
</property>
<layout class="QVBoxLayout" name="searchPageScrollAreaWidgetContentsLayout">
<item>
<widget class="QGroupBox" name="groupSearchUI">
<property name="title">
<string>Search UI</string>
</property>
<layout class="QVBoxLayout" name="groupSearchUILayout">
<item>
<widget class="QGroupBox" name="groupStoreOpenedTabs">
<property name="title">
<string>Store opened tabs</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="groupStoreOpenedTabsLayout">
<item>
<widget class="QCheckBox" name="checkStoreTabsSearchResults">
<property name="text">
<string>Also store search results</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="searchPageScrollAreaSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>422</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWebUIPage">
<layout class="QVBoxLayout" name="tabWebUIPageLayout">
<property name="leftMargin">
Expand Down
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 f485417

Please sign in to comment.