Commit b8476a9eb3dcafa9f27222418cc8312c0a94786b

Authored by Perry Werneck
1 parent 18d3698b

Fixing gsettings error.

pw3270.cbp
... ... @@ -142,6 +142,10 @@
142 142 <Unit filename="src/objects/settings/dialog.c">
143 143 <Option compilerVar="CC" />
144 144 </Unit>
  145 + <Unit filename="src/objects/settings/gsettings.c">
  146 + <Option compilerVar="CC" />
  147 + </Unit>
  148 + <Unit filename="src/objects/settings/gsettings.cc" />
145 149 <Unit filename="src/objects/settings/widget.c">
146 150 <Option compilerVar="CC" />
147 151 </Unit>
... ...
src/include/pw3270/application.h
... ... @@ -68,6 +68,7 @@ GtkApplication * pw3270_application_new(const gchar *application_id, GApplicatio
68 68 /// @brief Get application settings.
69 69 /// @param app The pw3270 application object.
70 70 /// @return The internal settings object (Do not unref it).
  71 +GSettings * pw3270_application_settings_new();
71 72 GSettings * pw3270_application_get_settings(GApplication *app);
72 73 GList * pw3270_application_get_keypad_models(GApplication *app);
73 74  
... ...
src/objects/application/application.c
... ... @@ -242,8 +242,7 @@ static gboolean on_allow_tabs(const gchar G_GNUC_UNUSED(*option), const gchar *v
242 242 }
243 243  
244 244 static gboolean on_logfile(const gchar G_GNUC_UNUSED(*option), const gchar *value, gpointer G_GNUC_UNUSED(dunno), GError **error) {
245   - pw3270Application *app = PW3270_APPLICATION(g_application_get_default());
246   - pw3270_application_set_log_filename(app,value);
  245 + pw3270_application_set_log_filename(g_application_get_default(),value);
247 246 return TRUE;
248 247 }
249 248  
... ... @@ -580,81 +579,6 @@ void pw3270_application_plugin_call(GApplication *app, const gchar *method, gpoi
580 579 }
581 580  
582 581  
583   -GSettings * pw3270_application_settings_new() {
584   -
585   - GSettings *settings = NULL;
586   -
587   -#if defined(DEBUG)
588   - {
589   - GError * error = NULL;
590   - GSettingsSchemaSource * source =
591   - g_settings_schema_source_new_from_directory(
592   - ".",
593   - NULL,
594   - TRUE,
595   - &error
596   - );
597   -
598   - g_assert_no_error(error);
599   -
600   - GSettingsSchema * schema =
601   - g_settings_schema_source_lookup(
602   - source,
603   - "br.com.bb." G_STRINGIFY(PRODUCT_NAME),
604   - TRUE);
605   -
606   - debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema);
607   -
608   - settings = g_settings_new_full(schema, NULL, NULL);
609   -
610   - g_settings_schema_source_unref(source);
611   - }
612   -#elif defined(_WIN32)
613   - {
614   - lib3270_autoptr(char) filename = lib3270_build_filename("gschemas.compiled",NULL);
615   -
616   - if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) {
617   -
618   - GError * error = NULL;
619   - g_autofree gchar *dirname = g_path_get_dirname(filename);
620   -
621   - GSettingsSchemaSource * source =
622   - g_settings_schema_source_new_from_directory(
623   - dirname,
624   - NULL,
625   - TRUE,
626   - &error
627   - );
628   -
629   - g_assert_no_error(error);
630   -
631   - GSettingsSchema * schema =
632   - g_settings_schema_source_lookup(
633   - source,
634   - "br.com.bb." G_STRINGIFY(PRODUCT_NAME),
635   - TRUE);
636   -
637   - debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema);
638   -
639   - settings = g_settings_new_full(schema, NULL, NULL);
640   -
641   - g_settings_schema_source_unref(source);
642   -
643   - } else {
644   -
645   - settings = g_settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME));
646   -
647   - }
648   - }
649   -#else
650   -
651   - settings = g_settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME));
652   -
653   -#endif // DEBUG
654   -
655   - return settings;
656   -}
657   -
658 582 GList * pw3270_application_get_keypad_models(GApplication *app) {
659 583 g_return_val_if_fail(PW3270_IS_APPLICATION(app),NULL);
660 584 return PW3270_APPLICATION(app)->keypads;
... ...
src/objects/application/private.h
... ... @@ -48,7 +48,6 @@
48 48  
49 49 G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
50 50 G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file);
51   -G_GNUC_INTERNAL GSettings * pw3270_application_settings_new();
52 51  
53 52 // Actions
54 53 G_GNUC_INTERNAL GAction * pw3270_about_action_new();
... ...
src/objects/settings/gsettings.c 0 → 100644
... ... @@ -0,0 +1,123 @@
  1 +/* SPDX-License-Identifier: LGPL-3.0-or-later */
  2 +
  3 +/*
  4 + * Copyright (C) 2021 Perry Werneck <perry.werneck@gmail.com>
  5 + *
  6 + * This program is free software: you can redistribute it and/or modify
  7 + * it under the terms of the GNU Lesser General Public License as published
  8 + * by the Free Software Foundation, either version 3 of the License, or
  9 + * (at your option) any later version.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License
  17 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18 + */
  19 +
  20 + #include <config.h>
  21 +
  22 + #ifndef GETTEXT_PACKAGE
  23 + #define GETTEXT_PACKAGE PACKAGE_NAME
  24 + #endif
  25 +
  26 + #include <libintl.h>
  27 + #include <glib/gi18n.h>
  28 + #include <gtk/gtk.h>
  29 +
  30 + #include <lib3270.h>
  31 + #include <v3270/dialogs.h>
  32 + #include <pw3270/application.h>
  33 + #include <pw3270/window.h>
  34 +
  35 + static GSettings * settings_new(const gchar *schema_id) {
  36 +
  37 + GSettings *settings = NULL;
  38 +
  39 +#if defined(DEBUG)
  40 + {
  41 + GError * error = NULL;
  42 + GSettingsSchemaSource * source =
  43 + g_settings_schema_source_new_from_directory(
  44 + ".",
  45 + NULL,
  46 + TRUE,
  47 + &error
  48 + );
  49 +
  50 + if(v3270_popup_gerror(NULL, &error, "Configuration error", _("Can't load '%s' from current path"), "gschemas.compiled")) {
  51 + return NULL;
  52 + }
  53 +
  54 + GSettingsSchema * schema =
  55 + g_settings_schema_source_lookup(
  56 + source,
  57 + schema_id,
  58 + TRUE
  59 + );
  60 +
  61 + settings = g_settings_new_full(schema, NULL, NULL);
  62 +
  63 + g_settings_schema_source_unref(source);
  64 + }
  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 + if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) {
  71 +
  72 + GError * error = NULL;
  73 + g_autofree gchar *dirname = g_path_get_dirname(filename);
  74 +
  75 + GSettingsSchemaSource * source =
  76 + g_settings_schema_source_new_from_directory(
  77 + dirname,
  78 + NULL,
  79 + TRUE,
  80 + &error
  81 + );
  82 +
  83 + if(v3270_popup_gerror(NULL, &error, "Configuration error", _("Can't load '%s'"), filename)) {
  84 + return NULL;
  85 + }
  86 +
  87 + GSettingsSchema * schema =
  88 + g_settings_schema_source_lookup(
  89 + source,
  90 + schema_id,
  91 + TRUE);
  92 +
  93 + debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema);
  94 +
  95 + g_message("Loading '%s'",filename);
  96 + settings = g_settings_new_full(schema, NULL, NULL);
  97 +
  98 + g_settings_schema_source_unref(source);
  99 +
  100 + } else {
  101 +
  102 + g_message("Loading '%s' from default path","gschemas.compiled");
  103 + settings = g_settings_new(schema_id);
  104 +
  105 + }
  106 + }
  107 +#else
  108 +
  109 + g_message("Loading '%s' from default path","gschemas.compiled");
  110 + settings = g_settings_new(schema_id);
  111 +
  112 +#endif // DEBUG
  113 +
  114 + return settings;
  115 + }
  116 +
  117 + GSettings * pw3270_application_settings_new() {
  118 + return settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME));
  119 + }
  120 +
  121 + GSettings * pw3270_application_window_settings_new() {
  122 + return settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME) ".window");
  123 + }
