mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
Add a "Start Now" action for newly added torrent notifications in the GTK client (#849)
* Add a "Start Now" action for newly added torrent notifications in the GTK client * Const placement * Compilation fixes * post-merge fix * Morph torrent_start_now into Session::start_now
This commit is contained in:
committed by
GitHub
parent
4ecf74081c
commit
5df3505832
+19
-4
@@ -110,6 +110,10 @@ void g_signal_callback(
|
||||
auto const path = Glib::build_filename(dir, inf->files[0].name);
|
||||
gtr_open_file(path);
|
||||
}
|
||||
else if (action == "start-now")
|
||||
{
|
||||
n.core->start_now(n.torrent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +224,7 @@ void gtr_notify_torrent_completed(Glib::RefPtr<Session> const& core, int torrent
|
||||
-1));
|
||||
}
|
||||
|
||||
void gtr_notify_torrent_added(Glib::ustring const& name)
|
||||
void gtr_notify_torrent_added(Glib::RefPtr<Session> const& core, int torrent_id)
|
||||
{
|
||||
g_return_if_fail(proxy != nullptr);
|
||||
|
||||
@@ -229,16 +233,27 @@ void gtr_notify_torrent_added(Glib::ustring const& name)
|
||||
return;
|
||||
}
|
||||
|
||||
auto const* const tor = core->find_torrent(torrent_id);
|
||||
|
||||
std::vector<Glib::ustring> actions;
|
||||
if (server_supports_actions)
|
||||
{
|
||||
actions.push_back("start-now");
|
||||
actions.push_back(_("Start Now"));
|
||||
}
|
||||
|
||||
auto const n = TrNotification{ core, torrent_id };
|
||||
|
||||
proxy->call(
|
||||
"Notify",
|
||||
[](auto& res) { notify_callback(res, {}); },
|
||||
[n](auto& res) { notify_callback(res, n); },
|
||||
make_variant_tuple(
|
||||
Glib::ustring("Transmission"),
|
||||
0u,
|
||||
Glib::ustring("transmission"),
|
||||
Glib::ustring(_("Torrent Added")),
|
||||
name,
|
||||
std::vector<Glib::ustring>(),
|
||||
Glib::ustring(tr_torrentName(tor)),
|
||||
actions,
|
||||
std::map<Glib::ustring, Glib::VariantBase>(),
|
||||
-1));
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,6 +14,6 @@ class Session;
|
||||
|
||||
void gtr_notify_init();
|
||||
|
||||
void gtr_notify_torrent_added(Glib::ustring const& name);
|
||||
void gtr_notify_torrent_added(Glib::RefPtr<Session> const& core, int torrent_id);
|
||||
|
||||
void gtr_notify_torrent_completed(Glib::RefPtr<Session> const& core, int torrent_id);
|
||||
|
||||
+14
-1
@@ -1005,7 +1005,7 @@ void Session::Impl::add_torrent(tr_torrent* tor, bool do_notify)
|
||||
|
||||
if (do_notify)
|
||||
{
|
||||
gtr_notify_torrent_added(tr_torrentName(tor));
|
||||
gtr_notify_torrent_added(get_core_ptr(), tr_torrentId(tor));
|
||||
}
|
||||
|
||||
tr_torrentSetMetadataCallback(
|
||||
@@ -1441,6 +1441,19 @@ void Session::update()
|
||||
impl_->update();
|
||||
}
|
||||
|
||||
void Session::start_now(int id)
|
||||
{
|
||||
tr_variant top;
|
||||
tr_variantInitDict(&top, 2);
|
||||
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-start-now");
|
||||
|
||||
auto args = tr_variantDictAddDict(&top, TR_KEY_arguments, 1);
|
||||
auto ids = tr_variantDictAddList(args, TR_KEY_ids, 1);
|
||||
tr_variantListAddInt(ids, id);
|
||||
exec(&top);
|
||||
tr_variantFree(&top);
|
||||
}
|
||||
|
||||
void Session::Impl::update()
|
||||
{
|
||||
/* update the model */
|
||||
|
||||
@@ -111,6 +111,11 @@ public:
|
||||
/* update the model with current torrent status */
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Attempts to start a torrent immediately.
|
||||
*/
|
||||
void start_now(int id);
|
||||
|
||||
/**
|
||||
*** Set a preference value, save the prefs file, and emit the "prefs-changed" signal
|
||||
**/
|
||||
|
||||
Reference in New Issue
Block a user