Aggiunta GUIDIR e caricamento della configurazione da file (da testare).
authorAndrea Zagli <azagli@libero.it>
Sat, 18 Dec 2010 10:08:11 +0000 (11:08 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 18 Dec 2010 10:08:11 +0000 (11:08 +0100)
data/libsolipa/gui/libsolipa.ui
src/Makefile.am
src/solipa.c
src/solipa.h
src/utils.c
src/utils.h

index b291899c9584b4e90d72ad3cf9beb8bf99a49530..ae7ca866a002ffb0c97ff1e44cd5e4cec8729313 100644 (file)
       </object>
     </child>
   </object>
+  <object class="GtkListStore" id="lstore_treemodel_campi">
+    <columns>
+      <!-- column-name selezionato -->
+      <column type="gboolean"/>
+      <!-- column-name nome -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="diag_gtktreemodel_to_csv">
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Esporta CSV</property>
                       <object class="GtkFileChooserWidget" id="filechooserwidget1">
                         <property name="visible">True</property>
                         <property name="orientation">vertical</property>
+                        <property name="action">save</property>
+                        <property name="local_only">False</property>
                       </object>
                     </child>
                   </object>
             </child>
             <child>
               <object class="GtkButton" id="button2">
-                <property name="label">gtk-ok</property>
+                <property name="label">gtk-save</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
       </object>
     </child>
     <action-widgets>
-      <action-widget response="0">button1</action-widget>
-      <action-widget response="0">button2</action-widget>
+      <action-widget response="-6">button1</action-widget>
+      <action-widget response="-5">button2</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkListStore" id="lstore_treemodel_campi">
-    <columns>
-      <!-- column-name selezionato -->
-      <column type="gboolean"/>
-      <!-- column-name nome -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
 </interface>
index 21ac57ebed5f7fd3b654a798610350e1b33ce237..880797eecfb3767d52b56efb98ee3ea9bb309f4d 100644 (file)
@@ -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
 
index 44ff59b30c718a363f12114d6ae15f65d36e86a1..ced98c078066877583c97fa43d645349ba6f9c91 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <stdlib.h>
 
+#include <gtk/gtk.h>
+
 #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)
 {
index 6d5d0c0a1ced4546b3af97b1bf109efbe3865ade..312ee317841db1399159663373caddf84d68ffc3 100644 (file)
@@ -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);
 
index bc2d451b257c2240d0a7ccec84a1e7ecc4cb43f8..9926d1a7f3b2723bac71a27861a597fa4fa2010e 100644 (file)
@@ -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;
+
+       
+}
+
index 1b952c1474be58b38302bfd756712f3f75ead8dd..91cf84f9c99361546a512a6cd4c0cabdef59ebf1 100644 (file)
@@ -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