... ...
src/objects/window/window.c
... ... @@ -880,83 +880,6 @@ void pw3270_application_window_set_active_terminal(GtkWidget *widget, GtkWidget
880 880  
881 881 }
882 882  
883   -GSettings *pw3270_application_window_settings_new() {
884   -
885   - GSettings * settings = NULL;
886   -
887   -#if defined(DEBUG)
888   - {
889   - GError * error = NULL;
890   - GSettingsSchemaSource * source =
891   - g_settings_schema_source_new_from_directory(
892   - ".",
893   - NULL,
894   - TRUE,
895   - &error
896   - );
897   -
898   - g_assert_no_error(error);
899   -
900   - GSettingsSchema * schema =
901   - g_settings_schema_source_lookup(
902   - source,
903   - "br.com.bb." G_STRINGIFY(PRODUCT_NAME) ".window",
904   - TRUE);
905   -
906   - settings = g_settings_new_full(schema, NULL, NULL);
907   -
908   - g_settings_schema_source_unref(source);
909   -
910   - }
911   -#elif defined(_WIN32)
912   - {
913   - lib3270_autoptr(char) filename = lib3270_build_filename("gschemas.compiled",NULL);
914   -
915   - if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) {
916   -
917   - GError * error = NULL;
918   - g_autofree gchar *dirname = g_path_get_dirname(filename);
919   -
920   - GSettingsSchemaSource * source =
921   - g_settings_schema_source_new_from_directory(
922   - dirname,
923   - NULL,
924   - TRUE,
925   - &error
926   - );
927   -
928   - g_assert_no_error(error);
929   -
930   - GSettingsSchema * schema =
931   - g_settings_schema_source_lookup(
932   - source,
933   - "br.com.bb." G_STRINGIFY(PRODUCT_NAME) ".window",
934   - TRUE);
935   -
936   - debug("schema %s=%p","br.com.bb." PACKAGE_NAME,schema);
937   -
938   - settings = g_settings_new_full(schema, NULL, NULL);
939   -
940   - g_settings_schema_source_unref(source);
941   -
942   - } else {
943   -
944   - settings = g_settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME));
945   -
946   - }
947   -
948   - }
949   -#else
950   - {
951   - settings = g_settings_new("br.com.bb." G_STRINGIFY(PRODUCT_NAME) ".window");
952   - }
953   -
954   -#endif // DEBUG
955   -
956   - return settings;
957   -
958   -}
959   -
960 883 GList * pw3270_application_window_get_keypads(GtkWidget *window) {
961 884  
962 885 g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(window),NULL);
... ...