Skip to content

Commit

Permalink
Better events
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyukaidesu committed Aug 19, 2014
1 parent 867c251 commit b932d59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions include/gtorrent/Torrent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <fstream>
#include <string>
#include <cstdint>

#include <functional>
#include <libtorrent/session.hpp>
#include <libtorrent/torrent_handle.hpp>

Expand All @@ -31,10 +31,10 @@ namespace gt
std::string m_path;

public:
Torrent(string path);
std::function<void(int, shared_ptr<Torrent>)> onStateChanged;
Torrent(std::string path);
std::function<void(int, std::shared_ptr<Torrent>)> onStateChanged; // why does this remind me of kirby <('_')>
bool pollEvent(gt::Event &event);
void defaultCallback(int, shared_ptr<Torrent>);
void defaultCallback(int, std::shared_ptr<Torrent>);
/* Think twice next time before mixing const correctness with inline */
// Getters
libtorrent::add_torrent_params getTorrentParams();
Expand Down
1 change: 1 addition & 0 deletions src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ std::shared_ptr<gt::Torrent> gt::Core::update()
{
std::string str = gt::Platform::readSharedData();
if(!str.empty()) gt::Log::Debug(str.c_str());

m_session.set_alert_mask(0x00000040);
std::deque<libtorrent::alert*> alerts;
m_session.pop_alerts(&alerts);
Expand Down
6 changes: 3 additions & 3 deletions src/Torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ gt::Torrent::Torrent(std::string path) : m_path(path)
}

// onStateChanged = [](int i, shared_ptr<Torrent> j) { std::cout << "State Changed ! Old state was " << i << ", new state is " << j->getHandle().status().state << std::endl; }; // default handler
onStateChanged = std::bind(&gt::Torrent::defaultCallback, this, placeholders::_1, placeholders::_2);
onStateChanged = std::bind(&gt::Torrent::defaultCallback, this, std::placeholders::_1, std::placeholders::_2);
/*
* To use, for example in GtkMainWindow, let's say tor is a shared_ptr, you would write
* tor->onStateChanged = [](int oldstate, shared_ptr<gt::Torrent> sender) {...}
Expand All @@ -109,7 +109,7 @@ gt::Torrent::Torrent(std::string path) : m_path(path)
*/
}

void gt::Torrent::defaultCallback(int i, shared_ptr<Torrent> j)
void gt::Torrent::defaultCallback(int i, std::shared_ptr<gt::Torrent> j)
{
std::cout << "State Changed ! Old state was " << i << ", new state is " << j->getHandle().status().state << std::endl;
}
Expand All @@ -119,7 +119,7 @@ void gt::Torrent::setSavePath(std::string savepath)
if (savepath.empty())
{
if(gt::Settings::optionExists(SAVEPATH_OPTION_KEY))
savepath = gt::Settings::getOptionAsString(SAVEPATH_OPTION_KEY);
savepath = gt::Settings::settings[SAVEPATH_OPTION_KEY];
else if(!gt::Platform::getDefaultSavePath().empty())
savepath = gt::Platform::getDefaultSavePath();
else
Expand Down

0 comments on commit b932d59

Please sign in to comment.