]> Pileus Git - ~andy/gtk/blob - demos/widget-factory/widget-factory.c
7c30f91f185076d1962909feab2e1d278c0995ef
[~andy/gtk] / demos / widget-factory / widget-factory.c
1 /* widget-factory: a collection of widgets in a single page, for easy
2  *                 theming
3  *
4  * Copyright (C) 2011 Canonical Ltd
5  *
6  * This  library is free  software; you can  redistribute it and/or
7  * modify it  under  the terms  of the  GNU Lesser  General  Public
8  * License  as published  by the Free  Software  Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed  in the hope that it will be useful,
12  * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Authored by Andrea Cimitan <andrea.cimitan@canonical.com>
20  *
21  */
22
23 #include "config.h"
24 #include <gtk/gtk.h>
25
26 static void
27 dark_toggled (GtkCheckMenuItem *item, gpointer data)
28 {
29   gboolean dark;
30
31   dark = gtk_check_menu_item_get_active (item);
32   g_object_set (gtk_settings_get_default (),
33                 "gtk-application-prefer-dark-theme", dark,
34                 NULL);
35 }
36
37 static void
38 show_about (GtkMenuItem *item, GtkWidget *window)
39 {
40   GdkPixbuf *pixbuf;
41   const gchar *authors[] = {
42     "Andrea Cimitan",
43     "Cosimo Cecchi",
44     NULL
45   };
46
47   pixbuf = gdk_pixbuf_new_from_resource ("/logos/gtk-logo-256.png", NULL);
48
49   gtk_show_about_dialog (GTK_WINDOW (window),
50                          "program-name", "GTK+ Widget Factory",
51                          "version", g_strdup_printf ("%s,\nRunning against GTK+ %d.%d.%d",
52                                                      PACKAGE_VERSION,
53                                                      gtk_get_major_version (),
54                                                      gtk_get_minor_version (),
55                                                      gtk_get_micro_version ()),
56                          "copyright", "(C) 1997-2009 The GTK+ Team",
57                          "license-type", GTK_LICENSE_LGPL_2_1,
58                          "website", "http://www.gtk.org",
59                          "comments", "Program to demonstrate GTK+ themes and widgets",
60                          "authors", authors,
61                          "logo", pixbuf,
62                          "title", "About GTK+ Widget Factory",
63                          NULL);
64
65   g_object_unref (pixbuf);
66 }
67
68 int
69 main (int argc, char *argv[])
70 {
71   GtkBuilder *builder;
72   GtkWidget  *window;
73   GtkWidget  *widget;
74   gboolean    dark = FALSE;
75
76   gtk_init (&argc, &argv);
77
78   if (argc > 1 && (g_strcmp0 (argv[1], "--dark") == 0))
79     dark = TRUE;
80
81   builder = gtk_builder_new ();
82   gtk_builder_add_from_resource (builder, "/ui/widget-factory.ui", NULL);
83
84   window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
85   gtk_builder_connect_signals (builder, NULL);
86
87   widget = (GtkWidget*) gtk_builder_get_object (builder, "darkmenuitem");
88   g_signal_connect (widget, "toggled", G_CALLBACK (dark_toggled), NULL);
89   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), dark);
90
91   widget = (GtkWidget*) gtk_builder_get_object (builder, "aboutmenuitem");
92   g_signal_connect (widget, "activate", G_CALLBACK (show_about), window);
93
94   g_object_unref (G_OBJECT (builder));
95
96   gtk_widget_show (window);
97   gtk_main ();
98
99   return 0;
100 }