2007-12-19 02:46:30 +00:00
|
|
|
/*
|
2008-01-01 17:20:20 +00:00
|
|
|
* This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
|
2007-12-19 02:46:30 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
2008-03-06 21:59:00 +00:00
|
|
|
* $Id$
|
2007-12-19 02:46:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "assert.h"
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gtk/gtkcellrenderertext.h>
|
2008-02-23 17:02:42 +00:00
|
|
|
#include <gtk/gtkcellrendererprogress.h>
|
2007-12-19 02:46:30 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <libtransmission/transmission.h>
|
2007-12-19 18:11:10 +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-torrent.h"
|
2007-12-19 02:46:30 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2008-02-16 19:36:07 +00:00
|
|
|
/* #define TEST_RTL */
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
P_TORRENT = 1,
|
|
|
|
P_BAR_HEIGHT,
|
2008-02-24 19:36:48 +00:00
|
|
|
P_MINIMAL
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_BAR_HEIGHT 12
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static char*
|
2007-12-20 01:33:51 +00:00
|
|
|
getProgressString( const tr_info * info, const tr_stat * torStat )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
const int isDone = torStat->leftUntilDone == 0;
|
2007-12-19 02:46:30 +00:00
|
|
|
const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid;
|
|
|
|
const int isSeed = torStat->haveValid >= info->totalSize;
|
2008-01-04 18:52:39 +00:00
|
|
|
char buf1[32], buf2[32], buf3[32], buf4[32];
|
2007-12-19 02:46:30 +00:00
|
|
|
char * str;
|
|
|
|
|
2007-12-20 15:16:14 +00:00
|
|
|
if( !isDone )
|
2007-12-19 02:46:30 +00:00
|
|
|
str = g_strdup_printf(
|
2008-03-08 01:43:20 +00:00
|
|
|
/* %1$s is how much we've got,
|
2008-03-08 04:53:11 +00:00
|
|
|
%2$s is how much we'll have when done,
|
|
|
|
%3$.2f%% is a percentage of the two */
|
2008-03-07 21:59:27 +00:00
|
|
|
_("%1$s of %2$s (%3$.2f%%)"),
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( buf1, haveTotal, sizeof(buf1) ),
|
2008-04-11 23:05:14 +00:00
|
|
|
tr_strlsize( buf2, torStat->sizeWhenDone, sizeof(buf2) ),
|
2007-12-19 02:46:30 +00:00
|
|
|
torStat->percentDone * 100.0 );
|
|
|
|
else if( !isSeed )
|
|
|
|
str = g_strdup_printf(
|
2008-03-08 01:43:20 +00:00
|
|
|
/* %1$s is how much we've got,
|
2008-03-08 04:53:11 +00:00
|
|
|
%2$s is the torrent's total size,
|
|
|
|
%3$.2f%% is a percentage of the two,
|
|
|
|
%4$s is how much we've uploaded,
|
|
|
|
%5$s is our upload-to-download ratio */
|
2008-03-07 21:59:27 +00:00
|
|
|
_("%1$s of %2$s (%3$.2f%%), uploaded %4$s (Ratio: %5$s)"),
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( buf1, haveTotal, sizeof(buf1) ),
|
|
|
|
tr_strlsize( buf2, info->totalSize, sizeof(buf2) ),
|
|
|
|
torStat->percentComplete * 100.0,
|
|
|
|
tr_strlsize( buf3, torStat->uploadedEver, sizeof(buf3) ),
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( buf4, torStat->ratio, sizeof( buf4 ) ) );
|
2007-12-19 02:46:30 +00:00
|
|
|
else
|
|
|
|
str = g_strdup_printf(
|
2008-03-08 01:43:20 +00:00
|
|
|
/* %1$s is the torrent's total size,
|
2008-03-08 04:53:11 +00:00
|
|
|
%2$s is how much we've uploaded,
|
|
|
|
%3$s is our upload-to-download ratio */
|
2008-03-07 21:59:27 +00:00
|
|
|
_("%1$s, uploaded %2$s (Ratio: %3$s)"),
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( buf1, info->totalSize, sizeof(buf1) ),
|
|
|
|
tr_strlsize( buf2, torStat->uploadedEver, sizeof(buf2) ),
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
/* add time when downloading */
|
2008-02-09 16:05:29 +00:00
|
|
|
if( torStat->status == TR_STATUS_DOWNLOAD )
|
|
|
|
{
|
|
|
|
const int eta = torStat->eta;
|
|
|
|
GString * gstr = g_string_new( str );
|
|
|
|
g_string_append( gstr, " - " );
|
2008-04-06 14:42:47 +00:00
|
|
|
if( eta == TR_ETA_NOT_AVAIL )
|
|
|
|
g_string_append( gstr, _( "Not available" ) );
|
|
|
|
else if( eta == TR_ETA_UNKNOWN )
|
2008-02-09 16:05:29 +00:00
|
|
|
g_string_append( gstr, _( "Stalled" ) );
|
|
|
|
else {
|
|
|
|
char timestr[128];
|
|
|
|
tr_strltime( timestr, eta, sizeof( timestr ) );
|
2008-03-08 04:53:11 +00:00
|
|
|
/* time remaining */
|
2008-02-09 16:05:29 +00:00
|
|
|
g_string_append_printf( gstr, _( "%s remaining" ), timestr );
|
|
|
|
}
|
|
|
|
g_free( str );
|
|
|
|
str = g_string_free( gstr, FALSE );
|
|
|
|
}
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2007-12-20 02:02:51 +00:00
|
|
|
getShortTransferString( const tr_stat * torStat, char * buf, size_t buflen )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
char downStr[32], upStr[32];
|
2008-02-13 16:16:50 +00:00
|
|
|
const int haveDown = torStat->peersSendingToUs > 0;
|
|
|
|
const int haveUp = torStat->peersGettingFromUs > 0;
|
2007-12-20 02:02:51 +00:00
|
|
|
|
|
|
|
if( haveDown )
|
|
|
|
tr_strlspeed( downStr, torStat->rateDownload, sizeof(downStr) );
|
|
|
|
if( haveUp )
|
|
|
|
tr_strlspeed( upStr, torStat->rateUpload, sizeof(upStr) );
|
|
|
|
|
|
|
|
if( haveDown && haveUp )
|
2008-03-08 01:43:20 +00:00
|
|
|
/* Translators: do not translate the "speed|" disambiguation prefix.
|
2008-03-08 04:53:11 +00:00
|
|
|
%1$s is the download speed
|
|
|
|
%2$s is the upload speed */
|
2008-03-08 01:43:20 +00:00
|
|
|
g_snprintf( buf, buflen, Q_( "speed|Down: %1$s, Up: %2$s"), downStr, upStr );
|
2007-12-20 02:02:51 +00:00
|
|
|
else if( haveDown )
|
2008-03-08 04:53:11 +00:00
|
|
|
/* download speed */
|
2007-12-20 02:02:51 +00:00
|
|
|
g_snprintf( buf, buflen, _( "Down: %s" ), downStr );
|
|
|
|
else if( haveUp )
|
2008-03-08 04:53:11 +00:00
|
|
|
/* upload speed */
|
2007-12-20 02:02:51 +00:00
|
|
|
g_snprintf( buf, buflen, _( "Up: %s" ), upStr );
|
|
|
|
else
|
2008-03-08 04:53:11 +00:00
|
|
|
/* the torrent isn't uploading or downloading */
|
2007-12-20 02:02:51 +00:00
|
|
|
g_strlcpy( buf, _( "Idle" ), buflen );
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
getShortStatusString( const tr_stat * torStat )
|
|
|
|
{
|
2007-12-19 18:11:10 +00:00
|
|
|
GString * gstr = g_string_new( NULL );
|
|
|
|
|
|
|
|
switch( torStat->status )
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
g_string_assign( gstr, _("Paused") );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
2008-03-06 21:59:00 +00:00
|
|
|
g_string_assign( gstr, _( "Waiting to verify local data" ) );
|
2007-12-19 18:11:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
g_string_append_printf( gstr, _("Verifying local data (%.1f%% tested)"),
|
|
|
|
torStat->recheckProgress * 100.0 );
|
2008-02-14 00:59:32 +00:00
|
|
|
break;
|
2007-12-19 18:11:10 +00:00
|
|
|
|
2007-12-20 02:02:51 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
2008-03-31 17:59:16 +00:00
|
|
|
case TR_STATUS_SEED: {
|
2007-12-20 02:02:51 +00:00
|
|
|
char buf[128];
|
2008-01-04 18:52:39 +00:00
|
|
|
if( torStat->status != TR_STATUS_DOWNLOAD ) {
|
|
|
|
tr_strlratio( buf, torStat->ratio, sizeof( buf ) );
|
2008-03-07 21:59:27 +00:00
|
|
|
g_string_append_printf( gstr, _("Ratio: %s" ), buf );
|
|
|
|
g_string_append( gstr, ", " );
|
2008-01-04 18:52:39 +00:00
|
|
|
}
|
2007-12-20 15:16:14 +00:00
|
|
|
getShortTransferString( torStat, buf, sizeof( buf ) );
|
|
|
|
g_string_append( gstr, buf );
|
2007-12-19 18:11:10 +00:00
|
|
|
break;
|
2007-12-20 01:33:51 +00:00
|
|
|
}
|
2007-12-19 18:11:10 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free( gstr, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
getStatusString( const tr_stat * torStat )
|
|
|
|
{
|
2007-12-19 02:46:30 +00:00
|
|
|
const int isActive = torStat->status != TR_STATUS_STOPPED;
|
|
|
|
const int isChecking = torStat->status == TR_STATUS_CHECK
|
|
|
|
|| torStat->status == TR_STATUS_CHECK_WAIT;
|
|
|
|
|
|
|
|
GString * gstr = g_string_new( NULL );
|
|
|
|
|
|
|
|
if( torStat->error )
|
|
|
|
{
|
|
|
|
g_string_assign( gstr, torStat->errorString );
|
|
|
|
}
|
|
|
|
else switch( torStat->status )
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
2007-12-20 15:16:14 +00:00
|
|
|
case TR_STATUS_CHECK: {
|
|
|
|
char * pch = getShortStatusString( torStat );
|
2007-12-19 18:11:10 +00:00
|
|
|
g_string_assign( gstr, pch );
|
|
|
|
g_free( pch );
|
2007-12-19 02:46:30 +00:00
|
|
|
break;
|
2007-12-20 15:16:14 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
g_string_append_printf( gstr,
|
2008-03-19 20:07:27 +00:00
|
|
|
ngettext( "Downloading from %1$'d of %2$'d connected peer",
|
|
|
|
"Downloading from %1$'d of %2$'d connected peers",
|
2007-12-20 01:33:51 +00:00
|
|
|
torStat->peersConnected ),
|
|
|
|
torStat->peersSendingToUs,
|
|
|
|
torStat->peersConnected );
|
2007-12-19 02:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
g_string_append_printf( gstr,
|
2008-03-19 20:07:27 +00:00
|
|
|
ngettext( "Seeding to %1$'d of %2$'d connected peer",
|
|
|
|
"Seeding to %1$'d of %2$'d connected peers",
|
2007-12-27 19:18:32 +00:00
|
|
|
torStat->peersConnected ),
|
2007-12-20 01:33:51 +00:00
|
|
|
torStat->peersGettingFromUs,
|
|
|
|
torStat->peersConnected );
|
2007-12-19 02:46:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isActive && !isChecking )
|
|
|
|
{
|
2007-12-20 02:02:51 +00:00
|
|
|
char buf[256];
|
|
|
|
getShortTransferString( torStat, buf, sizeof(buf) );
|
|
|
|
g_string_append_printf( gstr, " - %s", buf );
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free( gstr, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static GtkCellRendererClass * parent_class = NULL;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate
|
|
|
|
{
|
|
|
|
tr_torrent * tor;
|
|
|
|
GtkCellRenderer * text_renderer;
|
2008-01-18 00:16:49 +00:00
|
|
|
GtkCellRenderer * text_renderer_err;
|
2008-02-23 17:02:42 +00:00
|
|
|
GtkCellRenderer * progress_renderer;
|
2007-12-19 02:46:30 +00:00
|
|
|
int bar_height;
|
|
|
|
gboolean minimal;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_get_size( GtkCellRenderer * cell,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * cell_area,
|
|
|
|
gint * x_offset,
|
|
|
|
gint * y_offset,
|
|
|
|
gint * width,
|
|
|
|
gint * height)
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
|
|
|
|
|
|
|
|
if( self && self->priv->tor )
|
|
|
|
{
|
|
|
|
const tr_torrent * tor = self->priv->tor;
|
|
|
|
const tr_info * info = tr_torrentInfo( tor );
|
|
|
|
const char * name = info->name;
|
2007-12-21 22:18:40 +00:00
|
|
|
const tr_stat * torStat = tr_torrentStatCached( (tr_torrent*)tor );
|
2007-12-19 02:46:30 +00:00
|
|
|
char * str;
|
|
|
|
int w=0, h=0;
|
2007-12-19 20:04:38 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2008-01-18 00:16:49 +00:00
|
|
|
GtkCellRenderer * text_renderer = torStat->error != 0
|
|
|
|
? p->text_renderer_err
|
|
|
|
: p->text_renderer;
|
2007-12-19 20:04:38 +00:00
|
|
|
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
/* above the progressbar */
|
2007-12-19 20:04:38 +00:00
|
|
|
if( p->minimal )
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
|
|
|
int w1, w2, h1, h2;
|
2007-12-20 01:33:51 +00:00
|
|
|
char * shortStatus = getShortStatusString( torStat );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "text", name, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 18:11:10 +00:00
|
|
|
widget, NULL, NULL, NULL, &w1, &h1 );
|
2007-12-20 01:33:51 +00:00
|
|
|
str = g_markup_printf_escaped( "<small>%s</small>", shortStatus );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 18:11:10 +00:00
|
|
|
widget, NULL, NULL, NULL, &w2, &h2 );
|
|
|
|
h += MAX( h1, h2 );
|
|
|
|
w = MAX( w, w1+GUI_PAD_BIG+w2 );
|
|
|
|
g_free( str );
|
2007-12-20 01:33:51 +00:00
|
|
|
g_free( shortStatus );
|
2007-12-19 18:11:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 01:33:51 +00:00
|
|
|
int w1, h1;
|
|
|
|
char * progressString = getProgressString( info, torStat );
|
2007-12-19 18:11:10 +00:00
|
|
|
str = g_markup_printf_escaped( "<b>%s</b>\n<small>%s</small>",
|
|
|
|
name, progressString );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-20 01:33:51 +00:00
|
|
|
widget, NULL, NULL, NULL, &w1, &h1 );
|
|
|
|
h += h1;
|
|
|
|
w = MAX( w, w1 );
|
2007-12-19 18:11:10 +00:00
|
|
|
g_free( str );
|
|
|
|
g_free( progressString );
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
/* below the progressbar */
|
2007-12-19 20:04:38 +00:00
|
|
|
if( !p->minimal )
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
2007-12-20 01:33:51 +00:00
|
|
|
int w1, h1;
|
2007-12-19 18:11:10 +00:00
|
|
|
char * statusString = getStatusString( torStat );
|
|
|
|
str = g_markup_printf_escaped( "<small>%s</small>", statusString );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-20 01:33:51 +00:00
|
|
|
widget, NULL, NULL, NULL, &w1, &h1 );
|
|
|
|
h += h1;
|
|
|
|
w = MAX( w, w1 );
|
2007-12-19 18:11:10 +00:00
|
|
|
g_free( str );
|
|
|
|
g_free( statusString );
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2007-12-19 20:04:38 +00:00
|
|
|
h += p->bar_height;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
if( cell_area ) {
|
|
|
|
if( x_offset ) *x_offset = 0;
|
|
|
|
if( y_offset ) {
|
2008-04-01 04:24:01 +00:00
|
|
|
*y_offset = 0.5 * (cell_area->height - (h + (2 * cell->ypad)));
|
2007-12-19 02:46:30 +00:00
|
|
|
*y_offset = MAX( *y_offset, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 04:24:01 +00:00
|
|
|
*width = w + cell->xpad * 2;
|
|
|
|
*height = h + cell->ypad * 2;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_render( GtkCellRenderer * cell,
|
|
|
|
GdkDrawable * window,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * background_area,
|
2007-12-20 01:33:51 +00:00
|
|
|
GdkRectangle * cell_area UNUSED,
|
|
|
|
GdkRectangle * expose_area UNUSED,
|
2007-12-19 02:46:30 +00:00
|
|
|
GtkCellRendererState flags)
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
|
|
|
GtkTextDirection real_dir = gtk_widget_get_direction( widget );
|
|
|
|
gtk_widget_set_direction( widget, GTK_TEXT_DIR_RTL );
|
|
|
|
#endif
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
if( self && self->priv->tor )
|
|
|
|
{
|
|
|
|
const tr_torrent * tor = self->priv->tor;
|
|
|
|
const tr_info * info = tr_torrentInfo( tor );
|
|
|
|
const char * name = info->name;
|
2007-12-21 22:18:40 +00:00
|
|
|
const tr_stat * torStat = tr_torrentStatCached( (tr_torrent*)tor );
|
2007-12-19 02:46:30 +00:00
|
|
|
GdkRectangle my_bg;
|
|
|
|
GdkRectangle my_cell;
|
|
|
|
GdkRectangle my_expose;
|
|
|
|
int w, h;
|
2007-12-19 20:04:38 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2008-01-18 00:16:49 +00:00
|
|
|
GtkCellRenderer * text_renderer = torStat->error != 0
|
|
|
|
? p->text_renderer_err
|
|
|
|
: p->text_renderer;
|
2008-02-23 17:02:42 +00:00
|
|
|
const gboolean isActive = torStat->status != TR_STATUS_STOPPED;
|
2008-01-18 00:16:49 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
my_bg = *background_area;
|
2008-04-01 04:24:01 +00:00
|
|
|
my_bg.x += cell->xpad;
|
|
|
|
my_bg.y += cell->ypad;
|
|
|
|
my_bg.width -= cell->xpad * 2;
|
2007-12-20 01:33:51 +00:00
|
|
|
my_cell = my_expose = my_bg;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2008-02-23 17:02:42 +00:00
|
|
|
g_object_set( text_renderer, "sensitive", isActive, NULL );
|
|
|
|
g_object_set( p->progress_renderer, "sensitive", isActive, NULL );
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
/* above the progressbar */
|
2007-12-19 20:04:38 +00:00
|
|
|
if( !p->minimal )
|
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
char * progressString = getProgressString( info, torStat );
|
|
|
|
char * str = g_markup_printf_escaped( "<b>%s</b>\n<small>%s</small>",
|
|
|
|
name, progressString );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str,
|
2007-12-19 20:04:38 +00:00
|
|
|
"ellipsize", PANGO_ELLIPSIZE_NONE,
|
|
|
|
NULL );
|
2008-01-18 00:16:49 +00:00
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
widget, NULL, NULL, NULL, &w, &h );
|
2007-12-20 01:33:51 +00:00
|
|
|
my_bg.height =
|
|
|
|
my_cell.height =
|
2007-12-19 20:04:38 +00:00
|
|
|
my_expose.height = h;
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "ellipsize", PANGO_ELLIPSIZE_END,
|
2007-12-19 20:04:38 +00:00
|
|
|
NULL );
|
2008-01-18 00:16:49 +00:00
|
|
|
gtk_cell_renderer_render( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
window, widget,
|
|
|
|
&my_bg, &my_cell, &my_expose, flags );
|
|
|
|
my_bg.y += h;
|
|
|
|
my_cell.y += h;
|
|
|
|
my_expose.y += h;
|
2007-12-20 15:16:14 +00:00
|
|
|
|
|
|
|
g_free( str );
|
|
|
|
g_free( progressString );
|
2007-12-19 20:04:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
char * statusStr = getShortStatusString( torStat );
|
|
|
|
char * str = g_markup_printf_escaped( "<small>%s</small>", statusStr );
|
2007-12-19 20:04:38 +00:00
|
|
|
int w1, w2, h1, h2, tmp_h;
|
|
|
|
GdkRectangle tmp_bg, tmp_cell, tmp_expose;
|
|
|
|
|
|
|
|
/* get the dimensions for the name */
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "text", name,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_NONE,
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
widget, NULL, NULL, NULL, &w1, &h1 );
|
|
|
|
|
|
|
|
/* get the dimensions for the short status string */
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_NONE,
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
widget, NULL, NULL, NULL, &w2, &h2 );
|
|
|
|
|
|
|
|
tmp_h = MAX( h1, h2 );
|
|
|
|
|
|
|
|
/* short status */
|
|
|
|
tmp_bg.x = my_bg.width - w2;
|
2007-12-20 01:33:51 +00:00
|
|
|
tmp_bg.y = my_bg.y + (h2-h1)/2;
|
2007-12-19 20:04:38 +00:00
|
|
|
tmp_bg.width = w2;
|
|
|
|
tmp_bg.height = tmp_h;
|
|
|
|
tmp_expose = tmp_cell = tmp_bg;
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_render( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
window, widget,
|
|
|
|
&tmp_bg, &tmp_cell, &tmp_expose, flags );
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
tmp_bg.x = my_bg.x;
|
|
|
|
tmp_bg.width = my_bg.width - w2 - GUI_PAD_BIG;
|
|
|
|
tmp_expose = tmp_cell = tmp_bg;
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "text", name,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_render( text_renderer,
|
2007-12-19 20:04:38 +00:00
|
|
|
window, widget,
|
|
|
|
&tmp_bg, &tmp_cell, &tmp_expose, flags );
|
|
|
|
|
|
|
|
my_bg.y = tmp_bg.y + tmp_bg.height;
|
|
|
|
my_cell.y = tmp_cell.y + tmp_cell.height;
|
|
|
|
my_expose.y += tmp_expose.y + tmp_cell.height;
|
2007-12-20 15:16:14 +00:00
|
|
|
|
|
|
|
g_free( str );
|
|
|
|
g_free( statusStr );
|
2007-12-19 20:04:38 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
/* the progressbar */
|
2007-12-19 20:04:38 +00:00
|
|
|
my_cell.height = p->bar_height;
|
2008-02-24 19:36:48 +00:00
|
|
|
if( 1 )
|
2008-02-23 17:02:42 +00:00
|
|
|
{
|
|
|
|
const double havePercent = ( torStat->haveValid + torStat->haveUnchecked )
|
|
|
|
/ (double)info->totalSize;
|
|
|
|
g_object_set( p->progress_renderer, "value", (int)(havePercent*100.0),
|
|
|
|
"text", "",
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_render( p->progress_renderer,
|
|
|
|
window, widget,
|
|
|
|
&my_cell, &my_cell, &my_cell, flags );
|
|
|
|
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
my_bg.y += my_cell.height;
|
|
|
|
my_cell.y += my_cell.height;
|
|
|
|
my_expose.y += my_cell.height;
|
|
|
|
|
|
|
|
/* below progressbar */
|
2007-12-19 20:04:38 +00:00
|
|
|
if( !p->minimal )
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
char * statusString = getStatusString( torStat );
|
|
|
|
char * str = g_markup_printf_escaped( "<small>%s</small>",
|
|
|
|
statusString );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( text_renderer, "markup", str,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer,
|
2007-12-19 18:11:10 +00:00
|
|
|
widget, NULL, NULL, NULL, &w, &h );
|
2007-12-20 01:33:51 +00:00
|
|
|
my_bg.height =
|
|
|
|
my_cell.height =
|
2007-12-19 18:11:10 +00:00
|
|
|
my_expose.height = h;
|
2008-01-18 00:16:49 +00:00
|
|
|
gtk_cell_renderer_render( text_renderer,
|
2007-12-19 18:11:10 +00:00
|
|
|
window, widget,
|
|
|
|
&my_bg, &my_cell, &my_expose, flags );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2007-12-20 15:16:14 +00:00
|
|
|
g_free( str );
|
|
|
|
g_free( statusString );
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
|
|
|
gtk_widget_set_direction( widget, real_dir );
|
|
|
|
#endif
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_set_property( GObject * object,
|
|
|
|
guint property_id,
|
2007-12-19 18:11:10 +00:00
|
|
|
const GValue * v,
|
2007-12-19 02:46:30 +00:00
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( object );
|
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
|
|
|
switch( property_id )
|
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
case P_TORRENT: p->tor = g_value_get_pointer( v ); break;
|
|
|
|
case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break;
|
|
|
|
case P_MINIMAL: p->minimal = g_value_get_boolean( v ); break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec );
|
|
|
|
break;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_get_property( GObject * object,
|
|
|
|
guint property_id,
|
2007-12-19 18:11:10 +00:00
|
|
|
GValue * v,
|
2007-12-19 02:46:30 +00:00
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
const TorrentCellRenderer * self = TORRENT_CELL_RENDERER( object );
|
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
|
|
|
switch( property_id )
|
|
|
|
{
|
2007-12-20 15:16:14 +00:00
|
|
|
case P_TORRENT: g_value_set_pointer( v, p->tor ); break;
|
|
|
|
case P_BAR_HEIGHT: g_value_set_int( v, p->bar_height ); break;
|
|
|
|
case P_MINIMAL: g_value_set_boolean( v, p->minimal ); break;
|
2007-12-19 02:46:30 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 17:59:09 +00:00
|
|
|
static void
|
|
|
|
torrent_cell_renderer_dispose( GObject * o )
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * r = TORRENT_CELL_RENDERER( o );
|
2008-02-09 17:25:14 +00:00
|
|
|
GObjectClass * parent;
|
|
|
|
|
2008-01-12 17:59:09 +00:00
|
|
|
if( r && r->priv )
|
|
|
|
{
|
|
|
|
g_object_unref( G_OBJECT( r->priv->text_renderer ) );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_unref( G_OBJECT( r->priv->text_renderer_err ) );
|
2008-02-23 17:02:42 +00:00
|
|
|
g_object_unref( G_OBJECT( r->priv->progress_renderer ) );
|
2008-01-12 17:59:09 +00:00
|
|
|
r->priv = NULL;
|
|
|
|
}
|
2008-02-09 17:25:14 +00:00
|
|
|
|
|
|
|
parent = g_type_class_peek( g_type_parent( TORRENT_CELL_RENDERER_TYPE ) );
|
|
|
|
parent->dispose( o );
|
2008-01-12 17:59:09 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static void
|
|
|
|
torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
|
|
|
|
{
|
|
|
|
GObjectClass * gobject_class = G_OBJECT_CLASS( klass );
|
2007-12-20 01:33:51 +00:00
|
|
|
GtkCellRendererClass * cell_class = GTK_CELL_RENDERER_CLASS( klass );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2007-12-20 01:33:51 +00:00
|
|
|
g_type_class_add_private( klass,
|
|
|
|
sizeof(struct TorrentCellRendererPrivate) );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
parent_class = (GtkCellRendererClass*) g_type_class_peek_parent( klass );
|
|
|
|
|
2007-12-20 01:33:51 +00:00
|
|
|
cell_class->render = torrent_cell_renderer_render;
|
|
|
|
cell_class->get_size = torrent_cell_renderer_get_size;
|
2007-12-19 02:46:30 +00:00
|
|
|
gobject_class->set_property = torrent_cell_renderer_set_property;
|
|
|
|
gobject_class->get_property = torrent_cell_renderer_get_property;
|
2008-01-12 17:59:09 +00:00
|
|
|
gobject_class->dispose = torrent_cell_renderer_dispose;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
g_object_class_install_property( gobject_class, P_TORRENT,
|
|
|
|
g_param_spec_pointer( "torrent", NULL, "tr_torrent*",
|
|
|
|
G_PARAM_READWRITE ) );
|
|
|
|
|
|
|
|
g_object_class_install_property( gobject_class, P_BAR_HEIGHT,
|
|
|
|
g_param_spec_int( "bar-height", NULL, "Bar Height",
|
|
|
|
1, INT_MAX, DEFAULT_BAR_HEIGHT, G_PARAM_READWRITE ) );
|
|
|
|
|
|
|
|
g_object_class_install_property( gobject_class, P_MINIMAL,
|
|
|
|
g_param_spec_boolean( "minimal", NULL, "Minimal Mode",
|
|
|
|
FALSE, G_PARAM_READWRITE ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_init( GTypeInstance * instance, gpointer g_class UNUSED )
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( instance );
|
|
|
|
struct TorrentCellRendererPrivate * p;
|
|
|
|
|
|
|
|
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,
|
2007-12-20 01:33:51 +00:00
|
|
|
TORRENT_CELL_RENDERER_TYPE,
|
|
|
|
struct TorrentCellRendererPrivate );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
p->tor = NULL;
|
|
|
|
p->text_renderer = gtk_cell_renderer_text_new( );
|
2008-01-18 00:16:49 +00:00
|
|
|
p->text_renderer_err = gtk_cell_renderer_text_new( );
|
2008-02-23 17:02:42 +00:00
|
|
|
p->progress_renderer = gtk_cell_renderer_progress_new( );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( p->text_renderer_err, "foreground", "red", NULL );
|
2008-01-15 17:55:09 +00:00
|
|
|
tr_object_ref_sink( p->text_renderer );
|
2008-01-18 00:16:49 +00:00
|
|
|
tr_object_ref_sink( p->text_renderer_err );
|
2008-02-23 17:02:42 +00:00
|
|
|
tr_object_ref_sink( p->progress_renderer );
|
2008-01-18 00:16:49 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
p->bar_height = DEFAULT_BAR_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
torrent_cell_renderer_get_type( void )
|
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if( !type )
|
|
|
|
{
|
|
|
|
static const GTypeInfo info =
|
|
|
|
{
|
|
|
|
sizeof( TorrentCellRendererClass ),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc)torrent_cell_renderer_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof( TorrentCellRenderer ),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc)torrent_cell_renderer_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
type = g_type_register_static( GTK_TYPE_CELL_RENDERER,
|
|
|
|
"TorrentCellRenderer",
|
|
|
|
&info, (GTypeFlags)0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCellRenderer *
|
|
|
|
torrent_cell_renderer_new( void )
|
|
|
|
{
|
|
|
|
return (GtkCellRenderer *) g_object_new( TORRENT_CELL_RENDERER_TYPE, NULL );
|
|
|
|
}
|