mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-25 18:39:00 +02:00
Add some examples to the GApplication docs
This commit is contained in:
50
gio/tests/gapplication-example-open.c
Normal file
50
gio/tests/gapplication-example-open.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <gio/gio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
activate (GApplication *application)
|
||||
{
|
||||
g_application_hold (application);
|
||||
g_print ("activated\n");
|
||||
g_application_release (application);
|
||||
}
|
||||
|
||||
static void
|
||||
open (GApplication *application,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_application_hold (application);
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
{
|
||||
gchar *uri = g_file_get_uri (files[i]);
|
||||
g_print ("open %s\n", uri);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
g_application_release (application);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GApplication *app;
|
||||
int status;
|
||||
|
||||
app = g_application_new ("org.gtk.TestApplication",
|
||||
G_APPLICATION_HANDLES_OPEN);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
g_signal_connect (app, "open", G_CALLBACK (open), NULL);
|
||||
g_application_set_inactivity_timeout (app, 10000);
|
||||
|
||||
status = g_application_run (app, argc, argv);
|
||||
|
||||
g_object_unref (app);
|
||||
|
||||
return status;
|
||||
}
|
Reference in New Issue
Block a user