Hi,

this patch implements the gui for changing the autoplay policy from the mozilla plugin. The three possible configuration are: always autoplay, never autoplay and check last choice for the same host.

The idea implemented is to have the global autoplay key be not overriden by the per host configuration. If the global autoplay key is not present the behaviour of the actual implementation is preserved, and its default is still to do not play automatically.

Comments are appreciated.

thanks,
riccardo
diff --git a/src/swfmoz_config.c b/src/swfmoz_config.c
index 649b656..587fb49 100644
--- a/src/swfmoz_config.c
+++ b/src/swfmoz_config.c
@@ -35,20 +35,10 @@ swfmoz_config_save_file (SwfmozConfig *config)
   gchar *data;
   gsize data_size;
   GError *error = NULL;
-  gboolean has_global;
 
   gchar *keyfile_name = g_build_filename (g_get_user_config_dir (),
 					  SWFMOZ_CONFIG_FILE, NULL);
 
-  has_global = g_key_file_has_key (config->keyfile, "global", "autoplay",
-				   &error);
-  if (error) {
-    g_error_free (error);
-    error = NULL;
-  } else if (!has_global) {
-    g_key_file_set_boolean (config->keyfile, "global", "autoplay", FALSE);
-  }
-
   data = g_key_file_to_data (config->keyfile, &data_size, &error);
   if (error) {
     goto fail;
@@ -85,7 +75,7 @@ swfmoz_config_read_file (void)
 
   keyfile = g_key_file_new ();
   if (!g_key_file_load_from_file (keyfile, keyfile_name, G_KEY_FILE_NONE,
-				  &error)) {
+                                  &error)) {
       g_error_free (error);
       error = NULL;
   }
@@ -94,7 +84,21 @@ swfmoz_config_read_file (void)
   return keyfile;
 }
 
