New details dialog for gtk
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 25 Nov 2009 12:55:30 +0000 (13:55 +0100)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 25 Nov 2009 16:01:52 +0000 (17:01 +0100)
src/gtk/modest-platform.c
src/hildon2/modest-platform.c
src/widgets/Makefile.am
src/widgets/modest-gtk-details-dialog.c [new file with mode: 0644]
src/widgets/modest-gtk-details-dialog.h [new file with mode: 0644]
src/widgets/modest-toolkit-factory.c
src/widgets/modest-toolkit-factory.h

index b82bf74..3a13c3f 100644 (file)
@@ -62,6 +62,7 @@
 #include <modest-ui-constants.h>
 #include <modest-icon-names.h>
 #include <modest-count-stream.h>
+#include <modest-gtk-details-dialog.h>
 #include <math.h>
 
 
@@ -1047,7 +1048,6 @@ gboolean
 modest_platform_connect_and_wait (GtkWindow *parent_window, 
                                  TnyAccount *account)
 {
-       ConnectAndWaitData *data = NULL;
        gboolean device_online;
        TnyDevice *device;
        TnyConnectionStatus conn_status;
@@ -1228,7 +1228,7 @@ modest_platform_animation_banner (GtkWidget *parent,
                                  const gchar *animation_name,
                                  const gchar *text)
 {
-       return;
+       return NULL;
 }
 
 typedef struct
@@ -1342,16 +1342,13 @@ on_cert_dialog_response (GtkDialog *dialog, gint response_id,  const gchar* cert
 {
        /* GTK_RESPONSE_HELP means we need to show the certificate */
        if (response_id == GTK_RESPONSE_APPLY) {
-               GtkWidget *note;
                gchar *msg;
                
                /* Do not close the dialog */
                g_signal_stop_emission_by_name (dialog, "response");
 
                msg = g_strdup_printf (_("mcen_ni_view_unknown_certificate"), cert);    
-               note = modest_platform_information_banner (NULL, NULL, msg);
-               gtk_dialog_run (GTK_DIALOG(note));
-               gtk_widget_destroy (note);
+               modest_platform_run_information_dialog (NULL, msg, TRUE);
        }
 }
 
@@ -1383,9 +1380,6 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
                                _HL("wdgt_bd_no"), GTK_RESPONSE_CANCEL,
                                NULL, NULL);
 
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
-                                    (GtkWindow *) note, (GtkWindow *) win);
-
        g_signal_connect (G_OBJECT(note), "response",
                          G_CALLBACK(on_cert_dialog_response),
                          (gpointer) certificate);
