1 /* main.c -- M17N input method configuration tool
3 National Institute of Advanced Industrial Science and Technology (AIST)
4 Registration Number H15PRO112
6 This file is part of the m17n-im-config package; a sub-part of the
9 The m17n library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public License
11 as published by the Free Software Foundation; either version 2.1 of
12 the License, or (at your option) any later version.
14 The m17n library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with the m17n library; if not, write to the Free
21 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 #define _(String) gettext (String)
29 #include <m17n-im-config.h>
31 /* Common argument to all callback functions. */
33 struct CallbackArgument
35 /* IM configuration widget created by mim_config_new (). */
37 /* Button widget "default" */
39 /* Button widget "revert" */
41 /* Button widget "save" */
46 /* Called when the status of configuration is changed. */
48 status_changed_cb (GtkWidget *config, gpointer data)
50 struct CallbackArgument *arg = data;
51 gboolean modified = mim_config_modified (config);
53 if (GTK_WIDGET_SENSITIVE (arg->save))
57 gtk_widget_set_sensitive (arg->revert, FALSE);
58 gtk_widget_set_sensitive (arg->save, FALSE);
65 gtk_widget_set_sensitive (arg->revert, TRUE);
66 gtk_widget_set_sensitive (arg->save, TRUE);
71 /* Called when "default" button is clicked. */
73 default_clicked_cb (GtkButton *button, gpointer data)
75 struct CallbackArgument *arg = data;
77 mim_config_default (arg->config);
78 status_changed_cb (arg->config, data);
81 /* Called when "revert" button is clicked. */
83 revert_clicked_cb (GtkButton *button, gpointer data)
85 struct CallbackArgument *arg = data;
87 mim_config_revert (arg->config);
88 status_changed_cb (arg->config, data);
91 /* Called when "save" button is clicked. */
93 save_clicked_cb (GtkButton *button, gpointer data)
95 struct CallbackArgument *arg = data;
97 mim_config_save (arg->config);
98 status_changed_cb (arg->config, data);
101 /* Called when "quit" button is clicked. */
103 quit_clicked_cb (GtkButton *button, gpointer data)
105 struct CallbackArgument *arg = data;
107 if (mim_config_modified (arg->config))
109 GtkWidget *dialog, *label;
112 dialog = (gtk_dialog_new_with_buttons
114 GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))),
115 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
116 GTK_STOCK_NO, GTK_RESPONSE_NO,
117 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
118 GTK_STOCK_SAVE, GTK_RESPONSE_YES,
120 label = gtk_label_new (_("Save configuration?"));
121 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
122 gtk_widget_show_all (dialog);
123 response = gtk_dialog_run (GTK_DIALOG (dialog));
124 gtk_widget_destroy (dialog);
125 if (response == GTK_RESPONSE_CANCEL)
127 if (response == GTK_RESPONSE_YES)
128 mim_config_save (arg->config);
130 gtk_widget_destroy (arg->config);
134 /* Called when "ok" button is clicked. */
136 ok_clicked_cb (GtkButton *button, gpointer data)
138 struct CallbackArgument *arg = data;
140 if (mim_config_modified (arg->config))
141 mim_config_save (arg->config);
142 gtk_widget_destroy (arg->config);
147 main (int argc, char **argv)
149 GtkWidget *window, *vbox, *hbox;
150 GtkWidget *default_, *revert, *save, *ok, *quit;
151 struct CallbackArgument arg;
154 bindtextdomain ("m17n-im-config", GETTEXTDIR);
155 bind_textdomain_codeset ("m17n-im-config", "UTF-8");
157 gtk_init (&argc, &argv);
159 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
160 gtk_widget_set_size_request (window, 500, 300);
161 gtk_window_set_title (GTK_WINDOW (window), _("M17N-IM Configuration"));
162 g_signal_connect (G_OBJECT (window), "destroy",
163 G_CALLBACK (gtk_main_quit), NULL);
165 /* We create these widgets:
166 +-vbox----------------------------------+
167 |+-config------------------------------+|
170 || M17N-IM Configuration ||
173 |+-------------------------------------+|
174 |+-hbox--------------------------------+|
175 ||+-------+ +------+ +----+ +----+ +--+||
176 |||default| |revert| |save| |quit| |ok|||
177 ||+-------+ +------+ +----+ +----+ +--+||
178 |+-------------------------------------+|
179 +---------------------------------------+
182 vbox = gtk_vbox_new (FALSE, 12);
183 gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
184 gtk_container_add (GTK_CONTAINER (window), vbox);
186 default_ = gtk_button_new_from_stock (_("_Default"));
187 revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED);
188 gtk_widget_set_sensitive (revert, FALSE);
189 save = gtk_button_new_from_stock (GTK_STOCK_SAVE);
190 gtk_widget_set_sensitive (save, FALSE);
191 quit = gtk_button_new_from_stock (GTK_STOCK_QUIT);
192 ok = gtk_button_new_from_stock (GTK_STOCK_OK);
196 arg.config = mim_config_new (G_CALLBACK (status_changed_cb), &arg);
197 gtk_box_pack_start (GTK_BOX (vbox), arg.config, TRUE, TRUE, 0);
199 g_signal_connect (G_OBJECT (default_), "clicked",
200 G_CALLBACK (default_clicked_cb), &arg);
201 g_signal_connect (G_OBJECT (revert), "clicked",
202 G_CALLBACK (revert_clicked_cb), &arg);
203 g_signal_connect (G_OBJECT (save), "clicked",
204 G_CALLBACK (save_clicked_cb), &arg);
205 g_signal_connect (G_OBJECT (quit), "clicked",
206 G_CALLBACK (quit_clicked_cb), &arg);
207 g_signal_connect (G_OBJECT (ok), "clicked",
208 G_CALLBACK (ok_clicked_cb), &arg);
210 hbox = gtk_hbutton_box_new ();
211 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
212 gtk_box_set_spacing (GTK_BOX (hbox), 5);
213 gtk_container_add (GTK_CONTAINER (hbox), default_);
214 gtk_container_add (GTK_CONTAINER (hbox), revert);
215 gtk_container_add (GTK_CONTAINER (hbox), save);
216 gtk_container_add (GTK_CONTAINER (hbox), quit);
217 gtk_container_add (GTK_CONTAINER (hbox), ok);
218 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
220 gtk_widget_show_all (window);