2008-06-01 05:36:23 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2007-2010 Mnemosyne LLC
|
2008-06-01 05:36:23 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2008-06-01 05:36:23 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2010-10-01 13:33:39 +00:00
|
|
|
* $Id$
|
2008-06-01 05:36:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
2010-02-20 15:57:34 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_urlIsValidTracker() */
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
#include "actions.h"
|
|
|
|
#include "details.h"
|
|
|
|
#include "file-list.h"
|
|
|
|
#include "tracker-list.h"
|
|
|
|
#include "hig.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2008-10-02 15:29:45 +00:00
|
|
|
#define PAGE_KEY "page"
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
struct tracker_page
|
|
|
|
{
|
2009-04-24 01:37:04 +00:00
|
|
|
gboolean isNew;
|
|
|
|
|
|
|
|
tr_session * session;
|
|
|
|
int torrentId;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeView * view;
|
|
|
|
GtkListStore * store;
|
|
|
|
GtkTreeSelection * sel;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * add_button;
|
|
|
|
GtkWidget * remove_button;
|
|
|
|
GtkWidget * save_button;
|
|
|
|
GtkWidget * revert_button;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * last_scrape_time_lb;
|
|
|
|
GtkWidget * last_scrape_response_lb;
|
|
|
|
GtkWidget * next_scrape_countdown_lb;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * last_announce_time_lb;
|
|
|
|
GtkWidget * last_announce_response_lb;
|
|
|
|
GtkWidget * next_announce_countdown_lb;
|
|
|
|
GtkWidget * manual_announce_countdown_lb;
|
2008-06-01 05:36:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TR_COL_TIER,
|
|
|
|
TR_COL_ANNOUNCE,
|
|
|
|
TR_N_COLS
|
|
|
|
};
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
static tr_torrent * getTorrent( struct tracker_page * page )
|
|
|
|
{
|
|
|
|
return tr_torrentFindFromId( page->session, page->torrentId );
|
|
|
|
}
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
setTrackerChangeState( struct tracker_page * page,
|
|
|
|
gboolean changed )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
if( page->save_button )
|
|
|
|
gtk_widget_set_sensitive( page->save_button, changed );
|
|
|
|
|
|
|
|
if( page->revert_button )
|
|
|
|
gtk_widget_set_sensitive( page->revert_button, changed );
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel*
|
|
|
|
tracker_model_new( tr_torrent * tor )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int i;
|
2008-06-01 05:36:23 +00:00
|
|
|
const tr_info * inf = tr_torrentInfo( tor );
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkListStore * store = gtk_list_store_new( TR_N_COLS, G_TYPE_INT,
|
|
|
|
G_TYPE_STRING );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; inf && i < inf->trackerCount; ++i )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter iter;
|
2008-06-01 05:36:23 +00:00
|
|
|
const tr_tracker_info * tinf = inf->trackers + i;
|
|
|
|
gtk_list_store_append( store, &iter );
|
2008-10-02 15:29:45 +00:00
|
|
|
gtk_list_store_set( store, &iter,
|
|
|
|
TR_COL_TIER, tinf->tier + 1,
|
2008-09-23 19:11:04 +00:00
|
|
|
TR_COL_ANNOUNCE, tinf->announce,
|
|
|
|
-1 );
|
2008-06-01 05:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( store ),
|
|
|
|
TR_COL_TIER,
|
|
|
|
GTK_SORT_ASCENDING );
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL( store );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onTrackerSelectionChanged( GtkTreeSelection * sel,
|
|
|
|
gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2008-10-07 15:17:52 +00:00
|
|
|
const gboolean has_selection =
|
|
|
|
gtk_tree_selection_count_selected_rows( sel ) > 0;
|
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
2009-04-24 01:37:04 +00:00
|
|
|
const int trackerCount = model ? gtk_tree_model_iter_n_children( model, NULL ) : 0;
|
|
|
|
const gboolean ok_to_remove = page->isNew || ( trackerCount > 1 );
|
2008-10-02 19:51:16 +00:00
|
|
|
gtk_widget_set_sensitive( page->remove_button, has_selection && ok_to_remove );
|
2008-06-01 05:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-24 01:37:04 +00:00
|
|
|
onTrackerRemoveClicked( GtkButton * w UNUSED, gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2008-10-02 19:51:16 +00:00
|
|
|
GtkTreeModel * model;
|
|
|
|
GList * l;
|
|
|
|
GList * list = gtk_tree_selection_get_selected_rows( page->sel, &model );
|
|
|
|
|
|
|
|
/* convert the list to references */
|
|
|
|
for( l=list; l; l=l->next ) {
|
|
|
|
GtkTreePath * path = l->data;
|
|
|
|
l->data = gtk_tree_row_reference_new( model, path );
|
|
|
|
gtk_tree_path_free( path );
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-02 19:51:16 +00:00
|
|
|
/* remove the selected rows */
|
|
|
|
for( l=list; l; l=l->next ) {
|
|
|
|
GtkTreePath * path = gtk_tree_row_reference_get_path( l->data );
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gtk_tree_model_get_iter( model, &iter, path );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_list_store_remove( page->store, &iter );
|
2008-10-02 19:51:16 +00:00
|
|
|
gtk_tree_path_free( path );
|
|
|
|
gtk_tree_row_reference_free( l->data );
|
2008-06-01 05:36:23 +00:00
|
|
|
}
|
2008-10-02 19:51:16 +00:00
|
|
|
|
|
|
|
setTrackerChangeState( page, TRUE );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_list_free( list );
|
2008-06-01 05:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-24 01:37:04 +00:00
|
|
|
onTrackerAddClicked( GtkButton * w UNUSED, gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeIter iter;
|
2008-06-01 05:36:23 +00:00
|
|
|
struct tracker_page * page = gpage;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreePath * path;
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_list_store_append( page->store, &iter );
|
|
|
|
setTrackerChangeState( page, TRUE );
|
2008-10-02 15:29:45 +00:00
|
|
|
gtk_list_store_set( page->store, &iter,
|
|
|
|
TR_COL_TIER, 1,
|
2008-12-03 19:54:14 +00:00
|
|
|
TR_COL_ANNOUNCE, "",
|
2008-09-23 19:11:04 +00:00
|
|
|
-1 );
|
2008-06-01 05:36:23 +00:00
|
|
|
path = gtk_tree_model_get_path( GTK_TREE_MODEL( page->store ), &iter );
|
2008-12-03 19:54:14 +00:00
|
|
|
gtk_tree_view_set_cursor( page->view, path,
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_tree_view_get_column( page->view,
|
|
|
|
TR_COL_ANNOUNCE ),
|
2008-06-01 05:36:23 +00:00
|
|
|
TRUE );
|
|
|
|
gtk_tree_path_free( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onTrackerSaveClicked( GtkButton * w UNUSED,
|
|
|
|
gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
|
|
|
const int n = gtk_tree_model_iter_n_children( model, NULL );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
if( n > 0 ) /* must have at least one tracker */
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int i = 0;
|
|
|
|
GtkTreeIter iter;
|
2008-06-01 05:36:23 +00:00
|
|
|
tr_tracker_info * trackers;
|
|
|
|
|
|
|
|
/* build the tracker list */
|
|
|
|
trackers = g_new0( tr_tracker_info, n );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
|
|
|
{
|
|
|
|
gtk_tree_model_get( model, &iter, TR_COL_TIER,
|
|
|
|
&trackers[i].tier,
|
|
|
|
TR_COL_ANNOUNCE, &trackers[i].announce,
|
|
|
|
-1 );
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
g_assert( i == n );
|
|
|
|
|
|
|
|
/* set the tracker list */
|
2009-04-24 01:37:04 +00:00
|
|
|
tr_torrentSetAnnounceList( getTorrent( page ), trackers, n );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
setTrackerChangeState( page, FALSE );
|
|
|
|
|
|
|
|
/* cleanup */
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < n; ++i )
|
2008-06-01 05:36:23 +00:00
|
|
|
g_free( trackers[i].announce );
|
|
|
|
g_free( trackers );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onTrackerRevertClicked( GtkButton * w UNUSED,
|
|
|
|
gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2009-04-24 01:37:04 +00:00
|
|
|
GtkTreeModel * model;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
model = tracker_model_new( getTorrent( page ) );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_tree_view_set_model( page->view, model );
|
|
|
|
page->store = GTK_LIST_STORE( model );
|
|
|
|
g_object_unref( G_OBJECT( model ) );
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
setTrackerChangeState( page, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
onAnnounceEdited( GtkCellRendererText * renderer UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
gchar * path_string,
|
|
|
|
gchar * new_text,
|
|
|
|
gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath * path = gtk_tree_path_new_from_string( path_string );
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
if( gtk_tree_model_get_iter( model, &iter, path ) )
|
|
|
|
{
|
|
|
|
char * old_text;
|
|
|
|
gtk_tree_model_get( model, &iter, TR_COL_ANNOUNCE, &old_text, -1 );
|
2010-02-20 15:57:34 +00:00
|
|
|
if( tr_urlIsValidTracker( new_text ) )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
if( strcmp( old_text, new_text ) )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_list_store_set( page->store, &iter, TR_COL_ANNOUNCE,
|
|
|
|
new_text,
|
|
|
|
-1 );
|
2008-06-01 05:36:23 +00:00
|
|
|
setTrackerChangeState( page, TRUE );
|
|
|
|
}
|
|
|
|
}
|
2010-02-20 15:57:34 +00:00
|
|
|
else if( !tr_urlIsValidTracker( old_text ) )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
/* both old and new are invalid...
|
|
|
|
they must've typed in an invalid URL
|
|
|
|
after hitting the "Add" button */
|
|
|
|
onTrackerRemoveClicked( NULL, page );
|
|
|
|
setTrackerChangeState( page, TRUE );
|
|
|
|
}
|
|
|
|
g_free( old_text );
|
|
|
|
}
|
|
|
|
gtk_tree_path_free( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
onTierEdited( GtkCellRendererText * renderer UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
gchar * path_string,
|
|
|
|
gchar * new_text,
|
|
|
|
gpointer gpage )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
struct tracker_page * page = gpage;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath * path;
|
|
|
|
char * end;
|
|
|
|
int new_tier;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
new_tier = strtol( new_text, &end, 10 );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( new_tier < 1 || *end || errno )
|
2008-06-01 05:36:23 +00:00
|
|
|
return;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_string( path_string );
|
2008-06-01 05:36:23 +00:00
|
|
|
if( gtk_tree_model_get_iter( model, &iter, path ) )
|
|
|
|
{
|
|
|
|
int old_tier;
|
|
|
|
gtk_tree_model_get( model, &iter, TR_COL_TIER, &old_tier, -1 );
|
|
|
|
if( old_tier != new_tier )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_list_store_set( page->store, &iter, TR_COL_TIER, new_tier,
|
|
|
|
-1 );
|
2008-06-01 05:36:23 +00:00
|
|
|
setTrackerChangeState( page, TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_tree_path_free( path );
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
void
|
|
|
|
tracker_list_set_torrent( GtkWidget * w, int torrentId )
|
|
|
|
{
|
|
|
|
struct tracker_page * page = g_object_get_data( G_OBJECT( w ), PAGE_KEY );
|
|
|
|
GtkTreeModel * m;
|
|
|
|
|
|
|
|
m = tracker_model_new( tr_torrentFindFromId( page->session, torrentId ) );
|
|
|
|
page->torrentId = torrentId;
|
|
|
|
page->store = GTK_LIST_STORE( m );
|
|
|
|
gtk_tree_view_set_model( GTK_TREE_VIEW( page->view ), m );
|
|
|
|
g_object_unref( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tracker_list_clear( GtkWidget * w )
|
|
|
|
{
|
|
|
|
tracker_list_set_torrent( w, -1 );
|
|
|
|
}
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
GtkWidget*
|
2009-04-24 01:37:04 +00:00
|
|
|
tracker_list_new( tr_session * session, int torrentId, gboolean isNew )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * buttons;
|
|
|
|
GtkWidget * box;
|
|
|
|
GtkWidget * top;
|
|
|
|
GtkWidget * fr;
|
|
|
|
GtkCellRenderer * r;
|
|
|
|
GtkTreeViewColumn * c;
|
|
|
|
GtkTreeSelection * sel;
|
2008-06-01 05:36:23 +00:00
|
|
|
struct tracker_page * page = g_new0( struct tracker_page, 1 );
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
page->session = session;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2008-06-02 15:07:26 +00:00
|
|
|
top = gtk_hbox_new( FALSE, GUI_PAD );
|
|
|
|
box = gtk_vbox_new( FALSE, GUI_PAD );
|
|
|
|
buttons = gtk_vbox_new( TRUE, GUI_PAD );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
w = gtk_tree_view_new( );
|
2008-09-27 18:01:31 +00:00
|
|
|
g_signal_connect( w, "button-release-event",
|
|
|
|
G_CALLBACK( on_tree_view_button_released ), NULL );
|
2008-06-01 05:36:23 +00:00
|
|
|
page->view = GTK_TREE_VIEW( w );
|
|
|
|
gtk_tree_view_set_enable_search( page->view, FALSE );
|
|
|
|
r = gtk_cell_renderer_text_new( );
|
2009-04-24 01:37:04 +00:00
|
|
|
g_object_set( G_OBJECT( r ), "editable", TRUE, NULL );
|
|
|
|
g_signal_connect( r, "edited", G_CALLBACK( onTierEdited ), page );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes( _( "Tier" ), r, "text", TR_COL_TIER, NULL );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( c, TR_COL_TIER );
|
|
|
|
gtk_tree_view_append_column( page->view, c );
|
|
|
|
r = gtk_cell_renderer_text_new( );
|
2009-04-24 01:37:04 +00:00
|
|
|
g_object_set( G_OBJECT( r ), "editable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
|
|
|
|
g_signal_connect( r, "edited", G_CALLBACK( onAnnounceEdited ), page );
|
|
|
|
c = gtk_tree_view_column_new_with_attributes( _( "Announce URL" ), r, "text", TR_COL_ANNOUNCE, NULL );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id( c, TR_COL_ANNOUNCE );
|
|
|
|
gtk_tree_view_append_column( page->view, c );
|
|
|
|
w = gtk_scrolled_window_new( NULL, NULL );
|
2009-04-24 01:37:04 +00:00
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
|
2008-06-01 05:36:23 +00:00
|
|
|
sel = gtk_tree_view_get_selection( page->view );
|
|
|
|
page->sel = sel;
|
2009-04-24 01:37:04 +00:00
|
|
|
g_signal_connect( sel, "changed", G_CALLBACK( onTrackerSelectionChanged ), page );
|
2008-10-02 19:51:16 +00:00
|
|
|
gtk_tree_selection_set_mode( sel, GTK_SELECTION_MULTIPLE );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), GTK_WIDGET( page->view ) );
|
|
|
|
gtk_widget_set_size_request( w, -1, 133 );
|
|
|
|
fr = gtk_frame_new( NULL );
|
|
|
|
gtk_frame_set_shadow_type( GTK_FRAME( fr ), GTK_SHADOW_IN );
|
|
|
|
gtk_container_add( GTK_CONTAINER( fr ), w );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
w = gtk_button_new_from_stock( GTK_STOCK_ADD );
|
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK( onTrackerAddClicked ), page );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( buttons ), w, TRUE, TRUE, 0 );
|
2008-06-01 05:36:23 +00:00
|
|
|
page->add_button = w;
|
2009-06-09 04:57:10 +00:00
|
|
|
w = gtk_button_new_from_stock( GTK_STOCK_DELETE );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK(
|
|
|
|
onTrackerRemoveClicked ), page );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( buttons ), w, TRUE, TRUE, 0 );
|
2008-06-01 05:36:23 +00:00
|
|
|
page->remove_button = w;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
|
|
|
if( !isNew )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
|
|
|
w = gtk_button_new_from_stock( GTK_STOCK_SAVE );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK(
|
|
|
|
onTrackerSaveClicked ), page );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_widget_set_sensitive( w, FALSE );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( buttons ), w, TRUE, TRUE, 0 );
|
2008-06-01 05:36:23 +00:00
|
|
|
page->save_button = w;
|
|
|
|
|
|
|
|
w = gtk_button_new_from_stock( GTK_STOCK_REVERT_TO_SAVED );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK(
|
|
|
|
onTrackerRevertClicked ), page );
|
2008-06-01 05:36:23 +00:00
|
|
|
gtk_widget_set_sensitive( w, FALSE );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( buttons ), w, TRUE, TRUE, 0 );
|
2008-06-01 05:36:23 +00:00
|
|
|
page->revert_button = w;
|
|
|
|
}
|
|
|
|
|
2008-06-02 15:07:26 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( box ), buttons, FALSE, FALSE, 0 );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( top ), fr, TRUE, TRUE, 0 );
|
2008-06-02 15:07:26 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( top ), box, FALSE, FALSE, 0 );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
onTrackerSelectionChanged( sel, page );
|
|
|
|
|
2008-10-02 15:29:45 +00:00
|
|
|
g_object_set_data_full( G_OBJECT( top ), PAGE_KEY, page, g_free );
|
2009-04-24 01:37:04 +00:00
|
|
|
tracker_list_set_torrent( top, torrentId );
|
2008-06-01 05:36:23 +00:00
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_tracker_info*
|
|
|
|
tracker_list_get_trackers( GtkWidget * list,
|
2008-09-23 19:11:04 +00:00
|
|
|
int * trackerCount )
|
2008-06-01 05:36:23 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
struct tracker_page * page = g_object_get_data( G_OBJECT(
|
2008-10-02 15:29:45 +00:00
|
|
|
list ), PAGE_KEY );
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
|
|
|
|
const int n = gtk_tree_model_iter_n_children( model, NULL );
|
|
|
|
tr_tracker_info * trackers;
|
|
|
|
int i = 0;
|
|
|
|
GtkTreeIter iter;
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
/* build the tracker list */
|
|
|
|
trackers = g_new0( tr_tracker_info, n );
|
2008-09-23 19:11:04 +00:00
|
|
|
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
|
|
|
{
|
2008-10-02 15:29:45 +00:00
|
|
|
int tier;
|
|
|
|
gtk_tree_model_get( model, &iter,
|
|
|
|
TR_COL_TIER, &tier,
|
2008-09-23 19:11:04 +00:00
|
|
|
TR_COL_ANNOUNCE, &trackers[i].announce,
|
|
|
|
-1 );
|
2008-10-02 15:29:45 +00:00
|
|
|
/* tracker_info.tier is zero-based, but the display is 1-based */
|
|
|
|
trackers[i].tier = tier - 1;
|
2008-09-23 19:11:04 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
while( gtk_tree_model_iter_next( model, &iter ) );
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
g_assert( i == n );
|
|
|
|
|
|
|
|
*trackerCount = n;
|
|
|
|
|
|
|
|
return trackers;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-02 15:29:45 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|