* src/maemo/modest-address-book.c:
[modest] / src / maemo / modest-platform.c
index 2f1468d..f41dd95 100644 (file)
@@ -54,6 +54,7 @@
 #include <modest-text-utils.h>
 #include "modest-tny-folder.h"
 #include <string.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
 
 
 #define HILDON_OSSO_URI_ACTION "uri-action"
@@ -75,12 +76,40 @@ on_modest_conf_update_interval_changed (ModestConf* self,
        }
 }
 
+
+
+static gboolean
+check_required_files (void)
+{
+       FILE *mcc_file = modest_maemo_open_mcc_mapping_file ();
+       if (!mcc_file) {
+               g_printerr ("modest: check for mcc file failed\n");
+               return FALSE;
+       } else 
+               fclose (mcc_file);
+
+       if (access (MODEST_PROVIDERS_DATA_PATH, R_OK) != 0) {
+               g_printerr ("modest: cannot find providers data\n");
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+
 gboolean
 modest_platform_init (int argc, char *argv[])
 {
        osso_hw_state_t hw_state = { 0 };
        DBusConnection *con;    
 
+       if (!check_required_files ()) {
+               g_printerr ("modest: missing required files\n");
+               return FALSE;
+       }
+
+       
        osso_context =
                osso_initialize(PACKAGE,PACKAGE_VERSION,
                                FALSE, NULL);   
@@ -94,7 +123,7 @@ modest_platform_init (int argc, char *argv[])
                return FALSE;
 
        }
-       
+
        /* Add a D-Bus handler to be used when the main osso-rpc 
         * D-Bus handler has not handled something.
         * We use this for D-Bus methods that need to use more complex types 
@@ -177,45 +206,6 @@ modest_platform_get_new_device (void)
        return TNY_DEVICE (tny_maemo_conic_device_new ());
 }
 
-
-const gchar*
-guess_mime_type_from_name (const gchar* name)
-{
-       int i;
-       const static gchar* mime_type;
-       const static gchar* mime_map[][2] = {
-               { ".note.html", "text/note"}, /* for the osso_notes program */
-               { ".deb",       "application/x-deb"},
-               { ".install",   "application/x-install-instructions"},
-               { ".html",      "text/html"}, 
-               { ".htm",       "text/html"}, 
-               { ".pdf",       "application/pdf"},
-               { ".doc",       "application/msword"},
-               { ".xls",       "application/excel"},
-               { ".png",       "image/png" },
-               { ".gif",       "image/gif" },
-               { ".jpg",       "image/jpeg"},
-               { ".jpeg",      "image/jpeg"},
-               { ".mp3",       "audio/mp3" }
-       };
-
-       mime_type = "application/octet-stream";
-
-       if (name) {
-               gchar* lc_name = g_utf8_strdown (name, -1);
-               for (i = 0; i != G_N_ELEMENTS(mime_map); ++i) {
-                       if (g_str_has_suffix (lc_name, mime_map[i][0])) {
-                               mime_type = mime_map[i][1];
-                               break;
-                       }
-               }
-               g_free (lc_name);
-       }
-       
-       return mime_type;
-}
-
-
 gchar*
 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
                                    gchar **effective_mime_type)
@@ -223,9 +213,9 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
        GString *mime_str = NULL;
        gchar *icon_name  = NULL;
        gchar **icons, **cursor;
-
+       
        if (!mime_type || !g_ascii_strcasecmp (mime_type, "application/octet-stream")) 
-               mime_str = g_string_new (guess_mime_type_from_name(name));
+               mime_str = g_string_new (gnome_vfs_get_mime_type_for_name (name));
        else {
                mime_str = g_string_new (mime_type);
                g_string_ascii_down (mime_str);
@@ -259,14 +249,12 @@ modest_platform_activate_uri (const gchar *uri)
        HildonURIAction *action;
        gboolean result = FALSE;
        GSList *actions, *iter = NULL;
-       const gchar *scheme;
        
        g_return_val_if_fail (uri, FALSE);
        if (!uri)
                return FALSE;
-
-       scheme = hildon_uri_get_scheme_from_uri (uri, NULL);
-       actions = hildon_uri_get_actions (scheme, NULL);
+       
+       actions = hildon_uri_get_actions_by_uri (uri, -1, NULL);
        
        for (iter = actions; iter; iter = g_slist_next (iter)) {
                action = (HildonURIAction*) iter->data;
@@ -283,7 +271,7 @@ modest_platform_activate_uri (const gchar *uri)
                }
        }
        
-       /* if we could open it with email, try something else */
+       /* if we could not open it with email, try something else */
        if (!result)
                result = hildon_uri_open (uri, NULL, NULL);     
                
@@ -371,14 +359,12 @@ activate_uri_popup_item (GtkMenuItem *menu_item,
 gboolean 
 modest_platform_show_uri_popup (const gchar *uri)
 {
-       gchar *scheme;
        GSList *actions_list;
 
        if (uri == NULL)
                return FALSE;
-       
-       scheme = hildon_uri_get_scheme_from_uri (uri, NULL);
-       actions_list = hildon_uri_get_actions (scheme, NULL);
+
+       actions_list = hildon_uri_get_actions_by_uri (uri, -1, NULL);
        if (actions_list != NULL) {
                GSList *node;
                GtkWidget *menu = gtk_menu_new ();
@@ -424,8 +410,7 @@ modest_platform_show_uri_popup (const gchar *uri)
        } else {
                hildon_banner_show_information (NULL, NULL, _("mcen_ib_unsupported_link"));
        }
-       
-       g_free (scheme);
+
        return TRUE;
 }
 
@@ -1002,13 +987,9 @@ set_account_to_online (TnyAccount *account)
                 * a) They fundamentally need network access, so they can't really be offline.
                 * b) That might cause a transport connection to happen too early.
                 */
-               GError *error = NULL;
-               tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE, &error);
-               if (error) {
-                       g_warning ("%s: tny_camel_account_set_online() returned a GError:\n  %s\n", 
-                               __FUNCTION__, error->message);
-                       g_error_free (error);   
-               }
+
+               /* The last argument is user_data, the NULL before that is the callback */
+               tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE, NULL, NULL);
        }
        #endif
 }
@@ -1290,13 +1271,17 @@ modest_platform_on_new_header_received (TnyHeader *header)
                                            -1);
        g_free (url);
        
-       /* Play sound SR-SND-18 */
-       hildon_notification_set_sound (HILDON_NOTIFICATION(notification),
-                                      "/usr/share/sounds/ui-new_email.wav");
-       notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION(notification),
-                                           "dialog-type", 4);
+       /* Play sound if the user wants */
+       if (modest_conf_get_bool (modest_runtime_get_conf (), 
+                                 MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, 
+                                 NULL)) {
+               hildon_notification_set_sound (HILDON_NOTIFICATION(notification),
+                                              "/usr/share/sounds/ui-new_email.wav");
+       }
        
        /* Set the led pattern */
+       notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION(notification),
+                                           "dialog-type", 4);
        notify_notification_set_hint_string(NOTIFY_NOTIFICATION(notification), 
                                            "led-pattern", 
                                            "PatternCommunicationEmail");
@@ -1601,8 +1586,8 @@ modest_platform_run_alert_dialog (const gchar* prompt,
                
        } else {
                /* Just show the error text and use the default response: */
-               modest_maemo_show_information_note_and_forget(GTK_WINDOW (main_window), 
-                                                             prompt);
+               modest_platform_run_information_dialog (GTK_WINDOW (main_window), 
+                                                       prompt);
        }
        return retval;
 }