2 * Copyright © 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Authors: Ryan Lortie <desrt@desrt.ca>
22 #include "gapplicationimpl.h"
24 #include "gactiongroup.h"
25 #include "gapplication.h"
27 #include "gdbusconnection.h"
28 #include "gdbusintrospection.h"
29 #include "gdbuserror.h"
34 #include "gapplicationcommandline.h"
35 #include "gdbusmethodinvocation.h"
37 /* DBus Interface definition {{{1 */
38 static const GDBusArgInfo platform_data_arg = { -1, (gchar *) "platform_data", (gchar *) "a{sv}" };
40 static const GDBusArgInfo open_uris_arg = { -1, (gchar *) "uris", (gchar *) "as" };
41 static const GDBusArgInfo open_hint_arg = { -1, (gchar *) "hint", (gchar *) "s" };
43 static const GDBusArgInfo invoke_action_name_arg = { -1, (gchar *) "name", (gchar *) "s" };
44 static const GDBusArgInfo invoke_action_args_arg = { -1, (gchar *) "args", (gchar *) "v" };
46 static const GDBusArgInfo cmdline_path_arg = { -1, (gchar *) "path", (gchar *) "o" };
47 static const GDBusArgInfo cmdline_arguments_arg = { -1, (gchar *) "arguments", (gchar *) "aay" };
48 static const GDBusArgInfo cmdline_exit_status_arg = { -1, (gchar *) "exit_status", (gchar *) "i" };
50 static const GDBusArgInfo *activate_in[] = { &platform_data_arg, NULL };
51 static const GDBusArgInfo *activate_out[] = { NULL };
53 static const GDBusArgInfo *open_in[] = { &open_uris_arg, &open_hint_arg, &platform_data_arg, NULL };
54 static const GDBusArgInfo *open_out[] = { NULL };
56 static const GDBusArgInfo *cmdline_in[] = { &cmdline_path_arg, &cmdline_arguments_arg, &platform_data_arg, NULL };
57 static const GDBusArgInfo *cmdline_out[] = { &cmdline_exit_status_arg, NULL };
59 static const GDBusMethodInfo activate_method = {
60 -1, (gchar *) "Activate",
61 (GDBusArgInfo **) activate_in,
62 (GDBusArgInfo **) activate_out
65 static const GDBusMethodInfo open_method = {
67 (GDBusArgInfo **) open_in,
68 (GDBusArgInfo **) open_out
71 static const GDBusMethodInfo command_line_method = {
72 -1, (gchar *) "CommandLine",
73 (GDBusArgInfo **) cmdline_in,
74 (GDBusArgInfo **) cmdline_out
77 static const GDBusMethodInfo *application_methods[] = {
78 &activate_method, &open_method, &command_line_method, NULL
81 const GDBusInterfaceInfo org_gtk_Application = {
82 -1, (gchar *) "org.gtk.Application",
83 (GDBusMethodInfo **) application_methods
86 static const GDBusArgInfo list_arg = { -1, (gchar *) "list", (gchar *) "a(savbav)" };
87 static const GDBusArgInfo *describe_all_out[] = { &list_arg, NULL };
89 static const GDBusArgInfo action_name_arg = { -1, (gchar *) "action_name", (gchar *) "s" };
90 static const GDBusArgInfo value_arg = { -1, (gchar *) "value", (gchar *) "v" };
91 static const GDBusArgInfo *set_action_state_in[] = { &action_name_arg, &value_arg, &platform_data_arg, NULL };
93 static const GDBusArgInfo parameter_arg = { -1, (gchar *) "parameter", (gchar *) "av" };
94 static const GDBusArgInfo *activate_action_in[] = { &action_name_arg, ¶meter_arg, &platform_data_arg, NULL };
96 static const GDBusMethodInfo describe_all_method = {
97 -1, (gchar *) "DescribeAll", NULL,
98 (GDBusArgInfo **) describe_all_out
101 static const GDBusMethodInfo set_action_state_method = {
102 -1, (gchar *) "SetState",
103 (GDBusArgInfo **) set_action_state_in
106 static const GDBusMethodInfo activate_action_method = {
107 -1, (gchar *) "Activate",
108 (GDBusArgInfo **) activate_action_in
111 static const GDBusMethodInfo *actions_methods[] = {
112 &describe_all_method, &set_action_state_method, &activate_action_method, NULL
115 const GDBusInterfaceInfo org_gtk_Actions = {
116 -1, (gchar *) "org.gtk.Actions",
117 (GDBusMethodInfo **) actions_methods
120 static const GDBusArgInfo message_arg = { -1, (gchar *) "message", (gchar *) "s" };
121 static const GDBusArgInfo *print_in[] = { &message_arg, NULL };
122 static const GDBusArgInfo *print_out[] = { NULL };
124 static const GDBusMethodInfo stdout_method = {
125 -1, (gchar *) "Print",
126 (GDBusArgInfo **) print_in,
127 (GDBusArgInfo **) print_out
130 static const GDBusMethodInfo stderr_method = {
131 -1, (gchar *) "PrintError",
132 (GDBusArgInfo **) print_in,
133 (GDBusArgInfo **) print_out
136 static const GDBusMethodInfo *cmdline_methods[] = {
137 &stdout_method, &stderr_method, NULL
140 const GDBusInterfaceInfo org_gtk_private_Cmdline = {
141 -1, (gchar *) "org.gtk.private.CommandLine",
142 (GDBusMethodInfo **) cmdline_methods
145 /* GApplication implementation {{{1 */
146 struct _GApplicationImpl
148 GDBusConnection *session_bus;
149 const gchar *bus_name;
160 static GApplicationCommandLine *
161 g_dbus_command_line_new (GDBusMethodInvocation *invocation);
165 g_application_impl_method_call (GDBusConnection *connection,
167 const gchar *object_path,
168 const gchar *interface_name,
169 const gchar *method_name,
170 GVariant *parameters,
171 GDBusMethodInvocation *invocation,
174 GApplicationImpl *impl = user_data;
175 GApplicationClass *class;
177 class = G_APPLICATION_GET_CLASS (impl->app);
179 if (strcmp (method_name, "Activate") == 0)
181 GVariant *platform_data;
183 g_variant_get (parameters, "(@a{sv})", &platform_data);
184 class->before_emit (impl->app, platform_data);
185 g_signal_emit_by_name (impl->app, "activate");
186 class->after_emit (impl->app, platform_data);
187 g_variant_unref (platform_data);
189 g_dbus_method_invocation_return_value (invocation, NULL);
192 else if (strcmp (method_name, "Open") == 0)
194 GVariant *platform_data;
200 g_variant_get (parameters, "(@ass@a{sv})",
201 &array, &hint, &platform_data);
203 n = g_variant_n_children (array);
204 files = g_new (GFile *, n + 1);
206 for (i = 0; i < n; i++)
210 g_variant_get_child (array, i, "&s", &uri);
211 files[i] = g_file_new_for_uri (uri);
213 g_variant_unref (array);
216 class->before_emit (impl->app, platform_data);
217 g_signal_emit_by_name (impl->app, "open", files, n, hint);
218 class->after_emit (impl->app, platform_data);
220 g_variant_unref (platform_data);
222 for (i = 0; i < n; i++)
223 g_object_unref (files[i]);
226 g_dbus_method_invocation_return_value (invocation, NULL);
229 else if (strcmp (method_name, "CommandLine") == 0)
231 GApplicationCommandLine *cmdline;
232 GVariant *platform_data;
235 cmdline = g_dbus_command_line_new (invocation);
236 platform_data = g_variant_get_child_value (parameters, 2);
237 class->before_emit (impl->app, platform_data);
238 g_signal_emit_by_name (impl->app, "command-line", cmdline, &status);
239 g_application_command_line_set_exit_status (cmdline, status);
240 class->after_emit (impl->app, platform_data);
241 g_variant_unref (platform_data);
242 g_object_unref (cmdline);
245 g_assert_not_reached ();
249 g_application_impl_actions_method_call (GDBusConnection *connection,
251 const gchar *object_path,
252 const gchar *interface_name,
253 const gchar *method_name,
254 GVariant *parameters,
255 GDBusMethodInvocation *invocation,
258 GApplicationImpl *impl = user_data;
259 GActionGroup *action_group;
260 GApplicationClass *class;
262 class = G_APPLICATION_GET_CLASS (impl->app);
263 action_group = G_ACTION_GROUP (impl->app);
265 if (strcmp (method_name, "DescribeAll") == 0)
267 GVariantBuilder builder;
271 actions = g_action_group_list_actions (action_group);
272 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a(savbav))"));
273 g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(savbav)"));
275 for (i = 0; actions[i]; i++)
278 g_variant_builder_open (&builder, G_VARIANT_TYPE ("(savbav)"));
281 g_variant_builder_add (&builder, "s", actions[i]);
284 g_variant_builder_open (&builder, G_VARIANT_TYPE ("av"));
286 const GVariantType *type;
288 type = g_action_group_get_action_parameter_type (action_group,
292 GVariantType *array_type;
294 array_type = g_variant_type_new_array (type);
295 g_variant_builder_open (&builder, G_VARIANT_TYPE_VARIANT);
296 g_variant_builder_open (&builder, array_type);
297 g_variant_builder_close (&builder);
298 g_variant_builder_close (&builder);
299 g_variant_type_free (array_type);
302 g_variant_builder_close (&builder);
306 gboolean enabled = g_action_group_get_action_enabled (action_group,
308 g_variant_builder_add (&builder, "b", enabled);
312 g_variant_builder_open (&builder, G_VARIANT_TYPE ("av"));
314 GVariant *state = g_action_group_get_action_state (action_group,
318 g_variant_builder_add (&builder, "v", state);
319 g_variant_unref (state);
322 g_variant_builder_close (&builder);
325 g_variant_builder_close (&builder);
327 g_variant_builder_close (&builder);
329 g_dbus_method_invocation_return_value (invocation,
330 g_variant_builder_end (&builder));
332 g_strfreev (actions);
335 else if (strcmp (method_name, "SetState") == 0)
337 const gchar *action_name;
338 GVariant *platform_data;
341 g_variant_get (parameters, "(&sv@a{sv})",
342 &action_name, &state, &platform_data);
344 class->before_emit (impl->app, platform_data);
345 g_action_group_change_action_state (action_group, action_name, state);
346 class->after_emit (impl->app, platform_data);
347 g_variant_unref (platform_data);
348 g_variant_unref (state);
350 g_dbus_method_invocation_return_value (invocation, NULL);
353 else if (strcmp (method_name, "Activate") == 0)
355 const gchar *action_name;
356 GVariant *platform_data;
359 GVariant *unboxed_parameter;
361 g_variant_get (parameters, "(&sav@a{sv})",
362 &action_name, ¶m, &platform_data);
363 parameter = g_variant_iter_next_value (param);
364 unboxed_parameter = parameter ? g_variant_get_variant (parameter) : NULL;
365 g_variant_iter_free (param);
367 class->before_emit (impl->app, platform_data);
368 g_action_group_activate_action (action_group, action_name, unboxed_parameter);
369 class->after_emit (impl->app, platform_data);
370 g_variant_unref (platform_data);
372 if (unboxed_parameter)
373 g_variant_unref (unboxed_parameter);
375 g_variant_unref (parameter);
377 g_dbus_method_invocation_return_value (invocation, NULL);
381 g_assert_not_reached ();
385 application_path_from_appid (const gchar *appid)
387 gchar *appid_path, *iter;
389 appid_path = g_strconcat ("/", appid, NULL);
390 for (iter = appid_path; *iter; iter++)
400 g_application_impl_destroy (GApplicationImpl *impl)
402 if (impl->session_bus)
405 g_dbus_connection_unregister_object (impl->session_bus,
408 g_object_unref (impl->session_bus);
409 g_free (impl->object_path);
413 g_assert (impl->object_path == NULL);
414 g_assert (impl->object_id == 0);
417 g_slice_free (GApplicationImpl, impl);
421 remote_action_info_new_from_iter (GVariantIter *iter)
423 RemoteActionInfo *info;
425 GVariant *param_type;
429 if (!g_variant_iter_next (iter, "(s@avb@av)", &name,
430 ¶m_type, &enabled, &state))
433 info = g_slice_new (RemoteActionInfo);
434 info->parameter_type = g_variant_type_copy (
435 g_variant_type_element (
436 g_variant_get_type (param_type)));
437 info->enabled = enabled;
440 g_variant_unref (param_type);
446 g_application_impl_action_signal (GDBusConnection *connection,
447 const gchar *sender_name,
448 const gchar *object_path,
449 const gchar *interface_name,
450 const gchar *signal_name,
451 GVariant *parameters,
454 GApplicationImpl *impl = user_data;
455 GActionGroup *action_group;
457 action_group = G_ACTION_GROUP (impl->app);
459 if (strcmp (signal_name, "Added") == 0 &&
460 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a(savbav))")))
462 RemoteActionInfo *info;
465 g_variant_get_child (parameters, 0, "a(savbav)", &iter);
467 while ((info = remote_action_info_new_from_iter (iter)))
469 g_hash_table_replace (impl->actions, info->name, info);
470 g_action_group_action_added (action_group, info->name);
473 g_variant_iter_free (iter);
476 else if (strcmp (signal_name, "Removed") == 0 &&
477 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(as)")))
482 g_variant_get_child (parameters, 0, "as", &iter);
483 while (g_variant_iter_next (iter, "&s", &name))
484 if (g_hash_table_remove (impl->actions, name))
485 g_action_group_action_removed (action_group, name);
486 g_variant_iter_free (iter);
489 else if (strcmp (signal_name, "EnabledChanged") == 0 &&
490 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sb)")))
492 RemoteActionInfo *info;
496 g_variant_get (parameters, "(&sb)", &name, &enabled);
497 info = g_hash_table_lookup (impl->actions, name);
499 if (info && enabled != info->enabled)
501 info->enabled = enabled;
502 g_action_group_action_enabled_changed (action_group,
508 else if (strcmp (signal_name, "StateChanged") == 0 &&
509 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sv)")))
511 RemoteActionInfo *info;
515 g_variant_get (parameters, "(&sv)", &name, &state);
516 info = g_hash_table_lookup (impl->actions, name);
518 if (info && info->state &&
519 g_variant_is_of_type (state, g_variant_get_type (info->state)) &&
520 !g_variant_equal (state, info->state))
522 g_variant_unref (info->state);
523 info->state = g_variant_ref (state);
524 g_action_group_action_state_changed (action_group,
528 g_variant_unref (state);
533 g_application_impl_register (GApplication *application,
535 GApplicationFlags flags,
536 GHashTable **remote_actions,
537 GCancellable *cancellable,
540 const static GDBusInterfaceVTable vtable = {
541 g_application_impl_method_call
543 const static GDBusInterfaceVTable actions_vtable = {
544 g_application_impl_actions_method_call
546 GApplicationImpl *impl;
550 impl = g_slice_new (GApplicationImpl);
552 impl->app = application;
553 impl->bus_name = appid;
555 impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION,
558 if (impl->session_bus == NULL)
560 g_slice_free (GApplicationImpl, impl);
564 impl->object_path = application_path_from_appid (appid);
566 /* Only try to be the primary instance if
567 * G_APPLICATION_IS_LAUNCHER was not specified.
569 if (~flags & G_APPLICATION_IS_LAUNCHER)
571 /* Attempt to become primary instance. */
573 g_dbus_connection_register_object (impl->session_bus,
575 (GDBusInterfaceInfo *)
576 &org_gtk_Application,
577 &vtable, impl, NULL, error);
579 if (impl->object_id == 0)
581 g_object_unref (impl->session_bus);
582 g_free (impl->object_path);
583 impl->session_bus = NULL;
584 impl->object_path = NULL;
586 g_slice_free (GApplicationImpl, impl);
591 g_dbus_connection_register_object (impl->session_bus,
593 (GDBusInterfaceInfo *)
598 if (impl->action_id == 0)
600 g_dbus_connection_unregister_object (impl->session_bus,
603 g_object_unref (impl->session_bus);
604 g_free (impl->object_path);
605 impl->session_bus = NULL;
606 impl->object_path = NULL;
608 g_slice_free (GApplicationImpl, impl);
612 /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
613 reply = g_dbus_connection_call_sync (impl->session_bus,
614 "org.freedesktop.DBus",
615 "/org/freedesktop/DBus",
616 "org.freedesktop.DBus",
618 g_variant_new ("(su)",
621 G_VARIANT_TYPE ("(u)"),
622 0, -1, cancellable, error);
626 g_dbus_connection_unregister_object (impl->session_bus,
630 g_object_unref (impl->session_bus);
631 g_free (impl->object_path);
632 impl->session_bus = NULL;
633 impl->object_path = NULL;
635 g_slice_free (GApplicationImpl, impl);
639 g_variant_get (reply, "(u)", &rval);
640 g_variant_unref (reply);
642 /* DBUS_REQUEST_NAME_REPLY_EXISTS: 3 */
645 /* We are the primary instance. */
646 g_dbus_connection_emit_signal (impl->session_bus,
649 "org.gtk.Application",
651 g_variant_new ("(s)",
654 *remote_actions = NULL;
658 /* We didn't make it. Drop our service-side stuff. */
659 g_dbus_connection_unregister_object (impl->session_bus,
663 if (flags & G_APPLICATION_IS_SERVICE)
665 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
666 "Unable to acquire bus name `%s'", appid);
667 g_object_unref (impl->session_bus);
668 g_free (impl->object_path);
670 g_slice_free (GApplicationImpl, impl);
675 /* We are non-primary. Try to get the primary's list of actions.
676 * This also serves as a mechanism to ensure that the primary exists
677 * (ie: DBus service files installed correctly, etc).
680 g_dbus_connection_signal_subscribe (impl->session_bus, impl->bus_name,
681 "org.gtk.Actions", NULL,
682 impl->object_path, NULL,
683 G_DBUS_SIGNAL_FLAGS_NONE,
684 g_application_impl_action_signal,
687 reply = g_dbus_connection_call_sync (impl->session_bus, impl->bus_name,
688 impl->object_path, "org.gtk.Actions",
690 G_VARIANT_TYPE ("(a(savbav))"),
691 G_DBUS_CALL_FLAGS_NONE, -1,
696 /* The primary appears not to exist. Fail the registration. */
697 g_object_unref (impl->session_bus);
698 g_free (impl->object_path);
699 impl->session_bus = NULL;
700 impl->object_path = NULL;
702 g_slice_free (GApplicationImpl, impl);
706 /* Create and populate the hashtable */
708 GVariant *descriptions;
710 GVariant *param_type;
715 *remote_actions = g_hash_table_new (g_str_hash, g_str_equal);
716 descriptions = g_variant_get_child_value (reply, 0);
717 g_variant_iter_init (&iter, descriptions);
719 while (g_variant_iter_next (&iter, "(s@avb@av)", &name,
720 ¶m_type, &enabled, &state))
722 RemoteActionInfo *action;
724 action = g_slice_new (RemoteActionInfo);
725 action->parameter_type = g_variant_type_copy (
726 g_variant_type_element (
727 g_variant_get_type (param_type)));
728 action->enabled = enabled;
729 action->state = state;
731 g_hash_table_insert (*remote_actions, name, action);
732 g_variant_unref (param_type);
735 g_variant_unref (descriptions);
743 g_application_impl_activate (GApplicationImpl *impl,
744 GVariant *platform_data)
746 g_dbus_connection_call (impl->session_bus,
749 "org.gtk.Application",
751 g_variant_new ("(@a{sv})", platform_data),
752 NULL, 0, -1, NULL, NULL, NULL);
756 g_application_impl_open (GApplicationImpl *impl,
760 GVariant *platform_data)
762 GVariantBuilder builder;
765 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(assa{sv})"));
766 g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
767 for (i = 0; i < n_files; i++)
769 gchar *uri = g_file_get_uri (files[i]);
770 g_variant_builder_add (&builder, "s", uri);
773 g_variant_builder_close (&builder);
774 g_variant_builder_add (&builder, "s", hint);
775 g_variant_builder_add_value (&builder, platform_data);
777 g_dbus_connection_call (impl->session_bus,
780 "org.gtk.Application",
782 g_variant_builder_end (&builder),
783 NULL, 0, -1, NULL, NULL, NULL);
787 g_application_impl_cmdline_method_call (GDBusConnection *connection,
789 const gchar *object_path,
790 const gchar *interface_name,
791 const gchar *method_name,
792 GVariant *parameters,
793 GDBusMethodInvocation *invocation,
796 const gchar *message;
798 g_variant_get_child (parameters, 0, "&s", &message);
800 if (strcmp (method_name, "Print") == 0)
801 g_print ("%s", message);
802 else if (strcmp (method_name, "PrintError") == 0)
803 g_printerr ("%s", message);
805 g_assert_not_reached ();
807 g_dbus_method_invocation_return_value (invocation, NULL);
817 g_application_impl_cmdline_done (GObject *source,
818 GAsyncResult *result,
821 CommandLineData *data = user_data;
822 GError *error = NULL;
825 reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
830 g_variant_get (reply, "(i)", &data->status);
831 g_variant_unref (reply);
836 g_printerr ("%s\n", error->message);
837 g_error_free (error);
841 g_main_loop_quit (data->loop);
845 g_application_impl_command_line (GApplicationImpl *impl,
847 GVariant *platform_data)
849 const static GDBusInterfaceVTable vtable = {
850 g_application_impl_cmdline_method_call
852 const gchar *object_path = "/org/gtk/Application/CommandLine";
853 GMainContext *context;
854 CommandLineData data;
857 context = g_main_context_new ();
858 data.loop = g_main_loop_new (context, FALSE);
859 g_main_context_push_thread_default (context);
861 object_id = g_dbus_connection_register_object (impl->session_bus,
863 (GDBusInterfaceInfo *)
864 &org_gtk_private_Cmdline,
865 &vtable, &data, NULL, NULL);
866 /* In theory we should try other paths... */
867 g_assert (object_id != 0);
869 g_dbus_connection_call (impl->session_bus,
872 "org.gtk.Application",
874 g_variant_new ("(o^aay@a{sv})", object_path,
875 arguments, platform_data),
876 G_VARIANT_TYPE ("(i)"), 0, G_MAXINT, NULL,
877 g_application_impl_cmdline_done, &data);
879 g_main_loop_run (data.loop);
881 g_main_context_pop_thread_default (context);
882 g_main_context_unref (context);
883 g_main_loop_unref (data.loop);
889 g_application_impl_change_action_state (GApplicationImpl *impl,
890 const gchar *action_name,
892 GVariant *platform_data)
894 g_dbus_connection_call (impl->session_bus,
899 g_variant_new ("(sv@a{sv})", action_name,
900 value, platform_data),
901 NULL, 0, -1, NULL, NULL, NULL);
905 g_application_impl_activate_action (GApplicationImpl *impl,
906 const gchar *action_name,
908 GVariant *platform_data)
913 parameter = g_variant_new_variant (parameter);
915 param = g_variant_new_array (G_VARIANT_TYPE_VARIANT,
916 ¶meter, parameter != NULL);
918 g_dbus_connection_call (impl->session_bus,
923 g_variant_new ("(s@av@a{sv})", action_name,
924 param, platform_data),
925 NULL, 0, -1, NULL, NULL, NULL);
929 g_application_impl_flush (GApplicationImpl *impl)
931 g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
935 /* GDBusCommandLine implementation {{{1 */
937 typedef GApplicationCommandLineClass GDBusCommandLineClass;
938 static GType g_dbus_command_line_get_type (void);
941 GApplicationCommandLine parent_instance;
942 GDBusMethodInvocation *invocation;
944 GDBusConnection *connection;
945 const gchar *bus_name;
946 const gchar *object_path;
950 G_DEFINE_TYPE (GDBusCommandLine,
952 G_TYPE_APPLICATION_COMMAND_LINE)
955 g_dbus_command_line_print_literal (GApplicationCommandLine *cmdline,
956 const gchar *message)
958 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
960 g_dbus_connection_call (gdbcl->connection,
963 "org.gtk.private.CommandLine", "Print",
964 g_variant_new ("(s)", message),
965 NULL, 0, -1, NULL, NULL, NULL);
969 g_dbus_command_line_printerr_literal (GApplicationCommandLine *cmdline,
970 const gchar *message)
972 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
974 g_dbus_connection_call (gdbcl->connection,
977 "org.gtk.private.CommandLine", "PrintError",
978 g_variant_new ("(s)", message),
979 NULL, 0, -1, NULL, NULL, NULL);
983 g_dbus_command_line_finalize (GObject *object)
985 GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
986 GDBusCommandLine *gdbcl = (GDBusCommandLine *) object;
989 status = g_application_command_line_get_exit_status (cmdline);
991 g_dbus_method_invocation_return_value (gdbcl->invocation,
992 g_variant_new ("(i)", status));
993 g_object_unref (gdbcl->invocation);
995 G_OBJECT_CLASS (g_dbus_command_line_parent_class)
1000 g_dbus_command_line_init (GDBusCommandLine *gdbcl)
1005 g_dbus_command_line_class_init (GApplicationCommandLineClass *class)
1007 GObjectClass *object_class = G_OBJECT_CLASS (class);
1009 object_class->finalize = g_dbus_command_line_finalize;
1010 class->printerr_literal = g_dbus_command_line_printerr_literal;
1011 class->print_literal = g_dbus_command_line_print_literal;
1014 static GApplicationCommandLine *
1015 g_dbus_command_line_new (GDBusMethodInvocation *invocation)
1017 GDBusCommandLine *gdbcl;
1020 args = g_dbus_method_invocation_get_parameters (invocation);
1022 gdbcl = g_object_new (g_dbus_command_line_get_type (),
1023 "arguments", g_variant_get_child_value (args, 1),
1024 "platform-data", g_variant_get_child_value (args, 2),
1026 gdbcl->connection = g_dbus_method_invocation_get_connection (invocation);
1027 gdbcl->bus_name = g_dbus_method_invocation_get_sender (invocation);
1028 g_variant_get_child (args, 0, "&o", &gdbcl->object_path);
1029 gdbcl->invocation = g_object_ref (invocation);
1031 return G_APPLICATION_COMMAND_LINE (gdbcl);
1036 /* vim:set foldmethod=marker: */