misc cleanup. fix vertical alignment of the short status string in minimal view.

This commit is contained in:
Charles Kerr 2007-12-20 01:33:51 +00:00
parent 29634d7379
commit 69e1e025b2
4 changed files with 88 additions and 105 deletions

View File

@ -99,7 +99,7 @@ toggle_pref_cb ( GtkToggleAction * action, gpointer user_data UNUSED )
static GtkToggleActionEntry pref_toggle_entries[] =
{
{ "minimal-view", NULL,
N_("_Minimal View"), "<control>M", NULL, G_CALLBACK(toggle_pref_cb), FALSE },
N_("_Minimal View"), "<alt>M", NULL, G_CALLBACK(toggle_pref_cb), FALSE },
{ "sort-reversed", NULL,
N_("_Reverse Sort Order"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }
};
@ -112,7 +112,8 @@ static GtkActionEntry entries[] =
{ "edit-menu", NULL, N_("_Edit"), NULL, NULL, NULL },
{ "help-menu", NULL, N_("_Help"), NULL, NULL, NULL },
{ "priority-menu", NULL, N_("_Priority"), NULL, NULL, NULL },
{ "add-torrent", GTK_STOCK_OPEN, NULL, NULL, N_("Open Torrent"), G_CALLBACK(action_cb) },
{ "add-torrent", GTK_STOCK_OPEN,
NULL, NULL, N_("Open Torrent"), G_CALLBACK(action_cb) },
{ "start-torrent", GTK_STOCK_MEDIA_PLAY,
N_("_Start"), "<control>S", NULL, G_CALLBACK(action_cb) },
{ "show-stats", NULL, N_("_Statistics"), NULL, NULL, G_CALLBACK(action_cb) },
@ -164,7 +165,6 @@ typedef struct
}
BuiltinIconInfo;
/* only one icon now... but room to grow ;) */
const BuiltinIconInfo my_builtin_icons [] =
{
{ tr_icon_logo, "transmission-logo" },
@ -255,7 +255,8 @@ actions_init( GtkUIManager * ui_manager, gpointer callback_user_data )
callback_user_data );
for( i=0, n=G_N_ELEMENTS(pref_toggle_entries); i<n; ++i )
pref_toggle_entries[i].is_active = pref_flag_get( pref_toggle_entries[i].name );
pref_toggle_entries[i].is_active =
pref_flag_get( pref_toggle_entries[i].name );
gtk_action_group_add_toggle_actions( action_group,
pref_toggle_entries,

View File

@ -65,13 +65,12 @@ enum
***/
static char*
getProgressString( const tr_torrent * tor, const tr_stat * torStat )
getProgressString( const tr_info * info, const tr_stat * torStat )
{
const int allDownloaded = torStat->leftUntilDone == 0;
const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid;
const tr_info * info = tr_torrentInfo( tor );
const int isSeed = torStat->haveValid >= info->totalSize;
char buf1[128], buf2[128], buf3[128];
char buf1[32], buf2[32], buf3[32];
char * str;
if( !allDownloaded )
@ -101,7 +100,7 @@ getProgressString( const tr_torrent * tor, const tr_stat * torStat )
static char*
getShortStatusString( const tr_stat * torStat )
{
char upStr[64], downStr[64];
char upStr[32], downStr[32];
GString * gstr = g_string_new( NULL );
switch( torStat->status )
@ -118,18 +117,20 @@ getShortStatusString( const tr_stat * torStat )
g_string_append_printf( gstr, _("Verifying local data (%.1f%% tested)"),
torStat->recheckProgress * 100.0 );
case TR_STATUS_DOWNLOAD:
tr_strlspeed( downStr, torStat->rateDownload, sizeof(downStr) ),
case TR_STATUS_DOWNLOAD: {
tr_strlspeed( downStr, torStat->rateDownload, sizeof(downStr) );
tr_strlspeed( upStr, torStat->rateUpload, sizeof(upStr) );
g_string_append_printf( gstr, _("DL: %s, UL: %s"), downStr, upStr );
g_string_append_printf( gstr, _("Down: %s, Up: %s"), downStr, upStr );
break;
}
case TR_STATUS_SEED:
case TR_STATUS_DONE:
case TR_STATUS_DONE: {
tr_strlspeed( upStr, torStat->rateUpload, sizeof(upStr) );
g_string_append_printf( gstr, _("Ratio: %.1f, UL: %s"),
g_string_append_printf( gstr, _("Ratio: %.1f, Up: %s"),
torStat->ratio*100.0, upStr );
break;
}
default:
break;
@ -187,11 +188,11 @@ getStatusString( const tr_stat * torStat )
char ulbuf[64], dlbuf[64];
if (torStat->status == TR_STATUS_DOWNLOAD)
g_string_append_printf( gstr, _(" - DL: %s, UL: %s" ),
g_string_append_printf( gstr, _(" - Down: %s, Up: %s" ),
tr_strlspeed( dlbuf, torStat->rateDownload, sizeof(dlbuf) ),
tr_strlspeed( ulbuf, torStat->rateUpload, sizeof(ulbuf) ) );
else
g_string_append_printf( gstr, _(" - UL: %s" ),
g_string_append_printf( gstr, _(" - Up: %s" ),
tr_strlspeed( ulbuf, torStat->rateUpload, sizeof(ulbuf) ) );
}
@ -214,10 +215,10 @@ struct TorrentCellRendererPrivate
gboolean gradient;
GdkColor color_paused[2];
GdkColor color_verified[2];
GdkColor color_verifying[2];
GdkColor color_missing[2];
GdkColor color_unwanted[2];
GdkColor color_unavailable[2];
GdkColor color_verifying[2];
GdkColor color_seeding[2];
};
@ -241,7 +242,6 @@ torrent_cell_renderer_get_size( GtkCellRenderer * cell,
const char * name = info->name;
const tr_stat * torStat = tr_torrentStat( (tr_torrent*)tor );
char * str;
int tmp_w, tmp_h;
int w=0, h=0;
struct TorrentCellRendererPrivate * p = self->priv;
@ -251,29 +251,30 @@ torrent_cell_renderer_get_size( GtkCellRenderer * cell,
if( p->minimal )
{
int w1, w2, h1, h2;
char * shortStatusString = getShortStatusString( torStat );
char * shortStatus = getShortStatusString( torStat );
g_object_set( p->text_renderer, "text", name, NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &w1, &h1 );
str = g_markup_printf_escaped( "<small>%s</small>", shortStatusString );
str = g_markup_printf_escaped( "<small>%s</small>", shortStatus );
g_object_set( p->text_renderer, "markup", str, NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &w2, &h2 );
h += MAX( h1, h2 );
w = MAX( w, w1+GUI_PAD_BIG+w2 );
g_free( str );
g_free( shortStatusString );
g_free( shortStatus );
}
else
{
char * progressString = getProgressString( tor, torStat );
int w1, h1;
char * progressString = getProgressString( info, torStat );
str = g_markup_printf_escaped( "<b>%s</b>\n<small>%s</small>",
name, progressString );
g_object_set( p->text_renderer, "markup", str, NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &tmp_w, &tmp_h );
h += tmp_h;
w = MAX( w, tmp_w );
widget, NULL, NULL, NULL, &w1, &h1 );
h += h1;
w = MAX( w, w1 );
g_free( str );
g_free( progressString );
}
@ -281,13 +282,14 @@ torrent_cell_renderer_get_size( GtkCellRenderer * cell,
/* below the progressbar */
if( !p->minimal )
{
int w1, h1;
char * statusString = getStatusString( torStat );
str = g_markup_printf_escaped( "<small>%s</small>", statusString );
g_object_set( p->text_renderer, "markup", str, NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &tmp_w, &tmp_h );
h += tmp_h;
w = MAX( w, tmp_w );
widget, NULL, NULL, NULL, &w1, &h1 );
h += h1;
w = MAX( w, w1 );
g_free( str );
g_free( statusString );
}
@ -361,8 +363,10 @@ drawRegularBar( TorrentCellRenderer * self,
#if 1
const double verified = torStat->haveValid / (double)info->totalSize;
const double unverified = torStat->haveUnchecked / (double)info->totalSize;
const double unavailable = ( torStat->desiredSize - torStat->desiredAvailable ) / (double)info->totalSize;
const double unwanted = ( info->totalSize - torStat->desiredSize ) / (double)info->totalSize;
const double unavailable = ( torStat->desiredSize
- torStat->desiredAvailable ) / (double)info->totalSize;
const double unwanted = ( info->totalSize
- torStat->desiredSize ) / (double)info->totalSize;
#else /* for testing */
const double verified = 0.5;
const double unverified = 0.1;
@ -436,7 +440,7 @@ drawRegularBar( TorrentCellRenderer * self,
if( isChecking ) {
const int checkedWidth = torStat->recheckProgress * area->width;
int h2 = area->height / 2;
const int h2 = area->height / 2;
rect = *area;
rect.y += h2;
rect.height -= h2;
@ -462,8 +466,8 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
GdkDrawable * window,
GtkWidget * widget,
GdkRectangle * background_area,
GdkRectangle * cell_area,
GdkRectangle * expose_area,
GdkRectangle * cell_area UNUSED,
GdkRectangle * expose_area UNUSED,
GtkCellRendererState flags)
{
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
@ -473,7 +477,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
const tr_info * info = tr_torrentInfo( tor );
const char * name = info->name;
const tr_stat * torStat = tr_torrentStat( (tr_torrent*)tor );
char * progressString = getProgressString( tor, torStat );
char * progressString = getProgressString( info, torStat );
char * statusString = getStatusString( torStat );
char * str;
GdkRectangle my_bg;
@ -488,14 +492,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
my_bg.x += xpad;
my_bg.y += ypad;
my_bg.width -= xpad*2;
my_cell = *cell_area;
my_cell.x += xpad;
my_cell.y += ypad;
my_cell.width -= xpad*2;
my_expose = *expose_area;
my_expose.x += xpad;
my_expose.y += ypad;
my_expose.width -= xpad*2;
my_cell = my_expose = my_bg;
/* above the progressbar */
if( !p->minimal )
@ -507,8 +504,8 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &w, &h );
my_bg.height = h;
my_cell.height = h;
my_bg.height =
my_cell.height =
my_expose.height = h;
g_object_set( p->text_renderer, "ellipsize", PANGO_ELLIPSIZE_END,
NULL );
@ -522,7 +519,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
else
{
int w1, w2, h1, h2, tmp_h;
char * shortStatusString = getShortStatusString( torStat );
char * shortStatus = getShortStatusString( torStat );
GdkRectangle tmp_bg, tmp_cell, tmp_expose;
/* get the dimensions for the name */
@ -533,7 +530,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
widget, NULL, NULL, NULL, &w1, &h1 );
/* get the dimensions for the short status string */
str = g_markup_printf_escaped( "<small>%s</small>", shortStatusString );
str = g_markup_printf_escaped( "<small>%s</small>", shortStatus );
g_object_set( p->text_renderer, "markup", str,
"ellipsize", PANGO_ELLIPSIZE_NONE,
NULL );
@ -544,7 +541,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
/* short status */
tmp_bg.x = my_bg.width - w2;
tmp_bg.y = my_bg.y;
tmp_bg.y = my_bg.y + (h2-h1)/2;
tmp_bg.width = w2;
tmp_bg.height = tmp_h;
tmp_expose = tmp_cell = tmp_bg;
@ -567,7 +564,7 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
&tmp_bg, &tmp_cell, &tmp_expose, flags );
g_free( str );
g_free( shortStatusString );
g_free( shortStatus );
my_bg.y = tmp_bg.y + tmp_bg.height;
my_cell.y = tmp_cell.y + tmp_cell.height;
@ -590,8 +587,8 @@ torrent_cell_renderer_render( GtkCellRenderer * cell,
NULL );
gtk_cell_renderer_get_size( p->text_renderer,
widget, NULL, NULL, NULL, &w, &h );
my_bg.height = h;
my_cell.height = h;
my_bg.height =
my_cell.height =
my_expose.height = h;
gtk_cell_renderer_render( p->text_renderer,
window, widget,
@ -694,14 +691,15 @@ static void
torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
{
GObjectClass * gobject_class = G_OBJECT_CLASS( klass );
GtkCellRendererClass * cell_renderer_class = GTK_CELL_RENDERER_CLASS( klass );
GtkCellRendererClass * cell_class = GTK_CELL_RENDERER_CLASS( klass );
g_type_class_add_private( klass, sizeof(struct TorrentCellRendererPrivate) );
g_type_class_add_private( klass,
sizeof(struct TorrentCellRendererPrivate) );
parent_class = (GtkCellRendererClass*) g_type_class_peek_parent( klass );
cell_renderer_class->render = torrent_cell_renderer_render;
cell_renderer_class->get_size = torrent_cell_renderer_get_size;
cell_class->render = torrent_cell_renderer_render;
cell_class->get_size = torrent_cell_renderer_get_size;
gobject_class->set_property = torrent_cell_renderer_set_property;
gobject_class->get_property = torrent_cell_renderer_get_property;

View File

@ -282,46 +282,32 @@ static void
setSort( TrCore * core, const char * mode, gboolean isReversed )
{
int col = MC_TORRENT_RAW;
GtkSortType type;
GtkSortType type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
GtkTreeSortable * sortable = GTK_TREE_SORTABLE( core->model );
if( !strcmp( mode, "sort-by-activity" ) )
{
type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByActivity, NULL, NULL );
}
else if( !strcmp( mode, "sort-by-date-added" ) )
{
type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByDateAdded, NULL, NULL );
}
else if( !strcmp( mode, "sort-by-progress" ) )
{
type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByProgress, NULL, NULL );
}
else if( !strcmp( mode, "sort-by-state" ) )
{
type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByState, NULL, NULL );
}
else if( !strcmp( mode, "sort-by-tracker" ) )
{
type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByTracker, NULL, NULL );
}
else
{
else {
type = isReversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
gtk_tree_sortable_set_sort_func( sortable, col, compareByName, NULL, NULL );
}
gtk_tree_sortable_set_sort_column_id( sortable, col, type );
}
static void
prefsChanged( TrCore * core, const char * key, gpointer data UNUSED )
{
if( !strcmp( key, PREF_KEY_SORT_MODE ) || !strcmp( key, PREF_KEY_SORT_REVERSED ) )
if( !strcmp( key, PREF_KEY_SORT_MODE )
|| !strcmp( key, PREF_KEY_SORT_REVERSED ) )
{
char * mode = pref_string_get( PREF_KEY_SORT_MODE );
gboolean isReversed = pref_flag_get( PREF_KEY_SORT_REVERSED );
@ -347,10 +333,6 @@ tr_core_init( GTypeInstance * instance, gpointer g_class SHUTUP )
G_TYPE_INT /* ID for IPC */
};
#ifdef REFDBG
fprintf( stderr, "core %p init\n", self );
#endif
/* create the model used to store torrent data */
g_assert( ALEN( types ) == MC_ROW_COUNT );
store = gtk_list_store_newv( MC_ROW_COUNT, types );
@ -367,7 +349,7 @@ tr_core_get_type( void )
{
static GType type = 0;
if( 0 == type )
if( !type )
{
static const GTypeInfo info =
{

View File

@ -123,7 +123,8 @@ makeview( PrivateData * p )
g_signal_connect( view, "popup-menu",
G_CALLBACK(on_popup_menu), NULL );
g_signal_connect( view, "button-press-event",
G_CALLBACK(on_tree_view_button_pressed), (void *) on_popup_menu);
G_CALLBACK(on_tree_view_button_pressed),
(void *) on_popup_menu);
g_signal_connect( view, "row-activated",
G_CALLBACK(view_row_activated), NULL);
@ -218,7 +219,8 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
/* listen for prefs changes that affect the window */
prefsChanged( core, PREF_KEY_MINIMAL_VIEW, self );
p->core = core;
p->pref_handler_id = g_signal_connect( core, "prefs-changed", G_CALLBACK(prefsChanged), self );
p->pref_handler_id = g_signal_connect( core, "prefs-changed",
G_CALLBACK(prefsChanged), self );
return self;
}
@ -227,8 +229,8 @@ void
tr_window_update( TrWindow * self, float downspeed, float upspeed )
{
PrivateData * p = get_private_data( self );
char speedStr[64];
char buf[128];
char speedStr[32];
char buf[64];
tr_strlspeed( speedStr, downspeed, sizeof(speedStr) );
g_snprintf( buf, sizeof(buf), _("Total DL: %s"), speedStr );