2007-12-19 02:46:30 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-12-19 02:46:30 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
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
|
|
|
*/
|
|
|
|
|
2013-08-24 17:53:45 +00:00
|
|
|
#include <limits.h> /* INT_MAX */
|
2007-12-19 02:46:30 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <libtransmission/transmission.h>
|
2012-12-05 17:29: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"
|
|
|
|
#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
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2011-04-12 10:04:05 +00:00
|
|
|
static void
|
2012-12-14 20:04:37 +00:00
|
|
|
getProgressString (GString * gstr,
|
|
|
|
const tr_torrent * tor,
|
|
|
|
const tr_info * info,
|
|
|
|
const tr_stat * st)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2011-01-06 02:40:10 +00:00
|
|
|
const int isDone = st->leftUntilDone == 0;
|
|
|
|
const uint64_t haveTotal = st->haveUnchecked + st->haveValid;
|
|
|
|
const int isSeed = st->haveValid >= info->totalSize;
|
2010-06-22 22:30:58 +00:00
|
|
|
char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32];
|
2009-08-10 20:04:08 +00:00
|
|
|
double seedRatio;
|
2012-12-05 17:29:46 +00:00
|
|
|
const gboolean hasSeedRatio = tr_torrentGetSeedRatio (tor, &seedRatio);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!isDone) /* downloading */
|
2009-03-01 16:00:41 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
_("%1$s of %2$s (%3$s%%)"),
|
|
|
|
tr_strlsize (buf1, haveTotal, sizeof (buf1)),
|
|
|
|
tr_strlsize (buf2, st->sizeWhenDone, sizeof (buf2)),
|
|
|
|
tr_strlpercent (buf3, st->percentDone * 100.0, sizeof (buf3)));
|
2009-03-01 16:00:41 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (!isSeed) /* partial seeds */
|
2009-03-01 16:00:41 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
if (hasSeedRatio)
|
2010-04-01 06:08:20 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
2010-04-01 06:08:20 +00:00
|
|
|
/* %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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
_("%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s Goal: %6$s)"),
|
|
|
|
tr_strlsize (buf1, haveTotal, sizeof (buf1)),
|
|
|
|
tr_strlsize (buf2, info->totalSize, sizeof (buf2)),
|
|
|
|
tr_strlpercent (buf3, st->percentComplete * 100.0, sizeof (buf3)),
|
|
|
|
tr_strlsize (buf4, st->uploadedEver, sizeof (buf4)),
|
|
|
|
tr_strlratio (buf5, st->ratio, sizeof (buf5)),
|
|
|
|
tr_strlratio (buf6, seedRatio, sizeof (buf6)));
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
2010-04-01 06:08:20 +00:00
|
|
|
/* %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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
_("%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s)"),
|
|
|
|
tr_strlsize (buf1, haveTotal, sizeof (buf1)),
|
|
|
|
tr_strlsize (buf2, info->totalSize, sizeof (buf2)),
|
|
|
|
tr_strlpercent (buf3, st->percentComplete * 100.0, sizeof (buf3)),
|
|
|
|
tr_strlsize (buf4, st->uploadedEver, sizeof (buf4)),
|
|
|
|
tr_strlratio (buf5, st->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
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
if (hasSeedRatio)
|
2010-04-01 06:08:20 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
2010-04-01 06:08:20 +00:00
|
|
|
/* %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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
_("%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)"),
|
|
|
|
tr_strlsize (buf1, info->totalSize, sizeof (buf1)),
|
|
|
|
tr_strlsize (buf2, st->uploadedEver, sizeof (buf2)),
|
|
|
|
tr_strlratio (buf3, st->ratio, sizeof (buf3)),
|
|
|
|
tr_strlratio (buf4, seedRatio, sizeof (buf4)));
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
|
|
|
else /* seeding w/o a ratio */
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
2010-04-01 06:08:20 +00:00
|
|
|
/* %1$s is the torrent's total size,
|
|
|
|
%2$s is how much we've uploaded,
|
|
|
|
%3$s is our upload-to-download ratio */
|
2012-12-05 17:29:46 +00:00
|
|
|
_("%1$s, uploaded %2$s (Ratio: %3$s)"),
|
|
|
|
tr_strlsize (buf1, info->totalSize, sizeof (buf1)),
|
|
|
|
tr_strlsize (buf2, st->uploadedEver, sizeof (buf2)),
|
|
|
|
tr_strlratio (buf3, st->ratio, sizeof (buf3)));
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
if ((st->activity == TR_STATUS_DOWNLOAD)
|
|
|
|
|| (hasSeedRatio && (st->activity == TR_STATUS_SEED)))
|
2008-02-09 16:05:29 +00:00
|
|
|
{
|
2011-01-06 02:40:10 +00:00
|
|
|
const int eta = st->eta;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append (gstr, " - ");
|
|
|
|
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];
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_strltime (timestr, eta, sizeof (timestr));
|
2008-03-08 04:53:11 +00:00
|
|
|
/* time remaining */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr, _("%s remaining"), timestr);
|
2008-02-09 16:05:29 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2012-12-05 17:29:46 +00:00
|
|
|
getShortTransferString (const tr_torrent * tor,
|
2011-01-06 02:40:10 +00:00
|
|
|
const tr_stat * st,
|
2010-07-04 06:07:21 +00:00
|
|
|
double uploadSpeed_KBps,
|
|
|
|
double downloadSpeed_KBps,
|
2009-11-24 15:51:16 +00:00
|
|
|
char * buf,
|
2012-12-05 17:29:46 +00:00
|
|
|
size_t buflen)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2013-01-27 23:05:47 +00:00
|
|
|
const int haveMeta = tr_torrentHasMetadata (tor);
|
|
|
|
const int haveUp = haveMeta && st->peersGettingFromUs > 0;
|
|
|
|
const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
|
|
|
|
|
|
|
|
|
2013-01-30 00:22:52 +00:00
|
|
|
if (haveDown)
|
2013-01-27 23:05:47 +00:00
|
|
|
{
|
2013-01-30 00:22:52 +00:00
|
|
|
char dnStr[32], upStr[32];
|
|
|
|
tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr));
|
|
|
|
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
|
|
|
|
|
|
|
|
/* down speed, down symbol, up speed, up symbol */
|
|
|
|
g_snprintf (buf, buflen, _("%1$s %2$s %3$s %4$s"),
|
2013-01-27 23:05:47 +00:00
|
|
|
dnStr,
|
2013-01-30 00:22:52 +00:00
|
|
|
gtr_get_unicode_string (GTR_UNICODE_DOWN),
|
|
|
|
upStr,
|
|
|
|
gtr_get_unicode_string (GTR_UNICODE_UP));
|
2013-01-27 23:05:47 +00:00
|
|
|
}
|
|
|
|
else if (haveUp)
|
|
|
|
{
|
2013-01-30 00:22:52 +00:00
|
|
|
char upStr[32];
|
|
|
|
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
|
|
|
|
|
|
|
|
/* up speed, up symbol */
|
|
|
|
g_snprintf (buf, buflen, _("%1$s %2$s"),
|
2013-01-27 23:05:47 +00:00
|
|
|
upStr,
|
|
|
|
gtr_get_unicode_string (GTR_UNICODE_UP));
|
|
|
|
}
|
|
|
|
else if (st->isStalled)
|
|
|
|
{
|
|
|
|
g_strlcpy (buf, _("Stalled"), buflen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2007-12-20 02:02:51 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:04:05 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
getShortStatusString (GString * gstr,
|
2011-04-12 10:04:05 +00:00
|
|
|
const tr_torrent * tor,
|
2011-01-06 02:40:10 +00:00
|
|
|
const tr_stat * st,
|
2010-07-04 06:07:21 +00:00
|
|
|
double uploadSpeed_KBps,
|
2012-12-05 17:29:46 +00:00
|
|
|
double downloadSpeed_KBps)
|
2007-12-20 02:02:51 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (st->activity)
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append (gstr, st->finished ? _("Finished") : _("Paused"));
|
2007-12-19 18:11:10 +00:00
|
|
|
break;
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append (gstr, _("Queued for verification"));
|
2008-02-14 00:59:32 +00:00
|
|
|
break;
|
2011-08-01 22:24:24 +00:00
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append (gstr, _("Queued for download"));
|
2011-08-01 22:24:24 +00:00
|
|
|
break;
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append (gstr, _("Queued for seeding"));
|
2011-08-08 16:38:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr, _("Verifying local data (%.1f%% tested)"),
|
|
|
|
tr_truncd (st->recheckProgress * 100.0, 1));
|
2011-08-01 22:24:24 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-20 02:02:51 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
2008-09-23 19:11:04 +00:00
|
|
|
case TR_STATUS_SEED:
|
|
|
|
{
|
2013-01-30 00:22:52 +00:00
|
|
|
char speedStr[64];
|
|
|
|
char ratioStr[64];
|
|
|
|
tr_strlratio (ratioStr, st->ratio, sizeof (ratioStr));
|
|
|
|
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, speedStr, sizeof (speedStr));
|
|
|
|
/* download/upload speed, ratio */
|
|
|
|
g_string_append_printf (gstr, "%1$s Ratio: %2$s", speedStr, ratioStr);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:04:05 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
getStatusString (GString * gstr,
|
2011-04-12 10:04:05 +00:00
|
|
|
const tr_torrent * tor,
|
2011-01-06 02:40:10 +00:00
|
|
|
const tr_stat * st,
|
2010-07-04 06:07:21 +00:00
|
|
|
const double uploadSpeed_KBps,
|
2012-12-05 17:29:46 +00:00
|
|
|
const double downloadSpeed_KBps)
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
if (st->error)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * fmt[] = { NULL, N_("Tracker gave a warning: \"%s\""),
|
|
|
|
N_("Tracker gave an error: \"%s\""),
|
|
|
|
N_("Error: %s") };
|
|
|
|
g_string_append_printf (gstr, _ (fmt[st->error]), st->errorString);
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else switch (st->activity)
|
2009-11-24 15:51:16 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
case TR_STATUS_CHECK:
|
2011-08-01 22:24:24 +00:00
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
getShortStatusString (gstr, tor, st, uploadSpeed_KBps, downloadSpeed_KBps);
|
2009-11-24 15:51:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-11-24 15:51:16 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!tr_torrentHasMetadata (tor))
|
2009-11-24 15:51:16 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* Downloading metadata from 2 peer (s)(50% done) */
|
|
|
|
g_string_append_printf (gstr, _("Downloading metadata from %1$'d %2$s (%3$d%% done)"),
|
2012-10-07 17:51:56 +00:00
|
|
|
st->peersConnected,
|
2012-12-05 17:29:46 +00:00
|
|
|
ngettext ("peer","peers",st->peersConnected),
|
|
|
|
(int)(100.0*st->metadataPercentComplete));
|
2012-10-07 17:51:56 +00:00
|
|
|
}
|
|
|
|
else if (st->peersSendingToUs && st->webseedsSendingToUs)
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* Downloading from 2 of 3 peer (s) and 2 webseed (s) */
|
2012-10-07 17:51:56 +00:00
|
|
|
g_string_append_printf (gstr, _("Downloading from %1$'d of %2$'d %3$s and %4$'d %5$s"),
|
|
|
|
st->peersSendingToUs,
|
|
|
|
st->peersConnected,
|
2013-01-21 00:15:21 +00:00
|
|
|
ngettext ("peer","peers",st->peersConnected),
|
2012-10-07 17:51:56 +00:00
|
|
|
st->webseedsSendingToUs,
|
2012-12-05 17:29:46 +00:00
|
|
|
ngettext ("web seed","web seeds",st->webseedsSendingToUs));
|
2012-10-07 17:51:56 +00:00
|
|
|
}
|
|
|
|
else if (st->webseedsSendingToUs)
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* Downloading from 3 web seed (s) */
|
2012-10-07 17:51:56 +00:00
|
|
|
g_string_append_printf (gstr, _("Downloading from %1$'d %2$s"),
|
|
|
|
st->webseedsSendingToUs,
|
2012-12-05 17:29:46 +00:00
|
|
|
ngettext ("web seed","web seeds",st->webseedsSendingToUs));
|
2009-11-24 15:51:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* Downloading from 2 of 3 peer (s) */
|
2012-10-07 17:51:56 +00:00
|
|
|
g_string_append_printf (gstr, _("Downloading from %1$'d of %2$'d %3$s"),
|
|
|
|
st->peersSendingToUs,
|
|
|
|
st->peersConnected,
|
2013-01-21 00:15:21 +00:00
|
|
|
ngettext ("peer","peers",st->peersConnected));
|
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:
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_append_printf (gstr,
|
|
|
|
ngettext ("Seeding to %1$'d of %2$'d connected peer",
|
2011-05-02 17:58:27 +00:00
|
|
|
"Seeding to %1$'d of %2$'d connected peers",
|
2012-12-05 17:29:46 +00:00
|
|
|
st->peersConnected),
|
2011-01-06 02:40:10 +00:00
|
|
|
st->peersGettingFromUs,
|
2012-12-05 17:29:46 +00:00
|
|
|
st->peersConnected);
|
2009-11-24 15:51:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if ((st->activity != TR_STATUS_CHECK_WAIT) &&
|
|
|
|
(st->activity != TR_STATUS_CHECK) &&
|
|
|
|
(st->activity != TR_STATUS_DOWNLOAD_WAIT) &&
|
|
|
|
(st->activity != TR_STATUS_SEED_WAIT) &&
|
|
|
|
(st->activity != TR_STATUS_STOPPED))
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2007-12-20 02:02:51 +00:00
|
|
|
char buf[256];
|
2012-12-05 17:29:46 +00:00
|
|
|
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
|
|
|
|
if (*buf)
|
|
|
|
g_string_append_printf (gstr, " - %s", buf);
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate
|
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
tr_torrent * tor;
|
|
|
|
GtkCellRenderer * text_renderer;
|
|
|
|
GtkCellRenderer * progress_renderer;
|
|
|
|
GtkCellRenderer * icon_renderer;
|
2011-04-12 10:04:05 +00:00
|
|
|
GString * gstr1;
|
|
|
|
GString * gstr2;
|
2009-08-07 20:49:06 +00:00
|
|
|
int bar_height;
|
|
|
|
|
2010-12-27 19:18:17 +00:00
|
|
|
/* Use this instead of tr_stat.pieceUploadSpeed so that the model can
|
|
|
|
control when the speed displays get updated. This is done to keep
|
2009-08-07 20:49:06 +00:00
|
|
|
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*
|
2012-12-05 17:29:46 +00:00
|
|
|
get_icon (const tr_torrent * tor, GtkIconSize icon_size, GtkWidget * for_widget)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
|
|
|
const char * mime_type;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_info * info = tr_torrentInfo (tor);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (info->fileCount == 0)
|
2009-11-24 02:16:31 +00:00
|
|
|
mime_type = UNKNOWN_MIME_TYPE;
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (info->fileCount > 1)
|
2009-03-02 23:31:01 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (strchr (info->files[0].name, '/') != NULL)
|
2010-02-26 15:06:26 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2009-03-02 23:31:01 +00:00
|
|
|
else
|
2012-12-05 17:29:46 +00:00
|
|
|
mime_type = gtr_get_mime_type_from_filename (info->files[0].name);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return gtr_get_mime_type_icon (mime_type, icon_size, for_widget);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2011-07-26 01:02:32 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_cell_renderer_get_preferred_size (GtkCellRenderer * renderer,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkWidget * widget,
|
|
|
|
GtkRequisition * minimum_size,
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkRequisition * natural_size)
|
2011-07-26 01:02:32 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_cell_renderer_get_preferred_size (renderer, widget, minimum_size, natural_size);
|
2011-07-26 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
get_size_compact (TorrentCellRenderer * cell,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
|
|
|
gint * width,
|
2012-12-05 17:29:46 +00:00
|
|
|
gint * height)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2010-12-24 09:04:52 +00:00
|
|
|
int xpad, ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition icon_size;
|
|
|
|
GtkRequisition name_size;
|
|
|
|
GtkRequisition stat_size;
|
2009-03-02 23:31:01 +00:00
|
|
|
const char * name;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
|
|
|
const tr_torrent * tor = p->tor;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_stat * st = tr_torrentStatCached ((tr_torrent*)tor);
|
2011-04-12 10:04:05 +00:00
|
|
|
GString * gstr_stat = p->gstr1;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
icon = get_icon (tor, COMPACT_ICON_SIZE, widget);
|
|
|
|
name = tr_torrentName (tor);
|
|
|
|
g_string_truncate (gstr_stat, 0);
|
|
|
|
getShortStatusString (gstr_stat, tor, st, p->upload_speed_KBps, p->download_speed_KBps);
|
|
|
|
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->icon_renderer, "pixbuf", icon, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->icon_renderer, widget, NULL, &icon_size);
|
|
|
|
g_object_set (p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &name_size);
|
|
|
|
g_object_set (p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &stat_size);
|
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
|
2012-12-05 17:29:46 +00:00
|
|
|
if (width != NULL)
|
2011-07-26 01:02:32 +00:00
|
|
|
*width = xpad * 2 + icon_size.width + GUI_PAD + name_size.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_size.width;
|
2012-12-05 17:29:46 +00:00
|
|
|
if (height != NULL)
|
|
|
|
*height = ypad * 2 + MAX (name_size.height, p->bar_height);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2012-12-05 17:29:46 +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
|
2012-12-05 17:29:46 +00:00
|
|
|
get_size_full (TorrentCellRenderer * cell,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
|
|
|
gint * width,
|
2012-12-05 17:29:46 +00:00
|
|
|
gint * height)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2010-12-24 09:04:52 +00:00
|
|
|
int xpad, ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition icon_size;
|
|
|
|
GtkRequisition name_size;
|
|
|
|
GtkRequisition stat_size;
|
|
|
|
GtkRequisition prog_size;
|
2009-03-02 23:31:01 +00:00
|
|
|
const char * name;
|
|
|
|
GdkPixbuf * icon;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
2012-12-14 20:04:37 +00:00
|
|
|
const tr_torrent * tor = p->tor;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_stat * st = tr_torrentStatCached ((tr_torrent*)tor);
|
|
|
|
const tr_info * inf = tr_torrentInfo (tor);
|
2011-04-12 10:04:05 +00:00
|
|
|
GString * gstr_prog = p->gstr1;
|
|
|
|
GString * gstr_stat = p->gstr2;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
icon = get_icon (tor, FULL_ICON_SIZE, widget);
|
|
|
|
name = tr_torrentName (tor);
|
|
|
|
g_string_truncate (gstr_stat, 0);
|
|
|
|
getStatusString (gstr_stat, tor, st, p->upload_speed_KBps, p->download_speed_KBps);
|
|
|
|
g_string_truncate (gstr_prog, 0);
|
|
|
|
getProgressString (gstr_prog, tor, inf, st);
|
|
|
|
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->icon_renderer, "pixbuf", icon, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->icon_renderer, widget, NULL, &icon_size);
|
|
|
|
g_object_set (p->text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "scale", 1.0, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &name_size);
|
|
|
|
g_object_set (p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &prog_size);
|
|
|
|
g_object_set (p->text_renderer, "text", gstr_stat->str, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &stat_size);
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (width != NULL)
|
|
|
|
*width = xpad * 2 + icon_size.width + GUI_PAD + MAX3 (name_size.width, prog_size.width, stat_size.width);
|
|
|
|
if (height != NULL)
|
2011-07-26 01:02:32 +00:00
|
|
|
*height = ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_size.height;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_get_size (GtkCellRenderer * cell,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkWidget * widget,
|
|
|
|
const GdkRectangle * cell_area,
|
|
|
|
gint * x_offset,
|
|
|
|
gint * y_offset,
|
|
|
|
gint * width,
|
2012-12-05 17:29:46 +00:00
|
|
|
gint * height)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER (cell);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (self && self->priv->tor)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
int w, h;
|
2010-12-24 09:04:52 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2007-12-19 20:04:38 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (p->compact)
|
|
|
|
get_size_compact (TORRENT_CELL_RENDERER (cell), widget, &w, &h);
|
2007-12-19 18:11:10 +00:00
|
|
|
else
|
2012-12-05 17:29:46 +00:00
|
|
|
get_size_full (TORRENT_CELL_RENDERER (cell), widget, &w, &h);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (width)
|
2009-03-02 23:31:01 +00:00
|
|
|
*width = w;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (height)
|
2009-03-02 23:31:01 +00:00
|
|
|
*height = h;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (x_offset)
|
2010-09-27 20:24:41 +00:00
|
|
|
*x_offset = cell_area ? cell_area->x : 0;
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (y_offset) {
|
2010-12-24 09:04:52 +00:00
|
|
|
int xpad, ypad;
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
|
2010-12-24 09:04:52 +00:00
|
|
|
*y_offset = cell_area ? (int)((cell_area->height - (ypad*2 +h)) / 2.0) : 0;
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 19:26:55 +00:00
|
|
|
typedef GdkRGBA GtrColor;
|
|
|
|
#define FOREGROUND_COLOR_KEY "foreground-rgba"
|
2011-07-26 01:02:32 +00:00
|
|
|
|
2011-01-22 13:26:44 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
get_text_color (GtkWidget * w, const tr_stat * st, GtrColor * setme)
|
2011-01-22 13:26:44 +00:00
|
|
|
{
|
2012-12-12 20:22:57 +00:00
|
|
|
static const GdkRGBA red = { 1.0, 0, 0, 0 };
|
|
|
|
|
|
|
|
if (st->error)
|
|
|
|
*setme = red;
|
|
|
|
else if (st->activity == TR_STATUS_STOPPED)
|
|
|
|
gtk_style_context_get_color (gtk_widget_get_style_context (w), GTK_STATE_FLAG_INSENSITIVE, setme);
|
|
|
|
else
|
|
|
|
gtk_style_context_get_color (gtk_widget_get_style_context (w), GTK_STATE_FLAG_NORMAL, setme);
|
2011-01-22 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 01:02:32 +00:00
|
|
|
|
2011-05-28 00:09:15 +00:00
|
|
|
static double
|
2012-12-14 20:04:37 +00:00
|
|
|
get_percent_done (const tr_torrent * tor, const tr_stat * st, bool * seed)
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2012-12-12 20:22:57 +00:00
|
|
|
double d;
|
2011-05-28 00:09:15 +00:00
|
|
|
|
2012-12-12 20:22:57 +00:00
|
|
|
if ((st->activity == TR_STATUS_SEED) && tr_torrentGetSeedRatio (tor, &d))
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2012-12-12 20:22:57 +00:00
|
|
|
*seed = true;
|
|
|
|
d = MAX (0.0, st->seedRatioPercentDone);
|
2011-05-28 00:09:15 +00:00
|
|
|
}
|
2012-12-12 20:22:57 +00:00
|
|
|
else
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2012-12-12 20:22:57 +00:00
|
|
|
*seed = false;
|
|
|
|
d = MAX (0.0, st->percentDone);
|
2011-05-28 00:09:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 20:22:57 +00:00
|
|
|
return d;
|
2011-05-28 00:09:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 19:26:55 +00:00
|
|
|
typedef cairo_t GtrDrawable;
|
2011-07-26 01:02:32 +00:00
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_cell_renderer_render (GtkCellRenderer * renderer,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrDrawable * drawable,
|
|
|
|
GtkWidget * widget,
|
|
|
|
const GdkRectangle * area,
|
|
|
|
GtkCellRendererState flags)
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_cell_renderer_render (renderer, drawable, widget, area, area, flags);
|
2011-07-26 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
render_compact (TorrentCellRenderer * cell,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrDrawable * window,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
2011-07-26 01:02:32 +00:00
|
|
|
const GdkRectangle * background_area,
|
|
|
|
const GdkRectangle * cell_area UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkCellRendererState flags)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2010-12-24 09:04:52 +00:00
|
|
|
int xpad, ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition size;
|
2009-03-02 23:31:01 +00:00
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
GdkRectangle prog_area;
|
|
|
|
GdkRectangle fill_area;
|
|
|
|
const char * name;
|
|
|
|
GdkPixbuf * icon;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrColor text_color;
|
2011-05-28 00:09:15 +00:00
|
|
|
bool seed;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
2012-12-14 20:04:37 +00:00
|
|
|
const tr_torrent * tor = p->tor;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_stat * st = tr_torrentStatCached ((tr_torrent*)tor);
|
|
|
|
const gboolean active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) && (st->activity != TR_STATUS_SEED_WAIT);
|
|
|
|
const double percentDone = get_percent_done (tor, st, &seed);
|
2009-08-13 14:23:47 +00:00
|
|
|
const gboolean sensitive = active || st->error;
|
2011-04-12 10:04:05 +00:00
|
|
|
GString * gstr_stat = p->gstr1;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
icon = get_icon (tor, COMPACT_ICON_SIZE, widget);
|
|
|
|
name = tr_torrentName (tor);
|
|
|
|
g_string_truncate (gstr_stat, 0);
|
|
|
|
getShortStatusString (gstr_stat, tor, st, p->upload_speed_KBps, p->download_speed_KBps);
|
|
|
|
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
|
|
|
|
get_text_color (widget, st, &text_color);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
fill_area = *background_area;
|
2010-12-24 09:04:52 +00:00
|
|
|
fill_area.x += xpad;
|
|
|
|
fill_area.y += ypad;
|
|
|
|
fill_area.width -= xpad * 2;
|
|
|
|
fill_area.height -= ypad * 2;
|
2010-07-31 03:43:12 +00:00
|
|
|
icon_area = name_area = stat_area = prog_area = fill_area;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->icon_renderer, "pixbuf", icon, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->icon_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
icon_area.width = size.width;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
name_area.width = size.width;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
stat_area.width = size.width;
|
2010-03-15 14:42:43 +00:00
|
|
|
|
2010-07-31 03:43:12 +00:00
|
|
|
icon_area.x = fill_area.x;
|
2010-03-15 14:42:43 +00:00
|
|
|
prog_area.x = fill_area.x + fill_area.width - BAR_WIDTH;
|
|
|
|
prog_area.width = BAR_WIDTH;
|
|
|
|
stat_area.x = prog_area.x - GUI_PAD - stat_area.width;
|
2009-03-02 23:31:01 +00:00
|
|
|
name_area.x = icon_area.x + icon_area.width + GUI_PAD;
|
2010-07-31 03:43:12 +00:00
|
|
|
name_area.y = fill_area.y;
|
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
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
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", (int)(percentDone*100.0), "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);
|
|
|
|
g_object_set (p->text_renderer, "text", name, "scale", 1.0, FOREGROUND_COLOR_KEY, &text_color, NULL);
|
|
|
|
gtr_cell_renderer_render (p->text_renderer, window, widget, &name_area, flags);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
render_full (TorrentCellRenderer * cell,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrDrawable * window,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
2011-07-26 01:02:32 +00:00
|
|
|
const GdkRectangle * background_area,
|
|
|
|
const GdkRectangle * cell_area UNUSED,
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkCellRendererState flags)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2010-12-24 09:04:52 +00:00
|
|
|
int xpad, ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition size;
|
2009-03-02 23:31:01 +00:00
|
|
|
GdkRectangle fill_area;
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GdkRectangle name_area;
|
|
|
|
GdkRectangle stat_area;
|
|
|
|
GdkRectangle prog_area;
|
|
|
|
GdkRectangle prct_area;
|
|
|
|
const char * name;
|
|
|
|
GdkPixbuf * icon;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrColor text_color;
|
2011-05-28 00:09:15 +00:00
|
|
|
bool seed;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate * p = cell->priv;
|
2012-12-14 20:04:37 +00:00
|
|
|
const tr_torrent * tor = p->tor;
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_stat * st = tr_torrentStatCached ((tr_torrent*)tor);
|
|
|
|
const tr_info * inf = tr_torrentInfo (tor);
|
|
|
|
const gboolean active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) && (st->activity != TR_STATUS_SEED_WAIT);
|
|
|
|
const double percentDone = get_percent_done (tor, st, &seed);
|
2009-08-13 14:23:47 +00:00
|
|
|
const gboolean sensitive = active || st->error;
|
2011-04-12 10:04:05 +00:00
|
|
|
GString * gstr_prog = p->gstr1;
|
|
|
|
GString * gstr_stat = p->gstr2;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
icon = get_icon (tor, FULL_ICON_SIZE, widget);
|
|
|
|
name = tr_torrentName (tor);
|
|
|
|
g_string_truncate (gstr_prog, 0);
|
|
|
|
getProgressString (gstr_prog, tor, inf, st);
|
|
|
|
g_string_truncate (gstr_stat, 0);
|
|
|
|
getStatusString (gstr_stat, tor, st, p->upload_speed_KBps, p->download_speed_KBps);
|
|
|
|
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
|
|
|
|
get_text_color (widget, st, &text_color);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* get the idealized cell dimensions */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->icon_renderer, "pixbuf", icon, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->icon_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
icon_area.width = size.width;
|
|
|
|
icon_area.height = size.height;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
name_area.width = size.width;
|
|
|
|
name_area.height = size.height;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
prog_area.width = size.width;
|
|
|
|
prog_area.height = size.height;
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_set (p->text_renderer, "text", gstr_stat->str, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size (p->text_renderer, widget, NULL, &size);
|
2011-07-26 01:02:32 +00:00
|
|
|
stat_area.width = size.width;
|
|
|
|
stat_area.height = size.height;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-03-02 23:31:01 +00:00
|
|
|
/**
|
|
|
|
*** LAYOUT
|
|
|
|
**/
|
|
|
|
|
|
|
|
fill_area = *background_area;
|
2010-12-24 09:04:52 +00:00
|
|
|
fill_area.x += xpad;
|
|
|
|
fill_area.y += ypad;
|
|
|
|
fill_area.width -= xpad * 2;
|
|
|
|
fill_area.height -= ypad * 2;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* icon */
|
|
|
|
icon_area.x = fill_area.x;
|
2012-12-05 17:29:46 +00:00
|
|
|
icon_area.y = fill_area.y + (fill_area.height - icon_area.height) / 2;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
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->text_renderer, "text", name, "scale", 1.0, FOREGROUND_COLOR_KEY, &text_color, "ellipsize", PANGO_ELLIPSIZE_END, "weight", PANGO_WEIGHT_BOLD, NULL);
|
|
|
|
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", (int)(percentDone*100.0), "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);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_unref (icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_render (GtkCellRenderer * cell,
|
2011-07-26 01:02:32 +00:00
|
|
|
GtrDrawable * window,
|
2009-03-02 23:31:01 +00:00
|
|
|
GtkWidget * widget,
|
2011-07-26 01:02:32 +00:00
|
|
|
const GdkRectangle * background_area,
|
|
|
|
const GdkRectangle * cell_area,
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkCellRendererState flags)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER (cell);
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
2012-12-05 17:29:46 +00:00
|
|
|
GtkTextDirection real_dir = gtk_widget_get_direction (widget);
|
|
|
|
gtk_widget_set_direction (widget, GTK_TEXT_DIR_RTL);
|
2008-02-16 19:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (self && self->priv->tor)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2007-12-19 20:04:38 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
2012-12-05 17:29:46 +00:00
|
|
|
if (p->compact)
|
|
|
|
render_compact (self, window, widget, background_area, cell_area, flags);
|
2007-12-19 20:04:38 +00:00
|
|
|
else
|
2012-12-05 17:29:46 +00:00
|
|
|
render_full (self, window, widget, background_area, cell_area, flags);
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
2012-12-05 17:29:46 +00:00
|
|
|
gtk_widget_set_direction (widget, real_dir);
|
2008-02-16 19:36:07 +00:00
|
|
|
#endif
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +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,
|
2012-12-05 17:29:46 +00:00
|
|
|
GParamSpec * pspec)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
TorrentCellRenderer * self = TORRENT_CELL_RENDERER (object);
|
2007-12-19 02:46:30 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (property_id)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +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;
|
|
|
|
default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_get_property (GObject * object,
|
2009-08-07 20:49:06 +00:00
|
|
|
guint property_id,
|
|
|
|
GValue * v,
|
2012-12-05 17:29:46 +00:00
|
|
|
GParamSpec * pspec)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const TorrentCellRenderer * self = TORRENT_CELL_RENDERER (object);
|
2007-12-19 02:46:30 +00:00
|
|
|
struct TorrentCellRendererPrivate * p = self->priv;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (property_id)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
case P_TORRENT: g_value_set_pointer (v, p->tor); break;
|
|
|
|
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;
|
|
|
|
case P_BAR_HEIGHT: g_value_set_int (v, p->bar_height); break;
|
|
|
|
case P_COMPACT: g_value_set_boolean (v, p->compact); break;
|
|
|
|
default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break;
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-09 06:31:33 +00:00
|
|
|
G_DEFINE_TYPE (TorrentCellRenderer, torrent_cell_renderer, GTK_TYPE_CELL_RENDERER)
|
|
|
|
|
2008-01-12 17:59:09 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_dispose (GObject * o)
|
2008-01-12 17:59:09 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
TorrentCellRenderer * r = TORRENT_CELL_RENDERER (o);
|
2008-02-09 17:25:14 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (r && r->priv)
|
2008-01-12 17:59:09 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
g_string_free (r->priv->gstr1, TRUE);
|
|
|
|
g_string_free (r->priv->gstr2, TRUE);
|
|
|
|
g_object_unref (G_OBJECT (r->priv->text_renderer));
|
|
|
|
g_object_unref (G_OBJECT (r->priv->progress_renderer));
|
|
|
|
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
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
G_OBJECT_CLASS (torrent_cell_renderer_parent_class)->dispose (o);
|
2008-01-12 17:59:09 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_class_init (TorrentCellRendererClass * klass)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
GObjectClass * gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkCellRendererClass * cell_class = GTK_CELL_RENDERER_CLASS (klass);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_type_class_add_private (klass,
|
|
|
|
sizeof (struct TorrentCellRendererPrivate));
|
2007-12-19 02:46:30 +00:00
|
|
|
|
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
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_class_install_property (gobject_class, P_TORRENT,
|
|
|
|
g_param_spec_pointer ("torrent", NULL,
|
2008-09-23 19:11:04 +00:00
|
|
|
"tr_torrent*",
|
2012-12-05 17:29:46 +00:00
|
|
|
G_PARAM_READWRITE));
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_class_install_property (gobject_class, P_UPLOAD_SPEED,
|
|
|
|
g_param_spec_double ("piece-upload-speed", NULL,
|
2010-07-04 06:07:21 +00:00
|
|
|
"tr_stat.pieceUploadSpeed_KBps",
|
|
|
|
0, INT_MAX, 0,
|
2012-12-05 17:29:46 +00:00
|
|
|
G_PARAM_READWRITE));
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_class_install_property (gobject_class, P_DOWNLOAD_SPEED,
|
|
|
|
g_param_spec_double ("piece-download-speed", NULL,
|
2010-07-04 06:07:21 +00:00
|
|
|
"tr_stat.pieceDownloadSpeed_KBps",
|
|
|
|
0, INT_MAX, 0,
|
2012-12-05 17:29:46 +00:00
|
|
|
G_PARAM_READWRITE));
|
2009-08-07 20:49:06 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_class_install_property (gobject_class, P_BAR_HEIGHT,
|
|
|
|
g_param_spec_int ("bar-height", NULL,
|
2008-09-23 19:11:04 +00:00
|
|
|
"Bar Height",
|
|
|
|
1, INT_MAX,
|
|
|
|
DEFAULT_BAR_HEIGHT,
|
2012-12-05 17:29:46 +00:00
|
|
|
G_PARAM_READWRITE));
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
g_object_class_install_property (gobject_class, P_COMPACT,
|
|
|
|
g_param_spec_boolean ("compact", NULL,
|
2010-03-15 14:42:43 +00:00
|
|
|
"Compact Mode",
|
2008-09-23 19:11:04 +00:00
|
|
|
FALSE,
|
2012-12-05 17:29:46 +00:00
|
|
|
G_PARAM_READWRITE));
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_init (TorrentCellRenderer * self)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
|
|
|
struct TorrentCellRendererPrivate * p;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
|
2008-09-23 19:11:04 +00:00
|
|
|
self,
|
|
|
|
TORRENT_CELL_RENDERER_TYPE,
|
|
|
|
struct
|
2012-12-05 17:29:46 +00:00
|
|
|
TorrentCellRendererPrivate);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
p->tor = NULL;
|
2012-12-05 17:29:46 +00:00
|
|
|
p->gstr1 = g_string_new (NULL);
|
|
|
|
p->gstr2 = g_string_new (NULL);
|
|
|
|
p->text_renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (p->text_renderer, "xpad", 0, "ypad", 0, NULL);
|
|
|
|
p->progress_renderer = gtk_cell_renderer_progress_new ();
|
|
|
|
p->icon_renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
g_object_ref_sink (p->text_renderer);
|
|
|
|
g_object_ref_sink (p->progress_renderer);
|
|
|
|
g_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkCellRenderer *
|
2012-12-05 17:29:46 +00:00
|
|
|
torrent_cell_renderer_new (void)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +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
|
|
|
|