fix startup in case the dav config doesn't exist default tip

Sun, 06 Oct 2024 18:43:06 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Oct 2024 18:43:06 +0200
changeset 50
9c25e2616bfa
parent 49
2f71f4ee247a

fix startup in case the dav config doesn't exist

application/config.c file | annotate | diff | comparison | revisions
ui/gtk/image.c file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/application/config.c	Sun Oct 06 18:18:04 2024 +0200
+++ b/application/config.c	Sun Oct 06 18:43:06 2024 +0200
@@ -118,42 +118,47 @@
     return cx_mutstrn(buf.space, buf.size);
 }
 
-int load_config(DavContext* ctx) {
+int load_config(DavContext *ctx) {
     context = ctx;
     // TODO: free the config somewhere
     repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
     keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
-
-    char* pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
+    
+    char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
     pstore = pwdstore_open(pwfile);
     free(pwfile);
-
-    char* file = util_concat_path(ENV_HOME, ".dav/config.xml");
-
+    
+    char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
+    
     struct stat s;
-    if (stat(file, &s)) {
-        switch (errno) {
-        case ENOENT: {
-            return 0;
-        }
-        default: {
-            perror("Cannot load config.xml");
-        }
+    if(stat(file, &s)) {
+        switch(errno) {
+            case ENOENT: {
+                davconfig = dav_config_new(NULL);
+                return 0;
+            }
+            default: {
+                perror("Cannot load config.xml");
+            }
         }
         return 1;
     }
-
+    
     cxmutstr config_content = config_load_file(file);
     int config_error;
     davconfig = dav_config_load(config_content, &config_error);
     free(config_content.ptr);
     free(file);
-
-    if (!davconfig) {
+    
+    if(!davconfig) {
         fprintf(stderr, "Cannot load config.xml\n");
         return 1;
     }
-
+    
+    if(dav_config_register_namespaces(davconfig, ctx)) {
+        return 1;
+    }
+    
     return dav_config_register_keys(davconfig, ctx, load_key_file);
 }
 
--- a/ui/gtk/image.c	Sun Oct 06 18:18:04 2024 +0200
+++ b/ui/gtk/image.c	Sun Oct 06 18:43:06 2024 +0200
@@ -117,7 +117,7 @@
 }
 
 UiIcon* ui_fileicon(size_t size) {
-    return ui_icon("application-x-generic", size);
+    return ui_icon("file", size);
 }
 
 UiIcon* ui_icon_unscaled(const char *name, int size) {
--- a/ui/gtk/list.c	Sun Oct 06 18:18:04 2024 +0200
+++ b/ui/gtk/list.c	Sun Oct 06 18:43:06 2024 +0200
@@ -114,20 +114,24 @@
                     case UI_ICON_TEXT_FREE: {
                         UiIcon *icon = data;
 #if GTK_MAJOR_VERSION >= 4
-                        GValue iconvalue = G_VALUE_INIT;
-                        g_value_init(&iconvalue, G_TYPE_OBJECT);
-                        g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
-                        gtk_list_store_set_value(store, &iter, c, &iconvalue);
+                        if(icon) {
+                            GValue iconvalue = G_VALUE_INIT;
+                            g_value_init(&iconvalue, G_TYPE_OBJECT);
+                            g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
+                            gtk_list_store_set_value(store, &iter, c, &iconvalue);
+                        }
 #else
                         GValue pixbufvalue = G_VALUE_INIT;
-                        if(!icon->pixbuf && icon->info) {
-                            GError *error = NULL;
-                            GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
-                            icon->pixbuf = pixbuf;
+                        if(icon) {
+                            if(!icon->pixbuf && icon->info) {
+                                GError *error = NULL;
+                                GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
+                                icon->pixbuf = pixbuf;
+                            }
+                            g_value_init(&pixbufvalue, G_TYPE_OBJECT);
+                            g_value_set_object(&pixbufvalue, icon->pixbuf);
+                            gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
                         }
-                        g_value_init(&pixbufvalue, G_TYPE_OBJECT);
-                        g_value_set_object(&pixbufvalue, icon->pixbuf);
-                        gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
 #endif
                         c++;
                         

mercurial