]> saetta.ns0.it Git - libgdaex/commitdiff
GdaExGrid: csv export when libsolipa is present (closes #57).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Oct 2013 15:25:25 +0000 (17:25 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 3 Oct 2013 15:25:25 +0000 (17:25 +0200)
configure.ac
src/Makefile.am
src/grid.c
src/grid.h
tests/Makefile.am
tests/grid.c

index 5572827718012f945ec955de8b0ce0cb8433b6f2..18fe36279cd8f0619b703c9574a1f27b8332030d 100644 (file)
@@ -59,6 +59,17 @@ AC_SUBST(REPTOOL_CFLAGS)
 AC_SUBST(REPTOOL_LIBS)
 fi
 
+PKG_CHECK_EXISTS(libsolipa >= 0.4.0, [LIBSOLIPA_FOUND=yes], [LIBSOLIPA_FOUND=no])
+
+AM_CONDITIONAL(LIBSOLIPA_FOUND, test $LIBSOLIPA_FOUND = yes)
+
+if test $LIBSOLIPA_FOUND = yes; then
+PKG_CHECK_MODULES(SOLIPA, libsolipa >= 0.4.0)
+
+AC_SUBST(SOLIPA_CFLAGS)
+AC_SUBST(SOLIPA_LIBS)
+fi
+
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([string.h])
index f9c927366adc2f369df21237cb6bdb3ea96509ad..796a506c3352301564670050da81c4f94e4dc259 100644 (file)
@@ -12,10 +12,20 @@ if LIBREPTOOL_FOUND
 AM_CPPFLAGS += \
                $(REPTOOL_CFLAGS) \
                -DREPTOOL_FOUND=1
+
 LIBS += \
         $(REPTOOL_LIBS)
 endif
 
+if LIBSOLIPA_FOUND
+AM_CPPFLAGS += \
+               $(SOLIPA_CFLAGS) \
+               -DSOLIPA_FOUND=1
+
+LIBS += \
+        $(SOLIPA_LIBS)
+endif
+
 lib_LTLIBRARIES = libgdaex.la
 
 libgdaex_la_SOURCES = gdaex.c \
index 10dfe70d9a68b6c5cbc74d6cf03c164ef9c9a00c..d06d85af808687351766c8038c02bf63b0b32dc1 100644 (file)
 
 #include <gtk/gtk.h>
 
-#ifdef REPTOOL_FOUND
+#if defined (REPTOOL_FOUND) || defined (SOLIPA_FOUND)
        #include <gdk/gdkkeysyms.h>
+#endif
+
+#ifdef REPTOOL_FOUND
        #include <libreptool/libreptool.h>
 #endif
 
+#ifdef SOLIPA_FOUND
+       #include <libsolipa/utils.h>
+#endif
+
 #include "grid.h"
 
 static void gdaex_grid_class_init (GdaExGridClass *klass);
@@ -46,7 +53,7 @@ static void gdaex_grid_get_property (GObject *object,
                                GValue *value,
                                GParamSpec *pspec);
 
-#ifdef REPTOOL_FOUND
+#if defined (REPTOOL_FOUND) || defined (SOLIPA_FOUND)
 static gboolean gdaex_grid_on_key_release_event (GtkWidget *widget,
                             GdkEventKey *event,
                             gpointer user_data);
@@ -75,6 +82,10 @@ struct _GdaExGridPrivate
                GtkTreeModel *model;
                GtkWidget *view;
                GtkWidget *menu;
+
+#ifdef SOLIPA_FOUND
+               Solipa *solipa;
+#endif
        };
 
 G_DEFINE_TYPE (GdaExGrid, gdaex_grid, G_TYPE_OBJECT)
@@ -360,6 +371,20 @@ gdaex_grid_fill_from_datamodel (GdaExGrid *grid, GdaDataModel *dm, GError **erro
        return TRUE;
 }
 
+#ifdef SOLIPA_FOUND
+void
+gdaex_grid_set_solipa (GdaExGrid *grid, Solipa *solipa)
+{
+       GdaExGridPrivate *priv;
+
+       g_return_if_fail (GDAEX_IS_GRID (grid));
+
+       priv = GDAEX_GRID_GET_PRIVATE (grid);
+
+       priv->solipa = solipa;
+}
+#endif
+
 /* PRIVATE */
 static void
 gdaex_grid_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
@@ -530,7 +555,7 @@ static GtkTreeView
        return GTK_TREE_VIEW (priv->view);
 }
 
