root / src / prefs_ui.c @ 761
History | View | Annotate | Download (12.2 kB)
| 1 | 527 | hiro | /*
|
|---|---|---|---|
| 2 | 527 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 527 | hiro | * Copyright (C) 1999-2005 Hiroyuki Yamamoto |
| 4 | 527 | hiro | * |
| 5 | 527 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 527 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 527 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 527 | hiro | * (at your option) any later version. |
| 9 | 527 | hiro | * |
| 10 | 527 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 527 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 527 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 527 | hiro | * GNU General Public License for more details. |
| 14 | 527 | hiro | * |
| 15 | 527 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 527 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 527 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 527 | hiro | */ |
| 19 | 527 | hiro | |
| 20 | 527 | hiro | #ifdef HAVE_CONFIG_H
|
| 21 | 527 | hiro | # include "config.h" |
| 22 | 527 | hiro | #endif
|
| 23 | 527 | hiro | |
| 24 | 527 | hiro | #include <glib.h> |
| 25 | 527 | hiro | #include <glib/gi18n.h> |
| 26 | 527 | hiro | #include <gtk/gtk.h> |
| 27 | 527 | hiro | #include <stdio.h> |
| 28 | 527 | hiro | #include <stdlib.h> |
| 29 | 527 | hiro | #include <string.h> |
| 30 | 527 | hiro | #include <unistd.h> |
| 31 | 527 | hiro | #include <errno.h> |
| 32 | 527 | hiro | |
| 33 | 527 | hiro | #include "prefs.h" |
| 34 | 527 | hiro | #include "prefs_ui.h" |
| 35 | 527 | hiro | #include "codeconv.h" |
| 36 | 527 | hiro | #include "utils.h" |
| 37 | 527 | hiro | #include "gtkutils.h" |
| 38 | 527 | hiro | |
| 39 | 527 | hiro | typedef enum |
| 40 | 527 | hiro | {
|
| 41 | 527 | hiro | DUMMY_PARAM |
| 42 | 527 | hiro | } DummyEnum; |
| 43 | 527 | hiro | |
| 44 | 527 | hiro | void prefs_dialog_create(PrefsDialog *dialog)
|
| 45 | 527 | hiro | {
|
| 46 | 527 | hiro | GtkWidget *window; |
| 47 | 527 | hiro | GtkWidget *vbox; |
| 48 | 527 | hiro | GtkWidget *notebook; |
| 49 | 527 | hiro | |
| 50 | 527 | hiro | GtkWidget *confirm_area; |
| 51 | 527 | hiro | GtkWidget *ok_btn; |
| 52 | 527 | hiro | GtkWidget *cancel_btn; |
| 53 | 527 | hiro | GtkWidget *apply_btn; |
| 54 | 527 | hiro | |
| 55 | 527 | hiro | g_return_if_fail(dialog != NULL);
|
| 56 | 527 | hiro | |
| 57 | 527 | hiro | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
| 58 | 527 | hiro | gtk_container_set_border_width (GTK_CONTAINER (window), 8);
|
| 59 | 527 | hiro | gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
| 60 | 527 | hiro | gtk_window_set_modal (GTK_WINDOW (window), TRUE); |
| 61 | 527 | hiro | gtk_window_set_policy (GTK_WINDOW(window), FALSE, TRUE, FALSE); |
| 62 | 527 | hiro | |
| 63 | 527 | hiro | vbox = gtk_vbox_new (FALSE, 6);
|
| 64 | 527 | hiro | gtk_widget_show(vbox); |
| 65 | 527 | hiro | gtk_container_add (GTK_CONTAINER (window), vbox); |
| 66 | 527 | hiro | |
| 67 | 527 | hiro | notebook = gtk_notebook_new (); |
| 68 | 527 | hiro | gtk_widget_show(notebook); |
| 69 | 527 | hiro | gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
|
| 70 | 527 | hiro | gtk_container_set_border_width (GTK_CONTAINER (notebook), 2);
|
| 71 | 527 | hiro | /* GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS); */
|
| 72 | 527 | hiro | gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); |
| 73 | 527 | hiro | |
| 74 | 527 | hiro | gtkut_stock_button_set_create(&confirm_area, |
| 75 | 527 | hiro | &ok_btn, GTK_STOCK_OK, |
| 76 | 527 | hiro | &cancel_btn, GTK_STOCK_CANCEL, |
| 77 | 527 | hiro | &apply_btn, GTK_STOCK_APPLY); |
| 78 | 527 | hiro | gtk_widget_show(confirm_area); |
| 79 | 527 | hiro | gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
|
| 80 | 527 | hiro | gtk_widget_grab_default(ok_btn); |
| 81 | 527 | hiro | |
| 82 | 527 | hiro | dialog->window = window; |
| 83 | 527 | hiro | dialog->notebook = notebook; |
| 84 | 527 | hiro | dialog->confirm_area = confirm_area; |
| 85 | 527 | hiro | dialog->ok_btn = ok_btn; |
| 86 | 527 | hiro | dialog->cancel_btn = cancel_btn; |
| 87 | 527 | hiro | dialog->apply_btn = apply_btn; |
| 88 | 527 | hiro | } |
| 89 | 527 | hiro | |
| 90 | 527 | hiro | void prefs_dialog_destroy(PrefsDialog *dialog)
|
| 91 | 527 | hiro | {
|
| 92 | 527 | hiro | gtk_widget_destroy(dialog->window); |
| 93 | 527 | hiro | dialog->window = NULL;
|
| 94 | 527 | hiro | dialog->notebook = NULL;
|
| 95 | 527 | hiro | dialog->ok_btn = NULL;
|
| 96 | 527 | hiro | dialog->cancel_btn = NULL;
|
| 97 | 527 | hiro | dialog->apply_btn = NULL;
|
| 98 | 527 | hiro | } |
| 99 | 527 | hiro | |
| 100 | 527 | hiro | void prefs_button_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
|
| 101 | 527 | hiro | {
|
| 102 | 527 | hiro | gboolean is_active; |
| 103 | 527 | hiro | |
| 104 | 527 | hiro | is_active = gtk_toggle_button_get_active(toggle_btn); |
| 105 | 527 | hiro | gtk_widget_set_sensitive(widget, is_active); |
| 106 | 527 | hiro | } |
| 107 | 527 | hiro | |
| 108 | 533 | hiro | void prefs_register_ui(PrefParam *param, PrefsUIData *ui_data)
|
| 109 | 533 | hiro | {
|
| 110 | 533 | hiro | GHashTable *param_table; |
| 111 | 533 | hiro | PrefParam *param_; |
| 112 | 533 | hiro | gint i; |
| 113 | 533 | hiro | |
| 114 | 533 | hiro | param_table = prefs_param_table_get(param); |
| 115 | 533 | hiro | |
| 116 | 533 | hiro | for (i = 0; ui_data[i].name != NULL; i++) { |
| 117 | 533 | hiro | param_ = g_hash_table_lookup(param_table, ui_data[i].name); |
| 118 | 533 | hiro | if (param_) {
|
| 119 | 533 | hiro | param_->ui_data = &ui_data[i]; |
| 120 | 533 | hiro | } |
| 121 | 533 | hiro | } |
| 122 | 533 | hiro | |
| 123 | 533 | hiro | prefs_param_table_destroy(param_table); |
| 124 | 533 | hiro | } |
| 125 | 533 | hiro | |
| 126 | 527 | hiro | void prefs_set_dialog(PrefParam *param)
|
| 127 | 527 | hiro | {
|
| 128 | 533 | hiro | PrefsUIData *ui_data; |
| 129 | 527 | hiro | gint i; |
| 130 | 527 | hiro | |
| 131 | 527 | hiro | for (i = 0; param[i].name != NULL; i++) { |
| 132 | 533 | hiro | ui_data = (PrefsUIData *)param[i].ui_data; |
| 133 | 533 | hiro | if (ui_data && ui_data->widget_set_func)
|
| 134 | 533 | hiro | ui_data->widget_set_func(¶m[i]); |
| 135 | 527 | hiro | } |
| 136 | 527 | hiro | } |
| 137 | 527 | hiro | |
| 138 | 527 | hiro | void prefs_set_data_from_dialog(PrefParam *param)
|
| 139 | 527 | hiro | {
|
| 140 | 533 | hiro | PrefsUIData *ui_data; |
| 141 | 527 | hiro | gint i; |
| 142 | 527 | hiro | |
| 143 | 527 | hiro | for (i = 0; param[i].name != NULL; i++) { |
| 144 | 533 | hiro | ui_data = (PrefsUIData *)param[i].ui_data; |
| 145 | 533 | hiro | if (ui_data && ui_data->data_set_func)
|
| 146 | 533 | hiro | ui_data->data_set_func(¶m[i]); |
| 147 | 527 | hiro | } |
| 148 | 527 | hiro | } |
| 149 | 527 | hiro | |
| 150 | 527 | hiro | void prefs_set_dialog_to_default(PrefParam *param)
|
| 151 | 527 | hiro | {
|
| 152 | 527 | hiro | gint i; |
| 153 | 533 | hiro | PrefsUIData *ui_data; |
| 154 | 527 | hiro | PrefParam tmpparam; |
| 155 | 527 | hiro | gchar *str_data = NULL;
|
| 156 | 527 | hiro | gint int_data; |
| 157 | 527 | hiro | gushort ushort_data; |
| 158 | 527 | hiro | gboolean bool_data; |
| 159 | 527 | hiro | DummyEnum enum_data; |
| 160 | 527 | hiro | |
| 161 | 527 | hiro | for (i = 0; param[i].name != NULL; i++) { |
| 162 | 533 | hiro | ui_data = (PrefsUIData *)param[i].ui_data; |
| 163 | 533 | hiro | if (!ui_data || !ui_data->widget_set_func) continue; |
| 164 | 527 | hiro | |
| 165 | 527 | hiro | tmpparam = param[i]; |
| 166 | 527 | hiro | |
| 167 | 527 | hiro | switch (tmpparam.type) {
|
| 168 | 527 | hiro | case P_STRING:
|
| 169 | 527 | hiro | if (tmpparam.defval) {
|
| 170 | 527 | hiro | if (!g_ascii_strncasecmp
|
| 171 | 527 | hiro | (tmpparam.defval, "ENV_", 4)) { |
| 172 | 527 | hiro | str_data = g_strdup |
| 173 | 527 | hiro | (g_getenv(param[i].defval + 4));
|
| 174 | 527 | hiro | tmpparam.data = &str_data; |
| 175 | 527 | hiro | break;
|
| 176 | 527 | hiro | } else if (tmpparam.defval[0] == '~') { |
| 177 | 527 | hiro | str_data = |
| 178 | 624 | hiro | #ifdef G_OS_WIN32
|
| 179 | 624 | hiro | g_strconcat(get_rc_dir(), |
| 180 | 624 | hiro | #else
|
| 181 | 527 | hiro | g_strconcat(get_home_dir(), |
| 182 | 624 | hiro | #endif
|
| 183 | 527 | hiro | param[i].defval + 1,
|
| 184 | 527 | hiro | NULL);
|
| 185 | 527 | hiro | tmpparam.data = &str_data; |
| 186 | 527 | hiro | break;
|
| 187 | 527 | hiro | } |
| 188 | 527 | hiro | } |
| 189 | 527 | hiro | tmpparam.data = &tmpparam.defval; |
| 190 | 527 | hiro | break;
|
| 191 | 527 | hiro | case P_INT:
|
| 192 | 527 | hiro | if (tmpparam.defval)
|
| 193 | 527 | hiro | int_data = atoi(tmpparam.defval); |
| 194 | 527 | hiro | else
|
| 195 | 527 | hiro | int_data = 0;
|
| 196 | 527 | hiro | tmpparam.data = &int_data; |
| 197 | 527 | hiro | break;
|
| 198 | 527 | hiro | case P_USHORT:
|
| 199 | 527 | hiro | if (tmpparam.defval)
|
| 200 | 527 | hiro | ushort_data = atoi(tmpparam.defval); |
| 201 | 527 | hiro | else
|
| 202 | 527 | hiro | ushort_data = 0;
|
| 203 | 527 | hiro | tmpparam.data = &ushort_data; |
| 204 | 527 | hiro | break;
|
| 205 | 527 | hiro | case P_BOOL:
|
| 206 | 527 | hiro | if (tmpparam.defval) {
|
| 207 | 527 | hiro | if (!g_ascii_strcasecmp(tmpparam.defval, "TRUE")) |
| 208 | 527 | hiro | bool_data = TRUE; |
| 209 | 527 | hiro | else
|
| 210 | 527 | hiro | bool_data = atoi(tmpparam.defval) |
| 211 | 527 | hiro | ? TRUE : FALSE; |
| 212 | 527 | hiro | } else
|
| 213 | 527 | hiro | bool_data = FALSE; |
| 214 | 527 | hiro | tmpparam.data = &bool_data; |
| 215 | 527 | hiro | break;
|
| 216 | 527 | hiro | case P_ENUM:
|
| 217 | 527 | hiro | if (tmpparam.defval)
|
| 218 | 527 | hiro | enum_data = (DummyEnum)atoi(tmpparam.defval); |
| 219 | 527 | hiro | else
|
| 220 | 527 | hiro | enum_data = 0;
|
| 221 | 527 | hiro | tmpparam.data = &enum_data; |
| 222 | 527 | hiro | break;
|
| 223 | 527 | hiro | case P_OTHER:
|
| 224 | 527 | hiro | break;
|
| 225 | 527 | hiro | } |
| 226 | 533 | hiro | ui_data->widget_set_func(&tmpparam); |
| 227 | 527 | hiro | g_free(str_data); |
| 228 | 527 | hiro | str_data = NULL;
|
| 229 | 527 | hiro | } |
| 230 | 527 | hiro | } |
| 231 | 527 | hiro | |
| 232 | 527 | hiro | void prefs_set_data_from_entry(PrefParam *pparam)
|
| 233 | 527 | hiro | {
|
| 234 | 533 | hiro | PrefsUIData *ui_data; |
| 235 | 527 | hiro | gchar **str; |
| 236 | 527 | hiro | const gchar *entry_str;
|
| 237 | 527 | hiro | |
| 238 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 239 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 240 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 241 | 527 | hiro | |
| 242 | 533 | hiro | entry_str = gtk_entry_get_text(GTK_ENTRY(*ui_data->widget)); |
| 243 | 527 | hiro | |
| 244 | 527 | hiro | switch (pparam->type) {
|
| 245 | 527 | hiro | case P_STRING:
|
| 246 | 527 | hiro | str = (gchar **)pparam->data; |
| 247 | 527 | hiro | g_free(*str); |
| 248 | 527 | hiro | *str = entry_str[0] ? g_strdup(entry_str) : NULL; |
| 249 | 527 | hiro | break;
|
| 250 | 527 | hiro | case P_USHORT:
|
| 251 | 527 | hiro | *((gushort *)pparam->data) = atoi(entry_str); |
| 252 | 527 | hiro | break;
|
| 253 | 527 | hiro | case P_INT:
|
| 254 | 527 | hiro | *((gint *)pparam->data) = atoi(entry_str); |
| 255 | 527 | hiro | break;
|
| 256 | 527 | hiro | default:
|
| 257 | 527 | hiro | g_warning("Invalid PrefType for GtkEntry widget: %d\n",
|
| 258 | 527 | hiro | pparam->type); |
| 259 | 527 | hiro | } |
| 260 | 527 | hiro | } |
| 261 | 527 | hiro | |
| 262 | 527 | hiro | void prefs_set_entry(PrefParam *pparam)
|
| 263 | 527 | hiro | {
|
| 264 | 533 | hiro | PrefsUIData *ui_data; |
| 265 | 527 | hiro | gchar **str; |
| 266 | 527 | hiro | |
| 267 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 268 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 269 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 270 | 527 | hiro | |
| 271 | 527 | hiro | switch (pparam->type) {
|
| 272 | 527 | hiro | case P_STRING:
|
| 273 | 527 | hiro | str = (gchar **)pparam->data; |
| 274 | 533 | hiro | gtk_entry_set_text(GTK_ENTRY(*ui_data->widget), |
| 275 | 527 | hiro | *str ? *str : "");
|
| 276 | 527 | hiro | break;
|
| 277 | 527 | hiro | case P_INT:
|
| 278 | 533 | hiro | gtk_entry_set_text(GTK_ENTRY(*ui_data->widget), |
| 279 | 527 | hiro | itos(*((gint *)pparam->data))); |
| 280 | 527 | hiro | break;
|
| 281 | 527 | hiro | case P_USHORT:
|
| 282 | 533 | hiro | gtk_entry_set_text(GTK_ENTRY(*ui_data->widget), |
| 283 | 527 | hiro | itos(*((gushort *)pparam->data))); |
| 284 | 527 | hiro | break;
|
| 285 | 527 | hiro | default:
|
| 286 | 527 | hiro | g_warning("Invalid PrefType for GtkEntry widget: %d\n",
|
| 287 | 527 | hiro | pparam->type); |
| 288 | 527 | hiro | } |
| 289 | 527 | hiro | } |
| 290 | 527 | hiro | |
| 291 | 527 | hiro | void prefs_set_data_from_text(PrefParam *pparam)
|
| 292 | 527 | hiro | {
|
| 293 | 533 | hiro | PrefsUIData *ui_data; |
| 294 | 527 | hiro | gchar **str; |
| 295 | 527 | hiro | gchar *text = NULL, *tp = NULL; |
| 296 | 527 | hiro | gchar *tmp, *tmpp; |
| 297 | 527 | hiro | |
| 298 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 299 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 300 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 301 | 533 | hiro | g_return_if_fail(GTK_IS_EDITABLE(*ui_data->widget) || |
| 302 | 533 | hiro | GTK_IS_TEXT_VIEW(*ui_data->widget)); |
| 303 | 527 | hiro | |
| 304 | 527 | hiro | switch (pparam->type) {
|
| 305 | 527 | hiro | case P_STRING:
|
| 306 | 527 | hiro | str = (gchar **)pparam->data; |
| 307 | 527 | hiro | g_free(*str); |
| 308 | 533 | hiro | if (GTK_IS_EDITABLE(*ui_data->widget)) {
|
| 309 | 527 | hiro | tp = text = gtk_editable_get_chars |
| 310 | 533 | hiro | (GTK_EDITABLE(*ui_data->widget), 0, -1); |
| 311 | 533 | hiro | } else if (GTK_IS_TEXT_VIEW(*ui_data->widget)) { |
| 312 | 533 | hiro | GtkTextView *textview = GTK_TEXT_VIEW(*ui_data->widget); |
| 313 | 527 | hiro | GtkTextBuffer *buffer; |
| 314 | 527 | hiro | GtkTextIter start, end; |
| 315 | 527 | hiro | |
| 316 | 527 | hiro | buffer = gtk_text_view_get_buffer(textview); |
| 317 | 527 | hiro | gtk_text_buffer_get_start_iter(buffer, &start); |
| 318 | 527 | hiro | gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
|
| 319 | 527 | hiro | tp = text = gtk_text_buffer_get_text |
| 320 | 527 | hiro | (buffer, &start, &end, FALSE); |
| 321 | 527 | hiro | } |
| 322 | 527 | hiro | |
| 323 | 527 | hiro | g_return_if_fail(tp != NULL && text != NULL); |
| 324 | 527 | hiro | |
| 325 | 527 | hiro | if (text[0] == '\0') { |
| 326 | 527 | hiro | *str = NULL;
|
| 327 | 527 | hiro | g_free(text); |
| 328 | 527 | hiro | break;
|
| 329 | 527 | hiro | } |
| 330 | 527 | hiro | |
| 331 | 527 | hiro | Xalloca(tmpp = tmp, strlen(text) * 2 + 1, |
| 332 | 527 | hiro | { *str = NULL; break; });
|
| 333 | 527 | hiro | while (*tp) {
|
| 334 | 527 | hiro | if (*tp == '\n') { |
| 335 | 527 | hiro | *tmpp++ = '\\';
|
| 336 | 527 | hiro | *tmpp++ = 'n';
|
| 337 | 527 | hiro | tp++; |
| 338 | 527 | hiro | } else
|
| 339 | 527 | hiro | *tmpp++ = *tp++; |
| 340 | 527 | hiro | } |
| 341 | 527 | hiro | *tmpp = '\0';
|
| 342 | 527 | hiro | *str = g_strdup(tmp); |
| 343 | 527 | hiro | g_free(text); |
| 344 | 527 | hiro | break;
|
| 345 | 527 | hiro | default:
|
| 346 | 527 | hiro | g_warning("Invalid PrefType for GtkTextView widget: %d\n",
|
| 347 | 527 | hiro | pparam->type); |
| 348 | 527 | hiro | } |
| 349 | 527 | hiro | } |
| 350 | 527 | hiro | |
| 351 | 527 | hiro | void prefs_set_text(PrefParam *pparam)
|
| 352 | 527 | hiro | {
|
| 353 | 533 | hiro | PrefsUIData *ui_data; |
| 354 | 527 | hiro | gchar *buf, *sp, *bufp; |
| 355 | 527 | hiro | gchar **str; |
| 356 | 527 | hiro | GtkTextView *text; |
| 357 | 527 | hiro | GtkTextBuffer *buffer; |
| 358 | 527 | hiro | GtkTextIter iter; |
| 359 | 527 | hiro | |
| 360 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 361 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 362 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 363 | 527 | hiro | |
| 364 | 527 | hiro | switch (pparam->type) {
|
| 365 | 527 | hiro | case P_STRING:
|
| 366 | 527 | hiro | str = (gchar **)pparam->data; |
| 367 | 527 | hiro | if (*str) {
|
| 368 | 527 | hiro | bufp = buf = alloca(strlen(*str) + 1);
|
| 369 | 527 | hiro | if (!buf) buf = ""; |
| 370 | 527 | hiro | else {
|
| 371 | 527 | hiro | sp = *str; |
| 372 | 527 | hiro | while (*sp) {
|
| 373 | 527 | hiro | if (*sp == '\\' && *(sp + 1) == 'n') { |
| 374 | 527 | hiro | *bufp++ = '\n';
|
| 375 | 527 | hiro | sp += 2;
|
| 376 | 527 | hiro | } else
|
| 377 | 527 | hiro | *bufp++ = *sp++; |
| 378 | 527 | hiro | } |
| 379 | 527 | hiro | *bufp = '\0';
|
| 380 | 527 | hiro | } |
| 381 | 527 | hiro | } else
|
| 382 | 527 | hiro | buf = "";
|
| 383 | 527 | hiro | |
| 384 | 533 | hiro | text = GTK_TEXT_VIEW(*ui_data->widget); |
| 385 | 527 | hiro | buffer = gtk_text_view_get_buffer(text); |
| 386 | 527 | hiro | gtk_text_buffer_set_text(buffer, "", 0); |
| 387 | 527 | hiro | gtk_text_buffer_get_start_iter(buffer, &iter); |
| 388 | 527 | hiro | gtk_text_buffer_insert(buffer, &iter, buf, -1);
|
| 389 | 527 | hiro | break;
|
| 390 | 527 | hiro | default:
|
| 391 | 527 | hiro | g_warning("Invalid PrefType for GtkTextView widget: %d\n",
|
| 392 | 527 | hiro | pparam->type); |
| 393 | 527 | hiro | } |
| 394 | 527 | hiro | } |
| 395 | 527 | hiro | |
| 396 | 527 | hiro | void prefs_set_data_from_toggle(PrefParam *pparam)
|
| 397 | 527 | hiro | {
|
| 398 | 533 | hiro | PrefsUIData *ui_data; |
| 399 | 533 | hiro | |
| 400 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 401 | 527 | hiro | g_return_if_fail(pparam->type == P_BOOL); |
| 402 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 403 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 404 | 527 | hiro | |
| 405 | 527 | hiro | *((gboolean *)pparam->data) = |
| 406 | 533 | hiro | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(*ui_data->widget)); |
| 407 | 527 | hiro | } |
| 408 | 527 | hiro | |
| 409 | 527 | hiro | void prefs_set_toggle(PrefParam *pparam)
|
| 410 | 527 | hiro | {
|
| 411 | 533 | hiro | PrefsUIData *ui_data; |
| 412 | 533 | hiro | |
| 413 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 414 | 527 | hiro | g_return_if_fail(pparam->type == P_BOOL); |
| 415 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 416 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 417 | 527 | hiro | |
| 418 | 533 | hiro | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(*ui_data->widget), |
| 419 | 527 | hiro | *((gboolean *)pparam->data)); |
| 420 | 527 | hiro | } |
| 421 | 527 | hiro | |
| 422 | 527 | hiro | void prefs_set_data_from_spinbtn(PrefParam *pparam)
|
| 423 | 527 | hiro | {
|
| 424 | 533 | hiro | PrefsUIData *ui_data; |
| 425 | 527 | hiro | |
| 426 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 427 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 428 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 429 | 533 | hiro | |
| 430 | 527 | hiro | switch (pparam->type) {
|
| 431 | 527 | hiro | case P_INT:
|
| 432 | 527 | hiro | *((gint *)pparam->data) = |
| 433 | 527 | hiro | gtk_spin_button_get_value_as_int |
| 434 | 533 | hiro | (GTK_SPIN_BUTTON(*ui_data->widget)); |
| 435 | 527 | hiro | break;
|
| 436 | 527 | hiro | case P_USHORT:
|
| 437 | 527 | hiro | *((gushort *)pparam->data) = |
| 438 | 527 | hiro | (gushort)gtk_spin_button_get_value_as_int |
| 439 | 533 | hiro | (GTK_SPIN_BUTTON(*ui_data->widget)); |
| 440 | 527 | hiro | break;
|
| 441 | 527 | hiro | default:
|
| 442 | 527 | hiro | g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
|
| 443 | 527 | hiro | pparam->type); |
| 444 | 527 | hiro | } |
| 445 | 527 | hiro | } |
| 446 | 527 | hiro | |
| 447 | 527 | hiro | void prefs_set_spinbtn(PrefParam *pparam)
|
| 448 | 527 | hiro | {
|
| 449 | 533 | hiro | PrefsUIData *ui_data; |
| 450 | 527 | hiro | |
| 451 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 452 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 453 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 454 | 533 | hiro | |
| 455 | 527 | hiro | switch (pparam->type) {
|
| 456 | 527 | hiro | case P_INT:
|
| 457 | 533 | hiro | gtk_spin_button_set_value(GTK_SPIN_BUTTON(*ui_data->widget), |
| 458 | 527 | hiro | (gfloat)*((gint *)pparam->data)); |
| 459 | 527 | hiro | break;
|
| 460 | 527 | hiro | case P_USHORT:
|
| 461 | 533 | hiro | gtk_spin_button_set_value(GTK_SPIN_BUTTON(*ui_data->widget), |
| 462 | 527 | hiro | (gfloat)*((gushort *)pparam->data)); |
| 463 | 527 | hiro | break;
|
| 464 | 527 | hiro | default:
|
| 465 | 527 | hiro | g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
|
| 466 | 527 | hiro | pparam->type); |
| 467 | 527 | hiro | } |
| 468 | 527 | hiro | } |
| 469 | 527 | hiro | |
| 470 | 527 | hiro | void prefs_set_data_from_fontbtn(PrefParam *pparam)
|
| 471 | 527 | hiro | {
|
| 472 | 533 | hiro | PrefsUIData *ui_data; |
| 473 | 527 | hiro | gchar **str; |
| 474 | 527 | hiro | const gchar *font_str;
|
| 475 | 527 | hiro | |
| 476 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 477 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 478 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 479 | 527 | hiro | |
| 480 | 527 | hiro | font_str = gtk_font_button_get_font_name |
| 481 | 533 | hiro | (GTK_FONT_BUTTON(*ui_data->widget)); |
| 482 | 527 | hiro | |
| 483 | 527 | hiro | switch (pparam->type) {
|
| 484 | 527 | hiro | case P_STRING:
|
| 485 | 527 | hiro | str = (gchar **)pparam->data; |
| 486 | 527 | hiro | g_free(*str); |
| 487 | 527 | hiro | *str = font_str[0] ? g_strdup(font_str) : NULL; |
| 488 | 527 | hiro | break;
|
| 489 | 527 | hiro | default:
|
| 490 | 527 | hiro | g_warning("Invalid PrefType for GtkFontButton widget: %d\n",
|
| 491 | 527 | hiro | pparam->type); |
| 492 | 527 | hiro | } |
| 493 | 527 | hiro | } |
| 494 | 527 | hiro | |
| 495 | 527 | hiro | void prefs_set_fontbtn(PrefParam *pparam)
|
| 496 | 527 | hiro | {
|
| 497 | 533 | hiro | PrefsUIData *ui_data; |
| 498 | 527 | hiro | gchar **str; |
| 499 | 527 | hiro | |
| 500 | 533 | hiro | ui_data = (PrefsUIData *)pparam->ui_data; |
| 501 | 533 | hiro | g_return_if_fail(ui_data != NULL);
|
| 502 | 533 | hiro | g_return_if_fail(*ui_data->widget != NULL);
|
| 503 | 527 | hiro | |
| 504 | 527 | hiro | switch (pparam->type) {
|
| 505 | 527 | hiro | case P_STRING:
|
| 506 | 527 | hiro | str = (gchar **)pparam->data; |
| 507 | 533 | hiro | gtk_font_button_set_font_name(GTK_FONT_BUTTON(*ui_data->widget), |
| 508 | 527 | hiro | *str ? *str : "");
|
| 509 | 527 | hiro | break;
|
| 510 | 527 | hiro | default:
|
| 511 | 527 | hiro | g_warning("Invalid PrefType for GtkFontButton widget: %d\n",
|
| 512 | 527 | hiro | pparam->type); |
| 513 | 527 | hiro | } |
| 514 | 527 | hiro | } |