Ejemplo n.º 1
0
static gboolean
updateStats (gpointer gdata)
{
    char buf[128];
    const char * fmt;
    tr_session_stats one, all;
    const size_t buflen = sizeof (buf);
    struct stat_ui * ui = gdata;

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

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

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

    return TRUE;
}
Ejemplo n.º 2
0
static void
save_recent_destination( TrCore * core, const char * dir  )
{
    int i;
    GSList * l;
    GSList * list = get_recent_destinations( );

    if( dir == NULL )
        return;

    /* if it was already in the list, remove it */
    if(( l = g_slist_find_custom( list, dir, (GCompareFunc)strcmp )))
        list = g_slist_delete_link( list, l );

    /* add it to the front of the list */
    list = g_slist_prepend( list, (void*)dir );

    /* make local copies of the strings that aren't
     * invalidated by gtr_pref_string_set() */
    for( l=list; l; l=l->next )
        l->data = g_strdup( l->data );

    /* save the first N_RECENT directories */
    for( l=list, i=0; l && ( i<N_RECENT ); ++i, l=l->next ) {
        char key[64];
        g_snprintf( key, sizeof( key ), "recent-download-dir-%d", i + 1 );
        gtr_pref_string_set( key, l->data );
    }
    gtr_pref_save( gtr_core_session( core ) );

    /* cleanup */
    g_slist_foreach( list, (GFunc)g_free, NULL );
    g_slist_free( list );
}