-#ifdef REPTOOL_FOUND
+#if defined (REPTOOL_FOUND) || defined (SOLIPA_FOUND)
 static gboolean
 gdaex_grid_on_key_release_event (GtkWidget *widget,
                             GdkEventKey *event,
@@ -545,6 +570,7 @@ gdaex_grid_on_key_release_event (GtkWidget *widget,
 
        switch (event->keyval)
                {
+#ifdef REPTOOL_FOUND
                        case GDK_F12:
                                {
                                        if (event->state & GDK_CONTROL_MASK)
@@ -584,6 +610,50 @@ gdaex_grid_on_key_release_event (GtkWidget *widget,
                                                }
                                        break;
                                }
+#endif
+
+#ifdef SOLIPA_FOUND
+                       case GDK_F11:
+                               {
+                                       if (event->state & GDK_CONTROL_MASK)
+                                               {
+                                                       gint col;
+                                                       GdaExGridColumn *gcolumn;
+                                                       GString *gstr;
+
+                                                       priv = GDAEX_GRID_GET_PRIVATE (user_data);
+
+                                                       if (!IS_SOLIPA (priv->solipa))
+                                                               {
+                                                                       g_warning ("No Solipa object found");
+                                                                       break;
+                                                               }
+
+                                                       if (priv->columns->len)
+                                                               {
+                                                                       gstr = g_string_new ("");
+                                                                       for (col = 0; col < priv->columns->len; col++)
+                                                                               {
+                                                                                       gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
+                                                                                       g_string_append_printf (gstr, "|%s", gdaex_grid_column_get_title (gcolumn));
+                                                                               }
+
+                                                                       gchar **columns_title = g_strsplit (gstr->str + 1, "|", -1);
+
+                                                                       solipa_gtktreemodel_to_csv_gui (priv->solipa, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (priv->view))), priv->model,
+                                                                                                       columns_title, g_strv_length (columns_title));
+
+                                                                       g_strfreev (columns_title);
+
+                                                                       return TRUE;
+                                                               }
+                                               }
+                                       break;
+                               }
+#endif
+
+                       default:
+                               break;
                }
 
        return FALSE;
index 8d288801cc82d714eda133484bb66f8a375c0335..a7f7873197b54a801e7a9df59082bf4de00d4944 100644 (file)
 #include <glib.h>
 #include <glib-object.h>
 
+#ifdef SOLIPA_FOUND
+       #include <libsolipa/libsolipa.h>
+#endif
+
 #include "gdaex.h"
 #include "gridcolumn.h"
 
@@ -72,6 +76,10 @@ GtkWidget *gdaex_grid_get_widget (GdaExGrid *grid);
 gboolean gdaex_grid_fill_from_sql (GdaExGrid *grid, GdaEx *gdaex, const gchar *sql, GError **error);
 gboolean gdaex_grid_fill_from_datamodel (GdaExGrid *grid, GdaDataModel *dm, GError **error);
 
+#ifdef SOLIPA_FOUND
+void gdaex_grid_set_solipa (GdaExGrid *grid, Solipa *solipa);
+#endif
+
 
 G_END_DECLS
 
index 720f72621d815a5d23135f0edcb519ed3ce91e26..03f357ab9c35c466e9f4a1fb8f4d2aacd874bd0c 100644 (file)
@@ -5,6 +5,15 @@ AM_CPPFLAGS = $(GDAEX_CFLAGS) \
               -I$(top_srcdir)/src \
               -DTESTSDIR="\"@abs_builddir@\""
 
+if LIBSOLIPA_FOUND
+AM_CPPFLAGS += \
+               $(SOLIPA_CFLAGS) \
+               -DSOLIPA_FOUND=1
+
+LIBS += \
+        $(SOLIPA_LIBS)
+endif
+
 noinst_PROGRAMS = fill_liststore \
                   getsql \
                   grid \
index 134c03fe928cc5151c3a2388c7c0ab32c1973114..39978d2d06934407d4706e9befb8361814bdb59b 100644 (file)
@@ -66,6 +66,10 @@ main (int argc, char **argv)
        grid = gdaex_grid_new ();
        gdaex_grid_set_title (grid, "The grid title");
 
+#ifdef SOLIPA_FOUND
+       gdaex_grid_set_solipa (grid, solipa_new ());
+#endif
+
        gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, FALSE, FALSE, FALSE, -1);
        gdaex_grid_add_column (grid, gcol);