]> saetta.ns0.it Git - bcity/be/commitdiff
Added and managed field "icona" in "categorie". master
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Feb 2016 15:41:04 +0000 (16:41 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Feb 2016 15:41:04 +0000 (16:41 +0100)
data/bcity_be/gui/bcity_be.ui
doc/bcity_be/db/bcity.sql
src/categoria.c

index eeefda3f52fe31c3c8a3dffd8dafa19cd1ba24c8..658bdc754e9932f5b62b9f07af259daf67de1fa0 100644 (file)
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="top_attach">3</property>
+                <property name="top_attach">4</property>
               </packing>
             </child>
             <child>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
               </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Icona</property>
+                <property name="xalign">0</property>
+              </object>
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">3</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <child>
+                  <object class="GtkImage" id="image1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="stock">gtk-missing-image</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label5">
+                <property name="can_focus">False</property>
+                <property name="no_show_all">True</property>
+                <property name="label" translatable="yes">lbl_icona_percorso</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">5</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
index 9d4efc7ae66d5c1acfa272eb7baba1e48d91c260..bbe08312e5b713bfe94863dfc7ed2f861f59d9ca 100644 (file)
@@ -26,7 +26,8 @@ CREATE TABLE categorie (
     id_categorie integer DEFAULT 0,
     descrizione character varying(255) DEFAULT ''::character varying,
     status character varying(1) DEFAULT ''::character varying,
-    note text DEFAULT ''::text
+    note text DEFAULT ''::text,
+    icona oid
 );
 
 
index 4ee621245edc432e6b8c587af0a22806525e6c4a..70b7d3d8d8aea62f8dcff825526f631c5f6f7435 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 
 #include <gdk/gdk.h>
+#include <glib/gstdio.h>
 
 #include <libzakgtkdecoder/libzakgtkdecoder.h>
 #include <libzakform/libzakform.h>
@@ -64,6 +65,9 @@ static gboolean categoria_on_w_categoria_delete_event (GtkWidget *widget,
 static void categoria_on_btn_categoria_browse_clicked (GtkButton *button,
                                     gpointer user_data);
 
+static void categoria_on_btn_icona_clicked (GtkButton *button,
+                                    gpointer user_data);
+
 static void categoria_on_btn_annulla_clicked (GtkButton *button,
                                     gpointer user_data);
 static void categoria_on_btn_salva_clicked (GtkButton *button,
@@ -84,6 +88,7 @@ struct _CategoriaPrivate
                GtkWidget *w;
 
                GObject *lbl_id;
+               GObject *lbl_icona_percorso;
 
                gint id;
        };
@@ -160,6 +165,8 @@ Categoria
 
        priv->lbl_id = gtk_builder_get_object (priv->commons->gtkbuilder,
                                                                                   "label43");
+       priv->lbl_icona_percorso = gtk_builder_get_object (priv->commons->gtkbuilder,
+                                                                                                          "label5");
 
        g_signal_connect (priv->w,
                          "key-release-event", G_CALLBACK (categoria_on_key_release_event), (gpointer)a);
@@ -171,6 +178,9 @@ Categoria
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder4"),
                          "decode", G_CALLBACK (categoria_on_categoria_decode), (gpointer)a);
 
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button1"),
+                         "clicked", G_CALLBACK (categoria_on_btn_icona_clicked), (gpointer)a);
+
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button75"),
                          "clicked", G_CALLBACK (categoria_on_btn_annulla_clicked), (gpointer)a);
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button78"),
@@ -180,6 +190,8 @@ Categoria
 
        zak_form_form_clear (ZAK_FORM_FORM (priv->form));
 
+       gtk_label_set_text (GTK_LABEL (priv->lbl_icona_percorso), "");
+
        priv->id = id;
 
        if (priv->id == 0)
@@ -314,6 +326,32 @@ categoria_carica (Categoria *categoria)
 
        if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
+                       /* carico l'icona nel pulsante */
+                       GError *error;
+                       gchar *sql;
+                       const gchar *percorso;
+                       GdkPixbuf *pixbuf;
+
+                       sql = g_strdup_printf ("SELECT icona"
+                                                                  " FROM categorie"
+                                                                  " WHERE id = %d",
+                                                                  priv->id);
+                       percorso = gdaex_get_blob (priv->commons->gdaex, sql,
+                                                                          NULL, "icona");
+                       error = NULL;
+                       if (percorso != NULL)
+                               {
+                                       pixbuf = gdk_pixbuf_new_from_file (percorso, &error);
+                                       gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1")), pixbuf);
+                                       g_unlink (percorso);
+                               }
+                       else
+                               {
+                                       gtk_image_set_from_icon_name (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1")),
+                                                                                                 "gtk-missing-image",
+                                                                                                 GTK_ICON_SIZE_BUTTON);
+                               }
+                       g_free (sql);
                }
 }
 
