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-12-26 21:13:21 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <gtkmm/messagedialog.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2022-10-15 16:13:50 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
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
|
|
|
|
2022-10-15 16:13:50 +00:00
|
|
|
auto const primary_text = fmt::format(
|
2021-10-18 20:22:31 +00:00
|
|
|
!delete_files ?
|
2022-10-15 16:13:50 +00:00
|
|
|
ngettext("Remove torrent?", "Remove {count:L} torrents?", count) :
|
|
|
|
ngettext("Delete this torrent's downloaded files?", "Delete these {count:L} torrents' downloaded files?", count),
|
|
|
|
fmt::arg("count", 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,
|
2022-10-15 16:13:50 +00:00
|
|
|
fmt::format("<big><b>{}</b></big>", primary_text),
|
2022-02-10 20:31:11 +00:00
|
|
|
true /*use_markup*/,
|
2022-09-10 13:19:54 +00:00
|
|
|
TR_GTK_MESSAGE_TYPE(WARNING),
|
|
|
|
TR_GTK_BUTTONS_TYPE(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
|
|
|
}
|
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
d->add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(CANCEL));
|
|
|
|
d->add_button(delete_files ? _("_Delete") : _("_Remove"), TR_GTK_RESPONSE_TYPE(ACCEPT));
|
|
|
|
d->set_default_response(TR_GTK_RESPONSE_TYPE(CANCEL));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
d->signal_response().connect(
|
|
|
|
[d, core, torrent_ids, delete_files](int response) mutable
|
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
for (auto const id : torrent_ids)
|
|
|
|
{
|
|
|
|
core->remove_torrent(id, delete_files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d.reset();
|
|
|
|
});
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
d->show();
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|