From: Andrea Zagli Date: Sun, 3 Dec 2017 09:55:16 +0000 (+0100) Subject: Aggiunta la funzione Organigramma::init. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=3c03c0c744f9ad1925d3ed2665c108203553c51d;p=solipa%2Forganigramma Aggiunta la funzione Organigramma::init. --- diff --git a/src/commons.c b/src/commons.c index c25c29f..b52cc52 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,12 +21,13 @@ #include #endif -#include +#include "commons.h" #ifdef G_OS_WIN32 #include #endif + #ifdef G_OS_WIN32 static HMODULE hmodule; @@ -52,3 +53,128 @@ organigramma_get_module_handle () return (gpointer)hmodule; } #endif + +OrganigrammaCommons +*organigramma_init (ZakConfi *confi, const gchar *prefix) +{ + gchar *_prefix; + + GError *error; + gchar *str; + + GdaConnection *gdacon; + + OrganigrammaCommons *commons; + + if (prefix != NULL) + { + _prefix = g_strdup (prefix); + } + else + { + _prefix = g_strdup (""); + } + + /* inizializzazione commons */ + commons = g_new0 (OrganigrammaCommons, 1); + + commons->territorio_commons = territorio_init (confi, "TERRITORIO_"); + +#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); + } + else + { +#undef GUIDIR +#undef FORMDIR + + commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); + } + +#else + + commons->guidir = g_strdup (GUIDIR); + commons->formdir = g_strdup (FORMDIR); + +#endif + + commons->guifile = g_build_filename (commons->guidir, "organigramma.gui", NULL); + + /* leggo i parametri per libzakautho */ + 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."); + 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.\n", 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 (commons->autoz, gdacon, NULL, TRUE)) + { + g_warning ("Impossibile caricare la configurazione per libzakautho dal db."); + return NULL; + } + + /* inizializzo solipa */ + commons->solipa = solipa_new (); + + /* leggo la stringa di connessione al db */ + 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."); + } + + commons->gdaex = gdaex_new_from_string (str); + if (commons->gdaex == NULL) + { + g_error ("Errore nella connessione al database: %s", str); + } + + /* leggo la stringa di connessione al db nativa di postgres */ + str = zak_confi_path_get_value (confi, g_strdup_printf ("%sDB/pg_cnc_string", _prefix)); + if (str == NULL) + { + g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); + } + + commons->pgcon = PQconnectdb (str); + if (commons->pgcon == NULL + || PQstatus (commons->pgcon) == CONNECTION_BAD) + { + g_error ("Errore nella connessione al database: %s", str); + } + + /* gtkbuilder */ + commons->gtkbuilder = gtk_builder_new (); + + g_free (_prefix); + + return commons; +} diff --git a/src/commons.h b/src/commons.h index 36cefc9..55ba826 100644 --- a/src/commons.h +++ b/src/commons.h @@ -23,15 +23,16 @@ #ifndef __ORGANIGRAMMA_COMMONS_H__ #define __ORGANIGRAMMA_COMMONS_H__ +#include + #ifdef G_OS_WIN32 #include #endif #include -#include - #include +#include #include #include #include @@ -66,4 +67,7 @@ gpointer organigramma_get_module_handle (void); #endif +OrganigrammaCommons *organigramma_init (ZakConfi *confi, const gchar *prefix); + + #endif /* __ORGANIGRAMMA_COMMONS_H__ */ diff --git a/src/main.c b/src/main.c index 483156c..9638ec8 100644 --- a/src/main.c +++ b/src/main.c @@ -249,19 +249,11 @@ main (int argc, char *argv[]) ZakConfi *confi; - GdaConnection *gdacon; - ZakAuthe *aute; - gchar **aute_params; - gsize n_aute_params; GSList *sl_aute_params; gchar *utente; - gchar *cnc_string; - - gint i; - gtk_init (&argc, &argv); gda_init (); @@ -305,74 +297,11 @@ main (int argc, char *argv[]) } } - /* inizializzazione commons */ - commons = g_new0 (OrganigrammaCommons, 1); - commons->utente = utente; + commons = organigramma_init (confi, NULL); - commons->territorio_commons = territorio_init (confi, "TERRITORIO_"); + commons->utente = utente; commons->territorio_commons->utente = utente; -#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); - } - else - { -#undef GUIDIR -#undef FORMDIR - - commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); - commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); - } - -#else - - commons->guidir = g_strdup (GUIDIR); - commons->formdir = g_strdup (FORMDIR); - -#endif - - commons->guifile = g_build_filename (commons->guidir, "organigramma.gui", NULL); - - /* leggo i parametri per libzakautho */ - 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."); - return 0; - } - - error = NULL; - gdacon = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, &error); - if (gdacon == NULL) - { - g_warning ("Impossibile creare la connessione al db per libzakautho: %s.\n", 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 (commons->autoz, gdacon, NULL, TRUE)) - { - g_warning ("Impossibile caricare la configurazione per libzakautho dal db."); - return 0; - } - commons->role_utente = zak_autho_get_role_from_id (commons->autoz, commons->utente); if (commons->role_utente == NULL) { @@ -387,36 +316,6 @@ main (int argc, char *argv[]) return 0; } - /* inizializzo solipa */ - commons->solipa = solipa_new (); - - /* leggo la stringa di connessione al db */ - 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."); - } - - commons->gdaex = gdaex_new_from_string (cnc_string); - if (commons->gdaex == NULL) - { - g_error ("Errore nella connessione al database: %s", cnc_string); - } - - /* leggo la stringa di connessione al db nativa di postgres */ - cnc_string = zak_confi_path_get_value (confi, "DB/pg_cnc_string"); - if (cnc_string == NULL) - { - g_error ("Impossibile leggere la stringa di connessione dal file di configurazione."); - } - - commons->pgcon = PQconnectdb (cnc_string); - if (commons->pgcon == NULL - || PQstatus (commons->pgcon) == CONNECTION_BAD) - { - g_error ("Errore nella connessione al database: %s", cnc_string); - } - commons->territorio_commons->role_utente = zak_autho_get_role_from_id (commons->territorio_commons->autoz, commons->territorio_commons->utente); if (commons->territorio_commons->role_utente == NULL) { @@ -424,9 +323,6 @@ main (int argc, char *argv[]) return 0; } - /* gtkbuilder */ - commons->gtkbuilder = gtk_builder_new (); - error = NULL; gtk_builder_add_objects_from_file (commons->gtkbuilder, commons->guifile, g_strsplit_set ("w_main", "|", -1),