From 25dfc307078c76d86906552e9bdad8b6f8319665 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 18 Dec 2010 11:08:11 +0100 Subject: [PATCH] Aggiunta GUIDIR e caricamento della configurazione da file (da testare). --- data/libsolipa/gui/libsolipa.ui | 24 ++++---- src/Makefile.am | 5 +- src/solipa.c | 100 ++++++++++++++++++++++++++++++++ src/solipa.h | 3 + src/utils.c | 10 ++++ src/utils.h | 4 ++ 6 files changed, 134 insertions(+), 12 deletions(-) diff --git a/data/libsolipa/gui/libsolipa.ui b/data/libsolipa/gui/libsolipa.ui index b291899..ae7ca86 100644 --- a/data/libsolipa/gui/libsolipa.ui +++ b/data/libsolipa/gui/libsolipa.ui @@ -151,6 +151,14 @@ + + + + + + + + 5 Esporta CSV @@ -374,6 +382,8 @@ True vertical + save + False @@ -415,7 +425,7 @@ - gtk-ok + gtk-save True True True @@ -437,16 +447,8 @@ - button1 - button2 + button1 + button2 - - - - - - - - diff --git a/src/Makefile.am b/src/Makefile.am index 21ac57e..880797e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,9 @@ +guidir = $(datadir)/$(PACKAGE)/gui + LIBS = $(SOLIPA_LIBS) -AM_CPPFLAGS = $(SOLIPA_CFLAGS) +AM_CPPFLAGS = $(SOLIPA_CFLAGS) \ + -DGUIDIR=\""$(guidir)"\" lib_LTLIBRARIES = libsolipa.la diff --git a/src/solipa.c b/src/solipa.c index 44ff59b..ced98c0 100644 --- a/src/solipa.c +++ b/src/solipa.c @@ -22,6 +22,8 @@ #include +#include + #include "solipa.h" static void solipa_class_init (SolipaClass *class); @@ -44,6 +46,10 @@ struct _SolipaPrivate CamelSession *camel_session; GdaEx *gdaex; + + gchar *guidir; + gchar *guifile; + GtkBuilder *gtkbuilder; }; G_DEFINE_TYPE (Solipa, solipa, G_TYPE_OBJECT) @@ -94,9 +100,103 @@ Solipa priv->camel_session = solipa_camel_session_new (camel_tmpdir); + /* gui */ +#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)) + { + solipa->guidir = g_strdup (GUIDIR); + } + else + { + solipa->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + } + +#else + + priv->guidir = g_strdup (GUIDIR); + +#endif + + priv->guifile = g_build_filename (priv->guidir, "libsolipa.ui", NULL); + + priv->gtkbuilder = gtk_builder_new (); + return solipa; } +Solipa +*solipa_new_with_keyfile (const gchar *filename) +{ + Solipa *solipa; + + solipa = solipa_new (); + if (solipa != NULL) + { + solipa_set_from_keyfile (solipa, filename); + } + + return solipa; +} + +void +solipa_set_from_keyfile (Solipa *solipa, const gchar *filename) +{ + gchar *_filename; + + GError *error; + GKeyFile *config; + + gchar **config_params; + gsize n_params; + + gchar *cnc_string; + GdaEx *gdaex; + + g_return_if_fail (IS_SOLIPA (solipa)); + g_return_if_fail (filename == NULL); + + _filename = g_strstrip (g_strdup (filename)); + g_return_if_fail (g_strcmp0 (_filename, "") != 0); + + error = NULL; + config = g_key_file_new (); + if (!g_key_file_load_from_file (config, _filename, G_KEY_FILE_NONE, &error)) + { + g_warning ("Error on loading solipa config from file «%s»: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + return; + } + g_error_free (error); + + /* db params */ + error = NULL; + cnc_string = g_key_file_get_value (config, "SOLIPA_DB", "cnc_string", &error); + if (cnc_string == NULL) + { + g_warning ("Error on loading solipa db config from file «%s»: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + return; + } + + gdaex = gdaex_new_from_string (cnc_string); + if (gdaex == NULL) + { + g_warning ("Error on database connection with string: %s", cnc_string); + } + solipa_set_gdaex (solipa, gdaex); + + g_error_free (error); +} + CamelSession *solipa_get_camel_session (Solipa *solipa) { diff --git a/src/solipa.h b/src/solipa.h index 6d5d0c0..312ee31 100644 --- a/src/solipa.h +++ b/src/solipa.h @@ -54,6 +54,9 @@ GType solipa_get_type (void) G_GNUC_CONST; Solipa *solipa_new (void); +Solipa *solipa_new_with_keyfile (const gchar *filename); + +void solipa_set_from_keyfile (Solipa *solipa, const gchar *filename); CamelSession *solipa_get_camel_session (Solipa *solipa); diff --git a/src/utils.c b/src/utils.c index bc2d451..9926d1a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -181,3 +181,13 @@ solipa_gtktreemodel_to_csv (GtkTreeModel *model, const gchar *filename, } } +void +solipa_gtktreemodel_to_csv_gui (Solipa *solipa, GtkTreeModel *model, + gchar **columns_title, + guint n_columns) +{ + GtkWidget *diag; + + +} + diff --git a/src/utils.h b/src/utils.h index 1b952c1..91cf84f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -36,6 +36,10 @@ void solipa_gtktreemodel_to_csv (GtkTreeModel *model, const gchar *filename, guint *columns, guint n_columns); +void solipa_gtktreemodel_to_csv_gui (Solipa *solipa, GtkTreeModel *model, + gchar **columns_title, + guint n_columns); + G_END_DECLS -- 2.49.0