-
Notifications
You must be signed in to change notification settings - Fork 0
/
torrenttransfertableview.h
135 lines (112 loc) · 4.08 KB
/
torrenttransfertableview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
#ifndef TORRENTTRANSFERTABLEVIEW_H
#define TORRENTTRANSFERTABLEVIEW_H
#include <QAction>
#include <QPointer>
#include <QTableView>
#include "settings/settingvalue.h"
class QSortFilterProxyModel;
class QSqlRecord;
class QSqlTableModel;
class CsfdDetailService;
class StatusHash;
class TorrentTableDelegate;
class TorrentTransferTableView final : public QTableView
{
Q_OBJECT
Q_DISABLE_COPY(TorrentTransferTableView)
public:
explicit TorrentTransferTableView(HWND qBittorrentHwnd, QWidget *parent = nullptr);
int getModelRowCount() const;
inline bool isqBittorrentUp() const noexcept;
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
public slots:
void filterTextChanged(const QString &name) const;
void reloadTorrentModel() const;
void updateChangedTorrents(const QVector<QString> &torrentInfoHashes);
void resizeColumns() const;
inline void updateqBittorrentHwnd(HWND hwnd) noexcept;
/*! Show/hide seeds/leechs column by isqBittorrentUp() */
void togglePeerColumns();
protected:
void showEvent(QShowEvent *event) final;
void contextMenuEvent(QContextMenuEvent *event) final;
private:
// TODO duplicate enum, maps 1:1 to TorrentSqlTableModel::Column enum, may be enum using will be good too silverqx
enum TorrentColumn
{
TR_ID,
TR_NAME,
TR_PROGRESS,
TR_ETA,
TR_SIZE,
TR_SEEDS,
TR_TOTAL_SEEDS,
TR_LEECHERS,
TR_TOTAL_LEECHERS,
TR_AMOUNT_LEFT,
TR_ADDED_ON,
TR_HASH,
TR_CSFD_MOVIE_DETAIL,
TR_STATUS,
TR_MOVIE_DETAIL_INDEX,
TR_SAVE_PATH,
NB_COLUMNS
};
QSharedPointer<const QVector<QSqlRecord>> selectTorrentFilesById(quint64 id) const;
void displayListMenu(const QContextMenuEvent *event);
QModelIndex getSelectedTorrentIndex() const;
QSqlRecord getSelectedTorrentRecord() const;
void removeRecordFromTorrentFilesCache(quint64 torrentId) const;
/*! Context menu action factory. */
template<typename Func>
QAction *createActionForMenu(
const QIcon &icon, const QString &text, QKeySequence &&shortcut,
Func &&slot, QWidget *parent = nullptr, bool enabled = true) const;
void resumeTorrent(const QSqlRecord &torrent) const;
void pauseTorrent(const QSqlRecord &torrent) const;
QPointer<QSqlTableModel> m_model;
QPointer<QSortFilterProxyModel> m_proxyModel;
QPointer<TorrentTableDelegate> m_tableDelegate;
/*! Contains torrent files by torrent id. */
mutable QHash<quint64, QSharedPointer<const QVector<QSqlRecord>>> m_torrentFilesCache;
bool m_showEventInitialized = false;
HWND m_qBittorrentHwnd = nullptr;
std::shared_ptr<StatusHash> m_statusHash;
std::shared_ptr<CsfdDetailService> m_csfdDetailService;
Settings::CachedSettingValue<bool> m_regexTorrentsFilter;
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
private slots:
void previewSelectedTorrent();
void previewFile(const QString &filePath) const;
void deleteSelectedTorrent();
void showCsfdDetail();
void showImdbDetail();
void pauseSelectedTorrent();
void resumeSelectedTorrent();
void forceResumeSelectedTorrent();
void forceRecheckSelectedTorrent();
void openFolderForSelectedTorrent();
void pauseResumeSelectedTorrent() const;
};
bool TorrentTransferTableView::isqBittorrentUp() const noexcept
{
return m_qBittorrentHwnd != nullptr;
}
void TorrentTransferTableView::updateqBittorrentHwnd(HWND hwnd) noexcept
{
m_qBittorrentHwnd = hwnd;
}
template<typename Func>
QAction *TorrentTransferTableView::createActionForMenu(
const QIcon &icon, const QString &text, QKeySequence &&shortcut,
Func &&slot, QWidget *parent, const bool enabled) const
{
auto *const newAction = new QAction(icon, text, parent);
// TODO would be ideal to show this shortcut's text little grey silverqx
newAction->setShortcut(shortcut);
newAction->setEnabled(enabled);
connect(newAction, &QAction::triggered, this, std::forward<Func>(slot));
return newAction;
}
#endif // TORRENTTRANSFERTABLEVIEW_H