file2uri helper
authorjait <jari.tenhunen@iki.fi>
Wed, 4 Oct 2006 07:17:21 +0000 (07:17 +0000)
committerjait <jari.tenhunen@iki.fi>
Wed, 4 Oct 2006 07:17:21 +0000 (07:17 +0000)
git-svn-id: svn+ssh://garage/svnroot/maemo-recorder/trunk@16 2441f5eb-5316-0410-9386-a49b32a51a4a

src/maemo-recorder-file.c
src/maemo-recorder-file.h
src/maemo-recorder-ui.c

index af5d07d..2343281 100644 (file)
@@ -148,7 +148,7 @@ saveFile(const gchar *filename, const gchar *tmpfile, AudioFormat format, gchar
             goto save_error;
 
         /* open tmpfile(r) */
-        text_uri = g_strconcat("file://", tmpfile, NULL);
+        text_uri = file2uri(tmpfile);
         
         if (gnome_vfs_open(&tmp_handle, text_uri, GNOME_VFS_OPEN_READ) != GNOME_VFS_OK)
         {
@@ -161,7 +161,7 @@ saveFile(const gchar *filename, const gchar *tmpfile, AudioFormat format, gchar
         text_uri = NULL;
 
         /* open/create newfile for writing */
-        text_uri = g_strconcat("file://", newfile_tmp, NULL);
+        text_uri = file2uri(newfile_tmp);
         uri = gnome_vfs_uri_new(text_uri);
         g_free(text_uri);
         text_uri = NULL;
@@ -232,7 +232,8 @@ save_error:
  * - the tmpfile where the raw data is (or the same file name if the file was raw)
  * TODO: add parameter (GError?) to report back an error string
  */
-gboolean openFile(const gchar *filename, AudioFormat *format, gchar **tmpfile)
+gboolean 
+openFile(const gchar *filename, AudioFormat *format, gchar **tmpfile)
 {
     if (g_strrstr(filename, EXTENSION_PCMA))
     {
@@ -262,6 +263,7 @@ gboolean openFile(const gchar *filename, AudioFormat *format, gchar **tmpfile)
     {
         ULOG_INFO("%s() - file was %s", G_STRFUNC, EXTENSION_WAV);
         *format = FORMAT_WAV;
+        /* TODO: we should dig out the rate, channels and stuff from the WAV file here or get the caps from some GstPad */
         *tmpfile = g_strdup(filename);
     }
     else if (g_strrstr(filename, EXTENSION_ILBC))
@@ -282,7 +284,7 @@ gboolean openFile(const gchar *filename, AudioFormat *format, gchar **tmpfile)
 
         ULOG_INFO("%s() - file was AU/SND", G_STRFUNC);
         /* decode and extract raw AU data */
-        text_uri = g_strdup_printf("file://%s", filename);
+        text_uri = file2uri(filename);
         if (gnome_vfs_open(&from_handle, text_uri, GNOME_VFS_OPEN_READ) != GNOME_VFS_OK)
         {
             ULOG_WARN("%s() -  gnome_vfs_open() failed", G_STRFUNC);
@@ -362,7 +364,8 @@ gboolean openFile(const gchar *filename, AudioFormat *format, gchar **tmpfile)
     return TRUE;
 }
 
-GnomeVFSFileSize getFileLength(const gchar *file)
+GnomeVFSFileSize 
+getFileLength(const gchar *file)
 {
     GnomeVFSFileInfo *info;
     GnomeVFSResult res;
@@ -372,7 +375,7 @@ GnomeVFSFileSize getFileLength(const gchar *file)
     if (NULL == file)
         return ret;
 
-    text_uri = g_strdup_printf("file://%s", file);
+    text_uri = file2uri(file);
     info = gnome_vfs_file_info_new();
     res = gnome_vfs_get_file_info(text_uri,
                 info,
@@ -393,3 +396,18 @@ GnomeVFSFileSize getFileLength(const gchar *file)
 
     return ret;
 }
+
+gchar *
+file2uri(const gchar *filename)
+{
+    if (NULL == filename)
+        return NULL;
+
+    if (g_str_has_prefix(filename, "file://"))
+        return g_strdup(filename);
+
+    /*
+    return g_strconcat("file://", filename, NULL);
+    */
+    return g_filename_to_uri(filename, NULL, NULL);
+}
index f741af5..07da5b8 100644 (file)
@@ -56,6 +56,7 @@ const gchar * getExtension(gint format);
 
 GnomeVFSFileSize getFileLength(const gchar *file);
 
+gchar *file2uri(const gchar *filename);
 
 G_END_DECLS
 
index 0d58ce9..d737ebb 100644 (file)
@@ -641,6 +641,7 @@ static void cbDestroy(GtkWidget* widget, GdkEvent *event, gpointer data)
 
     app = (AppData *) data;
 
+    ULOG_DEBUG("delete_event");
     if (!closeFile(app))
         return;
 
@@ -892,6 +893,7 @@ openURI(gpointer user_data)
         else
             setLength(data, 0.0);
 
+        setFormatString(data, data->file_format);
         data->saved = TRUE;
     }
     else
@@ -1099,7 +1101,7 @@ static void cbEmailing(GtkWidget* widget, AppData *data)
     
     if (g_file_test(getFileName(data), G_FILE_TEST_EXISTS))
     {
-        file = g_strdup_printf("file://%s", getFileName(data)); 
+        file = file2uri(getFileName(data));
         ULOG_INFO("Emailing: %s", file);
         list = g_slist_append(list, file);
         if (osso_email_files_email(data->osso, list) != OSSO_OK)
@@ -1875,6 +1877,8 @@ setFormatString(AppData *data, AudioFormat afmt)
             format = FORMAT_NAME_ILBC;
             rate = ILBC_RATE;
             break;
+        /* TODO: we can play wavs with many sampling rates, 2 channels */
+        /* we really should migrate to the better format spec */
         case FORMAT_WAV:
             format = FORMAT_NAME_WAV;
             bits = PCM_WIDTH;