Revision 1913 trunk/nntpgrab_core/configuration.c
| configuration.c (revision 1913) | ||
|---|---|---|
| 564 | 564 | 
                  }  | 
              
| 565 | 565 | 
                   | 
              
| 566 | 566 | 
                  /**  | 
              
| 567 | 
                  * configuration_get_config_folder:  | 
              |
| 568 | 
                  *  | 
              |
| 569 | 
                  * Retrieve the folder where all configuration files can be stored  | 
              |
| 570 | 
                  *  | 
              |
| 571 | 
                  * Returns: The folder where all configuration files can be stored. Needs to be g_free'd after use  | 
              |
| 572 | 
                  */  | 
              |
| 573 | 
                  char *  | 
              |
| 574 | 
                  configuration_get_config_folder(void)  | 
              |
| 575 | 
                  {
                 | 
              |
| 576 | 
                      if (g_getenv("NNTPGRAB_CONFIG_DIR")) {
                 | 
              |
| 577 | 
                          return g_build_path(G_DIR_SEPARATOR_S, g_getenv("NNTPGRAB_CONFIG_DIR"), "NNTPGrab", NULL);
                 | 
              |
| 578 | 
                      } else {
                 | 
              |
| 579 | 
                  return g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "NNTPGrab", NULL);  | 
              |
| 580 | 
                  }  | 
              |
| 581 | 
                  }  | 
              |
| 582 | 
                   | 
              |
| 583 | 
                  /**  | 
              |
| 567 | 584 | 
                  * Load all settings from a local file on the harddrive  | 
              
| 568 | 585 | 
                  *  | 
              
| 569 | 586 | 
                  * @param obj The configuration object  | 
              
| ... | ... | |
| 576 | 593 | 
                  Configuration *config = CONFIGURATION(obj);  | 
              
| 577 | 594 | 
                  GKeyFile *keyfile;  | 
              
| 578 | 595 | 
                  GError *err = NULL;  | 
              
| 596 | 
                  char *config_folder;  | 
              |
| 579 | 597 | 
                  char *filename;  | 
              
| 580 | 598 | 
                  char **groups;  | 
              
| 581 | 599 | 
                  int i;  | 
              
| ... | ... | |
| 583 | 601 | 
                   | 
              
| 584 | 602 | 
                  g_static_rw_lock_writer_lock(&config->rwlock);  | 
              
| 585 | 603 | 
                   | 
              
| 586 | 
                  // Free the already known settings  | 
              |
| 604 | 
                  /* Free the already known settings */  | 
              |
| 587 | 605 | 
                  list = config->servers;  | 
              
| 588 | 606 | 
                      while (list) {
                 | 
              
| 589 | 607 | 
                  NGConfigServer *server = list->data;  | 
              
| ... | ... | |
| 596 | 614 | 
                  g_list_free(config->servers);  | 
              
| 597 | 615 | 
                  config->servers = NULL;  | 
              
| 598 | 616 | 
                   | 
              
| 599 | 
                  // Try to load the config file  | 
              |
| 600 | 
                      if (g_getenv("NNTPGRAB_CONFIG_DIR")) {
                 | 
              |
| 601 | 
                          filename = g_build_filename(g_getenv("NNTPGRAB_CONFIG_DIR"), "NNTPGrab", "nntpgrab.conf", NULL);
                 | 
              |
| 602 | 
                      } else {
                 | 
              |
| 603 | 
                  filename = g_build_filename(g_get_user_config_dir(), "NNTPGrab", "nntpgrab.conf", NULL);  | 
              |
| 604 | 
                  }  | 
              |
| 617 | 
                  /* Try to load the config file */  | 
              |
| 618 | 
                  config_folder = configuration_get_config_folder();  | 
              |
| 619 | 
                  filename = g_build_filename(config_folder, "nntpgrab.conf", NULL);  | 
              |
| 620 | 
                  g_free(config_folder);  | 
              |
| 621 | 
                   | 
              |
| 605 | 622 | 
                  keyfile = g_key_file_new();  | 
              
| 606 | 623 | 
                      if (!g_key_file_load_from_file(keyfile, filename, G_KEY_FILE_NONE, &err)) {
                 | 
              
| 607 | 624 | 
                  char *tmp;  | 
              
| ... | ... | |
| 907 | 924 | 
                  Configuration *config = CONFIGURATION(obj);  | 
              
| 908 | 925 | 
                  GKeyFile *keyfile;  | 
              
| 909 | 926 | 
                  GError *err = NULL;  | 
              
| 927 | 
                  char *config_folder;  | 
              |
| 910 | 928 | 
                  char *filename;  | 
              
| 911 | 
                  char *dirname;  | 
              |
| 912 | 929 | 
                  char *contents;  | 
              
| 913 | 930 | 
                  GList *list;  | 
              
| 914 | 
                  const char *config_dir;  | 
              |
| 915 | 931 | 
                   | 
              
| 916 | 932 | 
                  g_static_rw_lock_reader_lock(&config->rwlock);  | 
              
| 917 | 933 | 
                   | 
              
| ... | ... | |
| 965 | 981 | 
                  return FALSE;  | 
              
| 966 | 982 | 
                  }  | 
              
| 967 | 983 | 
                   | 
              
| 968 | 
                  // Create the folder ~/.config/NNTPGrab if it didn't exist already  | 
              |
| 969 | 
                      if (g_getenv("NNTPGRAB_CONFIG_DIR")) {
                 | 
              |
| 970 | 
                          config_dir = g_getenv("NNTPGRAB_CONFIG_DIR");
                 | 
              |
| 971 | 
                      } else {
                 | 
              |
| 972 | 
                  config_dir = g_get_user_config_dir();  | 
              |
| 973 | 
                  }  | 
              |
| 984 | 
                  /* Create the folder ~/.config/NNTPGrab if it didn't exist already */  | 
              |
| 985 | 
                  config_folder = configuration_get_config_folder();  | 
              |
| 986 | 
                  g_mkdir_with_parents(config_folder, 0700);  | 
              |
| 974 | 987 | 
                   | 
              
| 975 | 
                  dirname = g_build_path(G_DIR_SEPARATOR_S, config_dir, "NNTPGrab", NULL);  | 
              |
| 976 | 
                  g_mkdir_with_parents(dirname, 0700);  | 
              |
| 977 | 
                  g_free(dirname);  | 
              |
| 988 | 
                  /* Write the configuration to disk */  | 
              |
| 989 | 
                  filename = g_build_filename(config_folder, "nntpgrab.conf", NULL);  | 
              |
| 990 | 
                  g_free(config_folder);  | 
              |
| 978 | 991 | 
                   | 
              
| 979 | 
                  filename = g_build_filename(config_dir, "NNTPGrab", "nntpgrab.conf", NULL);  | 
              |
| 980 | 
                   | 
              |
| 981 | 992 | 
                      if (!g_file_set_contents(filename, contents, -1, &err)) {
                 | 
              
| 982 | 993 | 
                          if (errmsg) {
                 | 
              
| 983 | 994 | 
                              *errmsg = g_strdup_printf(_("configuration_save(): Error while opening file '%s'\n%s"), filename, err->message);
                 | 
              
Also available in: Unified diff
NNTPGrab

