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
|
|
|
*
|
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>
|
2017-04-21 07:40:57 +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
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void getProgressString(GString* gstr, tr_torrent const* tor, tr_info const* info, tr_stat const* st)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
bool const isDone = st->leftUntilDone == 0;
|
2017-04-20 16:02:19 +00:00
|
|
|
uint64_t const haveTotal = st->haveUnchecked + st->haveValid;
|
2017-04-30 16:25:26 +00:00
|
|
|
bool const isSeed = st->haveValid >= info->totalSize;
|
2017-05-01 15:46:41 +00:00
|
|
|
char buf1[32];
|
|
|
|
char buf2[32];
|
|
|
|
char buf3[32];
|
|
|
|
char buf4[32];
|
|
|
|
char buf5[32];
|
|
|
|
char buf6[32];
|
2017-04-19 12:04:45 +00:00
|
|
|
double seedRatio;
|
2017-04-30 16:25:26 +00:00
|
|
|
bool const 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
|
|
|
{
|
2017-04-19 12:04:45 +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%%)"),
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +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)"),
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
|
{
|
2017-04-19 12:04:45 +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)"),
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +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)"),
|
2017-04-19 12:04:45 +00:00
|
|
|
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 */
|
|
|
|
{
|
2017-04-19 12:04:45 +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)"),
|
2017-04-19 12:04:45 +00:00
|
|
|
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 */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (st->activity == TR_STATUS_DOWNLOAD || (hasSeedRatio && st->activity == TR_STATUS_SEED))
|
2008-02-09 16:05:29 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const eta = st->eta;
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append(gstr, " - ");
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (eta < 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
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];
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strltime(timestr, eta, sizeof(timestr));
|
2008-03-08 04:53:11 +00:00
|
|
|
/* time remaining */
|
2017-04-19 12:04:45 +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
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static char* getShortTransferString(tr_torrent const* tor, tr_stat const* st, double uploadSpeed_KBps,
|
2017-04-19 12:04:45 +00:00
|
|
|
double downloadSpeed_KBps, char* buf, size_t buflen)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
bool const haveMeta = tr_torrentHasMetadata(tor);
|
|
|
|
bool const haveUp = haveMeta && st->peersGettingFromUs > 0;
|
|
|
|
bool const haveDown = haveMeta && (st->peersSendingToUs > 0 || st->webseedsSendingToUs > 0);
|
2013-01-27 23:05:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (haveDown)
|
2013-01-27 23:05:47 +00:00
|
|
|
{
|
2019-03-17 06:15:35 +00:00
|
|
|
char dnStr[32];
|
|
|
|
char upStr[32];
|
2017-04-19 12:04:45 +00:00
|
|
|
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"), dnStr, gtr_get_unicode_string(GTR_UNICODE_DOWN), upStr,
|
|
|
|
gtr_get_unicode_string(GTR_UNICODE_UP));
|
2013-01-27 23:05:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (haveUp)
|
2013-01-27 23:05:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char upStr[32];
|
|
|
|
tr_formatter_speed_KBps(upStr, uploadSpeed_KBps, sizeof(upStr));
|
2013-01-30 00:22:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* up speed, up symbol */
|
|
|
|
g_snprintf(buf, buflen, _("%1$s %2$s"), upStr, gtr_get_unicode_string(GTR_UNICODE_UP));
|
2013-01-27 23:05:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (st->isStalled)
|
2013-01-27 23:05:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_strlcpy(buf, _("Stalled"), buflen);
|
2013-01-27 23:05:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-27 23:05:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*buf = '\0';
|
2013-01-27 23:05:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return buf;
|
2007-12-20 02:02:51 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void getShortStatusString(GString* gstr, tr_torrent const* tor, tr_stat const* st, double uploadSpeed_KBps,
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
g_string_append(gstr, st->finished ? _("Finished") : _("Paused"));
|
|
|
|
break;
|
2011-08-08 16:38:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
g_string_append(gstr, _("Queued for verification"));
|
|
|
|
break;
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
g_string_append(gstr, _("Queued for download"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
|
|
|
g_string_append(gstr, _("Queued for seeding"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
g_string_append_printf(gstr, _("Verifying local data (%.1f%% tested)"),
|
|
|
|
tr_truncd(st->recheckProgress * 100.0, 1));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
case TR_STATUS_SEED:
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2013-01-30 00:22:52 +00:00
|
|
|
char speedStr[64];
|
|
|
|
char ratioStr[64];
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strlratio(ratioStr, st->ratio, sizeof(ratioStr));
|
|
|
|
getShortTransferString(tor, st, uploadSpeed_KBps, downloadSpeed_KBps, speedStr, sizeof(speedStr));
|
2013-01-30 00:22:52 +00:00
|
|
|
/* download/upload speed, ratio */
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-12-19 18:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void getStatusString(GString* gstr, tr_torrent const* tor, tr_stat const* st, double const uploadSpeed_KBps,
|
|
|
|
double const downloadSpeed_KBps)
|
2007-12-19 18:11:10 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
if (st->error != 0)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* fmt[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2017-04-21 07:40:57 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
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:
|
2012-10-07 17:51:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
getShortStatusString(gstr, tor, st, uploadSpeed_KBps, downloadSpeed_KBps);
|
|
|
|
break;
|
2009-11-24 15:51:16 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2009-11-24 15:51:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!tr_torrentHasMetadata(tor))
|
|
|
|
{
|
|
|
|
/* Downloading metadata from 2 peer (s)(50% done) */
|
|
|
|
g_string_append_printf(gstr, _("Downloading metadata from %1$'d %2$s (%3$d%% done)"), st->peersConnected,
|
|
|
|
ngettext("peer", "peers", st->peersConnected), (int)(100.0 * st->metadataPercentComplete));
|
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (st->peersSendingToUs != 0 && st->webseedsSendingToUs != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
/* Downloading from 2 of 3 peer (s) and 2 webseed (s) */
|
2017-04-21 07:40:57 +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, ngettext("peer", "peers", st->peersConnected), st->webseedsSendingToUs,
|
2017-04-19 12:04:45 +00:00
|
|
|
ngettext("web seed", "web seeds", st->webseedsSendingToUs));
|
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (st->webseedsSendingToUs != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
/* Downloading from 3 web seed (s) */
|
|
|
|
g_string_append_printf(gstr, _("Downloading from %1$'d %2$s"), st->webseedsSendingToUs,
|
|
|
|
ngettext("web seed", "web seeds", st->webseedsSendingToUs));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Downloading from 2 of 3 peer (s) */
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("Downloading from %1$'d of %2$'d %3$s"), st->peersSendingToUs,
|
|
|
|
st->peersConnected, ngettext("peer", "peers", st->peersConnected));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-11-24 15:51:16 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2009-11-24 15:51:16 +00:00
|
|
|
case TR_STATUS_SEED:
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, ngettext("Seeding to %1$'d of %2$'d connected peer",
|
|
|
|
"Seeding to %1$'d of %2$'d connected peers", st->peersConnected), st->peersGettingFromUs, st->peersConnected);
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-04-21 07:40:57 +00:00
|
|
|
}
|
2009-11-24 15:51:16 +00:00
|
|
|
|
2017-04-30 16:25:26 +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];
|
2017-04-19 12:04:45 +00:00
|
|
|
getShortTransferString(tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof(buf));
|
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
if (!tr_str_is_empty(buf))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_string_append_printf(gstr, " - %s", buf);
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor;
|
|
|
|
GtkCellRenderer* text_renderer;
|
|
|
|
GtkCellRenderer* progress_renderer;
|
|
|
|
GtkCellRenderer* icon_renderer;
|
|
|
|
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
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static GdkPixbuf* get_icon(tr_torrent const* tor, GtkIconSize icon_size, GtkWidget* for_widget)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* mime_type;
|
|
|
|
tr_info const* info = tr_torrentInfo(tor);
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (info->fileCount == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2009-11-24 02:16:31 +00:00
|
|
|
mime_type = UNKNOWN_MIME_TYPE;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else if (info->fileCount > 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (strchr(info->files[0].name, '/') != NULL)
|
|
|
|
{
|
2010-02-26 15:06:26 +00:00
|
|
|
mime_type = DIRECTORY_MIME_TYPE;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
mime_type = gtr_get_mime_type_from_filename(info->files[0].name);
|
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return gtr_get_mime_type_icon(mime_type, icon_size, for_widget);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void gtr_cell_renderer_get_preferred_size(GtkCellRenderer* renderer, GtkWidget* widget, GtkRequisition* minimum_size,
|
|
|
|
GtkRequisition* natural_size)
|
2011-07-26 01:02:32 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_cell_renderer_get_preferred_size(renderer, widget, minimum_size, natural_size);
|
2011-07-26 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void get_size_compact(TorrentCellRenderer* cell, GtkWidget* widget, gint* width, gint* height)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int xpad;
|
|
|
|
int ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition icon_size;
|
|
|
|
GtkRequisition name_size;
|
|
|
|
GtkRequisition stat_size;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name;
|
2017-04-19 12:04:45 +00:00
|
|
|
GdkPixbuf* icon;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p = cell->priv;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = p->tor;
|
|
|
|
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
GString* gstr_stat = p->gstr1;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +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 */
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set(p->icon_renderer, "pixbuf", icon, NULL);
|
|
|
|
gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, NULL, &icon_size);
|
2017-04-21 07:40:57 +00:00
|
|
|
g_object_set(p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (width != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
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;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (height != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
*height = ypad * 2 + MAX(name_size.height, p->bar_height);
|
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
#define MAX3(a, b, c) MAX(a, MAX(b, c))
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void get_size_full(TorrentCellRenderer* cell, GtkWidget* widget, gint* width, gint* height)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int xpad;
|
|
|
|
int ypad;
|
2011-07-26 01:02:32 +00:00
|
|
|
GtkRequisition icon_size;
|
|
|
|
GtkRequisition name_size;
|
|
|
|
GtkRequisition stat_size;
|
|
|
|
GtkRequisition prog_size;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name;
|
2017-04-19 12:04:45 +00:00
|
|
|
GdkPixbuf* icon;
|
|
|
|
|
|
|
|
struct TorrentCellRendererPrivate* p = cell->priv;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = p->tor;
|
|
|
|
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
|
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
GString* gstr_prog = p->gstr1;
|
|
|
|
GString* gstr_stat = p->gstr2;
|
|
|
|
|
|
|
|
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 */
|
2017-04-19 12:04:45 +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)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
*width = xpad * 2 + icon_size.width + GUI_PAD + MAX3(name_size.width, prog_size.width, stat_size.width);
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (height != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
*height = ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL +
|
|
|
|
stat_size.height;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-03-02 23:31:01 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void torrent_cell_renderer_get_size(GtkCellRenderer* cell, GtkWidget* widget, GdkRectangle const* cell_area,
|
2017-04-19 12:04:45 +00:00
|
|
|
gint* x_offset, gint* y_offset, gint* width, gint* height)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(cell);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (self != NULL && self->priv->tor != NULL)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int w;
|
|
|
|
int h;
|
2017-04-19 12:04:45 +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)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
get_size_compact(TORRENT_CELL_RENDERER(cell), widget, &w, &h);
|
|
|
|
}
|
2007-12-19 18:11:10 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
get_size_full(TORRENT_CELL_RENDERER(cell), widget, &w, &h);
|
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (width != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
*width = w;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (height != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2009-03-02 23:31:01 +00:00
|
|
|
*height = h;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (x_offset != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2010-09-27 20:24:41 +00:00
|
|
|
*x_offset = cell_area ? cell_area->x : 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (y_offset != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2019-03-17 06:15:35 +00:00
|
|
|
int xpad;
|
|
|
|
int ypad;
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
|
|
|
|
*y_offset = cell_area ? (int)((cell_area->height - (ypad * 2 + h)) / 2.0) : 0;
|
2010-12-24 09:04:52 +00:00
|
|
|
}
|
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
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void get_text_color(GtkWidget* w, tr_stat const* st, GtrColor* setme)
|
2011-01-22 13:26:44 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
static GdkRGBA const red = { 1.0, 0, 0, 0 };
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (st->error != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
*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
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static double get_percent_done(tr_torrent const* tor, tr_stat const* st, bool* seed)
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
double d;
|
2011-05-28 00:09:15 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (st->activity == TR_STATUS_SEED && tr_torrentGetSeedRatio(tor, &d))
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*seed = true;
|
|
|
|
d = MAX(0.0, st->seedRatioPercentDone);
|
2011-05-28 00:09:15 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2011-05-28 00:09:15 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*seed = false;
|
|
|
|
d = MAX(0.0, st->percentDone);
|
2011-05-28 00:09:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void gtr_cell_renderer_render(GtkCellRenderer* renderer, GtrDrawable* drawable, GtkWidget* widget,
|
2017-04-20 16:02:19 +00:00
|
|
|
GdkRectangle const* area, GtkCellRendererState flags)
|
2011-07-26 01:02:32 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_cell_renderer_render(renderer, drawable, widget, area, area, flags);
|
2011-07-26 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void render_compact(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
|
2019-02-10 11:05:16 +00:00
|
|
|
GdkRectangle const* background_area, GdkRectangle const* cell_area UNUSED,
|
|
|
|
GtkCellRendererState flags)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int xpad;
|
|
|
|
int 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;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name;
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p = cell->priv;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = p->tor;
|
|
|
|
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
|
2017-04-30 16:25:26 +00:00
|
|
|
gboolean const active = st->activity != TR_STATUS_STOPPED && st->activity != TR_STATUS_DOWNLOAD_WAIT &&
|
|
|
|
st->activity != TR_STATUS_SEED_WAIT;
|
2017-04-20 16:02:19 +00:00
|
|
|
double const percentDone = get_percent_done(tor, st, &seed);
|
|
|
|
gboolean const sensitive = active || st->error;
|
2017-04-19 12:04:45 +00:00
|
|
|
GString* gstr_stat = p->gstr1;
|
2009-03-02 23:31:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +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;
|
2017-04-19 12:04:45 +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;
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +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 */
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget, GdkRectangle const* background_area,
|
|
|
|
GdkRectangle const* cell_area UNUSED, GtkCellRendererState flags)
|
2009-03-02 23:31:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int xpad;
|
|
|
|
int 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;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* name;
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p = cell->priv;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = p->tor;
|
|
|
|
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
|
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2017-04-30 16:25:26 +00:00
|
|
|
gboolean const active = st->activity != TR_STATUS_STOPPED && st->activity != TR_STATUS_DOWNLOAD_WAIT &&
|
|
|
|
st->activity != TR_STATUS_SEED_WAIT;
|
2017-04-20 16:02:19 +00:00
|
|
|
double const percentDone = get_percent_done(tor, st, &seed);
|
|
|
|
gboolean const sensitive = active || st->error;
|
2017-04-19 12:04:45 +00:00
|
|
|
GString* gstr_prog = p->gstr1;
|
|
|
|
GString* gstr_stat = p->gstr2;
|
|
|
|
|
|
|
|
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 */
|
2017-04-19 12:04:45 +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;
|
2017-04-19 12:04:45 +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;
|
2017-04-19 12:04:45 +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;
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +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);
|
2017-04-21 07:40:57 +00:00
|
|
|
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);
|
2017-04-19 12:04:45 +00:00
|
|
|
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 */
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_unref(icon);
|
2009-03-02 23:31:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void torrent_cell_renderer_render(GtkCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
|
2019-02-10 11:05:16 +00:00
|
|
|
GdkRectangle const* background_area, GdkRectangle const* cell_area,
|
|
|
|
GtkCellRendererState flags)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(cell);
|
2008-02-16 19:36:07 +00:00
|
|
|
|
|
|
|
#ifdef TEST_RTL
|
2017-04-19 12:04:45 +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
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (self != NULL && self->priv->tor != NULL)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p = self->priv;
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (p->compact)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
render_compact(self, window, widget, background_area, cell_area, flags);
|
|
|
|
}
|
2007-12-19 20:04:38 +00:00
|
|
|
else
|
2017-04-19 12:04:45 +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
|
2017-04-19 12:04:45 +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
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void torrent_cell_renderer_set_property(GObject* object, guint property_id, GValue const* v, GParamSpec* pspec)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(object);
|
|
|
|
struct TorrentCellRendererPrivate* p = self->priv;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (property_id)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void torrent_cell_renderer_get_property(GObject* object, guint property_id, GValue* v, GParamSpec* pspec)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
TorrentCellRenderer const* self = TORRENT_CELL_RENDERER(object);
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p = self->priv;
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (property_id)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
G_DEFINE_TYPE(TorrentCellRenderer, torrent_cell_renderer, GTK_TYPE_CELL_RENDERER)
|
2011-08-09 06:31:33 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void torrent_cell_renderer_dispose(GObject* o)
|
2008-01-12 17:59:09 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TorrentCellRenderer* r = TORRENT_CELL_RENDERER(o);
|
2008-02-09 17:25:14 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (r != NULL && r->priv != NULL)
|
2008-01-12 17:59:09 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
G_OBJECT_CLASS(torrent_cell_renderer_parent_class)->dispose(o);
|
2008-01-12 17:59:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void torrent_cell_renderer_class_init(TorrentCellRendererClass* klass)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_class_install_property(gobject_class, P_TORRENT,
|
|
|
|
g_param_spec_pointer("torrent", NULL, "tr_torrent*", G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property(gobject_class, P_UPLOAD_SPEED,
|
|
|
|
g_param_spec_double("piece-upload-speed", NULL, "tr_stat.pieceUploadSpeed_KBps", 0, INT_MAX, 0, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property(gobject_class, P_DOWNLOAD_SPEED,
|
|
|
|
g_param_spec_double("piece-download-speed", NULL, "tr_stat.pieceDownloadSpeed_KBps", 0, INT_MAX, 0, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property(gobject_class, P_BAR_HEIGHT,
|
|
|
|
g_param_spec_int("bar-height", NULL, "Bar Height", 1, INT_MAX, DEFAULT_BAR_HEIGHT, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property(gobject_class, P_COMPACT,
|
|
|
|
g_param_spec_boolean("compact", NULL, "Compact Mode", FALSE, G_PARAM_READWRITE));
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void torrent_cell_renderer_init(TorrentCellRenderer* self)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct TorrentCellRendererPrivate* p;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, TORRENT_CELL_RENDERER_TYPE, struct TorrentCellRendererPrivate);
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
p->tor = NULL;
|
2017-04-19 12:04:45 +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;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkCellRenderer* torrent_cell_renderer_new(void)
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return (GtkCellRenderer*)g_object_new(TORRENT_CELL_RENDERER_TYPE, NULL);
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|