transmission/qt/TorrentModel.h

80 lines
1.9 KiB
C
Raw Normal View History

2009-04-09 18:55:47 +00:00
/*
* This file Copyright (C) 2010-2015 Mnemosyne LLC
2009-04-09 18:55:47 +00:00
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
2009-04-09 18:55:47 +00:00
*
*/
#pragma once
2009-04-09 18:55:47 +00:00
#include <optional>
#include <vector>
2009-04-09 18:55:47 +00:00
#include <QAbstractListModel>
#include <QVector>
#include "Macros.h"
#include "Torrent.h"
#include "Typedefs.h"
2009-04-09 18:55:47 +00:00
class Prefs;
2015-06-12 22:12:12 +00:00
class Speed;
2009-04-09 18:55:47 +00:00
extern "C"
{
struct tr_variant;
}
2009-04-09 18:55:47 +00:00
class TorrentModel : public QAbstractListModel
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
Q_OBJECT
TR_DISABLE_COPY_MOVE(TorrentModel)
2013-09-14 22:45:04 +00:00
public:
2015-06-12 22:12:12 +00:00
enum Role
{
TorrentRole = Qt::UserRole
2015-06-12 22:12:12 +00:00
};
2013-09-14 22:45:04 +00:00
explicit TorrentModel(Prefs const& prefs);
~TorrentModel() override;
void clear();
bool hasTorrent(TorrentHash const& hash) const;
2013-09-14 22:45:04 +00:00
Torrent* getTorrentFromId(int id);
Torrent const* getTorrentFromId(int id) const;
2013-09-14 22:45:04 +00:00
using torrents_t = QVector<Torrent*>;
torrents_t const& torrents() const { return torrents_; }
2013-09-14 22:45:04 +00:00
2015-06-12 22:12:12 +00:00
// QAbstractItemModel
int rowCount(QModelIndex const& parent = QModelIndex()) const override;
QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override;
2013-09-14 22:45:04 +00:00
public slots:
void updateTorrents(tr_variant* torrent_list, bool is_complete_list);
void removeTorrents(tr_variant* torrent_list);
2013-09-14 22:45:04 +00:00
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);
2015-06-12 22:12:12 +00:00
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;
2013-09-14 22:45:04 +00:00
Prefs const& prefs_;
torrent_ids_t already_added_;
torrents_t torrents_;
2009-04-09 18:55:47 +00:00
};