[gtk+/wip/gapplication] Add an example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gapplication] Add an example
- Date: Fri, 4 Jun 2010 05:13:22 +0000 (UTC)
commit 685c2e5020009c0c57f70f469e9efd6fe21b47a9
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jun 4 01:11:28 2010 -0400
Add an example
gtk/gtkapplication.c | 33 +++++++++++++++++++
gtk/tests/Makefile.am | 6 +++-
gtk/tests/gtk-example-application.c | 60 +++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 63375ca..e0f2175 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -40,6 +40,29 @@
#include <gdk/x11/gdkx.h>
#endif
+/**
+ * SECTION:gtkapplication
+ * @title: GtkApplication
+ * @short_description: Application class
+ *
+ * #GtkApplication is a class that handles many important aspects
+ * of a GTK+ application in a convenient fashion, without enforcing
+ * a one-size-fits-all application model.
+ *
+ * Currently, GtkApplication handles application uniqueness, provides
+ * some basic scriptability by exporting 'actions', implements some
+ * standard actions itself (such as 'Quit') and provides a main window
+ * whose life-cycle is automatically tied to the life-cycle of your
+ * application.
+ *
+ * <example id="gtkapplication"><title>A simple application</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gtk/tests/gtk-example-application.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
+ */
enum
{
PROP_0,
@@ -162,6 +185,8 @@ gtk_application_receive_activation_data (GVariant *data)
* see g_application_new().
*
* Returns: (transfer full): A newly-referenced #GtkApplication
+ *
+ * Since: 3.0
*/
GtkApplication*
gtk_application_new (gint *argc,
@@ -217,6 +242,8 @@ on_action_sensitive (GtkAction *action,
* </itemizedlist>
*
* It is an error to call this function more than once.
+ *
+ * Since: 3.0
*/
void
gtk_application_set_action_group (GtkApplication *app,
@@ -266,6 +293,8 @@ gtk_application_on_window_destroy (GtkWidget *window,
* any other windows, the default action will be to call gtk_application_quit().
*
* Returns: (transfer none): The default #GtkWindow for this application
+ *
+ * Since: 3.0
*/
GtkWindow *
gtk_application_get_window (GtkApplication *app)
@@ -288,6 +317,8 @@ gtk_application_get_window (GtkApplication *app)
*
* Runs the main loop; see g_application_run().
* The default implementation for #GtkApplication uses gtk_main().
+ *
+ * Since: 3.0
*/
void
gtk_application_run (GtkApplication *app)
@@ -301,6 +332,8 @@ gtk_application_run (GtkApplication *app)
*
* Request the application exit.
* By default, this method will exit the main loop; see gtk_main_quit().
+ *
+ * Since: 3.0
*/
void
gtk_application_quit (GtkApplication *app)
diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am
index cf209a1..803314f 100644
--- a/gtk/tests/Makefile.am
+++ b/gtk/tests/Makefile.am
@@ -20,7 +20,7 @@ progs_ldadd = \
$(top_builddir)/gtk/$(gtktargetlib) \
$(GTK_DEP_LIBS)
-noinst_PROGRAMS = $(TEST_PROGS)
+noinst_PROGRAMS = $(TEST_PROGS) $(SAMPLE_PROGS)
TEST_PROGS += testing
@@ -94,6 +94,10 @@ TEST_PROGS += action
action_SOURCES = action.c
action_LDADD = $(progs_ldadd)
+SAMPLE_PROGS = gtk-example-application
+gtk_example_application_SOURCES = gtk-example-application.c
+gtk_example_application_LDADD = $(progs_ldadd)
+
EXTRA_DIST += \
file-chooser-test-dir/empty \
diff --git a/gtk/tests/gtk-example-application.c b/gtk/tests/gtk-example-application.c
new file mode 100644
index 0000000..4248e0e
--- /dev/null
+++ b/gtk/tests/gtk-example-application.c
@@ -0,0 +1,60 @@
+#include <gtk/gtk.h>
+
+static const char *builder_data =
+"<interface>"
+"<object class=\"GtkAboutDialog\" id=\"about_dialog\">"
+" <property name=\"program-name\">Example Application</property>"
+" <property name=\"website\">http://www.gtk.org</property>"
+"</object>"
+"<object class=\"GtkActionGroup\" id=\"actions\">"
+" <child>"
+" <object class=\"GtkAction\" id=\"About\">"
+" <property name=\"name\">About</property>"
+" <property name=\"stock_id\">gtk-about</property>"
+" </object>"
+" </child>"
+"</object>"
+"</interface>";
+
+static GtkWidget *about_dialog;
+
+static void
+about_activate (GtkAction *action,
+ gpointer user_data)
+{
+ gtk_dialog_run (GTK_DIALOG (about_dialog));
+ gtk_widget_hide (GTK_WIDGET (about_dialog));
+}
+
+int
+main (int argc, char **argv)
+{
+ GtkApplication *app;
+ GtkWindow *window;
+ GtkBuilder *builder;
+ GtkAction *action;
+ GtkActionGroup *actions;
+
+ app = gtk_application_new (&argc, &argv, "org.gtk.Example");
+ builder = gtk_builder_new ();
+ if (!gtk_builder_add_from_string (builder, builder_data, -1, NULL))
+ g_error ("failed to parse UI");
+ actions = GTK_ACTION_GROUP (gtk_builder_get_object (builder, "actions"));
+ gtk_application_set_action_group (app, actions);
+
+ action = gtk_action_group_get_action (actions, "About");
+ g_signal_connect (action, "activate", G_CALLBACK (about_activate), app);
+
+ about_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "about_dialog"));
+
+ gtk_builder_connect_signals (builder, app);
+ g_object_unref (builder);
+
+ window = gtk_application_get_window (app);
+ gtk_container_add (GTK_CONTAINER (window), gtk_label_new ("Hello world"));
+ gtk_widget_show_all (GTK_WIDGET (window));
+
+ gtk_application_run (app);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]