2007-02-07 07:35:33 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-01-19 13:48:47 +00:00
|
|
|
* Copyright (c) Transmission authors and contributors
|
2007-02-07 07:35:33 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2010-12-21 19:20:58 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_formatter_speed_KBps() */
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "actions.h"
|
2007-12-19 19:16:36 +00:00
|
|
|
#include "conf.h"
|
2010-03-14 05:13:02 +00:00
|
|
|
#include "filter.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "hig.h"
|
2007-12-19 02:46:30 +00:00
|
|
|
#include "torrent-cell-renderer.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-prefs.h"
|
|
|
|
#include "tr-window.h"
|
2007-02-07 07:35:33 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
typedef struct
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2009-04-15 15:10:22 +00:00
|
|
|
GtkWidget * speedlimit_on_item[2];
|
|
|
|
GtkWidget * speedlimit_off_item[2];
|
2009-04-15 04:28:04 +00:00
|
|
|
GtkWidget * ratio_on_item;
|
|
|
|
GtkWidget * ratio_off_item;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * scroll;
|
|
|
|
GtkWidget * view;
|
|
|
|
GtkWidget * toolbar;
|
|
|
|
GtkWidget * filter;
|
|
|
|
GtkWidget * status;
|
|
|
|
GtkWidget * status_menu;
|
|
|
|
GtkWidget * ul_lb;
|
|
|
|
GtkWidget * dl_lb;
|
|
|
|
GtkWidget * stats_lb;
|
|
|
|
GtkWidget * gutter_lb;
|
2009-12-14 19:24:05 +00:00
|
|
|
GtkWidget * alt_speed_image;
|
2009-03-28 16:47:01 +00:00
|
|
|
GtkWidget * alt_speed_button;
|
2009-04-15 04:28:04 +00:00
|
|
|
GtkWidget * options_menu;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeSelection * selection;
|
|
|
|
GtkCellRenderer * renderer;
|
|
|
|
GtkTreeViewColumn * column;
|
|
|
|
GtkTreeModel * filter_model;
|
|
|
|
TrCore * core;
|
|
|
|
gulong pref_handler_id;
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
PrivateData;
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2011-04-05 16:16:06 +00:00
|
|
|
static GQuark
|
|
|
|
get_private_data_key( void )
|
|
|
|
{
|
|
|
|
static GQuark q = 0;
|
|
|
|
if( !q ) q = g_quark_from_static_string( "private-data" );
|
|
|
|
return q;
|
|
|
|
}
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2008-08-11 19:05:02 +00:00
|
|
|
static PrivateData*
|
2007-06-18 03:40:41 +00:00
|
|
|
get_private_data( TrWindow * w )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2011-04-05 16:16:06 +00:00
|
|
|
return g_object_get_qdata ( G_OBJECT( w ), get_private_data_key( ) );
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
on_popup_menu( GtkWidget * self UNUSED,
|
|
|
|
GdkEventButton * event )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2010-12-21 19:20:58 +00:00
|
|
|
GtkWidget * menu = gtr_action_get_widget ( "/main-window-popup" );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
gtk_menu_popup ( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
|
|
|
|
( event ? event->button : 0 ),
|
|
|
|
( event ? event->time : 0 ) );
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
view_row_activated( GtkTreeView * tree_view UNUSED,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeViewColumn * column UNUSED,
|
|
|
|
gpointer user_data UNUSED )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_action_activate( "show-torrent-properties" );
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkWidget*
|
2010-03-14 05:13:02 +00:00
|
|
|
makeview( PrivateData * p )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * view;
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkTreeViewColumn * col;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeSelection * sel;
|
|
|
|
GtkCellRenderer * r;
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
view = gtk_tree_view_new( );
|
|
|
|
gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
|
2009-03-02 23:29:14 +00:00
|
|
|
gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW( view ), TRUE );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
p->selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2009-08-10 20:04:08 +00:00
|
|
|
p->column = col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
|
2009-03-02 23:29:14 +00:00
|
|
|
"title", _("Torrent"),
|
|
|
|
"resizable", TRUE,
|
|
|
|
"sizing", GTK_TREE_VIEW_COLUMN_FIXED,
|
|
|
|
NULL));
|
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
p->renderer = r = torrent_cell_renderer_new( );
|
2009-03-02 23:29:14 +00:00
|
|
|
gtk_tree_view_column_pack_start( col, r, FALSE );
|
2011-03-03 01:59:25 +00:00
|
|
|
gtk_tree_view_column_add_attribute( col, r, "torrent", MC_TORRENT );
|
2009-08-07 20:49:06 +00:00
|
|
|
gtk_tree_view_column_add_attribute( col, r, "piece-upload-speed", MC_SPEED_UP );
|
|
|
|
gtk_tree_view_column_add_attribute( col, r, "piece-download-speed", MC_SPEED_DOWN );
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col );
|
2007-12-19 02:46:30 +00:00
|
|
|
g_object_set( r, "xpad", GUI_PAD_SMALL, "ypad", GUI_PAD_SMALL, NULL );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( view ), TRUE );
|
|
|
|
sel = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
|
|
|
|
gtk_tree_selection_set_mode( GTK_TREE_SELECTION( sel ),
|
|
|
|
GTK_SELECTION_MULTIPLE );
|
2007-02-23 19:50:48 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
g_signal_connect( view, "popup-menu",
|
2008-09-23 19:11:04 +00:00
|
|
|
G_CALLBACK( on_popup_menu ), NULL );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_signal_connect( view, "button-press-event",
|
2008-09-23 19:11:04 +00:00
|
|
|
G_CALLBACK( on_tree_view_button_pressed ),
|
|
|
|
(void *) on_popup_menu );
|
2008-09-27 18:01:31 +00:00
|
|
|
g_signal_connect( view, "button-release-event",
|
|
|
|
G_CALLBACK( on_tree_view_button_released ), NULL );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_signal_connect( view, "row-activated",
|
2008-09-23 19:11:04 +00:00
|
|
|
G_CALLBACK( view_row_activated ), NULL );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
gtk_tree_view_set_model( GTK_TREE_VIEW( view ), p->filter_model );
|
2011-03-25 17:42:47 +00:00
|
|
|
g_object_unref( p->filter_model );
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return view;
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 16:47:01 +00:00
|
|
|
static void syncAltSpeedButton( PrivateData * p );
|
|
|
|
|
2007-12-19 19:16:36 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
prefsChanged( TrCore * core UNUSED,
|
|
|
|
const char * key,
|
|
|
|
gpointer wind )
|
2007-12-19 19:16:36 +00:00
|
|
|
{
|
2007-12-20 02:56:47 +00:00
|
|
|
PrivateData * p = get_private_data( GTK_WINDOW( wind ) );
|
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
if( !strcmp( key, PREF_KEY_COMPACT_VIEW ) )
|
2007-12-19 19:16:36 +00:00
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
g_object_set( p->renderer, "compact", gtr_pref_flag_get( key ), NULL );
|
2009-03-02 23:29:14 +00:00
|
|
|
/* since the cell size has changed, we need gtktreeview to revalidate
|
2010-12-27 19:18:17 +00:00
|
|
|
* its fixed-height mode values. Unfortunately there's not an API call
|
2009-03-02 23:29:14 +00:00
|
|
|
* for that, but it *does* revalidate when it thinks the style's been tweaked */
|
|
|
|
g_signal_emit_by_name( p->view, "style-set", NULL, NULL );
|
2007-12-19 19:16:36 +00:00
|
|
|
}
|
2008-03-19 19:30:03 +00:00
|
|
|
else if( !strcmp( key, PREF_KEY_STATUSBAR ) )
|
2007-12-20 02:56:47 +00:00
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
const gboolean isEnabled = gtr_pref_flag_get( key );
|
2007-12-20 02:56:47 +00:00
|
|
|
g_object_set( p->status, "visible", isEnabled, NULL );
|
|
|
|
}
|
2008-03-19 19:30:03 +00:00
|
|
|
else if( !strcmp( key, PREF_KEY_FILTERBAR ) )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
const gboolean isEnabled = gtr_pref_flag_get( key );
|
2007-12-24 00:14:39 +00:00
|
|
|
g_object_set( p->filter, "visible", isEnabled, NULL );
|
|
|
|
}
|
2007-12-20 02:56:47 +00:00
|
|
|
else if( !strcmp( key, PREF_KEY_TOOLBAR ) )
|
|
|
|
{
|
2010-12-22 06:25:30 +00:00
|
|
|
const gboolean isEnabled = gtr_pref_flag_get( key );
|
2007-12-20 02:56:47 +00:00
|
|
|
g_object_set( p->toolbar, "visible", isEnabled, NULL );
|
|
|
|
}
|
2008-03-19 19:30:03 +00:00
|
|
|
else if( !strcmp( key, PREF_KEY_STATUSBAR_STATS ) )
|
2007-12-20 19:21:21 +00:00
|
|
|
{
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_window_refresh( (TrWindow*)wind );
|
2007-12-20 19:21:21 +00:00
|
|
|
}
|
2009-06-27 05:23:13 +00:00
|
|
|
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) ||
|
2010-07-04 06:07:21 +00:00
|
|
|
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_KBps ) ||
|
|
|
|
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps ) )
|
2009-03-28 16:47:01 +00:00
|
|
|
{
|
|
|
|
syncAltSpeedButton( p );
|
|
|
|
}
|
2007-12-19 19:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
privateFree( gpointer vprivate )
|
|
|
|
{
|
2008-02-24 14:32:42 +00:00
|
|
|
PrivateData * p = vprivate;
|
2007-12-19 19:16:36 +00:00
|
|
|
g_signal_handler_disconnect( p->core, p->pref_handler_id );
|
|
|
|
g_free( p );
|
|
|
|
}
|
|
|
|
|
2007-12-20 19:21:21 +00:00
|
|
|
static void
|
2009-05-16 19:27:14 +00:00
|
|
|
onYinYangReleased( GtkWidget * w UNUSED, gpointer vprivate )
|
2007-12-20 19:21:21 +00:00
|
|
|
{
|
2008-02-24 14:32:42 +00:00
|
|
|
PrivateData * p = vprivate;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-05-16 19:27:14 +00:00
|
|
|
gtk_menu_popup( GTK_MENU( p->status_menu ),
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
|
|
|
gtk_get_current_event_time( ) );
|
2007-12-20 19:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STATS_MODE "stats-mode"
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char * val, *i18n;
|
2007-12-20 19:21:21 +00:00
|
|
|
} stats_modes[] = {
|
2008-09-23 19:11:04 +00:00
|
|
|
{ "total-ratio", N_( "Total Ratio" ) },
|
|
|
|
{ "session-ratio", N_( "Session Ratio" ) },
|
|
|
|
{ "total-transfer", N_( "Total Transfer" ) },
|
|
|
|
{ "session-transfer", N_( "Session Transfer" ) }
|
2007-12-20 19:21:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
status_menu_toggled_cb( GtkCheckMenuItem * menu_item,
|
|
|
|
gpointer vprivate )
|
2007-12-20 19:21:21 +00:00
|
|
|
{
|
|
|
|
if( gtk_check_menu_item_get_active( menu_item ) )
|
|
|
|
{
|
2008-02-24 14:32:42 +00:00
|
|
|
PrivateData * p = vprivate;
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * val = g_object_get_data( G_OBJECT(
|
|
|
|
menu_item ), STATS_MODE );
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref( p->core, PREF_KEY_STATUSBAR_STATS, val );
|
2007-12-20 19:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-28 16:47:01 +00:00
|
|
|
static void
|
|
|
|
syncAltSpeedButton( PrivateData * p )
|
|
|
|
{
|
2009-06-27 05:23:13 +00:00
|
|
|
char u[32];
|
|
|
|
char d[32];
|
2009-09-11 23:43:42 +00:00
|
|
|
char * str;
|
2009-06-27 05:23:13 +00:00
|
|
|
const char * fmt;
|
2010-12-22 06:25:30 +00:00
|
|
|
const gboolean b = gtr_pref_flag_get( TR_PREFS_KEY_ALT_SPEED_ENABLED );
|
2009-12-14 19:24:05 +00:00
|
|
|
const char * stock = b ? "alt-speed-on" : "alt-speed-off";
|
2009-03-28 16:47:01 +00:00
|
|
|
GtkWidget * w = p->alt_speed_button;
|
|
|
|
|
2010-12-22 06:25:30 +00:00
|
|
|
tr_formatter_speed_KBps( u, gtr_pref_int_get( TR_PREFS_KEY_ALT_SPEED_UP_KBps ), sizeof( u ) );
|
|
|
|
tr_formatter_speed_KBps( d, gtr_pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN_KBps ), sizeof( d ) );
|
2010-12-11 18:49:59 +00:00
|
|
|
fmt = b ? _( "Click to disable Alternative Speed Limits\n(%1$s down, %2$s up)" )
|
|
|
|
: _( "Click to enable Alternative Speed Limits\n(%1$s down, %2$s up)" );
|
2009-09-11 23:43:42 +00:00
|
|
|
str = g_strdup_printf( fmt, d, u );
|
2009-03-28 16:47:01 +00:00
|
|
|
|
2009-06-27 05:23:13 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), b );
|
2009-12-14 19:24:05 +00:00
|
|
|
gtk_image_set_from_stock( GTK_IMAGE( p->alt_speed_image ), stock, -1 );
|
2009-04-07 04:42:50 +00:00
|
|
|
gtk_button_set_alignment( GTK_BUTTON( w ), 0.5, 0.5 );
|
2009-09-11 23:43:42 +00:00
|
|
|
gtr_widget_set_tooltip_text( w, str );
|
|
|
|
|
|
|
|
g_free( str );
|
2009-03-28 16:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
alt_speed_toggled_cb( GtkToggleButton * button, gpointer vprivate )
|
|
|
|
{
|
|
|
|
PrivateData * p = vprivate;
|
|
|
|
const gboolean b = gtk_toggle_button_get_active( button );
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_bool( p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b );
|
2009-03-28 16:47:01 +00:00
|
|
|
}
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
/***
|
|
|
|
**** FILTER
|
|
|
|
***/
|
|
|
|
|
2008-10-02 02:13:26 +00:00
|
|
|
#if GTK_CHECK_VERSION( 2, 12, 0 )
|
|
|
|
|
|
|
|
static void
|
|
|
|
findMaxAnnounceTime( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gmaxTime )
|
|
|
|
{
|
|
|
|
tr_torrent * tor;
|
|
|
|
const tr_stat * torStat;
|
|
|
|
time_t * maxTime = gmaxTime;
|
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
2008-10-02 02:13:26 +00:00
|
|
|
torStat = tr_torrentStatCached( tor );
|
|
|
|
*maxTime = MAX( *maxTime, torStat->manualAnnounceTime );
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
onAskTrackerQueryTooltip( GtkWidget * widget UNUSED,
|
|
|
|
gint x UNUSED,
|
|
|
|
gint y UNUSED,
|
|
|
|
gboolean keyboard_tip UNUSED,
|
|
|
|
GtkTooltip * tooltip,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
const time_t now = time( NULL );
|
|
|
|
time_t maxTime = 0;
|
|
|
|
PrivateData * p = gdata;
|
|
|
|
|
|
|
|
gtk_tree_selection_selected_foreach( p->selection,
|
|
|
|
findMaxAnnounceTime,
|
|
|
|
&maxTime );
|
|
|
|
if( maxTime <= now )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-12 07:26:13 +00:00
|
|
|
char buf[512];
|
2008-10-02 02:13:26 +00:00
|
|
|
char timebuf[64];
|
|
|
|
const int seconds = maxTime - now;
|
|
|
|
|
|
|
|
tr_strltime( timebuf, seconds, sizeof( timebuf ) );
|
|
|
|
g_snprintf( buf, sizeof( buf ),
|
|
|
|
_( "Tracker will allow requests in %s" ), timebuf );
|
|
|
|
gtk_tooltip_set_text( tooltip, buf );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-03-28 16:47:01 +00:00
|
|
|
static gboolean
|
|
|
|
onAltSpeedToggledIdle( gpointer vp )
|
|
|
|
{
|
|
|
|
PrivateData * p = vp;
|
2011-03-03 01:59:25 +00:00
|
|
|
gboolean b = tr_sessionUsesAltSpeed( gtr_core_session( p->core ) );
|
|
|
|
gtr_core_set_pref_bool( p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b );
|
2009-03-28 16:47:01 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-22 15:19:54 +00:00
|
|
|
onAltSpeedToggled( tr_session * s UNUSED, bool isEnabled UNUSED, bool byUser UNUSED, void * p )
|
2009-03-28 16:47:01 +00:00
|
|
|
{
|
2009-06-29 17:22:35 +00:00
|
|
|
gtr_idle_add( onAltSpeedToggledIdle, p );
|
2009-03-28 16:47:01 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
/***
|
|
|
|
**** Speed limit menu
|
|
|
|
***/
|
|
|
|
|
|
|
|
#define DIRECTION_KEY "direction-key"
|
2009-04-15 04:28:04 +00:00
|
|
|
#define ENABLED_KEY "enabled-key"
|
|
|
|
#define SPEED_KEY "speed-key"
|
|
|
|
|
|
|
|
static void
|
2009-08-10 20:04:08 +00:00
|
|
|
onSpeedToggled( GtkCheckMenuItem * check, gpointer vp )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
|
|
|
PrivateData * p = vp;
|
2009-04-15 15:10:22 +00:00
|
|
|
GObject * o = G_OBJECT( check );
|
|
|
|
gboolean isEnabled = g_object_get_data( o, ENABLED_KEY ) != 0;
|
|
|
|
tr_direction dir = GPOINTER_TO_INT( g_object_get_data( o, DIRECTION_KEY ) );
|
|
|
|
const char * key = dir == TR_UP ? TR_PREFS_KEY_USPEED_ENABLED
|
|
|
|
: TR_PREFS_KEY_DSPEED_ENABLED;
|
|
|
|
|
2009-04-15 04:28:04 +00:00
|
|
|
if( gtk_check_menu_item_get_active( check ) )
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_bool( p->core, key, isEnabled );
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
2009-04-15 04:28:04 +00:00
|
|
|
static void
|
2009-08-10 20:04:08 +00:00
|
|
|
onSpeedSet( GtkCheckMenuItem * check, gpointer vp )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
2009-04-15 15:10:22 +00:00
|
|
|
const char * key;
|
2009-04-15 04:28:04 +00:00
|
|
|
PrivateData * p = vp;
|
2009-04-15 15:10:22 +00:00
|
|
|
GObject * o = G_OBJECT( check );
|
2010-07-04 06:07:21 +00:00
|
|
|
const int KBps = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) );
|
2009-04-15 15:10:22 +00:00
|
|
|
tr_direction dir = GPOINTER_TO_INT( g_object_get_data( o, DIRECTION_KEY ) );
|
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
key = dir==TR_UP ? TR_PREFS_KEY_USPEED_KBps : TR_PREFS_KEY_DSPEED_KBps;
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_int( p->core, key, KBps );
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
|
|
key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_bool( p->core, key, TRUE );
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
createSpeedMenu( PrivateData * p, tr_direction dir )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
2009-04-15 15:10:22 +00:00
|
|
|
int i, n;
|
|
|
|
GtkWidget *w, *m;
|
2010-07-09 20:53:38 +00:00
|
|
|
const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
|
|
m = gtk_menu_new( );
|
|
|
|
|
|
|
|
w = gtk_radio_menu_item_new_with_label( NULL, _( "Unlimited" ) );
|
|
|
|
p->speedlimit_off_item[dir] = w;
|
|
|
|
g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) );
|
|
|
|
g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( FALSE ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(onSpeedToggled), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
|
|
|
|
|
|
|
w = gtk_radio_menu_item_new_with_label_from_widget( GTK_RADIO_MENU_ITEM( w ), "" );
|
|
|
|
p->speedlimit_on_item[dir] = w;
|
|
|
|
g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) );
|
|
|
|
g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( TRUE ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(onSpeedToggled), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
|
|
|
|
|
|
|
w = gtk_separator_menu_item_new( );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
|
|
|
|
2010-07-09 20:53:38 +00:00
|
|
|
for( i=0, n=G_N_ELEMENTS(speeds_KBps); i<n; ++i )
|
2009-04-15 15:10:22 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
2010-07-09 20:53:38 +00:00
|
|
|
tr_formatter_speed_KBps( buf, speeds_KBps[i], sizeof( buf ) );
|
2009-04-15 15:10:22 +00:00
|
|
|
w = gtk_menu_item_new_with_label( buf );
|
|
|
|
g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) );
|
2010-07-09 20:53:38 +00:00
|
|
|
g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( speeds_KBps[i] ) );
|
2009-04-15 15:10:22 +00:00
|
|
|
g_signal_connect( w, "activate", G_CALLBACK(onSpeedSet), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
|
|
|
}
|
|
|
|
|
|
|
|
return m;
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
2009-04-15 15:10:22 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
**** Speed limit menu
|
|
|
|
***/
|
|
|
|
|
|
|
|
#define RATIO_KEY "stock-ratio-index"
|
|
|
|
|
|
|
|
static const double stockRatios[] = { 0.25, 0.5, 0.75, 1, 1.5, 2, 3 };
|
|
|
|
|
2009-04-15 04:28:04 +00:00
|
|
|
static void
|
2009-08-10 20:04:08 +00:00
|
|
|
onRatioToggled( GtkCheckMenuItem * check, gpointer vp )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
|
|
|
PrivateData * p = vp;
|
|
|
|
if( gtk_check_menu_item_get_active( check ) )
|
|
|
|
{
|
2009-04-15 15:10:22 +00:00
|
|
|
gboolean f = g_object_get_data( G_OBJECT( check ), ENABLED_KEY ) != 0;
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_bool( p->core, TR_PREFS_KEY_RATIO_ENABLED, f );
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
2009-08-10 20:04:08 +00:00
|
|
|
onRatioSet( GtkCheckMenuItem * check, gpointer vp )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
|
|
|
PrivateData * p = vp;
|
2009-04-15 15:10:22 +00:00
|
|
|
int i = GPOINTER_TO_INT( g_object_get_data( G_OBJECT( check ), RATIO_KEY ) );
|
|
|
|
const double ratio = stockRatios[i];
|
2011-03-03 01:59:25 +00:00
|
|
|
gtr_core_set_pref_double( p->core, TR_PREFS_KEY_RATIO, ratio );
|
|
|
|
gtr_core_set_pref_bool ( p->core, TR_PREFS_KEY_RATIO_ENABLED, TRUE );
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
2009-04-15 15:10:22 +00:00
|
|
|
createRatioMenu( PrivateData * p )
|
2009-04-15 04:28:04 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
2009-04-15 15:10:22 +00:00
|
|
|
GtkWidget *m, *w;
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
m = gtk_menu_new( );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
w = gtk_radio_menu_item_new_with_label( NULL, _( "Seed Forever" ) );
|
|
|
|
p->ratio_off_item = w;
|
|
|
|
g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( FALSE ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(onRatioToggled), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
w = gtk_radio_menu_item_new_with_label_from_widget( GTK_RADIO_MENU_ITEM( w ), "" );
|
|
|
|
p->ratio_on_item = w;
|
|
|
|
g_object_set_data( G_OBJECT( w ), ENABLED_KEY, GINT_TO_POINTER( TRUE ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(onRatioToggled), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
|
|
w = gtk_separator_menu_item_new( );
|
2009-04-15 15:10:22 +00:00
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
for( i=0, n=G_N_ELEMENTS(stockRatios); i<n; ++i )
|
|
|
|
{
|
2009-04-15 04:28:04 +00:00
|
|
|
char buf[128];
|
2009-04-15 15:10:22 +00:00
|
|
|
tr_strlratio( buf, stockRatios[i], sizeof( buf ) );
|
2009-04-15 04:28:04 +00:00
|
|
|
w = gtk_menu_item_new_with_label( buf );
|
2009-04-15 15:10:22 +00:00
|
|
|
g_object_set_data( G_OBJECT( w ), RATIO_KEY, GINT_TO_POINTER( i ) );
|
|
|
|
g_signal_connect( w, "activate", G_CALLBACK(onRatioSet), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
|
2009-04-15 04:28:04 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
return m;
|
|
|
|
}
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
/***
|
|
|
|
**** Option menu
|
|
|
|
***/
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
static GtkWidget*
|
|
|
|
createOptionsMenu( PrivateData * p )
|
|
|
|
{
|
|
|
|
GtkWidget * m;
|
|
|
|
GtkWidget * top = gtk_menu_new( );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
m = gtk_menu_item_new_with_label( _( "Limit Download Speed" ) );
|
|
|
|
gtk_menu_item_set_submenu( GTK_MENU_ITEM( m ), createSpeedMenu( p, TR_DOWN ) );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( top ), m );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
m = gtk_menu_item_new_with_label( _( "Limit Upload Speed" ) );
|
|
|
|
gtk_menu_item_set_submenu( GTK_MENU_ITEM( m ), createSpeedMenu( p, TR_UP ) );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( top ), m );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
m = gtk_separator_menu_item_new( );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( top ), m );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
m = gtk_menu_item_new_with_label( _( "Stop Seeding at Ratio" ) );
|
|
|
|
gtk_menu_item_set_submenu( GTK_MENU_ITEM( m ), createRatioMenu( p ) );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( top ), m );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
gtk_widget_show_all( top );
|
2009-04-15 04:28:04 +00:00
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
|
|
|
|
{
|
|
|
|
char buf1[512];
|
|
|
|
char buf2[512];
|
|
|
|
gboolean b;
|
2009-04-15 15:10:22 +00:00
|
|
|
GtkWidget * w;
|
2009-04-15 04:28:04 +00:00
|
|
|
PrivateData * p = vp;
|
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
w = p->speedlimit_on_item[TR_DOWN];
|
2010-12-22 06:25:30 +00:00
|
|
|
tr_formatter_speed_KBps( buf1, gtr_pref_int_get( TR_PREFS_KEY_DSPEED_KBps ), sizeof( buf1 ) );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2010-12-22 06:25:30 +00:00
|
|
|
b = gtr_pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED );
|
2009-04-15 15:10:22 +00:00
|
|
|
w = b ? p->speedlimit_on_item[TR_DOWN] : p->speedlimit_off_item[TR_DOWN];
|
|
|
|
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( w ), TRUE );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2009-04-15 15:10:22 +00:00
|
|
|
w = p->speedlimit_on_item[TR_UP];
|
2010-12-22 06:25:30 +00:00
|
|
|
tr_formatter_speed_KBps( buf1, gtr_pref_int_get( TR_PREFS_KEY_USPEED_KBps ), sizeof( buf1 ) );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2010-12-22 06:25:30 +00:00
|
|
|
b = gtr_pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED );
|
2009-04-15 15:10:22 +00:00
|
|
|
w = b ? p->speedlimit_on_item[TR_UP] : p->speedlimit_off_item[TR_UP];
|
|
|
|
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( w ), TRUE );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2010-12-22 06:25:30 +00:00
|
|
|
tr_strlratio( buf1, gtr_pref_double_get( TR_PREFS_KEY_RATIO ), sizeof( buf1 ) );
|
2009-04-15 04:28:04 +00:00
|
|
|
g_snprintf( buf2, sizeof( buf2 ), _( "Stop at Ratio (%s)" ), buf1 );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->ratio_on_item ) ) ), buf2 );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2010-12-22 06:25:30 +00:00
|
|
|
b = gtr_pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED );
|
2009-04-15 04:28:04 +00:00
|
|
|
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( b ? p->ratio_on_item : p->ratio_off_item ), TRUE );
|
|
|
|
|
|
|
|
gtk_menu_popup ( GTK_MENU( p->options_menu ), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time( ) );
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/***
|
|
|
|
**** PUBLIC
|
|
|
|
***/
|
|
|
|
|
|
|
|
GtkWidget *
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_window_new( GtkUIManager * ui_mgr, TrCore * core )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int i, n;
|
2009-06-21 17:18:02 +00:00
|
|
|
const char * pch;
|
2008-02-09 17:49:09 +00:00
|
|
|
PrivateData * p;
|
2009-06-21 17:18:02 +00:00
|
|
|
GtkWidget * mainmenu, *toolbar, *filter, *list, *status;
|
2010-03-14 05:13:02 +00:00
|
|
|
GtkWidget * vbox, *w, *self, *h, *hbox, *menu;
|
2009-06-21 17:18:02 +00:00
|
|
|
GtkWindow * win;
|
|
|
|
GSList * l;
|
2008-12-25 16:17:08 +00:00
|
|
|
|
2008-02-09 17:49:09 +00:00
|
|
|
p = g_new0( PrivateData, 1 );
|
2007-12-24 17:25:52 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/* make the window */
|
2008-09-23 19:11:04 +00:00
|
|
|
self = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
|
2011-04-05 16:16:06 +00:00
|
|
|
g_object_set_qdata_full( G_OBJECT(self), get_private_data_key( ), p, privateFree );
|
2008-04-21 20:58:39 +00:00
|
|
|
win = GTK_WINDOW( self );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_window_set_title( win, g_get_application_name( ) );
|
2008-04-21 20:58:39 +00:00
|
|
|
gtk_window_set_role( win, "tr-main" );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_window_set_default_size( win,
|
2010-12-22 06:25:30 +00:00
|
|
|
gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ),
|
|
|
|
gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) );
|
|
|
|
gtk_window_move( win, gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_X ),
|
|
|
|
gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
|
|
|
|
if( gtr_pref_flag_get( PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED ) )
|
2009-06-11 22:36:45 +00:00
|
|
|
gtk_window_maximize( win );
|
2008-12-25 16:17:08 +00:00
|
|
|
gtk_window_add_accel_group( win, gtk_ui_manager_get_accel_group( ui_mgr ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/* window's main container */
|
2008-09-23 19:11:04 +00:00
|
|
|
vbox = gtk_vbox_new ( FALSE, 0 );
|
|
|
|
gtk_container_add ( GTK_CONTAINER( self ), vbox );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/* main menu */
|
2010-12-21 19:20:58 +00:00
|
|
|
mainmenu = gtr_action_get_widget( "/main-window-menu" );
|
|
|
|
w = gtr_action_get_widget( "/main-window-menu/torrent-menu/update-tracker" );
|
2008-10-02 02:13:26 +00:00
|
|
|
#if GTK_CHECK_VERSION( 2, 12, 0 )
|
|
|
|
g_signal_connect( w, "query-tooltip",
|
|
|
|
G_CALLBACK( onAskTrackerQueryTooltip ), p );
|
|
|
|
#endif
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/* toolbar */
|
2010-12-21 19:20:58 +00:00
|
|
|
toolbar = p->toolbar = gtr_action_get_widget( "/main-window-toolbar" );
|
2011-01-20 19:48:13 +00:00
|
|
|
gtr_action_set_important( "open-torrent-toolbar", TRUE );
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_action_set_important( "show-torrent-properties", TRUE );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-01-17 18:03:45 +00:00
|
|
|
/* filter */
|
2011-03-03 01:59:25 +00:00
|
|
|
h = filter = p->filter = gtr_filter_bar_new( gtr_core_session( core ),
|
|
|
|
gtr_core_model( core ),
|
2010-03-15 02:53:31 +00:00
|
|
|
&p->filter_model );
|
2008-01-17 18:03:45 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
|
|
|
|
|
2007-12-20 19:21:21 +00:00
|
|
|
/* status menu */
|
2007-12-24 00:14:39 +00:00
|
|
|
menu = p->status_menu = gtk_menu_new( );
|
|
|
|
l = NULL;
|
2010-12-22 06:25:30 +00:00
|
|
|
pch = gtr_pref_string_get( PREF_KEY_STATUSBAR_STATS );
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0, n = G_N_ELEMENTS( stats_modes ); i < n; ++i )
|
2007-12-20 19:21:21 +00:00
|
|
|
{
|
|
|
|
const char * val = stats_modes[i].val;
|
|
|
|
w = gtk_radio_menu_item_new_with_label( l, _( stats_modes[i].i18n ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
l = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM( w ) );
|
|
|
|
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( w ),
|
|
|
|
!strcmp( val, pch ) );
|
|
|
|
g_object_set_data( G_OBJECT(
|
|
|
|
w ), STATS_MODE,
|
|
|
|
(gpointer)stats_modes[i].val );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(
|
|
|
|
status_menu_toggled_cb ), p );
|
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( menu ), w );
|
2007-12-20 19:21:21 +00:00
|
|
|
gtk_widget_show( w );
|
|
|
|
}
|
|
|
|
|
2008-01-17 18:03:45 +00:00
|
|
|
/* status */
|
2010-06-25 20:15:05 +00:00
|
|
|
h = status = p->status = gtk_hbox_new( FALSE, GUI_PAD_BIG );
|
2009-03-28 16:47:01 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
|
|
|
w = gtk_button_new( );
|
2010-11-27 19:30:20 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), gtk_image_new_from_stock( "utilities", -1 ) );
|
2010-01-03 17:38:24 +00:00
|
|
|
gtr_widget_set_tooltip_text( w, _( "Options" ) );
|
2009-04-15 04:28:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
|
|
|
|
gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
|
|
|
|
p->options_menu = createOptionsMenu( p );
|
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK(onOptionsClicked), p );
|
|
|
|
|
2009-12-14 19:24:05 +00:00
|
|
|
p->alt_speed_image = gtk_image_new( );
|
2009-04-15 04:28:04 +00:00
|
|
|
w = p->alt_speed_button = gtk_toggle_button_new( );
|
2009-12-14 19:24:05 +00:00
|
|
|
gtk_button_set_image( GTK_BUTTON( w ), p->alt_speed_image );
|
2009-04-15 04:28:04 +00:00
|
|
|
gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(alt_speed_toggled_cb ), p );
|
|
|
|
gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
|
|
|
|
|
|
|
|
w = p->gutter_lb = gtk_label_new( "N Torrents" );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( w ), TRUE );
|
2010-06-25 20:15:05 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h ), w, 1, 1, GUI_PAD );
|
2009-04-15 04:28:04 +00:00
|
|
|
|
2010-06-25 20:15:05 +00:00
|
|
|
hbox = gtk_hbox_new( FALSE, GUI_PAD );
|
2009-05-01 19:39:34 +00:00
|
|
|
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
|
|
|
|
gtk_widget_set_size_request( w, GUI_PAD, 0u );
|
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2009-05-02 13:53:49 +00:00
|
|
|
w = p->ul_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( w ), TRUE );
|
2009-08-10 20:04:08 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2010-06-25 20:15:05 +00:00
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU );
|
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2009-05-01 19:39:34 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), hbox, FALSE, FALSE, 0 );
|
|
|
|
|
2010-06-25 20:15:05 +00:00
|
|
|
hbox = gtk_hbox_new( FALSE, GUI_PAD );
|
2009-05-01 19:39:34 +00:00
|
|
|
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
|
|
|
|
gtk_widget_set_size_request( w, GUI_PAD, 0u );
|
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2009-05-02 13:53:49 +00:00
|
|
|
w = p->dl_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( w ), TRUE );
|
2009-08-10 20:04:08 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2010-06-25 20:15:05 +00:00
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU );
|
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2009-05-01 19:39:34 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), hbox, FALSE, FALSE, 0 );
|
|
|
|
|
2010-06-25 20:15:05 +00:00
|
|
|
hbox = gtk_hbox_new( FALSE, GUI_PAD );
|
2009-05-14 18:34:44 +00:00
|
|
|
w = gtk_button_new( );
|
2010-01-03 17:38:24 +00:00
|
|
|
gtr_widget_set_tooltip_text( w, _( "Statistics" ) );
|
2010-11-27 19:30:20 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), gtk_image_new_from_stock( "ratio", -1 ) );
|
2009-05-14 18:34:44 +00:00
|
|
|
gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
|
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK( onYinYangReleased ), p );
|
2009-05-01 19:39:34 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
|
|
|
w = p->stats_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( w ), TRUE );
|
2010-06-25 20:15:05 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( hbox ), w, FALSE, FALSE, 0 );
|
2009-05-01 19:39:34 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), hbox, FALSE, FALSE, 0 );
|
|
|
|
|
2007-12-20 02:56:47 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/* workarea */
|
2010-03-14 05:13:02 +00:00
|
|
|
p->view = makeview( p );
|
2008-12-25 16:17:08 +00:00
|
|
|
w = list = p->scroll = gtk_scrolled_window_new( NULL, NULL );
|
2008-11-16 07:26:35 +00:00
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ),
|
2008-12-25 16:17:08 +00:00
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
|
2008-11-16 07:26:35 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( w ),
|
|
|
|
GTK_SHADOW_IN );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), p->view );
|
2008-12-25 16:17:08 +00:00
|
|
|
|
2010-08-06 06:22:05 +00:00
|
|
|
/* lay out the widgets */
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), mainmenu, FALSE, FALSE, 0 );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), filter, FALSE, FALSE, 0 );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), list, TRUE, TRUE, 0 );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), status, FALSE, FALSE, 0 );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2010-01-10 01:43:04 +00:00
|
|
|
{
|
|
|
|
/* this is to determine the maximum width/height for the label */
|
2010-07-31 06:20:17 +00:00
|
|
|
int w=0, h=0;
|
|
|
|
PangoLayout * pango_layout;
|
2010-08-06 23:50:35 +00:00
|
|
|
pango_layout = gtk_widget_create_pango_layout( p->ul_lb, "999.99 KiB/s" );
|
2010-01-10 01:43:04 +00:00
|
|
|
pango_layout_get_pixel_size( pango_layout, &w, &h );
|
|
|
|
gtk_widget_set_size_request( p->ul_lb, w, h );
|
|
|
|
gtk_widget_set_size_request( p->dl_lb, w, h );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( p->ul_lb ), 1.0, 0.5 );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( p->dl_lb ), 1.0, 0.5 );
|
|
|
|
g_object_unref( G_OBJECT( pango_layout ) );
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/* show all but the window */
|
|
|
|
gtk_widget_show_all( vbox );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-12-19 19:16:36 +00:00
|
|
|
/* listen for prefs changes that affect the window */
|
2007-12-22 16:34:47 +00:00
|
|
|
p->core = core;
|
2010-03-15 14:42:43 +00:00
|
|
|
prefsChanged( core, PREF_KEY_COMPACT_VIEW, self );
|
2008-03-19 19:30:03 +00:00
|
|
|
prefsChanged( core, PREF_KEY_FILTERBAR, self );
|
|
|
|
prefsChanged( core, PREF_KEY_STATUSBAR, self );
|
|
|
|
prefsChanged( core, PREF_KEY_STATUSBAR_STATS, self );
|
2007-12-20 02:56:47 +00:00
|
|
|
prefsChanged( core, PREF_KEY_TOOLBAR, self );
|
2009-03-28 16:47:01 +00:00
|
|
|
prefsChanged( core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self );
|
2007-12-20 01:33:51 +00:00
|
|
|
p->pref_handler_id = g_signal_connect( core, "prefs-changed",
|
2008-09-23 19:11:04 +00:00
|
|
|
G_CALLBACK( prefsChanged ), self );
|
2007-12-19 19:16:36 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_sessionSetAltSpeedFunc( gtr_core_session( core ), onAltSpeedToggled, p );
|
2009-03-28 16:47:01 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return self;
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-24 17:25:52 +00:00
|
|
|
static void
|
|
|
|
updateTorrentCount( PrivateData * p )
|
|
|
|
{
|
|
|
|
if( p && p->core )
|
|
|
|
{
|
2009-09-12 07:26:13 +00:00
|
|
|
char buf[512];
|
2011-03-03 01:59:25 +00:00
|
|
|
const int torrentCount = gtk_tree_model_iter_n_children( gtr_core_model( p->core ), NULL );
|
2010-08-06 14:38:54 +00:00
|
|
|
const int visibleCount = gtk_tree_model_iter_n_children( p->filter_model, NULL );
|
2007-12-24 17:25:52 +00:00
|
|
|
|
2009-05-01 19:39:34 +00:00
|
|
|
if( !torrentCount )
|
|
|
|
*buf = '\0';
|
|
|
|
else if( torrentCount != visibleCount )
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ),
|
2011-05-02 17:58:27 +00:00
|
|
|
ngettext( "%1$'d of %2$'d Torrent",
|
|
|
|
"%1$'d of %2$'d Torrents",
|
|
|
|
torrentCount ),
|
2008-09-23 19:11:04 +00:00
|
|
|
visibleCount, torrentCount );
|
2007-12-24 17:25:52 +00:00
|
|
|
else
|
2009-05-01 19:39:34 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ),
|
2011-05-02 17:58:27 +00:00
|
|
|
ngettext( "%'d Torrent", "%'d Torrents", torrentCount ),
|
2008-09-23 19:11:04 +00:00
|
|
|
torrentCount );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( p->gutter_lb ), buf );
|
2007-12-24 17:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-24 19:12:52 +00:00
|
|
|
static void
|
|
|
|
updateStats( PrivateData * p )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * pch;
|
2009-09-12 07:26:13 +00:00
|
|
|
char up[32], down[32], ratio[32], buf[512];
|
2007-12-24 19:12:52 +00:00
|
|
|
struct tr_session_stats stats;
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_session * session = gtr_core_session( p->core );
|
2007-12-24 19:12:52 +00:00
|
|
|
|
|
|
|
/* update the stats */
|
2010-12-22 06:25:30 +00:00
|
|
|
pch = gtr_pref_string_get( PREF_KEY_STATUSBAR_STATS );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( !strcmp( pch, "session-ratio" ) )
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_sessionGetStats( session, &stats );
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), _( "Ratio: %s" ), ratio );
|
|
|
|
}
|
|
|
|
else if( !strcmp( pch, "session-transfer" ) )
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_sessionGetStats( session, &stats );
|
2007-12-24 19:12:52 +00:00
|
|
|
tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
|
|
|
|
tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
|
2010-12-27 19:18:17 +00:00
|
|
|
/* Translators: "size|" is here for disambiguation. Please remove it from your translation.
|
2008-03-08 04:53:11 +00:00
|
|
|
%1$s is the size of the data we've downloaded
|
|
|
|
%2$s is the size of the data we've uploaded */
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), Q_(
|
|
|
|
"size|Down: %1$s, Up: %2$s" ), down, up );
|
|
|
|
}
|
|
|
|
else if( !strcmp( pch, "total-transfer" ) )
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_sessionGetCumulativeStats( session, &stats );
|
2007-12-24 19:12:52 +00:00
|
|
|
tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
|
|
|
|
tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
|
2010-12-27 19:18:17 +00:00
|
|
|
/* Translators: "size|" is here for disambiguation. Please remove it from your translation.
|
2008-03-08 04:53:11 +00:00
|
|
|
%1$s is the size of the data we've downloaded
|
|
|
|
%2$s is the size of the data we've uploaded */
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), Q_(
|
|
|
|
"size|Down: %1$s, Up: %2$s" ), down, up );
|
|
|
|
}
|
|
|
|
else /* default is total-ratio */
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_sessionGetCumulativeStats( session, &stats );
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), _( "Ratio: %s" ), ratio );
|
2007-12-24 19:12:52 +00:00
|
|
|
}
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( p->stats_lb ), buf );
|
2007-12-24 19:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateSpeeds( PrivateData * p )
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_session * session = gtr_core_session( p->core );
|
2007-12-24 19:12:52 +00:00
|
|
|
|
2008-11-08 02:49:04 +00:00
|
|
|
if( session != NULL )
|
|
|
|
{
|
|
|
|
char buf[128];
|
2010-07-04 06:07:21 +00:00
|
|
|
double up=0, down=0;
|
2009-08-07 20:49:06 +00:00
|
|
|
GtkTreeIter iter;
|
2011-03-03 01:59:25 +00:00
|
|
|
GtkTreeModel * model = gtr_core_model( p->core );
|
2008-11-08 02:49:04 +00:00
|
|
|
|
2011-04-13 22:00:55 +00:00
|
|
|
if( gtk_tree_model_iter_nth_child( model, &iter, NULL, 0 ) ) do
|
2009-08-07 20:49:06 +00:00
|
|
|
{
|
2010-07-04 06:07:21 +00:00
|
|
|
double u, d;
|
2009-08-07 20:49:06 +00:00
|
|
|
gtk_tree_model_get( model, &iter, MC_SPEED_UP, &u,
|
|
|
|
MC_SPEED_DOWN, &d,
|
|
|
|
-1 );
|
|
|
|
up += u;
|
|
|
|
down += d;
|
|
|
|
}
|
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
tr_formatter_speed_KBps( buf, down, sizeof( buf ) );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( p->dl_lb ), buf );
|
2008-11-08 02:49:04 +00:00
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
tr_formatter_speed_KBps( buf, up, sizeof( buf ) );
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( p->ul_lb ), buf );
|
2008-11-08 02:49:04 +00:00
|
|
|
}
|
2007-12-24 19:12:52 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
void
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_window_refresh( TrWindow * self )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
PrivateData * p = get_private_data( self );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
if( p && p->core && gtr_core_session( p->core ) )
|
2007-12-20 19:21:21 +00:00
|
|
|
{
|
2007-12-24 19:12:52 +00:00
|
|
|
updateSpeeds( p );
|
2007-12-24 17:25:52 +00:00
|
|
|
updateTorrentCount( p );
|
2007-12-24 19:12:52 +00:00
|
|
|
updateStats( p );
|
2007-12-20 19:21:21 +00:00
|
|
|
}
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkTreeSelection*
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_window_get_selection( TrWindow * w )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
return get_private_data( w )->selection;
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2010-06-26 15:55:19 +00:00
|
|
|
void
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_window_set_busy( TrWindow * w, gboolean isBusy )
|
2010-06-26 15:55:19 +00:00
|
|
|
{
|
2010-06-26 16:07:15 +00:00
|
|
|
if( w && gtr_widget_get_realized( GTK_WIDGET( w ) ) )
|
2010-12-12 16:43:19 +00:00
|
|
|
{
|
2010-06-26 15:55:19 +00:00
|
|
|
GdkDisplay * display = gtk_widget_get_display( GTK_WIDGET( w ) );
|
|
|
|
GdkCursor * cursor = isBusy ? gdk_cursor_new_for_display( display, GDK_WATCH ) : NULL;
|
|
|
|
|
2010-12-24 09:04:52 +00:00
|
|
|
gdk_window_set_cursor( gtr_widget_get_window( GTK_WIDGET( w ) ), cursor );
|
2010-06-26 15:55:19 +00:00
|
|
|
gdk_display_flush( display );
|
|
|
|
|
2011-03-25 07:32:30 +00:00
|
|
|
if( cursor ) {
|
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
|
|
g_object_unref( cursor );
|
|
|
|
#else
|
2010-12-12 16:43:19 +00:00
|
|
|
gdk_cursor_unref( cursor );
|
2011-03-25 07:32:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-06-26 15:55:19 +00:00
|
|
|
}
|
|
|
|
}
|