@@ -1405,6 +1399,7 @@ modest_platform_run_alert_dialog (const gchar* prompt,
 
        gboolean retval = TRUE;
        if (is_question) {
+               GtkWidget *dialog;
                /* The Tinymail documentation says that we should show Yes and No buttons,
                 * when it is a question.
                 * Obviously, we need tinymail to use more specific error codes instead,
@@ -1667,7 +1662,8 @@ modest_platform_run_folder_details_dialog (GtkWindow *parent_window,
        GtkWidget *dialog;
        
        /* Create dialog */
-       dialog = modest_hildon2_details_dialog_new_with_folder (parent_window, folder);
+       dialog = modest_toolkit_factory_create_details_dialog_with_folder (modest_runtime_get_toolkit_factory (),
+                                                                          parent_window, folder);
 
        /* Run dialog */
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
@@ -1752,7 +1748,8 @@ modest_platform_run_header_details_dialog (GtkWindow *parent_window,
        GtkWidget *dialog;
 
        /* Create dialog */
-       dialog = modest_hildon2_details_dialog_new_with_header (parent_window, header, !async_get_size);
+       dialog = modest_toolkit_factory_create_details_dialog_with_header (modest_runtime_get_toolkit_factory (),
+                                                                          parent_window, header, !async_get_size);
 
        if (async_get_size && msg && TNY_IS_MSG (msg)) {
                HeaderDetailsGetSizeInfo *info;
index 125c3c8..74c27a9 100644 (file)
@@ -2486,7 +2486,8 @@ modest_platform_run_folder_details_dialog (GtkWindow *parent_window,
        GtkWidget *dialog;
        
        /* Create dialog */
-       dialog = modest_hildon2_details_dialog_new_with_folder (parent_window, folder);
+       dialog = modest_toolkit_factory_create_details_dialog_with_folder (modest_runtime_get_toolkit_factory (),
+                                                                          parent_window, folder);
 
        /* Run dialog */
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
@@ -2571,7 +2572,8 @@ modest_platform_run_header_details_dialog (GtkWindow *parent_window,
        GtkWidget *dialog;
 
        /* Create dialog */
-       dialog = modest_hildon2_details_dialog_new_with_header (parent_window, header, !async_get_size);
+       dialog = modest_toolkit_factory_create_details_dialog_with_header (modest_runtime_get_toolkit_factory (),
+                                                                          parent_window, header, !async_get_size);
 
        if (async_get_size && msg && TNY_IS_MSG (msg)) {
                HeaderDetailsGetSizeInfo *info;
index 099a092..5cdd28c 100644 (file)
@@ -67,6 +67,8 @@ libmodest_widgets_la_SOURCES=          \
        modest-global-settings-dialog.h \
        modest-gtkhtml-mime-part-view.c \
        modest-gtkhtml-mime-part-view.h \
+       modest-gtk-details-dialog.c \
+       modest-gtk-details-dialog.h \
        modest-gtk-security-options-view.c \
        modest-gtk-security-options-view.h \
        modest-hbox-cell-renderer.c    \
diff --git a/src/widgets/modest-gtk-details-dialog.c b/src/widgets/modest-gtk-details-dialog.c
new file mode 100644 (file)
index 0000000..42a6135
--- /dev/null
@@ -0,0 +1,159 @@
+/* Copyright (c) 2008, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modest-details-dialog.h"
+
+#include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtktable.h>
+#include <gtk/gtkstock.h>
+#include <gtk/gtklabel.h>
+#include <tny-msg.h>
+#include <tny-header.h>
+#include <tny-header-view.h>
+#include <tny-folder-store.h>
+#include <modest-tny-folder.h>
+#include <modest-tny-account.h>
+#include <modest-text-utils.h>
+#include "modest-gtk-details-dialog.h"
+#include <modest-scrollable.h>
+#include <modest-ui-constants.h>
+#include <modest-runtime.h>
+
+static void modest_gtk_details_dialog_create_container_default (ModestDetailsDialog *self);
+
+
+G_DEFINE_TYPE (ModestGtkDetailsDialog, 
+              modest_gtk_details_dialog, 
+              MODEST_TYPE_DETAILS_DIALOG);
+
+#define MODEST_GTK_DETAILS_DIALOG_GET_PRIVATE(o) \
+       (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DETAILS_DIALOG, ModestGtkDetailsDialogPrivate))
+
+
+typedef struct _ModestGtkDetailsDialogPrivate ModestGtkDetailsDialogPrivate;
+
+struct _ModestGtkDetailsDialogPrivate
+{
+       GtkWidget *props_table;
+};
+
+static void
+modest_gtk_details_dialog_finalize (GObject *object)
+{
+       G_OBJECT_CLASS (modest_gtk_details_dialog_parent_class)->finalize (object);
+}
+
+static void
+modest_gtk_details_dialog_class_init (ModestGtkDetailsDialogClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (klass, sizeof (ModestGtkDetailsDialogPrivate));
+       object_class->finalize = modest_gtk_details_dialog_finalize;
+
+       MODEST_DETAILS_DIALOG_CLASS (klass)->create_container_func = 
+               modest_gtk_details_dialog_create_container_default;
+}
+
+static void
+modest_gtk_details_dialog_init (ModestGtkDetailsDialog *self)
+{
+}
+
+GtkWidget*
+modest_gtk_details_dialog_new_with_header (GtkWindow *parent, 
+                                              TnyHeader *header,
+                                              gboolean get_size)
+{
+       ModestDetailsDialog *dialog;
+
+       g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
+       g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
+
+       dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_GTK_DETAILS_DIALOG, 
+                                                       "transient-for", parent, 
+                                                       NULL));
+
+       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
+       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_header_func (dialog, header, get_size);
+
+       return GTK_WIDGET (dialog);
+}
+
+GtkWidget* 
+modest_gtk_details_dialog_new_with_folder  (GtkWindow *parent, 
+                                               TnyFolder *folder)
+{
+       ModestDetailsDialog *dialog;
+
+       g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
+       g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
+
+       dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_GTK_DETAILS_DIALOG, 
+                                                       "transient-for", parent, 
+                                                       NULL));
+
+       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
+       MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_folder_func (dialog, folder);
+
+       return GTK_WIDGET (dialog);
+}
+
+
+static void
+modest_gtk_details_dialog_create_container_default (ModestDetailsDialog *self)
+{
+       ModestGtkDetailsDialogPrivate *priv;
+       GtkWidget *scrollable;
+       GtkWidget *align;
+
+       priv = MODEST_GTK_DETAILS_DIALOG_GET_PRIVATE (self);
+
+       gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
+
+       priv->props_table = gtk_table_new (0, 2, FALSE);
+       gtk_table_set_col_spacings (GTK_TABLE (priv->props_table), 12);
+       gtk_table_set_row_spacings (GTK_TABLE (priv->props_table), 1);
+
+       align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DEFAULT);
+
+       scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
+       modest_scrollable_set_vertical_policy (MODEST_SCROLLABLE (scrollable), GTK_POLICY_AUTOMATIC);
+       modest_scrollable_set_horizontal_policy (MODEST_SCROLLABLE (scrollable), GTK_POLICY_NEVER);
+
+       gtk_container_add (GTK_CONTAINER (align), priv->props_table);
+       modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), 
+                                            GTK_WIDGET (align));
+       gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), scrollable);
+
+       gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
+}
diff --git a/src/widgets/modest-gtk-details-dialog.h b/src/widgets/modest-gtk-details-dialog.h
new file mode 100644 (file)
index 0000000..deb837a
--- /dev/null
@@ -0,0 +1,83 @@
+/* Copyright (c) 2008, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *      contributors may be used to endorse or promote products derived from
+ *      this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_GTK_DETAILS_DIALOG
+#define __MODEST_GTK_DETAILS_DIALOG
+
+#include <glib.h>
+#include <gtk/gtkdialog.h>
+#include <tny-header.h>
+#include "modest-details-dialog.h"
+
+G_BEGIN_DECLS
+
+#define MODEST_TYPE_GTK_DETAILS_DIALOG modest_gtk_details_dialog_get_type()
+
+#define MODEST_GTK_DETAILS_DIALOG(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+       MODEST_TYPE_GTK_DETAILS_DIALOG, ModestGtkDetailsDialog))
+
+#define MODEST_GTK_DETAILS_DIALOG_CLASS(klass) \
+       (G_TYPE_CHECK_CLASS_CAST ((klass), \
+       MODEST_TYPE_GTK_DETAILS_DIALOG, ModestGtkDetailsDialogClass))
+
+#define MODEST_IS_GTK_DETAILS_DIALOG(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+       MODEST_TYPE_GTK_DETAILS_DIALOG))
+
+#define MODEST_IS_GTK_DETAILS_DIALOG_CLASS(klass) \
+       (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+       MODEST_TYPE_GTK_DETAILS_DIALOG))
+
+#define MODEST_GTK_DETAILS_DIALOG_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+       MODEST_TYPE_GTK_DETAILS_DIALOG, ModestGtkDetailsDialogClass))
+
+typedef struct {
+       ModestDetailsDialog parent;
+       
+} ModestGtkDetailsDialog;
+
+typedef struct {
+       ModestDetailsDialogClass parent_class;
+
+} ModestGtkDetailsDialogClass;
+
+GType modest_gtk_details_dialog_get_type (void);
+
+GtkWidget* modest_gtk_details_dialog_new_with_header (GtkWindow *parent, 
+                                                     TnyHeader *header,
+                                                     gboolean get_size);
+
+GtkWidget* modest_gtk_details_dialog_new_with_folder  (GtkWindow *parent, 
+                                                      TnyFolder *folder);
+
+G_END_DECLS
+
+#endif /* __MODEST_GTK_DETAILS_DIALOG */
index 234d49a..8e338cc 100644 (file)
@@ -49,6 +49,7 @@
 #define USE_GTK_SECURITY_OPTIONS_VIEW
 #define USE_GTK_TEXT_VIEW
 #define USE_SELECTOR_COMBOBOX
+#define USE_GTK_DETAILS_DIALOG
 #endif
 
 #ifdef USE_SCROLLED_WINDOW
 #include <modest-selector-picker.h>
 #endif
 
+#ifdef USE_GTK_DETAILS_DIALOG
+#include <modest-gtk-details-dialog.h>
+#else
+#include <modest-hildon2-details-dialog.h>
+#endif
+
 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
 
@@ -138,6 +145,10 @@ static GtkWidget * modest_toolkit_factory_create_security_options_view_default (
 static GtkWidget * modest_toolkit_factory_create_text_view_default            (ModestToolkitFactory *self);
 static GtkWidget * modest_toolkit_factory_create_selector_default             (ModestToolkitFactory *self,
                                                                               ModestPairList *pairs, GEqualFunc id_equal_func);
+static GtkWidget * modest_toolkit_factory_create_details_dialog_with_header_default   (ModestToolkitFactory *self, GtkWindow *parent,
+                                                                              TnyHeader *header, gboolean get_size);
+static GtkWidget * modest_toolkit_factory_create_details_dialog_with_folder_default  (ModestToolkitFactory *self, GtkWindow *parent,
+                                                                             TnyFolder *folder);
 
 /* globals */
 static GObjectClass *parent_class = NULL;
@@ -174,6 +185,8 @@ modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
        klass->create_security_options_view = modest_toolkit_factory_create_security_options_view_default;
        klass->create_text_view = modest_toolkit_factory_create_text_view_default;
        klass->create_selector = modest_toolkit_factory_create_selector_default;
+       klass->create_details_dialog_with_header = modest_toolkit_factory_create_details_dialog_with_header_default;
+       klass->create_details_dialog_with_folder = modest_toolkit_factory_create_details_dialog_with_folder_default;
 }
 
 static void
@@ -902,3 +915,46 @@ modest_selector_get_value_max_chars (GtkWidget *self)
        return modest_selector_picker_get_value_max_chars (MODEST_SELECTOR_PICKER (self));
 #endif
 }
+
+GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_header (ModestToolkitFactory *self,
+                                                         GtkWindow *parent,
+                                                         TnyHeader *header,
+                                                         gboolean get_size)
+{
+       return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_details_dialog_with_header (self, parent, header, get_size);
+}
+
+static GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_header_default (ModestToolkitFactory *self,
+                                                                 GtkWindow *parent,
+                                                                 TnyHeader *header, 
+                                                                 gboolean get_size)
+{
+#ifndef USE_GTK_DETAILS_DIALOG
+       return modest_hildon2_details_dialog_new_with_header (parent, header, get_size);
+#else
+       return modest_gtk_details_dialog_new_with_header (parent, header, get_size);
+#endif
+}
+
+GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_folder (ModestToolkitFactory *self,
+                                                         GtkWindow *parent,
+                                                         TnyFolder *folder)
+{
+       return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_details_dialog_with_folder (self, parent, folder);
+}
+
+static GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_folder_default (ModestToolkitFactory *self,
+                                                                 GtkWindow *parent,
+                                                                 TnyFolder *folder)
+{
+#ifndef USE_GTK_DETAILS_DIALOG
+       return modest_hildon2_details_dialog_new_with_folder (parent, folder);
+#else
+       return modest_gtk_details_dialog_new_with_folder (parent, folder);
+#endif
+}
+
index efe4dc1..8c00a5c 100644 (file)
@@ -6,6 +6,8 @@
 #include <modest-presets.h>
 #include <widgets/modest-security-options-view.h>
 #include <modest-pair.h>
+#include <tny-header.h>
+#include <tny-folder.h>
 
 G_BEGIN_DECLS
 
@@ -56,6 +58,10 @@ struct                                          _ModestToolkitFactoryClass
        GtkWidget * (*create_text_view) (ModestToolkitFactory *self);
        GtkWidget * (*create_selector) (ModestToolkitFactory *self,
                                        ModestPairList *pairs, GEqualFunc id_equal_func);
+       GtkWidget * (*create_details_dialog_with_header) (ModestToolkitFactory *self, GtkWindow *parent,
+                                                         TnyHeader *header, gboolean get_size);
+       GtkWidget * (*create_details_dialog_with_folder) (ModestToolkitFactory *self, GtkWindow *parent,
+                                                         TnyFolder *folder);
 };
 
 struct                                          _ModestToolkitFactory
@@ -118,6 +124,14 @@ GtkWidget *
 modest_toolkit_factory_create_selector (ModestToolkitFactory *self,
                                        ModestPairList *pairs, GEqualFunc id_equal_func);
 
+GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_header (ModestToolkitFactory *self, GtkWindow *parent,
+                                                         TnyHeader *header, gboolean get_size);
+
+GtkWidget *
+modest_toolkit_factory_create_details_dialog_with_folder (ModestToolkitFactory *self, GtkWindow *parent,
+                                                         TnyFolder *folder);
+
 gboolean
 modest_togglable_get_active (GtkWidget *widget);