2007-02-07 07:35:33 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2005-2008 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>
|
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"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "hig.h"
|
2007-12-24 00:14:39 +00:00
|
|
|
#include "sexy-icon-entry.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-torrent.h"
|
|
|
|
#include "tr-window.h"
|
2007-02-07 07:35:33 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
#if !GTK_CHECK_VERSION( 2, 8, 0 )
|
2007-12-19 20:04:38 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_view_column_queue_resize( GtkTreeViewColumn * column ) /* yuck */
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const int spacing = gtk_tree_view_column_get_spacing( column );
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_spacing( column, spacing + 1 );
|
|
|
|
gtk_tree_view_column_set_spacing( column, spacing );
|
2007-12-19 20:04:38 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-12-19 20:04:38 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FILTER_TEXT_MODE_NAME,
|
|
|
|
FILTER_TEXT_MODE_FILES,
|
|
|
|
FILTER_TEXT_MODE_TRACKER,
|
|
|
|
FILTER_TEXT_MODE_QTY
|
|
|
|
}
|
|
|
|
filter_text_mode_t;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FILTER_MODE_ALL,
|
|
|
|
FILTER_MODE_ACTIVE,
|
|
|
|
FILTER_MODE_DOWNLOADING,
|
|
|
|
FILTER_MODE_SEEDING,
|
|
|
|
FILTER_MODE_PAUSED,
|
|
|
|
FILTER_MODE_QTY
|
|
|
|
}
|
|
|
|
filter_mode_t;
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
typedef struct
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
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;
|
|
|
|
GtkTreeSelection * selection;
|
|
|
|
GtkCellRenderer * renderer;
|
|
|
|
GtkTreeViewColumn * column;
|
|
|
|
GtkTreeModel * filter_model;
|
|
|
|
TrCore * core;
|
|
|
|
gulong pref_handler_id;
|
|
|
|
filter_mode_t filter_mode;
|
|
|
|
filter_text_mode_t filter_text_mode;
|
|
|
|
char * filter_text;
|
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
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#define PRIVATE_DATA_KEY "private-data"
|
2007-02-23 19:50:48 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
#define FILTER_MODE_KEY "tr-filter-mode"
|
|
|
|
#define FILTER_TEXT_MODE_KEY "tr-filter-text-mode"
|
|
|
|
#define FILTER_TOGGLES_KEY "tr-filter-toggles"
|
|
|
|
|
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
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
return g_object_get_data ( G_OBJECT( w ), 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
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkWidget * menu = 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
|
|
|
{
|
2007-10-10 18:52:08 +00:00
|
|
|
action_activate( "show-torrent-details" );
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
static gboolean is_row_visible( GtkTreeModel *,
|
|
|
|
GtkTreeIter *,
|
|
|
|
gpointer );
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkWidget*
|
2008-09-23 19:11:04 +00:00
|
|
|
makeview( PrivateData * p,
|
|
|
|
TrCore * core )
|
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;
|
|
|
|
GtkTreeModel * filter_model;
|
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 );
|
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
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
p->renderer = r = torrent_cell_renderer_new( );
|
2007-12-19 20:04:38 +00:00
|
|
|
p->column = col = gtk_tree_view_column_new_with_attributes(
|
2008-09-23 19:11:04 +00:00
|
|
|
_( "Torrent" ), r, "torrent", MC_TORRENT_RAW, NULL );
|
|
|
|
g_object_set( G_OBJECT( col ), "resizable", TRUE,
|
|
|
|
"sizing", GTK_TREE_VIEW_COLUMN_FIXED,
|
|
|
|
NULL );
|
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
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
filter_model = p->filter_model = gtk_tree_model_filter_new(
|
|
|
|
tr_core_model( core ), NULL );
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER(
|
|
|
|
filter_model ),
|
2007-12-24 00:14:39 +00:00
|
|
|
is_row_visible,
|
|
|
|
p, NULL );
|
|
|
|
|
|
|
|
gtk_tree_view_set_model( GTK_TREE_VIEW( view ), filter_model );
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return view;
|
2007-02-07 07:35:33 +00:00
|
|
|
}
|
|
|
|
|
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 ) );
|
|
|
|
|
2007-12-19 19:16:36 +00:00
|
|
|
if( !strcmp( key, PREF_KEY_MINIMAL_VIEW ) )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
g_object_set( p->renderer, "minimal", pref_flag_get( key ), NULL );
|
|
|
|
gtk_tree_view_column_queue_resize( p->column );
|
|
|
|
gtk_widget_queue_draw( p->view );
|
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
|
|
|
{
|
|
|
|
const gboolean isEnabled = pref_flag_get( key );
|
|
|
|
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
|
|
|
{
|
|
|
|
const gboolean isEnabled = pref_flag_get( key );
|
|
|
|
g_object_set( p->filter, "visible", isEnabled, NULL );
|
|
|
|
}
|
2007-12-20 02:56:47 +00:00
|
|
|
else if( !strcmp( key, PREF_KEY_TOOLBAR ) )
|
|
|
|
{
|
|
|
|
const gboolean isEnabled = pref_flag_get( key );
|
|
|
|
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
|
|
|
{
|
|
|
|
tr_window_update( (TrWindow*)wind );
|
|
|
|
}
|
2007-12-19 19:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
privateFree( gpointer vprivate )
|
|
|
|
{
|
2008-02-24 14:32:42 +00:00
|
|
|
PrivateData * p = vprivate;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-12-19 19:16:36 +00:00
|
|
|
g_signal_handler_disconnect( p->core, p->pref_handler_id );
|
2008-01-12 17:59:09 +00:00
|
|
|
g_free( p->filter_text );
|
2007-12-19 19:16:36 +00:00
|
|
|
g_free( p );
|
|
|
|
}
|
|
|
|
|
2007-12-20 19:21:21 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onYinYangReleased( GtkWidget * w UNUSED,
|
|
|
|
GdkEventButton * button 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
|
|
|
|
|
|
|
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 );
|
2008-03-19 19:30:03 +00:00
|
|
|
tr_core_set_pref( p->core, PREF_KEY_STATUSBAR_STATS, val );
|
2007-12-20 19:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
/***
|
|
|
|
**** FILTER
|
|
|
|
***/
|
|
|
|
|
|
|
|
static int
|
2008-09-23 19:11:04 +00:00
|
|
|
checkFilterText( filter_text_mode_t filter_text_mode,
|
|
|
|
const tr_info * torInfo,
|
|
|
|
const char * text )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
2008-03-22 18:10:59 +00:00
|
|
|
tr_file_index_t i;
|
2008-09-23 19:11:04 +00:00
|
|
|
int ret = 0;
|
|
|
|
char * pch;
|
2007-12-24 00:14:39 +00:00
|
|
|
|
|
|
|
switch( filter_text_mode )
|
|
|
|
{
|
|
|
|
case FILTER_TEXT_MODE_FILES:
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < torInfo->fileCount && !ret; ++i )
|
|
|
|
{
|
2007-12-24 00:14:39 +00:00
|
|
|
pch = g_ascii_strdown( torInfo->files[i].name, -1 );
|
|
|
|
ret = !text || strstr( pch, text ) != NULL;
|
|
|
|
g_free( pch );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILTER_TEXT_MODE_TRACKER:
|
2008-04-24 01:42:53 +00:00
|
|
|
pch = g_ascii_strdown( torInfo->trackers[0].announce, -1 );
|
2007-12-24 00:14:39 +00:00
|
|
|
ret = !text || ( strstr( pch, text ) != NULL );
|
|
|
|
g_free( pch );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* NAME */
|
|
|
|
pch = g_ascii_strdown( torInfo->name, -1 );
|
|
|
|
ret = !text || ( strstr( pch, text ) != NULL );
|
|
|
|
g_free( pch );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-09-23 19:11:04 +00:00
|
|
|
checkFilterMode( filter_mode_t filter_mode,
|
|
|
|
tr_torrent * tor )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch( filter_mode )
|
|
|
|
{
|
|
|
|
case FILTER_MODE_DOWNLOADING:
|
2008-10-20 17:54:56 +00:00
|
|
|
ret = tr_torrentGetActivity( tor ) == TR_STATUS_DOWNLOAD;
|
2007-12-24 00:14:39 +00:00
|
|
|
break;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
case FILTER_MODE_SEEDING:
|
2008-10-20 17:54:56 +00:00
|
|
|
ret = tr_torrentGetActivity( tor ) == TR_STATUS_SEED;
|
2007-12-24 00:14:39 +00:00
|
|
|
break;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
case FILTER_MODE_PAUSED:
|
2008-10-20 17:54:56 +00:00
|
|
|
ret = tr_torrentGetActivity( tor ) == TR_STATUS_STOPPED;
|
2008-04-01 11:53:50 +00:00
|
|
|
break;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
case FILTER_MODE_ACTIVE:
|
|
|
|
{
|
2008-04-01 11:53:50 +00:00
|
|
|
const tr_stat * s = tr_torrentStatCached( tor );
|
2008-09-23 19:11:04 +00:00
|
|
|
ret = s->peersSendingToUs > 0 || s->peersGettingFromUs > 0;
|
2007-12-24 00:14:39 +00:00
|
|
|
break;
|
2008-04-01 11:53:50 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
default: /* all */
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
is_row_visible( GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer vprivate )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
|
|
|
PrivateData * p = vprivate;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrent * tor;
|
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
|
|
|
|
|
2008-04-01 11:53:50 +00:00
|
|
|
return checkFilterMode( p->filter_mode, tor )
|
2008-09-23 19:11:04 +00:00
|
|
|
&& checkFilterText( p->filter_text_mode, tr_torrentInfo(
|
|
|
|
tor ), p->filter_text );
|
2007-12-24 00:14:39 +00:00
|
|
|
}
|
|
|
|
|
2007-12-24 17:25:52 +00:00
|
|
|
static void updateTorrentCount( PrivateData * p );
|
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
static void
|
|
|
|
refilter( PrivateData * p )
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( p->filter_model ) );
|
2007-12-24 17:25:52 +00:00
|
|
|
|
|
|
|
updateTorrentCount( p );
|
2007-12-24 00:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
filter_text_toggled_cb( GtkCheckMenuItem * menu_item,
|
|
|
|
gpointer vprivate )
|
2007-12-24 00:14:39 +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
|
|
|
p->filter_text_mode =
|
|
|
|
GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( menu_item ),
|
|
|
|
FILTER_TEXT_MODE_KEY ) );
|
2007-12-24 00:14:39 +00:00
|
|
|
refilter( p );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
filter_toggled_cb( GtkToggleButton * toggle,
|
|
|
|
gpointer vprivate )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
PrivateData * p = vprivate;
|
|
|
|
GSList * l;
|
|
|
|
GSList * toggles = g_object_get_data( G_OBJECT(
|
|
|
|
toggle ),
|
|
|
|
FILTER_TOGGLES_KEY );
|
|
|
|
const gboolean isActive = gtk_toggle_button_get_active( toggle );
|
|
|
|
const filter_mode_t mode =
|
|
|
|
GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( toggle ),
|
|
|
|
FILTER_MODE_KEY ) );
|
2007-12-24 00:14:39 +00:00
|
|
|
|
|
|
|
/* update the filter */
|
2008-09-23 19:11:04 +00:00
|
|
|
if( isActive )
|
|
|
|
{
|
2007-12-24 00:14:39 +00:00
|
|
|
p->filter_mode = mode;
|
|
|
|
refilter( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deactivate the other toggles */
|
2008-09-23 19:11:04 +00:00
|
|
|
for( l = toggles; l != NULL; l = l->next )
|
|
|
|
{
|
2007-12-24 00:14:39 +00:00
|
|
|
GtkToggleButton * walk = GTK_TOGGLE_BUTTON( l->data );
|
|
|
|
if( isActive && ( toggle != walk ) )
|
|
|
|
gtk_toggle_button_set_active( walk, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* at least one button must always be set */
|
|
|
|
if( !isActive && ( p->filter_mode == mode ) )
|
|
|
|
gtk_toggle_button_set_active( toggle, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
filter_entry_changed( GtkEditable * e,
|
|
|
|
gpointer vprivate )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
char * pch;
|
2008-02-24 14:32:42 +00:00
|
|
|
PrivateData * p = vprivate;
|
2008-01-06 17:36:48 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
pch = gtk_editable_get_chars( e, 0, -1 );
|
2008-01-06 17:36:48 +00:00
|
|
|
g_free( p->filter_text );
|
2007-12-24 00:14:39 +00:00
|
|
|
p->filter_text = g_ascii_strdown( pch, -1 );
|
|
|
|
refilter( p );
|
|
|
|
g_free( pch );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
entry_icon_released( SexyIconEntry * entry UNUSED,
|
|
|
|
SexyIconEntryPosition icon_pos,
|
2007-12-24 00:14:39 +00:00
|
|
|
int button UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
gpointer menu )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
if( icon_pos == SEXY_ICON_ENTRY_PRIMARY )
|
|
|
|
gtk_menu_popup ( GTK_MENU(
|
|
|
|
menu ), NULL, NULL, NULL, NULL, 0,
|
|
|
|
gtk_get_current_event_time( ) );
|
2007-12-24 00:14:39 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
|
|
|
|
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
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
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
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/***
|
|
|
|
**** PUBLIC
|
|
|
|
***/
|
|
|
|
|
|
|
|
GtkWidget *
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_window_new( GtkUIManager * ui_manager,
|
|
|
|
TrCore * core )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int i, n;
|
|
|
|
const char * pch;
|
2008-02-09 17:49:09 +00:00
|
|
|
PrivateData * p;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * vbox, *w, *self, *h, *c, *s, *image, *menu;
|
|
|
|
GtkWindow * win;
|
|
|
|
GSList * l;
|
|
|
|
GSList * toggles;
|
|
|
|
const char * filter_names[FILTER_MODE_QTY] = {
|
2008-03-08 01:43:20 +00:00
|
|
|
/* show all torrents */
|
2008-09-23 19:11:04 +00:00
|
|
|
N_( "A_ll" ),
|
2008-03-08 01:43:20 +00:00
|
|
|
/* show only torrents that have connected peers */
|
2008-09-23 19:11:04 +00:00
|
|
|
N_( "_Active" ),
|
2008-03-08 01:43:20 +00:00
|
|
|
/* show only torrents that are trying to download */
|
2008-09-23 19:11:04 +00:00
|
|
|
N_( "_Downloading" ),
|
2008-03-08 01:43:20 +00:00
|
|
|
/* show only torrents that are trying to upload */
|
2008-09-23 19:11:04 +00:00
|
|
|
N_( "_Seeding" ),
|
2008-03-08 01:43:20 +00:00
|
|
|
/* show only torrents that are paused */
|
2008-09-23 19:11:04 +00:00
|
|
|
N_( "_Paused" )
|
2007-12-24 00:14:39 +00:00
|
|
|
};
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * filter_text_names[FILTER_TEXT_MODE_QTY] = {
|
|
|
|
N_( "Name" ), N_( "Files" ), N_( "Tracker" )
|
2007-12-24 00:14:39 +00:00
|
|
|
};
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2008-02-09 17:49:09 +00:00
|
|
|
p = g_new0( PrivateData, 1 );
|
2007-12-24 17:25:52 +00:00
|
|
|
p->filter_mode = FILTER_MODE_ALL;
|
|
|
|
p->filter_text_mode = FILTER_TEXT_MODE_NAME;
|
|
|
|
p->filter_text = NULL;
|
|
|
|
|
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 );
|
|
|
|
g_object_set_data_full( G_OBJECT(
|
|
|
|
self ), 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,
|
|
|
|
pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ),
|
|
|
|
pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) );
|
2008-04-21 20:58:39 +00:00
|
|
|
gtk_window_move( win, pref_int_get( PREF_KEY_MAIN_WINDOW_X ),
|
2008-09-23 19:11:04 +00:00
|
|
|
pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
|
|
|
|
gtk_window_add_accel_group( win,
|
|
|
|
gtk_ui_manager_get_accel_group( ui_manager ) );
|
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 */
|
|
|
|
w = action_get_widget( "/main-window-menu" );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
2008-02-09 17:49:09 +00:00
|
|
|
w = 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 */
|
2007-12-20 02:56:47 +00:00
|
|
|
w = p->toolbar = action_get_widget( "/main-window-toolbar" );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-01-17 18:03:45 +00:00
|
|
|
/* filter */
|
|
|
|
toggles = NULL;
|
|
|
|
h = p->filter = gtk_hbox_new( FALSE, 0 );
|
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < FILTER_MODE_QTY; ++i )
|
|
|
|
{
|
2008-01-17 18:03:45 +00:00
|
|
|
const char * mnemonic = _( filter_names[i] );
|
|
|
|
w = gtk_toggle_button_new_with_mnemonic( mnemonic );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_object_set_data( G_OBJECT( w ), FILTER_MODE_KEY,
|
|
|
|
GINT_TO_POINTER( i ) );
|
2008-01-17 18:03:45 +00:00
|
|
|
gtk_button_set_relief( GTK_BUTTON( w ), GTK_RELIEF_NONE );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(
|
|
|
|
w ), i == FILTER_MODE_ALL );
|
2008-01-17 18:03:45 +00:00
|
|
|
toggles = g_slist_prepend( toggles, w );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK( filter_toggled_cb ), p );
|
|
|
|
gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-17 18:03:45 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
for( l = toggles; l != NULL; l = l->next )
|
2008-01-17 18:03:45 +00:00
|
|
|
g_object_set_data( G_OBJECT( l->data ), FILTER_TOGGLES_KEY, toggles );
|
|
|
|
s = sexy_icon_entry_new( );
|
2008-09-23 19:11:04 +00:00
|
|
|
sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY( s ) );
|
2008-01-17 18:03:45 +00:00
|
|
|
image = gtk_image_new_from_stock( GTK_STOCK_FIND, GTK_ICON_SIZE_MENU );
|
2008-09-23 19:11:04 +00:00
|
|
|
sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(
|
|
|
|
s ), SEXY_ICON_ENTRY_PRIMARY,
|
|
|
|
GTK_IMAGE( image ) );
|
|
|
|
sexy_icon_entry_set_icon_highlight( SEXY_ICON_ENTRY(
|
|
|
|
s ), SEXY_ICON_ENTRY_PRIMARY,
|
|
|
|
TRUE );
|
2008-01-17 18:03:45 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), s, FALSE, FALSE, 0 );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), h, FALSE, FALSE, 0 );
|
2008-01-17 18:03:45 +00:00
|
|
|
g_signal_connect( s, "changed", G_CALLBACK( filter_entry_changed ), p );
|
|
|
|
|
|
|
|
w = gtk_hseparator_new( );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
2008-01-17 18:03:45 +00:00
|
|
|
|
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;
|
2008-03-19 19:30:03 +00:00
|
|
|
pch = 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 */
|
2007-12-20 02:56:47 +00:00
|
|
|
h = p->status = gtk_hbox_new( FALSE, GUI_PAD );
|
2008-01-17 18:03:45 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD );
|
2008-03-07 20:48:36 +00:00
|
|
|
w = p->gutter_lb = gtk_label_new( "N Torrents" );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 );
|
2007-12-20 02:56:47 +00:00
|
|
|
w = p->ul_lb = gtk_label_new( NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-20 01:18:11 +00:00
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2007-12-20 02:56:47 +00:00
|
|
|
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request( w, GUI_PAD, 0u );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2007-12-20 02:56:47 +00:00
|
|
|
w = p->dl_lb = gtk_label_new( NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-20 01:18:11 +00:00
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-17 18:03:45 +00:00
|
|
|
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request( w, GUI_PAD, 0u );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-17 18:03:45 +00:00
|
|
|
w = p->stats_lb = gtk_label_new( NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
2008-01-20 01:18:11 +00:00
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU );
|
2007-12-20 19:21:21 +00:00
|
|
|
c = gtk_event_box_new( );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( c ), w );
|
2007-12-20 19:21:21 +00:00
|
|
|
w = c;
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 );
|
|
|
|
g_signal_connect( w, "button-release-event",
|
|
|
|
G_CALLBACK( onYinYangReleased ), p );
|
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), h, FALSE, FALSE, 0 );
|
2007-12-20 02:56:47 +00:00
|
|
|
|
2007-12-24 00:14:39 +00:00
|
|
|
menu = gtk_menu_new( );
|
|
|
|
l = NULL;
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < FILTER_TEXT_MODE_QTY; ++i )
|
2007-12-24 00:14:39 +00:00
|
|
|
{
|
|
|
|
const char * name = _( filter_text_names[i] );
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * w = gtk_radio_menu_item_new_with_label ( l, name );
|
2007-12-24 00:14:39 +00:00
|
|
|
l = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM( w ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_object_set_data( G_OBJECT(
|
|
|
|
w ), FILTER_TEXT_MODE_KEY, GINT_TO_POINTER( i ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(
|
|
|
|
filter_text_toggled_cb ), p );
|
2007-12-24 00:14:39 +00:00
|
|
|
gtk_menu_shell_append( GTK_MENU_SHELL( menu ), w );
|
|
|
|
gtk_widget_show( w );
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( s, "icon-released", G_CALLBACK(
|
|
|
|
entry_icon_released ), menu );
|
2007-12-24 00:14:39 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/* workarea */
|
2007-12-24 00:14:39 +00:00
|
|
|
p->view = makeview( p, core );
|
2007-06-18 03:40:41 +00:00
|
|
|
w = p->scroll = gtk_scrolled_window_new( NULL, NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(
|
|
|
|
w ), GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC );
|
|
|
|
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(
|
|
|
|
w ), GTK_SHADOW_IN );
|
|
|
|
gtk_container_add( GTK_CONTAINER( w ), p->view );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( vbox ), w, TRUE, TRUE, 0 );
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_container_set_focus_child( GTK_CONTAINER( vbox ), w );
|
|
|
|
|
|
|
|
/* 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;
|
2007-12-19 19:16:36 +00:00
|
|
|
prefsChanged( core, PREF_KEY_MINIMAL_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 );
|
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
|
|
|
|
2008-01-06 17:36:48 +00:00
|
|
|
filter_entry_changed( GTK_EDITABLE( s ), p );
|
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 )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
char buf[128];
|
|
|
|
const int torrentCount = gtk_tree_model_iter_n_children(
|
|
|
|
tr_core_model( p->core ), NULL );
|
|
|
|
const int visibleCount = gtk_tree_model_iter_n_children(
|
|
|
|
p->filter_model, NULL );
|
2007-12-24 17:25:52 +00:00
|
|
|
|
|
|
|
if( torrentCount != visibleCount )
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ),
|
|
|
|
ngettext( "%1$'d of %2$'d Torrent",
|
|
|
|
"%1$'d of %2$'d Torrents",
|
|
|
|
torrentCount ),
|
|
|
|
visibleCount, torrentCount );
|
2007-12-24 17:25:52 +00:00
|
|
|
else
|
2008-03-19 20:07:27 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), ngettext( "%'d Torrent",
|
|
|
|
"%'d Torrents",
|
2007-12-24 17:25:52 +00:00
|
|
|
torrentCount ),
|
2008-09-23 19:11:04 +00:00
|
|
|
torrentCount );
|
2007-12-24 17:25:52 +00:00
|
|
|
gtk_label_set_text( GTK_LABEL( p->gutter_lb ), buf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-24 19:12:52 +00:00
|
|
|
static void
|
|
|
|
updateStats( PrivateData * p )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * pch;
|
|
|
|
char up[32], down[32], ratio[32], buf[128];
|
2007-12-24 19:12:52 +00:00
|
|
|
struct tr_session_stats stats;
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_session * session = tr_core_session( p->core );
|
2007-12-24 19:12:52 +00:00
|
|
|
|
|
|
|
/* update the stats */
|
2008-03-19 19:30:03 +00:00
|
|
|
pch = 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 ) );
|
2008-03-08 01:43:20 +00:00
|
|
|
/* Translators: do not translate the "size|" disambiguation prefix.
|
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 ) );
|
2008-03-08 01:43:20 +00:00
|
|
|
/* Translators: do not translate the "size|" disambiguation prefix.
|
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
|
|
|
}
|
|
|
|
gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateSpeeds( PrivateData * p )
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
tr_session * session = tr_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];
|
|
|
|
double d;
|
|
|
|
|
|
|
|
d = tr_sessionGetPieceSpeed( session, TR_DOWN );
|
|
|
|
tr_strlspeed( buf, d, sizeof( buf ) );
|
|
|
|
gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
|
|
|
|
|
|
|
|
d = tr_sessionGetPieceSpeed( session, TR_UP );
|
|
|
|
tr_strlspeed( buf, d, sizeof( buf ) );
|
|
|
|
gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
|
|
|
|
}
|
2007-12-24 19:12:52 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
void
|
2007-12-20 19:21:21 +00:00
|
|
|
tr_window_update( 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
|
|
|
|
2008-10-28 19:49:33 +00:00
|
|
|
if( p && p->core && tr_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 );
|
|
|
|
refilter( 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*
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_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
|
|
|
|