[totem/gnome-2-32] Port back to libunique
- From: Frederic Peters <fpeters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/gnome-2-32] Port back to libunique
- Date: Sat, 18 Sep 2010 11:24:17 +0000 (UTC)
commit ce41dd3bb5a1b0df947b3f428928a57957966df9
Author: Frédéric Péters <fpeters 0d be>
Date: Sat Sep 18 12:53:45 2010 +0200
Port back to libunique
This reverts a2c4d4bd, 144abab4 and ae8d468d.
configure.in | 2 +
src/Makefile.am | 5 ++-
src/plugins/publish/Makefile.am | 1 +
src/totem-options.c | 98 +++++++++++++--------------------------
src/totem-options.h | 4 +-
src/totem-private.h | 3 +-
src/totem.c | 99 +++++++++------------------------------
7 files changed, 66 insertions(+), 146 deletions(-)
---
diff --git a/configure.in b/configure.in
index 95c3613..2e4eb7b 100644
--- a/configure.in
+++ b/configure.in
@@ -196,6 +196,8 @@ PKG_CHECK_EXISTS([
$ISO_CODES
gnome-icon-theme >= $GNOMEICON_REQS])
+PKG_CHECK_MODULES([UNIQUE], unique-1.0)
+
dnl *************************
dnl X11 related functionality
dnl *************************
diff --git a/src/Makefile.am b/src/Makefile.am
index 8fb9a62..b9194a8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,7 @@ libtotem_player_la_CPPFLAGS = \
libtotem_player_la_CFLAGS = \
$(DEPENDENCY_CFLAGS) \
$(WARN_CFLAGS) \
+ $(UNIQUE_CFLAGS) \
$(AM_CFLAGS)
libtotem_player_la_LDFLAGS = \
@@ -100,6 +101,7 @@ libtotem_main_la_CFLAGS = \
$(WARN_CFLAGS) \
$(DBUS_CFLAGS) \
$(MISSING_PLUGINS_CFLAGS) \
+ $(UNIQUE_CFLAGS) \
$(AM_CFLAGS)
libtotem_main_la_LDFLAGS = \
@@ -109,7 +111,7 @@ libtotem_main_la_LIBADD = \
libtotem_player.la \
backend/libbaconvideowidget.la \
plugins/libtotemmodule.la \
- $(DEPENDENCY_LIBS) \
+ $(UNIQUE_LIBS) \
$(DBUS_LIBS) \
$(XVIDMODE_LIBS) \
$(XTEST_LIBS) \
@@ -177,6 +179,7 @@ totem_CPPFLAGS = \
$(AM_CPPFLAGS)
totem_CFLAGS = \
+ $(UNIQUE_CFLAGS) \
$(WARN_CFLAGS) \
$(DEPENDENCY_CFLAGS) \
$(AM_CFLAGS)
diff --git a/src/plugins/publish/Makefile.am b/src/plugins/publish/Makefile.am
index 6e3bf2d..83ebfcd 100644
--- a/src/plugins/publish/Makefile.am
+++ b/src/plugins/publish/Makefile.am
@@ -34,6 +34,7 @@ libpublish_la_CFLAGS = \
$(WARN_CFLAGS) \
$(DBUS_CFLAGS) \
$(LIBEPC_CFLAGS) \
+ $(UNIQUE_CFLAGS) \
$(AM_CFLAGS) \
-I$(top_srcdir)/ \
-I$(top_srcdir)/lib \
diff --git a/src/totem-options.c b/src/totem-options.c
index 88ceb2f..5441f5f 100644
--- a/src/totem-options.c
+++ b/src/totem-options.c
@@ -22,7 +22,6 @@
#include "config.h"
-#include <glib.h>
#include <glib/gi18n.h>
#include <string.h>
#include <stdlib.h>
@@ -92,8 +91,9 @@ totem_options_register_remote_commands (Totem *totem)
klass = (GEnumClass *) g_type_class_ref (TOTEM_TYPE_REMOTE_COMMAND);
for (i = TOTEM_REMOTE_COMMAND_UNKNOWN + 1; i < klass->n_values; i++) {
- GEnumValue *val = g_enum_get_value (klass, i);
- g_application_add_action (G_APPLICATION (totem->app), val->value_name, val->value_nick);
+ GEnumValue *val;
+ val = g_enum_get_value (klass, i);
+ unique_app_add_command (totem->app, val->value_name, i);
}
g_type_class_unref (klass);
}
@@ -111,41 +111,19 @@ totem_options_process_early (Totem *totem, const TotemCmdLineOptions* options)
options->debug, NULL);
}
-static char *
-totem_get_action_for_command (const TotemRemoteCommand command)
-{
- GEnumClass *klass;
- char *name;
-
- klass = g_type_class_ref (TOTEM_TYPE_REMOTE_COMMAND);
- name = g_strdup (g_enum_get_value (klass, command)->value_name);
- g_type_class_unref (klass);
-
- return name;
-}
-
-#define UPDATE_ACTION(action, command) \
- do { \
- g_free ((action)); \
- (action) = totem_get_action_for_command ((command)); \
- } while (0)
-
void
-totem_options_process_for_server (GApplication *app,
+totem_options_process_for_server (UniqueApp *app,
const TotemCmdLineOptions* options)
{
- gchar *action = NULL;
GList *commands, *l;
- int i;
+ int default_action, i;
commands = NULL;
- UPDATE_ACTION (action, TOTEM_REMOTE_COMMAND_REPLACE);
+ default_action = TOTEM_REMOTE_COMMAND_REPLACE;
/* Are we quitting ? */
if (options->quit) {
- g_application_invoke_action (G_APPLICATION (app),
- totem_get_action_for_command (TOTEM_REMOTE_COMMAND_QUIT),
- NULL);
+ unique_app_send_message (app, TOTEM_REMOTE_COMMAND_QUIT, NULL);
return;
}
@@ -154,113 +132,101 @@ totem_options_process_for_server (GApplication *app,
/* FIXME translate that */
g_warning ("Can't enqueue and replace at the same time");
} else if (options->replace) {
- UPDATE_ACTION (action, TOTEM_REMOTE_COMMAND_REPLACE);
+ default_action = TOTEM_REMOTE_COMMAND_REPLACE;
} else if (options->enqueue) {
- UPDATE_ACTION (action, TOTEM_REMOTE_COMMAND_ENQUEUE);
+ default_action = TOTEM_REMOTE_COMMAND_ENQUEUE;
}
/* Send the files to enqueue */
for (i = 0; options->filenames && options->filenames[i] != NULL; i++) {
- GVariant *data;
+ UniqueMessageData *data;
char *full_path;
- GVariantBuilder builder;
+ data = unique_message_data_new ();
+ full_path = totem_create_full_path (options->filenames[i]);
+ unique_message_data_set_text (data, full_path ? full_path : options->filenames[i], -1);
full_path = totem_create_full_path (options->filenames[i]);
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_add (&builder, "{sv}",
- "url", g_variant_new_string (full_path ? full_path : options->filenames[i]));
- data = g_variant_builder_end (&builder);
-
- g_application_invoke_action (G_APPLICATION (app), action, data);
-
- g_free (full_path);
- g_variant_unref (data);
+ unique_app_send_message (app, default_action, data);
/* Even if the default action is replace, we only want to replace with the
first file. After that, we enqueue. */
- if (i == 0) {
- UPDATE_ACTION (action, TOTEM_REMOTE_COMMAND_ENQUEUE);
- }
+ default_action = TOTEM_REMOTE_COMMAND_ENQUEUE;
+ unique_message_data_free (data);
+ g_free (full_path);
}
if (options->playpause) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_PLAYPAUSE));
}
if (options->play) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_PLAY));
}
if (options->pause) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_PAUSE));
}
if (options->next) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_NEXT));
}
if (options->previous) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_PREVIOUS));
}
if (options->seekfwd) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_SEEK_FORWARD));
}
if (options->seekbwd) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_SEEK_BACKWARD));
}
if (options->volumeup) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_VOLUME_UP));
}
if (options->volumedown) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_VOLUME_DOWN));
}
if (options->mute) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_MUTE));
}
if (options->fullscreen) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_FULLSCREEN));
}
if (options->togglecontrols) {
- commands = g_list_append (commands, totem_get_action_for_command
+ commands = g_list_append (commands, GINT_TO_POINTER
(TOTEM_REMOTE_COMMAND_TOGGLE_CONTROLS));
}
/* No commands, no files, show ourselves */
if (commands == NULL && options->filenames == NULL) {
- g_application_invoke_action (G_APPLICATION (app),
- totem_get_action_for_command (TOTEM_REMOTE_COMMAND_SHOW),
- NULL);
+ unique_app_send_message (app, TOTEM_REMOTE_COMMAND_SHOW, NULL);
return;
}
/* Send commands */
for (l = commands; l != NULL; l = l->next) {
- g_application_invoke_action (G_APPLICATION (app), l->data, NULL);
+ int command = GPOINTER_TO_INT (l->data);
+ unique_app_send_message (app, command, NULL);
}
-
- g_free (action);
- g_list_foreach (commands, (GFunc) g_free, NULL);
g_list_free (commands);
}
-#undef UPDATE_ACTION
-
diff --git a/src/totem-options.h b/src/totem-options.h
index d178134..185eec9 100644
--- a/src/totem-options.h
+++ b/src/totem-options.h
@@ -24,7 +24,7 @@
#define TOTEM_OPTIONS_H
#include <gconf/gconf-client.h>
-#include <gtk/gtk.h>
+#include <unique/uniqueapp.h>
#include "totem.h"
@@ -62,7 +62,7 @@ void totem_options_process_early (Totem *totem,
const TotemCmdLineOptions* options);
void totem_options_process_late (Totem *totem,
const TotemCmdLineOptions* options);
-void totem_options_process_for_server (GApplication *app,
+void totem_options_process_for_server (UniqueApp *app,
const TotemCmdLineOptions* options);
G_END_DECLS
diff --git a/src/totem-private.h b/src/totem-private.h
index 7b70d07..9d5b89c 100644
--- a/src/totem-private.h
+++ b/src/totem-private.h
@@ -31,6 +31,7 @@
#include <gconf/gconf-client.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
+#include <unique/uniqueapp.h>
#include "totem-playlist.h"
#include "bacon-video-widget.h"
@@ -157,7 +158,7 @@ struct _TotemObject {
gint64 seek_to;
TotemPlaylist *playlist;
GConfClient *gc;
- GApplication *app;
+ UniqueApp *app;
TotemStates state;
TotemOpenLocation *open_location;
gboolean remember_position;
diff --git a/src/totem.c b/src/totem.c
index 956ebc8..1a9a6e4 100644
--- a/src/totem.c
+++ b/src/totem.c
@@ -28,7 +28,6 @@
#include "config.h"
-#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -58,45 +57,25 @@ long_action (void)
gtk_main_iteration ();
}
-static void
-totem_action_handler (GApplication *app,
- gchar *name,
- GVariant *platform_data,
- gpointer user_data)
+static UniqueResponse
+totem_message_received_cb (UniqueApp *app,
+ int command,
+ UniqueMessageData *message_data,
+ guint time_,
+ Totem *totem)
{
- GEnumClass *klass;
- GEnumValue *enum_value;
- char *url = NULL;
- TotemRemoteCommand command;
-
- /* GApplication requires the platform_data to be of type a{sv}. */
- if (platform_data) {
- GVariantIter iter;
- GVariant *value;
- const char *key;
-
- g_variant_iter_init (&iter, platform_data);
- while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) {
- if (g_strcmp0 (key, "url") == 0) {
- url = g_variant_dup_string (value, NULL);
- g_variant_unref (value);
- break;
- }
- g_variant_unref (value);
- }
- }
-
- klass = g_type_class_ref (TOTEM_TYPE_REMOTE_COMMAND);
+ char *url;
- enum_value = g_enum_get_value_by_name (klass, name);
- if (!enum_value)
- return;
- command = enum_value->value;
+ if (message_data != NULL)
+ url = unique_message_data_get_text (message_data);
+ else
+ url = NULL;
- g_type_class_unref (klass);
+ totem_action_remote (totem, command, url);
- totem_action_remote (TOTEM_OBJECT (user_data), command, url);
g_free (url);
+
+ return UNIQUE_RESPONSE_OK;
}
static void
@@ -151,26 +130,6 @@ debug_handler (const char *log_domain,
g_log_default_handler (log_domain, log_level, message, NULL);
}
-static GVariant *
-variant_from_argv (int argc,
- char **argv)
-{
- GVariantBuilder builder;
- int i;
-
- g_variant_builder_init (&builder, G_VARIANT_TYPE("aay"));
-
- for (i = 1; i < argc; i++) {
- guint8 *argv_bytes;
-
- argv_bytes = (guint8 *) argv[i];
- g_variant_builder_add_value (&builder,
- g_variant_new_bytestring_array (argv_bytes, -1));
- }
-
- return g_variant_builder_end (&builder);
-}
-
int
main (int argc, char **argv)
{
@@ -222,9 +181,9 @@ main (int argc, char **argv)
gtk_about_dialog_set_email_hook (about_email_hook, NULL, NULL);
gc = gconf_client_get_default ();
- if (gc == NULL) {
- totem_action_error_and_exit (_("Totem could not initialize the configuration engine."),
- _("Make sure that GNOME is properly installed."), NULL);
+ if (gc == NULL)
+ {
+ totem_action_error_and_exit (_("Totem could not initialize the configuration engine."), _("Make sure that GNOME is properly installed."), NULL);
}
/* Debug log handling */
@@ -236,23 +195,13 @@ main (int argc, char **argv)
/* IPC stuff */
if (optionstate.notconnectexistingsession == FALSE) {
- GError *error = NULL;
-
- /* FIXME should be GtkApplication */
- totem->app = g_initable_new (G_TYPE_APPLICATION,
- NULL,
- &error,
- "application-id", "org.gnome.Totem",
- "argv", variant_from_argv (argc, argv),
- "default-quit", FALSE,
- NULL);
-
- if (g_application_is_remote (G_APPLICATION (totem->app))) {
- totem_options_process_for_server (G_APPLICATION (totem->app), &optionstate);
+ totem->app = unique_app_new ("org.gnome.Totem", NULL);
+ totem_options_register_remote_commands (totem);
+ if (unique_app_is_running (totem->app) != FALSE) {
+ totem_options_process_for_server (totem->app, &optionstate);
gdk_notify_startup_complete ();
totem_action_exit (totem);
} else {
- totem_options_register_remote_commands (totem);
totem_options_process_early (totem, &optionstate);
}
} else {
@@ -265,8 +214,6 @@ main (int argc, char **argv)
totem_action_exit (NULL);
totem->win = GTK_WIDGET (gtk_builder_get_object (totem->xml, "totem_main_window"));
- /* FIXME should be enabled
- gtk_application_add_window (totem->app, GTK_WINDOW (totem->win)); */
/* Menubar */
totem_ui_manager_setup (totem);
@@ -345,8 +292,8 @@ main (int argc, char **argv)
gdk_window_set_cursor (gtk_widget_get_window (totem->win), NULL);
if (totem->app != NULL) {
- g_signal_connect (G_APPLICATION (totem->app), "action-with-data",
- G_CALLBACK (totem_action_handler), totem);
+ g_signal_connect (totem->app, "message-received",
+ G_CALLBACK (totem_message_received_cb), totem);
}
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]