~ubuntu-branches/ubuntu/precise/transmission/precise

« back to all changes in this revision

Viewing changes to gtk/tr-icon.c

  • Committer: Bazaar Package Importer
  • Author(s): Leo Costela
  • Date: 2009-05-17 19:39:51 UTC
  • mto: (1.3.4 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20090517193951-k8x15sqoxzf7cuyx
ImportĀ upstreamĀ versionĀ 1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
 
2
 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
6
 
 * so that the bulk of its code can remain under the MIT license. 
 
6
 * so that the bulk of its code can remain under the MIT license.
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
 
 * 
10
 
 * $Id: tr-icon.c 5476 2008-04-01 02:36:41Z charles $
 
9
 *
 
10
 * $Id: tr-icon.c 7658 2009-01-10 23:09:07Z charles $
11
11
 */
12
12
 
13
13
#include <glib/gi18n.h>
26
26
 
27
27
#else
28
28
 
29
 
#define UPDATE_INTERVAL 2500
 
29
#define UPDATE_INTERVAL_SECONDS 2
30
30
 
31
31
static void
32
 
activated ( GtkStatusIcon   * self        UNUSED,
33
 
            gpointer          user_data   UNUSED )
 
32
activated( GtkStatusIcon   * self      UNUSED,
 
33
           gpointer          user_data UNUSED )
34
34
{
35
 
    action_activate ("toggle-main-window");
 
35
    action_activate ( "toggle-main-window" );
36
36
}
37
37
 
38
38
static void
39
 
popup ( GtkStatusIcon  * self,
40
 
        guint            button,
41
 
        guint            when,
42
 
        gpointer         data    UNUSED )
 
39
popup( GtkStatusIcon *       self,
 
40
       guint                 button,
 
41
       guint                 when,
 
42
       gpointer         data UNUSED )
43
43
{
44
44
    GtkWidget * w = action_get_widget( "/icon-popup" );
45
 
    gtk_menu_popup (GTK_MENU(w), NULL, NULL,
46
 
                    gtk_status_icon_position_menu,
47
 
                    self, button, when );
48
 
}
49
45
 
50
 
static void
51
 
core_destroyed( gpointer data, GObject * core UNUSED )
52
 
{
53
 
    g_source_remove( GPOINTER_TO_UINT( data ) );
 
46
    gtk_menu_popup ( GTK_MENU( w ), NULL, NULL,
 
47
                     gtk_status_icon_position_menu,
 
48
                     self, button, when );
54
49
}
55
50
 
56
51
static gboolean
57
52
refresh_tooltip_cb( gpointer data )
58
53
{
59
 
    GtkStatusIcon * icon = GTK_STATUS_ICON( data );
60
 
    TrCore * core = g_object_get_data( G_OBJECT( icon ), "tr-core" );
 
54
    GtkStatusIcon *   icon = GTK_STATUS_ICON( data );
 
55
    TrCore *          core = g_object_get_data( G_OBJECT( icon ), "tr-core" );
61
56
    struct core_stats stats;
62
 
    char downStr[32], upStr[32];
63
 
    char tip[256];
 
57
    char              downStr[32], upStr[32];
 
58
    char              tip[256];
64
59
 
65
60
    tr_core_get_stats( core, &stats );
66
61
 
71
66
                   %2$'d is the number of torrents we're downloading,
72
67
                   %3$s is our download speed,
73
68
                   %4$s is our upload speed */
74
 
                _( "%1$'d Seeding, %2$'d Downloading\nDown: %3$s, Up: %4$s" ), 
 
69
                _( "%1$'d Seeding, %2$'d Downloading\nDown: %3$s, Up: %4$s" ),
75
70
                stats.seedingCount,
76
71
                stats.downloadCount,
77
72
                downStr, upStr );
80
75
    return TRUE;
81
76
}
82
77
 
 
78
static void
 
79
closeTag( gpointer tag )
 
80
{
 
81
    g_source_remove( GPOINTER_TO_UINT( tag ) );
 
82
}
 
83
 
83
84
gpointer
84
85
tr_icon_new( TrCore * core )
85
86
{
86
 
    guint id;
87
 
    GtkStatusIcon * icon = gtk_status_icon_new_from_icon_name( "transmission" );
 
87
    guint           id;
 
88
    GtkStatusIcon * icon = gtk_status_icon_new_from_icon_name(
 
89
        "transmission" );
 
90
 
88
91
    g_signal_connect( icon, "activate", G_CALLBACK( activated ), NULL );
89
92
    g_signal_connect( icon, "popup-menu", G_CALLBACK( popup ), NULL );
90
 
    id = g_timeout_add( UPDATE_INTERVAL, refresh_tooltip_cb, icon );
91
 
    g_object_weak_ref( G_OBJECT( core ), core_destroyed, GUINT_TO_POINTER( id ) );
 
93
    id = gtr_timeout_add_seconds( UPDATE_INTERVAL_SECONDS, refresh_tooltip_cb, icon );
92
94
    g_object_set_data( G_OBJECT( icon ), "tr-core", core );
 
95
    g_object_set_data_full( G_OBJECT(
 
96
                                icon ), "update-tag", GUINT_TO_POINTER(
 
97
                                id ), closeTag );
93
98
    return icon;
94
99
}
95
100