]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
If blocks config. entry doesn't exist in theme error out, instead of
authorJames Antill <james@and.org>
Fri, 7 Feb 2003 19:14:16 +0000 (19:14 +0000)
committerJames Antill <james@src.gnome.org>
Fri, 7 Feb 2003 19:14:16 +0000 (19:14 +0000)
2003-02-07  James Antill  <james@and.org>

        * src/config.c (config_loadtheme): If blocks config. entry doesn't
        exist in theme error out, instead of crashing.
        (config_getthemeinfo): Use empty values, if author and/or
        description doesn't exist.
        (config_loadconfig): Don't crash if current_theme or midicmd don't
        exist.
        (config_loadconfig): Change currenttheme to a GString to fix overflow
        truncate problems.

ChangeLog
src/config.c
src/config.h
src/dialogs.c

index 4329db8acb11f4d13011229eff4698c93b13c9c5..8a3f79640df3cf9ac529e79b0effe23c06b3e880 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-02-07  James Antill  <james@and.org>
+
+       * src/config.c (config_loadtheme): If blocks config. entry doesn't
+       exist in theme error out, instead of crashing.
+       (config_getthemeinfo): Use empty values, if author and/or
+       description doesn't exist.
+       (config_loadconfig): Don't crash if current_theme or midicmd don't
+       exist.
+       (config_loadconfig): Change currenttheme to a GString to fix overflow
+       truncate problems.
+
 2003-02-06  Jordi Mallach  <jordi@sindominio.net>
 
        * src/config.c (config_loadconfig): remove unused variable.
index a4e11be85bf808db1cbfc86cefea8a1d66dc10b1..2d270c3a42ca5a52898cd9a9232069c07b8c3c65 100644 (file)
@@ -40,7 +40,7 @@
 char blocksfile[1024];
 int bsize;
 
-char currenttheme[1024];
+GString *currenttheme = NULL;
 
 extern GConfClient *gconf_client;
 
@@ -83,32 +83,28 @@ void config_loadtheme (const gchar *themedir)
     gnome_config_push_prefix (buf);
 
     p = gnome_config_get_string ("Theme/Name");
-    if (p == 0) {
-      GtkWidget *mb;
-      mb = gtk_message_dialog_new (NULL,
-                                   0,
-                                   GTK_MESSAGE_WARNING,
-                                   GTK_BUTTONS_OK,
-                                   _("Warning: theme does not have a name"));
-      gtk_dialog_run (GTK_DIALOG (mb));
-      gtk_widget_destroy (mb);
-    }
-    else g_free (p);
+    if (!p)
+      goto bad_theme;
+    g_free (p);
 
-    p = gnome_config_get_string ("Graphics/Blocks=blocks.png");
+    p = gnome_config_get_string ("Graphics/Blocks=blocks.png")
+    if (!p)
+      goto bad_theme;
+    
     GTET_O_STRCPY(blocksfile, themedir);
     GTET_O_STRCAT(blocksfile, p);
     g_free (p);
     bsize = gnome_config_get_int ("Graphics/BlockSize=16");
 
     p = gnome_config_get_string ("Sounds/MidiFile");
