2022-06-28 14:07:12 +00:00
|
|
|
// This file Copyright © 2005-2022 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <memory>
|
2022-07-26 02:45:54 +00:00
|
|
|
#include <vector>
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
#include <glibmm.h>
|
|
|
|
#include <glibmm/i18n.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-16 18:45:51 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void gtr_confirm_remove(
|
|
|
|
Gtk::Window& parent,
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-06-17 15:43:04 +00:00
|
|
|
std::vector<tr_torrent_id_t> const& torrent_ids,
|
2021-10-18 20:22:31 +00:00
|
|
|
bool delete_files)
|
2008-02-19 03:57:03 +00:00
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
int connected = 0;
|
|
|
|
int incomplete = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
int const count = torrent_ids.size();
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (count == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2008-03-07 17:47:42 +00:00
|
|
|
return;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const id : torrent_ids)
|
2011-03-03 01:59:25 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent* tor = core->find_torrent(id);
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_stat const* stat = tr_torrentStat(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (stat->leftUntilDone != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
++incomplete;
|
|
|
|
}
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (stat->peersConnected != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
++connected;
|
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
}
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const primary_text = gtr_sprintf(
|
|
|
|
!delete_files ?
|
|
|
|
ngettext("Remove torrent?", "Remove %d torrents?", count) :
|
2021-08-15 09:41:48 +00:00
|
|
|
ngettext("Delete this torrent's downloaded files?", "Delete these %d torrents' downloaded files?", count),
|
2021-10-18 20:22:31 +00:00
|
|
|
count);
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring secondary_text;
|
2017-04-30 16:25:26 +00:00
|
|
|
if (incomplete == 0 && connected == 0)
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text = ngettext(
|
|
|
|
"Once removed, continuing the transfer will require the torrent file or magnet link.",
|
|
|
|
"Once removed, continuing the transfers will require the torrent files or magnet links.",
|
|
|
|
count);
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (count == incomplete)
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text = ngettext(
|
|
|
|
"This torrent has not finished downloading.",
|
|
|
|
"These torrents have not finished downloading.",
|
|
|
|
count);
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (count == connected)
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text = ngettext("This torrent is connected to peers.", "These torrents are connected to peers.", count);
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2008-03-07 17:47:42 +00:00
|
|
|
else
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
if (connected != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text += ngettext(
|
|
|
|
"One of these torrents is connected to peers.",
|
|
|
|
"Some of these torrents are connected to peers.",
|
|
|
|
connected);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (connected != 0 && incomplete != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text += "\n";
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (incomplete != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
secondary_text += ngettext(
|
|
|
|
"One of these torrents has not finished downloading.",
|
|
|
|
"Some of these torrents have not finished downloading.",
|
|
|
|
incomplete);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2008-03-02 15:54:58 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto d = std::make_shared<Gtk::MessageDialog>(
|
2021-08-15 09:41:48 +00:00
|
|
|
parent,
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_sprintf("<big><b>%s</b></big>", primary_text),
|
2022-02-10 20:31:11 +00:00
|
|
|
true /*use_markup*/,
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::MESSAGE_QUESTION,
|
|
|
|
Gtk::BUTTONS_NONE,
|
2022-02-10 20:31:11 +00:00
|
|
|
true /*modal*/);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!secondary_text.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
d->set_secondary_text(secondary_text, true);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
d->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
d->add_button(delete_files ? _("_Delete") : _("_Remove"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
d->set_default_response(Gtk::RESPONSE_CANCEL);
|
|
|
|
|
|
|
|
d->signal_response().connect(
|
|
|
|
[d, core, torrent_ids, delete_files](int response) mutable
|
|
|
|
{
|
|
|
|
if (response == Gtk::RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
for (auto const id : torrent_ids)
|
|
|
|
{
|
|
|
|
core->remove_torrent(id, delete_files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
d->show_all();
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|