Re: [Rhythmbox-devel] [patch] Show window when not visible



Before going further I'd like to have some comments on the attached
patch. It is only about adding methods to the corba interface. I've
added the following methods :

               boolean toggleVisibility ();
               void playPause ();
               void next ();
               void previous ();
               void stop ();
               boolean toggleShuffle ();
               boolean toggleRepeat ();

Do we want a more fine-grained api ? eg. toggleRepeat() vs
getRepeat()+setRepeat(boolean repeat).

The command-line stuff in main.c is there mainly for testing purposes,
so it can be removed if it looks like future bloat (although I find it
very handy).

Also, there is a slight problem with rb_shell_player_stop () that
doesn't update the ui. Not sure if I should write a wrapper or if having
stop () isn't worth it.

Thanks,

Rached

On Mon, 2003-08-18 at 02:06, Colin Walters wrote:
> On Sun, 2003-08-17 at 15:54, Rached Ben Mustapha wrote:
> > Of course it would be nice to have an applet control rb's playback, etc,
> > and let the tray icon (if it stays) just indicate rb's status. It seems
> > like an interesting task.
> 
> Awesome, I'm glad you're interested in working on this.
> 
> > So I'm happily starting work on an applet. I'll see if real life lets me
> > get somewhere :)
> > 
> > Should I wait for some planned infrastructure work ?
> 
> Nope, you shouldn't need to wait to get started.  To begin, we need
> several methods added to the Rhythmbox.idl interface.  Maybe something
> like this:
> 
> void playPause ();
> 
> void stop ();
> 
> void show ();
> 
> void hide ();
> 
> This actually isn't very hard at all, and would be a good task for
> someone wanting to learn the Rhythmbox codebase.
> 
> Then the control applet will just use these bonobo methods.
> 
> _______________________________________________
> rhythmbox-devel mailing list
> rhythmbox-devel@gnome.org
> http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
> 
Index: corba/Rhythmbox.idl
===================================================================
RCS file: /cvs/gnome/rhythmbox/corba/Rhythmbox.idl,v
retrieving revision 1.1
diff -u -r1.1 Rhythmbox.idl
--- corba/Rhythmbox.idl	31 Jul 2003 00:53:16 -0000	1.1
+++ corba/Rhythmbox.idl	18 Aug 2003 14:39:04 -0000
@@ -9,7 +9,15 @@
 		void handleFile (in string uri);
 
 		void grabFocus ();
+		boolean toggleVisibility ();
 
+		void playPause ();
+		void next ();
+		void previous ();
+		void stop ();
+		boolean toggleShuffle ();
+		boolean toggleRepeat ();
+    
 		string getPlayingTitle ();
 		string getPlayingPath ();
 	
Index: shell/main.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/main.c,v
retrieving revision 1.27
diff -u -r1.27 main.c
--- shell/main.c	17 Aug 2003 08:14:45 -0000	1.27
+++ shell/main.c	18 Aug 2003 14:39:07 -0000
@@ -54,6 +54,14 @@
 static gboolean no_registration = FALSE;
 static gboolean print_playing = FALSE;
 static gboolean print_playing_path = FALSE;
+static gboolean playpause       = FALSE;
+static gboolean stop            = FALSE;
+static gboolean previous        = FALSE;
+static gboolean next            = FALSE;
+static gboolean toggle_shuffle	= FALSE;
+static gboolean toggle_visibility = FALSE;
+static gboolean toggle_repeat	= FALSE;
+
 
 int
 main (int argc, char **argv)
