</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>
#endif
#include <gdk/gdk.h>
+#include <glib/gstdio.h>
#include <libzakgtkdecoder/libzakgtkdecoder.h>
#include <libzakform/libzakform.h>
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,
GtkWidget *w;
GObject *lbl_id;
+ GObject *lbl_icona_percorso;
gint id;
};
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);
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"),
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)
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);
}
}
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;
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);
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,
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)