root/trunk/src/tmut-header-view.c

Revision 74 (checked in by pvanhoof, 8 months ago)

2008-03-26 Philip Van Hoof <pvanhoof@gnome.org>

        • Adapted TMut to the latest Tinymail API changes in trunk.
Line 
1 /* TMut
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with self library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #if HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <glib/gi18n-lib.h>
25
26 #include "tmut-header-view.h"
27 #include "tmut-shell-window.h"
28 #include "tmut-shell-child.h"
29
30 #include <tny-gtk-header-view.h>
31
32 static GObjectClass *parent_class = NULL;
33
34 typedef struct _TMutHeaderViewPriv TMutHeaderViewPriv;
35
36 struct _TMutHeaderViewPriv {
37         TMutShellWindow *shell;
38         TnyHeaderView *header_view;
39         GtkScrolledWindow *sw;
40         GtkWidget *expander, *subject;
41 };
42
43 #define TMUT_HEADER_VIEW_GET_PRIVATE(o) \
44         (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_HEADER_VIEW, TMutHeaderViewPriv))
45
46
47 static void
48 tmut_header_view_set_header (TnyHeaderView *self, TnyHeader *header)
49 {
50         TMutHeaderViewPriv *priv = TMUT_HEADER_VIEW_GET_PRIVATE (self);
51         if (header) {
52                 gchar *str = tny_header_dup_subject (header);
53                 gtk_label_set_text (GTK_LABEL (priv->subject), str);
54                 g_free (str);
55         } else
56                 gtk_label_set_text (GTK_LABEL (priv->subject), "");
57         tny_header_view_set_header (priv->header_view, header);
58         return;
59 }
60
61 static void
62 tmut_header_view_clear (TnyHeaderView *self)
63 {
64         TMutHeaderViewPriv *priv = TMUT_HEADER_VIEW_GET_PRIVATE (self);
65         gtk_label_set_text (GTK_LABEL (priv->subject), "");
66         tny_header_view_clear (priv->header_view);
67         return;
68 }
69
70
71 /**
72  * tmut_header_view_new:
73  * Create a GtkWindow that implements #TnyHeaderView
74  *
75  * Return value: a new #TnyHeaderView instance implemented for Gtk+
76  **/
77 TnyHeaderView*
78 tmut_header_view_new (void)
79 {
80         TMutHeaderView *self = g_object_new (TMUT_TYPE_HEADER_VIEW, NULL);
81
82         return TNY_HEADER_VIEW (self);
83 }
84
85
86 static void
87 tmut_header_view_instance_init (GTypeInstance *instance, gpointer g_class)
88 {
89         TMutHeaderViewPriv *priv = TMUT_HEADER_VIEW_GET_PRIVATE (instance);
90         GtkWidget *label = gtk_label_new (_("<b>Subject:</b>"));
91         GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
92
93         priv->expander = gtk_expander_new ("");
94         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
95         priv->subject = gtk_label_new ("");
96         gtk_box_pack_start (GTK_BOX (hbox), priv->subject, FALSE, TRUE, 0);
97         gtk_expander_set_label_widget (GTK_EXPANDER (priv->expander), hbox);
98
99         gtk_widget_show (priv->expander);
100         gtk_widget_show (hbox);
101         gtk_widget_show (label);
102         gtk_widget_show (priv->subject);
103
104         gtk_box_pack_start (GTK_BOX (instance), GTK_WIDGET (priv->expander), TRUE, TRUE, 0);
105         priv->header_view = tny_gtk_header_view_new ();
106         gtk_container_add (GTK_CONTAINER (priv->expander), GTK_WIDGET (priv->header_view));
107         gtk_widget_show (GTK_WIDGET (priv->header_view));
108
109         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
110         gtk_misc_set_alignment (GTK_MISC (priv->subject), 0, 0.5);
111
112
113         return;
114 }
115
116 static void
117 tmut_header_view_finalize (GObject *object)
118 {
119         (*parent_class->finalize) (object);
120
121         return;
122 }
123
124
125
126 static void
127 tmut_header_view_class_init (TMutHeaderViewClass *class)
128 {
129         GObjectClass *object_class;
130
131         parent_class = g_type_class_peek_parent (class);
132         object_class = (GObjectClass*) class;
133
134         object_class->finalize = tmut_header_view_finalize;
135
136         g_type_class_add_private (object_class, sizeof (TMutHeaderViewPriv));
137
138         return;
139 }
140
141
142 static void
143 tny_header_view_init (gpointer g, gpointer iface_data)
144 {
145         TnyHeaderViewIface *klass = (TnyHeaderViewIface *)g;
146
147         klass->set_header= tmut_header_view_set_header;
148         klass->clear= tmut_header_view_clear;
149
150         return;
151 }
152
153
154 GType
155 tmut_header_view_get_type (void)
156 {
157         static GType type = 0;
158
159         if (G_UNLIKELY(type == 0))
160         {
161                 static const GTypeInfo info =
162                 {
163                   sizeof (TMutHeaderViewClass),
164                   NULL,   /* base_init */
165                   NULL,   /* base_finalize */
166                   (GClassInitFunc) tmut_header_view_class_init,   /* class_init */
167                   NULL,   /* class_finalize */
168                   NULL,   /* class_data */
169                   sizeof (TMutHeaderView),
170                   0,      /* n_preallocs */
171                   tmut_header_view_instance_init,    /* instance_init */
172                   NULL
173                 };
174
175                 static const GInterfaceInfo tny_header_view_info =
176                 {
177                   (GInterfaceInitFunc) tny_header_view_init, /* interface_init */
178                   NULL,         /* interface_finalize */
179                   NULL          /* interface_data */
180                 };
181
182                 type = g_type_register_static (GTK_TYPE_VBOX,
183                         "TMutHeaderView",
184                         &info, 0);
185
186                 g_type_add_interface_static (type, TNY_TYPE_HEADER_VIEW,
187                         &tny_header_view_info);
188         }
189
190         return type;
191 }
Note: See TracBrowser for help on using the browser.