(trunk gtk) #2625: "ability to create a manget link" -- remove the magnet link from the properties dialog; add a "Copy _Magnet Link to Clipboard" menu & context menu item instead

This commit is contained in:
Charles Kerr
2009-11-29 18:23:06 +00:00
parent 5c3fd1b5cc
commit a87c15b389
4 changed files with 34 additions and 32 deletions

View File

@@ -108,13 +108,14 @@ static GtkActionEntry entries[] =
{ "sort-menu", NULL, N_( "_Sort Torrents By" ), NULL, NULL, NULL },
{ "edit-menu", NULL, N_( "_Edit" ), NULL, NULL, NULL },
{ "help-menu", NULL, N_( "_Help" ), NULL, NULL, NULL },
{ "copy-magnet-link-to-clipboard", GTK_STOCK_COPY, N_("Copy _Magnet Link to Clipboard" ), "<control>M", NULL, G_CALLBACK( action_cb ) },
{ "add-torrent-from-url", GTK_STOCK_ADD, N_("Add _URL..." ), NULL, N_( "Add URL..." ), G_CALLBACK( action_cb ) },
{ "add-torrent-toolbar", GTK_STOCK_ADD, NULL, NULL, N_( "Add a torrent" ), G_CALLBACK( action_cb ) },
{ "add-torrent-menu", GTK_STOCK_ADD, N_( "_Add File..." ), "<control>D", N_( "Add a torrent" ), G_CALLBACK( action_cb ) },
{ "start-torrent", GTK_STOCK_MEDIA_PLAY, N_( "_Start" ), "<control>S", N_( "Start torrent" ), G_CALLBACK( action_cb ) },
{ "show-stats", NULL, N_( "_Statistics" ), NULL, NULL, G_CALLBACK( action_cb ) },
{ "donate", NULL, N_( "_Donate" ), NULL, NULL, G_CALLBACK( action_cb ) },
{ "verify-torrent", NULL, N_( "_Verify Local Data" ), NULL, NULL, G_CALLBACK( action_cb ) },
{ "verify-torrent", NULL, N_( "_Verify Local Data" ), "<control>V", NULL, G_CALLBACK( action_cb ) },
{ "pause-torrent", GTK_STOCK_MEDIA_PAUSE, N_( "_Pause" ), "<control>P", N_( "Pause torrent" ), G_CALLBACK( action_cb ) },
{ "pause-all-torrents", GTK_STOCK_MEDIA_PAUSE, N_( "_Pause All" ), NULL, N_( "Pause all torrents" ), G_CALLBACK( action_cb ) },
{ "start-all-torrents", GTK_STOCK_MEDIA_PLAY, N_( "_Start All" ), NULL, N_( "Start all torrents" ), G_CALLBACK( action_cb ) },

View File

