e2774a2da8359fe493ac8743572bc2381d8fafd9
[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 <libgnomevfs/gnome-vfs-mime.h>
31 #include <libgnomeui/gnome-icon-lookup.h>
32 #include <tny-gnome-device.h>
33
34 #include "modest-platform.h"
35 #include "modest-mail-operation-queue.h"
36 #include "modest-runtime.h"
37
38 gboolean
39 modest_platform_init (void)
40 {       
41         return TRUE; /* nothing to do */
42 }
43
44
45 TnyDevice*
46 modest_platform_get_new_device (void)
47 {
48         return TNY_DEVICE (tny_gnome_device_new ());
49 }
50
51
52 gchar*
53 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
54                                           gchar **effective_mime_type)
55 {
56         GString *mime_str = NULL;
57         gchar *icon_name  = NULL;
58         gchar *uri;
59         const static gchar* octet_stream = "application/octet-stream";
60         
61         g_return_val_if_fail (name || mime_type, NULL);
62
63         if (!mime_type || g_ascii_strcasecmp (mime_type, octet_stream)) 
64                 mime_str = g_string_new(gnome_vfs_mime_type_from_name_or_default
65                                         (name, "application/octet-stream"));
66         else {
67                 mime_str = g_string_new (mime_type);
68                 g_string_ascii_down (mime_str);
69         }
70
71         uri = g_strconcat ("file:///", name ? name : "dummy", NULL);
72         icon_name  = gnome_icon_lookup (gtk_icon_theme_get_default(), NULL,
73                                         uri, NULL, NULL, mime_str->str, 0, 0);
74         g_free (uri);
75
76         if (effective_mime_type)
77                 *effective_mime_type = g_string_free (mime_str, FALSE);
78         else
79                 g_string_free (mime_str, TRUE);
80
81         return icon_name;
82 }
83
84 gboolean 
85 modest_platform_activate_uri (const gchar *uri)
86 {
87         modest_runtime_not_implemented (NULL);
88         return FALSE;
89 }
90
91 gboolean 
92 modest_platform_activate_file (const gchar *path)
93 {
94         modest_runtime_not_implemented (NULL);
95         return FALSE;
96 }
97
98 gboolean 
99 modest_platform_show_uri_popup (const gchar *uri)
100 {
101         modest_runtime_not_implemented (NULL);
102         return FALSE;
103 }
104
105 GdkPixbuf*
106 modest_platform_get_icon (const gchar *name)
107 {
108         GError *err = NULL;
109         GdkPixbuf* pixbuf;
110
111         g_return_val_if_fail (name, NULL);
112
113         pixbuf = gdk_pixbuf_new_from_file (name, &err);
114
115         if (!pixbuf) {
116                 g_printerr ("modest: error while loading icon '%s': %s\n",
117                             name, err->message);
118                 g_error_free (err);
119         }
120         
121         return pixbuf;
122 }
123
124
125 const gchar*
126 modest_platform_get_app_name (void)
127 {
128         return ("Modest");
129 }
130
131 gint 
132 modest_platform_run_new_folder_dialog (GtkWindow *parent_window,
133                                        TnyFolderStore *parent_folder,
134                                        gchar *suggested_name,
135                                        gchar **folder_name)
136 {
137         GtkWidget *dialog, *entry;
138         gboolean finished = FALSE;
139         gint result;
140         TnyFolder *new_folder;
141         ModestMailOperation *mail_op;
142
143         /* Ask the user for the folder name */
144         dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
145                                               parent_window,
146                                               GTK_DIALOG_MODAL,
147                                               GTK_STOCK_CANCEL,
148                                               GTK_RESPONSE_REJECT,
149                                               GTK_STOCK_OK,
150                                               GTK_RESPONSE_ACCEPT,
151                                               NULL);
152         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
153                             gtk_label_new (_("Please enter a name for the new folder")),
154                             FALSE, FALSE, 0);
155                 
156         entry = gtk_entry_new_with_max_length (40);
157         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
158                             entry,
159                             TRUE, FALSE, 0);
160         
161         gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
162
163         result = gtk_dialog_run (GTK_DIALOG(dialog));
164         if (result == GTK_RESPONSE_ACCEPT)
165                 *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
166
167         gtk_widget_destroy (dialog);
168
169         return result;
170 }
171
172
173 gint
174 modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
175                                          const gchar *msg)
176 {
177         /* TODO implement confirmation dialog */
178         return GTK_RESPONSE_CANCEL;
179 }
180
181 void
182 modest_platform_run_information_dialog (GtkWindow *parent_window,
183                                         ModestInformationDialogType type)
184 {
185         switch (type) {
186         case MODEST_INFORMATION_CREATE_FOLDER:
187                 break;
188         case MODEST_INFORMATION_DELETE_FOLDER:
189                 break;
190         };
191
192         /* TODO: implement a information dialog */
193 }
194
195 gboolean modest_platform_connect_and_wait (GtkWindow *parent_window)
196 {
197         /* TODO: Do something with network-manager? 
198            Otherwise, maybe it is safe to assume that we would already be online if we could be. */
199         return TRUE;
200 }
201
202 gboolean modest_platform_set_update_interval (guint minutes)
203 {
204         /* TODO. */
205 }
206
207 void
208 modest_platform_run_sort_dialog (GtkWindow *parent_window,
209                                  ModestSortDialogType type)
210 {
211         /* TODO */
212 }