[rhythmbox] shell: convert play button into play/pause/stop button



commit 912811ecb11ca1d0fd8a34e5a7f0106d23334f05
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Mar 9 20:21:21 2013 +1000

    shell: convert play button into play/pause/stop button

 data/ui/main-toolbar.ui |    2 +-
 shell/rb-shell-player.c |   45 +--------------------------------------------
 shell/rb-shell.c        |   23 ++++++++++++++++++++---
 3 files changed, 22 insertions(+), 48 deletions(-)
---
diff --git a/data/ui/main-toolbar.ui b/data/ui/main-toolbar.ui
index ac2afbe..5565884 100644
--- a/data/ui/main-toolbar.ui
+++ b/data/ui/main-toolbar.ui
@@ -23,7 +23,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkToggleToolButton" id="play-button">
+      <object class="GtkToolButton" id="play-button">
         <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
diff --git a/shell/rb-shell-player.c b/shell/rb-shell-player.c
index 671a7f6..24509fb 100644
--- a/shell/rb-shell-player.c
+++ b/shell/rb-shell-player.c
@@ -149,9 +149,6 @@ static void rb_shell_player_sync_buttons (RBShellPlayer *player);
 static void player_settings_changed_cb (GSettings *settings,
                                        const char *key,
                                        RBShellPlayer *player);
-static void rb_shell_player_playing_changed_cb (RBShellPlayer *player,
-                                               GParamSpec *arg1,
-                                               gpointer user_data);
 static void rb_shell_player_extra_metadata_cb (RhythmDB *db,
                                               RhythmDBEntry *entry,
                                               const char *field,
@@ -2802,41 +2799,6 @@ rb_shell_player_get_playing_path (RBShellPlayer *player,
 }
 
 static void
-rb_shell_player_playing_changed_cb (RBShellPlayer *player,
-                                   GParamSpec *arg1,
-                                   gpointer user_data)
-{
-       gboolean playing;
-       GActionMap *map;
-       GAction *action;
-       /*char *tooltip;*/
-
-       /* sync play action state */
-       g_object_get (player, "playing", &playing, NULL);
-
-       map = G_ACTION_MAP (g_application_get_default ());
-       action = g_action_map_lookup_action (map, "play");
-       g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (playing));
-
-#if 0
-       /* -> header, set tooltip on button directly */
-       action = gtk_action_group_get_action (player->priv->actiongroup,
-                                             "ControlPlay");
-       if (playing) {
-               if (rb_source_can_pause (player->priv->source)) {
-                       tooltip = g_strdup (_("Pause playback"));
-               } else {
-                       tooltip = g_strdup (_("Stop playback"));
-               }
-       } else {
-               tooltip = g_strdup (_("Start playback"));
-       }
-       g_object_set (action, "tooltip", tooltip, NULL);
-       g_free (tooltip);
-#endif
-}
-
-static void
 play_action_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
 {
        RBShellPlayer *player = RB_SHELL_PLAYER (user_data);
@@ -3025,7 +2987,7 @@ rb_shell_player_constructed (GObject *object)
        GAction *action;
 
        GActionEntry actions[] = {
-               { "play", play_action_cb, "b", "false" },
+               { "play", play_action_cb },
                { "play-previous", play_previous_action_cb },
                { "play-next", play_next_action_cb },
                { "play-repeat", play_repeat_action_cb, "b", "false" },
@@ -3064,11 +3026,6 @@ rb_shell_player_constructed (GObject *object)
        rb_shell_player_sync_control_state (player);
        rb_shell_player_sync_volume (player, FALSE, TRUE);
        player->priv->syncing_state = FALSE;
-
-       g_signal_connect (player,
-                         "notify::playing",
-                         G_CALLBACK (rb_shell_player_playing_changed_cb),
-                         NULL);
 }
 
 static void
diff --git a/shell/rb-shell.c b/shell/rb-shell.c
index 385c9e3..71eba7e 100644
--- a/shell/rb-shell.c
+++ b/shell/rb-shell.c
@@ -240,6 +240,7 @@ struct _RBShellPrivate
        GtkWidget *queue_paned;
        GtkWidget *queue_sidebar;
        GtkWidget *menu_button;
+       GtkWidget *play_button;
 
        GtkBox *sidebar_container;
        GtkBox *right_sidebar_container;
@@ -693,9 +694,9 @@ construct_load_ui (RBShell *shell)
        builder = rb_builder_load ("main-toolbar.ui", NULL);
        toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "main-toolbar"));
 
+       shell->priv->play_button = GTK_WIDGET (gtk_builder_get_object (builder, "play-button"));
+
        /* this seems a bit unnecessary */
-       gtk_actionable_set_action_target_value (GTK_ACTIONABLE (gtk_builder_get_object (builder, 
"play-button")),
-                                               g_variant_new_boolean (TRUE));
        gtk_actionable_set_action_target_value (GTK_ACTIONABLE (gtk_builder_get_object (builder, 
"shuffle-button")),
                                                g_variant_new_boolean (TRUE));
        gtk_actionable_set_action_target_value (GTK_ACTIONABLE (gtk_builder_get_object (builder, 
"repeat-button")),
@@ -2216,7 +2217,23 @@ rb_shell_playing_from_queue_cb (RBShellPlayer *player,
 static void
 rb_shell_playing_changed_cb (RBShellPlayer *player, gboolean playing, RBShell *shell)
 {
-       /* update tooltip on play/pause button */
+       const char *tooltip;
+       const char *icon_name;
+
+       if (playing) {
+               if (rb_source_can_pause (rb_shell_player_get_active_source (shell->priv->player_shell))) {
+                       icon_name = "media-playback-pause";
+                       tooltip = _("Pause playback");
+               } else {
+                       icon_name = "media-playback-stop";
+                       tooltip = _("Stop playback");
+               }
+       } else {
+               icon_name = "media-playback-start";
+               tooltip = _("Start playback");
+       }
+       gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (shell->priv->play_button), icon_name);
+       gtk_widget_set_tooltip_text (GTK_WIDGET (shell->priv->play_button), tooltip);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]