2008-02-10 22:25:42 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
|
2007-06-06 00:30:13 +00:00
|
|
|
*
|
2008-02-10 22:25:42 +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.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2007-07-19 03:55:00 +00:00
|
|
|
#include <stdio.h>
|
2007-06-06 00:30:13 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
#include "actions.h"
|
2008-02-19 03:57:03 +00:00
|
|
|
#include "details.h"
|
2008-02-10 22:25:42 +00:00
|
|
|
#include "file-list.h"
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "tr_torrent.h"
|
|
|
|
#include "hig.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2007-11-18 17:28:36 +00:00
|
|
|
#define UPDATE_INTERVAL_MSEC 2000
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
/****
|
|
|
|
***** PIECES VIEW
|
|
|
|
****/
|
|
|
|
|
|
|
|
static int
|
|
|
|
getGridSize (int pieceCount, int * n_rows, int * n_cols)
|
|
|
|
{
|
|
|
|
const int MAX_ACROSS = 16;
|
|
|
|
if (pieceCount >= (MAX_ACROSS * MAX_ACROSS)) {
|
|
|
|
*n_rows = *n_cols = MAX_ACROSS;
|
|
|
|
return MAX_ACROSS * MAX_ACROSS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
for (i=0; (i*i) < pieceCount; ++i);
|
|
|
|
*n_rows = *n_cols = i;
|
|
|
|
return pieceCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TO16(a) ((guint16)((a<<8)|(a)))
|
|
|
|
#define RGB_2_GDK(R,G,B) { 0, TO16(R), TO16(G), TO16(B) }
|
|
|
|
|
|
|
|
enum { DRAW_AVAIL, DRAW_PROG };
|
|
|
|
|
|
|
|
static void
|
|
|
|
release_gobject_array (gpointer data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GObject **objects = (GObject**) data;
|
|
|
|
for (i=0; objects[i]!=NULL; ++i)
|
|
|
|
g_object_unref (G_OBJECT(objects[i]));
|
|
|
|
g_free (objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-02-16 19:36:07 +00:00
|
|
|
refresh_pieces( GtkWidget * da, GdkEventExpose * event UNUSED, gpointer gtor )
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( TR_TORRENT(gtor) );
|
|
|
|
const tr_info * info = tr_torrent_info( TR_TORRENT(gtor) );
|
2007-06-06 00:30:13 +00:00
|
|
|
int mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(da), "draw-mode"));
|
|
|
|
|
|
|
|
GdkColormap * colormap = gtk_widget_get_colormap (da);
|
|
|
|
const int widget_w = da->allocation.width;
|
|
|
|
const int widget_h = da->allocation.height;
|
|
|
|
int n_rows, n_cols;
|
|
|
|
const int n_cells = getGridSize (info->pieceCount, &n_rows, &n_cols);
|
|
|
|
const GdkRectangle grid_bounds = { 0, 0, widget_w, widget_h };
|
|
|
|
const double piece_w = grid_bounds.width / (double)n_cols;
|
|
|
|
const double piece_h = grid_bounds.height / (double)n_rows;
|
|
|
|
const int piece_w_int = (int) (piece_w + 1); /* pad for roundoff */
|
|
|
|
const int piece_h_int = (int) (piece_h + 1); /* pad for roundoff */
|
2008-02-16 19:36:07 +00:00
|
|
|
const gboolean rtl = gtk_widget_get_direction( da ) == GTK_TEXT_DIR_RTL;
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
guint8 * prev_color = NULL;
|
|
|
|
gboolean first_time = FALSE;
|
|
|
|
|
|
|
|
int i, x, y;
|
|
|
|
int8_t * pieces = NULL;
|
|
|
|
float * completeness = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Get the Graphics Contexts...
|
|
|
|
**/
|
|
|
|
|
|
|
|
enum { ALL, LOTS, SOME, FEW, NONE,
|
|
|
|
BLACK, GRAY, BLINK,
|
|
|
|
N_COLORS };
|
|
|
|
GdkGC **gcs = (GdkGC**) g_object_get_data (G_OBJECT(da), "graphics-contexts");
|
|
|
|
if (gcs == NULL)
|
|
|
|
{
|
|
|
|
const GdkColor colors [N_COLORS] = {
|
2007-10-10 19:41:48 +00:00
|
|
|
RGB_2_GDK ( 114, 159, 207 ), /* all */
|
|
|
|
RGB_2_GDK ( 52, 101, 164 ), /* lots */
|
|
|
|
RGB_2_GDK ( 32, 74, 135 ), /* some */
|
|
|
|
RGB_2_GDK ( 85, 87, 83 ), /* few */
|
|
|
|
RGB_2_GDK ( 238, 238, 236 ), /* none - tango aluminum highlight */
|
|
|
|
RGB_2_GDK ( 46, 52, 54 ), /* black - tango slate shadow */
|
|
|
|
RGB_2_GDK ( 186, 189, 182 ), /* gray - tango aluminum shadow */
|
|
|
|
RGB_2_GDK ( 252, 233, 79 ), /* blink - tango butter highlight */
|
2007-06-06 00:30:13 +00:00
|
|
|
};
|
|
|
|
|
2007-08-08 06:19:13 +00:00
|
|
|
gcs = g_new (GdkGC*, N_COLORS+1);
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
for (i=0; i<N_COLORS; ++i) {
|
|
|
|
gcs[i] = gdk_gc_new (da->window);
|
|
|
|
gdk_gc_set_colormap (gcs[i], colormap);
|
|
|
|
gdk_gc_set_rgb_fg_color (gcs[i], &colors[i]);
|
|
|
|
gdk_gc_set_rgb_bg_color (gcs[i], &colors[i]);
|
|
|
|
};
|
|
|
|
|
|
|
|
gcs[N_COLORS] = NULL; /* a sentinel in the release function */
|
|
|
|
g_object_set_data_full (G_OBJECT(da), "graphics-contexts",
|
|
|
|
gcs, release_gobject_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Get the cells' previous colors...
|
|
|
|
*** (this is used for blinking when the color changes)
|
|
|
|
**/
|
|
|
|
|
|
|
|
prev_color = (guint8*) g_object_get_data (G_OBJECT(da), "prev-color");
|
|
|
|
if (prev_color == NULL)
|
|
|
|
{
|
|
|
|
first_time = TRUE;
|
|
|
|
prev_color = g_new0 (guint8, n_cells);
|
|
|
|
g_object_set_data_full (G_OBJECT(da), "prev-color", prev_color, g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Get the piece data values...
|
|
|
|
**/
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case DRAW_AVAIL:
|
2007-07-18 17:28:25 +00:00
|
|
|
pieces = g_new (int8_t, n_cells);
|
2007-06-06 00:30:13 +00:00
|
|
|
tr_torrentAvailability ( tor, pieces, n_cells );
|
|
|
|
break;
|
|
|
|
case DRAW_PROG:
|
|
|
|
completeness = g_new (float, n_cells);
|
|
|
|
tr_torrentAmountFinished ( tor, completeness, n_cells );
|
|
|
|
break;
|
|
|
|
default: g_error("no mode defined!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*** Draw...
|
|
|
|
**/
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (y=0; y<n_rows; ++y) {
|
|
|
|
for (x=0; x<n_cols; ++x) {
|
2008-02-16 19:36:07 +00:00
|
|
|
int draw_x = grid_bounds.x + (int)(x * piece_w);
|
|
|
|
int draw_y = grid_bounds.y + (int)(y * piece_h);
|
2007-06-06 00:30:13 +00:00
|
|
|
int color = BLACK;
|
|
|
|
int border = BLACK;
|
|
|
|
|
2008-02-16 19:36:07 +00:00
|
|
|
if( rtl )
|
|
|
|
draw_x = grid_bounds.x + grid_bounds.width - (int)((x+1) * piece_w);
|
|
|
|
else
|
|
|
|
draw_x = grid_bounds.x + (int)(x * piece_w);
|
|
|
|
draw_y = grid_bounds.y + (int)(y * piece_h);
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
if (i < n_cells)
|
|
|
|
{
|
|
|
|
border = GRAY;
|
|
|
|
|
|
|
|
if (mode == DRAW_AVAIL) {
|
|
|
|
const int8_t val = pieces[i];
|
|
|
|
if (val < 0) color = ALL;
|
|
|
|
else if (val == 0) color = NONE;
|
|
|
|
else if (val <= 4) color = FEW;
|
|
|
|
else if (val <= 8) color = SOME;
|
|
|
|
else color = LOTS;
|
|
|
|
} else { /* completeness */
|
|
|
|
const float val = completeness[i];
|
|
|
|
if (val >= 1.00) color = ALL;
|
|
|
|
else if (val >= 0.66) color = LOTS;
|
|
|
|
else if (val >= 0.33) color = SOME;
|
|
|
|
else if (val >= 0.01) color = FEW;
|
|
|
|
else color = NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw a "blink" for one interval when a piece changes */
|
|
|
|
if (first_time)
|
|
|
|
prev_color[i] = color;
|
|
|
|
else if (color != prev_color[i]) {
|
|
|
|
prev_color[i] = color;
|
|
|
|
color = border = BLINK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_draw_rectangle (da->window, gcs[color], TRUE,
|
|
|
|
draw_x, draw_y,
|
|
|
|
piece_w_int, piece_h_int);
|
|
|
|
|
|
|
|
if (i < n_cells)
|
|
|
|
gdk_draw_rectangle (da->window, gcs[border], FALSE,
|
|
|
|
draw_x, draw_y,
|
|
|
|
piece_w_int, piece_h_int);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_draw_rectangle (da->window, gcs[GRAY], FALSE,
|
|
|
|
grid_bounds.x, grid_bounds.y,
|
2007-06-18 03:40:41 +00:00
|
|
|
grid_bounds.width-1, grid_bounds.height-1);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
g_free (pieces);
|
|
|
|
g_free (completeness);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
***** PEERS TAB
|
|
|
|
****/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PEER_COL_ADDRESS,
|
|
|
|
PEER_COL_CLIENT,
|
|
|
|
PEER_COL_PROGRESS,
|
2007-09-20 16:32:01 +00:00
|
|
|
PEER_COL_IS_ENCRYPTED,
|
2007-06-06 00:30:13 +00:00
|
|
|
PEER_COL_DOWNLOAD_RATE,
|
|
|
|
PEER_COL_UPLOAD_RATE,
|
2007-11-17 23:43:33 +00:00
|
|
|
PEER_COL_STATUS,
|
2007-06-06 00:30:13 +00:00
|
|
|
N_PEER_COLS
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* peer_column_names[N_PEER_COLS] =
|
|
|
|
{
|
|
|
|
N_("Address"),
|
|
|
|
N_("Client"),
|
2008-01-20 17:18:28 +00:00
|
|
|
N_("%"),
|
2007-06-20 15:55:27 +00:00
|
|
|
" ",
|
2008-01-20 17:18:28 +00:00
|
|
|
N_("Down"),
|
|
|
|
N_("Up"),
|
2007-11-17 23:43:33 +00:00
|
|
|
N_("Status")
|
2007-06-06 00:30:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int compare_peers (const void * a, const void * b)
|
|
|
|
{
|
2007-09-20 20:14:13 +00:00
|
|
|
const tr_peer_stat * pa = a;
|
|
|
|
const tr_peer_stat * pb = b;
|
2007-06-06 00:30:13 +00:00
|
|
|
return strcmp (pa->addr, pb->addr);
|
|
|
|
}
|
|
|
|
static int compare_addr_to_peer (const void * a, const void * b)
|
|
|
|
{
|
|
|
|
const char * addr = (const char *) a;
|
2007-09-20 20:14:13 +00:00
|
|
|
const tr_peer_stat * peer = b;
|
2007-06-06 00:30:13 +00:00
|
|
|
return strcmp (addr, peer->addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-20 20:14:13 +00:00
|
|
|
peer_row_set (GtkTreeStore * store,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
const tr_peer_stat * peer)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2007-06-09 15:20:32 +00:00
|
|
|
const char * client = peer->client;
|
|
|
|
|
|
|
|
if (!client || !strcmp(client,"Unknown Client"))
|
2007-06-20 15:55:27 +00:00
|
|
|
client = " ";
|
2007-06-09 15:20:32 +00:00
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_tree_store_set (store, iter,
|
|
|
|
PEER_COL_ADDRESS, peer->addr,
|
2007-06-09 15:20:32 +00:00
|
|
|
PEER_COL_CLIENT, client,
|
2007-09-20 16:32:01 +00:00
|
|
|
PEER_COL_IS_ENCRYPTED, peer->isEncrypted,
|
2007-11-29 17:14:28 +00:00
|
|
|
PEER_COL_PROGRESS, (int)(100.0*peer->progress),
|
2007-06-06 00:30:13 +00:00
|
|
|
PEER_COL_DOWNLOAD_RATE, peer->downloadFromRate,
|
|
|
|
PEER_COL_UPLOAD_RATE, peer->uploadToRate,
|
2008-01-09 17:33:43 +00:00
|
|
|
PEER_COL_STATUS, peer->flagStr,
|
2007-06-06 00:30:13 +00:00
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-20 20:14:13 +00:00
|
|
|
append_peers_to_model (GtkTreeStore * store,
|
|
|
|
const tr_peer_stat * peers,
|
|
|
|
int n_peers)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<n_peers; ++i) {
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gtk_tree_store_append (store, &iter, NULL);
|
|
|
|
peer_row_set (store, &iter, &peers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel*
|
2007-09-20 20:14:13 +00:00
|
|
|
peer_model_new (tr_torrent * tor)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
|
|
|
GtkTreeStore * m = gtk_tree_store_new (N_PEER_COLS,
|
2008-01-09 17:33:43 +00:00
|
|
|
G_TYPE_STRING, /* addr */
|
|
|
|
G_TYPE_STRING, /* client */
|
|
|
|
G_TYPE_INT, /* progress [0..100] */
|
|
|
|
G_TYPE_BOOLEAN, /* isEncrypted */
|
|
|
|
G_TYPE_FLOAT, /* downloadFromRate */
|
|
|
|
G_TYPE_FLOAT, /* uploadToRate */
|
|
|
|
G_TYPE_STRING ); /* flagString */
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
int n_peers = 0;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_peer_stat * peers = tr_torrentPeers (tor, &n_peers);
|
|
|
|
qsort (peers, n_peers, sizeof(tr_peer_stat), compare_peers);
|
2007-06-06 00:30:13 +00:00
|
|
|
append_peers_to_model (m, peers, n_peers);
|
|
|
|
tr_torrentPeersFree( peers, 0 );
|
|
|
|
return GTK_TREE_MODEL (m);
|
|
|
|
}
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
static void
|
|
|
|
render_encrypted (GtkTreeViewColumn * column UNUSED,
|
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
gboolean is_encrypted = FALSE;
|
|
|
|
gtk_tree_model_get (tree_model, iter, PEER_COL_IS_ENCRYPTED, &is_encrypted,
|
|
|
|
-1);
|
|
|
|
g_object_set (renderer, "xalign", (gfloat)0.0,
|
|
|
|
"yalign", (gfloat)0.5,
|
2007-10-13 13:51:38 +00:00
|
|
|
"stock-id", (is_encrypted ? "transmission-lock" : NULL),
|
2007-09-20 16:32:01 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
static void
|
|
|
|
render_ul_rate (GtkTreeViewColumn * column UNUSED,
|
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
float rate = 0.0;
|
|
|
|
gtk_tree_model_get (tree_model, iter, PEER_COL_UPLOAD_RATE, &rate, -1);
|
2007-09-23 13:53:44 +00:00
|
|
|
if( rate < 0.01 )
|
|
|
|
g_object_set (renderer, "text", "", NULL);
|
|
|
|
else {
|
2007-12-19 02:46:30 +00:00
|
|
|
char speedStr[64];
|
|
|
|
tr_strlspeed( speedStr, rate, sizeof(speedStr) );
|
|
|
|
g_object_set( renderer, "text", speedStr, NULL );
|
2007-09-23 13:53:44 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_dl_rate (GtkTreeViewColumn * column UNUSED,
|
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
float rate = 0.0;
|
|
|
|
gtk_tree_model_get (tree_model, iter, PEER_COL_DOWNLOAD_RATE, &rate, -1);
|
2007-09-23 13:53:44 +00:00
|
|
|
if( rate < 0.01 )
|
|
|
|
g_object_set (renderer, "text", "", NULL);
|
|
|
|
else {
|
2007-12-19 02:46:30 +00:00
|
|
|
char speedStr[64];
|
|
|
|
tr_strlspeed( speedStr, rate, sizeof(speedStr) );
|
|
|
|
g_object_set( renderer, "text", speedStr, NULL );
|
2007-09-23 13:53:44 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_client (GtkTreeViewColumn * column UNUSED,
|
|
|
|
GtkCellRenderer * renderer,
|
|
|
|
GtkTreeModel * tree_model,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
char * client = NULL;
|
2007-10-01 03:24:52 +00:00
|
|
|
gtk_tree_model_get (tree_model, iter, PEER_COL_CLIENT, &client,
|
2007-06-06 00:30:13 +00:00
|
|
|
-1);
|
2007-10-01 03:24:52 +00:00
|
|
|
g_object_set (renderer, "text", (client ? client : ""), NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
g_free (client);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
TrTorrent * gtor;
|
|
|
|
GtkTreeModel * model; /* same object as store, but recast */
|
|
|
|
GtkTreeStore * store; /* same object as model, but recast */
|
|
|
|
GtkWidget * completeness;
|
|
|
|
GtkWidget * seeders_lb;
|
|
|
|
GtkWidget * leechers_lb;
|
|
|
|
GtkWidget * completed_lb;
|
|
|
|
}
|
|
|
|
PeerData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
fmtpeercount (GtkWidget * l, int count)
|
|
|
|
{
|
|
|
|
if( 0 > count ) {
|
2007-10-08 19:40:34 +00:00
|
|
|
gtk_label_set_text( GTK_LABEL(l), "?" );
|
2007-06-06 00:30:13 +00:00
|
|
|
} else {
|
|
|
|
char str[16];
|
2007-07-30 20:48:43 +00:00
|
|
|
g_snprintf( str, sizeof str, "%i", count );
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_label_set_text( GTK_LABEL(l), str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
refresh_peers (GtkWidget * top)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n_peers;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
PeerData * p = (PeerData*) g_object_get_data (G_OBJECT(top), "peer-data");
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle ( p->gtor );
|
2007-06-06 00:30:13 +00:00
|
|
|
GtkTreeModel * model = p->model;
|
|
|
|
GtkTreeStore * store = p->store;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_peer_stat * peers;
|
|
|
|
const tr_stat * stat = tr_torrent_stat( p->gtor );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** merge the peer diffs into the tree model.
|
|
|
|
***
|
|
|
|
*** this is more complicated than creating a new model,
|
|
|
|
*** but is also (a) more efficient and (b) doesn't undo
|
|
|
|
*** the view's visible area and sorting on every refresh.
|
|
|
|
**/
|
|
|
|
|
|
|
|
n_peers = 0;
|
|
|
|
peers = tr_torrentPeers (tor, &n_peers);
|
2007-09-20 20:14:13 +00:00
|
|
|
qsort (peers, n_peers, sizeof(tr_peer_stat), compare_peers);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
if (gtk_tree_model_get_iter_first (model, &iter)) do
|
|
|
|
{
|
|
|
|
char * addr = NULL;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_peer_stat * peer = NULL;
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_tree_model_get (model, &iter, PEER_COL_ADDRESS, &addr, -1);
|
2007-09-20 20:14:13 +00:00
|
|
|
peer = bsearch (addr, peers, n_peers, sizeof(tr_peer_stat),
|
2007-06-06 00:30:13 +00:00
|
|
|
compare_addr_to_peer);
|
2007-06-07 17:53:54 +00:00
|
|
|
g_free (addr);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
if (peer) /* update a pre-existing row */
|
|
|
|
{
|
|
|
|
const int pos = peer - peers;
|
|
|
|
const int n_rhs = n_peers - (pos+1);
|
|
|
|
g_assert (n_rhs >= 0);
|
|
|
|
|
|
|
|
peer_row_set (store, &iter, peer);
|
|
|
|
|
2007-09-20 20:14:13 +00:00
|
|
|
/* remove it from the tr_peer_stat list */
|
|
|
|
g_memmove (peer, peer+1, sizeof(tr_peer_stat)*n_rhs);
|
2007-06-06 00:30:13 +00:00
|
|
|
--n_peers;
|
|
|
|
}
|
|
|
|
else if (!gtk_tree_store_remove (store, &iter))
|
|
|
|
break; /* we removed the model's last item */
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (model, &iter));
|
|
|
|
|
|
|
|
append_peers_to_model (store, peers, n_peers); /* all these are new */
|
|
|
|
|
|
|
|
if (GDK_IS_DRAWABLE (p->completeness->window))
|
|
|
|
refresh_pieces (p->completeness, NULL, p->gtor);
|
|
|
|
|
|
|
|
fmtpeercount (p->seeders_lb, stat->seeders);
|
|
|
|
fmtpeercount (p->leechers_lb, stat->leechers);
|
|
|
|
fmtpeercount (p->completed_lb, stat->completedFromTracker );
|
2007-06-07 17:53:54 +00:00
|
|
|
|
2007-11-17 07:29:44 +00:00
|
|
|
free( peers );
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget* peer_page_new ( TrTorrent * gtor )
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
GtkTreeModel *m;
|
|
|
|
GtkWidget *h, *v, *w, *ret, *da, *sw, *l, *vbox, *hbox;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle (gtor);
|
2007-06-06 00:30:13 +00:00
|
|
|
PeerData * p = g_new (PeerData, 1);
|
|
|
|
char name[64];
|
|
|
|
|
|
|
|
/* TODO: make this configurable? */
|
2008-01-20 17:18:28 +00:00
|
|
|
int view_columns[] = { PEER_COL_IS_ENCRYPTED,
|
2007-06-06 00:30:13 +00:00
|
|
|
PEER_COL_UPLOAD_RATE,
|
2008-01-09 17:33:43 +00:00
|
|
|
PEER_COL_DOWNLOAD_RATE,
|
2008-01-20 17:18:28 +00:00
|
|
|
PEER_COL_PROGRESS,
|
|
|
|
PEER_COL_STATUS,
|
|
|
|
PEER_COL_ADDRESS,
|
|
|
|
PEER_COL_CLIENT };
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
m = peer_model_new (tor);
|
|
|
|
v = gtk_tree_view_new_with_model (m);
|
|
|
|
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(v), TRUE);
|
|
|
|
g_object_unref (G_OBJECT(m));
|
|
|
|
|
|
|
|
for (i=0; i<G_N_ELEMENTS(view_columns); ++i)
|
|
|
|
{
|
|
|
|
const int col = view_columns[i];
|
|
|
|
const char * t = _(peer_column_names[col]);
|
|
|
|
gboolean resizable = TRUE;
|
|
|
|
GtkTreeViewColumn * c;
|
|
|
|
GtkCellRenderer * r;
|
|
|
|
|
|
|
|
switch (col)
|
|
|
|
{
|
|
|
|
case PEER_COL_ADDRESS:
|
|
|
|
r = gtk_cell_renderer_text_new ();
|
2008-01-20 17:18:28 +00:00
|
|
|
g_object_set( G_OBJECT( r ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
|
2007-06-06 00:30:13 +00:00
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_COL_CLIENT:
|
|
|
|
r = gtk_cell_renderer_text_new ();
|
2008-01-20 17:18:28 +00:00
|
|
|
g_object_set( G_OBJECT( r ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
|
2007-06-06 00:30:13 +00:00
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (c, r, render_client,
|
|
|
|
NULL, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_COL_PROGRESS:
|
|
|
|
r = gtk_cell_renderer_progress_new ();
|
2008-01-20 17:18:28 +00:00
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "value", PEER_COL_PROGRESS, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
break;
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
case PEER_COL_IS_ENCRYPTED:
|
|
|
|
resizable = FALSE;
|
|
|
|
r = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, NULL);
|
|
|
|
gtk_tree_view_column_set_sizing (c, GTK_TREE_VIEW_COLUMN_FIXED);
|
2007-09-23 22:20:01 +00:00
|
|
|
gtk_tree_view_column_set_fixed_width (c, 20);
|
2007-09-20 16:32:01 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func (c, r, render_encrypted,
|
|
|
|
NULL, NULL);
|
|
|
|
break;
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
case PEER_COL_DOWNLOAD_RATE:
|
|
|
|
r = gtk_cell_renderer_text_new ();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (c, r, render_dl_rate,
|
|
|
|
NULL, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEER_COL_UPLOAD_RATE:
|
|
|
|
r = gtk_cell_renderer_text_new ();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (c, r, render_ul_rate,
|
|
|
|
NULL, NULL);
|
|
|
|
break;
|
|
|
|
|
2007-11-17 23:43:33 +00:00
|
|
|
case PEER_COL_STATUS:
|
|
|
|
r = gtk_cell_renderer_text_new( );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL);
|
|
|
|
break;
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_resizable (c, resizable);
|
|
|
|
gtk_tree_view_column_set_sort_column_id (c, col);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW(v), c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the 'expander' column has a 10-pixel margin on the left
|
|
|
|
that doesn't look quite correct in any of these columns...
|
|
|
|
so create a non-visible column and assign it as the
|
|
|
|
'expander column. */
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *c = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_column_set_visible (c, FALSE);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW(v), c);
|
|
|
|
gtk_tree_view_set_expander_column (GTK_TREE_VIEW(v), c);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(w),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(w),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER(w), v);
|
|
|
|
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, GUI_PAD);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER(vbox), GUI_PAD_BIG);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), "<b>%s</b>", _("Piece Availability"));
|
|
|
|
l = gtk_label_new (NULL);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC(l), 0.0f, 0.5f);
|
|
|
|
gtk_label_set_markup (GTK_LABEL(l), name);
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), l, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
w = da = p->completeness = gtk_drawing_area_new ();
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, 0u, 100u);
|
2007-06-06 00:30:13 +00:00
|
|
|
g_object_set_data (G_OBJECT(w), "draw-mode", GINT_TO_POINTER(DRAW_AVAIL));
|
|
|
|
g_signal_connect (w, "expose-event", G_CALLBACK(refresh_pieces), gtor);
|
|
|
|
|
|
|
|
h = gtk_hbox_new (FALSE, GUI_PAD);
|
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, GUI_PAD_BIG, 0);
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(h), w, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(h), da);
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), h, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* a small vertical spacer */
|
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, 0u, GUI_PAD);
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
|
|
|
|
|
2007-11-27 03:29:51 +00:00
|
|
|
g_snprintf (name, sizeof(name), "<b>%s</b>", _("Connected Peers"));
|
2007-06-06 00:30:13 +00:00
|
|
|
l = gtk_label_new (NULL);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC(l), 0.0f, 0.5f);
|
|
|
|
gtk_label_set_markup (GTK_LABEL(l), name);
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), l, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
h = gtk_hbox_new (FALSE, GUI_PAD);
|
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, GUI_PAD_BIG, 0);
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(h), w, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(h), sw);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(vbox), h);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, GUI_PAD);
|
|
|
|
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, GUI_PAD_BIG, 0);
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
|
|
|
|
g_snprintf (name, sizeof(name), "<b>%s:</b>", _("Seeders"));
|
2007-06-07 17:53:54 +00:00
|
|
|
l = gtk_label_new (NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL(l), name);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
l = p->seeders_lb = gtk_label_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(hbox),
|
|
|
|
gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
g_snprintf (name, sizeof(name), "<b>%s:</b>", _("Leechers"));
|
|
|
|
l = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL(l), name);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
l = p->leechers_lb = gtk_label_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(hbox),
|
|
|
|
gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
g_snprintf (name, sizeof(name), "<b>%s:</b>", _("Completed"));
|
|
|
|
l = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL(l), name);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
l = p->completed_lb = gtk_label_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
ret = vbox;
|
|
|
|
p->gtor = gtor;
|
|
|
|
p->model = m;
|
|
|
|
p->store = GTK_TREE_STORE(m);
|
|
|
|
g_object_set_data_full (G_OBJECT(ret), "peer-data", p, g_free);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
***** INFO TAB
|
|
|
|
****/
|
|
|
|
|
2007-09-20 20:14:13 +00:00
|
|
|
static GtkWidget* info_page_new (tr_torrent * tor)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
|
|
|
int row = 0;
|
|
|
|
GtkWidget *t = hig_workarea_create ();
|
|
|
|
GtkWidget *l, *w, *fr;
|
|
|
|
char *pch;
|
|
|
|
char *dname, *bname;
|
2007-12-19 02:46:30 +00:00
|
|
|
char sizeStr[128];
|
2007-06-06 00:30:13 +00:00
|
|
|
char buf[256];
|
|
|
|
char name[128];
|
|
|
|
const char * namefmt = "%s:";
|
|
|
|
GtkTextBuffer * b;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_tracker_info * track;
|
|
|
|
const tr_info * info = tr_torrentInfo(tor);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Torrent Information"));
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Tracker"));
|
|
|
|
track = info->trackerList->list;
|
|
|
|
pch = track->port==80
|
2007-12-25 08:03:35 +00:00
|
|
|
? g_strdup_printf( "http://%s%s", track->address, track->announce )
|
|
|
|
: g_strdup_printf( "http://%s:%d%s", track->address, track->port, track->announce );
|
|
|
|
l = gtk_label_new( pch );
|
|
|
|
gtk_label_set_ellipsize( GTK_LABEL( l ), PANGO_ELLIPSIZE_END );
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
g_free (pch);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Pieces"));
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( sizeStr, info->pieceSize, sizeof(sizeStr) );
|
|
|
|
g_snprintf( buf, sizeof(buf), "%d (%s)", info->pieceCount, sizeStr );
|
2007-06-06 00:30:13 +00:00
|
|
|
l = gtk_label_new (buf);
|
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Hash"));
|
|
|
|
l = gtk_label_new (info->hashString);
|
2007-12-25 08:03:35 +00:00
|
|
|
gtk_label_set_ellipsize( GTK_LABEL( l ), PANGO_ELLIPSIZE_END );
|
2007-06-06 00:30:13 +00:00
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Secure"));
|
2007-10-15 20:58:39 +00:00
|
|
|
pch = (info->isPrivate )
|
2007-06-06 00:30:13 +00:00
|
|
|
? _("Private Torrent, PEX disabled")
|
|
|
|
: _("Public Torrent");
|
|
|
|
l = gtk_label_new (pch);
|
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Comment"));
|
|
|
|
b = gtk_text_buffer_new (NULL);
|
2008-02-14 17:18:00 +00:00
|
|
|
if( info->comment )
|
|
|
|
gtk_text_buffer_set_text (b, info->comment, -1);
|
2007-06-06 00:30:13 +00:00
|
|
|
w = gtk_text_view_new_with_buffer (b);
|
|
|
|
gtk_widget_set_size_request (w, 0u, 100u);
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(w), GTK_WRAP_WORD);
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW(w), FALSE);
|
|
|
|
fr = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(fr), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER(fr), w);
|
2008-02-07 17:41:40 +00:00
|
|
|
w = hig_workarea_add_row (t, &row, name, fr, NULL);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider (t, &row);
|
2008-02-06 15:52:30 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Created by"));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Creator"));
|
|
|
|
l = gtk_label_new (*info->creator ? info->creator : _("N/A"));
|
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Date"));
|
|
|
|
pch = rfc822date ((guint64)info->dateCreated * 1000u);
|
|
|
|
l = gtk_label_new (pch);
|
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
g_free (pch);
|
|
|
|
|
|
|
|
hig_workarea_add_section_divider (t, &row);
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Location"));
|
|
|
|
|
2008-02-06 15:52:30 +00:00
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Downloaded data"));
|
2007-06-06 00:30:13 +00:00
|
|
|
l = gtk_label_new (tr_torrentGetFolder (tor));
|
2007-12-25 08:03:35 +00:00
|
|
|
gtk_label_set_ellipsize( GTK_LABEL( l ), PANGO_ELLIPSIZE_END );
|
2007-06-06 00:30:13 +00:00
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
|
2008-02-06 15:52:30 +00:00
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Torrent file path"));
|
2007-06-06 00:30:13 +00:00
|
|
|
dname = g_path_get_dirname (info->torrent);
|
2007-07-30 20:48:43 +00:00
|
|
|
l = gtk_label_new ( dname );
|
2007-12-25 08:03:35 +00:00
|
|
|
gtk_label_set_ellipsize( GTK_LABEL( l ), PANGO_ELLIPSIZE_END );
|
2007-06-06 00:30:13 +00:00
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
g_free (dname);
|
|
|
|
|
2008-02-06 15:52:30 +00:00
|
|
|
g_snprintf (name, sizeof(name), namefmt, _("Torrent file name"));
|
2007-06-06 00:30:13 +00:00
|
|
|
bname = g_path_get_basename (info->torrent);
|
|
|
|
l = gtk_label_new (bname);
|
2007-12-25 08:03:35 +00:00
|
|
|
gtk_label_set_ellipsize( GTK_LABEL( l ), PANGO_ELLIPSIZE_END );
|
2007-06-06 00:30:13 +00:00
|
|
|
hig_workarea_add_row (t, &row, name, l, NULL);
|
|
|
|
g_free (bname);
|
|
|
|
|
|
|
|
hig_workarea_finish (t, &row);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
***** ACTIVITY TAB
|
|
|
|
****/
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget * state_lb;
|
2007-11-18 17:28:36 +00:00
|
|
|
GtkWidget * progress_lb;
|
|
|
|
GtkWidget * have_lb;
|
2007-06-06 00:30:13 +00:00
|
|
|
GtkWidget * dl_lb;
|
|
|
|
GtkWidget * ul_lb;
|
2007-11-18 17:28:36 +00:00
|
|
|
GtkWidget * failed_lb;
|
2007-06-06 00:30:13 +00:00
|
|
|
GtkWidget * ratio_lb;
|
|
|
|
GtkWidget * err_lb;
|
|
|
|
GtkWidget * swarm_lb;
|
|
|
|
GtkWidget * date_added_lb;
|
|
|
|
GtkWidget * last_activity_lb;
|
|
|
|
GtkWidget * availability_da;
|
|
|
|
TrTorrent * gtor;
|
|
|
|
}
|
|
|
|
Activity;
|
|
|
|
|
|
|
|
static void
|
|
|
|
refresh_activity (GtkWidget * top)
|
|
|
|
{
|
|
|
|
Activity * a = (Activity*) g_object_get_data (G_OBJECT(top), "activity-data");
|
2007-09-20 20:14:13 +00:00
|
|
|
const tr_stat * stat = tr_torrent_stat( a->gtor );
|
2007-12-19 02:46:30 +00:00
|
|
|
char *pch;
|
|
|
|
char sizeStr[64];
|
|
|
|
char sizeStr2[64];
|
|
|
|
char buf[128];
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
pch = tr_torrent_status_str( a->gtor );
|
|
|
|
gtk_label_set_text (GTK_LABEL(a->state_lb), pch);
|
|
|
|
g_free (pch);
|
|
|
|
|
2007-12-27 16:11:38 +00:00
|
|
|
pch = g_strdup_printf( _( "%.1f%% (%.1f%% selected)" ), stat->percentComplete*100.0, stat->percentDone*100.0 );
|
2007-11-18 17:28:36 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL(a->progress_lb), pch);
|
2007-09-26 01:55:04 +00:00
|
|
|
g_free (pch);
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( sizeStr, stat->haveValid + stat->haveUnchecked, sizeof(sizeStr) );
|
|
|
|
tr_strlsize( sizeStr2, stat->haveValid, sizeof(sizeStr2) );
|
|
|
|
g_snprintf( buf, sizeof(buf), _("%s (%s verified)"), sizeStr, sizeStr2 );
|
|
|
|
gtk_label_set_text( GTK_LABEL( a->have_lb ), buf );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( sizeStr, stat->downloadedEver, sizeof(sizeStr) );
|
|
|
|
gtk_label_set_text( GTK_LABEL(a->dl_lb), sizeStr );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( sizeStr, stat->uploadedEver, sizeof(sizeStr) );
|
|
|
|
gtk_label_set_text( GTK_LABEL(a->ul_lb), sizeStr );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlsize( sizeStr, stat->corruptEver, sizeof( sizeStr ) );
|
|
|
|
gtk_label_set_text( GTK_LABEL( a->failed_lb ), sizeStr );
|
2007-11-18 17:28:36 +00:00
|
|
|
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( buf, stat->ratio, sizeof( buf ) );
|
|
|
|
gtk_label_set_text( GTK_LABEL( a->ratio_lb ), buf );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlspeed( buf, stat->swarmspeed, sizeof(buf) );
|
|
|
|
gtk_label_set_text (GTK_LABEL(a->swarm_lb), buf );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL(a->err_lb),
|
|
|
|
*stat->errorString ? stat->errorString : _("None"));
|
|
|
|
|
|
|
|
pch = stat->startDate ? rfc822date (stat->startDate)
|
2007-10-08 19:40:34 +00:00
|
|
|
: g_strdup_printf ("?");
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL(a->date_added_lb), pch);
|
|
|
|
g_free (pch);
|
|
|
|
|
|
|
|
pch = stat->activityDate ? rfc822date (stat->activityDate)
|
2007-10-08 19:40:34 +00:00
|
|
|
: g_strdup_printf ("?");
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL(a->last_activity_lb), pch);
|
|
|
|
g_free (pch);
|
|
|
|
|
|
|
|
if (GDK_IS_DRAWABLE (a->availability_da->window))
|
|
|
|
refresh_pieces (a->availability_da, NULL, a->gtor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
activity_page_new (TrTorrent * gtor)
|
|
|
|
{
|
|
|
|
Activity * a = g_new (Activity, 1);
|
|
|
|
int row = 0;
|
|
|
|
GtkWidget *t = hig_workarea_create ();
|
|
|
|
GtkWidget *l, *w;
|
|
|
|
|
|
|
|
a->gtor = gtor;
|
|
|
|
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Transfer"));
|
|
|
|
|
|
|
|
l = a->state_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("State:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-11-18 17:28:36 +00:00
|
|
|
l = a->progress_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Progress:"), l, NULL);
|
2007-09-26 01:55:04 +00:00
|
|
|
|
2007-11-18 17:28:36 +00:00
|
|
|
l = a->have_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Have:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
l = a->dl_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Downloaded:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
l = a->ul_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Uploaded:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-11-18 17:28:36 +00:00
|
|
|
l = a->failed_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Failed DL:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-11-18 17:28:36 +00:00
|
|
|
l = a->ratio_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Ratio:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
l = a->swarm_lb = gtk_label_new (NULL);
|
2008-02-06 15:52:30 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Swarm rate:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
l = a->err_lb = gtk_label_new (NULL);
|
2007-12-27 16:16:47 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Error:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-02-07 17:44:26 +00:00
|
|
|
hig_workarea_add_section_divider (t, &row);
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Completeness"));
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
w = a->availability_da = gtk_drawing_area_new ();
|
2008-01-27 18:50:37 +00:00
|
|
|
gtk_widget_set_size_request (w, 0u, 100u);
|
2007-06-06 00:30:13 +00:00
|
|
|
g_object_set_data (G_OBJECT(w), "draw-mode", GINT_TO_POINTER(DRAW_PROG));
|
|
|
|
g_signal_connect (w, "expose-event", G_CALLBACK(refresh_pieces), gtor);
|
2008-02-07 17:44:26 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider (t, &row);
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Dates"));
|
|
|
|
|
|
|
|
l = a->date_added_lb = gtk_label_new (NULL);
|
2008-02-06 15:52:30 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Date added:"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
l = a->last_activity_lb = gtk_label_new (NULL);
|
2008-02-06 15:52:30 +00:00
|
|
|
hig_workarea_add_row (t, &row, _("Last activity"), l, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider (t, &row);
|
|
|
|
hig_workarea_finish (t, &row);
|
|
|
|
g_object_set_data_full (G_OBJECT(t), "activity-data", a, g_free);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****
|
|
|
|
***** OPTIONS
|
|
|
|
****/
|
|
|
|
|
2007-07-20 03:24:04 +00:00
|
|
|
static void
|
|
|
|
speed_toggled_cb( GtkToggleButton * tb, gpointer gtor, int up_or_down )
|
|
|
|
{
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle (gtor);
|
2007-07-20 03:24:04 +00:00
|
|
|
gboolean b = gtk_toggle_button_get_active(tb);
|
|
|
|
tr_torrentSetSpeedMode( tor, up_or_down, b ? TR_SPEEDLIMIT_SINGLE
|
|
|
|
: TR_SPEEDLIMIT_GLOBAL );
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
static void
|
|
|
|
ul_speed_toggled_cb (GtkToggleButton *tb, gpointer gtor)
|
|
|
|
{
|
2007-07-20 03:24:04 +00:00
|
|
|
speed_toggled_cb( tb, gtor, TR_UP );
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
dl_speed_toggled_cb (GtkToggleButton *tb, gpointer gtor)
|
|
|
|
{
|
2007-07-20 03:24:04 +00:00
|
|
|
speed_toggled_cb( tb, gtor, TR_DOWN );
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2007-07-20 03:24:04 +00:00
|
|
|
|
2007-12-22 00:06:38 +00:00
|
|
|
#if 0
|
2007-06-06 00:30:13 +00:00
|
|
|
static void
|
|
|
|
seeding_cap_toggled_cb (GtkToggleButton *tb, gpointer gtor)
|
|
|
|
{
|
|
|
|
tr_torrent_set_seeding_cap_enabled (TR_TORRENT(gtor),
|
|
|
|
gtk_toggle_button_get_active(tb));
|
|
|
|
}
|
2007-12-22 00:06:38 +00:00
|
|
|
#endif
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
sensitize_from_check_cb (GtkToggleButton *toggle, gpointer w)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET(w),
|
|
|
|
gtk_toggle_button_get_active(toggle));
|
|
|
|
}
|
|
|
|
|
2007-07-20 03:24:04 +00:00
|
|
|
static void
|
|
|
|
setSpeedLimit( GtkSpinButton* spin, gpointer gtor, int up_or_down )
|
|
|
|
{
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle (gtor);
|
2007-07-20 03:24:04 +00:00
|
|
|
int KiB_sec = gtk_spin_button_get_value_as_int (spin);
|
|
|
|
tr_torrentSetSpeedLimit( tor, up_or_down, KiB_sec );
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
static void
|
|
|
|
ul_speed_spun_cb (GtkSpinButton *spin, gpointer gtor)
|
|
|
|
{
|
2007-07-20 03:24:04 +00:00
|
|
|
setSpeedLimit( spin, gtor, TR_UP );
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
dl_speed_spun_cb (GtkSpinButton *spin, gpointer gtor)
|
|
|
|
{
|
2007-07-20 03:24:04 +00:00
|
|
|
setSpeedLimit( spin, gtor, TR_DOWN );
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 00:06:38 +00:00
|
|
|
#if 0
|
2007-06-06 00:30:13 +00:00
|
|
|
static void
|
|
|
|
seeding_ratio_spun_cb (GtkSpinButton *spin, gpointer gtor)
|
|
|
|
{
|
|
|
|
tr_torrent_set_seeding_cap_ratio (TR_TORRENT(gtor),
|
|
|
|
gtk_spin_button_get_value(spin));
|
|
|
|
}
|
2007-12-22 00:06:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
max_peers_spun_cb( GtkSpinButton * spin, gpointer gtor )
|
|
|
|
{
|
2007-12-22 04:11:17 +00:00
|
|
|
const uint16_t n = gtk_spin_button_get_value( spin );
|
|
|
|
tr_torrentSetMaxConnectedPeers( tr_torrent_handle( gtor ), n );
|
2007-12-22 00:06:38 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-01-03 21:41:15 +00:00
|
|
|
static GtkWidget*
|
2007-06-06 00:30:13 +00:00
|
|
|
options_page_new ( TrTorrent * gtor )
|
|
|
|
{
|
2007-12-22 00:06:38 +00:00
|
|
|
uint16_t maxConnectedPeers;
|
2007-07-20 03:24:04 +00:00
|
|
|
int i, row;
|
|
|
|
gboolean b;
|
2007-06-06 00:30:13 +00:00
|
|
|
GtkAdjustment *a;
|
2008-02-06 15:52:30 +00:00
|
|
|
GtkWidget *t, *w, *tb, *hb, *mis;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle (gtor);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
row = 0;
|
|
|
|
t = hig_workarea_create ();
|
2007-10-08 19:40:34 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Speed Limits") );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-02-06 15:52:30 +00:00
|
|
|
tb = gtk_check_button_new_with_mnemonic (_("Limit _download speed to:"));
|
2007-07-20 03:24:04 +00:00
|
|
|
b = tr_torrentGetSpeedMode(tor,TR_DOWN) == TR_SPEEDLIMIT_SINGLE;
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), b );
|
2007-06-06 00:30:13 +00:00
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(dl_speed_toggled_cb), gtor);
|
2007-07-20 03:24:04 +00:00
|
|
|
|
|
|
|
i = tr_torrentGetSpeedLimit( tor, TR_DOWN );
|
2008-02-06 15:52:30 +00:00
|
|
|
hb = gtk_hbox_new ( FALSE, 6 );
|
2007-07-20 03:24:04 +00:00
|
|
|
a = (GtkAdjustment*) gtk_adjustment_new (i, 0.0, G_MAXDOUBLE, 1, 1, 1);
|
2007-06-06 00:30:13 +00:00
|
|
|
w = gtk_spin_button_new (a, 1, 0);
|
|
|
|
g_signal_connect (w, "value-changed", G_CALLBACK(dl_speed_spun_cb), gtor);
|
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(sensitize_from_check_cb), w);
|
|
|
|
sensitize_from_check_cb (GTK_TOGGLE_BUTTON(tb), w);
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (w), FALSE, TRUE, 0);
|
2008-02-07 17:41:40 +00:00
|
|
|
mis = gtk_label_new (_("KiB/s"));
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (mis), FALSE, TRUE, 0);
|
|
|
|
hig_workarea_add_row_w (t, &row, tb, hb, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-02-06 15:52:30 +00:00
|
|
|
tb = gtk_check_button_new_with_mnemonic (_("Limit _upload speed to:"));
|
2007-07-20 03:24:04 +00:00
|
|
|
b = tr_torrentGetSpeedMode(tor,TR_UP) == TR_SPEEDLIMIT_SINGLE;
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), b );
|
2007-06-06 00:30:13 +00:00
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(ul_speed_toggled_cb), gtor);
|
2007-07-20 03:24:04 +00:00
|
|
|
|
|
|
|
i = tr_torrentGetSpeedLimit( tor, TR_UP );
|
2008-02-06 15:52:30 +00:00
|
|
|
hb = gtk_hbox_new ( FALSE, 6 );
|
2007-07-20 03:24:04 +00:00
|
|
|
a = (GtkAdjustment*) gtk_adjustment_new (i, 0.0, G_MAXDOUBLE, 1, 1, 1);
|
2007-06-06 00:30:13 +00:00
|
|
|
w = gtk_spin_button_new (a, 1, 0);
|
|
|
|
g_signal_connect (w, "value-changed", G_CALLBACK(ul_speed_spun_cb), gtor);
|
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(sensitize_from_check_cb), w);
|
|
|
|
sensitize_from_check_cb (GTK_TOGGLE_BUTTON(tb), w);
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (w), FALSE, TRUE, 0);
|
2008-02-07 17:41:40 +00:00
|
|
|
mis = gtk_label_new (_("KiB/s"));
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (mis), FALSE, TRUE, 0);
|
|
|
|
hig_workarea_add_row_w (t, &row, tb, hb, NULL);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider (t, &row);
|
2007-12-22 00:06:38 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Peer Connections"));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2007-12-22 04:11:17 +00:00
|
|
|
maxConnectedPeers = tr_torrentGetMaxConnectedPeers( tor );
|
2007-12-22 00:06:38 +00:00
|
|
|
w = gtk_spin_button_new_with_range( 1, 3000, 5 );
|
|
|
|
gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), maxConnectedPeers );
|
2008-02-06 15:52:30 +00:00
|
|
|
hb = gtk_hbox_new ( FALSE, 6 );
|
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (w), FALSE, TRUE, 0);
|
|
|
|
mis = gtk_label_new (_("peers"));
|
|
|
|
gtk_box_pack_start ( GTK_BOX (hb), GTK_WIDGET (mis), FALSE, TRUE, 0);
|
2008-02-07 17:41:40 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Connect at _maximum to:" ), hb, w );
|
2007-12-22 00:06:38 +00:00
|
|
|
g_signal_connect( w, "value-changed", G_CALLBACK( max_peers_spun_cb ), gtor );
|
|
|
|
|
|
|
|
#if 0
|
2008-02-06 15:52:30 +00:00
|
|
|
tb = gtk_check_button_new_with_mnemonic (_("_Stop seeding at ratio:"));
|
2007-06-06 00:30:13 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), gtor->seeding_cap_enabled);
|
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(seeding_cap_toggled_cb), gtor);
|
|
|
|
a = (GtkAdjustment*) gtk_adjustment_new (gtor->seeding_cap, 0.0, G_MAXDOUBLE, 1, 1, 1);
|
|
|
|
w = gtk_spin_button_new (a, 1, 1);
|
|
|
|
g_signal_connect (w, "value-changed", G_CALLBACK(seeding_ratio_spun_cb), gtor);
|
|
|
|
g_signal_connect (tb, "toggled", G_CALLBACK(sensitize_from_check_cb), w);
|
|
|
|
sensitize_from_check_cb (GTK_TOGGLE_BUTTON(tb), w);
|
|
|
|
hig_workarea_add_row_w (t, &row, tb, w, NULL);
|
2007-12-22 00:06:38 +00:00
|
|
|
#endif
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
hig_workarea_finish (t, &row);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
refresh_options (GtkWidget * top UNUSED)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
***** DIALOG
|
|
|
|
****/
|
|
|
|
|
|
|
|
static void
|
|
|
|
torrent_destroyed (gpointer dialog, GObject * dead_torrent UNUSED)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (GTK_WIDGET(dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_tag (gpointer tag)
|
|
|
|
{
|
|
|
|
g_source_remove (GPOINTER_TO_UINT(tag)); /* stop the periodic refresh */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
response_cb (GtkDialog *dialog, int response UNUSED, gpointer gtor)
|
|
|
|
{
|
|
|
|
g_object_weak_unref (G_OBJECT(gtor), torrent_destroyed, dialog);
|
|
|
|
gtk_widget_destroy (GTK_WIDGET(dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
periodic_refresh (gpointer data)
|
|
|
|
{
|
2008-02-10 22:25:42 +00:00
|
|
|
refresh_peers (g_object_get_data (G_OBJECT(data), "peers-top"));
|
|
|
|
refresh_activity (g_object_get_data (G_OBJECT(data), "activity-top"));
|
|
|
|
refresh_options (g_object_get_data (G_OBJECT(data), "options-top"));
|
2007-06-06 00:30:13 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
torrent_inspector_new ( GtkWindow * parent, TrTorrent * gtor )
|
|
|
|
{
|
|
|
|
guint tag;
|
|
|
|
GtkWidget *d, *n, *w;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle (gtor);
|
2007-12-19 02:46:30 +00:00
|
|
|
char sizeStr[64];
|
|
|
|
char title[512];
|
2007-09-20 20:14:13 +00:00
|
|
|
const tr_info * info = tr_torrent_info (gtor);
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
/* create the dialog */
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_strlsize( sizeStr, info->totalSize, sizeof(sizeStr) );
|
|
|
|
g_snprintf( title, sizeof(title), _( "Details for %s (%s)" ), info->name, sizeStr );
|
|
|
|
d = gtk_dialog_new_with_buttons (title, parent, 0,
|
2007-06-06 00:30:13 +00:00
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
|
|
|
NULL);
|
|
|
|
gtk_window_set_role (GTK_WINDOW(d), "tr-info" );
|
|
|
|
g_signal_connect (d, "response", G_CALLBACK (response_cb), gtor);
|
2008-02-03 04:55:42 +00:00
|
|
|
gtk_dialog_set_has_separator( GTK_DIALOG( d ), FALSE );
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (d), 5);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (d)->vbox), 2);
|
2007-06-06 00:30:13 +00:00
|
|
|
g_object_weak_ref (G_OBJECT(gtor), torrent_destroyed, d);
|
2008-02-06 15:52:30 +00:00
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
/* add the notebook */
|
|
|
|
n = gtk_notebook_new ();
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_container_set_border_width ( GTK_CONTAINER ( n ), 5 );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
w = activity_page_new (gtor);
|
|
|
|
g_object_set_data (G_OBJECT(d), "activity-top", w);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK(n), w,
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_label_new (_("Activity")));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
w = peer_page_new (gtor);
|
|
|
|
g_object_set_data (G_OBJECT(d), "peers-top", w);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK(n), w,
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_label_new (_("Peers")));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK(n),
|
|
|
|
info_page_new (tor),
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_label_new (_("Info")));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-02-10 22:25:42 +00:00
|
|
|
w = file_list_new( gtor );
|
2008-02-12 18:53:31 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( w ), GUI_PAD_BIG );
|
2007-06-06 00:30:13 +00:00
|
|
|
g_object_set_data (G_OBJECT(d), "files-top", w);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK(n), w,
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_label_new (_("Files")));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
w = options_page_new (gtor);
|
|
|
|
g_object_set_data (G_OBJECT(d), "options-top", w);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK(n), w,
|
2008-02-06 15:52:30 +00:00
|
|
|
gtk_label_new (_("Options")));
|
2007-06-06 00:30:13 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start_defaults (GTK_BOX(GTK_DIALOG(d)->vbox), n);
|
|
|
|
|
|
|
|
tag = g_timeout_add (UPDATE_INTERVAL_MSEC, periodic_refresh, d);
|
|
|
|
g_object_set_data_full (G_OBJECT(d), "tag",
|
|
|
|
GUINT_TO_POINTER(tag), remove_tag);
|
|
|
|
|
|
|
|
/* return the results */
|
|
|
|
periodic_refresh (d);
|
|
|
|
gtk_widget_show_all (GTK_DIALOG(d)->vbox);
|
|
|
|
return d;
|
|
|
|
}
|