Commit 3f62a2857c7aba284f1485b6e332c05103960100
1 parent
438e6222
Exists in
master
and in
5 other branches
Fixing problem with default configuration file.
Showing
2 changed files
with
46 additions
and
25 deletions
Show diff stats
src/pw3270/common/config.c
| @@ -29,7 +29,13 @@ | @@ -29,7 +29,13 @@ | ||
| 29 | * | 29 | * |
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | + #define ENABLE_NLS | ||
| 33 | + #define GETTEXT_PACKAGE PACKAGE_NAME | ||
| 34 | + | ||
| 35 | + #include <libintl.h> | ||
| 36 | + #include <glib/gi18n.h> | ||
| 32 | #include <gtk/gtk.h> | 37 | #include <gtk/gtk.h> |
| 38 | + | ||
| 33 | #include "common.h" | 39 | #include "common.h" |
| 34 | #include <stdarg.h> | 40 | #include <stdarg.h> |
| 35 | #include <glib/gstdio.h> | 41 | #include <glib/gstdio.h> |
| @@ -58,7 +64,6 @@ | @@ -58,7 +64,6 @@ | ||
| 58 | #else | 64 | #else |
| 59 | 65 | ||
| 60 | static GKeyFile * program_config = NULL; | 66 | static GKeyFile * program_config = NULL; |
| 61 | - static const gchar * mask = "%s" G_DIR_SEPARATOR_S "%s.conf"; | ||
| 62 | 67 | ||
| 63 | #endif // HAVE_WIN_REGISTRY | 68 | #endif // HAVE_WIN_REGISTRY |
| 64 | 69 | ||
| @@ -192,51 +197,69 @@ | @@ -192,51 +197,69 @@ | ||
| 192 | g_get_user_config_dir, | 197 | g_get_user_config_dir, |
| 193 | g_get_user_data_dir, | 198 | g_get_user_data_dir, |
| 194 | g_get_home_dir, | 199 | g_get_home_dir, |
| 195 | - | ||
| 196 | }; | 200 | }; |
| 197 | - gchar *filename; | ||
| 198 | - int f; | ||
| 199 | 201 | ||
| 200 | - const gchar * const *sysconfig; | 202 | + size_t f; |
| 203 | + g_autofree gchar * name = g_strconcat(g_get_application_name(),".conf",NULL); | ||
| 201 | 204 | ||
| 202 | -#ifdef DEBUG | ||
| 203 | - filename = g_strdup_printf(mask,".",g_get_application_name()); | ||
| 204 | - trace("Checking for %s",filename); | ||
| 205 | - if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | ||
| 206 | - return filename; | ||
| 207 | - g_free(filename); | ||
| 208 | -#endif | 205 | + // |
| 206 | + // First search the user data | ||
| 207 | + // | ||
| 209 | 208 | ||
| 210 | for(f=0;f<G_N_ELEMENTS(dir);f++) | 209 | for(f=0;f<G_N_ELEMENTS(dir);f++) |
| 211 | { | 210 | { |
| 212 | - filename = g_strdup_printf(mask,dir[f](),g_get_application_name()); | 211 | + gchar *filename = g_build_filename(dir[f](),name,NULL); |
| 212 | + | ||
| 213 | trace("Checking for %s",filename); | 213 | trace("Checking for %s",filename); |
| 214 | + | ||
| 214 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | 215 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) |
| 215 | return filename; | 216 | return filename; |
| 216 | g_free(filename); | 217 | g_free(filename); |
| 218 | + | ||
| 217 | } | 219 | } |
| 218 | 220 | ||
| 219 | - sysconfig = g_get_system_config_dirs(); | ||
| 220 | - for(f=0;sysconfig[f];f++) | 221 | +#ifdef DATADIR |
| 222 | + // | ||
| 223 | + // Search the application DATADIR | ||
| 224 | + // | ||
| 221 | { | 225 | { |
| 222 | - filename = g_strdup_printf(mask,sysconfig[f],g_get_application_name()); | 226 | + gchar *filename = g_build_filename(G_STRINGIFY(DATADIR),name,NULL); |
| 227 | + | ||
| 223 | trace("Checking for %s",filename); | 228 | trace("Checking for %s",filename); |
| 229 | + | ||
| 224 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | 230 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) |
| 225 | return filename; | 231 | return filename; |
| 226 | g_free(filename); | 232 | g_free(filename); |
| 233 | + | ||
| 227 | } | 234 | } |
| 235 | +#endif // DATADIR | ||
| 236 | + | ||
| 237 | + // | ||
| 238 | + // Search the system folders | ||
| 239 | + // | ||
| 228 | 240 | ||
| 229 | - sysconfig = g_get_system_data_dirs(); | 241 | + const gchar * const * sysconfig = g_get_system_config_dirs(); |
| 230 | for(f=0;sysconfig[f];f++) | 242 | for(f=0;sysconfig[f];f++) |
| 231 | { | 243 | { |
| 232 | - filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S PACKAGE_NAME G_DIR_SEPARATOR_S "%s.conf",sysconfig[f],g_get_application_name()); | 244 | + gchar *filename = g_build_filename(sysconfig[f],name,NULL); |
| 233 | trace("Checking for %s",filename); | 245 | trace("Checking for %s",filename); |
| 234 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | 246 | if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) |
| 235 | return filename; | 247 | return filename; |
| 236 | g_free(filename); | 248 | g_free(filename); |
| 237 | } | 249 | } |
| 238 | 250 | ||
| 239 | - return g_strdup_printf(mask,g_get_user_config_dir(),g_get_application_name()); | 251 | + const gchar * const * sysdata = g_get_system_data_dirs(); |
| 252 | + for(f=0;sysdata[f];f++) | ||
| 253 | + { | ||
| 254 | + gchar *filename = g_build_filename(sysdata[f],name,NULL); | ||
| 255 | + trace("Checking for %s",filename); | ||
| 256 | + if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | ||
| 257 | + return filename; | ||
| 258 | + g_free(filename); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + return g_build_filename(g_get_user_config_dir(),name); | ||
| 262 | + | ||
| 240 | } | 263 | } |
| 241 | #endif // #ifdef HAVE_WIN_REGISTRY | 264 | #endif // #ifdef HAVE_WIN_REGISTRY |
| 242 | 265 | ||
| @@ -389,6 +412,7 @@ void configuration_init(void) | @@ -389,6 +412,7 @@ void configuration_init(void) | ||
| 389 | 412 | ||
| 390 | if(filename) | 413 | if(filename) |
| 391 | { | 414 | { |
| 415 | + g_message(_("Loading %s"),filename); | ||
| 392 | g_key_file_load_from_file(program_config,filename,G_KEY_FILE_NONE,NULL); | 416 | g_key_file_load_from_file(program_config,filename,G_KEY_FILE_NONE,NULL); |
| 393 | g_free(filename); | 417 | g_free(filename); |
| 394 | } | 418 | } |
| @@ -530,19 +554,16 @@ void configuration_deinit(void) | @@ -530,19 +554,16 @@ void configuration_deinit(void) | ||
| 530 | 554 | ||
| 531 | if(text) | 555 | if(text) |
| 532 | { | 556 | { |
| 533 | - gchar *filename = g_strdup_printf(mask,g_get_user_config_dir(),g_get_application_name()); | 557 | + g_autofree gchar * name = g_strconcat(g_get_application_name(),".conf",NULL); |
| 558 | + g_autofree gchar * filename = g_build_filename(g_get_user_config_dir(),name,NULL); | ||
| 534 | 559 | ||
| 535 | trace("Saving configuration in \"%s\"",filename); | 560 | trace("Saving configuration in \"%s\"",filename); |
| 536 | 561 | ||
| 537 | g_mkdir_with_parents(g_get_user_config_dir(),S_IRUSR|S_IWUSR); | 562 | g_mkdir_with_parents(g_get_user_config_dir(),S_IRUSR|S_IWUSR); |
| 538 | - | ||
| 539 | g_file_set_contents(filename,text,-1,NULL); | 563 | g_file_set_contents(filename,text,-1,NULL); |
| 540 | 564 | ||
| 541 | - g_free(filename); | ||
| 542 | - g_free(text); | ||
| 543 | } | 565 | } |
| 544 | 566 | ||
| 545 | - | ||
| 546 | g_key_file_free(program_config); | 567 | g_key_file_free(program_config); |
| 547 | program_config = NULL; | 568 | program_config = NULL; |
| 548 | 569 |
src/pw3270/main.c
| @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) | @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) | ||
| 307 | { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, | 307 | { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, |
| 308 | { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL }, | 308 | { "datadir", 'd', 0, G_OPTION_ARG_CALLBACK, datadir, N_( "Path to application data files" ), NULL }, |
| 309 | #endif // WIN32 | 309 | #endif // WIN32 |
| 310 | - { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), NULL }, | 310 | + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, |
| 311 | { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), host }, | 311 | { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), host }, |
| 312 | { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, | 312 | { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, |
| 313 | { "systype", 't', 0, G_OPTION_ARG_STRING, &systype, N_( "Host system type" ), "S390" }, | 313 | { "systype", 't', 0, G_OPTION_ARG_STRING, &systype, N_( "Host system type" ), "S390" }, |