<object class="GtkLabel" id="label139">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Percorso del file</property>
+ <property name="label" translatable="yes">Percorso</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="button5">
+ <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="stock">gtk-open</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkButton" id="button144">
<property name="label" translatable="yes">...</property>
</object>
<packing>
<property name="expand">False</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
<object class="GtkLabel" id="label141">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Data del file</property>
+ <property name="label" translatable="yes">Data</property>
</object>
<packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<object class="GtkLabel" id="label142">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Dimensione del file</property>
+ <property name="label" translatable="yes">Dimensione</property>
</object>
<packing>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<property name="label" translatable="yes">Salva nel database</property>
</object>
<packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
<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="preview_widget_active">False</property>
<property name="local_only">False</property>
</object>
</child>
GValue *value,
GParamSpec *pspec);
+static void solipa_allegato_on_file_pulisci (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
+ gpointer user_data);
+static void solipa_allegato_on_btn_file_clicked (GtkButton *button,
+ gpointer user_data);
+
+static void solipa_allegato_apri_allegato (GtkWindow *transient, const gchar *filename);
+
+static void solipa_allegato_on_btn_apri_clicked (GtkButton *button,
+ gpointer user_data);
+
#define SOLIPA_ALLEGATO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_SOLIPA_ALLEGATO, SolipaAllegatoPrivate))
typedef struct _SolipaAllegatoPrivate SolipaAllegatoPrivate;
struct _SolipaAllegatoPrivate
{
Solipa *solipa;
+
+ GtkBuilder *gtkbuilder;
+
+ GtkWidget *widget;
+
+ GtkWidget *txt_percorso;
+ GtkWidget *txt_data;
+ GtkWidget *txt_dimensione;
+ GtkWidget *chk_salva_nel_db;
};
G_DEFINE_TYPE (SolipaAllegato, solipa_allegato, G_TYPE_OBJECT)
SolipaAllegato
*solipa_allegato_new (Solipa *solipa)
{
+ GError *error;
+
SolipaAllegato *solipa_allegato;
SolipaAllegatoPrivate *priv;
priv->solipa = solipa;
+ priv->gtkbuilder = solipa_get_gtkbuilder (solipa);
+
+ if (!GTK_IS_BUILDER (priv->gtkbuilder))
+ {
+ g_warning ("GtkBuilder non inizializzato.");
+ return NULL;
+ }
+
+ error = NULL;
+ gtk_builder_add_objects_from_file (priv->gtkbuilder,
+ solipa_get_guifile (priv->solipa),
+ g_strsplit ("table22",
+ "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("Errore nell'inzializzazione della gui: %s.",
+ error->message != NULL ? error->message : "nessun dettaglio");
+ return NULL;
+ }
+
+ priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "table22"));
+
+ priv->txt_percorso = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "entry42"));
+ priv->txt_data = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "entry44"));
+ priv->txt_dimensione = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "entry45"));
+ priv->chk_salva_nel_db = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "checkbutton2"));
+
+ g_signal_connect (priv->txt_percorso,
+ "icon-press", G_CALLBACK (solipa_allegato_on_file_pulisci), (gpointer *)solipa_allegato);
+ g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button5"),
+ "clicked", G_CALLBACK (solipa_allegato_on_btn_apri_clicked), (gpointer *)solipa_allegato);
+ g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button144"),
+ "clicked", G_CALLBACK (solipa_allegato_on_btn_file_clicked), (gpointer *)solipa_allegato);
+
return solipa_allegato;
}
+GtkWidget
+*solipa_allegato_get_widget (SolipaAllegato *solipa_allegato)
+{
+ SolipaAllegatoPrivate *priv;
+
+ priv = SOLIPA_ALLEGATO_GET_PRIVATE (solipa_allegato);
+
+ return priv->widget;
+}
+
/* PRIVATE */
static void
solipa_allegato_set_property (GObject *object,
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;
- }
+ }
+}
+static void
+solipa_allegato_on_file_pulisci (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ SolipaAllegato *f = (SolipaAllegato *)user_data;
+ SolipaAllegatoPrivate *priv = SOLIPA_ALLEGATO_GET_PRIVATE (f);
+
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_percorso), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_data), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_dimensione), "");
+}
+
+static void
+solipa_allegato_on_btn_file_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ SolipaAllegato *allegato = (SolipaAllegato *)user_data;
+ SolipaAllegatoPrivate *priv = SOLIPA_ALLEGATO_GET_PRIVATE (allegato);
+
+ GtkWidget *dialog;
+
+ dialog = gtk_file_chooser_dialog_new ("Apri file",
+ GTK_WINDOW (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_WINDOW)),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ char *filename;
+ struct stat buf;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ if (g_stat (filename, &buf) == 0)
+ {
+ struct tm *tm;
+
+ tm = localtime (&buf.st_mtime);
+
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_percorso), filename);
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_data),
+ g_strdup_printf ("%02d/%02d/%04d %02d.%02d.%02d",
+ tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900,
+ tm->tm_hour, tm->tm_min, tm->tm_sec));
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_dimensione), g_strdup_printf ("%d", buf.st_size));
+ }
+ else
+ {
+ /* file non esistente */
+ /* non dovrebbe succedere */
+ gtk_widget_destroy (dialog);
+ dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_WINDOW)),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Il file selezionato non esiste.");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_percorso), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_data), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->txt_dimensione), "");
+ }
+
+ g_free (filename);
+ }
+ gtk_widget_destroy (dialog);
+}
+
+static void
+solipa_allegato_apri_allegato (GtkWindow *transient, const gchar *filename)
+{
+ GtkWidget *dialog;
+ GFile *gfile;
+ GAppInfo *gappinfo;
+ GError *error;
+ GList *lfiles;
+
+ gfile = g_file_new_for_commandline_arg (filename);
+ if (gfile == NULL)
+ {
+ dialog = gtk_message_dialog_new (transient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Impossibile aprire l'allegato selezionato.");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ return;
+ }
+
+ error = NULL;
+ gappinfo = g_file_query_default_handler (gfile, NULL, &error);
+ if (gappinfo == NULL)
+ {
+ dialog = gtk_message_dialog_new (transient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Impossibile aprire l'allegato selezionato: %s.",
+ (error != NULL & error->message != NULL ? error->message : "nessun dettaglio"));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ return;
+ }
+
+ lfiles = NULL;
+ lfiles = g_list_append (lfiles, (gpointer)gfile);
+
+ error = NULL;
+ if (!g_app_info_launch (gappinfo, lfiles, NULL, &error))
+ {
+ dialog = gtk_message_dialog_new (transient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Impossibile aprire l'allegato selezionato: %s.",
+ (error != NULL & error->message != NULL ? error->message : "nessun dettaglio"));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ }
+}
+
+static void
+solipa_allegato_on_btn_apri_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ SolipaAllegato *allegato = (SolipaAllegato *)user_data;
+ SolipaAllegatoPrivate *priv = SOLIPA_ALLEGATO_GET_PRIVATE (allegato);
+
+ gchar *percorso;
+
+ percorso = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt_percorso));
+ if (percorso == NULL) return;
+
+ percorso = g_strdup (percorso);
+ if (g_strcmp0 (g_strstrip (percorso), "") == 0) return;
+
+ solipa_allegato_apri_allegato (GTK_WINDOW (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_WINDOW)), percorso);
}
--- /dev/null
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <solipa.h>
+#include <allegato.h>
+
+int
+main (int argc, char *argv[])
+{
+ GError *error;
+ GtkBuilder *builder;
+
+ Solipa *solipa;
+ SolipaAllegato *allegato;
+
+ GtkWidget *w;
+
+ gtk_init (&argc, &argv);
+
+ solipa = solipa_new ();
+ if (solipa == NULL)
+ {
+ g_error ("Errore nell'inizializzazione di Solipa.");
+ return 0;
+ }
+
+ allegato = solipa_allegato_new (solipa);
+ if (allegato == NULL)
+ {
+ g_error ("Errore nell'inizializzazione di SolipaAllegato.");
+ return 0;
+ }
+
+ builder = gtk_builder_new ();
+ error = NULL;
+ gtk_builder_add_objects_from_file (builder, GUIDIR "/tests.ui",
+ g_strsplit ("w_allegato",
+ "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_error ("Errore nel caricamento della gui: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ return 0;
+ }
+
+ gtk_builder_connect_signals (builder, NULL);
+
+ w = GTK_WIDGET (gtk_builder_get_object (builder, "w_allegato"));
+
+ gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "vbox1")),
+ solipa_allegato_get_widget (allegato),
+ TRUE, TRUE, 5);
+
+ gtk_widget_show (w);
+
+ gtk_main ();
+
+ return 0;
+}