1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-10 14:13:23 +00:00

(trunk gtk) #1963: Use tooltip to notify user of added torrent

This commit is contained in:
Charles Kerr 2009-06-11 16:17:48 +00:00
parent c2dd366154
commit ebfd93fe7b
7 changed files with 54 additions and 31 deletions

View file

@ -123,7 +123,7 @@ addResponseCB( GtkDialog * dialog,
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) ) if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) )
tr_torrentStart( tr_torrent_handle( data->gtor ) ); tr_torrentStart( tr_torrent_handle( data->gtor ) );
tr_core_add_torrent( data->core, data->gtor ); tr_core_add_torrent( data->core, data->gtor, FALSE );
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->trash_check ) ) ) if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->trash_check ) ) )
@ -426,7 +426,7 @@ onAddDialogResponse( GtkDialog * dialog,
: PREF_FLAG_FALSE; : PREF_FLAG_FALSE;
GSList * l = gtk_file_chooser_get_filenames( chooser ); GSList * l = gtk_file_chooser_get_filenames( chooser );
tr_core_add_list( core, l, start, prompt ); tr_core_add_list( core, l, start, prompt, FALSE );
} }
gtk_widget_destroy( GTK_WIDGET( dialog ) ); gtk_widget_destroy( GTK_WIDGET( dialog ) );

View file

