Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2008-09-04 11:32:12 (GMT)
committer Carlos Garcia Campos <carlosgc@src.gnome.org>2008-09-04 11:32:12 (GMT)
commite01d6f5fd8c8682948d87cbfe3456a424652ad71 (patch)
tree073fd98fd4fbe243f55662f3aca82ef1a64733d9 /shell
parenteb120a34995e8be1b37e86f4eae2bdd3a8878146 (diff)
Clean up the media player keys stuff.
2008-09-04 Carlos Garcia Campos <carlosgc@gnome.org> * shell/ev-application.c: (ev_application_get_media_keys): * shell/ev-media-player-keys.[ch]: (ev_media_player_keys_class_init), (on_media_player_key_pressed), (ev_media_player_keys_grab_keys), (ev_media_player_keys_release_keys), (ev_media_player_keys_init), (ev_media_player_keys_focused), (ev_media_player_keys_finalize): * shell/ev-window.[ch]: (ev_window_dispose), (view_actions_focus_in_cb), (ev_window_media_player_key_pressed), (ev_window_init): Clean up the media player keys stuff. svn path=/trunk/; revision=3148
Diffstat (limited to 'shell')
-rw-r--r--shell/ev-application.c15
-rw-r--r--shell/ev-media-player-keys.c157
-rw-r--r--shell/ev-media-player-keys.h9
-rw-r--r--shell/ev-window.c90
-rw-r--r--shell/ev-window.h7
5 files changed, 140 insertions, 138 deletions
diff --git a/shell/ev-application.c b/shell/ev-application.c
index fd43c88..e852561 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -722,6 +722,13 @@ ev_application_shutdown (EvApplication *application)
application->print_settings = NULL;
}
#endif /* GTK 2.11.0 */
+
+#ifdef ENABLE_DBUS
+ if (application->keys) {
+ g_object_unref (application->keys);
+ application->keys = NULL;
+ }
+#endif /* ENABLE_DBUS */
g_free (application->last_chooser_uri);
g_object_unref (application);
@@ -825,13 +832,11 @@ ev_application_get_windows (EvApplication *application)
*
* Returns: A #EvMediaPlayerKeys.
*/
-GObject
-*ev_application_get_media_keys (EvApplication *application)
+GObject *
+ev_application_get_media_keys (EvApplication *application)
{
#ifdef ENABLE_DBUS
- if (!application->keys)
- return NULL;
- return g_object_ref (G_OBJECT (application->keys));
+ return G_OBJECT (application->keys);
#else
return NULL;
#endif /* ENABLE_DBUS */
diff --git a/shell/ev-media-player-keys.c b/shell/ev-media-player-keys.c
index c244b2e..04d858f 100644
--- a/shell/ev-media-player-keys.c
+++ b/shell/ev-media-player-keys.c
@@ -22,9 +22,6 @@
#include "config.h"
#include <glib.h>
-#include <glib-object.h>
-#include <glib/gi18n-lib.h>
-#include <gmodule.h>
#include <dbus/dbus-glib.h>
#include <string.h>
@@ -32,62 +29,79 @@
#include "ev-marshal.h"
+enum {
+ KEY_PRESSED,
+ LAST_SIGNAL
+};
+
struct _EvMediaPlayerKeys
{
GObject parent;
- DBusGProxy *media_player_keys_proxy;
- EvWindow *window;
+
+ DBusGProxy *proxy;
};
struct _EvMediaPlayerKeysClass
{
GObjectClass parent_class;
+
+ /* Signals */
+ void (* key_pressed) (EvMediaPlayerKeys *keys,
+ const gchar *key);
};
+static guint signals[LAST_SIGNAL] = { 0 };
+
G_DEFINE_TYPE (EvMediaPlayerKeys, ev_media_player_keys, G_TYPE_OBJECT)
-static void ev_media_player_keys_init (EvMediaPlayerKeys *keys);
-static void ev_media_player_keys_finalize (GObject *object);
+static void ev_media_player_keys_finalize (GObject *object);
static void
ev_media_player_keys_class_init (EvMediaPlayerKeysClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ signals[KEY_PRESSED] =
+ g_signal_new ("key_pressed",
+ EV_TYPE_MEDIA_PLAYER_KEYS,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvMediaPlayerKeysClass, key_pressed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
object_class->finalize = ev_media_player_keys_finalize;
}
static void
-proxy_destroy (DBusGProxy *proxy,
- EvMediaPlayerKeys* keys)
+on_media_player_key_pressed (DBusGProxy *proxy,
+ const gchar *application,
+ const gchar *key,
+ EvMediaPlayerKeys *keys)
{
- keys->media_player_keys_proxy = NULL;
+ if (strcmp ("Evince", application) == 0) {
+ g_signal_emit (keys, signals[KEY_PRESSED], 0, key);
+ }
}
static void
-on_media_player_key_pressed (DBusGProxy *proxy, const gchar *application, const gchar *key, EvMediaPlayerKeys *keys)
+ev_media_player_keys_grab_keys (EvMediaPlayerKeys *keys)
{
- if (strcmp ("Evince", application) == 0 && keys->window != NULL) {
- /* Note how Previous/Next only go to the
- * next/previous page despite their icon telling you
- * they should go to the beginning/end.
- *
- * There's very few keyboards with FFW/RWD though,
- * so we stick the most useful keybinding on the most
- * often seen keys
- */
- if (strcmp ("Play", key) == 0) {
- ev_window_start_presentation (keys->window);
- } else if (strcmp ("Previous", key) == 0) {
- ev_window_go_previous_page (keys->window);
- } else if (strcmp ("Next", key) == 0) {
- ev_window_go_next_page (keys->window);
- } else if (strcmp ("FastForward", key) == 0) {
- ev_window_go_last_page (keys->window);
- } else if (strcmp ("Rewind", key) == 0) {
- ev_window_go_first_page (keys->window);
- }
- }
+ dbus_g_proxy_call (keys->proxy,
+ "GrabMediaPlayerKeys", NULL,
+ G_TYPE_STRING, "Evince",
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+static void
+ev_media_player_keys_release_keys (EvMediaPlayerKeys *keys)
+{
+ dbus_g_proxy_call (keys->proxy,
+ "ReleaseMediaPlayerKeys", NULL,
+ G_TYPE_STRING, "Evince",
+ G_TYPE_INVALID, G_TYPE_INVALID);
}
static void
@@ -104,17 +118,17 @@ ev_media_player_keys_init (EvMediaPlayerKeys *keys)
/* Try the gnome-settings-daemon version,
* then the gnome-control-center version of things */
- keys->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
- "org.gnome.SettingsDaemon",
- "/org/gnome/SettingsDaemon/MediaKeys",
- "org.gnome.SettingsDaemon.MediaKeys",
- NULL);
- if (keys->media_player_keys_proxy == NULL) {
- keys->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
- "org.gnome.SettingsDaemon",
- "/org/gnome/SettingsDaemon",
- "org.gnome.SettingsDaemon",
- &err);
+ keys->proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.gnome.SettingsDaemon",
+ "/org/gnome/SettingsDaemon/MediaKeys",
+ "org.gnome.SettingsDaemon.MediaKeys",
+ NULL);
+ if (keys->proxy == NULL) {
+ keys->proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.gnome.SettingsDaemon",
+ "/org/gnome/SettingsDaemon",
+ "org.gnome.SettingsDaemon",
+ &err);
}
dbus_g_connection_unref (connection);
@@ -122,44 +136,36 @@ ev_media_player_keys_init (EvMediaPlayerKeys *keys)
g_warning ("Failed to create dbus proxy for org.gnome.SettingsDaemon: %s",
err->message);
g_error_free (err);
+
+ if (keys->proxy) {
+ g_object_unref (keys->proxy);
+ keys->proxy = NULL;
+ }
+
return;
- } else {
- g_signal_connect_object (keys->media_player_keys_proxy,
- "destroy",
- G_CALLBACK (proxy_destroy),
- keys, 0);
}
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "GrabMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Evince", G_TYPE_UINT, 0, G_TYPE_INVALID,
- G_TYPE_INVALID);
+ g_object_add_weak_pointer (G_OBJECT (keys->proxy),
+ (gpointer) &(keys->proxy));
+
+ ev_media_player_keys_grab_keys (keys);
dbus_g_object_register_marshaller (ev_marshal_VOID__STRING_STRING,
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_add_signal (keys->media_player_keys_proxy, "MediaPlayerKeyPressed",
+ dbus_g_proxy_add_signal (keys->proxy, "MediaPlayerKeyPressed",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (keys->media_player_keys_proxy, "MediaPlayerKeyPressed",
+ dbus_g_proxy_connect_signal (keys->proxy, "MediaPlayerKeyPressed",
G_CALLBACK (on_media_player_key_pressed), keys, NULL);
}
void
-ev_media_player_keys_focused (EvMediaPlayerKeys *keys, EvWindow *window)
+ev_media_player_keys_focused (EvMediaPlayerKeys *keys)
{
- if (keys->media_player_keys_proxy != NULL) {
- if (keys->window != NULL) {
- g_object_unref (keys->window);
- keys->window = NULL;
- }
- if (window != NULL) {
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "GrabMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Evince", G_TYPE_UINT, 0, G_TYPE_INVALID,
- G_TYPE_INVALID);
- keys->window = g_object_ref (window);
- }
- }
+ if (!keys->proxy)
+ return;
+
+ ev_media_player_keys_grab_keys (keys);
}
static void
@@ -167,17 +173,10 @@ ev_media_player_keys_finalize (GObject *object)
{
EvMediaPlayerKeys *keys = EV_MEDIA_PLAYER_KEYS (object);
- if (keys->media_player_keys_proxy != NULL) {
- dbus_g_proxy_call (keys->media_player_keys_proxy,
- "ReleaseMediaPlayerKeys", NULL,
- G_TYPE_STRING, "Ev", G_TYPE_INVALID, G_TYPE_INVALID);
- g_object_unref (keys->media_player_keys_proxy);
- keys->media_player_keys_proxy = NULL;
- }
-
- if (keys->window != NULL) {
- g_object_unref (keys->window);
- keys->window = NULL;
+ if (keys->proxy) {
+ ev_media_player_keys_release_keys (keys);
+ g_object_unref (keys->proxy);
+ keys->proxy = NULL;
}
G_OBJECT_CLASS (ev_media_player_keys_parent_class)->finalize (object);
diff --git a/shell/ev-media-player-keys.h b/shell/ev-media-player-keys.h
index 135aa81..d23c188 100644
--- a/shell/ev-media-player-keys.h
+++ b/shell/ev-media-player-keys.h
@@ -22,7 +22,7 @@
#ifndef EV_MEDIA_PLAYER_KEYS_H
#define EV_MEDIA_PLAYER_KEYS_H
-#include "ev-window.h"
+#include <glib-object.h>
G_BEGIN_DECLS
@@ -37,12 +37,11 @@ typedef struct _EvMediaPlayerKeys EvMediaPlayerKeys;
typedef struct _EvMediaPlayerKeysClass EvMediaPlayerKeysClass;
-GType ev_media_player_keys_get_type (void) G_GNUC_CONST;
+GType ev_media_player_keys_get_type (void) G_GNUC_CONST;
-EvMediaPlayerKeys * ev_media_player_keys_new (void);
+EvMediaPlayerKeys *ev_media_player_keys_new (void);
-void ev_media_player_keys_focused (EvMediaPlayerKeys *keys,
- EvWindow *window);
+void ev_media_player_keys_focused (EvMediaPlayerKeys *keys);
G_END_DECLS
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 65f5d46..03f98cb 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -285,6 +285,9 @@ static void find_bar_search_changed_cb (EggFindBar *find_
static void ev_window_do_preview_print (EvWindow *window);
static void ev_window_load_file_remote (EvWindow *ev_window,
GFile *source_file);
+static void ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
@@ -3256,12 +3259,6 @@ ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
ev_view_previous_page (EV_VIEW (ev_window->priv->view));
}
-void
-ev_window_go_previous_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_previous_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
{
@@ -3270,12 +3267,6 @@ ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
ev_view_next_page (EV_VIEW (ev_window->priv->view));
}
-void
-ev_window_go_next_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_next_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
{
@@ -3284,12 +3275,6 @@ ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
ev_page_cache_set_current_page (ev_window->priv->page_cache, 0);
}
-void
-ev_window_go_first_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_first_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
{
@@ -3301,12 +3286,6 @@ ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
ev_page_cache_set_current_page (ev_window->priv->page_cache, n_pages - 1);
}
-void
-ev_window_go_last_page (EvWindow *ev_window)
-{
- ev_window_cmd_go_last_page (NULL, ev_window);
-}
-
static void
ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
{
@@ -3407,12 +3386,6 @@ ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
ev_window_run_presentation (window);
}
-void
-ev_window_start_presentation (EvWindow *ev_window)
-{
- ev_window_run_presentation (ev_window);
-}
-
static gboolean
ev_window_enumerate_printer_cb (GtkPrinter *printer,
EvWindow *window)
@@ -4220,16 +4193,14 @@ ev_window_dispose (GObject *object)
{
EvWindow *window = EV_WINDOW (object);
EvWindowPrivate *priv = window->priv;
-#ifdef ENABLE_DBUS
- GObject *keys;
+ GObject *mpkeys = ev_application_get_media_keys (EV_APP);
- keys = ev_application_get_media_keys (EV_APP);
- if (keys) {
- ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys), NULL);
- g_object_unref (keys);
+ if (mpkeys) {
+ g_signal_handlers_disconnect_by_func (mpkeys,
+ ev_window_media_player_key_pressed,
+ window);
}
-#endif /* ENABLE_DBUS */
-
+
if (priv->setup_document_idle > 0) {
g_source_remove (priv->setup_document_idle);
priv->setup_document_idle = 0;
@@ -4766,10 +4737,7 @@ view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *win
GObject *keys;
keys = ev_application_get_media_keys (EV_APP);
- if (keys) {
- ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys), window);
- g_object_unref (keys);
- }
+ ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
#endif /* ENABLE_DBUS */
update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
@@ -5338,12 +5306,42 @@ ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
}
static void
+ev_window_media_player_key_pressed (EvWindow *window,
+ const gchar *key,
+ gpointer user_data)
+{
+ if (!gtk_window_is_active (GTK_WINDOW (window)))
+ return;
+
+ /* Note how Previous/Next only go to the
+ * next/previous page despite their icon telling you
+ * they should go to the beginning/end.
+ *
+ * There's very few keyboards with FFW/RWD though,
+ * so we stick the most useful keybinding on the most
+ * often seen keys
+ */
+ if (strcmp (key, "Play") == 0) {
+ ev_window_run_presentation (window);
+ } else if (strcmp (key, "Previous") == 0) {
+ ev_window_cmd_go_previous_page (NULL, window);
+ } else if (strcmp (key, "Next") == 0) {
+ ev_window_cmd_go_next_page (NULL, window);
+ } else if (strcmp (key, "FastForward") == 0) {
+ ev_window_cmd_go_last_page (NULL, window);
+ } else if (strcmp (key, "Rewind") == 0) {
+ ev_window_cmd_go_first_page (NULL, window);
+ }
+}
+
+static void
ev_window_init (EvWindow *ev_window)
{
GtkActionGroup *action_group;
GtkAccelGroup *accel_group;
GError *error = NULL;
GtkWidget *sidebar_widget;
+ GObject *mpkeys;
g_signal_connect (ev_window, "configure_event",
G_CALLBACK (window_configure_event_cb), NULL);
@@ -5624,6 +5622,14 @@ ev_window_init (EvWindow *ev_window)
"/AttachmentPopup");
ev_window->priv->attach_list = NULL;
+ /* Media player keys */
+ mpkeys = ev_application_get_media_keys (EV_APP);
+ if (mpkeys) {
+ g_signal_connect_swapped (mpkeys, "key_pressed",
+ G_CALLBACK (ev_window_media_player_key_pressed),
+ ev_window);
+ }
+
/* Give focus to the document view */
gtk_widget_grab_focus (ev_window->priv->view);
diff --git a/shell/ev-window.h b/shell/ev-window.h
index 2957c44..5ed7dd7 100644
--- a/shell/ev-window.h
+++ b/shell/ev-window.h
@@ -85,13 +85,6 @@ void ev_window_print_range (EvWindow *ev_window,
int first_page,
int last_page);
-void ev_window_go_last_page (EvWindow *ev_window);
-void ev_window_go_first_page (EvWindow *ev_window);
-void ev_window_go_next_page (EvWindow *ev_window);
-void ev_window_go_previous_page(EvWindow *ev_window);
-void ev_window_start_presentation
- (EvWindow *ev_window);
-
G_END_DECLS
#endif /* !EV_WINDOW_H */