1 /*
2 * Copyright (C) 2020 The HIME team, Taiwan
3 * Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
4 *
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 version 2.1
8 * of the License.
9 *
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.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "hime.h"
21
22 static GtkWidget *about_window;
23
24 /* Our usual callback function */
callback_close(GtkWidget * widget,gpointer dummy)25 static void callback_close (GtkWidget *widget, gpointer dummy) {
26 gtk_widget_destroy (about_window);
27 about_window = NULL;
28 }
29
30 /* Create a new about_window */
get_new_about_window(void)31 static GtkWidget *get_new_about_window (void) {
32 GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
33
34 /* Sets attributes of the about_window. */
35 gtk_window_set_title (GTK_WINDOW (window), _ ("About hime"));
36 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
37 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
38
39 /* kill signals */
40 g_signal_connect (
41 G_OBJECT (window), "destroy",
42 G_CALLBACK (callback_close), NULL);
43
44 g_signal_connect (
45 G_OBJECT (window), "delete-event",
46 G_CALLBACK (callback_close), NULL);
47
48 return window;
49 }
50
51 /*
52 * Create a new hbox
53 *
54 * This is the container for the HIME icon image and the version label.
55 */
get_new_hbox(void)56 static GtkWidget *get_new_hbox (void) {
57 GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
58
59 gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
60
61 return hbox;
62 }
63
64 /*
65 * Create a new vbox
66 *
67 * This is the container for everthing under the about window.
68 */
get_new_vbox(void)69 static GtkWidget *get_new_vbox (void) {
70 GtkWidget *vbox = gtk_vbox_new (FALSE, 3);
71 gtk_orientable_set_orientation (
72 GTK_ORIENTABLE (vbox), GTK_ORIENTATION_VERTICAL);
73
74 return vbox;
75 }
76
77 /*
78 * Create a new label for HIME_VERSION (with GIT_HASH)
79 */
get_version_label(void)80 static GtkWidget *get_version_label (void) {
81 GtkWidget *label;
82
83 #if GIT_HAVE
84 label = gtk_label_new ("version " HIME_VERSION "\n(git " GIT_HASH ")");
85 #else
86 label = gtk_label_new ("version " HIME_VERSION);
87 #endif
88
89 return label;
90 }
91
92 /*
93 * Create a new gtk button for close button
94 */
get_close_button(void)95 static GtkWidget *get_close_button (void) {
96 GtkWidget *button = gtk_button_new_with_label (_ ("Close"));
97 g_signal_connect (
98 G_OBJECT (button), "clicked",
99 G_CALLBACK (callback_close), NULL);
100
101 return button;
102 }
103
104 /* Put a child Widget inside the parent box */
box_add(GtkBox * parent,GtkWidget * child)105 static void box_add (GtkBox *parent, GtkWidget *child) {
106 /* no expand, no filling, padding = 3 */
107 gtk_box_pack_start (parent, child, FALSE, FALSE, 3);
108 }
109
create_about_window()110 void create_about_window () {
111
112 if (about_window) {
113 gtk_window_present (GTK_WINDOW (about_window));
114 return;
115 }
116
117 about_window = get_new_about_window ();
118
119 GtkWidget *hbox = get_new_hbox ();
120 GtkWidget *vbox = get_new_vbox ();
121 GtkWidget *separator = gtk_hseparator_new ();
122 GtkWidget *image = gtk_image_new_from_file (SYS_ICON_DIR "/hime.png");
123 GtkWidget *version_label = get_version_label ();
124 GtkWidget *close_button = get_close_button ();
125
126 box_add (GTK_BOX (vbox), hbox);
127 box_add (GTK_BOX (vbox), separator);
128 box_add (GTK_BOX (hbox), image);
129 box_add (GTK_BOX (hbox), version_label);
130 gtk_container_add (GTK_CONTAINER (about_window), vbox);
131 box_add (GTK_BOX (vbox), close_button);
132
133 gtk_widget_show_all (about_window);
134
135 /* Put gtk_label_set_selectable() here so it will not be selected
136 * by default. It is still selectable and can be copied.
137 */
138 gtk_label_set_selectable (GTK_LABEL (version_label), TRUE);
139
140 return;
141 }
142