@ -300,8 +300,7 @@ onRPCChanged( tr_session * session UNUSED,
switch( type ) switch( type )
{ {
case TR_RPC_TORRENT_ADDED: case TR_RPC_TORRENT_ADDED:
tr_core_add_torrent( cbdata->core, tr_core_add_torrent( cbdata->core, tr_torrent_new_preexisting( tor ), TRUE );
tr_torrent_new_preexisting( tor ) );
break; break;
case TR_RPC_TORRENT_STARTED: case TR_RPC_TORRENT_STARTED:
@ -517,7 +516,7 @@ appsetup( TrWindow * wind,
/* add torrents from command-line and saved state */ /* add torrents from command-line and saved state */
tr_core_load( cbdata->core, forcepause ); tr_core_load( cbdata->core, forcepause );
tr_core_add_list( cbdata->core, torrentFiles, start, prompt ); tr_core_add_list( cbdata->core, torrentFiles, start, prompt, TRUE );
torrentFiles = NULL; torrentFiles = NULL;
tr_core_torrents_added( cbdata->core ); tr_core_torrents_added( cbdata->core );
@ -793,7 +792,7 @@ gotdrag( GtkWidget * widget UNUSED,
if( paths ) if( paths )
{ {
paths = g_slist_reverse( paths ); paths = g_slist_reverse( paths );
tr_core_add_list_defaults( data->core, paths ); tr_core_add_list_defaults( data->core, paths, TRUE );
tr_core_torrents_added( data->core ); tr_core_torrents_added( data->core );
} }

View file

@ -22,10 +22,9 @@
#ifndef HAVE_LIBNOTIFY #ifndef HAVE_LIBNOTIFY
void void tr_notify_init( void ) { }
tr_notify_init( void ) { } void tr_notify_send( TrTorrent * tor UNUSED ) { }
void void tr_notify_added( const char * name UNUSED ) { }
tr_notify_send( TrTorrent * tor UNUSED ) { }
#else #else
#include <libnotify/notify.h> #include <libnotify/notify.h>
@ -113,4 +112,16 @@ tr_notify_send( TrTorrent *tor )
} }
} }
void
tr_notify_added( const char * name )
{
if( pref_flag_get( PREF_KEY_SHOW_DESKTOP_NOTIFICATION ) )
{
NotifyNotification * n = notify_notification_new(
_( "Torrent Added" ), name, "transmission", NULL );
notify_notification_set_timeout( n, NOTIFY_EXPIRES_DEFAULT );
notify_notification_show( n, NULL );
}
}
#endif #endif

View file

@ -19,4 +19,6 @@ void tr_notify_init( void );
void tr_notify_send( TrTorrent * tor ); void tr_notify_send( TrTorrent * tor );
void tr_notify_added( const char * name );
#endif #endif

View file

@ -40,6 +40,7 @@
#include <libtransmission/utils.h> /* tr_free */ #include <libtransmission/utils.h> /* tr_free */
#include "conf.h" #include "conf.h"
#include "notify.h"
#include "tr-core.h" #include "tr-core.h"
#ifdef HAVE_DBUS_GLIB #ifdef HAVE_DBUS_GLIB
#include "tr-core-dbus.h" #include "tr-core-dbus.h"
@ -469,7 +470,7 @@ watchFolderIdle( gpointer gcore )
TrCore * core = TR_CORE( gcore ); TrCore * core = TR_CORE( gcore );
core->priv->adding_from_watch_dir = TRUE; core->priv->adding_from_watch_dir = TRUE;
tr_core_add_list_defaults( core, core->priv->monitor_files ); tr_core_add_list_defaults( core, core->priv->monitor_files, TRUE );
core->priv->adding_from_watch_dir = FALSE; core->priv->adding_from_watch_dir = FALSE;
/* cleanup */ /* cleanup */
@ -784,8 +785,9 @@ doCollate( const char * in )
} }
void void
tr_core_add_torrent( TrCore * self, tr_core_add_torrent( TrCore * self,
TrTorrent * gtor ) TrTorrent * gtor,
gboolean doNotify )
{ {
const tr_info * inf = tr_torrent_info( gtor ); const tr_info * inf = tr_torrent_info( gtor );
const tr_stat * torStat = tr_torrent_stat( gtor ); const tr_stat * torStat = tr_torrent_stat( gtor );
@ -802,6 +804,9 @@ tr_core_add_torrent( TrCore * self,
MC_ACTIVITY, torStat->activity, MC_ACTIVITY, torStat->activity,
-1 ); -1 );
if( doNotify )
tr_notify_added( inf->name );
/* cleanup */ /* cleanup */
g_object_unref( G_OBJECT( gtor ) ); g_object_unref( G_OBJECT( gtor ) );
g_free( collated ); g_free( collated );
@ -824,7 +829,7 @@ tr_core_load( TrCore * self,
torrents = tr_sessionLoadTorrents ( tr_core_session( self ), ctor, &count ); torrents = tr_sessionLoadTorrents ( tr_core_session( self ), ctor, &count );
for( i = 0; i < count; ++i ) for( i = 0; i < count; ++i )
tr_core_add_torrent( self, tr_torrent_new_preexisting( torrents[i] ) ); tr_core_add_torrent( self, tr_torrent_new_preexisting( torrents[i] ), FALSE );
tr_free( torrents ); tr_free( torrents );
tr_ctorFree( ctor ); tr_ctorFree( ctor );
@ -853,7 +858,7 @@ tr_core_errsig( TrCore * core,
} }
static int static int
add_ctor( TrCore * core, tr_ctor * ctor, gboolean doPrompt ) add_ctor( TrCore * core, tr_ctor * ctor, gboolean doPrompt, gboolean doNotify )
{ {
tr_info inf; tr_info inf;
int err = tr_torrentParse( ctor, &inf ); int err = tr_torrentParse( ctor, &inf );
@ -879,9 +884,8 @@ add_ctor( TrCore * core, tr_ctor * ctor, gboolean doPrompt )
else { else {
tr_session * session = tr_core_session( core ); tr_session * session = tr_core_session( core );
TrTorrent * gtor = tr_torrent_new_ctor( session, ctor, &err ); TrTorrent * gtor = tr_torrent_new_ctor( session, ctor, &err );
g_message( "creating a gtorrent" );
if( !err ) if( !err )
tr_core_add_torrent( core, gtor ); tr_core_add_torrent( core, gtor, doNotify );
} }
tr_metainfoFree( &inf ); tr_metainfoFree( &inf );
break; break;
@ -918,7 +922,7 @@ tr_core_add_metainfo( TrCore * core,
err = tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length ); err = tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
if( !err ) if( !err )
err = add_ctor( core, ctor, do_prompt ); err = add_ctor( core, ctor, do_prompt, TRUE );
tr_free( file_contents ); tr_free( file_contents );
tr_core_torrents_added( core ); tr_core_torrents_added( core );
@ -932,7 +936,8 @@ static void
add_filename( TrCore * core, add_filename( TrCore * core,
const char * filename, const char * filename,
gboolean doStart, gboolean doStart,
gboolean doPrompt ) gboolean doPrompt,
gboolean doNotify )
{ {
tr_session * session = tr_core_session( core ); tr_session * session = tr_core_session( core );
if( filename && session ) if( filename && session )
@ -943,7 +948,7 @@ add_filename( TrCore * core,
tr_ctorSetPaused( ctor, TR_FORCE, !doStart ); tr_ctorSetPaused( ctor, TR_FORCE, !doStart );
tr_ctorSetMetainfoFromFile( ctor, filename ); tr_ctorSetMetainfoFromFile( ctor, filename );
err = add_ctor( core, ctor, doPrompt ); err = add_ctor( core, ctor, doPrompt, doNotify );
if( err == TR_EINVALID ) if( err == TR_EINVALID )
tr_core_errsig( core, TR_EINVALID, filename ); tr_core_errsig( core, TR_EINVALID, filename );
} }
@ -960,17 +965,18 @@ tr_core_present_window( TrCore * core UNUSED,
} }
void void
tr_core_add_list( TrCore * core, tr_core_add_list( TrCore * core,
GSList * torrentFiles, GSList * torrentFiles,
pref_flag_t start, pref_flag_t start,
pref_flag_t prompt ) pref_flag_t prompt,
gboolean doNotify )
{ {
const gboolean doStart = pref_flag_eval( start, PREF_KEY_START ); const gboolean doStart = pref_flag_eval( start, PREF_KEY_START );
const gboolean doPrompt = pref_flag_eval( prompt, PREF_KEY_OPTIONS_PROMPT ); const gboolean doPrompt = pref_flag_eval( prompt, PREF_KEY_OPTIONS_PROMPT );
GSList * l; GSList * l;
for( l = torrentFiles; l != NULL; l = l->next ) for( l = torrentFiles; l != NULL; l = l->next )
add_filename( core, l->data, doStart, doPrompt ); add_filename( core, l->data, doStart, doPrompt, doNotify );
tr_core_torrents_added( core ); tr_core_torrents_added( core );
freestrlist( torrentFiles ); freestrlist( torrentFiles );

View file

@ -134,10 +134,11 @@ int tr_core_load( TrCore * self,
void tr_core_add_list( TrCore * self, void tr_core_add_list( TrCore * self,
GSList * torrentFiles, GSList * torrentFiles,
pref_flag_t start, pref_flag_t start,
pref_flag_t prompt ); pref_flag_t prompt,
gboolean doNotify );
#define tr_core_add_list_defaults( c, l ) \ #define tr_core_add_list_defaults( c, l, doNotify ) \
tr_core_add_list( c, l, PREF_FLAG_DEFAULT, PREF_FLAG_DEFAULT ) tr_core_add_list( c, l, PREF_FLAG_DEFAULT, PREF_FLAG_DEFAULT, doNotify )
/** @brief Add a torrent. */ /** @brief Add a torrent. */
@ -147,7 +148,7 @@ gboolean tr_core_add_metainfo( TrCore * core,
GError ** err ); GError ** err );
/** Add a torrent. */ /** Add a torrent. */
void tr_core_add_torrent( TrCore*, TrTorrent* ); void tr_core_add_torrent( TrCore*, TrTorrent*, gboolean doNotify );
/** Present the main window */ /** Present the main window */
gboolean tr_core_present_window( TrCore*, gboolean * setme_success, GError ** err ); gboolean tr_core_present_window( TrCore*, gboolean * setme_success, GError ** err );

View file

@ -538,12 +538,16 @@ peerPage( GObject * core )
w = new_encryption_combo( core, "encryption" ); w = new_encryption_combo( core, "encryption" );
hig_workarea_add_row( t, &row, s, w, NULL ); hig_workarea_add_row( t, &row, s, w, NULL );
s = _( "Use peer e_xchange (PEX)" ); s = _( "Use PE_X to find more peers" );
w = new_check_button( s, TR_PREFS_KEY_PEX_ENABLED, core ); w = new_check_button( s, TR_PREFS_KEY_PEX_ENABLED, core );
s = _( "PEX is a tool for exchanging peer lists with the peers you're connected to." );
gtr_widget_set_tooltip_text( w, s );
hig_workarea_add_wide_control( t, &row, w ); hig_workarea_add_wide_control( t, &row, w );
s = _( "Use _distributed hash table (DHT)" ); s = _( "Use _DHT to find more peers" );
w = new_check_button( s, TR_PREFS_KEY_DHT_ENABLED, core ); w = new_check_button( s, TR_PREFS_KEY_DHT_ENABLED, core );
s = _( "DHT is a tool for finding peers without a tracker." );
gtr_widget_set_tooltip_text( w, s );
hig_workarea_add_wide_control( t, &row, w ); hig_workarea_add_wide_control( t, &row, w );
hig_workarea_finish( t, &row ); hig_workarea_finish( t, &row );