]> spindle.queued.net Git - midori/commitdiff
Load extension settings from global config folders
authorChristian Dywan <christian@twotoasts.de>
Fri, 2 Oct 2009 21:07:36 +0000 (23:07 +0200)
committerChristian Dywan <christian@twotoasts.de>
Fri, 2 Oct 2009 21:07:36 +0000 (23:07 +0200)
For example, /etc/xdg/midori/extensions/extension_name/config

midori/main.c
midori/midori-extension.c
midori/sokoke.c
midori/sokoke.h

index 738e7f94e323e3153f2bdd9f8677d939ab69b24e..dfe9489f0342a3a59d642dc94427e269a8e07266 100644 (file)
@@ -94,7 +94,7 @@ settings_new_from_file (const gchar* filename,
     {
         if (error->code == G_FILE_ERROR_NOENT)
         {
-            gchar* config_file = sokoke_find_config_filename ("config");
+            gchar* config_file = sokoke_find_config_filename (NULL, "config");
             g_key_file_load_from_file (key_file, config_file,
                                        G_KEY_FILE_KEEP_COMMENTS, NULL);
         }
@@ -1818,7 +1818,7 @@ main (int    argc,
         search_engines = search_engines_new_from_file (config_file, NULL);
         #else
         katze_assign (config_file,
-            sokoke_find_config_filename ("search"));
+            sokoke_find_config_filename (NULL, "search"));
         search_engines = search_engines_new_from_file (config_file, NULL);
         #endif
     }
@@ -1839,7 +1839,7 @@ main (int    argc,
         if (error->code == G_FILE_ERROR_NOENT)
         {
             katze_assign (config_file,
-                sokoke_find_config_filename ("bookmarks.xbel"));
+                sokoke_find_config_filename (NULL, "bookmarks.xbel"));
             midori_array_from_file (bookmarks, config_file, "xbel", NULL);
         }
         else
index ece419fdda65108262acf930fac41284286912a8..27ab9df9e49081d0cb411c312e6b88fe837aef75 100644 (file)
@@ -272,11 +272,21 @@ midori_extension_activate_cb (MidoriExtension* extension,
         if (!g_key_file_load_from_file (extension->priv->key_file, config_file,
                                         G_KEY_FILE_KEEP_COMMENTS, &error))
         {
-            if (error->code != G_FILE_ERROR_NOENT)
+            if (error->code == G_FILE_ERROR_NOENT)
+            {
+                gchar* filename = g_object_get_data (G_OBJECT (extension), "filename");
+                gchar* folder = g_strconcat ("extensions/", filename, NULL);
+                katze_assign (config_file,
+                    sokoke_find_config_filename (folder, "config"));
+                g_key_file_load_from_file (extension->priv->key_file, config_file,
+                                           G_KEY_FILE_KEEP_COMMENTS, NULL);
+            }
+            else
                 printf (_("The configuration of the extension '%s' couldn't be loaded: %s\n"),
                         extension->priv->name, error->message);
             g_error_free (error);
         }
+        g_free (config_file);
     }
 
     while (lsettings)
index bc16970394e312190068b3bc983bd98b3dd53ca0..35b95d5a6e5041af0045086d964bf1fc3697d388 100644 (file)
@@ -963,6 +963,7 @@ sokoke_remove_path (const gchar* path,
 
 /**
  * sokoke_find_config_filename:
+ * @folder: a subfolder
  * @filename: a filename or relative path
  *
  * Looks for the specified filename in the system config
@@ -971,20 +972,24 @@ sokoke_remove_path (const gchar* path,
  * Return value: a full path
  **/
 gchar*
-sokoke_find_config_filename (const gchar* filename)
+sokoke_find_config_filename (const gchar* folder,
+                             const gchar* filename)
 {
     const gchar* const* config_dirs = g_get_system_config_dirs ();
     guint i = 0;
     const gchar* config_dir;
 
+    if (!folder)
+        folder = "";
+
     while ((config_dir = config_dirs[i++]))
     {
-        gchar* path = g_build_filename (config_dir, PACKAGE_NAME, filename, NULL);
+        gchar* path = g_build_filename (config_dir, PACKAGE_NAME, folder, filename, NULL);
         if (g_file_test (path, G_FILE_TEST_EXISTS))
             return path;
         g_free (path);
     }
-    return g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, filename, NULL);
+    return g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder, filename, NULL);
 }
 
 /**
index 9deee903bb8ebbb95bf78c172ae1b75a107064b6..e2dbb210c073d96bd989032b0d9f72255d202679 100644 (file)
@@ -152,7 +152,8 @@ sokoke_remove_path                      (const gchar*    path,
                                          gboolean        ignore_errors);
 
 gchar*
-sokoke_find_config_filename             (const gchar*    filename);
+sokoke_find_config_filename             (const gchar*    folder,
+                                         const gchar*    filename);
 
 gchar*
 sokoke_find_data_filename               (const gchar*    filename);