]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunta la funzione SolipaAllegato::get_blob.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 5 Dec 2012 10:47:49 +0000 (11:47 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 5 Dec 2012 10:47:49 +0000 (11:47 +0100)
data/libsolipa/gui/libsolipa.ui
src/allegato.c
src/allegato.h

index d185fa883ca546ff5db2fce2d8cd9a85904d5355..cbce9d31f18f7f63b320526beb9e3ca41d33df98 100644 (file)
         <property name="n_columns">2</property>
         <property name="column_spacing">5</property>
         <property name="row_spacing">5</property>
-        <child>
-          <placeholder/>
-        </child>
         <child>
           <object class="GtkLabel" id="label139">
             <property name="visible">True</property>
             <property name="y_options">GTK_FILL</property>
           </packing>
         </child>
+        <child>
+          <placeholder/>
+        </child>
       </object>
     </child>
   </object>
index 76380f617dc646d0e6a810a7bad107d87f2c776a..8479b48f3f355b4ff3e28d7d6ce48f1a63d26828 100644 (file)
@@ -254,6 +254,8 @@ solipa_allegato_apri_allegato (GtkWindow *transient, const gchar *filename)
        GError *error;
        GList *lfiles;
 
+       g_return_if_fail (filename != NULL);
+
        gfile = g_file_new_for_commandline_arg (filename);
        if (gfile == NULL)
                {
@@ -343,10 +345,100 @@ solipa_allegato_salva_in_db (GdaConnection *gda_con, const gchar *sql,
        return TRUE;
 }
 
-void solipa_allegato_add_to_gtkform (SolipaAllegato *solipa_allegato, GtkForm *form,
-                                     const gchar *percorso_field,
-                                     const gchar *data_field,
-                                     const gchar *dimensione_field)
+const gchar
+*solipa_allegato_get_blob (GdaEx *gdaex,
+                           const gchar *sql,
+                           const gchar *percorso_field_name,
+                           const gchar *blob_field_name)
+{
+       GdaDataModel *dm;
+       GError *error;
+       gint fin;
+       gchar *filename_tmp;
+       const GValue *value;
+       const gchar *percorso;
+       gchar *filename_orig;
+       const GdaBlob *blob;
+       gint i;
+
+       gchar *ret;
+
+       ret = NULL;
+
+       dm = gdaex_query (gdaex, sql);
+       if (dm != NULL)
+               {
+                       error = NULL;
+                       value = gda_data_model_get_value_at (dm,
+                                                            gda_data_model_get_column_index (dm, blob_field_name),
+                                                            0, &error);
+                       if (!gda_value_is_null (value) && gda_value_isa (value, GDA_TYPE_BLOB))
+                               {
+                                       blob = gda_value_get_blob (value);
+
+                                       filename_orig = g_strdup ("");
+                                       error = NULL;
+                                       value = gda_data_model_get_value_at (dm,
+                                                                            gda_data_model_get_column_index (dm, percorso_field_name),
+                                                                            0, &error);
+                                       if (!gda_value_is_null (value))
+                                               {
+                                                       percorso = g_value_get_string (value);
+                                                       filename_orig = g_path_get_basename (percorso);
+                                               }
+
+                                       error = NULL;
+                                       fin = g_file_open_tmp (g_strdup_printf ("solipa-XXXXXX-%s", filename_orig),
+                                                              &filename_tmp, &error);
+                                       if (fin > 0)
+                                               {
+                                                       if (gda_blob_op_read_all (blob->op, blob))
+                                                               {
+                                                                       if (write (fin, blob->data.data, blob->data.binary_length) < 0)
+                                                                               {
+                                                                                       g_warning ("Errore nella scrittura del file temporaneo.");
+                                                                                       g_free (ret);
+                                                                                       ret = NULL;
+                                                                               }
+                                                                       else
+                                                                               {
+                                                                                       ret = g_strdup (filename_tmp);
+                                                                               }
+#ifdef G_OS_WIN32
+                                                                       _commit (fin);
+#else
+                                                                       fsync (fin);
+#endif
+                                                               }
+                                                       else
+                                                               {
+                                                                       g_warning ("Errore nella lettura dell'allegato.");
+                                                                       g_free (ret);
+                                                                       ret = NULL;
+                                                               }
+
+                                                       close (fin);
+                                               }
+                                       else
+                                               {
+                                                       g_warning ("Errore nella lettura dell'allegato: %s.", error->message);
+                                                       g_free (ret);
+                                                       ret = NULL;
+                                               }
+
+                                       g_free (filename_tmp);
+                                       g_free (filename_orig);
+                               }
+               }
+
+       return ret;
+}
+
+void
+solipa_allegato_add_to_gtkform (SolipaAllegato *solipa_allegato, GtkForm *form,
+                                const gchar *percorso_field,
+                                const gchar *data_field,
+                                const gchar *dimensione_field)
 {
        SolipaAllegatoPrivate *priv;
 
index 22ec0d5fb7c3ddb2d35aebe5cee9c766c3448cd1..51f9e562d80574e27c6c445cf3ad3546a556626d 100644 (file)
@@ -67,6 +67,11 @@ guint solipa_allegato_get_dimensione (SolipaAllegato *solipa_allegato);
 gboolean solipa_allegato_get_salva_in_db (SolipaAllegato *solipa_allegato);
 void solipa_allegato_set_salva_in_db (SolipaAllegato *solipa_allegato, gboolean salva);
 
+const gchar *solipa_allegato_get_blob (GdaEx *gdaex,
+                           const gchar *sql,
+                           const gchar *percorso_field_name,
+                           const gchar *blob_field_name);
+
 void solipa_allegato_add_to_gtkform (SolipaAllegato *solipa_allegato, GtkForm *form,
                                      const gchar *percorso_field,
                                      const gchar *data_field,