2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
2011-01-19 13:48:47 +00:00
|
|
|
* Copyright (c) Transmission authors and contributors
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#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,
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<int> const& torrent_ids,
|
|
|
|
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),
|
|
|
|
true,
|
|
|
|
Gtk::MESSAGE_QUESTION,
|
|
|
|
Gtk::BUTTONS_NONE,
|
|
|
|
false);
|
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
|
|
|
}
|