(gtk) #616: tray icon info popup, suggested by inferneux and seconded a few times in the forums.
This commit is contained in:
parent
470d588b50
commit
756bacd076
|
@ -407,7 +407,7 @@ static void
|
|||
makeicon( struct cbdata * cbdata )
|
||||
{
|
||||
if( cbdata->icon == NULL )
|
||||
cbdata->icon = tr_icon_new( );
|
||||
cbdata->icon = tr_icon_new( cbdata->core );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
|
|
|
@ -645,17 +645,28 @@ static gboolean
|
|||
update_foreach( GtkTreeModel * model,
|
||||
GtkTreePath * path UNUSED,
|
||||
GtkTreeIter * iter,
|
||||
gpointer data UNUSED)
|
||||
gpointer data )
|
||||
{
|
||||
TrTorrent * gtor;
|
||||
int oldStatus;
|
||||
const tr_stat * torStat;
|
||||
struct core_stats * stats = data;
|
||||
|
||||
gtk_tree_model_get( model, iter, MC_TORRENT, >or,
|
||||
MC_STATUS, &oldStatus,
|
||||
-1 );
|
||||
|
||||
torStat = tr_torrent_stat( gtor );
|
||||
|
||||
/* sum the torrents' cumulative stats... */
|
||||
if( torStat->status == TR_STATUS_DOWNLOAD )
|
||||
++stats->downloadCount;
|
||||
else if( torStat->status == TR_STATUS_SEED )
|
||||
++stats->seedingCount;
|
||||
stats->clientDownloadSpeed += torStat->rateDownload;
|
||||
stats->clientUploadSpeed += torStat->rateUpload;
|
||||
|
||||
/* update the model's status if necessary */
|
||||
if( oldStatus != (int) torStat->status )
|
||||
gtk_list_store_set( GTK_LIST_STORE( model ), iter,
|
||||
MC_STATUS, torStat->status,
|
||||
|
@ -680,7 +691,8 @@ tr_core_update( TrCore * self )
|
|||
gtk_tree_sortable_set_sort_column_id( sortable, GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, order );
|
||||
|
||||
/* refresh the model */
|
||||
gtk_tree_model_foreach( self->model, update_foreach, NULL );
|
||||
memset( &self->stats, 0, sizeof( struct core_stats ) );
|
||||
gtk_tree_model_foreach( self->model, update_foreach, &self->stats );
|
||||
|
||||
/* resume sorting */
|
||||
gtk_tree_sortable_set_sort_column_id( sortable, column, order );
|
||||
|
|
|
@ -55,15 +55,24 @@
|
|||
typedef struct _TrCore TrCore;
|
||||
typedef struct _TrCoreClass TrCoreClass;
|
||||
|
||||
struct core_stats
|
||||
{
|
||||
int downloadCount;
|
||||
int seedingCount;
|
||||
float clientDownloadSpeed;
|
||||
float clientUploadSpeed;
|
||||
};
|
||||
|
||||
/* treat the contents of this structure as private */
|
||||
struct _TrCore
|
||||
{
|
||||
GObject parent;
|
||||
GtkTreeModel * model;
|
||||
tr_handle * handle;
|
||||
int nextid;
|
||||
gboolean quitting;
|
||||
gboolean disposed;
|
||||
GObject parent;
|
||||
GtkTreeModel * model;
|
||||
tr_handle * handle;
|
||||
int nextid;
|
||||
gboolean quitting;
|
||||
gboolean disposed;
|
||||
struct core_stats stats;
|
||||
};
|
||||
|
||||
struct _TrCoreClass
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "actions.h"
|
||||
#include "tr_icon.h"
|
||||
|
@ -30,7 +31,7 @@
|
|||
#ifndef STATUS_ICON_SUPPORTED
|
||||
|
||||
gpointer
|
||||
tr_icon_new( void )
|
||||
tr_icon_new( tr_handle * handle )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -56,13 +57,44 @@ popup ( GtkStatusIcon * self,
|
|||
self, button, when );
|
||||
}
|
||||
|
||||
gpointer
|
||||
tr_icon_new( void )
|
||||
static void
|
||||
core_destroyed( gpointer data, GObject * core UNUSED )
|
||||
{
|
||||
GtkStatusIcon * ret = gtk_status_icon_new_from_stock ("transmission-logo");
|
||||
g_signal_connect( ret, "activate", G_CALLBACK( activated ), NULL );
|
||||
g_signal_connect( ret, "popup-menu", G_CALLBACK( popup ), NULL );
|
||||
return ret;
|
||||
g_source_remove( GPOINTER_TO_UINT( data ) );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
refresh_tooltip_cb( gpointer data )
|
||||
{
|
||||
GtkStatusIcon * icon = GTK_STATUS_ICON( data );
|
||||
TrCore * core = g_object_get_data( G_OBJECT( icon ), "tr-core" );
|
||||
const struct core_stats * stats = &core->stats;
|
||||
char downStr[32], upStr[32];
|
||||
char tip[256];
|
||||
|
||||
tr_strlspeed( downStr, stats->clientDownloadSpeed, sizeof( downStr ) );
|
||||
tr_strlspeed( upStr, stats->clientUploadSpeed, sizeof( upStr ) );
|
||||
g_snprintf( tip, sizeof( tip ),
|
||||
_( "%d Seeding, %d Downloading\nDown: %s, Up: %s" ),
|
||||
stats->seedingCount,
|
||||
stats->downloadCount,
|
||||
downStr, upStr );
|
||||
gtk_status_icon_set_tooltip( GTK_STATUS_ICON( icon ), tip );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gpointer
|
||||
tr_icon_new( TrCore * core )
|
||||
{
|
||||
guint id;
|
||||
GtkStatusIcon * icon = gtk_status_icon_new_from_stock ("transmission-logo");
|
||||
g_signal_connect( icon, "activate", G_CALLBACK( activated ), NULL );
|
||||
g_signal_connect( icon, "popup-menu", G_CALLBACK( popup ), NULL );
|
||||
id = g_timeout_add( 1000, refresh_tooltip_cb, icon );
|
||||
g_object_weak_ref( G_OBJECT( core ), core_destroyed, GUINT_TO_POINTER( id ) );
|
||||
g_object_set_data( G_OBJECT( icon ), "tr-core", core );
|
||||
return icon;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define TR_ICON_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "tr_core.h"
|
||||
|
||||
#if GTK_CHECK_VERSION(2,10,0)
|
||||
#define STATUS_ICON_SUPPORTED
|
||||
|
@ -34,6 +35,6 @@
|
|||
#define status_icon_supported() (FALSE)
|
||||
#endif
|
||||
|
||||
gpointer tr_icon_new( void );
|
||||
gpointer tr_icon_new( TrCore * core );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue