diff --git a/gtk/Notify.cc b/gtk/Notify.cc index 737063e43..63eb35959 100644 --- a/gtk/Notify.cc +++ b/gtk/Notify.cc @@ -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 const& core, int torrent -1)); } -void gtr_notify_torrent_added(Glib::ustring const& name) +void gtr_notify_torrent_added(Glib::RefPtr 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 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(tr_torrentName(tor)), + actions, std::map(), -1)); } diff --git a/gtk/Notify.h b/gtk/Notify.h index 6e06f09ff..58999fda7 100644 --- a/gtk/Notify.h +++ b/gtk/Notify.h @@ -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 const& core, int torrent_id); void gtr_notify_torrent_completed(Glib::RefPtr const& core, int torrent_id); diff --git a/gtk/Session.cc b/gtk/Session.cc index 597190e3b..d6daa19d4 100644 --- a/gtk/Session.cc +++ b/gtk/Session.cc @@ -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 */ diff --git a/gtk/Session.h b/gtk/Session.h index 4fe3bbec1..f71db5e8f 100644 --- a/gtk/Session.h +++ b/gtk/Session.h @@ -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 **/