-static gboolean
+gboolean
+swfmoz_config_has_global_key (SwfmozConfig *config)
+{
+  GError *error = NULL;
+  gboolean ret;
+
+  ret = g_key_file_has_key (config->keyfile, "global", "autoplay",
+				   &error);
+  if (error)
+    g_error_free (error);
+
+  return ret; 
+}
+
+gboolean
 swfmoz_config_read_autoplay (SwfmozConfig *config, const char *host,
 			     gboolean autoplay)
 {
@@ -120,11 +124,13 @@ swfmoz_config_should_autoplay (SwfmozConfig *config, const SwfdecURL *url)
 
   g_return_val_if_fail (SWFMOZ_IS_CONFIG (config), FALSE);
 
+  if (swfmoz_config_has_global_key (config))
+    return swfmoz_config_read_autoplay (config, "global", autoplay);
+
   host = swfdec_url_get_host (url);
   if (host == NULL)
     host = swfdec_url_get_protocol (url);
 
-  autoplay = swfmoz_config_read_autoplay (config, "global", autoplay);
   autoplay = swfmoz_config_read_autoplay (config, host, autoplay);
 
   return autoplay;
@@ -148,6 +154,29 @@ swfmoz_config_set_autoplay (SwfmozConfig *config, const SwfdecURL *url,
   swfmoz_config_save_file (config);
 }
 
+void
+swfmoz_config_set_global_autoplay (SwfmozConfig *config, gboolean autoplay)
+{
+  g_return_if_fail (SWFMOZ_IS_CONFIG (config));
+
+  g_key_file_set_boolean (config->keyfile, "global", "autoplay", autoplay);
+
+  swfmoz_config_save_file (config);
+}
+
+void
+swfmoz_config_remove_global_autoplay (SwfmozConfig *config)
+{
+  GError *error = NULL;
+  g_return_if_fail (SWFMOZ_IS_CONFIG (config));
+
+  g_key_file_remove_key (config->keyfile, "global", "autoplay", &error);
+  if (error)
+    g_error_free (error);
+
+  swfmoz_config_save_file (config);
+}
+
 static void
 swfmoz_config_dispose (GObject *object)
 {
diff --git a/src/swfmoz_config.h b/src/swfmoz_config.h
index b14c786..37e5b4f 100644
--- a/src/swfmoz_config.h
+++ b/src/swfmoz_config.h
@@ -46,14 +46,20 @@ struct _SwfmozConfigClass
  GObjectClass 	parent;
 };
 
-GType		swfmoz_config_get_type   	(void);
-
-SwfmozConfig *	swfmoz_config_new		(void);
-gboolean 	swfmoz_config_should_autoplay 	(SwfmozConfig *config,
-						 const SwfdecURL *url);
-void		swfmoz_config_set_autoplay 	(SwfmozConfig *config,
-						 const SwfdecURL *url,
-						 gboolean autoplay);
+GType		swfmoz_config_get_type   		(void);
 
+SwfmozConfig *	swfmoz_config_new			(void);
+gboolean	swfmoz_config_read_autoplay		(SwfmozConfig *config,
+							 const char *host,
+							 gboolean autoplay);
+gboolean 	swfmoz_config_should_autoplay 		(SwfmozConfig *config,
+						 	 const SwfdecURL *url);
+void		swfmoz_config_set_autoplay 		(SwfmozConfig *config,
+						 	 const SwfdecURL *url,
+						 	 gboolean autoplay);
+gboolean	swfmoz_config_has_global_key		(SwfmozConfig *config);
+void		swfmoz_config_set_global_autoplay	(SwfmozConfig *config,
+							 gboolean autoplay);
+void		swfmoz_config_remove_global_autoplay	(SwfmozConfig *config);
 G_END_DECLS
 #endif
diff --git a/src/swfmoz_player.c b/src/swfmoz_player.c
index 03746c4..a726bbd 100644
--- a/src/swfmoz_player.c
+++ b/src/swfmoz_player.c
@@ -65,6 +65,31 @@ swfmoz_player_menu_notify_audio (SwfdecGtkPlayer *player, GParamSpec *pspec,
 }
 
 static void
+swfmoz_player_menu_autoplay_always_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  swfmoz_config_set_global_autoplay (player->config, item_active);
+}
+
+static void
+swfmoz_player_menu_autoplay_remember_last_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  if (item_active && swfmoz_config_has_global_key (player->config))
+    swfmoz_config_remove_global_autoplay (player->config);
+}
+
+static void
+swfmoz_player_menu_autoplay_never_toggled (GtkCheckMenuItem *item,
+    SwfmozPlayer* player)
+{
+  gboolean item_active = gtk_check_menu_item_get_active (item);
+  swfmoz_config_set_global_autoplay (player->config, !item_active);
+}
+
+static void
 swfmoz_player_menu_about (GtkMenuItem *item, SwfmozPlayer *player)
 {
   static const char *authors[] = {
@@ -95,7 +120,7 @@ static void
 swfmoz_player_popup_menu (SwfmozPlayer *player)
 {
   if (player->menu == NULL) {
-    GtkWidget *item;
+    GtkWidget *item, *submenu;
 
     player->menu = GTK_MENU (gtk_menu_new ());
     g_object_ref_sink (player->menu);
@@ -120,6 +145,37 @@ swfmoz_player_popup_menu (SwfmozPlayer *player)
     gtk_widget_show (item);
     gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
 
+    submenu = gtk_menu_new();
+    item = gtk_radio_menu_item_new_with_mnemonic (NULL, "Always");
+    g_signal_connect (item, "toggled", 
+        G_CALLBACK (swfmoz_player_menu_autoplay_always_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
+	swfmoz_config_read_autoplay (player->config, "global", FALSE));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_radio_menu_item_new_with_mnemonic_from_widget (GTK_RADIO_MENU_ITEM (item),
+        "Remember last choice");
+    g_signal_connect (item, "toggled", 
+	G_CALLBACK (swfmoz_player_menu_autoplay_remember_last_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
+        !swfmoz_config_has_global_key (player->config));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_radio_menu_item_new_with_mnemonic_from_widget (GTK_RADIO_MENU_ITEM (item), "Never");
+    g_signal_connect (item, "toggled", 
+        G_CALLBACK (swfmoz_player_menu_autoplay_never_toggled), player);
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
+	!swfmoz_config_read_autoplay (player->config, "global", TRUE));
+    gtk_widget_show (item);
+    gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
+
+    item = gtk_menu_item_new_with_label ("Autoplay");
+    gtk_widget_show (item);
+    gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+    gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
+
     item = gtk_separator_menu_item_new ();
     gtk_widget_show (item);
     gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item);
_______________________________________________
Swfdec mailing list
Swfdec@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/swfdec

Reply via email to