* check return value of hildon_uri_open, small cleanups
[modest] / src / maemo / modest-maemo-utils.c
index 8fe546c..40da89c 100644 (file)
 #define BTNAME_MATCH_RULE "type='signal',interface='" BTNAME_SIGNAL_IF \
                           "',member='" BTNAME_SIG_CHANGED "'"
 
-GQuark modest_maemo_utils_get_supported_secure_authentication_error_quark (void)
+
+static osso_context_t *__osso_context = NULL; /* urgh global */
+
+osso_context_t *
+modest_maemo_utils_get_osso_context (void)
+{
+       if (!__osso_context) 
+               g_warning ("%s: __osso_context == NULL", __FUNCTION__);
+       
+       return __osso_context;
+}
+
+void
+modest_maemo_utils_set_osso_context (osso_context_t *osso_context)
+{
+       g_return_if_fail (osso_context);
+       __osso_context = osso_context;
+}
+
+
+GQuark
+modest_maemo_utils_get_supported_secure_authentication_error_quark (void)
 {
        return g_quark_from_static_string("modest-maemo-utils-get-supported-secure-authentication-error-quark");
 }
@@ -242,11 +263,12 @@ modest_maemo_utils_file_exists (const gchar *filename)
 }
 
 TnyFsStream *
-modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path)
+modest_maemo_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path)
 {
        gint fd;
        gchar *filepath = NULL;
        gchar *tmpdir;
+       guint hash_number;
 
        /* hmmm... maybe we need a modest_text_utils_validate_file_name? */
        g_return_val_if_fail (orig_name || strlen(orig_name) == 0, NULL);
@@ -263,8 +285,13 @@ modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path)
        }
                
        /* make a random subdir under /tmp or /var/tmp */
-       tmpdir = g_strdup_printf ("%s/%d", g_get_tmp_dir (), (guint)random());
-       if (g_mkdir (tmpdir, 0755) == -1) {
+       if (hash_base != NULL) {
+               hash_number = g_str_hash (hash_base);
+       } else {
+               hash_number = (guint) random ();
+       }
+       tmpdir = g_strdup_printf ("%s/%u", g_get_tmp_dir (), hash_number);
+       if ((g_access (tmpdir, R_OK) == -1) && (g_mkdir (tmpdir, 0755) == -1)) {
                g_warning ("%s: failed to create dir '%s': %s",
                           __FUNCTION__, tmpdir, g_strerror(errno));
                g_free (tmpdir);