2010-08-06 19:05:18 +02:00
|
|
|
#include <gio/gio.h>
|
2010-06-07 19:25:39 +02:00
|
|
|
#include <gstdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
static gboolean action3_added = FALSE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_app_action (GApplication *application,
|
|
|
|
const gchar *action_name,
|
2010-06-08 22:25:33 +02:00
|
|
|
GVariant *platform_data)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
if (strcmp (action_name, "action1") == 0)
|
|
|
|
exit (1);
|
|
|
|
else if (strcmp (action_name, "action2") == 0)
|
|
|
|
{
|
|
|
|
if (action3_added)
|
|
|
|
g_application_remove_action (application, "action3");
|
|
|
|
else
|
|
|
|
g_application_add_action (application, "action3", "An extra action");
|
|
|
|
action3_added = !action3_added;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_app_activated (GApplication *application,
|
|
|
|
GVariant *args,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
2010-06-16 20:17:26 +02:00
|
|
|
GVariantIter iter;
|
|
|
|
const char *key;
|
|
|
|
GVariant *value;
|
|
|
|
char *cwd;
|
|
|
|
|
|
|
|
cwd = g_get_current_dir ();
|
|
|
|
g_variant_iter_init (&iter, platform_data);
|
|
|
|
while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
|
|
|
|
{
|
|
|
|
const char *activate_cwd;
|
2010-07-07 16:37:16 +02:00
|
|
|
|
2010-06-16 20:17:26 +02:00
|
|
|
if (strcmp (key, "cwd") != 0)
|
|
|
|
continue;
|
|
|
|
|
2010-07-07 16:37:16 +02:00
|
|
|
activate_cwd = g_variant_get_bytestring (value);
|
2010-06-16 20:17:26 +02:00
|
|
|
g_assert_cmpstr (cwd, ==, activate_cwd);
|
|
|
|
g_variant_unref (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (cwd);
|
2010-06-09 03:43:16 +02:00
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static gboolean
|
|
|
|
on_monitor_fd_io (GIOChannel *source,
|
|
|
|
GIOCondition condition,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
exit (0);
|
|
|
|
return FALSE;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GApplication *app;
|
2010-06-09 03:43:16 +02:00
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
{
|
|
|
|
const char *slave_fd_env = g_getenv ("_G_TEST_SLAVE_FD");
|
|
|
|
if (slave_fd_env)
|
|
|
|
{
|
|
|
|
int slave_fd = atoi (slave_fd_env);
|
|
|
|
fcntl (slave_fd, F_SETFD, FD_CLOEXEC);
|
|
|
|
g_io_add_watch (g_io_channel_unix_new (slave_fd), G_IO_HUP | G_IO_ERR,
|
|
|
|
on_monitor_fd_io, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-16 06:18:09 +02:00
|
|
|
app = g_application_unregistered_try_new ("org.gtk.test.app",
|
|
|
|
argc, argv, NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
if (!(argc > 1 && strcmp (argv[1], "--non-unique") == 0))
|
2010-06-16 06:18:09 +02:00
|
|
|
{
|
|
|
|
if (!g_application_register (app))
|
|
|
|
exit (0);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
if (g_application_is_remote (app))
|
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
g_application_invoke_action (app, "action1", 0);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_application_add_action (app, "action1", "Action1");
|
|
|
|
g_application_add_action (app, "action2", "Action2");
|
2010-06-08 22:25:33 +02:00
|
|
|
g_signal_connect (app, "action-with-data",
|
2010-06-07 19:25:39 +02:00
|
|
|
G_CALLBACK (on_app_action), NULL);
|
|
|
|
g_signal_connect (app, "prepare-activation",
|
|
|
|
G_CALLBACK (on_app_activated), NULL);
|
|
|
|
g_application_run (app);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|