@@ -65,8 +73,17 @@
 
 	const struct poptOption popt_options[] =
 	{
-		{ "print-playing",   0,  POPT_ARG_NONE,          &print_playing,                                  0, N_("Print the playing song and exit"),     NULL },
-		{ "print-playing-path", 0,  POPT_ARG_NONE,          &print_playing_path,                          0, N_("Print the playing song URI and exit"),     NULL },
+		{ "print-playing",	0,  POPT_ARG_NONE,          &print_playing,                                  0, N_("Print the playing song and exit"),     NULL },
+		{ "print-playing-path",	0,  POPT_ARG_NONE,          &print_playing_path,                          0, N_("Print the playing song URI and exit"),     NULL },
+        
+		{ "play-pause",		0,  POPT_ARG_NONE,	&playpause,		0, N_("Toggle play/pause mode"),     NULL },
+		{ "stop",		0,  POPT_ARG_NONE,	&stop,			0, N_("Stop playing"),     NULL },
+		{ "previous",		0,  POPT_ARG_NONE,	&previous,		0, N_("Jump to previous song"),     NULL },
+		{ "next",		0,  POPT_ARG_NONE,	&next,			0, N_("Jump to next song"),     NULL },
+		{ "toggle-visibility",	0,  POPT_ARG_NONE,	&toggle_visibility,	0, N_("Toggle window visibility"),     NULL },
+		{ "toggle-shuffle",	0,  POPT_ARG_NONE,	&toggle_shuffle,	0, N_("Toggle shuffle mode"),     NULL },
+		{ "toggle-repeat",	0,  POPT_ARG_NONE,	&toggle_repeat,		0, N_("Toggle repeat mode"),     NULL },
+		
 		{ "debug",           'd',  POPT_ARG_NONE,          &debug,                                        0, N_("Enable debugging code"),     NULL },
 		{ "no-registration", 'n',  POPT_ARG_NONE,          &no_registration,                              0, N_("Do not register the shell"), NULL },
 		{ "quit",            'q',  POPT_ARG_NONE,          &quit,                                         0, N_("Quit Rhythmbox"),            NULL },
@@ -195,7 +212,7 @@
 {
 	GNOME_Rhythmbox shell;
 	int i;
-
+	gboolean grab_focus = FALSE;
 	shell = bonobo_activation_activate_from_id (RB_SHELL_OAFIID, 0, NULL, &ev);
 	if (shell == NULL)
 	{
@@ -208,19 +225,44 @@
 
 	if (print_playing)
 		printf ("%s\n", GNOME_Rhythmbox_getPlayingTitle (shell, &ev));
+	
 	if (print_playing_path)
 		printf ("%s\n", GNOME_Rhythmbox_getPlayingPath (shell, &ev));
 
+	if (playpause)
+		GNOME_Rhythmbox_playPause (shell, &ev);
+
+	if (stop)
+		GNOME_Rhythmbox_stop (shell, &ev);
+
+	if (previous)
+		GNOME_Rhythmbox_previous (shell, &ev);
+
+	if (next)
+		GNOME_Rhythmbox_next (shell, &ev);
+
+	if (toggle_visibility)
+		GNOME_Rhythmbox_toggleVisibility (shell, &ev);
+
+	if (toggle_shuffle)
+		GNOME_Rhythmbox_toggleShuffle (shell, &ev);
+
+	if (toggle_repeat)
+		GNOME_Rhythmbox_toggleRepeat (shell, &ev);
+
 	for (i = 1; i < argc; i++)
 	{
 		char *tmp;
 
 		tmp = rb_uri_resolve_relative (argv[i]);
 			
-		if (rb_uri_exists (tmp) == TRUE)
+		if (rb_uri_exists (tmp) == TRUE) {
 			GNOME_Rhythmbox_handleFile (shell, tmp, &ev);
-
+			grab_focus = TRUE;
+		}
+		
 		g_free (tmp);
+		
 	}
 	
 	if (quit == TRUE)
@@ -229,6 +271,6 @@
 	}
 
 	/* at the very least, we focus the window */
-	if (already_running == TRUE && !(print_playing_path || print_playing))
+	if (already_running == TRUE && grab_focus == TRUE)
 		GNOME_Rhythmbox_grabFocus (shell, &ev);
 }
Index: shell/rb-shell-player.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell-player.c,v
retrieving revision 1.72
diff -u -r1.72 rb-shell-player.c
--- shell/rb-shell-player.c	18 Aug 2003 00:51:44 -0000	1.72
+++ shell/rb-shell-player.c	18 Aug 2003 14:39:07 -0000
@@ -68,21 +68,18 @@
 					  guint prop_id,
 					  GValue *value,
 					  GParamSpec *pspec);
-static void rb_shell_player_do_previous (RBShellPlayer *player);
 static void rb_shell_player_cmd_previous (BonoboUIComponent *component,
 			                  RBShellPlayer *player,
 			                  const char *verbname);
 static void rb_shell_player_cmd_play (BonoboUIComponent *component,
 			              RBShellPlayer *player,
 			              const char *verbname);
