~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to shell/rb-tray-icon.c

Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *
17
17
 *  You should have received a copy of the GNU General Public License
18
18
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
20
20
 *
21
21
 */
22
22
 
38
38
#include "eel-gconf-extensions.h"
39
39
#include "rb-preferences.h"
40
40
#include "rb-shell.h"
 
41
#include "rb-shell-player.h"
41
42
 
42
43
static void rb_tray_icon_class_init (RBTrayIconClass *klass);
43
44
static void rb_tray_icon_init (RBTrayIcon *shell_player);
44
45
static GObject *rb_tray_icon_constructor (GType type, guint n_construct_properties,
45
46
                                          GObjectConstructParam *construct_properties);
46
47
static void rb_tray_icon_finalize (GObject *object);
47
 
static void rb_tray_icon_sync_action (RBRemoteProxy *proxy, 
 
48
static void rb_tray_icon_sync_action (RBShell *shell, 
48
49
                                      gboolean visible, 
49
50
                                      RBTrayIcon *tray);
50
51
static void rb_tray_icon_set_property (GObject *object,
80
81
 
81
82
        GtkWidget *ebox;
82
83
 
83
 
        RBRemoteProxy *proxy;
 
84
        RBShell *shell;
 
85
        RBShellPlayer *shell_player;
84
86
 
85
87
        gboolean show_notifications;
86
88
};
92
94
        PROP_0,
93
95
        PROP_UI_MANAGER,
94
96
        PROP_ACTION_GROUP,
95
 
        PROP_REMOTE
 
97
        PROP_SHELL
96
98
};
97
99
 
98
100
enum
105
107
        { "TrayShowWindow", NULL, N_("_Show Music Player"), NULL,
106
108
          N_("Choose music to play"),
107
109
          G_CALLBACK (rb_tray_icon_show_window_changed_cb) },
108
 
        { "TrayShowNotifications", NULL, N_("Show _Notifications"), NULL,
 
110
        { "TrayShowNotifications", NULL, N_("Show N_otifications"), NULL,
109
111
          N_("Show notifications of song changes and other events"),
110
112
          G_CALLBACK (rb_tray_icon_show_notifications_changed_cb) }
111
113
};
127
129
        object_class->get_property = rb_tray_icon_get_property;
128
130
 
