</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>
<property name="left_padding">5</property>
<property name="right_padding">5</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">etched-in</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">5</property>
<child>
- <object class="GtkTreeView" id="treeview1">
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">lstore_treemodel_campi</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <property name="shadow_type">etched-in</property>
<child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <object class="GtkTreeView" id="treeview1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">lstore_treemodel_campi</property>
+ <property name="headers_clickable">False</property>
+ <property name="search_column">0</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <child>
+ <object class="GtkCellRendererToggle" id="cellrenderertoggle1"/>
+ <attributes>
+ <attribute name="active">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
<child>
- <object class="GtkCellRendererToggle" id="cellrenderertoggle1"/>
- <attributes>
- <attribute name="active">0</attribute>
- </attributes>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <property name="title">Campo</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
+ </child>
+ </object>
</child>
</object>
</child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHButtonBox" id="hbuttonbox1">
+ <property name="visible">True</property>
+ <property name="spacing">5</property>
+ <property name="layout_style">end</property>
<child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn2">
- <property name="title">Campo</property>
- <child>
- <object class="GtkCellRendererText" id="cellrenderertext1"/>
- <attributes>
- <attribute name="text">1</attribute>
- </attributes>
- </child>
+ <object class="GtkButton" id="button3">
+ <property name="label" translatable="yes">Deseleziona tutti</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button4">
+ <property name="label" translatable="yes">Seleziona tutti</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
</child>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
+ <property name="text" translatable="yes">"</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
+ <property name="text" translatable="yes">,</property>
</object>
<packing>
<property name="left_attach">1</property>
<object class="GtkFileChooserWidget" id="filechooserwidget1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
+ <property name="use_preview_label">False</property>
+ <property name="preview_widget_active">False</property>
<property name="action">save</property>
<property name="local_only">False</property>
</object>
<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 id -->
+ <column type="guint"/>
+ <!-- column-name nome -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
</interface>
gchar *moddir;
gchar *p;
- moddir = g_win32_get_package_installation_directory_of_module (NULL);
+ moddir = g_win32_get_package_installation_directory_of_module (NULL);
p = strrchr (moddir, G_DIR_SEPARATOR);
if (p != NULL
priv = SOLIPA_GET_PRIVATE (solipa);
- return priv->gdaex;
+ return priv->gdaex;
+}
+
+const gchar
+*solipa_get_guifile (Solipa *solipa)
+{
+ SolipaPrivate *priv;
+
+ g_return_val_if_fail (IS_SOLIPA (solipa), NULL);
+
+ priv = SOLIPA_GET_PRIVATE (solipa);
+
+ return g_strdup (priv->guifile);
+}
+
+GtkBuilder
+*solipa_get_gtkbuilder (Solipa *solipa)
+{
+ SolipaPrivate *priv;
+
+ g_return_val_if_fail (IS_SOLIPA (solipa), NULL);
+
+ priv = SOLIPA_GET_PRIVATE (solipa);
+
+ return priv->gtkbuilder;
}
/* PRIVATE */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
static void
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
#include <glib.h>
#include <glib-object.h>
+#include <gtk/gtk.h>
+
#include <camel/camel.h>
#include <libgdaex.h>
void solipa_set_gdaex (Solipa *solipa, GdaEx *gdaex);
GdaEx *solipa_get_gdaex (Solipa *solipa);
+const gchar *solipa_get_guifile (Solipa *solipa);
+
+GtkBuilder *solipa_get_gtkbuilder (Solipa *solipa);
+
G_END_DECLS
#endif
#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include <solipa.h>
#include "utils.h"
+static void solipa_fixed_toggled (GtkCellRendererToggle *cell,
+ gchar *path_str,
+ gpointer data);
+
+static void solipa_gtkliststore_select_unselect_all (GtkListStore *store,
+ gboolean select);
+
+static void solipa_on_btn_select_all_clicked (GtkButton *button,
+ gpointer user_data);
+static void solipa_on_btn_unselect_all_clicked (GtkButton *button,
+ gpointer user_data);
+
+gboolean
+solipa_file_exists (const gchar *filename)
+{
+ return (g_file_query_exists (g_file_new_for_path (filename), NULL));
+}
+
void
solipa_gtktreemodel_to_csv (GtkTreeModel *model, const gchar *filename,
gboolean overwrite,
}
}
+static void
+solipa_fixed_toggled (GtkCellRendererToggle *cell,
+ gchar *path_str,
+ gpointer data)
+{
+ GtkTreeModel *model = (GtkTreeModel *)data;
+ GtkTreeIter iter;
+ GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+
+ gboolean choosen;
+
+ /* get toggled iter */
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, 0, &choosen, -1);
+
+ choosen ^= 1;
+
+ /* set new value */
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, choosen, -1);
+
+ /* clean up */
+ gtk_tree_path_free (path);
+}
+
+static void
+solipa_gtkliststore_select_unselect_all (GtkListStore *store, gboolean select)
+{
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
+ {
+ do
+ {
+ gtk_list_store_set (store, &iter, 0, select, -1);
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
+ }
+}
+
+static void
+solipa_on_btn_select_all_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ solipa_gtkliststore_select_unselect_all ((GtkListStore *)user_data, TRUE);
+}
+
+static void
+solipa_on_btn_unselect_all_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ solipa_gtkliststore_select_unselect_all ((GtkListStore *)user_data, FALSE);
+}
+
void
solipa_gtktreemodel_to_csv_gui (Solipa *solipa, GtkTreeModel *model,
gchar **columns_title,
guint n_columns)
{
GtkWidget *diag;
+ GError *error;
+ GtkBuilder *builder;
+
+ GtkListStore *store;
+ GtkTreeIter iter;
-
+ gchar *filename;
+
+ guint col;
+ gboolean sel;
+
+ guint *columns;
+ guint _n_columns;
+
+ builder = solipa_get_gtkbuilder (solipa);
+
+ error = NULL;
+ gtk_builder_add_objects_from_file (builder,
+ solipa_get_guifile (solipa),
+ g_strsplit ("diag_gtktreemodel_to_csv"
+ "|lstore_treemodel_campi",
+ "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("Error: %s.",
+ error->message != NULL ? error->message : "no details");
+ return;
+ }
+
+ diag = GTK_WIDGET (gtk_builder_get_object (builder, "diag_gtktreemodel_to_csv"));
+ if (GTK_IS_WIDGET (diag))
+ {
+ /* carico i nomi campi per la selezione nel model */
+ store = GTK_LIST_STORE (gtk_builder_get_object (builder, "lstore_treemodel_campi"));
+
+ g_signal_connect (gtk_builder_get_object (builder, "cellrenderertoggle1"),
+ "toggled", G_CALLBACK (solipa_fixed_toggled), (gpointer)store);
+
+ g_signal_connect (gtk_builder_get_object (builder, "button3"),
+ "clicked", G_CALLBACK (solipa_on_btn_unselect_all_clicked), (gpointer *)store);
+ g_signal_connect (gtk_builder_get_object (builder, "button4"),
+ "clicked", G_CALLBACK (solipa_on_btn_select_all_clicked), (gpointer *)store);
+
+ gtk_list_store_clear (store);
+
+ for (col = 0; col < n_columns; col++)
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, FALSE,
+ 1, col,
+ 2, columns_title[col],
+ -1);
+ }
+
+ do
+ {
+ if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK)
+ {
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (gtk_builder_get_object (builder, "filechooserwidget1")));
+ if (filename == NULL
+ || g_strcmp0 (g_strstrip (filename), "") == 0)
+ {
+ GtkWidget *diag_req;
+
+ diag_req = gtk_message_dialog_new (GTK_WINDOW (diag),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Immettere il nome del file nel quale esportare i dati.");
+ gtk_dialog_run (GTK_DIALOG (diag_req));
+ gtk_widget_destroy (diag_req);
+ continue;
+ }
+
+ if (solipa_file_exists (filename))
+ {
+ GtkWidget *diag_req;
+
+ diag_req = gtk_message_dialog_new (GTK_WINDOW (diag),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "File esistente. Sovrascriverlo?");
+ if (gtk_dialog_run (GTK_DIALOG (diag_req)) == GTK_RESPONSE_YES)
+ {
+ gtk_widget_destroy (diag_req);
+ break;
+ }
+ gtk_widget_destroy (diag_req);
+ }
+ break;
+ }
+ else
+ {
+ gtk_widget_destroy (diag);
+ return;
+ }
+ } while (TRUE);
+
+ /* ricavo i campi selezionati che devono essere esportati */
+ _n_columns = 0;
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
+ {
+ columns = g_malloc0 (sizeof (guint));
+ do
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &sel, 1, &col, -1);
+ if (sel)
+ {
+ _n_columns++;
+ columns = g_realloc_n (columns, _n_columns, sizeof (guint));
+ columns[_n_columns - 1] = col;
+ }
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
+ }
+
+ /* export */
+ solipa_gtktreemodel_to_csv (model,
+ filename,
+ TRUE,
+ gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "entry1"))),
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "checkbutton1"))),
+ gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, "entry2"))),
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "checkbutton3"))),
+ columns_title,
+ columns,
+ _n_columns);
+
+ gtk_widget_destroy (diag);
+ }
}
G_BEGIN_DECLS
+gboolean solipa_file_exists (const gchar *filename);
+
void solipa_gtktreemodel_to_csv (GtkTreeModel *model, const gchar *filename,
gboolean overwrite,
const gchar *quote, gboolean quote_all,
int
main (int argc, char *argv[])
{
+ Solipa *solipa;
+
GtkListStore *model;
gchar **columns_title;
gtk_init (&argc, &argv);
+ solipa = solipa_new ();
+
columns_title = g_malloc0 (3 * sizeof (gchar));
columns_title[0] = g_strdup ("ID");
columns_title[1] = g_strdup ("Ragione Sociale");
columns,
2);
+ solipa_gtktreemodel_to_csv_gui (solipa, GTK_TREE_MODEL (model),
+ columns_title, 3);
+
return 0;
}