This is a manual merge of branch drop split view intro trunk.
[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
48 static void modest_hildon2_details_dialog_create_container_default (ModestDetailsDialog *self);
49
50
51 G_DEFINE_TYPE (ModestHildon2DetailsDialog, 
52                modest_hildon2_details_dialog, 
53                MODEST_TYPE_DETAILS_DIALOG);
54
55 #define MODEST_HILDON2_DETAILS_DIALOG_GET_PRIVATE(o) \
56         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DETAILS_DIALOG, ModestHildon2DetailsDialogPrivate))
57
58
59 typedef struct _ModestHildon2DetailsDialogPrivate ModestHildon2DetailsDialogPrivate;
60
61 struct _ModestHildon2DetailsDialogPrivate
62 {
63         GtkWidget *props_table;
64 };
65
66 static void
67 modest_hildon2_details_dialog_finalize (GObject *object)
68 {
69         G_OBJECT_CLASS (modest_hildon2_details_dialog_parent_class)->finalize (object);
70 }
71
72 static void
73 modest_hildon2_details_dialog_class_init (ModestHildon2DetailsDialogClass *klass)
74 {
75         GObjectClass *object_class = G_OBJECT_CLASS (klass);
76
77         g_type_class_add_private (klass, sizeof (ModestHildon2DetailsDialogPrivate));
78         object_class->finalize = modest_hildon2_details_dialog_finalize;
79
80         MODEST_DETAILS_DIALOG_CLASS (klass)->create_container_func = 
81                 modest_hildon2_details_dialog_create_container_default;
82 }
83
84 static void
85 modest_hildon2_details_dialog_init (ModestHildon2DetailsDialog *self)
86 {
87 }
88
89 GtkWidget*
90 modest_hildon2_details_dialog_new_with_header (GtkWindow *parent, 
91                                                TnyHeader *header)
92 {
93         ModestDetailsDialog *dialog;
94
95         g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
96         g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
97
98         dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_HILDON2_DETAILS_DIALOG, 
99                                                         "transient-for", parent, 
100                                                         NULL));
101
102         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
103         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_header_func (dialog, header);
104
105         return GTK_WIDGET (dialog);
106 }
107
108 GtkWidget* 
109 modest_hildon2_details_dialog_new_with_folder  (GtkWindow *parent, 
110                                                 TnyFolder *folder)
111 {
112         ModestDetailsDialog *dialog;
113
114         g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
115         g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
116
117         dialog = (ModestDetailsDialog *) (g_object_new (MODEST_TYPE_HILDON2_DETAILS_DIALOG, 
118                                                         "transient-for", parent, 
119                                                         NULL));
120
121         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->create_container_func (dialog);
122         MODEST_DETAILS_DIALOG_GET_CLASS (dialog)->set_folder_func (dialog, folder);
123
124         return GTK_WIDGET (dialog);
125 }
126
127
128 static void
129 modest_hildon2_details_dialog_create_container_default (ModestDetailsDialog *self)
130 {
131         ModestHildon2DetailsDialogPrivate *priv;
132         GtkWidget *pannable;
133
134         priv = MODEST_HILDON2_DETAILS_DIALOG_GET_PRIVATE (self);
135
136         gtk_window_set_default_size (GTK_WINDOW (self), 400, 220);
137
138         priv->props_table = gtk_table_new (0, 2, FALSE);
139         gtk_table_set_col_spacings (GTK_TABLE (priv->props_table), 12);
140         gtk_table_set_row_spacings (GTK_TABLE (priv->props_table), 1);
141
142         pannable = g_object_new (HILDON_TYPE_PANNABLE_AREA, "initial-hint", TRUE, NULL);
143         hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), 
144                                                 GTK_WIDGET (priv->props_table));
145         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), pannable);
146
147         gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
148 }