2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2005-2008 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 "conf.h"
|
|
|
|
#include "dialogs.h"
|
2007-07-16 18:45:51 +00:00
|
|
|
#include "hig.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
|
|
|
#include "tr-prefs.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-16 18:45:51 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct quitdata
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TrCore * core;
|
2007-07-16 18:45:51 +00:00
|
|
|
callbackfunc_t func;
|
2008-09-23 19:11:04 +00:00
|
|
|
void * cbdata;
|
|
|
|
GtkWidget * dontask;
|
2007-07-16 18:45:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
quitresp( GtkWidget * widget,
|
|
|
|
int response,
|
|
|
|
gpointer data )
|
2007-07-16 18:45:51 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
struct quitdata * stuff = data;
|
2008-02-13 03:00:21 +00:00
|
|
|
GtkToggleButton * tb = GTK_TOGGLE_BUTTON( stuff->dontask );
|
2007-07-16 18:45:51 +00:00
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
tr_core_set_pref_bool( stuff->core,
|
2008-09-23 19:11:04 +00:00
|
|
|
PREF_KEY_ASKQUIT,
|
|
|
|
!gtk_toggle_button_get_active( tb ) );
|
2007-07-16 18:45:51 +00:00
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
|
|
|
stuff->func( stuff->cbdata );
|
|
|
|
|
|
|
|
g_free( stuff );
|
|
|
|
gtk_widget_destroy( widget );
|
|
|
|
}
|
|
|
|
|
2008-01-27 20:12:10 +00:00
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
countActiveTorrents( GtkTreeModel * model,
|
2008-01-27 20:12:10 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer activeTorrentCount )
|
2008-01-27 20:12:10 +00:00
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
int activity = -1;
|
|
|
|
gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
|
|
|
|
if( activity != TR_STATUS_STOPPED )
|
2008-01-27 20:12:10 +00:00
|
|
|
*(int*)activeTorrentCount += 1;
|
|
|
|
return FALSE; /* keep iterating */
|
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
void
|
2008-09-23 19:11:04 +00:00
|
|
|
askquit( TrCore * core,
|
|
|
|
GtkWindow * parent,
|
|
|
|
callbackfunc_t func,
|
|
|
|
void * cbdata )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
|
|
|
struct quitdata * stuff;
|
2009-06-09 04:52:22 +00:00
|
|
|
GtkWidget * w;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * wind;
|
|
|
|
GtkWidget * dontask;
|
|
|
|
GtkTreeModel * model;
|
|
|
|
int activeTorrentCount;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2008-01-21 15:51:53 +00:00
|
|
|
/* if the user doesn't want to be asked, don't ask */
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
|
|
|
|
{
|
2008-01-21 15:51:53 +00:00
|
|
|
func( cbdata );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-27 20:12:10 +00:00
|
|
|
/* if there aren't any active torrents, don't ask */
|
|
|
|
model = tr_core_model( core );
|
|
|
|
activeTorrentCount = 0;
|
|
|
|
gtk_tree_model_foreach( model, countActiveTorrents, &activeTorrentCount );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !activeTorrentCount )
|
|
|
|
{
|
2007-04-05 22:28:02 +00:00
|
|
|
func( cbdata );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
stuff = g_new( struct quitdata, 1 );
|
|
|
|
stuff->func = func;
|
|
|
|
stuff->cbdata = cbdata;
|
2007-07-16 18:45:51 +00:00
|
|
|
stuff->core = core;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
wind = gtk_message_dialog_new_with_markup(
|
|
|
|
parent,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_WARNING,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
_(
|
|
|
|
"<big><b>Quit Transmission?</b></big>" ) );
|
2007-07-27 01:40:46 +00:00
|
|
|
|
2009-06-09 04:52:22 +00:00
|
|
|
gtk_dialog_add_button( GTK_DIALOG( wind ), GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL );
|
|
|
|
w = gtk_dialog_add_button( GTK_DIALOG( wind ), GTK_STOCK_QUIT,
|
|
|
|
GTK_RESPONSE_ACCEPT );
|
2007-07-27 01:40:46 +00:00
|
|
|
gtk_dialog_set_default_response( GTK_DIALOG( wind ),
|
|
|
|
GTK_RESPONSE_ACCEPT );
|
2008-02-28 14:48:23 +00:00
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( wind ),
|
2008-04-29 22:56:44 +00:00
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
2008-09-23 19:11:04 +00:00
|
|
|
dontask = gtk_check_button_new_with_mnemonic( _( "_Don't ask me again" ) );
|
2007-07-16 18:45:51 +00:00
|
|
|
stuff->dontask = dontask;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG(
|
|
|
|
wind )->vbox ), dontask, FALSE, FALSE,
|
|
|
|
GUI_PAD );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-07-16 18:45:51 +00:00
|
|
|
g_signal_connect( G_OBJECT( wind ), "response",
|
|
|
|
G_CALLBACK( quitresp ), stuff );
|
2009-06-09 04:52:22 +00:00
|
|
|
gtk_widget_grab_focus( w );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-07-16 18:45:51 +00:00
|
|
|
gtk_widget_show_all( wind );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
2008-02-19 03:57:03 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct DeleteData
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
gboolean delete_files;
|
|
|
|
GSList * torrents;
|
|
|
|
TrCore * core;
|
2008-02-19 03:57:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-03-07 17:47:42 +00:00
|
|
|
removeTorrents( struct DeleteData * data )
|
2008-02-19 03:57:03 +00:00
|
|
|
{
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * l;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
for( l = data->torrents; l != NULL; l = l->next )
|
2008-03-07 17:47:42 +00:00
|
|
|
tr_core_remove_torrent( data->core, l->data, data->delete_files );
|
2008-03-18 01:22:11 +00:00
|
|
|
g_slist_free( data->torrents );
|
2008-04-17 19:54:22 +00:00
|
|
|
data->torrents = NULL;
|
2008-03-07 17:47:42 +00:00
|
|
|
}
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2008-03-07 17:47:42 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
removeResponse( GtkDialog * dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer gdata )
|
2008-03-07 17:47:42 +00:00
|
|
|
{
|
|
|
|
struct DeleteData * data = gdata;
|
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
|
|
|
removeTorrents( data );
|
|
|
|
else
|
2008-03-18 01:22:11 +00:00
|
|
|
g_slist_foreach( data->torrents, (GFunc)g_object_unref, NULL );
|
2008-02-19 03:57:03 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
2008-04-17 19:54:22 +00:00
|
|
|
g_slist_free( data->torrents );
|
2008-02-19 03:57:03 +00:00
|
|
|
g_free( data );
|
|
|
|
}
|
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
struct count_data
|
|
|
|
{
|
|
|
|
int incomplete;
|
|
|
|
int connected;
|
|
|
|
};
|
|
|
|
|
2008-03-07 17:47:42 +00:00
|
|
|
static void
|
2008-11-16 07:11:34 +00:00
|
|
|
countBusyTorrents( gpointer gtor, gpointer gdata )
|
2008-03-07 17:47:42 +00:00
|
|
|
{
|
|
|
|
const tr_stat * stat = tr_torrent_stat( gtor );
|
2008-11-16 07:11:34 +00:00
|
|
|
struct count_data * data = gdata;
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
if( stat->leftUntilDone ) ++data->incomplete;
|
|
|
|
if( stat->peersConnected ) ++data->connected;
|
2008-03-07 17:47:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-02 15:54:58 +00:00
|
|
|
void
|
2008-03-07 17:47:42 +00:00
|
|
|
confirmRemove( GtkWindow * parent,
|
2008-09-23 19:11:04 +00:00
|
|
|
TrCore * core,
|
|
|
|
GSList * torrents,
|
2008-03-07 17:47:42 +00:00
|
|
|
gboolean delete_files )
|
2008-03-02 15:54:58 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * d;
|
|
|
|
const int count = g_slist_length( torrents );
|
2008-11-16 07:11:34 +00:00
|
|
|
struct count_data counts;
|
|
|
|
const char * primary_text;
|
|
|
|
GString * secondary_text;
|
|
|
|
struct DeleteData * dd;
|
2008-03-07 17:47:42 +00:00
|
|
|
|
|
|
|
if( !count )
|
|
|
|
return;
|
2008-02-19 03:57:03 +00:00
|
|
|
|
2008-03-07 17:47:42 +00:00
|
|
|
dd = g_new0( struct DeleteData, 1 );
|
2008-03-02 15:54:58 +00:00
|
|
|
dd->core = core;
|
|
|
|
dd->torrents = torrents;
|
2008-03-07 17:47:42 +00:00
|
|
|
dd->delete_files = delete_files;
|
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
counts.incomplete = 0;
|
|
|
|
counts.connected = 0;
|
|
|
|
g_slist_foreach( torrents, countBusyTorrents, &counts );
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
if( !counts.incomplete && !counts.connected && !delete_files ) /* don't prompt boring torrents */
|
2008-03-07 17:47:42 +00:00
|
|
|
{
|
|
|
|
removeTorrents( dd );
|
|
|
|
g_free( dd );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !delete_files )
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
|
|
|
primary_text = ngettext( "Remove torrent?",
|
|
|
|
"Remove torrents?",
|
2008-09-23 19:11:04 +00:00
|
|
|
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
|
|
|
{
|
2008-03-07 17:47:42 +00:00
|
|
|
primary_text = ngettext( "Delete this torrent's downloaded files?",
|
|
|
|
"Delete these torrents' downloaded files?",
|
|
|
|
count );
|
2008-11-16 07:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
secondary_text = g_string_new( NULL );
|
2008-03-07 17:47:42 +00:00
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
if( !counts.incomplete && !counts.connected )
|
|
|
|
{
|
|
|
|
/* boring -- no secondary text needed */
|
|
|
|
}
|
|
|
|
else if( count == counts.incomplete )
|
|
|
|
{
|
|
|
|
g_string_assign( secondary_text, ngettext( "This torrent has not finished downloading.",
|
|
|
|
"These torrents have not finished downloading.",
|
|
|
|
count ) );
|
|
|
|
}
|
|
|
|
else if( count == counts.connected )
|
|
|
|
{
|
|
|
|
g_string_assign( secondary_text, ngettext( "This torrent is connected to peers.",
|
|
|
|
"These torrents are connected to peers.",
|
|
|
|
count ) );
|
|
|
|
}
|
2008-03-07 17:47:42 +00:00
|
|
|
else
|
2008-11-16 07:11:34 +00:00
|
|
|
{
|
|
|
|
if( counts.connected )
|
|
|
|
g_string_append( secondary_text, ngettext( "One of these torrents is connected to peers.",
|
|
|
|
"Some of these torrents are connected to peers.",
|
|
|
|
counts.connected ) );
|
|
|
|
if( counts.connected && counts.incomplete )
|
|
|
|
g_string_append( secondary_text, "\n" );
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
if( counts.incomplete )
|
|
|
|
g_string_assign( secondary_text, ngettext( "One of these torrents has not finished downloading.",
|
|
|
|
"Some of these torrents have not finished downloading.",
|
|
|
|
counts.incomplete ) );
|
|
|
|
}
|
2008-03-02 15:54:58 +00:00
|
|
|
|
|
|
|
d = gtk_message_dialog_new_with_markup( parent,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2008-04-12 15:01:43 +00:00
|
|
|
GTK_MESSAGE_WARNING,
|
2008-03-02 15:54:58 +00:00
|
|
|
GTK_BUTTONS_NONE,
|
2008-09-23 19:11:04 +00:00
|
|
|
"<big><b>%s</b></big>",
|
|
|
|
primary_text );
|
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 );
|
2008-03-02 15:54:58 +00:00
|
|
|
g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
|
|
|
|
gtk_widget_show_all( d );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-11-16 07:11:34 +00:00
|
|
|
g_string_free( secondary_text, TRUE );
|
|
|
|
}
|