diff options
author | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | 2008-08-16 20:24:31 +0300 |
---|---|---|
committer | Pekka Lampila <pekka.lampila@iki.fi> | 2008-08-16 20:24:31 +0300 |
commit | 071dc432d829732f1452c52ab342d50d3a43837d (patch) | |
tree | 61e7c6a54b208007f8584989e8b3fc405c48d7f8 | |
parent | 373931a2f30088951659d3fb011ef9e6a09e9a36 (diff) |
Implement different autoplay policies, add GUI for changing between them
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 overridden 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.
-rw-r--r-- | src/swfmoz_config.c | 53 | ||||
-rw-r--r-- | src/swfmoz_config.h | 23 | ||||
-rw-r--r-- | src/swfmoz_player.c | 66 |
3 files changed, 117 insertions, 25 deletions
diff --git a/src/swfmoz_config.c b/src/swfmoz_config.c index 649b656..10685e3 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; @@ -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..5a02f29 100644 --- a/src/swfmoz_config.h +++ b/src/swfmoz_config.h @@ -46,14 +46,21 @@ 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 05f7fca..b1685af 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,31 +120,62 @@ 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); item = gtk_check_menu_item_new_with_mnemonic ("Playing"); - g_signal_connect (item, "toggled", + g_signal_connect (item, "toggled", G_CALLBACK (swfmoz_player_menu_playing_toggled), player); g_signal_connect (player, "notify::playing", G_CALLBACK (swfmoz_player_menu_notify_playing), item); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), swfdec_gtk_player_get_playing (SWFDEC_GTK_PLAYER (player))); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (player->menu), item); item = gtk_check_menu_item_new_with_mnemonic ("Enable Audio"); - g_signal_connect (item, "toggled", + g_signal_connect (item, "toggled", G_CALLBACK (swfmoz_player_menu_audio_toggled), player); g_signal_connect (player, "notify::audio-enabled", G_CALLBACK (swfmoz_player_menu_notify_audio), item); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), swfdec_gtk_player_get_audio_enabled (SWFDEC_GTK_PLAYER (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); |