1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #include <glib/gi18n.h>
31 #include "modest-toolbar.h"
33 /* 'private'/'protected' functions */
34 static void modest_toolbar_class_init (ModestToolbarClass *klass);
35 static void modest_toolbar_init (ModestToolbar *obj);
36 static void modest_toolbar_finalize (GObject *obj);
38 static void on_toolbutton_clicked (GtkToolButton *button, ModestToolbar *self);
42 BUTTON_CLICKED_SIGNAL,
46 typedef struct _ModestToolbarPrivate ModestToolbarPrivate;
47 struct _ModestToolbarPrivate {
48 GtkTooltips *tooltips;
51 #define MODEST_TOOLBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
52 MODEST_TYPE_TOOLBAR, \
53 ModestToolbarPrivate))
55 static GtkToolbarClass *parent_class = NULL;
57 static guint signals[LAST_SIGNAL] = {0};
60 modest_toolbar_get_type (void)
62 static GType my_type = 0;
64 static const GTypeInfo my_info = {
65 sizeof(ModestToolbarClass),
67 NULL, /* base finalize */
68 (GClassInitFunc) modest_toolbar_class_init,
69 NULL, /* class finalize */
70 NULL, /* class data */
71 sizeof(ModestToolbar),
73 (GInstanceInitFunc) modest_toolbar_init,
76 my_type = g_type_register_static (GTK_TYPE_TOOLBAR,
84 modest_toolbar_class_init (ModestToolbarClass *klass)
86 GObjectClass *gobject_class;
87 gobject_class = (GObjectClass*) klass;
89 parent_class = g_type_class_peek_parent (klass);
90 gobject_class->finalize = modest_toolbar_finalize;
92 g_type_class_add_private (gobject_class, sizeof(ModestToolbarPrivate));
94 signals[BUTTON_CLICKED_SIGNAL] =
95 g_signal_new ("button_clicked",
96 G_TYPE_FROM_CLASS (gobject_class),
98 G_STRUCT_OFFSET (ModestToolbarClass, button_clicked),
100 g_cclosure_marshal_VOID__INT,
101 G_TYPE_NONE, 1, G_TYPE_INT);
105 modest_toolbar_init (ModestToolbar *obj)
111 modest_toolbar_finalize (GObject *obj)
113 G_OBJECT_CLASS(parent_class)->finalize (obj);
117 /* don't free icon_name/label/tooltip, they're static */
119 data_for_button_id (ModestToolbarButton button_id,
120 gchar **icon_name, gchar **label, gchar **tooltip)
123 case MODEST_TOOLBAR_BUTTON_MAIL_SEND:
125 *tooltip = _("Send the current email message");
126 *icon_name = MODEST_TOOLBAR_ICON_MAIL_SEND;
128 case MODEST_TOOLBAR_BUTTON_NEW_MAIL:
129 *label = _("New mail");
130 *tooltip = _("Compose a new email message");
131 *icon_name = MODEST_TOOLBAR_ICON_NEW_MAIL;
133 case MODEST_TOOLBAR_BUTTON_SEND_RECEIVE:
134 *label = _("Send/Receive");
135 *tooltip = _("Send and receive messages");
136 *icon_name = MODEST_TOOLBAR_ICON_SEND_RECEIVE;
138 case MODEST_TOOLBAR_BUTTON_REPLY:
140 *tooltip = _("Reply to the selected email message");
141 *icon_name = MODEST_TOOLBAR_ICON_REPLY;
143 case MODEST_TOOLBAR_BUTTON_REPLY_ALL:
144 *label = _("Reply all");
145 *tooltip = _("Reply to all people the selected email was sent to");
146 *icon_name = MODEST_TOOLBAR_ICON_REPLY_ALL;
148 case MODEST_TOOLBAR_BUTTON_FORWARD:
149 *label = _("Forward");
150 *tooltip = _("Forward the selected email");
151 *icon_name = MODEST_TOOLBAR_ICON_FORWARD;
153 case MODEST_TOOLBAR_BUTTON_DELETE:
154 *label = _("Delete");
155 *tooltip = _("Delete the selected email message(s)");
156 *icon_name = MODEST_TOOLBAR_ICON_DELETE;
158 case MODEST_TOOLBAR_BUTTON_NEXT:
160 *tooltip = _("Move to the next message");
161 *icon_name = MODEST_TOOLBAR_ICON_NEXT;
163 case MODEST_TOOLBAR_BUTTON_PREV:
164 *label = _("Previous");
165 *tooltip = _("Move to the previous message");
166 *icon_name = MODEST_TOOLBAR_ICON_PREV;
168 case MODEST_TOOLBAR_BUTTON_STOP:
170 *tooltip = _("Stop whatever");
171 *icon_name = MODEST_TOOLBAR_ICON_STOP;
174 g_printerr ("modest: not a valid button id: %d\n",
183 modest_toolbar_set_buttons (ModestToolbar *self, const GSList *buttons)
185 const GSList *cursor;
186 GtkTooltips *tooltips;
188 g_return_val_if_fail (self, FALSE);
190 tooltips = gtk_tooltips_new ();
191 gtk_tooltips_enable (tooltips);
192 gtk_toolbar_set_tooltips (GTK_TOOLBAR(self), TRUE);
196 ModestToolbarButton button_id =
197 (ModestToolbarButton) GPOINTER_TO_INT(cursor->data);
199 if (button_id == MODEST_TOOLBAR_SEPARATOR)
200 gtk_toolbar_insert (GTK_TOOLBAR(self),
201 gtk_separator_tool_item_new(), -1);
203 gchar *icon_name, *label, *tooltip; /* don't free these */
204 if (!data_for_button_id (button_id, &icon_name, &label, &tooltip))
205 g_printerr ("modest: error getting data for toolbar button %d\n",
208 GtkWidget *icon = NULL;
209 GtkToolItem *button = NULL;
210 GdkPixbuf *pixbuf = NULL;
212 pixbuf = modest_icon_factory_get_icon_at_size (icon_name, 24, 24);
214 icon = gtk_image_new_from_pixbuf ((GdkPixbuf*)pixbuf);
215 button = gtk_tool_button_new (icon, label);
216 g_object_set_data (G_OBJECT(button), "button_id",
217 GINT_TO_POINTER(button_id));
218 g_signal_connect (G_OBJECT(button), "clicked",
219 G_CALLBACK(on_toolbutton_clicked), self);
221 gtk_tooltips_set_tip (tooltips, GTK_WIDGET(button),tooltip, NULL);
222 gtk_widget_show_all (GTK_WIDGET(button));
223 gtk_toolbar_insert (GTK_TOOLBAR(self), button, -1);
226 cursor = cursor->next;
229 return TRUE; /* FIXME */
234 modest_toolbar_new (const GSList *buttons)
238 obj = g_object_new(MODEST_TYPE_TOOLBAR, NULL);
239 modest_toolbar_set_buttons (MODEST_TOOLBAR(obj), buttons);
241 return MODEST_TOOLBAR(obj);
245 on_toolbutton_clicked (GtkToolButton *button, ModestToolbar *self)
247 gint button_id = GPOINTER_TO_INT(
248 g_object_get_data(G_OBJECT(button), "button_id"));
250 g_signal_emit (G_OBJECT(self), signals[BUTTON_CLICKED_SIGNAL],