@@ -325,6 +363,11 @@ categoria_salva (Categoria *categoria, gboolean chiudi)
        CategoriaClass *klass = CATEGORIA_GET_CLASS (categoria);
        CategoriaPrivate *priv = CATEGORIA_GET_PRIVATE (categoria);
 
+       gchar *sql;
+       gchar *percorso;
+
+       gboolean success;
+
        if (!zak_form_gtk_form_is_valid (priv->form, priv->w))
                {
                        return;
@@ -348,7 +391,8 @@ categoria_salva (Categoria *categoria, gboolean chiudi)
                        ret = zak_form_form_update (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider));
                }
 
-       if (ret)
+       success = ret;
+       if (success)
                {
                        g_signal_emit (categoria, klass->aggiornato_signal_id, 0);
 
@@ -359,6 +403,30 @@ categoria_salva (Categoria *categoria, gboolean chiudi)
                                        priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->lbl_id)), NULL, 10);
                                }
 
+                       /* salvo il file nel db */
+                       percorso = g_strdup (gtk_label_get_text (GTK_LABEL (priv->lbl_icona_percorso)));
+                       if (g_strcmp0 (percorso, "") != 0)
+                               {
+                                       sql = g_strdup_printf ("UPDATE categorie"
+                                                                                  " SET icona = ##/*name:'icona' type:'GdaBlob'*/"
+                                                                                  " WHERE id = %d",
+                                                                                  priv->id);
+                                       if (!gdaex_save_file_in_blob (priv->commons->gdaex,
+                                                                                                 sql,
+                                                                                                 "icona",
+                                                                                                 percorso))
+                                               {
+                                                       success = FALSE;
+
+                                                       g_free (sql);
+                                               }
+                               }
+
+                       g_free (percorso);
+               }
+
+       if (success)
+               {
                        solipa_message_dialog (priv->w,
                                               GTK_MESSAGE_INFO,
                                               GTK_BUTTONS_OK,
@@ -513,6 +581,72 @@ categoria_on_btn_categoria_browse_clicked (GtkButton *button,
        categorie_show (c, GTK_WINDOW (priv->w));
 }
 
+static void
+update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
+{
+       GtkWidget *preview;
+       char *filename;
+       GdkPixbuf *pixbuf;
+       gboolean have_preview;
+
+       preview = GTK_WIDGET (data);
+       filename = gtk_file_chooser_get_preview_filename (file_chooser);
+
+       pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
+       have_preview = (pixbuf != NULL);
+       g_free (filename);
+
+       gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
+       if (pixbuf)
+               g_object_unref (pixbuf);
+
+       gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
+}
+
+static void
+categoria_on_btn_icona_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       GtkWidget *dlg;
+       GtkWidget *preview;
+
+       Categoria *categoria = (Categoria *)user_data;
+       CategoriaPrivate *priv = CATEGORIA_GET_PRIVATE (categoria);
+
+       preview = gtk_image_new ();
+
+       dlg = gtk_file_chooser_dialog_new ("Scegli icona",
+                                                                          GTK_WINDOW (priv->w),
+                                                                          GTK_FILE_CHOOSER_ACTION_OPEN,
+                                                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                                          GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                                                          NULL);
+
+       gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dlg), preview);
+       g_signal_connect (dlg, "update-preview",
+                                         G_CALLBACK (update_preview_cb), preview);
+
+       if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
+               {
+                       gchar *filename;
+
+                       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
+
+                       gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1")), filename);
+                       if (gtk_image_get_pixbuf (GTK_IMAGE (gtk_builder_get_object (priv->commons->gtkbuilder, "image1"))) != NULL)
+                               {
+                                       gtk_label_set_text (GTK_LABEL (priv->lbl_icona_percorso), filename);
+                               }
+                       else
+                               {
+                                       gtk_label_set_text (GTK_LABEL (priv->lbl_icona_percorso), "");
+                               }
+
+                       g_free (filename);
+               }
+       gtk_widget_destroy (dlg);
+}
+
 static void
 categoria_on_btn_annulla_clicked (GtkButton *button,
                         gpointer user_data)