(gtk) #662: It is possible to have several information windows for the same torrent
This commit is contained in:
parent
f72ba4b8d8
commit
00a9df7291
46
gtk/main.c
46
gtk/main.c
|
@ -96,7 +96,8 @@ static const char * LICENSE =
|
||||||
"SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
|
"SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct cbdata {
|
struct cbdata
|
||||||
|
{
|
||||||
GtkWindow * wind;
|
GtkWindow * wind;
|
||||||
TrCore * core;
|
TrCore * core;
|
||||||
GtkWidget * icon;
|
GtkWidget * icon;
|
||||||
|
@ -105,6 +106,8 @@ struct cbdata {
|
||||||
guint timer;
|
guint timer;
|
||||||
gboolean closing;
|
gboolean closing;
|
||||||
GList * errqueue;
|
GList * errqueue;
|
||||||
|
GHashTable * tor2details;
|
||||||
|
GHashTable * details2tor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CBDATA_PTR "callback-data-pointer"
|
#define CBDATA_PTR "callback-data-pointer"
|
||||||
|
@ -220,7 +223,7 @@ int
|
||||||
main( int argc, char ** argv )
|
main( int argc, char ** argv )
|
||||||
{
|
{
|
||||||
char * err;
|
char * err;
|
||||||
struct cbdata * cbdata = g_new (struct cbdata, 1);
|
struct cbdata * cbdata;
|
||||||
GList * argfiles;
|
GList * argfiles;
|
||||||
GError * gerr;
|
GError * gerr;
|
||||||
gboolean didinit = FALSE;
|
gboolean didinit = FALSE;
|
||||||
|
@ -241,6 +244,10 @@ main( int argc, char ** argv )
|
||||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cbdata = g_new0( struct cbdata, 1 );
|
||||||
|
cbdata->tor2details = g_hash_table_new( g_str_hash, g_str_equal );
|
||||||
|
cbdata->details2tor = g_hash_table_new( g_direct_hash, g_direct_equal );
|
||||||
|
|
||||||
/* bind the gettext domain */
|
/* bind the gettext domain */
|
||||||
bindtextdomain( domain, TRANSMISSIONLOCALEDIR );
|
bindtextdomain( domain, TRANSMISSIONLOCALEDIR );
|
||||||
bind_textdomain_codeset( domain, "UTF-8" );
|
bind_textdomain_codeset( domain, "UTF-8" );
|
||||||
|
@ -440,6 +447,9 @@ quitThreadFunc( gpointer gdata )
|
||||||
g_list_foreach( cbdata->errqueue, (GFunc)g_free, NULL );
|
g_list_foreach( cbdata->errqueue, (GFunc)g_free, NULL );
|
||||||
g_list_free( cbdata->errqueue );
|
g_list_free( cbdata->errqueue );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_hash_table_destroy( cbdata->details2tor );
|
||||||
|
g_hash_table_destroy( cbdata->tor2details );
|
||||||
g_free( cbdata );
|
g_free( cbdata );
|
||||||
|
|
||||||
/* exit the gtk main loop */
|
/* exit the gtk main loop */
|
||||||
|
@ -849,17 +859,39 @@ updateTrackerForeach (GtkTreeModel * model,
|
||||||
g_object_unref( G_OBJECT( tor ) );
|
g_object_unref( G_OBJECT( tor ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
detailsClosed( gpointer user_data, GObject * details )
|
||||||
|
{
|
||||||
|
struct cbdata * data = user_data;
|
||||||
|
gpointer hashString = g_hash_table_lookup( data->details2tor, details );
|
||||||
|
g_hash_table_remove( data->details2tor, details );
|
||||||
|
g_hash_table_remove( data->tor2details, hashString );
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
showInfoForeach (GtkTreeModel * model,
|
showInfoForeach (GtkTreeModel * model,
|
||||||
GtkTreePath * path UNUSED,
|
GtkTreePath * path UNUSED,
|
||||||
GtkTreeIter * iter,
|
GtkTreeIter * iter,
|
||||||
gpointer data UNUSED)
|
gpointer user_data )
|
||||||
{
|
{
|
||||||
|
const char * hashString;
|
||||||
|
struct cbdata * data = user_data;
|
||||||
TrTorrent * tor = NULL;
|
TrTorrent * tor = NULL;
|
||||||
GtkWidget * w;
|
GtkWidget * w;
|
||||||
|
|
||||||
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
||||||
w = torrent_inspector_new( GTK_WINDOW(data), tor );
|
hashString = tr_torrent_info(tor)->hashString;
|
||||||
gtk_widget_show( w );
|
w = g_hash_table_lookup( data->tor2details, hashString );
|
||||||
|
if( w != NULL )
|
||||||
|
gtk_window_present( GTK_WINDOW( w ) );
|
||||||
|
else {
|
||||||
|
w = torrent_inspector_new( GTK_WINDOW( data->wind ), tor );
|
||||||
|
gtk_widget_show( w );
|
||||||
|
g_hash_table_insert( data->tor2details, (gpointer)hashString, w );
|
||||||
|
g_hash_table_insert( data->details2tor, w, (gpointer)hashString );
|
||||||
|
g_object_weak_ref( G_OBJECT( w ), detailsClosed, data );
|
||||||
|
}
|
||||||
|
|
||||||
g_object_unref( G_OBJECT( tor ) );
|
g_object_unref( G_OBJECT( tor ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +917,7 @@ msgwinclosed()
|
||||||
void
|
void
|
||||||
doAction ( const char * action_name, gpointer user_data )
|
doAction ( const char * action_name, gpointer user_data )
|
||||||
{
|
{
|
||||||
struct cbdata * data = (struct cbdata *) user_data;
|
struct cbdata * data = user_data;
|
||||||
gboolean changed = FALSE;
|
gboolean changed = FALSE;
|
||||||
|
|
||||||
if (!strcmp (action_name, "add-torrent"))
|
if (!strcmp (action_name, "add-torrent"))
|
||||||
|
@ -919,7 +951,7 @@ doAction ( const char * action_name, gpointer user_data )
|
||||||
else if (!strcmp (action_name, "show-torrent-details"))
|
else if (!strcmp (action_name, "show-torrent-details"))
|
||||||
{
|
{
|
||||||
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
||||||
gtk_tree_selection_selected_foreach( s, showInfoForeach, data->wind );
|
gtk_tree_selection_selected_foreach( s, showInfoForeach, data );
|
||||||
}
|
}
|
||||||
else if (!strcmp( action_name, "update-tracker"))
|
else if (!strcmp( action_name, "update-tracker"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue