From ec1ad6ea23636ecad14b491d98296ca93077abb5 Mon Sep 17 00:00:00 2001 From: jait Date: Wed, 4 Oct 2006 07:17:21 +0000 Subject: [PATCH] file2uri helper git-svn-id: svn+ssh://garage/svnroot/maemo-recorder/trunk@16 2441f5eb-5316-0410-9386-a49b32a51a4a --- src/maemo-recorder-file.c | 30 ++++++++++++++++++++++++------ src/maemo-recorder-file.h | 1 + src/maemo-recorder-ui.c | 6 +++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/maemo-recorder-file.c b/src/maemo-recorder-file.c index af5d07d..2343281 100644 --- a/src/maemo-recorder-file.c +++ b/src/maemo-recorder-file.c @@ -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); +} diff --git a/src/maemo-recorder-file.h b/src/maemo-recorder-file.h index f741af5..07da5b8 100644 --- a/src/maemo-recorder-file.h +++ b/src/maemo-recorder-file.h @@ -56,6 +56,7 @@ const gchar * getExtension(gint format); GnomeVFSFileSize getFileLength(const gchar *file); +gchar *file2uri(const gchar *filename); G_END_DECLS diff --git a/src/maemo-recorder-ui.c b/src/maemo-recorder-ui.c index 0d58ce9..d737ebb 100644 --- a/src/maemo-recorder-ui.c +++ b/src/maemo-recorder-ui.c @@ -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; -- 1.7.9.5