129
131
        g_object_class_install_property (object_class,
130
 
                                         PROP_REMOTE,
131
 
                                         g_param_spec_object ("remote",
132
 
                                                              "RBRemoteProxy",
133
 
                                                              "RBRemoteProxy object",
134
 
                                                              RB_TYPE_REMOTE_PROXY,
 
132
                                         PROP_SHELL,
 
133
                                         g_param_spec_object ("shell",
 
134
                                                              "RBShell",
 
135
                                                              "RBShell object",
 
136
                                                              RB_TYPE_SHELL,
135
137
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
136
138
        g_object_class_install_property (object_class,
137
139
                                         PROP_UI_MANAGER,
199
201
                                (type, n_construct_properties,
200
202
                                 construct_properties));
201
203
 
 
204
#ifdef HAVE_NOTIFY
202
205
        tray->priv->show_notifications = eel_gconf_get_boolean (CONF_UI_SHOW_NOTIFICATIONS);
 
206
#endif
203
207
 
204
208
        tray->priv->actiongroup = gtk_action_group_new ("TrayActions");
205
209
        gtk_action_group_set_translation_domain (tray->priv->actiongroup,
238
242
}
239
243
 
240
244
static void
241
 
rb_tray_icon_sync_action (RBRemoteProxy *proxy, gboolean visible, RBTrayIcon *tray)
 
245
rb_tray_icon_sync_action (RBShell *shell, gboolean visible, RBTrayIcon *tray)
242
246
{
243
247
        GtkAction *action;
244
 
        if ((tray->priv->actiongroup != NULL) && (tray->priv->proxy != NULL)) {
 
248
        if ((tray->priv->actiongroup != NULL) && (tray->priv->shell != NULL)) {
 
249
                gboolean visible;
 
250
 
245
251
                action = gtk_action_group_get_action (tray->priv->actiongroup,
246
252
                                                      "TrayShowWindow");
247
 
                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
248
 
                                              rb_remote_proxy_get_visibility (tray->priv->proxy));
 
253
                g_object_get (G_OBJECT (tray->priv->shell), "visibility", &visible, NULL);
 
254
                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
249
255
 
250
256
                action = gtk_action_group_get_action (tray->priv->actiongroup,
251
257
                                                      "TrayShowNotifications");
 
258
#ifdef HAVE_NOTIFY
252
259
                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
253
260
                                              tray->priv->show_notifications);
 
261
#else
 
262
                gtk_action_set_visible (action, FALSE);
 
263
#endif
254
264
        }
255
265
}
256
266
 
264
274
 
265
275
        switch (prop_id)
266
276
        {
267
 
        case PROP_REMOTE:
268
 
                tray->priv->proxy = g_value_get_object (value);
269
 
                g_signal_connect_object (G_OBJECT (tray->priv->proxy),
 
277
        case PROP_SHELL:
 
278
                tray->priv->shell = g_value_get_object (value);
 
279
                g_signal_connect_object (G_OBJECT (tray->priv->shell),
270
280
                                         "visibility_changed",
271
281
                                         G_CALLBACK (rb_tray_icon_sync_action),
272
282
                                         tray, 0);
 
283
                g_object_get (G_OBJECT (tray->priv->shell), 
 
284
                              "shell-player", &tray->priv->shell_player, 
 
285
                              NULL);
273
286
                rb_tray_icon_sync_action (NULL, FALSE, tray);
274
287
                break;
275
288
        case PROP_UI_MANAGER:
291
304
 
292
305
        switch (prop_id)
293
306
        {
294
 
        case PROP_REMOTE:
295
 
                g_value_set_object (value, tray->priv->proxy);
 
307
        case PROP_SHELL:
 
308
                g_value_set_object (value, tray->priv->shell);
296
309
                break;
297
310
        case PROP_UI_MANAGER:
298
311
                g_value_set_object (value, tray->priv->ui_manager);
308
321
 
309
322
RBTrayIcon *
310
323
rb_tray_icon_new (GtkUIManager *mgr,
311
 
                  RBRemoteProxy *remote)
 
324
                  RBShell *shell)
312
325
{
313
326
        return g_object_new (RB_TYPE_TRAY_ICON,
314
327
                             "title", "Rhythmbox tray icon",
315
328
                             "ui-manager", mgr,
316
 
                             "remote", remote,
 
329
                             "shell", shell,
317
330
                             NULL);
318
331
}
319
332
 
361
374
        rb_debug ("tray button press");
362
375
 
363
376
        switch (event->button) {
364
 
        case 1: {
365
 
                gboolean visible = rb_remote_proxy_get_visibility (icon->priv->proxy);
366
 
                rb_remote_proxy_set_visibility (icon->priv->proxy, !visible);
367
 
                break;
368
 
        }
369
 
        case 2: {
370
 
                if (rb_remote_proxy_playing (icon->priv->proxy))
371
 
                        rb_remote_proxy_pause (icon->priv->proxy);
372
 
                else
373
 
                        rb_remote_proxy_play (icon->priv->proxy);
374
 
                break;
375
 
        }
376
 
                
377
 
        case 3: {
 
377
        case 1:
 
378
                rb_shell_toggle_visibility (icon->priv->shell);
 
379
                break;
 
380
        case 2:
 
381
                rb_shell_player_playpause (icon->priv->shell_player, FALSE, NULL);
 
382
                break;
 
383
        case 3:
378
384
                popup = gtk_ui_manager_get_widget (GTK_UI_MANAGER (icon->priv->ui_manager),
379
385
                                                   "/RhythmboxTrayPopup");
380
386
                gtk_menu_set_screen (GTK_MENU (popup), gtk_widget_get_screen (GTK_WIDGET (icon)));
383
389
                                gtk_get_current_event_time ());
384
390
                break;
385
391
        }
386
 
        }
387
392
}
388
393
 
389
394
static void
390
395
rb_tray_icon_scroll_event_cb (GtkWidget *ebox, GdkEvent *event,
391
396
                                    RBTrayIcon *icon)
392
397
{
393
 
        float volume;
394
 
        GValue volume_val = {0,};
395
 
        rb_debug ("tray button scroll");
396
 
 
397
 
        g_value_init (&volume_val, G_TYPE_FLOAT);
398
 
        rb_remote_proxy_get_player_property (icon->priv->proxy, "volume", &volume_val);
399
 
        volume = g_value_get_float (&volume_val);
 
398
        gdouble adjust;
400
399
 
401
400
        switch (event->scroll.direction) {
402
401
        case GDK_SCROLL_UP:
403
 
                volume += 0.1;
404
 
                if (volume > 1.0)
405
 
                        volume = 1.0;
 
402
                adjust = 0.1;
406
403
                break;
407
404
        case GDK_SCROLL_DOWN:
408
 
                volume -= 0.1;
409
 
                if (volume < 0)
410
 
                        volume = 0;
411
 
                break;
412
 
        case GDK_SCROLL_LEFT:
413
 
        case GDK_SCROLL_RIGHT:
414
 
                break;
 
405
                adjust = -0.1;
 
406
                break;
 
407
        default:
 
408
                return;
415
409
        }
416
 
        
417
 
        rb_debug ("got scroll, setting volume to %f", volume);
418
 
        g_value_set_float (&volume_val, volume);
419
 
        rb_remote_proxy_set_player_property (icon->priv->proxy, "volume", &volume_val);
 
410
 
 
411
        rb_shell_player_set_volume_relative (icon->priv->shell_player, adjust, NULL);
420
412
}
421
413
 
422
414
static void
462
454
        for (i = uri_list; i != NULL; i = i->next) {
463
455
                char *uri = i->data;
464
456
                if (uri != NULL)
465
 
                        rb_remote_proxy_load_uri (icon->priv->proxy, uri, FALSE);
 
457
                        rb_shell_load_uri (icon->priv->shell, uri, FALSE, NULL);
466
458
 
467
459
                g_free (uri);
468
460
        }
477
469
                                     RBTrayIcon *icon)
478
470
{
479
471
        rb_debug ("show window clicked for %p", icon);
480
 
        rb_remote_proxy_set_visibility (icon->priv->proxy,
481
 
                                        gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
 
472
        g_object_set (G_OBJECT (icon->priv->shell), 
 
473
                      "visibility", gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)), 
 
474
                      NULL);
482
475
}
483
476
 
484
477
static void