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 "revert" */
39 /* Button widget "save" */
44 /* Called when the status of configuration is changed. */
46 status_changed_cb (GtkWidget *config, gpointer data)
48 struct CallbackArgument *arg = data;
49 gboolean modified = mim_config_modified (config);
51 if (GTK_WIDGET_SENSITIVE (arg->save))
55 gtk_widget_set_sensitive (arg->revert, FALSE);
56 gtk_widget_set_sensitive (arg->save, FALSE);
63 gtk_widget_set_sensitive (arg->revert, TRUE);
64 gtk_widget_set_sensitive (arg->save, TRUE);
69 /* Called when "revert" button is clicked. */
71 revert_clicked_cb (GtkButton *button, gpointer data)
73 struct CallbackArgument *arg = data;
75 mim_config_revert (arg->config);
76 status_changed_cb (arg->config, data);
79 /* Called when "save" button is clicked. */
81 save_clicked_cb (GtkButton *button, gpointer data)
83 struct CallbackArgument *arg = data;
85 mim_config_save (arg->config);
86 status_changed_cb (arg->config, data);
89 /* Called when "quit" button is clicked. */
91 quit_clicked_cb (GtkButton *button, gpointer data)
93 struct CallbackArgument *arg = data;
95 if (mim_config_modified (arg->config))
97 GtkWidget *dialog, *label;
100 dialog = (gtk_dialog_new_with_buttons
102 GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))),
103 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
104 GTK_STOCK_NO, GTK_RESPONSE_NO,
105 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
106 GTK_STOCK_SAVE, GTK_RESPONSE_YES,
108 label = gtk_label_new (_("Save configuration?"));
109 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
110 gtk_widget_show_all (dialog);
111 response = gtk_dialog_run (GTK_DIALOG (dialog));
112 gtk_widget_destroy (dialog);
113 if (response == GTK_RESPONSE_CANCEL)
115 if (response == GTK_RESPONSE_YES)
116 mim_config_save (arg->config);
118 gtk_widget_destroy (arg->config);
122 /* Called when "ok" button is clicked. */
124 ok_clicked_cb (GtkButton *button, gpointer data)
126 struct CallbackArgument *arg = data;
128 if (mim_config_modified (arg->config))
129 mim_config_save (arg->config);
130 gtk_widget_destroy (arg->config);
135 main (int argc, char **argv)
137 GtkWidget *window, *vbox, *hbox;
138 GtkWidget *revert, *save, *ok, *quit;
139 struct CallbackArgument arg;
142 bindtextdomain ("m17n-im-config", GETTEXTDIR);
143 bind_textdomain_codeset ("m17n-im-config", "UTF-8");
145 gtk_init (&argc, &argv);
147 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
148 gtk_widget_set_size_request (window, 500, 300);
149 gtk_window_set_title (GTK_WINDOW (window), _("M17N-IM Configuration"));
150 g_signal_connect (G_OBJECT (window), "destroy",
151 G_CALLBACK (gtk_main_quit), NULL);
153 /* We create these widgets:
154 +-vbox----------------------------------+
155 |+-config------------------------------+|
158 || M17N-IM Configuration ||
161 |+-------------------------------------+|
162 |+-hbox--------------------------------+|
163 || +------+ +----+ +----+ +--+||
164 || |revert| |save| |quit| |ok|||
165 || +------+ +----+ +----+ +--+||
166 |+-------------------------------------+|
167 +---------------------------------------+
170 vbox = gtk_vbox_new (FALSE, 12);
171 gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
172 gtk_container_add (GTK_CONTAINER (window), vbox);
174 revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED);
175 gtk_widget_set_sensitive (revert, FALSE);
176 save = gtk_button_new_from_stock (GTK_STOCK_SAVE);
177 gtk_widget_set_sensitive (save, FALSE);
178 quit = gtk_button_new_from_stock (GTK_STOCK_QUIT);
179 ok = gtk_button_new_from_stock (GTK_STOCK_OK);
183 arg.config = mim_config_new (G_CALLBACK (status_changed_cb), &arg);
184 gtk_box_pack_start (GTK_BOX (vbox), arg.config, TRUE, TRUE, 0);
186 g_signal_connect (G_OBJECT (revert), "clicked",
187 G_CALLBACK (revert_clicked_cb), &arg);
188 g_signal_connect (G_OBJECT (save), "clicked",
189 G_CALLBACK (save_clicked_cb), &arg);
190 g_signal_connect (G_OBJECT (quit), "clicked",
191 G_CALLBACK (quit_clicked_cb), &arg);
192 g_signal_connect (G_OBJECT (ok), "clicked",
193 G_CALLBACK (ok_clicked_cb), &arg);
195 hbox = gtk_hbutton_box_new ();
196 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
197 gtk_box_set_spacing (GTK_BOX (hbox), 5);
198 gtk_container_add (GTK_CONTAINER (hbox), revert);
199 gtk_container_add (GTK_CONTAINER (hbox), save);
200 gtk_container_add (GTK_CONTAINER (hbox), quit);
201 gtk_container_add (GTK_CONTAINER (hbox), ok);
202 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
204 gtk_widget_show_all (window);