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.
23 #include <gio/gdesktopappinfo.h>
25 static const char *builder_data =
27 "<object class=\"GtkAboutDialog\" id=\"about_dialog\">"
28 " <property name=\"program-name\">Test Application</property>"
29 " <property name=\"website\">http://gtk.org</property>"
31 "<object class=\"GtkActionGroup\" id=\"actions\">"
33 " <object class=\"GtkAction\" id=\"About\">"
34 " <property name=\"name\">About</property>"
35 " <property name=\"stock_id\">gtk-about</property>"
41 static GtkWidget *about_dialog;
44 about_activate (GtkAction *action,
47 gtk_dialog_run (GTK_DIALOG (about_dialog));
48 gtk_widget_hide (GTK_WIDGET (about_dialog));
58 ai = (GAppInfo*)g_desktop_app_info_new_from_filename ("./testapplication.desktop");
59 g_app_info_launch (ai, NULL, NULL, NULL);
63 main (int argc, char **argv)
70 GtkActionGroup *actions;
72 if (argc > 1 && strcmp (argv[1], "--launch-yourself") == 0)
78 app = gtk_application_new ("org.gtk.TestApp", &argc, &argv);
79 builder = gtk_builder_new ();
80 if (!gtk_builder_add_from_string (builder, builder_data, -1, NULL))
81 g_error ("failed to parse UI");
82 actions = GTK_ACTION_GROUP (gtk_builder_get_object (builder, "actions"));
83 gtk_application_set_action_group (app, actions);
85 action = gtk_action_group_get_action (actions, "About");
86 g_signal_connect (action, "activate", G_CALLBACK (about_activate), app);
88 about_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "about_dialog"));
90 gtk_builder_connect_signals (builder, app);
91 g_object_unref (builder);
93 window = gtk_application_get_window (app);
94 gtk_container_add (GTK_CONTAINER (window), gtk_label_new ("Hello world"));
95 gtk_widget_show_all (GTK_WIDGET (window));
97 window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
98 gtk_container_add (GTK_CONTAINER (window2), gtk_label_new ("Hello again"));
99 gtk_widget_show_all (GTK_WIDGET (window2));
100 gtk_application_add_window (app, window2);
102 gtk_application_run (app);