]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Added SolipaProgressWindow (with test).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 16 Jun 2011 11:18:10 +0000 (13:18 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 16 Jun 2011 11:18:10 +0000 (13:18 +0200)
.gitignore
configure.ac
data/libsolipa/gui/libsolipa.ui
src/Makefile.am
src/libsolipa.h
src/progresswindow.c [new file with mode: 0644]
src/progresswindow.h [new file with mode: 0644]
tests/Makefile.am
tests/progresswindow.c [new file with mode: 0644]

index f4d398b191f8c08c6eccc4d66d19d9932ede17a6..1ddf9ffe904db50681c117c33b1324b1a5938169 100644 (file)
@@ -49,6 +49,7 @@ Rules-quot
 *.exe
 tests/allegato
 tests/mail
+tests/progresswindow
 tests/utils
 tests/utils_codfisc_piva
 tests/utils_format_money
index e013399237bb8303b310184a9dd26c68f11f2fcb..5d837927c989490940f534718feb9b62cca4d098 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.65)
-AC_INIT([libsolipa], [0.3.0], [azagli@libero.it])
+AC_INIT([libsolipa], [0.3.1], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/solipa.c])
 AC_CONFIG_HEADER([config.h])
 
index a7ae81605dc0d3755817df18ea29cb77c8e4603c..c5ddddeae087b5b69ce438b3bbfa9b1f640b9d07 100644 (file)
       <action-widget response="0">button7</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkWindow" id="w_progress">
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="default_width">550</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="deletable">False</property>
+    <child>
+      <object class="GtkVBox" id="vbox6">
+        <property name="visible">True</property>
+        <property name="border_width">5</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">5</property>
+        <child>
+          <object class="GtkLabel" id="label13">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">label</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progressbar1">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHButtonBox" id="hbuttonbox2">
+            <property name="visible">True</property>
+            <property name="layout_style">center</property>
+            <child>
+              <object class="GtkButton" id="button8">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="no_show_all">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
index 5a1e1fa3be2db9a50554a8a34048b92e37d1347e..c2e59c1df7e4fc136bcbdc267dca72d371d2ff16 100644 (file)
@@ -13,6 +13,7 @@ libsolipa_la_SOURCES = solipa.c \
                        camelsession.c \
                        mail.c \
                        mailui.c \
+                       progresswindow.c \
                        utils.c
 
 libsolipa_la_LDFLAGS = -no-undefined
@@ -23,6 +24,7 @@ libsolipa_include_HEADERS = libsolipa.h \
                             camelsession.h \
                             mail.h \
                             mailui.h \
+                            progresswindow.h \
                             utils.h
 
 libsolipa_includedir = $(includedir)/libsolipa
index a7c7ae7bf7385317c9b808f572600e908fbca16b..3e6c2c83f59a58716b8747c5c5c40f74c52e952b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-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
@@ -22,6 +22,7 @@
 #include <libsolipa/solipa.h>
 #include <libsolipa/allegato.h>
 #include <libsolipa/mail.h>
+#include <libsolipa/progresswindow.h>
 #include <libsolipa/utils.h>
 
 #endif /* __LIBSOLIPA_H__ */
