Beispiel #1
0
static gboolean
updateStats( gpointer gdata )
{
    const char *     fmt;
    char             buf[128];

    struct stat_ui * ui = gdata;
    tr_session_stats one, all;

    tr_sessionGetStats( tr_core_session( ui->core ), &one );
    tr_sessionGetCumulativeStats( tr_core_session( ui->core ), &all );

    setLabel( ui->one_up_lb,
             tr_strlsize( buf, one.uploadedBytes, sizeof( buf ) ) );
    setLabel( ui->one_down_lb,
             tr_strlsize( buf, one.downloadedBytes, sizeof( buf ) ) );
    setLabel( ui->one_time_lb,
             tr_strltime( buf, one.secondsActive, sizeof( buf ) ) );
    setLabelFromRatio( ui->one_ratio_lb, one.ratio );

    fmt = ngettext( "Started %'d time", "Started %'d times",
                    (int)all.sessionCount );
    g_snprintf( buf, sizeof( buf ), fmt, (int)all.sessionCount );
    setLabel( ui->all_sessions_lb, buf );
    setLabel( ui->all_up_lb,
             tr_strlsize( buf, all.uploadedBytes, sizeof( buf ) ) );
    setLabel( ui->all_down_lb,
             tr_strlsize( buf, all.downloadedBytes, sizeof( buf ) ) );
    setLabel( ui->all_time_lb,
             tr_strltime( buf, all.secondsActive, sizeof( buf ) ) );
    setLabelFromRatio( ui->all_ratio_lb, all.ratio );

    return TRUE;
}
Beispiel #2
0
static void
refreshFromBuilder( MakeMetaUI * ui )
{
    char                  sizeStr[128];
    char                * buf;
    tr_metainfo_builder * builder = ui->builder;
    const char *          filename = builder ? builder->top : NULL;


    /* update the progressbar */
    if( !filename )
        buf = g_strdup( _( "No source selected" ) );
    else
        buf = g_strdup_printf( "%s.torrent (%d%%)", filename, 0 );
    gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ), buf );
    refreshButtons( ui );
    g_free( buf );

    /* update the size label */
    if( !filename )
        buf = g_strdup( "<i>No source selected</i>" );
    else {
        tr_strlsize( sizeStr, builder->totalSize, sizeof( sizeStr ) );
        buf = g_strdup_printf( /* %1$s is the torrent size
                                  %2$'d is its number of files */
                               ngettext( "<i>%1$s; %2$'d File</i>",
                                         "<i>%1$s; %2$'d Files</i>",
                                         builder->fileCount ),
                               sizeStr, builder->fileCount );
    }
    gtk_label_set_markup ( GTK_LABEL( ui->size_lb ), buf );
    g_free( buf );

    /* update the pieces label */
    if( !filename )
        buf = g_strdup( "" );
    else {
        char * countStr = g_strdup_printf( ngettext( "%'d Piece", "%'d Pieces",
                                                     builder->pieceCount ),
                                           builder->pieceCount );
        tr_strlsize( sizeStr, builder->pieceSize, sizeof( sizeStr ) );
        buf = g_strdup_printf( /* %1$s is number of pieces;
                                  %2$s is how big each piece is */
                               _( "%1$s @ %2$s" ), countStr, sizeStr );
        g_free( countStr );
    }
    gtk_label_set_markup ( GTK_LABEL( ui->pieces_lb ), buf );
    g_free( buf );
}
Beispiel #3
0
static gboolean
onProgressDialogRefresh (gpointer data)
{
  char * str = NULL;
  MakeMetaUI * ui = data;
  const tr_metainfo_builder * b = ui->builder;
  GtkDialog * d = GTK_DIALOG (ui->progress_dialog);
  GtkProgressBar * p = GTK_PROGRESS_BAR (ui->progress_bar);
  const double fraction = b->pieceCount ? ((double)b->pieceIndex / b->pieceCount) : 0;
  char * base = g_path_get_basename (b->top);

  /* progress label */
  if (!b->isDone)
    str = g_strdup_printf (_("Creating \"%s\""), base);
  else if (b->result == TR_MAKEMETA_OK)
    str = g_strdup_printf (_("Created \"%s\"!"), base);
  else if (b->result == TR_MAKEMETA_URL)
    str = g_strdup_printf (_("Error: invalid announce URL \"%s\""), b->errfile);
  else if (b->result == TR_MAKEMETA_CANCELLED)
    str = g_strdup_printf (_("Cancelled"));
  else if (b->result == TR_MAKEMETA_IO_READ)
    str = g_strdup_printf (_("Error reading \"%s\": %s"), b->errfile, g_strerror (b->my_errno));
  else if (b->result == TR_MAKEMETA_IO_WRITE)
    str = g_strdup_printf (_("Error writing \"%s\": %s"), b->errfile, g_strerror (b->my_errno));
  else
    g_assert_not_reached ();

  if (str != NULL)
    {
      gtr_label_set_text (GTK_LABEL (ui->progress_label), str);
      g_free (str);
    }

  /* progress bar */
  if (!b->pieceIndex)
    {
      str = g_strdup ("");
    }
  else
    {
      char sizebuf[128];
      tr_strlsize (sizebuf, (uint64_t)b->pieceIndex *
                            (uint64_t)b->pieceSize, sizeof (sizebuf));
      /* how much data we've scanned through to generate checksums */
      str = g_strdup_printf (_("Scanned %s"), sizebuf);
    }
  gtk_progress_bar_set_fraction (p, fraction);
  gtk_progress_bar_set_text (p, str);
  g_free (str);

  /* buttons */
  gtk_dialog_set_response_sensitive (d, GTK_RESPONSE_CANCEL, !b->isDone);
  gtk_dialog_set_response_sensitive (d, GTK_RESPONSE_CLOSE, b->isDone);
  gtk_dialog_set_response_sensitive (d, GTK_RESPONSE_ACCEPT, b->isDone && !b->result);

  g_free (base);
  return G_SOURCE_CONTINUE;
}
static void
getProgressString( GString          * gstr,
                   const tr_torrent * tor,
                   const tr_info    * info,
                   const tr_stat    * st )
{
    const int      isDone = st->leftUntilDone == 0;
    const uint64_t haveTotal = st->haveUnchecked + st->haveValid;
    const int      isSeed = st->haveValid >= info->totalSize;
    char           buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32];
    double         seedRatio;
    const gboolean hasSeedRatio = tr_torrentGetSeedRatio( tor, &seedRatio );

    if( !isDone ) /* downloading */
    {
        g_string_append_printf( gstr,
            /* %1$s is how much we've got,
               %2$s is how much we'll have when done,
               %3$s%% is a percentage of the two */
            _( "%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 ) ) );
    }
    else if( !isSeed ) /* partial seeds */
    {
        if( hasSeedRatio )
        {
            g_string_append_printf( gstr,
                /* %1$s is how much we've got,
                   %2$s is the torrent's total size,
                   %3$s%% is a percentage of the two,
                   %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 */
                _( "%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 ) ) );
        }
        else
        {
            g_string_append_printf( gstr,
                /* %1$s is how much we've got,
                   %2$s is the torrent's total size,
                   %3$s%% is a percentage of the two,
                   %4$s is how much we've uploaded,
                   %5$s is our upload-to-download ratio */
                _( "%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 ) ) );
        }
    }
    else /* seeding */
    {
        if( hasSeedRatio )
        {
            g_string_append_printf( gstr,
                /* %1$s is the torrent's total size,
                   %2$s is how much we've uploaded,
                   %3$s is our upload-to-download ratio,
                   %4$s is the ratio we want to reach before we stop uploading */
                _( "%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)" ),
                tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
                tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ),
                tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ),
                tr_strlratio( buf4, seedRatio, sizeof( buf4 ) ) );
        }
        else /* seeding w/o a ratio */
        {
            g_string_append_printf( gstr,
                /* %1$s is the torrent's total size,
                   %2$s is how much we've uploaded,
                   %3$s is our upload-to-download ratio */
                _( "%1$s, uploaded %2$s (Ratio: %3$s)" ),
                tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
                tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ),
                tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ) );
        }
    }

    /* add time when downloading */
    if( ( st->activity == TR_STATUS_DOWNLOAD )
        || ( hasSeedRatio && ( st->activity == TR_STATUS_SEED ) ) )
    {
        const int eta = st->eta;
        g_string_append( gstr, " - " );
        if( eta < 0 )
            g_string_append( gstr, _( "Remaining time unknown" ) );
        else
        {
            char timestr[128];
            tr_strltime( timestr, eta, sizeof( timestr ) );
            /* time remaining */
            g_string_append_printf( gstr, _( "%s remaining" ), timestr );
        }
    }
}
static char*
getProgressString( const tr_info * info,
                   const tr_stat * torStat )
{
    const int      isDone = torStat->leftUntilDone == 0;
    const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid;
    const int      isSeed = torStat->haveValid >= info->totalSize;
    char           buf1[32], buf2[32], buf3[32], buf4[32];
    char *         str;

    if( !isDone )
        str = g_strdup_printf(
            /* %1$s is how much we've got,
               %2$s is how much we'll have when done,
               %3$.2f%% is a percentage of the two */
            _( "%1$s of %2$s (%3$.2f%%)" ),
            tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
            tr_strlsize( buf2, torStat->sizeWhenDone, sizeof( buf2 ) ),
            torStat->percentDone * 100.0 );
    else if( !isSeed )
        str = g_strdup_printf(
            /* %1$s is how much we've got,
               %2$s is the torrent's total size,
               %3$.2f%% is a percentage of the two,
               %4$s is how much we've uploaded,
               %5$s is our upload-to-download ratio */
            _( "%1$s of %2$s (%3$.2f%%), uploaded %4$s (Ratio: %5$s)" ),
            tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ),
            tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ),
            torStat->percentComplete * 100.0,
            tr_strlsize( buf3, torStat->uploadedEver, sizeof( buf3 ) ),
            tr_strlratio( buf4, torStat->ratio, sizeof( buf4 ) ) );
    else
        str = g_strdup_printf(
            /* %1$s is the torrent's total size,
               %2$s is how much we've uploaded,
               %3$s is our upload-to-download ratio */
            _( "%1$s, uploaded %2$s (Ratio: %3$s)" ),
            tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ),
            tr_strlsize( buf2, torStat->uploadedEver, sizeof( buf2 ) ),
            tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );

    /* add time when downloading */
    if( torStat->activity == TR_STATUS_DOWNLOAD )
    {
        const int eta = torStat->eta;
        GString * gstr = g_string_new( str );
        g_string_append( gstr, " - " );
        if( eta < 0 )
            g_string_append( gstr, _( "Remaining time unknown" ) );
        else
        {
            char timestr[128];
            tr_strltime( timestr, eta, sizeof( timestr ) );
            /* time remaining */
            g_string_append_printf( gstr, _( "%s remaining" ), timestr );
        }
        g_free( str );
        str = g_string_free( gstr, FALSE );
    }

    return str;
}