| 1 |
#include <gio/gio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <string.h> |
| 4 |
|
| 5 |
static void |
| 6 |
activate (GApplication *application) |
| 7 |
{ |
| 8 |
g_print ("activated\n"); |
| 9 |
|
| 10 |
/* Note: when doing a longer-lasting action here that returns |
| 11 |
* to the mainloop, you should use g_application_hold() and |
| 12 |
* g_application_release() to keep the application alive until |
| 13 |
* the action is completed. |
| 14 |
*/ |
| 15 |
} |
| 16 |
|
| 17 |
typedef GApplication TestApplication; |
| 18 |
typedef GApplicationClass TestApplicationClass; |
| 19 |
|
| 20 |
static GType test_application_get_type (void); |
| 21 |
G_DEFINE_TYPE (TestApplication, test_application, G_TYPE_APPLICATION) |
| 22 |
|
| 23 |
static gboolean |
| 24 |
test_application_dbus_register (GApplication *application, |
| 25 |
GDBusConnection *connection, |
| 26 |
const gchar *object_path, |
| 27 |
GError **error) |
| 28 |
{ |
| 29 |
/* We must chain up to the parent class */ |
| 30 |
if (!G_APPLICATION_CLASS (test_application_parent_class)->dbus_register (application, |
| 31 |
connection, |
| 32 |
object_path, |
| 33 |
error)) |
| 34 |
return FALSE; |
| 35 |
|
| 36 |
/* Now we can do our own stuff here. For example, we could export some D-Bus objects */ |
| 37 |
return TRUE; |
| 38 |
} |
| 39 |
|
| 40 |
static void |
| 41 |
test_application_dbus_unregister (GApplication *application, |
| 42 |
GDBusConnection *connection, |
| 43 |
const gchar *object_path) |
| 44 |
{ |
| 45 |
/* Do our own stuff here, e.g. unexport any D-Bus objects we exported in the dbus_register |
| 46 |
* hook above. Be sure to check that we actually did export them, since the hook |
| 47 |
* above might have returned early due to the parent class' hook returning FALSE! |
| 48 |
*/ |
| 49 |
|
| 50 |
/* Lastly, we must chain up to the parent class */ |
| 51 |
G_APPLICATION_CLASS (test_application_parent_class)->dbus_unregister (application, |
| 52 |
connection, |
| 53 |
object_path); |
| 54 |
} |
| 55 |
|
| 56 |
static void |
| 57 |
test_application_init (TestApplication *app) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
static void |
| 62 |
test_application_class_init (TestApplicationClass *class) |
| 63 |
{ |
| 64 |
GApplicationClass *g_application_class = G_APPLICATION_CLASS (class); |
| 65 |
|
| 66 |
g_application_class->dbus_register = test_application_dbus_register; |
| 67 |
g_application_class->dbus_unregister = test_application_dbus_unregister; |
| 68 |
} |
| 69 |
|
| 70 |
static GApplication * |
| 71 |
test_application_new (const gchar *application_id, |
| 72 |
GApplicationFlags flags) |
| 73 |
{ |
| 74 |
g_return_val_if_fail (g_application_id_is_valid (application_id), NULL); |
| 75 |
|
| 76 |
return g_object_new (test_application_get_type (), |
| 77 |
"application-id", application_id, |
| 78 |
"flags", flags, |
| 79 |
NULL); |
| 80 |
} |
| 81 |
|
| 82 |
int |
| 83 |
main (int argc, char **argv) |
| 84 |
{ |
| 85 |
GApplication *app; |
| 86 |
int status; |
| 87 |
|
| 88 |
app = test_application_new ("org.gtk.TestApplication", 0); |
| 89 |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); |
| 90 |
g_application_set_inactivity_timeout (app, 10000); |
| 91 |
|
| 92 |
status = g_application_run (app, argc, argv); |
| 93 |
|
| 94 |
g_object_unref (app); |
| 95 |
|
| 96 |
return status; |
| 97 |
} |