chiark / gitweb /
DisOrder 5.0
[disorder] / disobedience / settings.c
index 0fe1237221cc28cf845e1f78934679bcd76f2894..2c4ffeb3c32f2d2e50e680e8d28ce8e03579918c 100644 (file)
@@ -1,21 +1,19 @@
 /*
  * This file is part of Disobedience
- * Copyright (C) 2007 Richard Kettlewell
+ * Copyright (C) 2007, 2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * 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
+ * the Free Software Foundation, either version 3 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.
- *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /** @file disobedience/settings.c
  * @brief Disobedience settings
@@ -221,25 +219,25 @@ void load_settings(void) {
       if(!strcmp(vec[0], "color")) {
         GdkColor *color;
         if(nvec != 7) {
-          error(0, "%s: malformed '%s' command", path, vec[0]);
+          disorder_error(0, "%s: malformed '%s' command", path, vec[0]);
           continue;
         }
         for(n = 0; n < NSTYLES && strcmp(styles[n].name, vec[1]); ++n)
           ;
         if(n >= NSTYLES) {
-          error(0, "%s: unknown style '%s'", path, vec[1]);
+          disorder_error(0, "%s: unknown style '%s'", path, vec[1]);
           continue;
         }
         for(m = 0; m < NSTATES && strcmp(states[m], vec[2]); ++m)
           ;
         if(m >= NSTATES) {
-          error(0, "%s: unknown state '%s'", path, vec[2]);
+          disorder_error(0, "%s: unknown state '%s'", path, vec[2]);
           continue;
         }
         for(c = 0; c < NCOLORS && strcmp(colors[c].name, vec[3]); ++c)
           ;
         if(c >= NCOLORS) {
-          error(0, "%s: unknown color '%s'", path, vec[3]);
+          disorder_error(0, "%s: unknown color '%s'", path, vec[3]);
           continue;
         }
         color = (GdkColor *)((char *)styles[n].style + colors[c].offset) + m;
@@ -248,13 +246,13 @@ void load_settings(void) {
         color->blue = strtoul(vec[6], 0, 0);
       } else if(!strcmp(vec[0], "browser")) {
         if(nvec != 2) {
-          error(0, "%s: malformed '%s' command", path, vec[0]);
+          disorder_error(0, "%s: malformed '%s' command", path, vec[0]);
           continue;
         }
         browser = vec[1];
       } else
         /* mention errors but otherwise ignore them */
-        error(0, "%s: unknown command '%s'", path, vec[0]);
+        disorder_error(0, "%s: unknown command '%s'", path, vec[0]);
     }
     if(ferror(fp)) {
       fpopup_msg(GTK_MESSAGE_ERROR, "error reading %s: %s",
@@ -264,22 +262,77 @@ void load_settings(void) {
   }
 }
 
-/** @brief Callback used by set_tool_colors() */
-static void set_tool_colors_callback(GtkWidget *w,
-                                     gpointer attribute((unused)) data) {
-  set_tool_colors(w);
+/** @brief Recursively set tool widget colors
+ *
+ * This is currently unused; the idea was to allow for configurability without
+ * allowing GTK+ to override our use of color, but things seem generally better
+ * without this particular call.
+ */
+void set_tool_colors(GtkWidget attribute((unused)) *w) {
 }
 
-/** @brief Recursively set tool widget colors */
-void set_tool_colors(GtkWidget *w) {
-  GtkWidget *child;
+/** @brief Pop up a settings editor widget */
+void popup_settings(void) {
+  static GtkWidget *settings_window;
+  GtkWidget *table;
+  unsigned row, col;
 
-  gtk_widget_set_style(w, tool_style);
-  if(GTK_IS_CONTAINER(w))
-    gtk_container_foreach(GTK_CONTAINER(w), set_tool_colors_callback, 0);
-  if(GTK_IS_MENU_ITEM(w)
-     && (child = gtk_menu_item_get_submenu(GTK_MENU_ITEM(w))))
-    set_tool_colors(child);
+  if(settings_window) { 
+    gtk_window_present(GTK_WINDOW(settings_window));
+    return;
+  }
+  /* Create the window */
+  settings_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  gtk_widget_set_style(settings_window, tool_style);
+  gtk_window_set_title(GTK_WINDOW(settings_window), "Disobedience Settings");
+  /* Clear the pointer to the window widget when it is closed */
+  g_signal_connect(settings_window, "destroy",
+                  G_CALLBACK(gtk_widget_destroyed), &settings_window);
+
+  /* The color settings live in a big table */
+  table = gtk_table_new(2 * NSTYLES + 1/*rows */, NSTATES + 1/*cols*/,
+                        TRUE/*homogeneous*/);
+  /* Titles */
+  for(row = 0; row < 2 * NSTYLES; ++row) {
+    char *legend;
+
+    byte_xasprintf(&legend, "%s %s", styles[row / 2].name,
+                   row % 2 ? "background" : "foreground");
+    gtk_table_attach(GTK_TABLE(table),
+                     gtk_label_new(legend),
+                     0, 1,
+                     row + 1, row + 2,
+                     GTK_FILL, GTK_FILL,
+                     1, 1);
+  }
+  for(col = 0; col < NSTATES; ++col) {
+    gtk_table_attach(GTK_TABLE(table),
+                     gtk_label_new(states[col]),
+                     col + 1, col + 2,
+                     0, 1,
+                     GTK_FILL, GTK_FILL,
+                     1, 1);
+  }
+  /* The actual colors */
+  for(row = 0; row < 2 * NSTYLES; ++row) {
+    for(col = 0; col <  NSTATES; ++col) {
+      GdkColor *const c = &(row % 2
+                            ? (**styles[row / 2].style).bg
+                            : (**styles[row / 2].style).fg)[col];
+      gtk_table_attach(GTK_TABLE(table),
+                       gtk_color_button_new_with_color(c),
+                       col + 1, col + 2,
+                       row + 1, row + 2,
+                       GTK_FILL, GTK_FILL,
+                       1, 1);
+    }
+  }
+  gtk_container_add(GTK_CONTAINER(settings_window), frame_widget(table, NULL));
+  gtk_widget_show_all(settings_window);
+  /* TODO: save settings
+     TODO: web browser
+     TODO: impose settings when they are set
+  */
 }
 
 /*