-static void rb_shell_player_playpause (RBShellPlayer *player);
 static void rb_shell_player_cmd_pause (BonoboUIComponent *component,
 			               RBShellPlayer *player,
 			               const char *verbname);
 static void rb_shell_player_cmd_stop (BonoboUIComponent *component,
 			              RBShellPlayer *player,
 			              const char *verbname);
-static void rb_shell_player_do_next (RBShellPlayer *player);
 static void rb_shell_player_cmd_next (BonoboUIComponent *component,
 			              RBShellPlayer *player,
 			              const char *verbname);
@@ -841,7 +838,7 @@
 	rb_node_view_select_node (songs, rb_node_view_get_playing_node (songs));
 }
 
-static void
+void
 rb_shell_player_do_previous (RBShellPlayer *player)
 {
 	if (monkey_media_player_get_time (player->priv->mmplayer) < 3 &&
@@ -877,7 +874,7 @@
 	rb_shell_player_playpause (player);
 }
 
-static void
+void
 rb_shell_player_playpause (RBShellPlayer *player)
 {
 	switch (player->priv->playbutton_state) {
@@ -1023,7 +1020,7 @@
 	rb_source_song_properties (player->priv->selected_source);
 }
 
-static void
+void
 rb_shell_player_do_next (RBShellPlayer *player)
 {
 	if (player->priv->source != NULL)
Index: shell/rb-shell-player.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell-player.h,v
retrieving revision 1.13
diff -u -r1.13 rb-shell-player.h
--- shell/rb-shell-player.h	7 Aug 2003 17:41:07 -0000	1.13
+++ shell/rb-shell-player.h	18 Aug 2003 14:39:07 -0000
@@ -66,7 +66,11 @@
 
 void			rb_shell_player_jump_to_current (RBShellPlayer *player);
 
+void			rb_shell_player_playpause	(RBShellPlayer *player);
 void			rb_shell_player_stop		(RBShellPlayer *shell_player);
+void			rb_shell_player_do_previous	(RBShellPlayer *player);
+void			rb_shell_player_do_next		(RBShellPlayer *player);
+
 
 void			rb_shell_player_set_shuffle	(RBShellPlayer *shell_player,
 							 gboolean shuffle);
Index: shell/rb-shell.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-shell.c,v
retrieving revision 1.162
diff -u -r1.162 rb-shell.c
--- shell/rb-shell.c	17 Aug 2003 08:14:44 -0000	1.162
+++ shell/rb-shell.c	18 Aug 2003 14:39:08 -0000
@@ -97,7 +97,20 @@
 						CORBA_Environment *ev);
 static char * rb_shell_corba_get_playing_path (PortableServer_Servant _servant,
 					       CORBA_Environment *ev);
-
+static CORBA_boolean rb_shell_corba_toggle_visibility (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static void rb_shell_corba_playpause (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static void rb_shell_corba_next (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static void rb_shell_corba_previous (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static void rb_shell_corba_stop (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static CORBA_boolean rb_shell_corba_toggle_shuffle (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
+static CORBA_boolean rb_shell_corba_toggle_repeat (PortableServer_Servant _servant,
+					       CORBA_Environment *ev);
 void rb_shell_handle_playlist_entry (RBShell *shell, GList *locations, const char *title,
 				     const char *genre);
 static gboolean rb_shell_window_state_cb (GtkWidget *widget,
@@ -106,6 +119,9 @@
 static gboolean rb_shell_window_delete_cb (GtkWidget *win,
 			                   GdkEventAny *event,
 			                   RBShell *shell);
+static gboolean rb_shell_window_visibility_cb (GtkWidget *win,
+			                   GdkEventVisibility *event,
+			                   RBShell *shell);
 static void rb_shell_sync_window_state (RBShell *shell);
 static void rb_shell_sync_paned (RBShell *shell);
 static void paned_size_allocate_cb (GtkWidget *widget,
@@ -255,6 +271,7 @@
 struct RBShellPrivate
 {
 	GtkWidget *window;
+	gboolean window_obscured;
 
 	BonoboUIComponent *ui_component;
 	BonoboUIContainer *container;
@@ -380,8 +397,16 @@
 	epv->handleFile   = rb_shell_corba_handle_file;
 	epv->addToLibrary = rb_shell_corba_add_to_library;
 	epv->grabFocus    = rb_shell_corba_grab_focus;
+	epv->toggleVisibility = rb_shell_corba_toggle_visibility;
 	epv->getPlayingTitle = rb_shell_corba_get_playing_title;
 	epv->getPlayingPath = rb_shell_corba_get_playing_path;
+	epv->playPause = rb_shell_corba_playpause;
+	epv->previous = rb_shell_corba_previous;
+	epv->next = rb_shell_corba_next;
+	epv->stop = rb_shell_corba_stop;
+	epv->toggleShuffle = rb_shell_corba_toggle_shuffle;
+	epv->toggleRepeat = rb_shell_corba_toggle_repeat;
+
 }
 
 static void
@@ -577,6 +602,81 @@
 	return ret;
 }
 
+static CORBA_boolean
+rb_shell_corba_toggle_shuffle (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	gboolean shuffle;
+	
+	shuffle = eel_gconf_get_boolean(CONF_STATE_SHUFFLE);
+	eel_gconf_set_boolean(CONF_STATE_SHUFFLE, !shuffle);
+	
+	return !shuffle;
+}
+
+static CORBA_boolean
+rb_shell_corba_toggle_repeat (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	gboolean repeat;
+	
+	repeat = eel_gconf_get_boolean(CONF_STATE_REPEAT);
+	eel_gconf_set_boolean(CONF_STATE_REPEAT, !repeat);
+	
+	return !repeat;
+}
+
+/* returns TRUE if the window was shown, FALSE if it was hidden */
+static CORBA_boolean
+rb_shell_corba_toggle_visibility (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	gboolean window_hidden;
+	RBShell *shell = RB_SHELL (bonobo_object (_servant));
+
+	window_hidden = eel_gconf_get_boolean (CONF_STATE_WINDOW_HIDDEN);
+
+	if (window_hidden || !shell->priv->window_obscured) {
+		eel_gconf_set_boolean (CONF_STATE_WINDOW_HIDDEN, !window_hidden);
+		return window_hidden; /* (!!window_hidden actually) */
+	}
+	
+	gtk_window_present (GTK_WINDOW(shell->priv->window));
+	return TRUE;
+}
+
+static void
+rb_shell_corba_playpause (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	RBShell *shell = RB_SHELL (bonobo_object (_servant));
+	rb_shell_player_playpause (shell->priv->player_shell);
+}
+
+static void
+rb_shell_corba_next (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	RBShell *shell = RB_SHELL (bonobo_object (_servant));
+	rb_shell_player_do_next (shell->priv->player_shell);
+}
+
+static void
+rb_shell_corba_previous (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	RBShell *shell = RB_SHELL (bonobo_object (_servant));
+	rb_shell_player_do_previous (shell->priv->player_shell);
+}
+
+static void
+rb_shell_corba_stop (PortableServer_Servant _servant,
+				 CORBA_Environment *ev)
+{
+	RBShell *shell = RB_SHELL (bonobo_object (_servant));
+	rb_shell_player_stop (shell->priv->player_shell);
+}
+
 static gboolean
 async_library_release_brakes (RBShell *shell)
 {
@@ -620,7 +720,11 @@
 	g_signal_connect (G_OBJECT (win), "delete_event",
 			  G_CALLBACK (rb_shell_window_delete_cb),
 			  shell);
-
+	g_signal_connect (G_OBJECT (win), "visibility-notify-event",
+			  G_CALLBACK (rb_shell_window_visibility_cb),
+			  shell);
+	gtk_widget_add_events (GTK_WIDGET (win), GDK_VISIBILITY_NOTIFY_MASK);
+  
 	rb_debug ("shell: creating container area");
 	shell->priv->container = bonobo_window_get_ui_container (win);
 
@@ -914,6 +1018,22 @@
 
 	return TRUE;
 };
+
+static gboolean
+rb_shell_window_visibility_cb (GtkWidget *win,
+			       GdkEventVisibility *event,
+			       RBShell *shell)
+{
+	rb_debug ("window visibility changed");
+
+	if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) {
+		shell->priv->window_obscured = TRUE;
+	} else {
+		shell->priv->window_obscured = FALSE;
+	}
+    
+	return FALSE;
+}
 
 static void
 source_selected_cb (RBSourceList *sourcelist,


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