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.
31 #include <modest-platform.h>
34 #ifdef MODEST_HILDON_VERSION_0
35 #include <osso-mime.h>
37 #include <hildon-mime.h>
38 #endif /*MODEST_HILDON_VERSION_0*/
40 #include <tny-maemo-device.h>
41 #include <gtk/gtkicontheme.h>
44 modest_platform_init (void)
46 osso_context_t *osso_context =
47 osso_initialize(PACKAGE, PACKAGE_VERSION,
50 g_printerr ("modest: failed to acquire osso context\n");
57 modest_platform_get_new_device (void)
59 return TNY_DEVICE (tny_maemo_device_new ());
64 guess_mime_type_from_name (const gchar* name)
68 const static gchar* octet_stream= "application/octet-stream";
69 const static gchar* mime_map[][2] = {
70 { "pdf", "application/pdf"},
71 { "doc", "application/msword"},
72 { "xls", "application/excel"},
73 { "png", "image/png" },
74 { "gif", "image/gif" },
75 { "jpg", "image/jpeg"},
76 { "jpeg", "image/jpeg"},
77 { "mp3", "audio/mp3" }
83 ext = g_strrstr (name, ".");
87 for (i = 0; i != G_N_ELEMENTS(mime_map); ++i) {
88 if (g_ascii_strcasecmp (mime_map[i][0], ext + 1)) /* +1: ignore '.'*/
89 return mime_map[i][1];
96 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
97 gchar **effective_mime_type)
99 GString *mime_str = NULL;
100 gchar *icon_name = NULL;
101 gchar **icons, **cursor;
104 g_return_val_if_fail (name || mime_type, NULL);
106 if (!mime_type || g_ascii_strcasecmp (mime_type, "application/octet-stream"))
107 mime_str = g_string_new (guess_mime_type_from_name(name));
109 mime_str = g_string_new (mime_type);
110 g_string_ascii_down (mime_str);
112 #ifdef MODEST_HILDON_VERSION_0
113 icons = osso_mime_get_icon_names (mime_str->str, NULL);
115 icons = hildon_mime_get_icon_names (mime_str->str, NULL);
116 #endif /*MODEST_HILDON_VERSION_0*/
117 for (cursor = icons; cursor; ++cursor) {
118 if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default(), *cursor)) {
119 icon_name = g_strdup (*cursor);
125 if (effective_mime_type)
126 *effective_mime_type = g_string_free (mime_str, FALSE);
128 g_string_free (mime_str, TRUE);
135 modest_platform_get_icon (const gchar *name)
139 GtkIconTheme *current_theme;
141 g_return_val_if_fail (name, NULL);
143 current_theme = gtk_icon_theme_get_default ();
144 pixbuf = gtk_icon_theme_load_icon (current_theme, name, 26,
145 GTK_ICON_LOOKUP_NO_SVG,
148 g_printerr ("modest: error while loading icon '%s': %s\n",