qBittorrent
searchjobwidget.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2018 Vladimir Golovnev <[email protected]>
4  * Copyright (C) 2006 Christophe Dumez <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, the copyright holders give permission to
21  * link this program with the OpenSSL project's "OpenSSL" library (or with
22  * modified versions of it that use the same license as the "OpenSSL" library),
23  * and distribute the linked executables. You must obey the GNU General Public
24  * License in all respects for all of the code used other than "OpenSSL". If you
25  * modify file(s), you may extend this exception to your version of the file(s),
26  * but you are not obligated to do so. If you do not wish to do so, delete this
27  * exception statement from your version.
28  */
29 
30 #pragma once
31 
32 #include <QWidget>
33 
34 #define ENGINE_URL_COLUMN 4
35 #define URL_COLUMN 5
36 
37 class QHeaderView;
38 class QModelIndex;
39 class QStandardItemModel;
40 
41 class LineEdit;
42 class SearchHandler;
43 class SearchSortModel;
44 struct SearchResult;
45 
46 template <typename T> class SettingValue;
47 
48 namespace Ui
49 {
50  class SearchJobWidget;
51 }
52 
53 class SearchJobWidget final : public QWidget
54 {
55  Q_OBJECT
56  Q_DISABLE_COPY_MOVE(SearchJobWidget)
57 
58 public:
59  enum class NameFilteringMode
60  {
61  Everywhere,
62  OnlyNames
63  };
64  Q_ENUM(NameFilteringMode)
65 
66  enum class Status
67  {
68  Ongoing,
69  Finished,
70  Error,
71  Aborted,
72  NoResults
73  };
74 
75  explicit SearchJobWidget(SearchHandler *searchHandler, QWidget *parent = nullptr);
76  ~SearchJobWidget() override;
77 
78  Status status() const;
79  int visibleResultsCount() const;
81 
82  void cancelSearch();
83 
84 signals:
86  void statusChanged();
87 
88 protected:
89  void keyPressEvent(QKeyEvent *event) override;
90 
91 private:
92  enum class AddTorrentOption
93  {
94  Default,
95  ShowDialog,
96  SkipDialog,
97  };
98 
99  void loadSettings();
100  void saveSettings() const;
101  void updateFilter();
102  void filterSearchResults(const QString &name);
103  void showFilterContextMenu(const QPoint &);
104  void contextMenuEvent(QContextMenuEvent *event) override;
105  void displayToggleColumnsMenu(const QPoint &);
106  void onItemDoubleClicked(const QModelIndex &index);
107  void searchFinished(bool cancelled);
108  void searchFailed();
109  void appendSearchResults(const QVector<SearchResult> &results);
110  void updateResultsCount();
111  void setStatus(Status value);
112  void downloadTorrent(const QModelIndex &rowIndex, AddTorrentOption option = AddTorrentOption::Default);
114  void fillFilterComboBoxes();
116  QHeaderView *header() const;
117  void setRowColor(int row, const QColor &color);
118 
120  void openTorrentPages() const;
121  void copyTorrentURLs() const;
122  void copyTorrentDownloadLinks() const;
123  void copyTorrentNames() const;
124  void copyField(int column) const;
125 
126  static QString statusText(Status st);
128 
129  Ui::SearchJobWidget *m_ui;
131  QStandardItemModel *m_searchListModel;
135  bool m_noSearchResults = true;
136 };
137 
138 Q_DECLARE_METATYPE(SearchJobWidget::NameFilteringMode)
SearchSortModel * m_proxyModel
NameFilteringMode filteringMode() const
void openTorrentPages() const
LineEdit * m_lineEditSearchResultsFilter
void setRowColor(int row, const QColor &color)
static QString statusText(Status st)
void copyTorrentURLs() const
int visibleResultsCount() const
QHeaderView * header() const
void displayToggleColumnsMenu(const QPoint &)
~SearchJobWidget() override
Status status() const
void statusChanged()
void copyTorrentNames() const
void appendSearchResults(const QVector< SearchResult > &results)
void downloadTorrent(const QModelIndex &rowIndex, AddTorrentOption option=AddTorrentOption::Default)
void downloadTorrents(AddTorrentOption option=AddTorrentOption::Default)
void keyPressEvent(QKeyEvent *event) override
void showFilterContextMenu(const QPoint &)
void saveSettings() const
void setStatus(Status value)
void filterSearchResults(const QString &name)
void searchFinished(bool cancelled)
SearchHandler * m_searchHandler
void addTorrentToSession(const QString &source, AddTorrentOption option=AddTorrentOption::Default)
static SettingValue< NameFilteringMode > & nameFilteringModeSetting()
QStandardItemModel * m_searchListModel
Ui::SearchJobWidget * m_ui
void resultsCountUpdated()
void onItemDoubleClicked(const QModelIndex &index)
LineEdit * lineEditSearchResultsFilter() const
void contextMenuEvent(QContextMenuEvent *event) override
void copyTorrentDownloadLinks() const
SearchJobWidget(SearchHandler *searchHandler, QWidget *parent=nullptr)
void copyField(int column) const
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64