From e870530fda8913e7feef6a696c1655fdd3bbc2e5 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 2 Dec 2017 11:19:39 +0100 Subject: [PATCH] Aggiunta la funzione Territorio::init. --- src/commons.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/commons.h | 6 ++- src/main.c | 100 ++------------------------------------- 3 files changed, 134 insertions(+), 100 deletions(-) diff --git a/src/commons.c b/src/commons.c index a4846d8..ee23159 100644 --- a/src/commons.c +++ b/src/commons.c @@ -1,5 +1,5 @@ -/* - * Copyright (C) 2015 Andrea Zagli +/* + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,7 +21,7 @@ #include #endif -#include +#include "commons.h" #ifdef G_OS_WIN32 #include @@ -52,3 +52,125 @@ territorio_get_module_handle () return (gpointer)hmodule; } #endif + +TerritorioCommons +*territorio_init (ZakConfi *confi, const gchar *prefix) +{ + TerritorioCommons *commons; + + GError *error; + gchar *str; + + gchar *_prefix; + + GdaConnection *gdacon; + + if (prefix != NULL) + { + _prefix = g_strdup (prefix); + } + else + { + _prefix = g_strdup (""); + } + + /* inizializzazione commons */ + commons = g_new0 (TerritorioCommons, 1); + + /* leggo i parametri per libzakautho */ + error = NULL; + str = zak_confi_path_get_value (confi, g_strdup_printf ("%sZAKAUTHO/cnc_string", _prefix)); + if (str == NULL) + { + g_warning ("Impossibile leggere la stringa di connessione per libzakautho dal file di configurazione: %s.", + error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return NULL; + } + + error = NULL; + gdacon = gda_connection_open_from_string (NULL, str, NULL, 0, &error); + if (gdacon == NULL) + { + g_warning ("Impossibile creare la connessione al db per libzakautho: %s.", + error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + return NULL; + } + + commons->autoz = zak_autho_new (); + if (commons->autoz == NULL) + { + g_warning ("Impossibile creare l'oggetto per libzakautho."); + return NULL; + } + if (!zak_autho_load_from_db_with_monitor (commons->autoz, gdacon, NULL, TRUE)) + { + g_warning ("Impossibile caricare la configurazione per libzakautho dal db."); + return NULL; + } + +#ifdef G_OS_WIN32 + + gchar *moddir; + gchar *p; + + moddir = g_win32_get_package_installation_directory_of_module (NULL); + + p = strrchr (moddir, G_DIR_SEPARATOR); + if (p != NULL + && (g_ascii_strcasecmp (p + 1, "src") == 0 + || g_ascii_strcasecmp (p + 1, ".libs") == 0)) + { + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + commons->queryeditordir = g_strdup (QUERYEDITORDIR); + } + else + { + commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); + commons->queryeditordir = g_build_filename (moddir, "share", PACKAGE, "queryeditor", NULL); + } + +#else + + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + commons->queryeditordir = g_strdup (QUERYEDITORDIR); + +#endif + + commons->guifile = g_build_filename (commons->guidir, "territorio.gui", NULL); + + /* leggo la stringa di connessione al db */ + error = NULL; + str = zak_confi_path_get_value (confi, g_strdup_printf ("%sDB/cnc_string", _prefix)); + if (str == NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s.", + error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); + } + + commons->gdaex = gdaex_new_from_string (str); + if (commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", str); + } + + /* inizializzo solipa */ + commons->solipa = solipa_new (); + + commons->gtkbuilder = gtk_builder_new (); + + error = NULL; + gtk_builder_add_objects_from_file (commons->gtkbuilder, commons->guifile, + g_strsplit_set ("w_main", "|", -1), + &error); + if (error != NULL) + { + g_error ("Errore: %s", error->message); + } + + g_free (_prefix); + + return commons; +} diff --git a/src/commons.h b/src/commons.h index 87c183e..7f84d58 100644 --- a/src/commons.h +++ b/src/commons.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2017 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -64,6 +65,9 @@ gpointer territorio_get_module_handle (void); #endif +TerritorioCommons *territorio_init (ZakConfi *confi, const gchar *prefix); + + G_END_DECLS diff --git a/src/main.c b/src/main.c index 6c5bc42..2e24348 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2017 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -217,11 +217,7 @@ main (int argc, char *argv[]) ZakConfi *confi; - GdaConnection *gdacon; - ZakAuthe *zak_authe; - gchar **zak_authe_params; - gsize n_zak_authe_params; GSList *sl_zak_authe_params; gchar *utente; @@ -284,40 +280,14 @@ main (int argc, char *argv[]) } /* inizializzazione commons */ - commons = g_malloc (sizeof (TerritorioCommons)); - - commons->utente = g_strdup (utente); - - /* leggo i parametri per libzakautho */ - error = NULL; - cnc_string = zak_confi_path_get_value (confi, "ZAKAUTHO/cnc_string"); - if (cnc_string == NULL) - { - g_warning ("Impossibile leggere la stringa di connessione per libzakautho dal file di configurazione: %s.", - error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); - return 0; - } + commons = territorio_init (confi, NULL); - error = NULL; - gdacon = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, &error); - if (gdacon == NULL) + if (commons == NULL) { - g_warning ("Impossibile creare la connessione al db per libzakautho: %s.", - error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); return 0; } - commons->autoz = zak_autho_new (); - if (commons->autoz == NULL) - { - g_warning ("Impossibile creare l'oggetto per libzakautho."); - return 0; - } - if (!zak_autho_load_from_db_with_monitor (commons->autoz, gdacon, NULL, TRUE)) - { - g_warning ("Impossibile caricare la configurazione per libzakautho dal db."); - return 0; - } + commons->utente = g_strdup (utente); commons->role_utente = zak_autho_get_role_from_id (commons->autoz, commons->utente); if (commons->role_utente == NULL) @@ -326,68 +296,6 @@ main (int argc, char *argv[]) return 0; } -#ifdef G_OS_WIN32 - - gchar *moddir; - gchar *p; - - moddir = g_win32_get_package_installation_directory_of_module (NULL); - - p = strrchr (moddir, G_DIR_SEPARATOR); - if (p != NULL - && (g_ascii_strcasecmp (p + 1, "src") == 0 - || g_ascii_strcasecmp (p + 1, ".libs") == 0)) - { - commons->guidir = g_strdup (GUIDIR); - commons->formdir = g_strdup (FORMDIR); - commons->queryeditordir = g_strdup (QUERYEDITORDIR); - } - else - { - commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); - commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); - commons->queryeditordir = g_build_filename (moddir, "share", PACKAGE, "queryeditor", NULL); - } - -#else - - commons->guidir = g_strdup (GUIDIR); - commons->formdir = g_strdup (FORMDIR); - commons->queryeditordir = g_strdup (QUERYEDITORDIR); - -#endif - - commons->guifile = g_build_filename (commons->guidir, "territorio.gui", NULL); - - /* leggo la stringa di connessione al db */ - error = NULL; - cnc_string = zak_confi_path_get_value (confi, "DB/cnc_string"); - if (cnc_string == NULL) - { - g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s.", - error != NULL && error->message != NULL ? error->message : "nessun dettaglio"); - } - - commons->gdaex = gdaex_new_from_string (cnc_string); - if (commons->gdaex == NULL) - { - g_error ("Errore nella connessione al database: %s", cnc_string); - } - - /* inizializzo solipa */ - commons->solipa = solipa_new (); - - commons->gtkbuilder = gtk_builder_new (); - - error = NULL; - gtk_builder_add_objects_from_file (commons->gtkbuilder, commons->guifile, - g_strsplit_set ("w_main", "|", -1), - &error); - if (error != NULL) - { - g_error ("Errore: %s", error->message); - } - gtk_builder_connect_signals (commons->gtkbuilder, NULL); w = GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "w_main")); -- 2.49.0