/** * fm_config_load_from_file * @cfg: pointer to configuration * @name: (allow-none): file name to load configuration * * Fills configuration @cfg with data from configuration file. The file * @name may be %NULL to load default configuration file. If @name is * full path then that file will be loaded. Otherwise @name will be * searched in system config directories and after that in ~/.config/ * directory and all found files will be loaded, overwriting existing * data in @cfg. * * See also: fm_config_load_from_key_file() * * Since: 0.1.0 */ void fm_config_load_from_file(FmConfig* cfg, const char* name) { const gchar * const *dirs, * const *dir; char *path; GKeyFile* kf = g_key_file_new(); g_strfreev(cfg->modules_blacklist); g_strfreev(cfg->system_modules_blacklist); cfg->modules_blacklist = NULL; cfg->system_modules_blacklist = NULL; _cfg_monitor_free(cfg); g_free(cfg->_cfg_name); if(G_LIKELY(!name)) name = "libfm/libfm.conf"; else { if(G_UNLIKELY(g_path_is_absolute(name))) { cfg->_cfg_name = g_strdup(name); if(g_key_file_load_from_file(kf, name, 0, NULL)) { fm_config_load_from_key_file(cfg, kf); _cfg_monitor_add(cfg, name); } goto _out; } } cfg->_cfg_name = g_strdup(name); dirs = g_get_system_config_dirs(); /* bug SF #887: first dir in XDG_CONFIG_DIRS is the most relevant so we shoult process the list in reverse order */ dir = dirs; while (*dir) ++dir; while (dir-- != dirs) { path = g_build_filename(*dir, name, NULL); if(g_key_file_load_from_file(kf, path, 0, NULL)) fm_config_load_from_key_file(cfg, kf); g_free(path); } /* we got all system blacklists, save them and get user's one */ cfg->system_modules_blacklist = cfg->modules_blacklist; cfg->modules_blacklist = NULL; path = g_build_filename(g_get_user_config_dir(), name, NULL); if(g_key_file_load_from_file(kf, path, 0, NULL)) { fm_config_load_from_key_file(cfg, kf); _cfg_monitor_add(cfg, path); } g_free(path); _out: g_key_file_free(kf); g_signal_emit(cfg, signals[CHANGED], 0); /* FIXME: compare and send individual changes instead */ }
/** * fm_config_load_from_file * @cfg: pointer to configuration * @name: (allow-none): file name to load configuration * * Fills configuration @cfg with data from configuration file. The file * @name may be %NULL to load default configuration file. If @name is * full path then that file will be loaded. Otherwise @name will be * searched in system config directories and after that in ~/.config/ * directory and all found files will be loaded, overwriting existing * data in @cfg. * * See also: fm_config_load_from_key_file() * * Since: 0.1.0 */ void fm_config_load_from_file(FmConfig* cfg, const char* name) { const gchar * const *dirs, * const *dir; char *path; GKeyFile* kf = g_key_file_new(); g_strfreev(cfg->modules_blacklist); g_strfreev(cfg->system_modules_blacklist); cfg->modules_blacklist = NULL; cfg->system_modules_blacklist = NULL; if(G_LIKELY(!name)) name = "libfm/libfm.conf"; else { if(G_UNLIKELY(g_path_is_absolute(name))) { cfg->_cfg_name = g_strdup(name); if(g_key_file_load_from_file(kf, name, 0, NULL)) fm_config_load_from_key_file(cfg, kf); goto _out; } } cfg->_cfg_name = g_strdup(name); dirs = g_get_system_config_dirs(); for(dir=dirs;*dir;++dir) { path = g_build_filename(*dir, name, NULL); if(g_key_file_load_from_file(kf, path, 0, NULL)) fm_config_load_from_key_file(cfg, kf); g_free(path); } path = g_build_filename(SYSCONF_DIR, name, NULL); if(g_key_file_load_from_file(kf, path, 0, NULL)) fm_config_load_from_key_file(cfg, kf); g_free(path); /* we got all system blacklists, save them and get user's one */ cfg->system_modules_blacklist = cfg->modules_blacklist; cfg->modules_blacklist = NULL; path = g_build_filename(g_get_user_config_dir(), name, NULL); if(g_key_file_load_from_file(kf, path, 0, NULL)) fm_config_load_from_key_file(cfg, kf); g_free(path); _out: g_key_file_free(kf); g_signal_emit(cfg, signals[CHANGED], 0); }