Commit a6bb7b1f31dfc3ea06841779e0f47f5136977bf1
1 parent
294acfb7
Exists in
develop
Searching for gschemas on standard path.
Showing
1 changed file
with
85 additions
and
79 deletions
Show diff stats
src/objects/settings/gsettings.c
| ... | ... | @@ -30,11 +30,94 @@ |
| 30 | 30 | #include <pw3270/application.h> |
| 31 | 31 | #include <pw3270/window.h> |
| 32 | 32 | |
| 33 | + /* | |
| 34 | + static void failed() { | |
| 35 | + | |
| 36 | + GtkWidget * dialog = gtk_message_dialog_new_with_markup( | |
| 37 | + NULL, | |
| 38 | + 0, | |
| 39 | + GTK_MESSAGE_ERROR, | |
| 40 | + GTK_BUTTONS_CLOSE, | |
| 41 | + _("Can't load system settings") | |
| 42 | + ); | |
| 43 | + | |
| 44 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_("Unable to initialize system settings. Application may crash in unexpected ways")); | |
| 45 | + | |
| 46 | + gtk_window_set_title(GTK_WINDOW(dialog),_("System settings error")); | |
| 47 | + | |
| 48 | + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | |
| 49 | + | |
| 50 | + gtk_widget_show_all(dialog); | |
| 51 | + | |
| 52 | + gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 53 | + | |
| 54 | + gtk_widget_destroy(dialog); | |
| 55 | + | |
| 56 | + g_application_quit(g_application_get_default()); | |
| 57 | + | |
| 58 | + } | |
| 59 | + */ | |
| 60 | + | |
| 33 | 61 | static GSettings * settings_new(const gchar *schema_id) { |
| 34 | 62 | |
| 35 | 63 | GSettings *settings = NULL; |
| 36 | 64 | |
| 37 | -#if defined(DEBUG) | |
| 65 | +#if defined(_WIN32) | |
| 66 | + | |
| 67 | + { | |
| 68 | + g_autofree gchar * pkgdir = g_win32_get_package_installation_directory_of_module(NULL); | |
| 69 | + | |
| 70 | + g_autofree gchar * appdir = g_build_filename(pkgdir,"gschemas.compiled",NULL); | |
| 71 | + g_autofree gchar * sysdir = g_build_filename(pkgdir,"share","glib-2.0","schemas","gschemas.compiled",NULL); | |
| 72 | + | |
| 73 | + const char * names[] = { appdir, sysdir }; | |
| 74 | + size_t ix; | |
| 75 | + | |
| 76 | + for(ix = 0; ix < G_N_ELEMENTS(names); ix++) { | |
| 77 | + | |
| 78 | + if(g_file_test(names[ix],G_FILE_TEST_IS_REGULAR)) { | |
| 79 | + | |
| 80 | + GError * error = NULL; | |
| 81 | + g_autofree gchar *dirname = g_path_get_dirname(names[ix]); | |
| 82 | + | |
| 83 | + GSettingsSchemaSource * source = | |
| 84 | + g_settings_schema_source_new_from_directory( | |
| 85 | + dirname, | |
| 86 | + NULL, | |
| 87 | + TRUE, | |
| 88 | + &error | |
| 89 | + ); | |
| 90 | + | |
| 91 | + if(error) { | |
| 92 | + g_warning("Error loading '%s': %s",names[ix],error->message); | |
| 93 | + g_error_free(error); | |
| 94 | + return NULL; | |
| 95 | + } | |
| 96 | + | |
| 97 | + GSettingsSchema * schema = | |
| 98 | + g_settings_schema_source_lookup( | |
| 99 | + source, | |
| 100 | + schema_id, | |
| 101 | + TRUE); | |
| 102 | + | |
| 103 | + g_message("Loading '%s'",names[ix]); | |
| 104 | + settings = g_settings_new_full(schema, NULL, NULL); | |
| 105 | + | |
| 106 | + g_settings_schema_source_unref(source); | |
| 107 | + | |
| 108 | + if(settings) { | |
| 109 | + g_message("Got gsettings from %s",names[ix]); | |
| 110 | + return settings; | |
| 111 | + } | |
| 112 | + | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + | |
| 117 | + } | |
| 118 | + | |
| 119 | +#elif defined(DEBUG) | |
| 120 | + | |
| 38 | 121 | { |
| 39 | 122 | GError * error = NULL; |
| 40 | 123 | GSettingsSchemaSource * source = |
| ... | ... | @@ -62,89 +145,12 @@ |
| 62 | 145 | |
| 63 | 146 | g_settings_schema_source_unref(source); |
| 64 | 147 | } |
| 65 | -#elif defined(_WIN32) | |
| 66 | - { | |
| 67 | - g_autofree gchar * appdir = g_win32_get_package_installation_directory_of_module(NULL); | |
| 68 | - g_autofree gchar * filename = g_build_filename(appdir,"gschemas.compiled",NULL); | |
| 69 | - | |
| 70 | - // TODO: Scan appdir + filename, appdir + /share/glib-2.0/schemas/ | |
| 71 | - | |
| 72 | - if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) { | |
| 73 | - | |
| 74 | - GError * error = NULL; | |
| 75 | - g_autofree gchar *dirname = g_path_get_dirname(filename); | |
| 76 | - | |
| 77 | - GSettingsSchemaSource * source = | |
| 78 | - g_settings_schema_source_new_from_directory( | |
| 79 | - dirname, | |
| 80 | - NULL, | |
| 81 | - TRUE, | |
| 82 | - &error | |
| 83 | - ); | |
| 84 | - | |
| 85 | - if(error) { | |
| 86 | - g_warning("Error loading '%s': %s",filename,error->message); | |
| 87 | - g_error_free(error); | |
| 88 | - return NULL; | |
| 89 | - } | |
| 90 | - | |
| 91 | - GSettingsSchema * schema = | |
| 92 | - g_settings_schema_source_lookup( | |
| 93 | - source, | |
| 94 | - schema_id, | |
| 95 | - TRUE); | |
| 96 | 148 | |
| 97 | - g_message("Loading '%s'",filename); | |
| 98 | - settings = g_settings_new_full(schema, NULL, NULL); | |
| 99 | - | |
| 100 | - g_settings_schema_source_unref(source); | |
| 101 | - | |
| 102 | - } else { | |
| 103 | - | |
| 104 | -#ifdef DEBUG | |
| 105 | - g_message("Can't find '%s' loading from default path",filename); | |
| 106 | -#endif // DEBUG | |
| 107 | - settings = g_settings_new(schema_id); | |
| 108 | - | |
| 109 | - } | |
| 110 | - } | |
| 111 | 149 | #else |
| 112 | 150 | |
| 113 | -#ifdef DEBUG | |
| 114 | - g_message("Loading '%s' from default path","gschemas.compiled"); | |
| 115 | -#endif // DEBUG | |
| 116 | - | |
| 117 | 151 | settings = g_settings_new(schema_id); |
| 118 | 152 | |
| 119 | -#endif // DEBUG | |
| 120 | - | |
| 121 | - if(!settings) { | |
| 122 | - | |
| 123 | - g_warning("Error loading system settings"); | |
| 124 | - | |
| 125 | - GtkWidget * dialog = gtk_message_dialog_new_with_markup( | |
| 126 | - NULL, | |
| 127 | - 0, | |
| 128 | - GTK_MESSAGE_ERROR, | |
| 129 | - GTK_BUTTONS_CLOSE, | |
| 130 | - _("Can't load system settings") | |
| 131 | - ); | |
| 132 | - | |
| 133 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_("Unable to initialize system settings. Application may crash in unexpected ways")); | |
| 134 | - | |
| 135 | - gtk_window_set_title(GTK_WINDOW(dialog),_("System settings error")); | |
| 136 | - | |
| 137 | - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | |
| 138 | - | |
| 139 | - gtk_widget_show_all(dialog); | |
| 140 | - | |
| 141 | - //g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 142 | - //g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 143 | - gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 144 | - | |
| 145 | - g_application_quit(g_application_get_default()); | |
| 146 | - | |
| 147 | - } | |
| 153 | +#endif | |
| 148 | 154 | |
| 149 | 155 | return settings; |
| 150 | 156 | } | ... | ... |