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>
33 #include <osso-mime.h>
34 #include <tny-maemo-device.h>
35 #include <gtk/gtkicontheme.h>
38 modest_platform_init (void)
40 osso_context_t *osso_context =
41 osso_initialize(PACKAGE, PACKAGE_VERSION,
44 g_printerr ("modest: failed to acquire osso context\n");
51 modest_platform_get_new_device (void)
53 return TNY_DEVICE (tny_maemo_device_new ());
58 guess_mime_type_from_name (const gchar* name)
62 const static gchar* octet_stream= "application/octet-stream";
63 const static gchar* mime_map[][2] = {
64 { "pdf", "application/pdf"},
65 { "doc", "application/msword"},
66 { "xls", "application/excel"},
67 { "png", "image/png" },
68 { "gif", "image/gif" },
69 { "jpg", "image/jpeg"},
70 { "jpeg", "image/jpeg"},
71 { "mp3", "audio/mp3" }
77 ext = g_strrstr (name, ".");
81 for (i = 0; i != G_N_ELEMENTS(mime_map); ++i) {
82 if (g_ascii_strcasecmp (mime_map[i][0], ext + 1)) /* +1: ignore '.'*/
83 return mime_map[i][1];
90 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
91 gchar **effective_mime_type)
93 GString *mime_str = NULL;
94 gchar *icon_name = NULL;
95 gchar **icons, **cursor;
98 g_return_val_if_fail (name || mime_type, NULL);
100 if (!mime_type || g_ascii_strcasecmp (mime_type, "application/octet-stream"))
101 mime_str = g_string_new (guess_mime_type_from_name(name));
103 mime_str = g_string_new (mime_type);
104 g_string_ascii_down (mime_str);
107 icons = osso_mime_get_icon_names (mime_str->str, NULL);
108 for (cursor = icons; cursor; ++cursor) {
109 if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default(), *cursor)) {
110 icon_name = g_strdup (*cursor);
116 if (effective_mime_type)
117 *effective_mime_type = g_string_free (mime_str, FALSE);
119 g_string_free (mime_str, TRUE);