@@ -76,7 +76,6 @@ struct DetailsImpl
GtkWidget * last_activity_lb;
GtkWidget * hash_lb;
GtkWidget * magnet_lb;
GtkWidget * privacy_lb;
GtkWidget * origin_lb;
GtkWidget * destination_lb;
@@ -620,7 +619,6 @@ static void
refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
{
int i;
char * freeme;
const char * str;
const char * none = _( "None" );
const char * mixed = _( "Mixed" );
@@ -887,19 +885,6 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
str = mixed;
gtr_label_set_text( GTK_LABEL( di->hash_lb ), str );
/* magnet lb */
freeme = NULL;
if( n<=0 )
str = none;
else if ( n>1 )
str = mixed;
else if( infos[0]->isPrivate )
str = _( "Private Torrent" );
else
str = freeme = tr_torrentGetMagnetLink( torrents[0] );
gtr_label_set_text( GTK_LABEL( di->magnet_lb ), str );
tr_free( freeme );
/* error */
if( n <= 0 )
str = none;
@@ -1014,13 +999,6 @@ info_page_new( struct DetailsImpl * di )
hig_workarea_add_row( t, &row, _( "Hash:" ), l, NULL );
di->hash_lb = l;
/* magnet url */
l = g_object_new( GTK_TYPE_LABEL, "selectable", TRUE,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL );
hig_workarea_add_row( t, &row, _( "Magnet link:" ), l, NULL );
di->magnet_lb = l;
/* privacy */
l = gtk_label_new( NULL );
hig_workarea_add_row( t, &row, _( "Privacy:" ), l, NULL );

View File

@@ -179,6 +179,7 @@ refreshActions( struct cbdata * data )
action_sensitize( "show-torrent-properties", counts.totalCount != 0 );
action_sensitize( "open-torrent-folder", counts.totalCount == 1 );
action_sensitize( "relocate-torrent", counts.totalCount == 1 );
action_sensitize( "copy-magnet-link-to-clipboard", counts.totalCount == 1 );
canUpdate = 0;
gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );
@@ -1343,6 +1344,17 @@ detailsClosed( gpointer gdata, GObject * dead )
data->details = g_slist_remove( data->details, dead );
}
static void
copyMagnetLinkToClipboard( GtkWidget * w, tr_torrent * tor )
{
char * magnet = tr_torrentGetMagnetLink( tor );
GdkDisplay * display = gtk_widget_get_display( w );
GdkAtom selection = GDK_SELECTION_CLIPBOARD;
GtkClipboard * clipboard = gtk_clipboard_get_for_display( display, selection );
gtk_clipboard_set_text( clipboard, magnet, -1 );
tr_free( magnet );
}
void
doAction( const char * action_name, gpointer user_data )
{
@@ -1381,10 +1393,18 @@ doAction( const char * action_name, gpointer user_data )
{
startAllTorrents( data );
}
else if( !strcmp( action_name, "copy-magnet-link-to-clipboard" ) )
{
tr_torrent * tor = getFirstSelectedTorrent( data );
if( tor != NULL )
{
copyMagnetLinkToClipboard( GTK_WIDGET( data->wind ), tor );
}
}
else if( !strcmp( action_name, "relocate-torrent" ) )
{
tr_torrent * tor = getFirstSelectedTorrent( data );
if( tor )
if( tor != NULL )
{
GtkWindow * parent = GTK_WINDOW( data->wind );
GtkWidget * w = gtr_relocate_dialog_new( parent, tor );

View File

@@ -19,12 +19,14 @@ static const char * fallback_ui_file =
" </menu>\n"
" <menu action='torrent-menu'>\n"
" <menuitem action='show-torrent-properties'/>\n"
" <menuitem action='open-torrent-folder'/>\n"
" <menuitem action='relocate-torrent'/>\n"
" <separator/>\n"
" <menuitem action='start-torrent'/>\n"
" <menuitem action='update-tracker'/>\n"
" <menuitem action='pause-torrent'/>\n"
" <menuitem action='copy-magnet-link-to-clipboard'/>\n"
" <separator/>\n"
" <menuitem action='open-torrent-folder'/>\n"
" <menuitem action='relocate-torrent'/>\n"
" <menuitem action='verify-torrent'/>\n"
" <separator/>\n"
" <menuitem action='remove-torrent'/>\n"
@@ -71,12 +73,6 @@ static const char * fallback_ui_file =
"\n"
" <popup name='main-window-popup'>\n"
" <menuitem action='show-torrent-properties'/>\n"
" <menuitem action='open-torrent-folder'/>\n"
" <separator/>\n"
" <menuitem action='start-torrent'/>\n"
" <menuitem action='update-tracker'/>\n"
" <menuitem action='pause-torrent'/>\n"
" <menuitem action='verify-torrent'/>\n"
" <separator/>\n"
" <menu action='sort-menu'>\n"
" <menuitem action='sort-by-activity'/>\n"
@@ -92,6 +88,13 @@ static const char * fallback_ui_file =
" <menuitem action='sort-reversed'/>\n"
" </menu>\n"
" <separator/>\n"
" <menuitem action='start-torrent'/>\n"
" <menuitem action='update-tracker'/>\n"
" <menuitem action='pause-torrent'/>\n"
" <menuitem action='copy-magnet-link-to-clipboard'/>\n"
" <separator/>\n"
" <menuitem action='open-torrent-folder'/>\n"
" <menuitem action='verify-torrent'/>\n"
" <menuitem action='relocate-torrent'/>\n"
" <separator/>\n"
" <menuitem action='remove-torrent'/>\n"