Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip/rss2 #130

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions include/gtorrent/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ namespace gt
friend class FeedGroup;

TorrentGroup m_torrents;
std::deque<std::shared_ptr<gt::Torrent>> m_pendingTorrents; //Contains torrent that have been added to the session but that haven't been reported to the UI
//Contains torrent that have been added to the session but that haven't been reported to the UI
std::vector<std::shared_ptr<gt::Torrent>> m_pending_torrents;
// TODO add a TorrentGroup vector once group functionality has been tested with m_torrents

public:
std::vector<std::shared_ptr<gt::FeedGroup>> m_feeds;
std::vector<std::shared_ptr<gt::Feed>> m_feedhandles;
std::vector<std::shared_ptr<gt::Feed>> m_feeds;
// std::vector<std::shared_ptr<gt::Feed>> m_feedhandles;
libtorrent::session m_session;
bool m_running;

Expand All @@ -59,9 +60,10 @@ namespace gt
TorrentGroup *getAllTorrents();

std::vector<TorrentGroup> getAllGroups(); // TODO implement

std::shared_ptr<gt::Torrent> addTorrent(std::string path, std::vector<char> *resumedata = nullptr);

std::shared_ptr<gt::Feed> addFeed(std::string Url);
std::shared_ptr<gt::Feed> addFeed(std::string url);

std::shared_ptr<gt::FeedGroup> addFeedGroup(std::string Name);

Expand All @@ -80,5 +82,9 @@ namespace gt
void shutdown();

std::shared_ptr<gt::Torrent> update();

std::vector<std::shared_ptr<gt::Torrent>> getPendingTorrents();

Feed *getFeedWithHandle(libtorrent::feed_handle handle);
};
}
18 changes: 15 additions & 3 deletions include/gtorrent/Feed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include <memory>
#include <vector>
#include <set>

#include <libtorrent/rss.hpp>
#include <libtorrent/alert_types.hpp>

#include <Torrent.hpp>
#include <Core.hpp>
#include "FeedGroup.hpp"

#include <FeedGroup.hpp>

namespace gt
{
Expand All @@ -18,8 +20,18 @@ namespace gt
public:
std::set<std::shared_ptr<gt::FeedGroup>> owners;

// Question: Does this really need a reference to itself? See how it's being used so far and determine if the args can be simplified.
// Should move this to a pure virtual class/interface
std::function<void(int, gt::Feed*)> onStateChanged;

typedef std::function<void(libtorrent::rss_item_alert*)> itemCallback;
typedef std::function<void(int)> stateCallback;

std::function<void(libtorrent::rss_item_alert*)> onItemAlert;
std::function<void(libtorrent::feed_item&, std::shared_ptr<gt::Feed>)> onNewItemAvailable;

// When a feed changes state, all of its groups are informed
Feed(const libtorrent::feed_handle &fe);
Feed(libtorrent::feed_handle fe);

bool operator==(const libtorrent::feed_handle& rhs) { return rhs.get_feed_status().url == get_feed_status().url; }
};
Expand Down
14 changes: 9 additions & 5 deletions include/gtorrent/FeedGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

namespace gt
{
// Is used to manage a feed group and serialization/deserialization
/**
* Is used to manage a feed group and serialization/deserialization
* Deprecated; Use the vector of Feeds instead
*/
class FeedGroup
{
public:
Expand All @@ -22,6 +25,7 @@ namespace gt
int updating;
std::set<std::string> functions;
std::map<std::string, std::string> filters;

void addFunction(std::string);
void addItem(const libtorrent::feed_item &fi);
operator std::string();
Expand All @@ -39,11 +43,11 @@ namespace gt
typedef std::function<void(const libtorrent::feed_item&, std::shared_ptr<gt::Feed>)> itemCallback;
typedef std::function<void(int, std::shared_ptr<gt::Feed>)> stateCallback;

stateCallback onStateChanged ;
feedCallback onUpdateFinished ;
feedCallback onUpdateErrored ;
stateCallback onStateChanged;
feedCallback onUpdateFinished;
feedCallback onUpdateErrored;
itemCallback onNewItemAvailable;
feedCallback onUpdateStarted ;
feedCallback onUpdateStarted;

};
}
6 changes: 4 additions & 2 deletions include/gtorrent/Torrent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ namespace gt
public:
Torrent(libtorrent::torrent_handle h) : libtorrent::torrent_handle(h) { };
Torrent(std::string path);
std::function<void(int, std::shared_ptr<Torrent>)> onStateChanged; // why does this remind me of kirby <('_')>
// Question: Does this really need a reference to itself? See how it's being used so far and determine if the args can be simplified.
// Should move this to a pure virtual class/interface
std::function<void(int, Torrent*)> onStateChanged; // why does this remind me of kirby <('_')>

bool pollEvent(gt::Event &event);
void defaultCallback(int, std::shared_ptr<Torrent>);
static void defaultCallback(int, Torrent*);
/* Think twice next time before mixing const correctness with inline */
// Getters
libtorrent::add_torrent_params getTorrentParams();
Expand Down
Loading