aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/webbrowser.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2004-06-22 16:28:27 +0000
committerUlf Lamping <ulf.lamping@web.de>2004-06-22 16:28:27 +0000
commiteab0af6659b193eac71555d0c63961067808c524 (patch)
treed816bfbada016621f71d41c4f21bd08a715afbed /gtk/webbrowser.c
parent00a21837110b9b8f454f43cc0d7f6b4b589e74fd (diff)
add functionality, to show html files from the local installation
svn path=/trunk/; revision=11213
Diffstat (limited to 'gtk/webbrowser.c')
-rw-r--r--gtk/webbrowser.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/gtk/webbrowser.c b/gtk/webbrowser.c
index 58c5d0322e..21f26dd6a8 100644
--- a/gtk/webbrowser.c
+++ b/gtk/webbrowser.c
@@ -169,3 +169,52 @@ strreplace (const gchar *string,
}
#endif /* MUST_LAUNCH_BROWSER_OURSELVES */
+
+/** Convert local absolute path to uri.
+ *
+ * @param filename to (absolute pathed) filename to convert
+ * @return a newly allocated uri, you must g_free it later
+ */
+gchar *
+filename2uri(gchar *filename)
+{
+ int i = 0;
+ gchar *file_tmp;
+ GString *filestr;
+
+
+ filestr = g_string_sized_new(200);
+
+ /* this escaping is somewhat slow but should working fine */
+ for(i=0; filename[i]; i++) {
+ switch(filename[i]) {
+ case(' '):
+ g_string_append(filestr, "%20");
+ break;
+ case('%'):
+ g_string_append(filestr, "%%");
+ break;
+ case('\\'):
+ g_string_append_c(filestr, '/');
+ break;
+ /* XXX - which other chars need to be escaped? */
+ default:
+ g_string_append_c(filestr, filename[i]);
+ }
+ }
+
+
+ /* prepend URI header "file:" appropriate for the system */
+#ifdef G_OS_WIN32
+ /* XXX - how do we handle UNC names (e.g. //servername/sharename/dir1/dir2/capture-file.cap) */
+ g_string_prepend(filestr, "file:///");
+#else
+ g_string_prepend(filestr, "file:");
+#endif
+
+ file_tmp = filestr->str;
+
+ g_string_free(filestr, FALSE /* don't free segment data */);
+
+ return file_tmp;
+} \ No newline at end of file