These changes are for reenabling build of gnome port.
[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 #include "gnome/modest-gnome-global-settings-dialog.h"
38
39 gboolean
40 modest_platform_init (int argc, char *argv[])
41 {       
42         return TRUE; /* nothing to do */
43 }
44
45
46 gboolean modest_platform_uninit (void)
47 {
48         return TRUE; /*nothing to do */
49 }
50
51
52 TnyDevice*
53 modest_platform_get_new_device (void)
54 {
55         return TNY_DEVICE (tny_gnome_device_new ());
56 }
57
58
59 gchar*
60 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
61                                           gchar **effective_mime_type)
62 {
63         GString *mime_str = NULL;
64         gchar *icon_name  = NULL;
65         gchar *uri;
66         const static gchar* octet_stream = "application/octet-stream";
67         
68         g_return_val_if_fail (name || mime_type, NULL);
69
70         if (!mime_type || g_ascii_strcasecmp (mime_type, octet_stream)) 
71                 mime_str = g_string_new(gnome_vfs_mime_type_from_name_or_default
72                                         (name, "application/octet-stream"));
73         else {
74                 mime_str = g_string_new (mime_type);
75                 g_string_ascii_down (mime_str);
76         }
77
78         uri = g_strconcat ("file:///", name ? name : "dummy", NULL);
79         icon_name  = gnome_icon_lookup (gtk_icon_theme_get_default(), NULL,
80                                         uri, NULL, NULL, mime_str->str, 0, 0);
81         g_free (uri);
82
83         if (effective_mime_type)
84                 *effective_mime_type = g_string_free (mime_str, FALSE);
85         else
86                 g_string_free (mime_str, TRUE);
87
88         return icon_name;
89 }
90
91 gboolean 
92 modest_platform_activate_uri (const gchar *uri)
93 {
94         g_message ("NOT IMPLEMENTED");;
95         return FALSE;
96 }
97
98 gboolean 
99 modest_platform_activate_file (const gchar *path, const gchar *mime_type)
100 {
101         g_message ("NOT IMPLEMENTED");;
102         return FALSE;
103 }
104
105 gboolean 
106 modest_platform_show_uri_popup (const gchar *uri)
107 {
108         g_message ("NOT IMPLEMENTED");;
109         return FALSE;
110 }
111
112 GdkPixbuf*
113 modest_platform_get_icon (const gchar *name)
114 {
115         GError *err = NULL;
116         GdkPixbuf* pixbuf;
117
118         g_return_val_if_fail (name, NULL);
119
120         pixbuf = gdk_pixbuf_new_from_file (name, &err);
121
122         if (!pixbuf) {
123                 g_printerr ("modest: error while loading icon '%s': %s\n",
124                             name, err->message);
125                 g_error_free (err);
126         }
127         
128         return pixbuf;
129 }
130
131
132 const gchar*
133 modest_platform_get_app_name (void)
134 {
135         return ("Modest");
136 }
137
138 gint 
139 modest_platform_run_new_folder_dialog (GtkWindow *parent_window,
140                                        TnyFolderStore *parent_folder,
141                                        gchar *suggested_name,
142                                        gchar **folder_name)
143 {
144         GtkWidget *dialog, *entry;
145         gint result;
146
147         /* Ask the user for the folder name */
148         dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
149                                               parent_window,
150                                               GTK_DIALOG_MODAL,
151                                               GTK_STOCK_CANCEL,
152                                               GTK_RESPONSE_REJECT,
153                                               GTK_STOCK_OK,
154                                               GTK_RESPONSE_ACCEPT,
155                                               NULL);
156         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
157                             gtk_label_new (_("Please enter a name for the new folder")),
158                             FALSE, FALSE, 0);
159                 
160         entry = gtk_entry_new_with_max_length (40);
161         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
162                             entry,
163                             TRUE, FALSE, 0);
164         
165         gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
166
167         result = gtk_dialog_run (GTK_DIALOG(dialog));
168         if (result == GTK_RESPONSE_ACCEPT)
169                 *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
170
171         gtk_widget_destroy (dialog);
172
173         return result;
174 }
175
176
177 gint
178 modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
179                                          const gchar *msg)
180 {
181         /* TODO implement confirmation dialog */
182         return GTK_RESPONSE_CANCEL;
183 }
184
185 void
186 modest_platform_run_information_dialog (GtkWindow *parent_window,
187                                         const gchar *message)
188 {
189         /* TODO: implement a information dialog */
190 }
191
192 gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account)
193 {
194         /* TODO: Do something with network-manager? 
195            Otherwise, maybe it is safe to assume that we would already be online if we could be. */
196         return TRUE;
197 }
198
199 gboolean modest_platform_connect_and_wait_if_network_account (GtkWindow *parent_window, TnyAccount *account)
200 {
201         /* TODO: Do something with network-manager? 
202            Otherwise, maybe it is safe to assume that we would already be online if we could be. */
203         return TRUE;
204 }
205
206 gboolean modest_platform_set_update_interval (guint minutes)
207 {
208         /* TODO. */
209         return FALSE;
210 }
211
212 void
213 modest_platform_run_sort_dialog (GtkWindow *parent_window,
214                                  ModestSortDialogType type)
215 {
216         /* TODO */
217 }
218
219 GtkWidget *
220 modest_platform_get_global_settings_dialog ()
221 {
222         return modest_gnome_global_settings_dialog_new ();
223 }
224
225
226 void 
227 modest_platform_on_new_headers_received (TnyList *header_list)
228 {
229         /* TODO: implement this */
230         g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n");
231 }
232
233
234
235 void
236 modest_platform_show_help (GtkWindow *parent_window, const gchar *help_id)
237 {
238         return; /* TODO */
239 }
240
241 void 
242 modest_platform_information_banner (GtkWidget *widget,
243                                     const gchar *icon_name,
244                                     const gchar *text)
245 {
246         g_message ("NOT IMPLEMENTED");;
247 }
248
249 GtkWidget *
250 modest_platform_animation_banner (GtkWidget *widget,
251                                   const gchar *icon_name,
252                                   const gchar *text)
253 {
254         g_message ("NOT IMPLEMENTED");
255         return NULL;
256 }
257
258
259 void
260 modest_platform_show_search_messages (GtkWindow *parent_window)
261 {
262         g_message ("NOT IMPLEMENTED");;
263 }
264
265 GtkWidget *
266 modest_platform_create_folder_view (TnyFolderStoreQuery *query)
267 {
268         GtkWidget *widget = modest_folder_view_new (query);
269
270         /* Show all accounts by default */
271         modest_folder_view_set_style (MODEST_FOLDER_VIEW (widget),
272                                       MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
273
274         return widget;
275 }
276
277 gboolean
278 modest_platform_run_alert_dialog (const gchar* prompt, 
279                                   gboolean is_question)
280 {
281         /* TODO */
282         return TRUE;
283 }
284
285 void 
286 modest_platform_connect_and_perform (GtkWindow *parent_window, 
287                                      TnyAccount *account, 
288                                      ModestConnectedPerformer callback, 
289                                      gpointer user_data)
290 {
291         if (callback)
292                 callback (FALSE, NULL, parent_window, account, user_data);
293 }
294
295 void 
296 modest_platform_connect_and_perform_if_network_account (GtkWindow *parent_window, 
297                                                         TnyAccount *account,
298                                                         ModestConnectedPerformer callback, 
299                                                         gpointer user_data)
300 {
301         if (callback)
302                 callback (FALSE, NULL, parent_window, account, user_data);
303 }
304
305 void
306 modest_platform_connect_and_perform_if_network_folderstore (GtkWindow *parent_window, 
307                                                             TnyFolderStore *folder_store, 
308                                                             ModestConnectedPerformer callback, 
309                                                             gpointer user_data)
310 {
311         if (callback)
312                 callback (FALSE, NULL, parent_window, NULL, user_data);
313 }
314
315
316 void 
317 modest_platform_remove_new_mail_notifications (void)
318 {
319         g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
320 }
321
322 gboolean 
323 modest_platform_check_and_wait_for_account_is_online(TnyAccount *account)
324 {
325         g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
326         return TRUE;
327 }
328
329 gboolean 
330 modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
331                                                      const gchar *certificate)
332 {
333         g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
334         return TRUE;
335 }
336
337 gint
338 modest_platform_run_rename_folder_dialog (GtkWindow *parent_window,
339                                           TnyFolderStore *parent_folder,
340                                           const gchar *suggested_name,
341                                           gchar **folder_name)
342 {
343         g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
344         return GTK_RESPONSE_CANCEL;
345 }
346
347 void 
348 modest_platform_show_addressbook (GtkWindow *parent_window)
349 {
350         g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
351 }
352