-    if (p) {
+    if (!p)
+        midifile[0] = 0;
+    else
+    {
         GTET_O_STRCPY(midifile, themedir);
         GTET_O_STRCAT(midifile, p);
         g_free (p);
     }
-    else
-        midifile[0] = 0;
 
     for (i = 0; i < S_NUM; i ++) {
         p = gnome_config_get_string (soundkeys[i]);
@@ -124,12 +120,27 @@ void config_loadtheme (const gchar *themedir)
     sound_cache ();
 
     gnome_config_pop_prefix ();
+
+    return;
+
+ bad_theme:
+    {
+      GtkWidget *mb;
+      mb = gtk_message_dialog_new (NULL,
+                                   0,
+                                   GTK_MESSAGE_WARNING,
+                                   GTK_BUTTONS_OK,
+                                   _("Warning: theme does not have a name"));
+      gtk_dialog_run (GTK_DIALOG (mb));
+      gtk_widget_destroy (mb);
+    }
 }
 
 /* Arrggh... all these params are sizeof() == 1024 ... this needs a real fix */
 int config_getthemeinfo (char *themedir, char *name, char *author, char *desc)
 {
-    char buf[1024], *p;
+    char buf[1024];
+    const char *p = NULL;
 
     GTET_O_STRCPY (buf, "=");
     GTET_O_STRCAT (buf, themedir);
@@ -146,13 +157,11 @@ int config_getthemeinfo (char *themedir, char *name, char *author, char *desc)
         if (name) GTET_STRCPY(name, p, 1024);
         g_free (p);
     }
-    if (author) {
-        p = gnome_config_get_string ("Theme/Author=");
+    if (author && (p = gnome_config_get_string ("Theme/Author="))) {
         GTET_STRCPY(author, p, 1024);
         g_free (p);
     }
-    if (desc) {
-        p = gnome_config_get_string ("Theme/Description=");
+    if (desc && (p = gnome_config_get_string ("Theme/Description="))) {
         GTET_STRCPY(desc, p, 1024);
         g_free (p);
     }
@@ -166,29 +175,34 @@ void config_loadconfig (void)
 {
     int l;
     gchar *p;
+
+    currenttheme = g_string_sized_new(100);
     
     /* get the current theme */
     p = gconf_client_get_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", NULL);
     /* if there is no theme configured, then we fallback to DEFAULTTHEME */
-    if (strlen (p) == 0) 
+    if (!p || !p[0])
     {
       g_free (p);
-      p = g_strdup (DEFAULTTHEME);
-      gconf_client_set_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", p, NULL);
+      g_string_assign(currenttheme, DEFAULTTHEME);
+      gconf_client_set_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", currenttheme->str, NULL);
     }
-    GTET_O_STRCPY(currenttheme, p);
+    else
+      g_string_assign(currenttheme, p);
     g_free (p);
+    
     /* add trailing slash if none exists */
-    l = strlen(currenttheme);
-    if (currenttheme[l-1] != '/') {
-      GTET_O_STRCAT(currenttheme, "/");
-    }
+    if (currenttheme->str[currenttheme->len - 1] != '/')
+      g_string_append_c(currenttheme, '/');
 
     /* get the midi player */
     p = gconf_client_get_string (gconf_client, "/apps/gtetrinet/sound/midi_player", NULL);
-    GTET_O_STRCPY(midicmd, p);
-    g_free (p);
-
+    if (p)
+    {
+      GTET_O_STRCPY(midicmd, p);
+      g_free (p);
+    }
+    
     /* get the other sound options */
     soundenable = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/sound/enable_sound", NULL);
     midienable  = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/sound/enable_midi",  NULL);
@@ -287,13 +301,13 @@ void config_loadconfig (void)
     else
       keys[K_GAMEMSG] = defaultkeys[K_GAMEMSG];
 
-    config_loadtheme (currenttheme);
+    config_loadtheme (currenttheme->str);
 }
 
 void load_theme (const gchar *theme_dir)
 {
   /* load the theme */
-  GTET_O_STRCPY (currenttheme, theme_dir);
+  g_string_assign(currenttheme, theme_dir);
   config_loadtheme (theme_dir);
 
   /* update the fields */
index 5fae7052e6216dd8b55c7220809b146d03c8a9ba..f8a23f6d7992eeb6ceea3d8b073130e2071372ec 100644 (file)
@@ -2,7 +2,7 @@
 
 extern char blocksfile[1024];
 extern int bsize;
-extern gchar currenttheme[1024];
+extern GString *currenttheme;
 extern guint keys[];
 extern guint defaultkeys[];
 
index 68c3193e8582bb869b0fd4a8271a060b15ac4f17..4caeae3eb3ca404c07d7104bf14a9f87ad339829 100644 (file)
@@ -757,7 +757,7 @@ void prefdialog_themelist ()
         text[1] = 0;
         gtk_list_store_append (theme_store, &iter);
         gtk_list_store_set (theme_store, &iter, 0, themes[i].name, 1, i, -1);
-        if (strcmp (themes[i].dir, currenttheme) == 0)
+        if (strcmp (themes[i].dir, currenttheme->str) == 0)
         {
             iter_selected = iter;
             theme_select = i;