5 new_activated (GSimpleAction
*action
,
9 GApplication
*app
= user_data
;
11 g_application_activate (app
);
15 quit_activated (GSimpleAction
*action
,
19 GApplication
*app
= user_data
;
21 g_application_quit (app
);
25 action1_activated (GSimpleAction
*action
,
29 g_print ("activate action1\n");
33 action2_activated (GSimpleAction
*action
,
39 state
= g_action_get_state (G_ACTION (action
));
40 g_action_change_state (G_ACTION (action
), g_variant_new_boolean (!g_variant_get_boolean (state
)));
41 g_print ("activate action2 %d\n", !g_variant_get_boolean (state
));
42 g_variant_unref (state
);
46 change_action2 (GSimpleAction
*action
,
50 g_print ("change action2 %d\n", g_variant_get_boolean (state
));
54 startup (GApplication
*app
)
56 static GActionEntry actions
[] = {
57 { "new", new_activated
, NULL
, NULL
, NULL
},
58 { "quit", quit_activated
, NULL
, NULL
, NULL
},
59 { "action1", action1_activated
, NULL
, NULL
, NULL
},
60 { "action2", action2_activated
, "b", "false", change_action2
}
63 g_action_map_add_action_entries (G_ACTION_MAP (app
),
64 actions
, G_N_ELEMENTS (actions
),
69 activate (GApplication
*application
)
71 g_application_hold (application
);
72 g_print ("activated\n");
73 g_application_release (application
);
77 open (GApplication
*application
,
84 g_application_hold (application
);
87 for (i
= 0; i
< n_files
; i
++)
89 gchar
*uri
= g_file_get_uri (files
[i
]);
95 g_application_release (application
);
99 command_line (GApplication
*application
,
100 GApplicationCommandLine
*cmdline
)
106 g_application_hold (application
);
107 argv
= g_application_command_line_get_arguments (cmdline
, &argc
);
111 if (g_strcmp0 (argv
[1], "echo") == 0)
114 for (i
= 0; i
< argc
; i
++)
115 g_print (" %s", argv
[i
]);
118 else if (g_strcmp0 (argv
[1], "env") == 0)
120 const gchar
* const *env
;
122 env
= g_application_command_line_get_environ (cmdline
);
123 g_print ("environment");
124 for (i
= 0; env
[i
]; i
++)
125 if (g_str_has_prefix (env
[i
], "TEST="))
126 g_print (" %s", env
[i
]);
129 else if (g_strcmp0 (argv
[1], "getenv") == 0)
131 g_print ("getenv TEST=%s\n", g_application_command_line_getenv (cmdline
, "TEST"));
133 else if (g_strcmp0 (argv
[1], "print") == 0)
135 g_application_command_line_print (cmdline
, "print %s\n", argv
[2]);
137 else if (g_strcmp0 (argv
[1], "printerr") == 0)
139 g_application_command_line_printerr (cmdline
, "printerr %s\n", argv
[2]);
141 else if (g_strcmp0 (argv
[1], "file") == 0)
145 file
= g_application_command_line_create_file_for_arg (cmdline
, argv
[2]);
146 g_print ("file %s\n", g_file_get_path (file
));
147 g_object_unref (file
);
149 else if (g_strcmp0 (argv
[1], "properties") == 0)
154 g_object_get (cmdline
,
155 "is-remote", &remote
,
158 data
= g_application_command_line_get_platform_data (cmdline
);
160 g_assert (g_variant_is_of_type (data
, G_VARIANT_TYPE ("a{sv}")));
161 g_variant_unref (data
);
162 g_print ("properties ok\n");
164 else if (g_strcmp0 (argv
[1], "cwd") == 0)
166 g_print ("cwd %s\n", g_application_command_line_get_cwd (cmdline
));
168 else if (g_strcmp0 (argv
[1], "busy") == 0)
170 g_application_mark_busy (g_application_get_default ());
173 else if (g_strcmp0 (argv
[1], "idle") == 0)
175 g_application_unmark_busy (g_application_get_default ());
178 else if (g_strcmp0 (argv
[1], "stdin") == 0)
180 GInputStream
*stream
;
182 stream
= g_application_command_line_get_stdin (cmdline
);
184 g_assert (stream
== NULL
|| G_IS_INPUT_STREAM (stream
));
185 g_object_unref (stream
);
187 g_print ("stdin ok\n");
190 g_print ("unexpected command: %s\n", argv
[1]);
193 g_print ("got ./cmd %d\n", g_application_command_line_get_is_remote (cmdline
));
196 g_application_release (application
);
202 action_cb (gpointer data
)
209 if (g_strcmp0 (argv
[1], "./actions") == 0)
211 app
= g_application_get_default ();
213 if (g_strcmp0 (argv
[2], "list") == 0)
216 actions
= g_action_group_list_actions (G_ACTION_GROUP (app
));
217 for (i
= 0; actions
[i
]; i
++)
218 g_print (" %s", actions
[i
]);
220 g_strfreev (actions
);
222 else if (g_strcmp0 (argv
[2], "activate") == 0)
224 g_action_group_activate_action (G_ACTION_GROUP (app
),
227 else if (g_strcmp0 (argv
[2], "set-state") == 0)
229 g_action_group_change_action_state (G_ACTION_GROUP (app
),
231 g_variant_new_boolean (TRUE
));
233 g_application_release (app
);
236 return G_SOURCE_REMOVE
;
240 main (int argc
, char **argv
)
245 app
= g_application_new ("org.gtk.TestApplication",
246 G_APPLICATION_SEND_ENVIRONMENT
|
247 (g_strcmp0 (argv
[1], "./cmd") == 0
248 ? G_APPLICATION_HANDLES_COMMAND_LINE
249 : G_APPLICATION_HANDLES_OPEN
));
250 g_signal_connect (app
, "startup", G_CALLBACK (startup
), NULL
);
251 g_signal_connect (app
, "activate", G_CALLBACK (activate
), NULL
);
252 g_signal_connect (app
, "open", G_CALLBACK (open
), NULL
);
253 g_signal_connect (app
, "command-line", G_CALLBACK (command_line
), NULL
);
255 g_application_set_inactivity_timeout (app
, 10000);
257 g_application_set_inactivity_timeout (app
, 1000);
260 if (g_strcmp0 (argv
[1], "./actions") == 0)
262 g_application_set_inactivity_timeout (app
, 0);
263 g_application_hold (app
);
264 g_idle_add (action_cb
, argv
);
267 status
= g_application_run (app
, argc
- 1, argv
+ 1);
269 g_object_unref (app
);
271 g_print ("exit status: %d\n", status
);