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