mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
(gtk) #1026: "new torrent" dialogue: remember last announce URL
This commit is contained in:
parent
0386f8ca9d
commit
9337a6f69f
3 changed files with 78 additions and 8 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/makemeta.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "hig.h"
|
||||
#include "makemeta-ui.h"
|
||||
#include "tracker-list.h"
|
||||
|
@ -26,6 +27,7 @@
|
|||
#define UPDATE_INTERVAL_MSEC 200
|
||||
|
||||
#define UI_KEY "ui"
|
||||
#define ANNOUNCE_KEY "recent-announce-url"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -211,6 +213,16 @@ response_cb( GtkDialog* d,
|
|||
|
||||
trackers = tracker_list_get_trackers( ui->announce_list, &trackerCount );
|
||||
|
||||
pref_int_set( ANNOUNCE_KEY"-count", trackerCount );
|
||||
for( i=0; i<trackerCount; ++i )
|
||||
{
|
||||
char key[512];
|
||||
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-tier", i );
|
||||
pref_int_set( key, trackers[i].tier );
|
||||
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-announce", i );
|
||||
pref_string_set( key, trackers[i].announce );
|
||||
}
|
||||
|
||||
tr_makeMetaInfo( ui->builder,
|
||||
NULL,
|
||||
trackers, trackerCount,
|
||||
|
@ -355,6 +367,7 @@ GtkWidget*
|
|||
make_meta_ui( GtkWindow * parent,
|
||||
tr_handle * handle )
|
||||
{
|
||||
int n;
|
||||
int row = 0;
|
||||
GtkWidget * d, *t, *w, *h, *h2, *v, *focusMe, *extras;
|
||||
GtkBox * main_vbox;
|
||||
|
@ -414,6 +427,35 @@ make_meta_ui( GtkWindow * parent,
|
|||
hig_workarea_add_section_title( t, &row, _( "Trackers" ) );
|
||||
|
||||
w = tracker_list_new( NULL );
|
||||
|
||||
n = pref_int_get( ANNOUNCE_KEY"-count" );
|
||||
if( n > 0 )
|
||||
{
|
||||
int i;
|
||||
int trackerCount = 0;
|
||||
tr_tracker_info * trackers = g_new0( tr_tracker_info, n );
|
||||
|
||||
for( i=0; i<n; ++i )
|
||||
{
|
||||
char key[512];
|
||||
int tier;
|
||||
const char * announce;
|
||||
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-tier", i );
|
||||
tier = pref_int_get( key );
|
||||
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-announce", i );
|
||||
announce = pref_string_get( key );
|
||||
if( tier >= 0 && announce && *announce ) {
|
||||
trackers[trackerCount].tier = tier;
|
||||
trackers[trackerCount++].announce = (char*) announce;
|
||||
}
|
||||
}
|
||||
|
||||
if( trackerCount > 0 )
|
||||
tracker_list_add_trackers( w, trackers, trackerCount );
|
||||
|
||||
g_free( trackers );
|
||||
}
|
||||
|
||||
ui->announce_list = w;
|
||||
hig_workarea_add_wide_control( t, &row, w );
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "util.h"
|
||||
|
||||
#define UPDATE_INTERVAL_MSEC 2000
|
||||
|
||||
#define PAGE_KEY "page"
|
||||
|
||||
struct tracker_page
|
||||
{
|
||||
|
@ -85,7 +85,8 @@ tracker_model_new( tr_torrent * tor )
|
|||
GtkTreeIter iter;
|
||||
const tr_tracker_info * tinf = inf->trackers + i;
|
||||
gtk_list_store_append( store, &iter );
|
||||
gtk_list_store_set( store, &iter, TR_COL_TIER, tinf->tier + 1,
|
||||
gtk_list_store_set( store, &iter,
|
||||
TR_COL_TIER, tinf->tier + 1,
|
||||
TR_COL_ANNOUNCE, tinf->announce,
|
||||
-1 );
|
||||
}
|
||||
|
@ -139,7 +140,8 @@ onTrackerAddClicked( GtkButton * w UNUSED,
|
|||
|
||||
gtk_list_store_append( page->store, &iter );
|
||||
setTrackerChangeState( page, TRUE );
|
||||
gtk_list_store_set( page->store, &iter, TR_COL_TIER, 1,
|
||||
gtk_list_store_set( page->store, &iter,
|
||||
TR_COL_TIER, 1,
|
||||
TR_COL_ANNOUNCE, "http://",
|
||||
-1 );
|
||||
path = gtk_tree_model_get_path( GTK_TREE_MODEL( page->store ), &iter );
|
||||
|
@ -375,7 +377,7 @@ tracker_list_new( TrTorrent * gtor )
|
|||
|
||||
onTrackerSelectionChanged( sel, page );
|
||||
|
||||
g_object_set_data_full( G_OBJECT( top ), "page", page, g_free );
|
||||
g_object_set_data_full( G_OBJECT( top ), PAGE_KEY, page, g_free );
|
||||
return top;
|
||||
}
|
||||
|
||||
|
@ -384,7 +386,7 @@ tracker_list_get_trackers( GtkWidget * list,
|
|||
int * trackerCount )
|
||||
{
|
||||
struct tracker_page * page = g_object_get_data( G_OBJECT(
|
||||
list ), "page" );
|
||||
list ), PAGE_KEY );
|
||||
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
||||
const int n = gtk_tree_model_iter_n_children( model, NULL );
|
||||
tr_tracker_info * trackers;
|
||||
|
@ -395,10 +397,13 @@ tracker_list_get_trackers( GtkWidget * list,
|
|||
trackers = g_new0( tr_tracker_info, n );
|
||||
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
||||
{
|
||||
gtk_tree_model_get( model, &iter, TR_COL_TIER,
|
||||
&trackers[i].tier,
|
||||
int tier;
|
||||
gtk_tree_model_get( model, &iter,
|
||||
TR_COL_TIER, &tier,
|
||||
TR_COL_ANNOUNCE, &trackers[i].announce,
|
||||
-1 );
|
||||
/* tracker_info.tier is zero-based, but the display is 1-based */
|
||||
trackers[i].tier = tier - 1;
|
||||
++i;
|
||||
}
|
||||
while( gtk_tree_model_iter_next( model, &iter ) );
|
||||
|
@ -410,3 +415,22 @@ tracker_list_get_trackers( GtkWidget * list,
|
|||
return trackers;
|
||||
}
|
||||
|
||||
void
|
||||
tracker_list_add_trackers( GtkWidget * list,
|
||||
const tr_tracker_info * trackers,
|
||||
int trackerCount )
|
||||
{
|
||||
int i;
|
||||
struct tracker_page * page = g_object_get_data( G_OBJECT( list ), PAGE_KEY );
|
||||
GtkListStore * store = page->store;
|
||||
|
||||
for( i=0; i<trackerCount; ++i )
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append( store, &iter );
|
||||
gtk_list_store_set( store, &iter,
|
||||
TR_COL_TIER, trackers[i].tier + 1,
|
||||
TR_COL_ANNOUNCE, trackers[i].announce,
|
||||
-1 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ GtkWidget* tracker_list_new( TrTorrent * gtor );
|
|||
* to g_free() every announce in the array, then the array itself.
|
||||
*/
|
||||
tr_tracker_info* tracker_list_get_trackers( GtkWidget * list,
|
||||
int * trackerCount );
|
||||
int * trackerCount );
|
||||
|
||||
void tracker_list_add_trackers( GtkWidget * list,
|
||||
const tr_tracker_info * trackers,
|
||||
int trackerCount );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue