2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
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
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "dialogs.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-16 18:45:51 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
struct delete_data
|
2007-07-16 18:45:51 +00:00
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
gboolean delete_files;
|
|
|
|
GSList * torrent_ids;
|
|
|
|
TrCore * core;
|
2007-07-16 18:45:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-03-03 01:59:25 +00:00
|
|
|
on_remove_dialog_response( GtkDialog * dialog, gint response, gpointer gdd )
|
2008-02-19 03:57:03 +00:00
|
|
|
{
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * l;
|
2011-03-03 01:59:25 +00:00
|
|
|
struct delete_data * dd = gdd;
|
2008-03-07 17:47:42 +00:00
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
2011-03-03 01:59:25 +00:00
|
|
|
for( l=dd->torrent_ids; l!=NULL; l=l->next )
|
|
|
|
gtr_core_remove_torrent( dd->core, GPOINTER_TO_INT( l->data ), dd->delete_files );
|
2008-02-19 03:57:03 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
2011-03-03 01:59:25 +00:00
|
|
|
g_slist_free( dd->torrent_ids );
|
|
|
|
g_free( dd );
|
2008-03-07 17:47:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-02 15:54:58 +00:00
|
|
|
void
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_confirm_remove( GtkWindow * parent,
|
|
|
|
TrCore * core,
|
2011-03-03 01:59:25 +00:00
|
|
|
GSList * torrent_ids,
|
2010-12-21 19:20:58 +00:00
|
|
|
gboolean delete_files )
|
2008-03-02 15:54:58 +00:00
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
GSList * l;
|
|
|
|
GtkWidget * d;
|
|
|
|
GString * primary_text;
|
|
|
|
GString * secondary_text;
|
|
|
|
struct delete_data * dd;
|
|
|
|
int connected = 0;
|
|
|
|
int incomplete = 0;
|
|
|
|
const int count = g_slist_length( torrent_ids );
|
2008-03-07 17:47:42 +00:00
|
|
|
|
|
|
|
if( !count )
|
|
|
|
return;
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
dd = g_new0( struct delete_data, 1 );
|
2008-03-02 15:54:58 +00:00
|
|
|
dd->core = core;
|
2011-03-03 01:59:25 +00:00
|
|
|
dd->torrent_ids = torrent_ids;
|
2008-03-07 17:47:42 +00:00
|
|
|
dd->delete_files = delete_files;
|
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
for( l=torrent_ids; l!=NULL; l=l->next )
|
|
|
|
{
|
|
|
|
const int id = GPOINTER_TO_INT( l->data );
|
|
|
|
tr_torrent * tor = gtr_core_find_torrent( core, id );
|
|
|
|
const tr_stat * stat = tr_torrentStat( tor );
|
|
|
|
if( stat->leftUntilDone ) ++incomplete;
|
|
|
|
if( stat->peersConnected ) ++connected;
|
|
|
|
}
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2010-05-18 23:49:41 +00:00
|
|
|
primary_text = g_string_new( NULL );
|
2008-03-07 17:47:42 +00:00
|
|
|
|
|
|
|
if( !delete_files )
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_printf( primary_text, gtr_ngettext( "Remove torrent?",
|
|
|
|
"Remove %d torrents?",
|
|
|
|
count ), 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
|
|
|
{
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_printf( primary_text, gtr_ngettext( "Delete this torrent's downloaded files?",
|
|
|
|
"Delete these %d torrents' downloaded files?",
|
|
|
|
count ), count );
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
secondary_text = g_string_new( NULL );
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
if( !incomplete && !connected )
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_assign( secondary_text, gtr_ngettext(
|
2010-05-18 23:49:41 +00:00
|
|
|
"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
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
else if( count == incomplete )
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_assign( secondary_text, gtr_ngettext( "This torrent has not finished downloading.",
|
|
|
|
"These torrents have not finished downloading.",
|
|
|
|
count ) );
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2011-03-03 01:59:25 +00:00
|
|
|
else if( count == connected )
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_assign( secondary_text, gtr_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
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
if( connected )
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_append( secondary_text, gtr_ngettext( "One of these torrents is connected to peers.",
|
|
|
|
"Some of these torrents are connected to peers.",
|
2011-03-03 01:59:25 +00:00
|
|
|
connected ) );
|
|
|
|
if( connected && incomplete )
|
2008-11-16 07:11:34 +00:00
|
|
|
g_string_append( secondary_text, "\n" );
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
if( incomplete )
|
2010-08-06 14:38:54 +00:00
|
|
|
g_string_assign( secondary_text, gtr_ngettext( "One of these torrents has not finished downloading.",
|
|
|
|
"Some of these torrents have not finished downloading.",
|
2011-03-03 01:59:25 +00:00
|
|
|
incomplete ) );
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
2008-03-02 15:54:58 +00:00
|
|
|
|
|
|
|
d = gtk_message_dialog_new_with_markup( parent,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2010-05-18 23:49:41 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
2008-03-02 15:54:58 +00:00
|
|
|
GTK_BUTTONS_NONE,
|
2008-09-23 19:11:04 +00:00
|
|
|
"<big><b>%s</b></big>",
|
2010-05-18 23:49:41 +00:00
|
|
|
primary_text->str );
|
2008-11-16 07:11:34 +00:00
|
|
|
if( secondary_text->len )
|
2008-10-09 20:03:34 +00:00
|
|
|
gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG( d ),
|
2008-11-16 07:11:34 +00:00
|
|
|
"%s", secondary_text->str );
|
2008-03-02 15:54:58 +00:00
|
|
|
gtk_dialog_add_buttons( GTK_DIALOG( d ),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2008-09-23 19:11:04 +00:00
|
|
|
( delete_files ? GTK_STOCK_DELETE :
|
|
|
|
GTK_STOCK_REMOVE ), GTK_RESPONSE_ACCEPT,
|
2008-03-02 15:54:58 +00:00
|
|
|
NULL );
|
|
|
|
gtk_dialog_set_default_response( GTK_DIALOG ( d ),
|
|
|
|
GTK_RESPONSE_CANCEL );
|
2008-02-28 14:48:23 +00:00
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
2011-03-03 01:59:25 +00:00
|
|
|
g_signal_connect( d, "response", G_CALLBACK( on_remove_dialog_response ), dd );
|
2008-03-02 15:54:58 +00:00
|
|
|
gtk_widget_show_all( d );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2010-05-18 23:49:41 +00:00
|
|
|
g_string_free( primary_text, TRUE );
|
2008-11-16 07:11:34 +00:00
|
|
|
g_string_free( secondary_text, TRUE );
|
|
|
|
}
|