1 /* GTK - The GIMP Toolkit
2 * testapplication.c: Using GtkApplication
3 * Copyright (C) 2010, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include <gio/gdesktopappinfo.h>
28 static const char *builder_data =
30 "<object class=\"GtkAboutDialog\" id=\"about_dialog\">"
31 " <property name=\"program-name\">Test Application</property>"
32 " <property name=\"website\">http://gtk.org</property>"
34 "<object class=\"GtkActionGroup\" id=\"actions\">"
36 " <object class=\"GtkAction\" id=\"About\">"
37 " <property name=\"name\">About</property>"
38 " <property name=\"stock_id\">gtk-about</property>"
44 static GtkWidget *about_dialog;
47 about_activate (GtkAction *action,
50 gtk_dialog_run (GTK_DIALOG (about_dialog));
51 gtk_widget_hide (GTK_WIDGET (about_dialog));
61 ai = (GAppInfo*)g_desktop_app_info_new_from_filename ("./testapplication.desktop");
62 g_app_info_launch (ai, NULL, NULL, NULL);
66 main (int argc, char **argv)
73 GtkActionGroup *actions;
75 if (argc > 1 && g_strcmp0 (argv[1], "--launch-yourself") == 0)
81 app = gtk_application_new ("org.gtk.TestApp", &argc, &argv);
82 builder = gtk_builder_new ();
83 if (!gtk_builder_add_from_string (builder, builder_data, -1, NULL))
84 g_error ("failed to parse UI");
85 actions = GTK_ACTION_GROUP (gtk_builder_get_object (builder, "actions"));
86 gtk_application_set_action_group (app, actions);
88 action = gtk_action_group_get_action (actions, "About");
89 g_signal_connect (action, "activate", G_CALLBACK (about_activate), app);
91 about_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "about_dialog"));
93 gtk_builder_connect_signals (builder, app);
94 g_object_unref (builder);
96 window = gtk_application_get_window (app);
97 gtk_container_add (GTK_CONTAINER (window), gtk_label_new ("Hello world"));
98 gtk_widget_show_all (GTK_WIDGET (window));
100 window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
101 gtk_container_add (GTK_CONTAINER (window2), gtk_label_new ("Hello again"));
102 gtk_widget_show_all (window2);
103 gtk_application_add_window (app, GTK_WINDOW (window2));
105 gtk_application_run (app);