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));
333 else if (strcmp (method_name, "SetState") == 0)
335 const gchar *action_name;
336 GVariant *platform_data;
339 g_variant_get (parameters, "(&sv@a{sv})",
340 &action_name, &state, &platform_data);
342 class->before_emit (impl->app, platform_data);
343 g_action_group_change_action_state (action_group, action_name, state);
344 class->after_emit (impl->app, platform_data);
345 g_variant_unref (platform_data);
346 g_variant_unref (state);
348 g_dbus_method_invocation_return_value (invocation, NULL);
351 else if (strcmp (method_name, "Activate") == 0)
353 const gchar *action_name;
354 GVariant *platform_data;
358 g_variant_get (parameters, "(&sav@a{sv})",
359 &action_name, ¶m, &platform_data);
360 parameter = g_variant_iter_next_value (param);
361 g_variant_iter_free (param);
363 class->before_emit (impl->app, platform_data);
364 g_action_group_activate_action (action_group, action_name, parameter);
365 class->after_emit (impl->app, platform_data);
366 g_variant_unref (platform_data);
369 g_variant_unref (parameter);
371 g_dbus_method_invocation_return_value (invocation, NULL);
375 g_assert_not_reached ();
379 application_path_from_appid (const gchar *appid)
381 gchar *appid_path, *iter;
383 appid_path = g_strconcat ("/", appid, NULL);
384 for (iter = appid_path; *iter; iter++)
394 g_application_impl_destroy (GApplicationImpl *impl)
396 if (impl->session_bus)
399 g_dbus_connection_unregister_object (impl->session_bus,
402 g_object_unref (impl->session_bus);
403 g_free (impl->object_path);
407 g_assert (impl->object_path == NULL);
408 g_assert (impl->object_id == 0);
411 g_slice_free (GApplicationImpl, impl);
415 remote_action_info_new_from_iter (GVariantIter *iter)
417 RemoteActionInfo *info;
419 GVariant *param_type;
423 if (!g_variant_iter_next (iter, "(s@avb@av)", &name,
424 ¶m_type, &enabled, &state))
427 info = g_slice_new (RemoteActionInfo);
428 info->parameter_type = g_variant_type_copy (
429 g_variant_type_element (
430 g_variant_get_type (param_type)));
431 info->enabled = enabled;
434 g_variant_unref (param_type);
440 g_application_impl_action_signal (GDBusConnection *connection,
441 const gchar *sender_name,
442 const gchar *object_path,
443 const gchar *interface_name,
444 const gchar *signal_name,
445 GVariant *parameters,
448 GApplicationImpl *impl = user_data;
449 GActionGroup *action_group;
451 action_group = G_ACTION_GROUP (impl->app);
453 if (strcmp (signal_name, "Added") == 0 &&
454 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a(savbav))")))
456 RemoteActionInfo *info;
459 g_variant_get_child (parameters, 0, "a(savbav)", &iter);
461 while ((info = remote_action_info_new_from_iter (iter)))
463 g_hash_table_replace (impl->actions, info->name, info);
464 g_action_group_action_added (action_group, info->name);
467 g_variant_iter_free (iter);
470 else if (strcmp (signal_name, "Removed") == 0 &&
471 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(as)")))
476 g_variant_get_child (parameters, 0, "as", &iter);
477 while (g_variant_iter_next (iter, "&s", &name))
478 if (g_hash_table_remove (impl->actions, name))
479 g_action_group_action_removed (action_group, name);
480 g_variant_iter_free (iter);
483 else if (strcmp (signal_name, "EnabledChanged") == 0 &&
484 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sb)")))
486 RemoteActionInfo *info;
490 g_variant_get (parameters, "(&sb)", &name, &enabled);
491 info = g_hash_table_lookup (impl->actions, name);
493 if (info && enabled != info->enabled)
495 info->enabled = enabled;
496 g_action_group_action_enabled_changed (action_group,
502 else if (strcmp (signal_name, "StateChanged") == 0 &&
503 g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sv)")))
505 RemoteActionInfo *info;
509 g_variant_get (parameters, "(&sv)", &name, &state);
510 info = g_hash_table_lookup (impl->actions, name);
512 if (info && info->state &&
513 g_variant_is_of_type (state, g_variant_get_type (info->state)) &&
514 !g_variant_equal (state, info->state))
516 g_variant_unref (info->state);
517 info->state = g_variant_ref (state);
518 g_action_group_action_state_changed (action_group,
522 g_variant_unref (state);
527 g_application_impl_register (GApplication *application,
529 GApplicationFlags flags,
530 GHashTable **remote_actions,
531 GCancellable *cancellable,
534 const static GDBusInterfaceVTable vtable = {
535 g_application_impl_method_call
537 const static GDBusInterfaceVTable actions_vtable = {
538 g_application_impl_actions_method_call
540 GApplicationImpl *impl;
544 impl = g_slice_new (GApplicationImpl);
546 impl->app = application;
547 impl->bus_name = appid;
549 impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION,
552 if (impl->session_bus == NULL)
554 g_slice_free (GApplicationImpl, impl);
558 impl->object_path = application_path_from_appid (appid);
560 /* Only try to be the primary instance if
561 * G_APPLICATION_IS_LAUNCHER was not specified.
563 if (~flags & G_APPLICATION_IS_LAUNCHER)
565 /* Attempt to become primary instance. */
567 g_dbus_connection_register_object (impl->session_bus,
569 (GDBusInterfaceInfo *)
570 &org_gtk_Application,
571 &vtable, impl, NULL, error);
573 if (impl->object_id == 0)
575 g_object_unref (impl->session_bus);
576 g_free (impl->object_path);
577 impl->session_bus = NULL;
578 impl->object_path = NULL;
580 g_slice_free (GApplicationImpl, impl);
585 g_dbus_connection_register_object (impl->session_bus,
587 (GDBusInterfaceInfo *)
592 if (impl->action_id == 0)
594 g_dbus_connection_unregister_object (impl->session_bus,
597 g_object_unref (impl->session_bus);
598 g_free (impl->object_path);
599 impl->session_bus = NULL;
600 impl->object_path = NULL;
602 g_slice_free (GApplicationImpl, impl);
606 /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
607 reply = g_dbus_connection_call_sync (impl->session_bus,
608 "org.freedesktop.DBus",
609 "/org/freedesktop/DBus",
610 "org.freedesktop.DBus",
612 g_variant_new ("(su)",
615 G_VARIANT_TYPE ("(u)"),
616 0, -1, cancellable, error);
620 g_dbus_connection_unregister_object (impl->session_bus,
624 g_object_unref (impl->session_bus);
625 g_free (impl->object_path);
626 impl->session_bus = NULL;
627 impl->object_path = NULL;
629 g_slice_free (GApplicationImpl, impl);
633 g_variant_get (reply, "(u)", &rval);
634 g_variant_unref (reply);
636 /* DBUS_REQUEST_NAME_REPLY_EXISTS: 3 */
639 /* We are the primary instance. */
640 *remote_actions = NULL;
644 /* We didn't make it. Drop our service-side stuff. */
645 g_dbus_connection_unregister_object (impl->session_bus,
649 if (flags & G_APPLICATION_IS_SERVICE)
651 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
652 "Unable to acquire bus name `%s'", appid);
653 g_object_unref (impl->session_bus);
654 g_free (impl->object_path);
656 g_slice_free (GApplicationImpl, impl);
661 /* We are non-primary. Try to get the primary's list of actions.
662 * This also serves as a mechanism to ensure that the primary exists
663 * (ie: DBus service files installed correctly, etc).
666 g_dbus_connection_signal_subscribe (impl->session_bus, impl->bus_name,
667 "org.gtk.Actions", NULL,
668 impl->object_path, NULL,
669 G_DBUS_SIGNAL_FLAGS_NONE,
670 g_application_impl_action_signal,
673 reply = g_dbus_connection_call_sync (impl->session_bus, impl->bus_name,
674 impl->object_path, "org.gtk.Actions",
676 G_VARIANT_TYPE ("(a(savbav))"),
677 G_DBUS_CALL_FLAGS_NONE, -1,
682 /* The primary appears not to exist. Fail the registration. */
683 g_object_unref (impl->session_bus);
684 g_free (impl->object_path);
685 impl->session_bus = NULL;
686 impl->object_path = NULL;
688 g_slice_free (GApplicationImpl, impl);
692 /* Create and populate the hashtable */
694 GVariant *descriptions;
696 GVariant *param_type;
701 *remote_actions = g_hash_table_new (g_str_hash, g_str_equal);
702 descriptions = g_variant_get_child_value (reply, 0);
703 g_variant_iter_init (&iter, descriptions);
705 while (g_variant_iter_next (&iter, "(s@avb@av)", &name,
706 ¶m_type, &enabled, &state))
708 RemoteActionInfo *action;
710 action = g_slice_new (RemoteActionInfo);
711 action->parameter_type = g_variant_type_copy (
712 g_variant_type_element (
713 g_variant_get_type (param_type)));
714 action->enabled = enabled;
715 action->state = state;
717 g_hash_table_insert (*remote_actions, name, action);
718 g_variant_unref (param_type);
721 g_variant_unref (descriptions);
729 g_application_impl_activate (GApplicationImpl *impl,
730 GVariant *platform_data)
732 g_dbus_connection_call (impl->session_bus,
735 "org.gtk.Application",
737 g_variant_new ("(@a{sv})", platform_data),
738 NULL, 0, -1, NULL, NULL, NULL);
742 g_application_impl_open (GApplicationImpl *impl,
746 GVariant *platform_data)
748 GVariantBuilder builder;
751 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(assa{sv})"));
752 g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
753 for (i = 0; i < n_files; i++)
755 gchar *uri = g_file_get_uri (files[i]);
756 g_variant_builder_add (&builder, "s", uri);
759 g_variant_builder_close (&builder);
760 g_variant_builder_add (&builder, "s", hint);
761 g_variant_builder_add_value (&builder, platform_data);
763 g_dbus_connection_call (impl->session_bus,
766 "org.gtk.Application",
768 g_variant_builder_end (&builder),
769 NULL, 0, -1, NULL, NULL, NULL);
773 g_application_impl_cmdline_method_call (GDBusConnection *connection,
775 const gchar *object_path,
776 const gchar *interface_name,
777 const gchar *method_name,
778 GVariant *parameters,
779 GDBusMethodInvocation *invocation,
782 const gchar *message;
784 g_variant_get_child (parameters, 0, "&s", &message);
786 if (strcmp (method_name, "Print") == 0)
787 g_print ("%s", message);
788 else if (strcmp (method_name, "PrintError") == 0)
789 g_printerr ("%s", message);
791 g_assert_not_reached ();
793 g_dbus_method_invocation_return_value (invocation, NULL);
803 g_application_impl_cmdline_done (GObject *source,
804 GAsyncResult *result,
807 CommandLineData *data = user_data;
808 GError *error = NULL;
811 reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
816 g_variant_get (reply, "(i)", &data->status);
817 g_variant_unref (reply);
822 g_printerr ("%s\n", error->message);
823 g_error_free (error);
827 g_main_loop_quit (data->loop);
831 g_application_impl_command_line (GApplicationImpl *impl,
833 GVariant *platform_data)
835 const static GDBusInterfaceVTable vtable = {
836 g_application_impl_cmdline_method_call
838 const gchar *object_path = "/org/gtk/Application/CommandLine";
839 GMainContext *context;
840 CommandLineData data;
843 context = g_main_context_new ();
844 data.loop = g_main_loop_new (context, FALSE);
845 g_main_context_push_thread_default (context);
847 object_id = g_dbus_connection_register_object (impl->session_bus,
849 (GDBusInterfaceInfo *)
850 &org_gtk_private_Cmdline,
851 &vtable, &data, NULL, NULL);
852 /* In theory we should try other paths... */
853 g_assert (object_id != 0);
855 g_dbus_connection_call (impl->session_bus,
858 "org.gtk.Application",
860 g_variant_new ("(o^aay@a{sv})", object_path,
861 arguments, platform_data),
862 G_VARIANT_TYPE ("(i)"), 0, -1, NULL,
863 g_application_impl_cmdline_done, &data);
865 g_main_loop_run (data.loop);
867 g_main_context_pop_thread_default (context);
868 g_main_context_unref (context);
869 g_main_loop_unref (data.loop);
875 g_application_impl_change_action_state (GApplicationImpl *impl,
876 const gchar *action_name,
878 GVariant *platform_data)
880 g_dbus_connection_call (impl->session_bus,
885 g_variant_new ("(sv@a{sv})", action_name,
886 value, platform_data),
887 NULL, 0, -1, NULL, NULL, NULL);
891 g_application_impl_activate_action (GApplicationImpl *impl,
892 const gchar *action_name,
894 GVariant *platform_data)
899 parameter = g_variant_new_variant (parameter);
901 param = g_variant_new_array (G_VARIANT_TYPE_VARIANT,
902 ¶meter, parameter != NULL);
904 g_dbus_connection_call (impl->session_bus,
909 g_variant_new ("(s@av@a{sv})", action_name,
910 param, platform_data),
911 NULL, 0, -1, NULL, NULL, NULL);
915 g_application_impl_flush (GApplicationImpl *impl)
917 g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
921 /* GDBusCommandLine implementation {{{1 */
923 typedef GApplicationCommandLineClass GDBusCommandLineClass;
924 static GType g_dbus_command_line_get_type (void);
927 GApplicationCommandLine parent_instance;
928 GDBusMethodInvocation *invocation;
930 GDBusConnection *connection;
931 const gchar *bus_name;
932 const gchar *object_path;
936 G_DEFINE_TYPE (GDBusCommandLine,
938 G_TYPE_APPLICATION_COMMAND_LINE)
941 g_dbus_command_line_print_literal (GApplicationCommandLine *cmdline,
942 const gchar *message)
944 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
946 g_dbus_connection_call (gdbcl->connection,
949 "org.gtk.private.CommandLine", "Print",
950 g_variant_new ("(s)", message),
951 NULL, 0, -1, NULL, NULL, NULL);
955 g_dbus_command_line_printerr_literal (GApplicationCommandLine *cmdline,
956 const gchar *message)
958 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
960 g_dbus_connection_call (gdbcl->connection,
963 "org.gtk.private.CommandLine", "PrintError",
964 g_variant_new ("(s)", message),
965 NULL, 0, -1, NULL, NULL, NULL);
969 g_dbus_command_line_finalize (GObject *object)
971 GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
972 GDBusCommandLine *gdbcl = (GDBusCommandLine *) object;
975 status = g_application_command_line_get_exit_status (cmdline);
977 g_dbus_method_invocation_return_value (gdbcl->invocation,
978 g_variant_new ("(i)", status));
979 g_object_unref (gdbcl->invocation);
981 G_OBJECT_CLASS (g_dbus_command_line_parent_class)
986 g_dbus_command_line_init (GDBusCommandLine *gdbcl)
991 g_dbus_command_line_class_init (GApplicationCommandLineClass *class)
993 GObjectClass *object_class = G_OBJECT_CLASS (class);
995 object_class->finalize = g_dbus_command_line_finalize;
996 class->printerr_literal = g_dbus_command_line_printerr_literal;
997 class->print_literal = g_dbus_command_line_print_literal;
1000 static GApplicationCommandLine *
1001 g_dbus_command_line_new (GDBusMethodInvocation *invocation)
1003 GDBusCommandLine *gdbcl;
1006 args = g_dbus_method_invocation_get_parameters (invocation);
1008 gdbcl = g_object_new (g_dbus_command_line_get_type (),
1009 "arguments", g_variant_get_child_value (args, 1),
1010 "platform-data", g_variant_get_child_value (args, 2),
1012 gdbcl->connection = g_dbus_method_invocation_get_connection (invocation);
1013 gdbcl->bus_name = g_dbus_method_invocation_get_sender (invocation);
1014 g_variant_get_child (args, 0, "&o", &gdbcl->object_path);
1015 gdbcl->invocation = g_object_ref (invocation);
1017 return G_APPLICATION_COMMAND_LINE (gdbcl);
1022 /* vim:set foldmethod=marker: */