mirror of
https://github.com/transmission/transmission
synced 2025-01-19 05:19:54 +00:00
c2fb393390
* refactor: mark subclass' destructors as override. * refactor: use QUrl to parse announce URL strings. The prompt for this was to work around a clang-tidy issue where "char* host = nullptr;" triggers a "don't use varargs" warning, but on the other hand it's also terser / cleaner. * refactor: make the TorrentDelegate brushes const. * refactor: s/auto/auto const*/ where appropriate * chore: add some nonconst global warning exemptions * chore: turn off warnings in GTest * refactor: just disable the clang-tidy warning. Apparently a std::array<T>::iterator is a T* on clang, since clang-tidy's readability warning says we should use 'auto*' instead of 'auto'. However adding that annotation fails on MSVC, where the is apparently _not_ a raw pointer. Since there's not a way to satisfy both of them at the same time, disable the warning.
79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
/*
|
|
* This file Copyright (C) 2010-2015 Mnemosyne LLC
|
|
*
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
#include <QAbstractListModel>
|
|
#include <QVector>
|
|
|
|
#include "Macros.h"
|
|
#include "Torrent.h"
|
|
#include "Typedefs.h"
|
|
|
|
class Prefs;
|
|
class Speed;
|
|
|
|
extern "C"
|
|
{
|
|
struct tr_variant;
|
|
}
|
|
|
|
class TorrentModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
TR_DISABLE_COPY_MOVE(TorrentModel)
|
|
|
|
public:
|
|
enum Role
|
|
{
|
|
TorrentRole = Qt::UserRole
|
|
};
|
|
|
|
explicit TorrentModel(Prefs const& prefs);
|
|
~TorrentModel() override;
|
|
void clear();
|
|
|
|
bool hasTorrent(TorrentHash const& hash) const;
|
|
|
|
Torrent* getTorrentFromId(int id);
|
|
Torrent const* getTorrentFromId(int id) const;
|
|
|
|
using torrents_t = QVector<Torrent*>;
|
|
torrents_t const& torrents() const { return torrents_; }
|
|
|
|
// QAbstractItemModel
|
|
int rowCount(QModelIndex const& parent = QModelIndex()) const override;
|
|
QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override;
|
|
|
|
public slots:
|
|
void updateTorrents(tr_variant* torrent_list, bool is_complete_list);
|
|
void removeTorrents(tr_variant* torrent_list);
|
|
|
|
signals:
|
|
void torrentsAdded(torrent_ids_t const&);
|
|
void torrentsChanged(torrent_ids_t const&, Torrent::fields_t const& fields);
|
|
void torrentsCompleted(torrent_ids_t const&);
|
|
void torrentsEdited(torrent_ids_t const&);
|
|
void torrentsNeedInfo(torrent_ids_t const&);
|
|
|
|
private:
|
|
void rowsAdd(torrents_t const& torrents);
|
|
void rowsRemove(torrents_t const& torrents);
|
|
void rowsEmitChanged(torrent_ids_t const& ids);
|
|
|
|
std::optional<int> getRow(int id) const;
|
|
using span_t = std::pair<int, int>;
|
|
std::vector<span_t> getSpans(torrent_ids_t const& ids) const;
|
|
|
|
Prefs const& prefs_;
|
|
torrent_ids_t already_added_;
|
|
torrents_t torrents_;
|
|
};
|