summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2012-08-24 15:48:35 +0100
committerGravatar Alan Fitton <ajf@eth0.org.uk>2012-08-24 15:48:35 +0100
commitf947bb4f8265cd3053c8f993a327fa6a7d45b836 (patch)
tree96f6c094ed5816e8a284dc226e00636316f8ef8b /src
parentb0ad42a97cc5fb962d229b9c9743989e2f47216f (diff)
new renderer mostly complete now
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/protocol-constants.h1
-rw-r--r--src/requests.c2
-rw-r--r--src/torrent-cell-renderer.c91
-rw-r--r--src/torrent.c4
-rw-r--r--src/torrent.h1
-rw-r--r--src/trg-torrent-model.c6
-rw-r--r--src/trg-torrent-model.h2
-rw-r--r--src/trg-torrent-tree-view.c2
9 files changed, 76 insertions, 35 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fe20953..0c1abd6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,7 +44,7 @@ desktop_DATA = transmission-remote-gtk.desktop
endif
bin_PROGRAMS = transmission-remote-gtk
-INCLUDES = -std=c99 --pedantic -Wall -I.. -Wno-overflow -DTRGLICENSE=\""$(trglicense)"\" $(libcurl_CFLAGS) $(jsonglib_CFLAGS) $(gthread_CFLAGS) $(gtk_CFLAGS) $(gio_CFLAGS) $(unique_CFLAGS) $(notify_CFLAGS) $(libproxy_CFLAGS) $(libappindicator_CFLAGS)
+INCLUDES = -std=c99 -Wall -I.. -Wno-overflow -DTRGLICENSE=\""$(trglicense)"\" $(libcurl_CFLAGS) $(jsonglib_CFLAGS) $(gthread_CFLAGS) $(gtk_CFLAGS) $(gio_CFLAGS) $(unique_CFLAGS) $(notify_CFLAGS) $(libproxy_CFLAGS) $(libappindicator_CFLAGS)
transmission_remote_gtk_SOURCES = \
trg-cell-renderer-speed.c \
diff --git a/src/protocol-constants.h b/src/protocol-constants.h
index 293a937..43b68f4 100644
--- a/src/protocol-constants.h
+++ b/src/protocol-constants.h
@@ -62,6 +62,7 @@
#define FIELD_PEERSFROM "peersFrom"
#define FIELD_FILES "files"
#define FIELD_WANTED "wanted"
+#define FIELD_WEB_SEEDS_SENDING_TO_US "webseedsSendingToUs"
#define FIELD_PRIORITIES "priorities"
#define FIELD_COMMENT "comment"
#define FIELD_LEFTUNTILDONE "leftUntilDone"
diff --git a/src/requests.c b/src/requests.c
index d0e4222..702319f 100644
--- a/src/requests.c
+++ b/src/requests.c
@@ -168,6 +168,7 @@ JsonNode *torrent_get(gint64 id)
json_array_add_string_element(fields, FIELD_FILES);
json_array_add_string_element(fields, FIELD_PEERS_SENDING_TO_US);
json_array_add_string_element(fields, FIELD_PEERS_GETTING_FROM_US);
+ json_array_add_string_element(fields, FIELD_WEB_SEEDS_SENDING_TO_US);
json_array_add_string_element(fields, FIELD_PEERS_CONNECTED);
json_array_add_string_element(fields, FIELD_HAVEVALID);
json_array_add_string_element(fields, FIELD_HAVEUNCHECKED);
@@ -186,6 +187,7 @@ JsonNode *torrent_get(gint64 id)
json_array_add_string_element(fields, FIELD_PERCENTDONE);
json_array_add_string_element(fields, FIELD_COMMENT);
json_array_add_string_element(fields, FIELD_TOTAL_SIZE);
+ json_array_add_string_element(fields, FIELD_METADATAPERCENTCOMPLETE);
json_array_add_string_element(fields, FIELD_LEFT_UNTIL_DONE);
json_array_add_string_element(fields, FIELD_ANNOUNCE_URL);
json_array_add_string_element(fields, FIELD_ERROR_STRING);
diff --git a/src/torrent-cell-renderer.c b/src/torrent-cell-renderer.c
index bdac1d8..d590be5 100644
--- a/src/torrent-cell-renderer.c
+++ b/src/torrent-cell-renderer.c
@@ -37,9 +37,11 @@ enum
P_TOTALSIZE,
P_UPLOADED,
P_PERCENTCOMPLETE,
+ P_METADATAPERCENTCOMPLETE,
P_UPSPEED,
P_DOWNSPEED,
P_PEERSGETTINGFROMUS,
+ P_WEBSEEDSTOUS,
P_PEERSTOUS,
P_ETA,
P_JSON,
@@ -100,10 +102,12 @@ struct TorrentCellRendererPrivate
gint64 downSpeed;
gpointer json;
gdouble done;
+ gdouble metadataPercentComplete;
gdouble ratio;
guint flags;
const gchar *name;
gint64 peersFromUs;
+ gint64 webSeedsToUs;
gint64 peersToUs;
gint64 connected;
guint fileCount;
@@ -227,11 +231,9 @@ getShortTransferString( TorrentCellRenderer * r,
struct TorrentCellRendererPrivate *priv = r->priv;
char downStr[32], upStr[32];
- //const int haveMeta = tr_torrentHasMetadata( tor );
- //const int haveUp = haveMeta && st->peersGettingFromUs > 0;
- //const int haveDown = haveMeta && ( ( st->peersSendingToUs > 0 ) || ( st->webseedsSendingToUs > 0 ) );
- const int haveUp = priv->peersFromUs > 0;
- const int haveDown = priv->peersToUs > 0;
+ const gboolean haveMeta = priv->fileCount > 0;
+ const gboolean haveUp = haveMeta && priv->peersFromUs > 0;
+ const gboolean haveDown = haveMeta && priv->peersToUs > 0;
if( haveDown )
tr_formatter_speed_KBps( downStr, priv->downSpeed, sizeof( downStr ) );
@@ -252,9 +254,9 @@ getShortTransferString( TorrentCellRenderer * r,
g_snprintf( buf, buflen, _( "%1$s %2$s" ),
GTR_UNICODE_UP, upStr );
/*else if( st->isStalled )
- g_strlcpy( buf, _( "Stalled" ), buflen );
+ g_strlcpy( buf, _( "Stalled" ), buflen );*/
else if( haveMeta )
- g_strlcpy( buf, _( "Idle" ), buflen );*/
+ g_strlcpy( buf, _( "Idle" ), buflen );
else
*buf = '\0';
@@ -277,8 +279,9 @@ getShortStatusString( GString * gstr,
} else if (flags & TORRENT_FLAG_SEEDING_WAIT) {
g_string_append( gstr, _( "Queued for seeding" ) );
} else if (flags & TORRENT_FLAG_CHECKING) {
- g_string_append_printf( gstr, _( "Verifying data (%.1f% tested)" ),
- tr_truncd( priv->done * 100.0, 1 ) );
+ char buf1[32];
+ g_string_append_printf( gstr, _( "Verifying data (%1$s tested)" ),
+ tr_strlpercent( buf1, priv->done, sizeof( buf1 ) ) );
} else if ((flags & TORRENT_FLAG_DOWNLOADING) || (flags & TORRENT_FLAG_SEEDING)) {
char buf[512];
if( flags & ~TORRENT_FLAG_DOWNLOADING )
@@ -297,8 +300,7 @@ getStatusString( GString * gstr,
TorrentCellRenderer * r )
{
struct TorrentCellRendererPrivate *priv = r->priv;
-
- //TODO: handle metadata for downloading
+ char buf[256];
if ( priv->error ) {
const char * fmt[] = { NULL, N_( "Tracker gave a warning: \"%s\"" ),
@@ -306,16 +308,24 @@ getStatusString( GString * gstr,
N_( "Error: %s" ) };
g_string_append_printf( gstr, _( fmt[priv->error] ), torrent_get_errorstr(priv->json) );
} else if (priv->flags & TORRENT_FLAG_DOWNLOADING) {
- g_string_append_printf( gstr,
- ngettext( "Downloading from %1$'d of %2$'d connected peer",
- "Downloading from %1$'d of %2$'d connected peers",
- priv->peersToUs ),
- priv->peersToUs,
- priv->connected );
+ if (priv->fileCount > 0) {
+ g_string_append_printf( gstr,
+ ngettext( "Downloading from %1$li of %2$li connected peer",
+ "Downloading from %1$li of %2$li connected peers",
+ priv->webSeedsToUs + priv->peersToUs ),
+ priv->webSeedsToUs + priv->peersToUs,
+ priv->webSeedsToUs + priv->connected );
+ } else {
+ g_string_append_printf( gstr,
+ ngettext( "Downloading metadata from %1$li peer (%2$s done)",
+ "Downloading metadata from %1$li peers (%2$s done)",
+ priv->connected + priv->webSeedsToUs ),
+ priv->connected + priv->webSeedsToUs, tr_strlpercent( buf, priv->metadataPercentComplete, sizeof(buf) ) );
+ }
} else if (priv->flags & TORRENT_FLAG_SEEDING) {
g_string_append_printf( gstr,
- ngettext( "Seeding to %1$'d of %2$'d connected peer",
- "Seeding to %1$'d of %2$'d connected peers",
+ ngettext( "Seeding to %1$li of %2$li connected peer",
+ "Seeding to %1$li of %2$li connected peers",
priv->connected ),
priv->peersFromUs,
priv->connected );
@@ -327,7 +337,6 @@ getStatusString( GString * gstr,
( priv->flags & ~TORRENT_FLAG_SEEDING_WAIT ) &&
( priv->flags & ~TORRENT_FLAG_PAUSED ) )
{
- char buf[256];
getShortTransferString( r, buf, sizeof( buf ) );
if( *buf )
g_string_append_printf( gstr, " - %s", buf );
@@ -522,18 +531,16 @@ get_text_color( GtkWidget * w, TorrentCellRenderer *r, GtrColor * setme )
gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_NORMAL, setme );
}
-/*static double
+static double
get_percent_done( TorrentCellRenderer *r, gboolean * seed )
{
struct TorrentCellRendererPrivate *priv = r->priv;
double d;
- //TODO: handle seed ratios
-
- if( ( priv->flags & TORRENT_FLAG_SEEDING ) && tr_torrentGetSeedRatio( tor, &d ) )
+ if( ( priv->flags & TORRENT_FLAG_SEEDING ) && getSeedRatio( r, &d ) )
{
- *seed = true;
- d = MAX( 0.0, st->seedRatioPercentDone );
+ *seed = TRUE;
+ d = MAX( 0.0, (priv->ratio/d)*100 );
}
else
{
@@ -542,7 +549,7 @@ get_percent_done( TorrentCellRenderer *r, gboolean * seed )
}
return d;
-}*/
+}
static void
gtr_cell_renderer_render( GtkCellRenderer * renderer,
@@ -614,6 +621,9 @@ static void torrent_cell_renderer_set_property(GObject * object,
case P_PEERSGETTINGFROMUS:
p->peersFromUs = g_value_get_int64(v);
break;
+ case P_WEBSEEDSTOUS:
+ p->webSeedsToUs = g_value_get_int64(v);
+ break;
case P_CONNECTED:
p->connected = g_value_get_int64(v);
break;
@@ -638,6 +648,9 @@ static void torrent_cell_renderer_set_property(GObject * object,
case P_PERCENTCOMPLETE:
p->done = g_value_get_double(v);
break;
+ case P_METADATAPERCENTCOMPLETE:
+ p->metadataPercentComplete = g_value_get_double(v);
+ break;
case P_BAR_HEIGHT:
p->bar_height = g_value_get_int(v);
break;
@@ -755,6 +768,11 @@ torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
0, 100.00, 0,
G_PARAM_READWRITE ) );
+ g_object_class_install_property( gobject_class, P_METADATAPERCENTCOMPLETE,
+ g_param_spec_double( "metadataPercentComplete", NULL,
+ "metadataPercentComplete",
+ 0, 100.00, 0,
+ G_PARAM_READWRITE ) );
g_object_class_install_property( gobject_class, P_TOTALSIZE,
g_param_spec_int64( "totalSize", NULL,
@@ -834,6 +852,12 @@ torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
-1, G_MAXINT64, 0,
G_PARAM_READWRITE ) );
+ g_object_class_install_property( gobject_class, P_WEBSEEDSTOUS,
+ g_param_spec_int64( "webSeedsToUs", NULL,
+ "webSeedsToUs",
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE ) );
+
g_object_class_install_property( gobject_class, P_ETA,
g_param_spec_int64( "eta", NULL,
"eta",
@@ -909,12 +933,11 @@ render_compact( TorrentCellRenderer * cell,
GdkRectangle fill_area;
GdkPixbuf * icon;
GtrColor text_color;
- //TODO
- //gboolean seed;
+ gboolean seed;
struct TorrentCellRendererPrivate * p = cell->priv;
const gboolean active = ( p->flags & ~TORRENT_FLAG_PAUSED ) && ( p->flags & ~TORRENT_FLAG_DOWNLOADING_WAIT ) && ( p->flags & ~TORRENT_FLAG_SEEDING_WAIT );
-
+ const double percentDone = get_percent_done( cell, &seed );
const gboolean sensitive = active || p->error;
GString * gstr_stat = p->gstr1;
@@ -956,7 +979,7 @@ render_compact( TorrentCellRenderer * cell,
g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
gtr_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, flags );
- g_object_set( p->progress_renderer, "value", (gint)p->done, "text", NULL, "sensitive", sensitive, NULL );
+ g_object_set( p->progress_renderer, "value", (gint)percentDone, "text", NULL, "sensitive", sensitive, NULL );
gtr_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, flags );
g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, FOREGROUND_COLOR_KEY, &text_color, NULL );
gtr_cell_renderer_render( p->text_renderer, window, widget, &stat_area, flags );
@@ -985,12 +1008,12 @@ render_full( TorrentCellRenderer * cell,
GdkRectangle prct_area;
GdkPixbuf * icon;
GtrColor text_color;
- //TODO
- //gboolean seed;
+ gboolean seed;
struct TorrentCellRendererPrivate * p = cell->priv;
const gboolean active = ( p->flags & ~TORRENT_FLAG_PAUSED ) && ( p->flags & ~TORRENT_FLAG_DOWNLOADING_WAIT ) && ( p->flags & ~TORRENT_FLAG_SEEDING_WAIT );
const gboolean sensitive = active || p->error;
+ const double percentDone = get_percent_done( cell, &seed );
GString * gstr_prog = p->gstr1;
GString * gstr_stat = p->gstr2;
@@ -1065,7 +1088,7 @@ render_full( TorrentCellRenderer * cell,
gtr_cell_renderer_render( p->text_renderer, window, widget, &name_area, flags );
g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
gtr_cell_renderer_render( p->text_renderer, window, widget, &prog_area, flags );
- g_object_set( p->progress_renderer, "value", (gint)p->done, /*"text", "",*/ "sensitive", sensitive, NULL );
+ g_object_set( p->progress_renderer, "value", (gint)percentDone, /*"text", "",*/ "sensitive", sensitive, NULL );
gtr_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, flags );
g_object_set( p->text_renderer, "text", gstr_stat->str, FOREGROUND_COLOR_KEY, &text_color, NULL );
gtr_cell_renderer_render( p->text_renderer, window, widget, &stat_area, flags );
diff --git a/src/torrent.c b/src/torrent.c
index 025118a..d35be51 100644
--- a/src/torrent.c
+++ b/src/torrent.c
@@ -451,6 +451,10 @@ gint64 torrent_get_peers_getting_from_us(JsonObject * args)
return json_object_get_int_member(args, FIELD_PEERS_GETTING_FROM_US);
}
+gint64 torrent_get_web_seeds_sending_to_us(JsonObject *args) {
+ return json_object_get_int_member(args, FIELD_WEB_SEEDS_SENDING_TO_US);
+}
+
gint64 torrent_get_queue_position(JsonObject * args)
{
if (json_object_has_member(args, FIELD_QUEUE_POSITION))
diff --git a/src/torrent.h b/src/torrent.h
index 163df39..ae6c432 100644
--- a/src/torrent.h
+++ b/src/torrent.h
@@ -72,6 +72,7 @@ gint64 torrent_get_id(JsonObject * t);
JsonArray *torrent_get_files(JsonObject * args);
gint64 torrent_get_peers_getting_from_us(JsonObject * args);
gint64 torrent_get_peers_sending_to_us(JsonObject * args);
+gint64 torrent_get_web_seeds_sending_to_us(JsonObject *args);
gint64 torrent_get_peers_connected(JsonObject * args);
gdouble torrent_get_percent_done(JsonObject * t);
gdouble torrent_get_recheck_progress(JsonObject * t);
diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c
index 0499f05..a9e8d7c 100644
--- a/src/trg-torrent-model.c
+++ b/src/trg-torrent-model.c
@@ -207,6 +207,7 @@ static void trg_torrent_model_init(TrgTorrentModel * self)
column_types[TORRENT_COLUMN_TOTALSIZE] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_HAVE_UNCHECKED] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_PERCENTDONE] = G_TYPE_DOUBLE;
+ column_types[TORRENT_COLUMN_METADATAPERCENTCOMPLETE] = G_TYPE_DOUBLE;
column_types[TORRENT_COLUMN_STATUS] = G_TYPE_STRING;
column_types[TORRENT_COLUMN_SEEDS] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_LEECHERS] = G_TYPE_INT64;
@@ -238,6 +239,7 @@ static void trg_torrent_model_init(TrgTorrentModel * self)
column_types[TORRENT_COLUMN_SEED_RATIO_MODE] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_PEERS_CONNECTED] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_PEERS_FROM_US] = G_TYPE_INT64;
+ column_types[TORRENT_COLUMN_WEB_SEEDS_TO_US] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_PEERS_TO_US] = G_TYPE_INT64;
column_types[TORRENT_COLUMN_TRACKERHOST] = G_TYPE_STRING;
column_types[TORRENT_COLUMN_QUEUE_POSITION] = G_TYPE_INT64;
@@ -490,6 +492,8 @@ update_torrent_iter(TrgTorrentModel * model,
(newFlags & TORRENT_FLAG_CHECKING) ?
torrent_get_recheck_progress(t)
: torrent_get_percent_done(t),
+ TORRENT_COLUMN_METADATAPERCENTCOMPLETE,
+ torrent_get_metadata_percent_complete(t),
TORRENT_COLUMN_STATUS, statusString,
TORRENT_COLUMN_DOWNSPEED, downRate,
TORRENT_COLUMN_FLAGS, newFlags,
@@ -514,6 +518,8 @@ update_torrent_iter(TrgTorrentModel * model,
torrent_get_peers_sending_to_us(t),
TORRENT_COLUMN_PEERS_FROM_US,
torrent_get_peers_getting_from_us(t),
+ TORRENT_COLUMN_WEB_SEEDS_TO_US,
+ torrent_get_web_seeds_sending_to_us(t),
TORRENT_COLUMN_QUEUE_POSITION,
torrent_get_queue_position(t),
TORRENT_COLUMN_SEED_RATIO_LIMIT, torrent_get_seed_ratio_limit(t),
diff --git a/src/trg-torrent-model.h b/src/trg-torrent-model.h
index 0367206..05862e4 100644
--- a/src/trg-torrent-model.h
+++ b/src/trg-torrent-model.h
@@ -106,12 +106,14 @@ enum {
TORRENT_COLUMN_NAME,
TORRENT_COLUMN_SIZEWHENDONE,
TORRENT_COLUMN_PERCENTDONE,
+ TORRENT_COLUMN_METADATAPERCENTCOMPLETE,
TORRENT_COLUMN_STATUS,
TORRENT_COLUMN_SEEDS,
TORRENT_COLUMN_LEECHERS,
TORRENT_COLUMN_DOWNLOADS,
TORRENT_COLUMN_PEERS_CONNECTED,
TORRENT_COLUMN_PEERS_FROM_US,
+ TORRENT_COLUMN_WEB_SEEDS_TO_US,
TORRENT_COLUMN_PEERS_TO_US,
TORRENT_COLUMN_DOWNSPEED,
TORRENT_COLUMN_UPSPEED,
diff --git a/src/trg-torrent-tree-view.c b/src/trg-torrent-tree-view.c
index c181e4d..b2b5ac1 100644
--- a/src/trg-torrent-tree-view.c
+++ b/src/trg-torrent-tree-view.c
@@ -178,10 +178,12 @@ static void setup_classic_layout(TrgClient *tc, TrgTorrentTreeView *tv)
"sizeWhenDone", TORRENT_COLUMN_SIZEWHENDONE,
"uploaded", TORRENT_COLUMN_UPLOADED,
"percentComplete", TORRENT_COLUMN_PERCENTDONE,
+ "metadataPercentComplete", TORRENT_COLUMN_METADATAPERCENTCOMPLETE,
"upSpeed", TORRENT_COLUMN_UPSPEED,
"downSpeed", TORRENT_COLUMN_DOWNSPEED,
"peersToUs", TORRENT_COLUMN_PEERS_TO_US,
"peersGettingFromUs", TORRENT_COLUMN_PEERS_FROM_US,
+ "webSeedsToUs", TORRENT_COLUMN_WEB_SEEDS_TO_US,
"eta", TORRENT_COLUMN_ETA,
"json", TORRENT_COLUMN_JSON,
"seedRatioMode", TORRENT_COLUMN_SEED_RATIO_MODE,