diff --git a/src/progresswindow.c b/src/progresswindow.c
new file mode 100644 (file)
index 0000000..178048a
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include "progresswindow.h"
+
+enum
+{
+       PROP_0,
+       PROP_TITLE,
+       PROP_LABEL,
+       PROP_WITH_CANCEL_BUTTON
+};
+
+static void solipa_progress_window_class_init (SolipaProgressWindowClass *klass);
+static void solipa_progress_window_init (SolipaProgressWindow *solipa_progress_window);
+
+static void solipa_progress_window_set_property (GObject *object,
+                               guint property_id,
+                               const GValue *value,
+                               GParamSpec *pspec);
+static void solipa_progress_window_get_property (GObject *object,
+                               guint property_id,
+                               GValue *value,
+                               GParamSpec *pspec);
+
+static void solipa_progress_window_on_cancel_clicked (GtkButton *button,
+                                              gpointer user_data);
+
+#define SOLIPA_PROGRESS_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_SOLIPA_PROGRESS_WINDOW, SolipaProgressWindowPrivate))
+
+typedef struct _SolipaProgressWindowPrivate SolipaProgressWindowPrivate;
+struct _SolipaProgressWindowPrivate
+       {
+               Solipa *solipa;
+
+               GtkWidget *dialog;
+               GtkWidget *label;
+               GtkWidget *progress;
+               GtkWidget *btn_cancel;
+       };
+
+G_DEFINE_TYPE (SolipaProgressWindow, solipa_progress_window, G_TYPE_OBJECT)
+
+static void
+solipa_progress_window_class_init (SolipaProgressWindowClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->set_property = solipa_progress_window_set_property;
+       object_class->get_property = solipa_progress_window_get_property;
+
+       g_object_class_install_property (object_class, PROP_TITLE,
+                                        g_param_spec_string ("title",
+                                                             "Title text",
+                                                             "Title's text",
+                                                             "",
+                                                             G_PARAM_READWRITE));
+
+       g_object_class_install_property (object_class, PROP_LABEL,
+                                        g_param_spec_string ("label",
+                                                             "Label text",
+                                                             "Label's text",
+                                                             "",
+                                                             G_PARAM_READWRITE));
+
+       g_object_class_install_property (object_class, PROP_WITH_CANCEL_BUTTON,
+                                        g_param_spec_boolean ("with-cancel-button",
+                                                              "With cancel button",
+                                                              "With cancel button",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE));
+
+       /**
+        * SolipaProgressWindow::btn_cancel_clicked:
+        * @solipa_progress_window:
+        *
+        */
+       klass->btn_cancel_clicked_signal_id = g_signal_new ("btn-cancel-clicked",
+                                                           G_TYPE_FROM_CLASS (object_class),
+                                                           G_SIGNAL_RUN_LAST,
+                                                           0,
+                                                           NULL,
+                                                           NULL,
+                                                           g_cclosure_marshal_BOOLEAN__FLAGS,
+                                                           G_TYPE_BOOLEAN,
+                                                           1, G_TYPE_INT);
+
+       g_type_class_add_private (object_class, sizeof (SolipaProgressWindowPrivate));
+}
+
+static void
+solipa_progress_window_init (SolipaProgressWindow *solipa_progress_window)
+{
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (solipa_progress_window);
+}
+
+/**
+ * solipa_progress_window_new:
+ * @solipa:
+ *
+ * Returns: the newly created #SolipaProgressWindow object.
+ */
+SolipaProgressWindow
+*solipa_progress_window_new (Solipa *solipa)
+{
+       GtkBuilder *builder;
+       GError *error;
+
+       SolipaProgressWindow *solipa_progress_window;
+       SolipaProgressWindowPrivate *priv;
+
+       g_return_val_if_fail (IS_SOLIPA (solipa), NULL);
+
+       solipa_progress_window = SOLIPA_PROGRESS_WINDOW (g_object_new (solipa_progress_window_get_type (), NULL));
+
+       priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (solipa_progress_window);
+
+       priv->solipa = solipa;
+
+       builder = solipa_get_gtkbuilder (solipa);
+
+       if (!GTK_IS_BUILDER (builder))
+               {
+                       g_warning ("GtkBuilder non inizializzato.");
+                       return NULL;
+               }
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (builder,
+                                          solipa_get_guifile (solipa),
+                                          g_strsplit ("w_progress",
+                                                      "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore nell'inzializzazione della gui: %s.",
+                                  error->message != NULL ? error->message : "no details");
+                       return NULL;
+               }
+
+       priv->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "w_progress"));
+       priv->label = GTK_WIDGET (gtk_builder_get_object (builder, "label13"));
+       priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "progressbar1"));
+
+       g_signal_connect (gtk_builder_get_object (builder, "button8"), "clicked",
+                         G_CALLBACK (solipa_progress_window_on_cancel_clicked), (gpointer)solipa_progress_window);
+
+       return solipa_progress_window;
+}
+
+/**
+ * solipa_progress_window_get_dialog:
+ * @solipa:
+ * @transient:
+ *
+ * Returns: the dialog.
+ */
+void
+solipa_progress_window_run (SolipaProgressWindow *progressw, GtkWindow *transient)
+{
+       g_return_if_fail (IS_SOLIPA_PROGRESS_WINDOW (progressw));
+
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (progressw);
+
+       if (GTK_IS_WINDOW (transient))
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), transient);
+               }
+
+       gtk_widget_show_all (priv->dialog);
+       gtk_widget_show_now (priv->dialog);
+
+       return;
+}
+
+void
+solipa_progress_window_pulse (SolipaProgressWindow *progressw)
+{
+       g_return_if_fail (IS_SOLIPA_PROGRESS_WINDOW (progressw));
+
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (progressw);
+
+       gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress));
+}
+
+void
+solipa_progress_window_set_fraction (SolipaProgressWindow *progressw, gdouble fraction)
+{
+       g_return_if_fail (IS_SOLIPA_PROGRESS_WINDOW (progressw));
+
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (progressw);
+
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress), fraction);
+}
+
+/* PRIVATE */
+static void
+solipa_progress_window_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+       SolipaProgressWindow *solipa_progress_window = (SolipaProgressWindow *)object;
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (solipa_progress_window);
+
+       switch (property_id)
+               {
+                       case PROP_TITLE:
+                               gtk_window_set_title (GTK_WINDOW (priv->dialog), g_strstrip (g_value_dup_string (value)));
+                               break;
+
+                       case PROP_LABEL:
+                               gtk_label_set_text (GTK_LABEL (priv->label), g_strstrip (g_value_dup_string (value)));
+                               break;
+
+                       case PROP_WITH_CANCEL_BUTTON:
+                               gtk_widget_set_visible (priv->btn_cancel, g_value_get_boolean (value));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+solipa_progress_window_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+       SolipaProgressWindow *solipa_progress_window = (SolipaProgressWindow *)object;
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (solipa_progress_window);
+
+       switch (property_id)
+               {
+                       case PROP_TITLE:
+                               g_value_set_string (value, gtk_window_get_title (GTK_WINDOW (priv->dialog)));
+                               break;
+
+                       case PROP_LABEL:
+                               g_value_set_string (value, gtk_label_get_text (GTK_LABEL (priv->label)));
+                               break;
+
+                       case PROP_WITH_CANCEL_BUTTON:
+                               g_value_set_boolean (value, gtk_widget_get_visible (priv->btn_cancel));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+/* CALLBACK */
+static void
+solipa_progress_window_on_cancel_clicked (GtkButton *button,
+                                  gpointer user_data)
+{
+       gboolean ret;
+
+       SolipaProgressWindow *solipa_progress_window = (SolipaProgressWindow *)user_data;
+       SolipaProgressWindowPrivate *priv = SOLIPA_PROGRESS_WINDOW_GET_PRIVATE (solipa_progress_window);
+       SolipaProgressWindowClass *klass = SOLIPA_PROGRESS_WINDOW_GET_CLASS (solipa_progress_window);
+
+       ret = FALSE;
+       g_signal_emit (G_OBJECT (user_data), klass->btn_cancel_clicked_signal_id, 0, 0, &ret);
+
+       if (!ret)
+               {
+                       /* close the dialog */
+                       gtk_widget_destroy (priv->dialog);
+                       g_object_unref (user_data);
+               }
+}
\ No newline at end of file
diff --git a/src/progresswindow.h b/src/progresswindow.h
new file mode 100644 (file)
index 0000000..078209f
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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
+ */
+
+#ifndef __SOLIPA_PROGRESS_WINDOW_H__
+#define __SOLIPA_PROGRESS_WINDOW_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "solipa.h"
+
+
+G_BEGIN_DECLS
+
+
+#define TYPE_SOLIPA_PROGRESS_WINDOW                 (solipa_progress_window_get_type ())
+#define SOLIPA_PROGRESS_WINDOW(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SOLIPA_PROGRESS_WINDOW, SolipaProgressWindow))
+#define SOLIPA_PROGRESS_WINDOW_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SOLIPA_PROGRESS_WINDOW, SolipaProgressWindowClass))
+#define IS_SOLIPA_PROGRESS_WINDOW(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SOLIPA_PROGRESS_WINDOW))
+#define IS_SOLIPA_PROGRESS_WINDOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SOLIPA_PROGRESS_WINDOW))
+#define SOLIPA_PROGRESS_WINDOW_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SOLIPA_PROGRESS_WINDOW, SolipaProgressWindowClass))
+
+typedef struct _SolipaProgressWindow SolipaProgressWindow;
+typedef struct _SolipaProgressWindowClass SolipaProgressWindowClass;
+
+struct _SolipaProgressWindow
+       {
+               GObject parent;
+       };
+
+struct _SolipaProgressWindowClass
+       {
+               GObjectClass parent_class;
+
+               guint btn_cancel_clicked_signal_id;
+       };
+
+GType solipa_progress_window_get_type (void) G_GNUC_CONST;
+
+
+SolipaProgressWindow *solipa_progress_window_new (Solipa *solipa);
+
+void solipa_progress_window_run (SolipaProgressWindow *progressw, GtkWindow *transient);
+
+void solipa_progress_window_pulse (SolipaProgressWindow *progressw);
+void solipa_progress_window_set_fraction (SolipaProgressWindow *progressw, gdouble fraction);
+
+
+G_END_DECLS
+
+
+#endif /* __SOLIPA_PROGRESS_WINDOW_H__ */
index 1abf03d1190874e99f33269c8ef74b3946380d01..f694e60c67829e69994d2f7044e2dec29567abc3 100644 (file)
@@ -13,6 +13,7 @@ noinst_PROGRAMS = allegato \
                   mail \
                   mail_get_addresses_from_string \
                   mailui \
+                  progresswindow \
                   utils \
                   utils_codfisc_piva \
                   utils_format_money \
diff --git a/tests/progresswindow.c b/tests/progresswindow.c
new file mode 100644 (file)
index 0000000..e2997f5
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * 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 <progresswindow.h>
+
+Solipa *solipa;
+SolipaProgressWindow *solipa_prgw;
+
+GtkWidget *w;
+
+gboolean stop;
+
+static gboolean
+on_btn_cancel_clicked (gpointer instance, gpointer user_data)
+{
+       stop = TRUE;
+       g_debug ("Cancel clicked");
+       return FALSE;
+}
+
+gboolean
+on_w_delete_event (GtkWidget *widget,
+                   GdkEvent *event,
+                   gpointer user_data)
+{
+       return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+       GError *error;
+
+       gtk_init (&argc, &argv);
+
+       solipa = solipa_new ();
+       if (solipa == NULL)
+               {
+                       g_error ("Errore nell'inizializzazione di Solipa.");
+                       return 0;
+               }
+
+       solipa_prgw = solipa_progress_window_new (solipa);
+       if (solipa_prgw == NULL)
+               {
+                       g_error ("Errore nell'inizializzazione di SolipaProgressWindow.");
+                       return 0;
+               }
+
+       w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_default_size (GTK_WINDOW (w), 600, 550);
+       g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), (gpointer)solipa);
+       g_signal_connect (w, "destroy", gtk_main_quit, NULL);
+
+       g_signal_connect (G_OBJECT (solipa_prgw), "btn-cancel-clicked",
+                         G_CALLBACK (on_btn_cancel_clicked), NULL);
+
+       g_object_set (G_OBJECT (solipa_prgw),
+                     "title", "SolipaProgressWindow test",
+                     "label", "Please wait...",
+                     NULL);
+
+       gtk_widget_show (w);
+
+       stop = FALSE;
+       solipa_progress_window_run (solipa_prgw, GTK_WINDOW (w));
+
+       guint i;
+       for (i = 0; i < 20; i++)
+       {
+               if (stop) break;
+               while (gtk_events_pending ()) gtk_main_iteration ();
+               g_usleep (500000);
+
+               g_object_set (G_OBJECT (solipa_prgw),
+                             "label", g_strdup_printf ("Please wait... %d", i),
+                             NULL);
+               solipa_progress_window_pulse (solipa_prgw);
+       }
+
+       if (!stop)
+               {
+                       g_object_set (G_OBJECT (solipa_prgw),
+                                     "label", "Done!",
+                                     NULL);
+
+                       while (gtk_events_pending ()) gtk_main_iteration ();
+                       g_usleep (5000000);
+
+                       for (i = 0; i < 20; i++)
+                               {
+                                       if (stop) break;
+                                       while (gtk_events_pending ()) gtk_main_iteration ();
+                                       g_usleep (500000);
+
+                                       g_object_set (G_OBJECT (solipa_prgw),
+                                                     "label", g_strdup_printf ("Please wait... %f", 1.0 / 20.0 * (gdouble)i),
+                                                     NULL);
+                                       solipa_progress_window_set_fraction (solipa_prgw, 1.0 / 20.0 * (gdouble)i);
+                               }
+                       if (!stop)
+                               {
+                                       solipa_progress_window_set_fraction (solipa_prgw, 1.0 / 20.0 * (gdouble)i);
+                                       g_object_set (G_OBJECT (solipa_prgw),
+                                                     "label", "Done!",
+                                                     NULL);
+                               }
+               }
+
+         gtk_main ();
+
+       g_object_unref (solipa);
+
+       return 0;
+}