140e2f3179c7461179aff562ccbd66b139632446
[modest] / src / hildon2 / modest-maemo-utils.c
1 /* Copyright (c) 2006, 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 #ifndef DBUS_API_SUBJECT_TO_CHANGE
31 #define DBUS_API_SUBJECT_TO_CHANGE
32 #endif /*DBUS_API_SUBJECT_TO_CHANGE*/
33
34 #include <dbus/dbus.h>
35 #include <dbus/dbus-glib-lowlevel.h>
36 #include <glib.h>
37 #include <glib/gstdio.h>
38 #include <errno.h>
39 #include <string.h> /* for strlen */
40 #include <modest-runtime.h>
41 #include <libgnomevfs/gnome-vfs.h>
42 #include <tny-fs-stream.h>
43 #include <tny-camel-account.h>
44 #include <tny-status.h>
45 #include <tny-camel-transport-account.h>
46 #include <tny-camel-imap-store-account.h>
47 #include <tny-camel-pop-store-account.h>
48 #include "modest-hildon-includes.h"
49
50 #include <modest-defs.h>
51 #include "modest-maemo-utils.h"
52 #include "modest-text-utils.h"
53 #include "modest-platform.h"
54 #include "modest-ui-constants.h"
55 #include <hildon/hildon-picker-dialog.h>
56
57 /* Label child of a captioned */
58 #define CAPTIONED_LABEL_CHILD "captioned-label"
59
60 #ifdef MODEST_PLATFORM_MAEMO
61 #define INTERNAL_MMC_USB_MODE  "/system/osso/af/internal-mmc-used-over-usb"
62 #endif
63
64 static osso_context_t *__osso_context = NULL; /* urgh global */
65
66 osso_context_t *
67 modest_maemo_utils_get_osso_context (void)
68 {
69         if (!__osso_context) 
70                 __osso_context = osso_initialize(PACKAGE,PACKAGE_VERSION,
71                                                  FALSE, NULL);
72
73         return __osso_context;
74 }
75
76 static void
77 get_properties_cb (DBusMessage *message)
78 {
79         DBusMessageIter iter;
80         DBusMessageIter dict_iter;
81         DBusMessageIter dict_entry_iter;
82         DBusError err;
83         gchar *bt_name = NULL;
84         int key_type, array_type, msg_type;
85
86         dbus_error_init(&err);
87         if (dbus_set_error_from_message (&err, message)) {
88                 g_warning ("%s: %s", __FUNCTION__, err.message);
89         }
90
91         /* Get msg type */
92         dbus_message_iter_init (message, &iter);
93         msg_type = dbus_message_iter_get_arg_type (&iter);
94         dbus_message_iter_recurse (&iter, &dict_iter);
95
96         while ((array_type = dbus_message_iter_get_arg_type (&dict_iter)) == DBUS_TYPE_DICT_ENTRY) {
97
98                 dbus_message_iter_recurse (&dict_iter, &dict_entry_iter);
99
100                 while ((key_type = dbus_message_iter_get_arg_type (&dict_entry_iter)) == DBUS_TYPE_STRING) {
101                         DBusMessageIter dict_entry_content_iter;
102                         char *key;
103                         char *value;
104                         int dict_entry_type;
105                         int dict_entry_content_type;
106
107                         dbus_message_iter_get_basic (&dict_entry_iter, &key);
108                         dbus_message_iter_next (&dict_entry_iter);
109                         dict_entry_type = dbus_message_iter_get_arg_type (&dict_entry_iter);
110                         dbus_message_iter_recurse (&dict_entry_iter, &dict_entry_content_iter);
111                         dict_entry_content_type = dbus_message_iter_get_arg_type (&dict_entry_content_iter);
112
113                         if (dict_entry_content_type == DBUS_TYPE_STRING) {
114                                 dbus_message_iter_get_basic ( &dict_entry_content_iter, &value );
115
116                                 if (strcmp (key, "Name") == 0 ) {
117                                         g_debug ("-------------Name %s", value);
118                                         bt_name = value;
119                                         break;
120                                 }
121                         }
122                         dbus_message_iter_next (&dict_entry_iter);
123                 }
124
125                 if (key_type != DBUS_TYPE_INVALID)
126                         break;
127
128                 dbus_message_iter_next (&dict_iter);
129         }
130
131         /* Save device name */
132         if (bt_name) {
133                 g_debug ("Setting the device name %s", bt_name);
134                 modest_conf_set_string (modest_runtime_get_conf(),
135                                         MODEST_CONF_DEVICE_NAME, bt_name,
136                                         NULL);
137         }
138 }
139
140 static void
141 get_default_adapter_cb (DBusConnection *conn,
142                         DBusMessage *message)
143 {
144         DBusMessageIter iter;
145         gchar* path = NULL;
146         DBusError error;
147         DBusMessage *msg, *adapterMsg;
148
149         dbus_message_iter_init (message, &iter);
150         dbus_message_iter_get_basic (&iter, &path);
151
152         if (!path)
153                 return;
154
155         adapterMsg = dbus_message_new_method_call ("org.bluez", path,
156                                                    "org.bluez.Adapter",
157                                                    "GetProperties");
158
159         dbus_error_init (&error);
160         msg = dbus_connection_send_with_reply_and_block (conn, adapterMsg, -1, &error);
161         if (msg) {
162                 g_debug ("Getting the properties");
163                 get_properties_cb (msg);
164                 dbus_message_unref (msg);
165         }
166         dbus_message_unref (adapterMsg);
167 }
168
169 void
170 modest_maemo_utils_get_device_name (void)
171 {
172         static DBusConnection *conn = NULL;
173         DBusMessage *request;
174         DBusError error;
175         DBusMessage *msg;
176
177         dbus_error_init (&error);
178         if (!conn) {
179                 conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
180                 if (!conn) {
181                         g_printerr ("modest: cannot get on the dbus: %s: %s\n",
182                                     error.name, error.message);
183                         dbus_error_free (&error);
184                         return;
185                 }
186         }
187
188         /* Get the default adapter */
189         request = dbus_message_new_method_call ("org.bluez", "/" ,
190                                                 "org.bluez.Manager",
191                                                 "DefaultAdapter");
192
193         msg = dbus_connection_send_with_reply_and_block (conn, request, -1, &error);
194         if (msg) {
195                 g_debug ("Getting the default adapter");
196                 get_default_adapter_cb (conn, msg);
197                 dbus_message_unref (msg);
198         }
199
200         dbus_message_unref (request);
201         if (dbus_error_is_set (&error))
202                 dbus_error_free (&error);
203 }
204
205 void
206 modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser)
207 {
208         GtkFileFilter *file_filter;
209         GList *image_mimetypes_list;
210         GList *node;
211         gchar *conf_folder;
212
213         g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
214
215         conf_folder = modest_conf_get_string (modest_runtime_get_conf (),
216                                               MODEST_CONF_LATEST_INSERT_IMAGE_PATH, NULL);
217         if (conf_folder && conf_folder[0] != '\0') {
218                 gtk_file_chooser_set_current_folder_uri (chooser, conf_folder);
219         } else {
220                 gchar *images_folder;
221                 /* Set the default folder to images folder */
222                 images_folder = (gchar *) g_strdup(g_get_user_special_dir (G_USER_DIRECTORY_PICTURES));
223                 if (!images_folder) {
224                         /* fallback */
225                         images_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV),
226                                                           MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL);
227                 }
228                 gtk_file_chooser_set_current_folder (chooser, images_folder);
229                 g_free (images_folder);
230         }
231         g_free (conf_folder);
232
233         /* Set the images mime filter */
234         file_filter = gtk_file_filter_new ();
235 #ifdef MODEST_HAVE_HILDON0_WIDGETS
236         image_mimetypes_list = osso_mime_get_mime_types_for_category (OSSO_MIME_CATEGORY_IMAGES);
237 #else
238         image_mimetypes_list = hildon_mime_get_mime_types_for_category (HILDON_MIME_CATEGORY_IMAGES);
239 #endif
240         for (node = image_mimetypes_list; node != NULL; node = g_list_next (node)) {
241                 gtk_file_filter_add_mime_type (file_filter, node->data);
242         }
243         gtk_file_chooser_set_filter (chooser, file_filter);
244 #ifdef MODEST_HAVE_HILDON0_WIDGETS
245         osso_mime_types_list_free (image_mimetypes_list);
246 #else
247         hildon_mime_types_list_free (image_mimetypes_list);
248 #endif
249
250 }
251
252 void
253 modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, 
254                                       gboolean thumbable)
255 {
256         g_return_if_fail (GTK_IS_SCROLLED_WINDOW(win));
257 #ifdef MODEST_HAVE_HILDON1_WIDGETS              
258         hildon_helper_set_thumb_scrollbar (win, thumbable);
259 #endif /* MODEST_HAVE_HILDON1_WIDGETS */
260 }
261
262 GtkWidget *
263 modest_maemo_utils_get_manager_menubar_as_menu (GtkUIManager *manager,
264                                                 const gchar *item_name)
265 {
266         GtkWidget *new_menu;
267         GtkWidget *menubar;
268         GList *children, *iter;
269
270         menubar = gtk_ui_manager_get_widget (manager, item_name);
271         new_menu = gtk_menu_new ();
272
273         children = gtk_container_get_children (GTK_CONTAINER (menubar));
274         for (iter = children; iter != NULL; iter = g_list_next (iter)) {
275                 GtkWidget *menu;
276
277                 menu = GTK_WIDGET (iter->data);
278                 gtk_widget_reparent (menu, new_menu);
279         }
280         
281         g_list_free (children);
282
283         return new_menu;
284 }
285
286 /**
287  * modest_maemo_utils_create_captioned:
288  * @title_size_group: a #GtkSizeGroup
289  * @value_size_group: a #GtkSizeGroup
290  * @title: a string
291  * @control: a #GtkWidget
292  *
293  * this creates a widget (a #GtkHBox) with a control, and a label
294  * (@string) captioning it. It also uses the proper size groups for title
295  * and control.
296  *
297  * Returns: a widget containing the control and a proper label.
298  */
299 GtkWidget *
300 modest_maemo_utils_create_captioned    (GtkSizeGroup *title_size_group,
301                                         GtkSizeGroup *value_size_group,
302                                         const gchar *title,
303                                         gboolean use_markup,
304                                         GtkWidget *control)
305 {
306         return modest_maemo_utils_create_captioned_with_size_type (title_size_group,
307                                                                    value_size_group,
308                                                                    title,
309                                                                    use_markup,
310                                                                    control,
311                                                                    0);
312 }
313
314 /**
315  * modest_maemo_utils_create_captioned_with_size_type:
316  * @title_size_group: a #GtkSizeGroup
317  * @value_size_group: a #GtkSizeGroup
318  * @title: a string
319  * @control: a #GtkWidget
320  * @size_type: a #HildonSizeType
321  *
322  * this creates a widget (a #GtkHBox) with a control, and a label
323  * (@string) captioning it. It also uses the proper size groups for title
324  * and control.
325  *
326  * Returns: a widget containing the control and a proper label.
327  */
328 GtkWidget *
329 modest_maemo_utils_create_captioned_with_size_type    (GtkSizeGroup *title_size_group,
330                                                        GtkSizeGroup *value_size_group,
331                                                        const gchar *title,
332                                                        gboolean use_markup,
333                                                        GtkWidget *control,
334                                                        HildonSizeType size_type)
335 {
336         GtkWidget *label;
337         GtkWidget *align;
338         GtkWidget *box;
339   
340         if (use_markup) {
341                 label = gtk_label_new (NULL);
342                 gtk_label_set_markup (GTK_LABEL (label), title);
343         } else {
344                 label = gtk_label_new (title);
345         }
346         align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
347         gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
348
349         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
350         hildon_gtk_widget_set_theme_size (label, HILDON_SIZE_FINGER_HEIGHT);
351         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
352         gtk_widget_show (label);
353         gtk_widget_show (align);
354         box = gtk_hbox_new (FALSE, 0);
355         gtk_container_add (GTK_CONTAINER (align), label);
356         gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0);
357         gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0);
358         if (title_size_group)
359                 gtk_size_group_add_widget (title_size_group, label);
360         if (value_size_group)
361                 gtk_size_group_add_widget (value_size_group, control);
362
363         hildon_gtk_widget_set_theme_size (control, size_type);
364
365         g_object_set_data (G_OBJECT (box), CAPTIONED_LABEL_CHILD, label);
366
367         return box;
368 }
369
370 /**
371  * modest_maemo_utils_captioned_set_label:
372  * @captioned: a #GtkWidget built as captioned
373  * @new_label: a string
374  * @use_markup: a #gboolean
375  *
376  * set a new label for the captioned
377  */
378 void
379 modest_maemo_utils_captioned_set_label (GtkWidget *captioned,
380                                         const gchar *new_label,
381                                         gboolean use_markup)
382 {
383         GtkWidget *label;
384
385         g_return_if_fail (GTK_IS_WIDGET (captioned));
386
387         label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD);
388         g_return_if_fail (GTK_IS_LABEL (label));
389
390         if (use_markup) {
391                 gtk_label_set_markup (GTK_LABEL (label), new_label);
392         } else {
393                 gtk_label_set_text (GTK_LABEL (label), new_label);
394         }
395 }
396
397 /**
398  * modest_maemo_utils_captioned_get_label_widget:
399  * @captioned: a #GtkWidget built as captioned
400  *
401  * obtains the label widget for the captioned
402  *
403  * Returns: a #GtkLabel
404  */
405 GtkWidget *
406 modest_maemo_utils_captioned_get_label_widget (GtkWidget *captioned)
407 {
408         GtkWidget *label;
409
410         g_return_val_if_fail (GTK_IS_WIDGET (captioned), NULL);
411
412         label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD);
413         g_return_val_if_fail (GTK_IS_LABEL (label), NULL);
414
415         return label;
416
417 }
418
419 /**
420  * modest_maemo_utils_set_hbutton_layout:
421  * @title_sizegroup: a #GtkSizeGroup, or %NULL
422  * @value_sizegroup: a #GtkSizeGroup, or %NULL
423  * @title: a string
424  * @button: a #HildonButton
425  *
426  * Configures the alignment and layout of @button. If @title_sizegroup is provided,
427  * the title will be aligned to the left using it. If @value_sizegroup is provided,
428  * the value will be aligned to the left using it. It also sets the title
429  * of the button.
430  *
431  * The alignment is left for the title and for the value.
432  */
433 void
434 modest_maemo_utils_set_hbutton_layout (GtkSizeGroup *title_sizegroup, 
435                                        GtkSizeGroup *value_sizegroup,
436                                        const gchar *title, 
437                                        GtkWidget *button)
438 {
439         hildon_button_set_title (HILDON_BUTTON (button), title);
440         if (title_sizegroup)
441                 hildon_button_add_title_size_group (HILDON_BUTTON (button), title_sizegroup);
442         if (value_sizegroup)
443                 hildon_button_add_value_size_group (HILDON_BUTTON (button), value_sizegroup);
444         hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
445         hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5);
446         hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
447 }
448
449 void
450 modest_maemo_utils_set_vbutton_layout (GtkSizeGroup *sizegroup, 
451                                        const gchar *title, 
452                                        GtkWidget *button)
453 {
454         hildon_button_set_title (HILDON_BUTTON (button), title);
455         if (sizegroup) {
456                 hildon_button_add_title_size_group (HILDON_BUTTON (button), sizegroup);
457                 hildon_button_add_value_size_group (HILDON_BUTTON (button), sizegroup);
458         }
459         hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
460         hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5);
461         hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
462 }
463
464 GtkWidget *
465 modest_maemo_utils_create_group_box (const gchar *label_text, GtkWidget *contents)
466 {
467         GtkWidget *label;
468         GtkWidget *box;
469
470         label = gtk_label_new (label_text);
471         gtk_widget_show (label);
472
473         box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
474         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
475         gtk_box_pack_start (GTK_BOX (box), contents, TRUE, TRUE, 0);
476         gtk_widget_show (box);
477
478         return box;
479 }
480
481 static gboolean match_all (TnyList *list, GObject *item, gpointer match_data)
482 {
483         return TRUE;
484 }
485
486 gboolean
487 modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list, gboolean include_msgs)
488 {
489         GtkTreeModel *model;
490         TnyIterator *iterator;
491         GtkWidget *selector;
492         GtkCellRenderer *renderer;
493         GtkWidget *dialog;
494         gint response;
495         gboolean result = TRUE;
496         gint attachments_added = 0;
497
498         model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT));
499         for (iterator = tny_list_create_iterator (att_list);
500              !tny_iterator_is_done (iterator);
501              tny_iterator_next (iterator)) {
502                 GtkTreeIter iter;
503                 TnyMimePart *part;
504                 gchar *filename = NULL;
505
506                 part = (TnyMimePart *) tny_iterator_get_current (iterator);
507
508                 /* Ignore purged attachments and messages if ignore is
509                    set to TRUE */
510                 if (!(tny_mime_part_is_purged (part) ||
511                       (TNY_IS_MSG (part) && !include_msgs))) {
512
513                         if (TNY_IS_MSG (part)) {
514                                 TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
515                                 filename = tny_header_dup_subject (header);
516                                 g_object_unref (header);
517                         } else {
518                                 filename = g_strdup (tny_mime_part_get_filename (part));
519                         }
520                         if ((filename == NULL) || (filename[0] == '\0')) {
521                                 g_free (filename);
522                                 filename = g_strdup (_("mail_va_no_subject"));
523                         }
524                         gtk_list_store_append (GTK_LIST_STORE (model), &iter);
525                         gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filename, 1, part, -1);
526                         attachments_added ++;
527                         g_free (filename);
528                 }
529                 g_object_unref (part);
530         }
531         g_object_unref (iterator);
532
533         selector = GTK_WIDGET (hildon_touch_selector_new ());
534         renderer = gtk_cell_renderer_text_new ();
535         hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), model, renderer,
536                                              "text", 0, NULL);
537         hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector), 
538                                                          HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
539
540         dialog = hildon_picker_dialog_new (window);
541         gtk_window_set_title (GTK_WINDOW (dialog), (attachments_added > 1)?
542                               _("mcen_ti_select_attachments_title"):_("mcen_ti_select_attachment_title"));
543         hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
544         hildon_picker_dialog_set_done_label (HILDON_PICKER_DIALOG (dialog), _HL("wdgt_bd_done"));
545
546         response = gtk_dialog_run (GTK_DIALOG (dialog));
547
548         if (response == GTK_RESPONSE_OK) {
549                 GList *selected_rows, *node;
550
551                 tny_list_remove_matches (att_list, match_all, NULL);
552                 selected_rows = hildon_touch_selector_get_selected_rows (HILDON_TOUCH_SELECTOR (selector), 0);
553                 for (node = selected_rows; node != NULL; node = g_list_next (node)) {
554                         GtkTreePath *path;
555                         GObject *selected;
556                         GtkTreeIter iter;
557
558                         path = (GtkTreePath *) node->data;
559                         gtk_tree_model_get_iter (model, &iter, path);
560                         gtk_tree_model_get (model, &iter, 1, &selected, -1);
561                         tny_list_append (att_list, selected);
562                 }
563                 if (tny_list_get_length (att_list) == 0)
564                         result = FALSE;
565
566                 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
567                 g_list_free (selected_rows);
568         } else {
569                 result = FALSE;
570         }
571
572         gtk_widget_destroy (dialog);
573
574         g_object_unref (model);
575
576         return result;
577 }
578
579 #ifdef MODEST_PLATFORM_MAEMO
580 gboolean
581 modest_maemo_utils_in_usb_mode ()
582 {
583         return modest_conf_get_bool (modest_runtime_get_conf (), INTERNAL_MMC_USB_MODE, NULL);
584 }
585 #endif
586
587 void
588 modest_maemo_utils_scroll_pannable (HildonPannableArea *pannable,
589                                     gint horizontal,
590                                     gint vertical)
591 {
592         gint h_pos = -1;
593         gint v_pos = -1;
594
595         g_assert (pannable);
596         /* at atleast one of values have to be valid */
597         g_return_if_fail (h_pos == -1 && v_pos == -1);
598
599         if (horizontal != 0) {
600                 GtkAdjustment *h_adj;
601
602                 h_adj = hildon_pannable_area_get_hadjustment (pannable);
603                 g_return_if_fail (h_adj);
604
605                 h_pos = h_adj->value + h_adj->step_increment * horizontal;
606                 if (horizontal > 0) {
607                         h_pos += h_adj->page_size;
608                 }
609         }
610
611         if (vertical != 0) {
612                 GtkAdjustment *v_adj;
613
614                 v_adj = hildon_pannable_area_get_vadjustment (pannable);
615                 g_return_if_fail (v_adj);
616
617                 v_pos = v_adj->value + v_adj->step_increment * vertical;
618                 if (vertical > 0) {
619                         v_pos += v_adj->page_size;
620                 }
621         }
622
623         hildon_pannable_area_scroll_to (pannable, h_pos, v_pos);
624 }