* src/maemo/modest-msg-edit-window.c:
[modest] / src / gnome / modest-platform.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 #include <modest-platform.h>
31 #include <libgnomevfs/gnome-vfs-mime.h>
32 #include <libgnomeui/gnome-icon-lookup.h>
33 #include <tny-gnome-device.h>
34
35 gboolean
36 modest_platform_init (void)
37 {       
38         return TRUE; /* nothing to do */
39 }
40
41
42 TnyDevice*
43 modest_platform_get_new_device (void)
44 {
45         return TNY_DEVICE (tny_gnome_device_new ());
46 }
47
48
49 gchar*
50 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
51                                           gchar **effective_mime_type)
52 {
53         GString *mime_str = NULL;
54         gchar *icon_name  = NULL;
55         gchar *uri;
56         const static gchar* octet_stream = "application/octet-stream";
57         
58         g_return_val_if_fail (name || mime_type, NULL);
59
60         if (!mime_type || g_ascii_strcasecmp (mime_type, octet_stream)) 
61                 mime_str = g_string_new(gnome_vfs_mime_type_from_name_or_default
62                                         (name, "application/octet-stream"));
63         else {
64                 mime_str = g_string_new (mime_type);
65                 g_string_ascii_down (mime_str);
66         }
67
68         uri = g_strconcat ("file:///", name ? name : "dummy", NULL);
69         icon_name  = gnome_icon_lookup (gtk_icon_theme_get_default(), NULL,
70                                         uri, NULL, NULL, mime_str->str, 0, 0);
71         g_free (uri);
72
73         if (effective_mime_type)
74                 *effective_mime_type = g_string_free (mime_str, FALSE);
75         else
76                 g_string_free (mime_str, TRUE);
77
78         return icon_name;
79 }
80
81 gboolean 
82 modest_platform_activate_uri (const gchar *uri)
83 {
84         g_message ("not implemented %s", __FUNCTION__);
85 }
86
87 gboolean 
88 modest_platform_show_uri_popup (const gchar *uri)
89 {
90         g_message ("not implemented %s", __FUNCTION__);
91 }
92
93 GdkPixbuf*
94 modest_platform_get_icon (const gchar *name)
95 {
96         GError *err = NULL;
97         GdkPixbuf* pixbuf;
98
99         g_return_val_if_fail (name, NULL);
100
101         pixbuf = gdk_pixbuf_new_from_file (name, &err);
102
103         if (!pixbuf) {
104                 g_printerr ("modest: error while loading icon '%s': %s\n",
105                             name, err->message);
106                 g_error_free (err);
107         }
108         
109         return pixbuf;
110 }