2bc983abee1e8815afaab5885bbda2d36bd6e2dc
[modest] / src / hildon2 / modest-hildon2-details-dialog.c
1 /* Copyright (c) 2008, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "modest-details-dialog.h"
31
32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
34 #include <gtk/gtkscrolledwindow.h>
35 #include <gtk/gtktable.h>
36 #include <gtk/gtkstock.h>
37 #include <gtk/gtklabel.h>
38 #include <tny-msg.h>
39 #include <tny-header.h>
40 #include <tny-header-view.h>
41 #include <tny-folder-store.h>
42 #include <modest-tny-folder.h>
43 #include <modest-tny-account.h>
44 #include <modest-text-utils.h>
45 #include "modest-hildon2-details-dialog.h"
46 #include <hildon/hildon-pannable-area.h>
47 #include <modest-ui-constants.h>
48
49 static void modest_hildon2_details_dialog_create_container_default (ModestDetailsDialog *self);
50
51
52 G_DEFINE_TYPE (ModestHildon2DetailsDialog, 
53                modest_hildon2_details_dialog, 
54                MODEST_TYPE_DETAILS_DIALOG);
55
56 #define MODEST_HILDON2_DETAILS_DIALOG_GET_PRIVATE(o) \
57         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DETAILS_DIALOG, ModestHildon2DetailsDialogPrivate))
58
59
60 typedef struct _ModestHildon2DetailsDialogPrivate ModestHildon2DetailsDialogPrivate;
61
62 struct _ModestHildon2DetailsDialogPrivate
63 {
64         GtkWidget *props_table;
65 };
66
67 static void
68 modest_hildon2_details_dialog_finalize (GObject *object)
69 {
70         G_OBJECT_CLASS (modest_hildon2_details_dialog_parent_class)->finalize (object);
71 }
72
73 static void
74 modest_hildon2_details_dialog_class_init (ModestHildon2DetailsDialogClass *klass)
75 {
76         GObjectClass *object_class = G_OBJECT_CLASS (klass);
77
78         g_type_class_add_private (klass, sizeof (ModestHildon2DetailsDialogPrivate));
79         object_class->finalize = modest_hildon2_details_dialog_finalize;
80
81         MODEST_DETAILS_DIALOG_CLASS (klass)->create_container_func = 
82                 modest_hildon2_details_dialog_create_container_default;
83 }
84
85 static void
86 modest_hildon2_details_dialog_init (ModestHildon2DetailsDialog *self)
87 {
88 }
89
90 GtkWidget*
91 modest_hildon2_details_dialog_new_with_header (GtkWindow *parent, 
92                                                TnyHeader *header,
93                                                gboolean get_size)
94 {
95         ModestDetailsDialog *dialog;
96
97         g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
98         g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
99
100         dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_HILDON2_DETAILS_DIALOG, 
101                                                         "transient-for", parent, 
102                                                         NULL));
103
104         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
105         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_header_func (dialog, header, get_size);
106
107         return GTK_WIDGET (dialog);
108 }
109
110 GtkWidget* 
111 modest_hildon2_details_dialog_new_with_folder  (GtkWindow *parent, 
112                                                 TnyFolder *folder)
113 {
114         ModestDetailsDialog *dialog;
115
116         g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
117         g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
118
119         dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_HILDON2_DETAILS_DIALOG, 
120                                                         "transient-for", parent, 
121                                                         NULL));
122
123         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
124         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_folder_func (dialog, folder);
125
126         return GTK_WIDGET (dialog);
127 }
128
129
130 static void
131 modest_hildon2_details_dialog_create_container_default (ModestDetailsDialog *self)
132 {
133         ModestHildon2DetailsDialogPrivate *priv;
134         GtkWidget *pannable;
135         GtkWidget *align;
136
137         priv = MODEST_HILDON2_DETAILS_DIALOG_GET_PRIVATE (self);
138
139         gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
140
141         priv->props_table = gtk_table_new (0, 2, FALSE);
142         gtk_table_set_col_spacings (GTK_TABLE (priv->props_table), 12);
143         gtk_table_set_row_spacings (GTK_TABLE (priv->props_table), 1);
144
145         align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
146         gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DEFAULT);
147
148         pannable = g_object_new (HILDON_TYPE_PANNABLE_AREA, "initial-hint", TRUE, NULL);
149         gtk_container_add (GTK_CONTAINER (align), priv->props_table);
150         hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), 
151                                                 GTK_WIDGET (align));
152         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), pannable);
153
154         gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
155 }