2007-12-19 02:46:30 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2007-2010 Mnemosyne LLC
|
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)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-12-19 02:46:30 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-03-06 21:59:00 +00:00
|
|
|
* $Id$
|
2007-12-19 02:46:30 +00:00
|
|
|
*/
|
|
|
|
|
2009-07-14 20:09:46 +00:00
|
|
|
#include <string.h> /* strcmp() */
|
2007-12-19 02:46:30 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <libtransmission/transmission.h>
|
2009-07-14 20:09:46 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_truncd() */
|
2007-12-19 18:11:10 +00:00
|
|
|
#include "hig.h"
|
2009-03-02 23:31:01 +00:00
|
|
|
#include "icons.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,
|
2009-08-07 20:49:06 +00:00
|
|
|
P_UPLOAD_SPEED,
|
|
|
|
P_DOWNLOAD_SPEED,
|
2007-12-19 02:46:30 +00:00
|
|
|
P_BAR_HEIGHT,
|
2010-03-15 14:42:43 +00:00
|
|
|
P_COMPACT
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_BAR_HEIGHT 12
|
2009-03-02 23:31:01 +00:00
|
|
|
#define SMALL_SCALE 0.9
|
2010-03-15 14:42:43 +00:00
|
|
|
#define COMPACT_ICON_SIZE GTK_ICON_SIZE_MENU
|
2009-03-02 23:31:01 +00:00
|
|
|
#define FULL_ICON_SIZE GTK_ICON_SIZE_DND
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static char*
|
2009-03-01 16:00:41 +00:00
|
|
|
getProgressString( const tr_torrent * tor,
|
|
|
|
const tr_info * info,
|
|
|
|
const tr_stat * torStat )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
const int isDone = torStat->leftUntilDone == 0;
|
2007-12-19 02:46:30 +00:00
|
|
|
const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid;
|
2008-09-23 19:11:04 +00:00
|
|
|
const int isSeed = torStat->haveValid >= info->totalSize;
|
2010-06-22 22:30:58 +00:00
|
|
|
char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32];
|
2008-09-23 19:11:04 +00:00
|
|
|
char * str;
|
2009-08-10 20:04:08 +00:00
|
|
|
double seedRatio;
|
2010-04-01 06:08:20 +00:00
|
|
|
const gboolean hasSeedRatio = tr_torrentGetSeedRatio( tor, &seedRatio );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2010-04-01 06:08:20 +00:00
|
|
|
if( !isDone ) /* downloading */
|
2009-03-01 16:00:41 +00:00
|
|
|
{
|
2007-12-19 02:46:30 +00:00
|
|
|
str = g_strdup_printf(
|
2008-09-23 19:11:04 +00:00
|
|
|
/* %1$s is how much we've got,
|
|
|
|
%2$s is how much we'll have when done,
|
2010-06-22 22:30:58 +00:00
|
|
|
%3$s%% is a percentage of the two */
|
|
|
|
_( "%1$s of %2$s (%3$s%%)" ),
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
|
|
|
|
tr_strlsize( buf2, torStat->sizeWhenDone, sizeof( buf2 ) ),
|
2010-06-22 22:30:58 +00:00
|
|
|
tr_strlpercent( buf3, torStat->percentDone * 100.0, sizeof( buf3 ) ) );
|
2009-03-01 16:00:41 +00:00
|
|
|
}
|
2010-04-01 06:08:20 +00:00
|
|
|
else if( !isSeed ) /* partial seeds */
|
2009-03-01 16:00:41 +00:00
|
|
|
{
|
2010-04-01 06:08:20 +00:00
|
|
|
if( hasSeedRatio )
|
|
|
|
{
|
|
|
|
str = g_strdup_printf(
|
|
|
|
/* %1$s is how much we've got,
|
|
|
|
%2$s is the torrent's total size,
|
2010-06-22 22:30:58 +00:00
|
|
|
%3$s%% is a percentage of the two,
|
2010-04-01 06:08:20 +00:00
|
|
|
%4$s is how much we've uploaded,
|
|
|
|
%5$s is our upload-to-download ratio,
|
|
|
|
%6$s is the ratio we want to reach before we stop uploading */
|
2010-06-22 22:30:58 +00:00
|
|
|
_( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s Goal: %6$s)" ),
|
2010-04-01 06:08:20 +00:00
|
|
|
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
|
|
|
|
tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ),
|
2010-06-22 22:30:58 +00:00
|
|
|
tr_strlpercent( buf3, torStat->percentComplete * 100.0, sizeof( buf3 ) ),
|
|
|
|
tr_strlsize( buf4, torStat->uploadedEver, sizeof( buf4 ) ),
|
|
|
|
tr_strlratio( buf5, torStat->ratio, sizeof( buf5 ) ),
|
|
|
|
tr_strlratio( buf6, seedRatio, sizeof( buf6 ) ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = g_strdup_printf(
|
|
|
|
/* %1$s is how much we've got,
|
|
|
|
%2$s is the torrent's total size,
|
2010-06-22 22:30:58 +00:00
|
|
|
%3$s%% is a percentage of the two,
|
2010-04-01 06:08:20 +00:00
|
|
|
%4$s is how much we've uploaded,
|
|
|
|
%5$s is our upload-to-download ratio */
|
2010-06-22 22:30:58 +00:00
|
|
|
_( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s)" ),
|
2010-04-01 06:08:20 +00:00
|
|
|
tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
|
|
|
|
tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ),
|
2010-06-22 22:30:58 +00:00
|
|
|
tr_strlpercent( buf3, torStat->percentComplete * 100.0, sizeof( buf3 ) ),
|
|
|
|
tr_strlsize( buf4, torStat->uploadedEver, sizeof( buf4 ) ),
|
|
|
|
tr_strlratio( buf5, torStat->ratio, sizeof( buf5 ) ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
2009-03-01 16:00:41 +00:00
|
|
|
}
|
2010-04-01 06:08:20 +00:00
|
|
|
else /* seeding */
|
2009-03-01 16:00:41 +00:00
|
|
|
{
|
2010-04-01 06:08:20 +00:00
|
|
|
if( hasSeedRatio )
|
|
|
|
{
|
|
|
|
str = g_strdup_printf(
|
|
|
|
/* %1$s is the torrent's total size,
|
|
|
|
%2$s is how much we've uploaded,
|
|
|
|
%3$s is our upload-to-download ratio,
|
|
|
|
%4$s is the ratio we want to reach before we stop uploading */
|
|
|
|
_( "%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)" ),
|
|
|
|
tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
|
|
|
|
tr_strlsize( buf2, torStat->uploadedEver, sizeof( buf2 ) ),
|
|
|
|
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ),
|
|
|
|
tr_strlratio( buf4, seedRatio, sizeof( buf4 ) ) );
|
|
|
|
}
|
|
|
|
else /* seeding w/o a ratio */
|
|
|
|
{
|
|
|
|
str = g_strdup_printf(
|
|
|
|
/* %1$s is the torrent's total size,
|
|
|
|
%2$s is how much we've uploaded,
|
|
|
|
%3$s is our upload-to-download ratio */
|
|
|
|
_( "%1$s, uploaded %2$s (Ratio: %3$s)" ),
|
|
|
|
tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
|
|
|
|
tr_strlsize( buf2, torStat->uploadedEver, sizeof( buf2 ) ),
|
|
|
|
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );
|
|
|
|
}
|
2009-03-01 16:00:41 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2008-03-16 15:18:19 +00:00
|
|
|
/* add time when downloading */
|
2010-01-22 07:32:02 +00:00
|
|
|
if( ( torStat->activity == TR_STATUS_DOWNLOAD )
|
|
|
|
|| ( hasSeedRatio && ( torStat->activity == TR_STATUS_SEED ) ) )
|
2008-02-09 16:05:29 +00:00
|
|
|
{
|
|
|
|
const int eta = torStat->eta;
|
|
|
|
GString * gstr = g_string_new( str );
|
|
|
|
g_string_append( gstr, " - " );
|
2008-08-10 19:11:59 +00:00
|
|
|
if( eta < 0 )
|
|
|
|
g_string_append( gstr, _( "Remaining time unknown" ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
else
|
|
|
|
{
|
2008-02-09 16:05:29 +00:00
|
|
|
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*
|
2009-11-24 15:51:16 +00:00
|
|
|
getShortTransferString( const tr_torrent * tor,
|
|
|
|
const tr_stat * torStat,
|
2010-07-04 06:07:21 +00:00
|
|
|
double uploadSpeed_KBps,
|
|
|
|
double downloadSpeed_KBps,
|
2009-11-24 15:51:16 +00:00
|
|
|
char * buf,
|
|
|
|
size_t buflen )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2009-11-24 15:51:16 +00:00
|
|
|
char downStr[32], upStr[32];
|
|
|
|
const int haveMeta = tr_torrentHasMetadata( tor );
|
|
|
|
const int haveDown = haveMeta && torStat->peersSendingToUs > 0;
|
|
|
|
const int haveUp = haveMeta && torStat->peersGettingFromUs > 0;
|
2007-12-20 02:02:51 +00:00
|
|
|
|
|
|
|
if( haveDown )
|
2010-07-04 06:07:21 +00:00
|
|
|
tr_formatter_speed_KBps( downStr, downloadSpeed_KBps, sizeof( downStr ) );
|
2007-12-20 02:02:51 +00:00
|
|
|
if( haveUp )
|
2010-07-04 06:07:21 +00:00
|
|
|
tr_formatter_speed_KBps( upStr, uploadSpeed_KBps, sizeof( upStr ) );
|
2007-12-20 02:02:51 +00:00
|
|
|
|
|
|
|
if( haveDown && haveUp )
|
2010-03-20 14:53:08 +00:00
|
|
|
/* 1==down speed, 2==down arrow, 3==up speed, 4==down arrow */
|
|
|
|
g_snprintf( buf, buflen, _( "%1$s %2$s, %3$s %4$s" ),
|
|
|
|
gtr_get_unicode_string( GTR_UNICODE_DOWN ), downStr,
|
|
|
|
gtr_get_unicode_string( GTR_UNICODE_UP ), upStr );
|
2007-12-20 02:02:51 +00:00
|
|
|
else if( haveDown )
|
2010-03-20 14:53:08 +00:00
|
|
|
/* bandwidth speed + unicode arrow */
|
|
|
|
g_snprintf( buf, buflen, _( "%1$s %2$s" ),
|
|
|
|
gtr_get_unicode_string( GTR_UNICODE_DOWN ), downStr );
|
2007-12-20 02:02:51 +00:00
|
|
|
else if( haveUp )
|
2010-03-20 14:53:08 +00:00
|
|
|
/* bandwidth speed + unicode arrow */
|
|
|
|
g_snprintf( buf, buflen, _( "%1$s %2$s" ),
|
|
|
|
gtr_get_unicode_string( GTR_UNICODE_UP ), upStr );
|
2009-11-24 15:51:16 +00:00
|
|
|
else if( tr_torrentHasMetadata( tor ) )
|
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 );
|
2009-11-24 15:51:16 +00:00
|
|
|
else
|
|
|
|
*buf = '\0';
|
2007-12-20 02:02:51 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2009-11-24 15:51:16 +00:00
|
|
|
getShortStatusString( const tr_torrent * tor,
|
|
|
|
const tr_stat * torStat,
|
2010-07-04 06:07:21 +00:00
|
|
|
double uploadSpeed_KBps,
|
|
|
|
double downloadSpeed_KBps )
|
2007-12-20 02:02:51 +00:00
|
|
|
{
|
2007-12-19 18:11:10 +00:00
|
|
|
GString * gstr = g_string_new( NULL );
|
|
|
|
|
2008-10-20 17:54:56 +00:00
|
|
|
switch( torStat->activity )
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
2010-04-06 02:34:45 +00:00
|
|
|
if( torStat->finished )
|
|
|
|
g_string_assign( gstr, _( "Finished" ) );
|
|
|
|
else
|
|
|
|
g_string_assign( gstr, _( "Paused" ) );
|
2007-12-19 18:11:10 +00:00
|
|
|
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:
|
2008-09-23 19:11:04 +00:00
|
|
|
g_string_append_printf( gstr,
|
2009-07-14 20:09:46 +00:00
|
|
|
_( "Verifying local data (%.1f%% tested)" ),
|
|
|
|
tr_truncd( torStat->recheckProgress * 100.0, 1 ) );
|
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-09-23 19:11:04 +00:00
|
|
|
case TR_STATUS_SEED:
|
|
|
|
{
|
2009-09-12 07:26:13 +00:00
|
|
|
char buf[512];
|
2008-10-20 17:54:56 +00:00
|
|
|
if( torStat->activity != TR_STATUS_DOWNLOAD )
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( buf, torStat->ratio, sizeof( buf ) );
|
2010-03-20 14:53:08 +00:00
|
|
|
g_string_append_printf( gstr, _( "Ratio %s" ), buf );
|
2008-03-07 21:59:27 +00:00
|
|
|
g_string_append( gstr, ", " );
|
2008-01-04 18:52:39 +00:00
|
|
|
}
|
2010-07-04 06:07:21 +00:00
|
|
|
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
|
2007-12-20 15:16:14 +00:00
|
|
|
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*
|
2009-11-24 15:51:16 +00:00
|
|
|
getStatusString( const tr_torrent * tor,
|
|
|
|
const tr_stat * torStat,
|
2010-07-04 06:07:21 +00:00
|
|
|
const double uploadSpeed_KBps,
|
|
|
|
const double downloadSpeed_KBps )
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
const int isActive = torStat->activity != TR_STATUS_STOPPED;
|
|
|
|
const int isChecking = torStat->activity == TR_STATUS_CHECK
|
|
|
|
|| torStat->activity == TR_STATUS_CHECK_WAIT;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
GString * gstr = g_string_new( NULL );
|
|
|
|
|
|
|
|
if( torStat->error )
|
|
|
|
{
|
2009-08-06 07:04:19 +00:00
|
|
|
const char * fmt[] = { NULL, N_( "Tracker gave a warning: \"%s\"" ),
|
|
|
|
N_( "Tracker gave an error: \"%s\"" ),
|
2009-08-13 17:48:53 +00:00
|
|
|
N_( "Error: %s" ) };
|
2009-08-05 01:25:36 +00:00
|
|
|
g_string_append_printf( gstr, _( fmt[torStat->error] ), torStat->errorString );
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2008-10-20 17:54:56 +00:00
|
|
|
else switch( torStat->activity )
|
2009-11-24 15:51:16 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
case TR_STATUS_CHECK:
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2010-07-04 06:07:21 +00:00
|
|
|
char * pch = getShortStatusString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps );
|
2009-11-24 15:51:16 +00:00
|
|
|
g_string_assign( gstr, pch );
|
|
|
|
g_free( pch );
|
|
|
|
break;
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-11-24 15:51:16 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
{
|
2010-01-05 23:47:50 +00:00
|
|
|
if( tr_torrentHasMetadata( tor ) )
|
2009-11-24 15:51:16 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
g_string_append_printf( gstr,
|
2008-10-07 15:17:52 +00:00
|
|
|
ngettext( "Downloading from %1$'d of %2$'d connected peer",
|
|
|
|
"Downloading from %1$'d of %2$'d connected peers",
|
|
|
|
torStat->peersConnected ),
|
|
|
|
torStat->peersSendingToUs +
|
|
|
|
torStat->webseedsSendingToUs,
|
|
|
|
torStat->peersConnected +
|
|
|
|
torStat->webseedsSendingToUs );
|
2009-11-24 15:51:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
g_string_append_printf( gstr,
|
2009-12-05 00:35:58 +00:00
|
|
|
ngettext( "Downloading metadata from %1$'d peer (%2$d%% done)",
|
|
|
|
"Downloading metadata from %1$'d peers (%2$d%% done)",
|
2008-10-07 15:17:52 +00:00
|
|
|
torStat->peersConnected ),
|
2009-11-24 17:10:40 +00:00
|
|
|
torStat->peersConnected + torStat->webseedsSendingToUs,
|
|
|
|
(int)(100.0*torStat->metadataPercentComplete) );
|
2009-11-24 15:51:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-11-24 15:51:16 +00:00
|
|
|
case TR_STATUS_SEED:
|
|
|
|
g_string_append_printf( gstr,
|
|
|
|
ngettext( "Seeding to %1$'d of %2$'d connected peer",
|
|
|
|
"Seeding to %1$'d of %2$'d connected peers",
|
|
|
|
torStat->peersConnected ),
|
|
|
|
torStat->peersGettingFromUs,
|
|
|
|
torStat->peersConnected );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
if( isActive && !isChecking )
|
|
|
|
{
|
2007-12-20 02:02:51 +00:00
|
|
|
char buf[256];
|
2010-07-04 06:07:21 +00:00
|
|
|
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
|
2009-11-24 15:51:16 +00:00
|
|
|
if( *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
|
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
tr_torrent * tor;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
GtkCellRenderer * text_renderer_err;
|
|
|
|
GtkCellRenderer * progress_renderer;
|
|
|
|
GtkCellRenderer * icon_renderer;
|
2009-08-07 20:49:06 +00:00
|
|
|
int bar_height;
|
|
|
|
|
|
|
|
/* use this instead of tr_stat.pieceUploadSpeed so that the model can
|
|
|
|
control when the speed displays get updated. this is done to keep
|
|
|
|
the individual torrents' speeds and the status bar's overall speed
|
|
|
|
in sync even if they refresh at slightly different times */
|
2010-07-04 06:07:21 +00:00
|
|
|
double upload_speed_KBps;
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
/* @see upload_speed_Bps */
|
2010-07-04 06:07:21 +00:00
|
|
|
double download_speed_KBps;
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
gboolean compact;
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static GdkPixbuf*
|
|
|
|
get_icon( const tr_torrent * tor, GtkIconSize icon_size, GtkWidget * for_widget )
|
|
|
|
{
|
|
|
|
const char * mime_type;
|
|
|
|
const tr_info * info = tr_torrentInfo( tor );
|
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
if( info->fileCount == 0 )
|
|
|
|
mime_type = UNKNOWN_MIME_TYPE;
|
|
|
|
else if( info->fileCount > 1 )
|
2009-03-02 23:31:01 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2010-02-26 15:06:26 +00:00
|
|
|
else if( strchr( info->files[0].name, '/' ) != NULL )
|
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2009-03-02 23:31:01 +00:00
|
|
|
else
|
|
|
|
mime_type = get_mime_type_from_filename( info->files[0].name );
|
|
|
|
|
2009-03-03 19:43:23 +00:00
|
|
|
return get_mime_type_icon( mime_type, icon_size, for_widget );
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCellRenderer*
|
|
|
|
get_text_renderer( const tr_stat * st, TorrentCellRenderer * r )
|
|
|
|
{
|
|
|
|
return st->error ? r->priv->text_renderer_err : r->priv->text_renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
2010-03-15 14:42:43 +00:00
|
|
|
get_size_compact( TorrentCellRenderer * cell,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
|
|
|
gint * width,
|
|
|
|
gint * height )
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
const char * name;
|
|
|
|
char * status;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
|
|
|
const tr_torrent * tor = p->tor;
|
|
|
|
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
icon = get_icon( tor, COMPACT_ICON_SIZE, widget );
|
2009-03-02 23:31:01 +00:00
|
|
|
name = tr_torrentInfo( tor )->name;
|
2010-07-04 06:07:21 +00:00
|
|
|
status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
|
|
|
gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
icon_area.width = w;
|
|
|
|
icon_area.height = h;
|
|
|
|
text_renderer = get_text_renderer( st, cell );
|
|
|
|
g_object_set( text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
name_area.width = w;
|
|
|
|
name_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", status, "scale", SMALL_SCALE, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
stat_area.width = w;
|
|
|
|
stat_area.height = h;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
#define BAR_WIDTH 50
|
2009-03-02 23:31:01 +00:00
|
|
|
if( width != NULL )
|
2010-03-15 14:42:43 +00:00
|
|
|
*width = cell->parent.xpad * 2 + icon_area.width + GUI_PAD + name_area.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_area.width;
|
2009-03-02 23:31:01 +00:00
|
|
|
if( height != NULL )
|
2010-03-15 14:42:43 +00:00
|
|
|
*height = cell->parent.ypad * 2 + MAX( name_area.height, p->bar_height );
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_free( status );
|
2009-03-03 17:58:25 +00:00
|
|
|
g_object_unref( icon );
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX3(a,b,c) MAX(a,MAX(b,c))
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_size_full( TorrentCellRenderer * cell,
|
|
|
|
GtkWidget * widget,
|
|
|
|
gint * width,
|
|
|
|
gint * height )
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
GdkRectangle prog_area;
|
|
|
|
const char * name;
|
|
|
|
char * status;
|
|
|
|
char * progress;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
|
|
|
const tr_torrent * tor = p->tor;
|
|
|
|
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
|
|
|
const tr_info * inf = tr_torrentInfo( tor );
|
|
|
|
|
|
|
|
icon = get_icon( tor, FULL_ICON_SIZE, widget );
|
|
|
|
name = inf->name;
|
2010-07-04 06:07:21 +00:00
|
|
|
status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
2009-03-02 23:31:01 +00:00
|
|
|
progress = getProgressString( tor, inf, st );
|
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
|
|
|
gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
icon_area.width = w;
|
|
|
|
icon_area.height = h;
|
|
|
|
text_renderer = get_text_renderer( st, cell );
|
|
|
|
g_object_set( text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "scale", 1.0, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
name_area.width = w;
|
|
|
|
name_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", progress, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
prog_area.width = w;
|
|
|
|
prog_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", status, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
stat_area.width = w;
|
|
|
|
stat_area.height = h;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
|
|
|
if( width != NULL )
|
|
|
|
*width = cell->parent.xpad * 2 + icon_area.width + GUI_PAD + MAX3( name_area.width, prog_area.width, stat_area.width );
|
|
|
|
if( height != NULL )
|
|
|
|
*height = cell->parent.ypad * 2 + name_area.height + prog_area.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_area.height;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_free( status );
|
|
|
|
g_free( progress );
|
2009-03-03 17:58:25 +00:00
|
|
|
g_object_unref( icon );
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static void
|
2009-03-02 23:31:01 +00:00
|
|
|
torrent_cell_renderer_get_size( GtkCellRenderer * cell,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * cell_area,
|
|
|
|
gint * x_offset,
|
|
|
|
gint * y_offset,
|
|
|
|
gint * width,
|
|
|
|
gint * height )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
|
|
|
|
|
|
|
|
if( self && self->priv->tor )
|
|
|
|
{
|
2007-12-19 20:04:38 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2009-03-02 23:31:01 +00:00
|
|
|
int w, h;
|
2007-12-19 20:04:38 +00:00
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
if( p->compact )
|
|
|
|
get_size_compact( TORRENT_CELL_RENDERER( cell ), widget, &w, &h );
|
2007-12-19 18:11:10 +00:00
|
|
|
else
|
2009-03-02 23:31:01 +00:00
|
|
|
get_size_full( TORRENT_CELL_RENDERER( cell ), widget, &w, &h );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
if( width )
|
|
|
|
*width = w;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
if( height )
|
|
|
|
*height = h;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
if( cell_area ) {
|
2007-12-19 02:46:30 +00:00
|
|
|
if( x_offset ) *x_offset = 0;
|
2009-03-02 23:31:01 +00:00
|
|
|
if( y_offset ) {
|
|
|
|
*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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-15 14:42:43 +00:00
|
|
|
render_compact( TorrentCellRenderer * cell,
|
2009-03-02 23:31:01 +00:00
|
|
|
GdkDrawable * window,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * background_area,
|
|
|
|
GdkRectangle * cell_area UNUSED,
|
|
|
|
GdkRectangle * expose_area UNUSED,
|
|
|
|
GtkCellRendererState flags )
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
GdkRectangle prog_area;
|
|
|
|
GdkRectangle fill_area;
|
|
|
|
const char * name;
|
|
|
|
char * status;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
|
|
|
const tr_torrent * tor = p->tor;
|
|
|
|
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
|
|
|
const gboolean active = st->activity != TR_STATUS_STOPPED;
|
|
|
|
const double percentDone = MAX( 0.0, st->percentDone );
|
2009-08-13 14:23:47 +00:00
|
|
|
const gboolean sensitive = active || st->error;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
icon = get_icon( tor, COMPACT_ICON_SIZE, widget );
|
2009-03-02 23:31:01 +00:00
|
|
|
name = tr_torrentInfo( tor )->name;
|
2010-07-04 06:07:21 +00:00
|
|
|
status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the cell dimensions */
|
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
|
|
|
gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
icon_area.width = w;
|
|
|
|
icon_area.height = h;
|
|
|
|
text_renderer = get_text_renderer( st, cell );
|
|
|
|
g_object_set( text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
name_area.width = w;
|
|
|
|
name_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", status, "scale", SMALL_SCALE, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
stat_area.width = w;
|
|
|
|
stat_area.height = h;
|
2010-03-15 14:42:43 +00:00
|
|
|
prog_area.height = p->bar_height;
|
|
|
|
|
|
|
|
h = 1;
|
|
|
|
h = MAX( h, stat_area.height );
|
|
|
|
h = MAX( h, name_area.height );
|
|
|
|
h = MAX( h, icon_area.height );
|
|
|
|
h = MAX( h, prog_area.height );
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
|
|
|
fill_area = *background_area;
|
|
|
|
fill_area.x += cell->parent.xpad;
|
|
|
|
fill_area.y += cell->parent.ypad;
|
|
|
|
fill_area.width -= cell->parent.xpad * 2;
|
|
|
|
fill_area.height -= cell->parent.ypad * 2;
|
|
|
|
|
|
|
|
/* icon */
|
|
|
|
icon_area.x = fill_area.x;
|
2010-03-15 14:42:43 +00:00
|
|
|
icon_area.y = fill_area.y;
|
|
|
|
icon_area.height = h;
|
|
|
|
|
|
|
|
/* progressbar */
|
|
|
|
prog_area.x = fill_area.x + fill_area.width - BAR_WIDTH;
|
|
|
|
prog_area.y = fill_area.y;
|
|
|
|
prog_area.width = BAR_WIDTH;
|
|
|
|
prog_area.height = h;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* short status (right justified) */
|
2010-03-15 14:42:43 +00:00
|
|
|
stat_area.x = prog_area.x - GUI_PAD - stat_area.width;
|
|
|
|
stat_area.y = fill_area.y + ( h - stat_area.height ) / 2;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* name */
|
|
|
|
name_area.x = icon_area.x + icon_area.width + GUI_PAD;
|
2010-03-15 14:42:43 +00:00
|
|
|
name_area.y = fill_area.y + ( h - name_area.height ) / 2;
|
2009-03-02 23:31:01 +00:00
|
|
|
name_area.width = stat_area.x - GUI_PAD - name_area.x;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** RENDER
|
|
|
|
**/
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-08-13 14:23:47 +00:00
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
|
2010-03-15 14:42:43 +00:00
|
|
|
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive, NULL );
|
|
|
|
gtk_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
|
2009-08-13 14:23:47 +00:00
|
|
|
g_object_set( text_renderer, "text", status, "scale", SMALL_SCALE, "sensitive", sensitive, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_cell_renderer_render( text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
|
|
|
|
g_object_set( text_renderer, "text", name, "scale", 1.0, NULL );
|
|
|
|
gtk_cell_renderer_render( text_renderer, window, widget, &name_area, &name_area, &name_area, flags );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_free( status );
|
2009-03-03 17:58:25 +00:00
|
|
|
g_object_unref( icon );
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_full( TorrentCellRenderer * cell,
|
|
|
|
GdkDrawable * window,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * background_area,
|
|
|
|
GdkRectangle * cell_area UNUSED,
|
|
|
|
GdkRectangle * expose_area UNUSED,
|
|
|
|
GtkCellRendererState flags )
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GdkRectangle fill_area;
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
GdkRectangle prog_area;
|
|
|
|
GdkRectangle prct_area;
|
|
|
|
const char * name;
|
|
|
|
char * status;
|
|
|
|
char * progress;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
|
|
|
const tr_torrent * tor = p->tor;
|
|
|
|
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
|
|
|
const tr_info * inf = tr_torrentInfo( tor );
|
|
|
|
const gboolean active = st->activity != TR_STATUS_STOPPED;
|
|
|
|
const double percentDone = MAX( 0.0, st->percentDone );
|
2009-08-13 14:23:47 +00:00
|
|
|
const gboolean sensitive = active || st->error;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
icon = get_icon( tor, FULL_ICON_SIZE, widget );
|
|
|
|
name = inf->name;
|
2010-07-04 06:07:21 +00:00
|
|
|
status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
2009-03-02 23:31:01 +00:00
|
|
|
progress = getProgressString( tor, inf, st );
|
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
|
|
|
gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
icon_area.width = w;
|
|
|
|
icon_area.height = h;
|
|
|
|
text_renderer = get_text_renderer( st, cell );
|
|
|
|
g_object_set( text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
name_area.width = w;
|
|
|
|
name_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", progress, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
prog_area.width = w;
|
|
|
|
prog_area.height = h;
|
|
|
|
g_object_set( text_renderer, "text", status, NULL );
|
|
|
|
gtk_cell_renderer_get_size( text_renderer, widget, NULL, NULL, NULL, &w, &h );
|
|
|
|
stat_area.width = w;
|
|
|
|
stat_area.height = h;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
|
|
|
fill_area = *background_area;
|
|
|
|
fill_area.x += cell->parent.xpad;
|
|
|
|
fill_area.y += cell->parent.ypad;
|
|
|
|
fill_area.width -= cell->parent.xpad * 2;
|
|
|
|
fill_area.height -= cell->parent.ypad * 2;
|
|
|
|
|
|
|
|
/* icon */
|
|
|
|
icon_area.x = fill_area.x;
|
|
|
|
icon_area.y = fill_area.y + ( fill_area.height - icon_area.height ) / 2;
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
name_area.x = icon_area.x + icon_area.width + GUI_PAD;
|
|
|
|
name_area.y = fill_area.y;
|
|
|
|
name_area.width = fill_area.width - GUI_PAD - icon_area.width - GUI_PAD_SMALL;
|
|
|
|
|
|
|
|
/* prog */
|
|
|
|
prog_area.x = name_area.x;
|
|
|
|
prog_area.y = name_area.y + name_area.height;
|
|
|
|
prog_area.width = name_area.width;
|
|
|
|
|
|
|
|
/* progressbar */
|
|
|
|
prct_area.x = prog_area.x;
|
|
|
|
prct_area.y = prog_area.y + prog_area.height + GUI_PAD_SMALL;
|
|
|
|
prct_area.width = prog_area.width;
|
|
|
|
prct_area.height = p->bar_height;
|
|
|
|
|
|
|
|
/* status */
|
|
|
|
stat_area.x = prct_area.x;
|
|
|
|
stat_area.y = prct_area.y + prct_area.height + GUI_PAD_SMALL;
|
|
|
|
stat_area.width = prct_area.width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** RENDER
|
|
|
|
**/
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-08-13 14:23:47 +00:00
|
|
|
g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
|
2009-08-13 14:23:47 +00:00
|
|
|
g_object_set( text_renderer, "text", name, "scale", 1.0, "sensitive", sensitive, "ellipsize", PANGO_ELLIPSIZE_END, "weight", PANGO_WEIGHT_BOLD, NULL );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_cell_renderer_render( text_renderer, window, widget, &name_area, &name_area, &name_area, flags );
|
|
|
|
g_object_set( text_renderer, "text", progress, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
|
|
|
|
gtk_cell_renderer_render( text_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
|
2009-08-13 14:23:47 +00:00
|
|
|
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive, NULL );
|
2009-03-02 23:31:01 +00:00
|
|
|
gtk_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, &prct_area, &prct_area, flags );
|
|
|
|
g_object_set( text_renderer, "text", status, NULL );
|
|
|
|
gtk_cell_renderer_render( text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_free( status );
|
|
|
|
g_free( progress );
|
2009-03-03 17:58:25 +00:00
|
|
|
g_object_unref( icon );
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_cell_renderer_render( GtkCellRenderer * cell,
|
|
|
|
GdkDrawable * window,
|
|
|
|
GtkWidget * widget,
|
|
|
|
GdkRectangle * background_area,
|
|
|
|
GdkRectangle * cell_area,
|
|
|
|
GdkRectangle * expose_area,
|
|
|
|
GtkCellRendererState flags )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTextDirection real_dir = gtk_widget_get_direction( widget );
|
2008-02-16 19:36:07 +00:00
|
|
|
gtk_widget_set_direction( widget, GTK_TEXT_DIR_RTL );
|
|
|
|
#endif
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
if( self && self->priv->tor )
|
|
|
|
{
|
2007-12-19 20:04:38 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2010-03-15 14:42:43 +00:00
|
|
|
if( p->compact )
|
|
|
|
render_compact( self, window, widget, background_area, cell_area, expose_area, flags );
|
2007-12-19 20:04:38 +00:00
|
|
|
else
|
2009-03-02 23:31:01 +00:00
|
|
|
render_full( self, window, widget, background_area, cell_area, expose_area, flags );
|
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
|
2009-08-07 20:49:06 +00:00
|
|
|
torrent_cell_renderer_set_property( GObject * object,
|
2007-12-19 02:46:30 +00:00
|
|
|
guint property_id,
|
2007-12-19 18:11:10 +00:00
|
|
|
const GValue * v,
|
2009-08-07 20:49:06 +00:00
|
|
|
GParamSpec * pspec )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2009-08-07 20:49:06 +00:00
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER( object );
|
2007-12-19 02:46:30 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
|
|
|
switch( property_id )
|
|
|
|
{
|
2010-07-04 06:07:21 +00:00
|
|
|
case P_TORRENT: p->tor = g_value_get_pointer( v ); break;
|
|
|
|
case P_UPLOAD_SPEED: p->upload_speed_KBps = g_value_get_double( v ); break;
|
|
|
|
case P_DOWNLOAD_SPEED: p->download_speed_KBps = g_value_get_double( v ); break;
|
|
|
|
case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break;
|
|
|
|
case P_COMPACT: p->compact = g_value_get_boolean( v ); break;
|
2009-08-07 20:49:06 +00:00
|
|
|
default: G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec ); break;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-07 20:49:06 +00:00
|
|
|
torrent_cell_renderer_get_property( GObject * object,
|
|
|
|
guint property_id,
|
|
|
|
GValue * v,
|
|
|
|
GParamSpec * pspec )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2009-08-07 20:49:06 +00:00
|
|
|
const TorrentCellRenderer * self = TORRENT_CELL_RENDERER( object );
|
2007-12-19 02:46:30 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
|
|
|
switch( property_id )
|
|
|
|
{
|
2009-08-07 20:49:06 +00:00
|
|
|
case P_TORRENT: g_value_set_pointer( v, p->tor ); break;
|
2010-07-04 06:07:21 +00:00
|
|
|
case P_UPLOAD_SPEED: g_value_set_double( v, p->upload_speed_KBps ); break;
|
|
|
|
case P_DOWNLOAD_SPEED: g_value_set_double( v, p->download_speed_KBps ); break;
|
2009-08-07 20:49:06 +00:00
|
|
|
case P_BAR_HEIGHT: g_value_set_int( v, p->bar_height ); break;
|
2010-03-15 14:42:43 +00:00
|
|
|
case P_COMPACT: g_value_set_boolean( v, p->compact ); break;
|
2009-08-07 20:49:06 +00:00
|
|
|
default: G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec ); break;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 17:59:09 +00:00
|
|
|
static void
|
|
|
|
torrent_cell_renderer_dispose( GObject * o )
|
|
|
|
{
|
|
|
|
TorrentCellRenderer * r = TORRENT_CELL_RENDERER( o );
|
2008-09-23 19:11:04 +00:00
|
|
|
GObjectClass * parent;
|
2008-02-09 17:25:14 +00:00
|
|
|
|
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 ) );
|
2009-03-02 23:31:01 +00:00
|
|
|
g_object_unref( G_OBJECT( r->priv->icon_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 )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
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,
|
2008-09-23 19:11:04 +00:00
|
|
|
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,
|
2008-09-23 19:11:04 +00:00
|
|
|
g_param_spec_pointer( "torrent", NULL,
|
|
|
|
"tr_torrent*",
|
|
|
|
G_PARAM_READWRITE ) );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-08-07 20:49:06 +00:00
|
|
|
g_object_class_install_property( gobject_class, P_UPLOAD_SPEED,
|
2010-07-04 06:07:21 +00:00
|
|
|
g_param_spec_double( "piece-upload-speed", NULL,
|
|
|
|
"tr_stat.pieceUploadSpeed_KBps",
|
|
|
|
0, INT_MAX, 0,
|
|
|
|
G_PARAM_READWRITE ) );
|
2009-08-07 20:49:06 +00:00
|
|
|
|
|
|
|
g_object_class_install_property( gobject_class, P_DOWNLOAD_SPEED,
|
2010-07-04 06:07:21 +00:00
|
|
|
g_param_spec_double( "piece-download-speed", NULL,
|
|
|
|
"tr_stat.pieceDownloadSpeed_KBps",
|
|
|
|
0, INT_MAX, 0,
|
|
|
|
G_PARAM_READWRITE ) );
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
g_object_class_install_property( gobject_class, P_BAR_HEIGHT,
|
2008-09-23 19:11:04 +00:00
|
|
|
g_param_spec_int( "bar-height", NULL,
|
|
|
|
"Bar Height",
|
|
|
|
1, INT_MAX,
|
|
|
|
DEFAULT_BAR_HEIGHT,
|
|
|
|
G_PARAM_READWRITE ) );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2010-03-15 14:42:43 +00:00
|
|
|
g_object_class_install_property( gobject_class, P_COMPACT,
|
|
|
|
g_param_spec_boolean( "compact", NULL,
|
|
|
|
"Compact Mode",
|
2008-09-23 19:11:04 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE ) );
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
torrent_cell_renderer_init( GTypeInstance * instance,
|
|
|
|
gpointer g_class UNUSED )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER(
|
|
|
|
instance );
|
2007-12-19 02:46:30 +00:00
|
|
|
struct TorrentCellRendererPrivate * p;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(
|
|
|
|
self,
|
|
|
|
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( );
|
2009-03-02 23:31:01 +00:00
|
|
|
g_object_set( p->text_renderer, "xpad", 0, "ypad", 0, NULL );
|
2008-01-18 00:16:49 +00:00
|
|
|
p->text_renderer_err = gtk_cell_renderer_text_new( );
|
2009-03-02 23:31:01 +00:00
|
|
|
g_object_set( p->text_renderer_err, "xpad", 0, "ypad", 0, NULL );
|
2008-02-23 17:02:42 +00:00
|
|
|
p->progress_renderer = gtk_cell_renderer_progress_new( );
|
2009-03-02 23:31:01 +00:00
|
|
|
p->icon_renderer = gtk_cell_renderer_pixbuf_new( );
|
2008-01-18 00:16:49 +00:00
|
|
|
g_object_set( p->text_renderer_err, "foreground", "red", NULL );
|
2010-04-21 04:38:54 +00:00
|
|
|
gtr_object_ref_sink( p->text_renderer );
|
|
|
|
gtr_object_ref_sink( p->text_renderer_err );
|
|
|
|
gtr_object_ref_sink( p->progress_renderer );
|
|
|
|
gtr_object_ref_sink( p->icon_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 ),
|
2008-09-23 19:11:04 +00:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2007-12-19 02:46:30 +00:00
|
|
|
(GClassInitFunc)torrent_cell_renderer_class_init,
|
2008-09-23 19:11:04 +00:00
|
|
|
NULL, /* class_finalize
|
|
|
|
*/
|
|
|
|
NULL, /* class_data */
|
2007-12-19 02:46:30 +00:00
|
|
|
sizeof( TorrentCellRenderer ),
|
2008-09-23 19:11:04 +00:00
|
|
|
0, /* n_preallocs */
|
2007-12-19 02:46:30 +00:00
|
|
|
(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 )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
return (GtkCellRenderer *) g_object_new( TORRENT_CELL_RENDERER_TYPE,
|
|
|
|
NULL );
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|