transmission/gtk/Dialogs.cc

137 lines
3.6 KiB
C++
Raw Normal View History

// This file Copyright © 2005-2023 Transmission authors and contributors.
// 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
#include "Dialogs.h"
#include "GtkCompat.h"
#include "Session.h"
#include "Utils.h"
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <gtkmm/messagedialog.h>
2006-07-16 19:39:23 +00:00
#include <fmt/core.h>
#include <memory>
#include <vector>
2006-07-16 19:39:23 +00:00
/***
****
***/
void gtr_confirm_remove(
Gtk::Window& parent,
Glib::RefPtr<Session> const& core,
std::vector<tr_torrent_id_t> const& torrent_ids,
bool delete_files)
{
int connected = 0;
int incomplete = 0;
int const count = torrent_ids.size();
if (count == 0)
{
return;
}
for (auto const id : torrent_ids)
{
tr_torrent* tor = core->find_torrent(id);
tr_stat const* stat = tr_torrentStat(tor);
if (stat->leftUntilDone != 0)
{
++incomplete;
}
if (stat->peersConnected != 0)
{
++connected;
}
}
auto const primary_text = fmt::format(
!delete_files ?
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));
Glib::ustring secondary_text;
if (incomplete == 0 && connected == 0)
{
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);
}
else if (count == incomplete)
{
secondary_text = ngettext(
"This torrent has not finished downloading.",
"These torrents have not finished downloading.",
count);
}
else if (count == connected)
{
secondary_text = ngettext("This torrent is connected to peers.", "These torrents are connected to peers.", count);
}
else
{
if (connected != 0)
{
secondary_text += ngettext(
"One of these torrents is connected to peers.",
"Some of these torrents are connected to peers.",
connected);
}
if (connected != 0 && incomplete != 0)
{
secondary_text += "\n";
}
2009-08-10 20:04:08 +00:00
if (incomplete != 0)
{
secondary_text += ngettext(
"One of these torrents has not finished downloading.",
"Some of these torrents have not finished downloading.",
incomplete);
}
}
auto d = std::make_shared<Gtk::MessageDialog>(
parent,
fmt::format("<big><b>{}</b></big>", primary_text),
true /*use_markup*/,
TR_GTK_MESSAGE_TYPE(WARNING),
TR_GTK_BUTTONS_TYPE(NONE),
true /*modal*/);
if (!secondary_text.empty())
{
d->set_secondary_text(secondary_text, true);
}
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));
d->signal_response().connect(
[d, core, torrent_ids, delete_files](int response) mutable
{
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
{
for (auto const id : torrent_ids)
{
core->remove_torrent(id, delete_files);
}
}
d.reset();
});
Add support for GTK 4 (#3916) * Make compact mode switch work for both GTK 3 and 4 * Implement GTK 4-specific view gesture handling * Fix torrents view context menu on GTK 4 * Explicitly show/hide menubar on startup/teardown * Switch from `Gtk::Pixbuf` to `Gio::Icon` for views * Support GTK 4 exceptions based on `std::exception` * Fix options menu setup with GTK 4 * Use `delete-event` (GTK 3) and `close-request` (GTK 4) signals to handle window clousure * Add custom file chooser button implementation GTK 4 drops FileChooserButton widget and suggests implementing it using Button. * Add helpers to set X11 hints with GTK 4 * Remove `HigWorkarea` class that's no longer used * Make main menu shortcuts work with GTK 4 * Make drops work in main window and make dialog with GTK 4 * Remove unused `gtr_action_get_widget()` helper * Fix text direction mark setup with GTK 4 (due to switch to enum class) * Fix file tree font size calculation with GTK 4 * Fix crash during shutdown with GTK 4 * Switch from `RadioButton` to `CheckButton` for compatibility with GTK 4 * Fix opening files with GTK 4 * Rework torrent cell renderer to support both GTK 3 and 4 * Disable system tray icon support with GTK 4 * Fix windows positioning with GTK 4 * Fix focus event handling with GTK 4 * Adapt to tree model row/iterator changes in GTK 4 * Adapt to toplevel/root window changes in GTK 4 * Adapt to clipboard changes in GTK 4 * Adapt to icon/theme changes in GTK 4 * Adapt to file/path changes in GTK 4 * Random leftover fixes for GTK 4 compatibility * Clean up unused code * Move GTK 3 *.ui files into a subdirectory * Add GTK 4 *.ui files * Search for both GTK 3 and 4 during configuration
2022-10-08 22:50:03 +00:00
d->show();
}