summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2007-10-21 18:41:33 +0200
committerBenjamin Otte <otte@gnome.org>2007-10-21 18:41:33 +0200
commitc5264978a0b42c446df2b89942b465990ac7d1d2 (patch)
tree29b954a5b381ba07ccb8710ed1ea64a297264638
parent6df59db6a88d7ea85d674a1c67466fe52b45dcbe (diff)
add SwfdecWindowSettings to hold all the settings for a window
I"m using a separate struct, so I can easily move the settings separate from the window, which may be interesting when passing it to gconf, creating new windows, etc
-rw-r--r--player/swfdec-player.ui12
-rw-r--r--player/swfdec-window-handlers.c15
-rw-r--r--player/swfdec-window.c30
-rw-r--r--player/swfdec-window.h20
4 files changed, 68 insertions, 9 deletions
diff --git a/player/swfdec-player.ui b/player/swfdec-player.ui
index 82f5cab..1413ecb 100644
--- a/player/swfdec-player.ui
+++ b/player/swfdec-player.ui
@@ -21,15 +21,23 @@
<accelerator key="O" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
- <object class="GtkAction" id="play">
+ <object class="GtkToggleAction" id="play">
<property name="label">Play / P_ause</property>
<property name="stock-id">gtk-media-play</property>
<property name="tooltip">Play or pause the file</property>
- <signal name="activate" handler="menu_file_play"/>
+ <signal name="toggled" handler="menu_file_play"/>
</object>
<accelerator key="space" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
+ <object class="GtkToggleAction" id="mute">
+ <property name="label">Mute</property>
+ <property name="tooltip">Mute sound output</property>
+ <signal name="toggled" handler="menu_file_mute"/>
+ </object>
+ <accelerator key="M" modifiers="GDK_CONTROL_MASK"/>
+ </child>
+ <child>
<object class="GtkAction" id="quit">
<property name="label">_Close</property>
<property name="stock-id">gtk-close</property>
diff --git a/player/swfdec-window-handlers.c b/player/swfdec-window-handlers.c
index 5ca190d..0aabff0 100644
--- a/player/swfdec-window-handlers.c
+++ b/player/swfdec-window-handlers.c
@@ -29,8 +29,21 @@ menu_file_open (GtkAction *action, SwfdecWindow *window)
}
void
-menu_file_play (GtkAction *action, SwfdecWindow *window)
+menu_file_play (GtkToggleAction *action, SwfdecWindow *window)
{
+ if (window->player) {
+ swfdec_gtk_player_set_playing (SWFDEC_GTK_PLAYER (window->player),
+ gtk_toggle_action_get_active (action));
+ }
+}
+
+void
+menu_file_mute (GtkToggleAction *action, SwfdecWindow *window)
+{
+ if (window->player) {
+ swfdec_gtk_player_set_audio_enabled (SWFDEC_GTK_PLAYER (window->player),
+ !gtk_toggle_action_get_active (action));
+ }
}
void
diff --git a/player/swfdec-window.c b/player/swfdec-window.c
index 58f4304..45860ab 100644
--- a/player/swfdec-window.c
+++ b/player/swfdec-window.c
@@ -28,6 +28,8 @@ G_DEFINE_TYPE (SwfdecWindow, swfdec_window, G_TYPE_OBJECT)
/* global list of windows */
static GSList *windows = NULL;
+/* the default settings */
+static const SwfdecWindowSettings default_settings = { FALSE, TRUE };
static void
swfdec_window_dispose (GObject *object)
@@ -68,6 +70,8 @@ swfdec_window_class_init (SwfdecWindowClass *klass)
static void
swfdec_window_init (SwfdecWindow *window)
{
+ window->settings = default_settings;
+
windows = g_slist_prepend (windows, window);
}
@@ -84,6 +88,7 @@ swfdec_window_init (SwfdecWindow *window)
gboolean
swfdec_window_set_url (SwfdecWindow *window, const char *url)
{
+ SwfdecWindowSettings settings;
GObject *o;
g_return_val_if_fail (SWFDEC_IS_WINDOW (window), FALSE);
@@ -95,9 +100,12 @@ swfdec_window_set_url (SwfdecWindow *window, const char *url)
window->loader = swfdec_gtk_loader_new (url);
window->player = swfdec_gtk_player_new (NULL);
swfdec_player_set_loader (window->player, window->loader);
- swfdec_gtk_player_set_playing (SWFDEC_GTK_PLAYER (window->player), TRUE);
o = gtk_builder_get_object (window->builder, "player-widget");
swfdec_gtk_widget_set_player (SWFDEC_GTK_WIDGET (o), window->player);
+ /* cute little hack to apply the settings without lots of code */
+ settings = window->settings;
+ window->settings = default_settings;
+ swfdec_window_set_settings (window, &settings);
return TRUE;
}
@@ -160,3 +168,23 @@ swfdec_window_new (const char *url)
return window;
}
+void
+swfdec_window_set_settings (SwfdecWindow *window, const SwfdecWindowSettings *settings)
+{
+ SwfdecWindowSettings *org;
+
+ g_return_if_fail (SWFDEC_IS_WINDOW (window));
+ g_return_if_fail (settings != NULL);
+
+ if (window->settings.playing != settings->playing) {
+ GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_builder_get_object (window->builder, "play"));
+ gtk_toggle_action_set_active (action, settings->playing);
+ g_assert (window->settings.playing == settings->playing);
+ }
+ if (window->settings.sound != settings->sound) {
+ GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_builder_get_object (window->builder, "mute"));
+ gtk_toggle_action_set_active (action, !settings->sound);
+ g_assert (window->settings.sound == settings->sound);
+ }
+}
+
diff --git a/player/swfdec-window.h b/player/swfdec-window.h
index 65ca20a..daa13ab 100644
--- a/player/swfdec-window.h
+++ b/player/swfdec-window.h
@@ -26,6 +26,7 @@
typedef struct _SwfdecWindow SwfdecWindow;
+typedef struct _SwfdecWindowSettings SwfdecWindowSettings;
typedef struct _SwfdecWindowClass SwfdecWindowClass;
#define SWFDEC_TYPE_WINDOW (swfdec_window_get_type())
@@ -35,6 +36,12 @@ typedef struct _SwfdecWindowClass SwfdecWindowClass;
#define SWFDEC_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_WINDOW, SwfdecWindowClass))
#define SWFDEC_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_WINDOW, SwfdecWindowClass))
+struct _SwfdecWindowSettings
+{
+ gboolean playing; /* TRUE if this window should be playing automagically */
+ gboolean sound; /* TRUE if sund is active */
+};
+
struct _SwfdecWindow
{
GObject object;
@@ -44,6 +51,7 @@ struct _SwfdecWindow
GtkWidget * window; /* the toplevel window */
SwfdecPlayer * player; /* the player we show or NULL if not initialized yet */
SwfdecLoader * loader; /* the loader we use to load the content or NULL if not initialized yet */
+ SwfdecWindowSettings settings; /* the settings that apply to this window */
};
struct _SwfdecWindowClass
@@ -51,12 +59,14 @@ struct _SwfdecWindowClass
GObjectClass object_class;
};
-SwfdecWindow * swfdec_window_new (const char * url);
+SwfdecWindow * swfdec_window_new (const char * url);
-gboolean swfdec_window_set_url (SwfdecWindow * window,
- const char * url);
-void swfdec_window_error (SwfdecWindow * window,
- const char * msg);
+gboolean swfdec_window_set_url (SwfdecWindow * window,
+ const char * url);
+void swfdec_window_error (SwfdecWindow * window,
+ const char * msg);
+void swfdec_window_set_settings (SwfdecWindow * window,
+ const SwfdecWindowSettings * settings);
G_END_DECLS