/* Copyright (C) 1999 Southern Gold Development * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "gview.h" void checkHit(GtkWidget *widget, gpointer data) { gboolean state; state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget)); if (state) gtk_label_set_text(GTK_LABEL (GTK_BUTTON (widget)->child), _("Yes")); else gtk_label_set_text(GTK_LABEL (GTK_BUTTON (widget)->child), _("No")); } void applyChange(GtkWidget *widget, gpointer data) { config *conf; gint state, depth, cnt; GSList *list; gchar *str; conf = (config *) data; conf->view->slideTime = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (conf->timeOut)) * 1000; conf->view->defGamma = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON (conf->defaultGamma)); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->hiddenFiles)); if (state) conf->view->statCh = conf->view->statCh & 0xfe; else conf->view->statCh = conf->view->statCh | 0x01; state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->persistZoom)); if (state) conf->view->statCh = conf->view->statCh | 0x80; else conf->view->statCh = conf->view->statCh & 0x7f; depth = gdk_visual_get_best_depth(); list = conf->defaultRender; if (depth == 8) cnt = 3; else cnt = 5; while (list) { state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (list->data)); if (state) gdk_imlib_set_render_type(cnt); list = list->next; cnt--; } gtk_label_get(GTK_LABEL (GTK_BIN (conf->backColor)->child), &str); g_free(conf->view->defBackColor); conf->view->defBackColor = g_strdup(str); gtk_widget_destroy(conf->rsp); } void saveChange(GtkWidget *widget, gpointer data) { config *conf; gint state, depth, cnt; GSList *list; gchar *str; #ifdef HAVE_SGC sg_registry *db; #else FILE *fHnd; gchar *outLine, *fname, *home; #endif /* HAVE_SGC */ conf = (config *) data; conf->view->slideTime = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (conf->timeOut)) * 1000; conf->view->defGamma = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON (conf->defaultGamma)); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->hiddenFiles)); if (state) conf->view->statCh = conf->view->statCh & 0xfe; else conf->view->statCh = conf->view->statCh | 0x01; state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->persistZoom)); if (state) conf->view->statCh = conf->view->statCh | 0x80; else conf->view->statCh = conf->view->statCh & 0x7f; depth = gdk_visual_get_best_depth(); list = conf->defaultRender; if (depth == 8) cnt = 3; else cnt = 5; while (list) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (list->data))) { gdk_imlib_set_render_type(cnt); depth = cnt; } list = list->next; cnt--; } gtk_label_get(GTK_LABEL (GTK_BIN (conf->backColor)->child), &str); g_free(conf->view->defBackColor); conf->view->defBackColor = g_strdup(str); #ifdef HAVE_SGC db = sg_registry_init("/etc/registry"); state = conf->view->slideTime / 1000; sg_registry_set_key(db, "Software.gView:SlideTimeOut", SG_TYPE_INT, (gpointer) &state); state = conf->view->defGamma * 100; sg_registry_set_key(db, "Software.gView:DefaultGamma", SG_TYPE_INT, (gpointer) &state); sg_registry_set_key(db, "Software.gView:DefaultRender", SG_TYPE_INT, (gpointer) &depth); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->hiddenFiles)); sg_registry_set_key(db, "Software.gView:ShowHiddenFiles", SG_TYPE_BOOL, (gpointer) &state); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->persistZoom)); sg_registry_set_key(db, "Software.gView:PersistantZoom", SG_TYPE_BOOL, (gpointer) &state); sg_registry_set_key(db, "Software.gView:DefaultBackColor", SG_TYPE_STRING, (gpointer) conf->view->defBackColor); sg_registry_close(db); #else home = getenv("HOME"); fname = g_strconcat(home, "/.gviewrc", NULL); fHnd = fopen(fname, "wb"); g_free(fname); if (fHnd) { outLine = g_strdup_printf("SlideTimeOut %d\n", conf->view->slideTime / 1000); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->hiddenFiles)); if (state) outLine = g_strdup_printf("ShowHiddenFiles 1\n"); else outLine = g_strdup_printf("ShowHiddenFiles 0\n"); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (conf->persistZoom)); if (state) outLine = g_strdup_printf("PersistantZoom 1\n"); else outLine = g_strdup_printf("PersistantZoom 0\n"); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); outLine = g_strdup_printf("DefaultGamma %.0f\n", conf->view->defGamma * 100); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); outLine = g_strdup_printf("DefaultRender %d\n", depth); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); outLine = g_strdup_printf("DefaultBackColor %s\n", conf->view->defBackColor); fwrite((void *) outLine, sizeof(gchar), strlen(outLine), fHnd); g_free(outLine); fclose(fHnd); } #endif /* HAVE_SGC */ gtk_widget_destroy(conf->rsp); } void cancelChange(GtkWidget *widget, gpointer data) { config *conf; conf = (config *) data; gtk_widget_destroy(conf->rsp); } void destroyChange(GtkWidget *widget, gpointer data) { g_free((config *) data); } void colorOK(GtkWidget *widget, gpointer data) { config *conf; gdouble *color; gint val[3]; gchar *hexstr; conf = (config *) data; color = g_malloc(sizeof(gdouble) * 3); hexstr = g_malloc(sizeof(gchar) * 8); gtk_color_selection_get_color(GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (conf->colDiag)->colorsel), color); val[0] = color[0] * 255; val[1] = color[1] * 255; val[2] = color[2] * 255; g_snprintf(hexstr, 8, "#%.2x%.2x%.2x", val[0], val[1], val[2]); gtk_label_set_text(GTK_LABEL (GTK_BIN (conf->backColor)->child), hexstr); gtk_widget_destroy(conf->colDiag); g_free(color); g_free(hexstr); } void colorCancel(GtkWidget *widget, gpointer data) { config *conf; conf = (config *) data; gtk_widget_destroy(conf->colDiag); } void changeColor(GtkWidget *widget, gpointer data) { config *conf; GtkWidget *coldiag; gdouble *color; glong val1; gchar val[3]; conf = (config *) data; color = g_malloc(sizeof(gdouble) * 3); val[0] = conf->view->defBackColor[1]; val[1] = conf->view->defBackColor[2]; val[2] = '\0'; val1 = strtol(val, NULL, 16); color[0] = val1 / 255.0; val[0] = conf->view->defBackColor[3]; val[1] = conf->view->defBackColor[4]; val[2] = '\0'; val1 = strtol(val, NULL, 16); color[1] = val1 / 255.0; val[0] = conf->view->defBackColor[5]; val[1] = conf->view->defBackColor[6]; val[2] = '\0'; val1 = strtol(val, NULL, 16); color[2] = val1 / 255.0; coldiag = gtk_color_selection_dialog_new(_("Choose Background Filler Color")); gtk_color_selection_set_color(GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (coldiag)->colorsel), color); conf->colDiag = coldiag; gtk_widget_destroy(GTK_COLOR_SELECTION_DIALOG(coldiag)->help_button); gtk_signal_connect(GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (coldiag)->ok_button), "clicked", (GtkSignalFunc) colorOK, (gpointer) conf); gtk_signal_connect(GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (coldiag)->cancel_button), "clicked", (GtkSignalFunc) colorCancel, (gpointer) conf); gtk_widget_show(coldiag); g_free(color); } void configWin(GtkWidget *widget, gpointer data) { sgview *view; config *conf; GtkWidget *rsp, *lbl, *btn, *chk, *ent, *fix, *fra; GtkObject *adj; GSList *grp; gint depth, type; view = (sgview *) data; conf = g_malloc(sizeof(config) * 1); conf->view = view; rsp = gtk_window_new(GTK_WINDOW_TOPLEVEL); conf->rsp = rsp; gtk_window_set_title(GTK_WINDOW (rsp), _("Configure gView")); gtk_window_set_position(GTK_WINDOW (rsp), GTK_WIN_POS_MOUSE); gtk_window_set_policy(GTK_WINDOW (rsp), FALSE, FALSE, FALSE); gtk_signal_connect(GTK_OBJECT (rsp), "destroy", (GtkSignalFunc) destroyChange, (gpointer) conf); gtk_container_border_width(GTK_CONTAINER (rsp), 5); fix = gtk_fixed_new(); gtk_container_add(GTK_CONTAINER (rsp), fix); fra = gtk_frame_new(_("General Settings")); gtk_widget_set_usize(GTK_WIDGET (fra), 250, 155); gtk_fixed_put(GTK_FIXED (fix), fra, 0, 0); gtk_widget_show(fra); lbl = gtk_label_new(_("Slide show delay (seconds)")); gtk_fixed_put(GTK_FIXED (fix), lbl, 10, 15); gtk_widget_show (lbl); adj = gtk_adjustment_new(view->slideTime / 1000, 0, 3600, 1, 10, 10); ent = gtk_spin_button_new(GTK_ADJUSTMENT (adj), 1.0, 0); conf->timeOut = ent; gtk_widget_set_usize(GTK_WIDGET (ent), 60, 25); gtk_fixed_put(GTK_FIXED (fix), ent, 180, 10); gtk_widget_show (ent); lbl = gtk_label_new(_("Show hidden directories")); gtk_fixed_put(GTK_FIXED (fix), lbl, 10, 40); gtk_widget_show (lbl); if (view->statCh & 0x01) { chk = gtk_check_button_new_with_label(_("No")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); } else { chk = gtk_check_button_new_with_label(_("Yes")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); } gtk_signal_connect(GTK_OBJECT (chk), "toggled", (GtkSignalFunc) checkHit, NULL); gtk_fixed_put(GTK_FIXED (fix), chk, 180, 35); conf->hiddenFiles = chk; gtk_widget_show(chk); lbl = gtk_label_new(_("Persistant Zoom")); gtk_fixed_put(GTK_FIXED (fix), lbl, 10, 63); gtk_widget_show (lbl); if (view->statCh & 0x80) { chk = gtk_check_button_new_with_label(_("Yes")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); } else { chk = gtk_check_button_new_with_label(_("No")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); } gtk_signal_connect(GTK_OBJECT (chk), "toggled", (GtkSignalFunc) checkHit, NULL); gtk_fixed_put(GTK_FIXED (fix), chk, 180, 58); conf->persistZoom = chk; gtk_widget_show(chk); lbl = gtk_label_new(_("Default gamma setting")); gtk_fixed_put(GTK_FIXED (fix), lbl, 10, 93); gtk_widget_show(lbl); adj = gtk_adjustment_new(view->defGamma, 0.0, 10.0, 0.01, 0.1, 0.1); ent = gtk_spin_button_new(GTK_ADJUSTMENT (adj), 0.1, 2); conf->defaultGamma = ent; gtk_widget_set_usize(GTK_WIDGET (ent), 60, 25); gtk_fixed_put(GTK_FIXED (fix), ent, 180, 88); gtk_widget_show(ent); /*-------------------------------------------------------------------------*/ lbl = gtk_label_new(_("Background color")); gtk_fixed_put(GTK_FIXED(fix), lbl, 10, 125); gtk_widget_show(lbl); btn = gtk_button_new_with_label(view->defBackColor); conf->backColor = btn; gtk_tooltips_set_tip(view->tips, btn, _("Click the button to change the color"), NULL); gtk_widget_set_usize(GTK_WIDGET (btn), 60, 25); gtk_fixed_put(GTK_FIXED (fix), btn, 180, 120); gtk_signal_connect(GTK_OBJECT (btn), "clicked", (GtkSignalFunc) changeColor, (gpointer) conf); gtk_widget_show(btn); /*-------------------------------------------------------------------------*/ depth = gdk_visual_get_best_depth(); fra = gtk_frame_new(_("Default Render Type")); gtk_fixed_put(GTK_FIXED (fix), fra, 0, 160); gtk_widget_show(fra); type = gdk_imlib_get_render_type(); if (depth == 8) { gtk_widget_set_usize(GTK_WIDGET (fra), 250, 65); chk = gtk_radio_button_new_with_label(NULL, _("Plain Palette")); gtk_fixed_put(GTK_FIXED (fix), chk, 5, 175); gtk_widget_show(chk); if (type == 0) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); chk = gtk_radio_button_new_with_label(grp, _("Plain Palette Fast")); gtk_fixed_put(GTK_FIXED (fix), chk, 120, 175); gtk_widget_show(chk); if (type == 1) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); chk = gtk_radio_button_new_with_label(grp, _("Dither Palette")); gtk_fixed_put(GTK_FIXED (fix), chk, 5, 195); gtk_widget_show(chk); if (type == 2) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); chk = gtk_radio_button_new_with_label(grp, _("Dither Palette Fast")); gtk_fixed_put(GTK_FIXED (fix), chk, 120, 195); gtk_widget_show(chk); if (type == 3) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); } else { gtk_widget_set_usize(GTK_WIDGET (fra), 250, 45); chk = gtk_radio_button_new_with_label(NULL, _("Plain True Color")); gtk_fixed_put(GTK_FIXED (fix), chk, 5, 175); gtk_widget_show(chk); if (type == 4) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); chk = gtk_radio_button_new_with_label(grp, _("Dither True Color")); gtk_fixed_put(GTK_FIXED (fix), chk, 120, 175); gtk_widget_show(chk); if (type == 5) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), TRUE); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (chk), FALSE); grp = gtk_radio_button_group(GTK_RADIO_BUTTON (chk)); } conf->defaultRender = grp; fra = gtk_hbox_new(TRUE, 5); gtk_widget_set_usize(GTK_WIDGET (fra), 250, 25); if (depth == 8) { gtk_fixed_put(GTK_FIXED (fix), fra, 0, 230); gtk_widget_set_usize(GTK_WIDGET (rsp), 260, 265); } else { gtk_fixed_put(GTK_FIXED (fix), fra, 0, 210); gtk_widget_set_usize(GTK_WIDGET (rsp), 260, 245); } gAddButtonBox(view, (gpointer) conf, GTK_BOX (fra), _("OK"), _("Apply the changes"), (GtkSignalFunc) applyChange); gAddButtonBox(view, (gpointer) conf, GTK_BOX (fra), _("Save"), _("Save changes to file"), (GtkSignalFunc) saveChange); gAddButtonBox(view, (gpointer) conf, GTK_BOX (fra), _("Cancel"), _("Cancel configuration"), (GtkSignalFunc) cancelChange); gtk_widget_show(fra); gtk_widget_show(fix); gtk_widget_show(rsp); }