changeset 474:4ddc3d87242e

Refactor web-browser launching into nn_open_uri().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 07:46:26 +0300
parents 06aa00ba32a2
children f7d20fbf821e
files main.c
diffstat 1 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sat May 26 07:45:36 2012 +0300
+++ b/main.c	Sat May 26 07:46:26 2012 +0300
@@ -591,30 +591,20 @@
 }
 
 
-int nncmd_open_profile(nn_conn_t *conn, char *name)
+int nn_open_uri(const char *uri)
 {
-    char *uri, *enc_name = nn_encode_str1(name);
 #ifdef __WIN32
     HINSTANCE status;
-#else
-    int status;
-    int fds[2];
-    pid_t pid;
-#endif
-    (void) conn;
 
-    printMsg(currWin, "Opening profile for: '%s'\n", name);
-
-#ifdef __WIN32
-    uri = th_strdup_printf(SET_PROFILE_PREFIX, enc_name);
     status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA);
     if (status <= (HINSTANCE) 32)
     {
         printMsgQ(currWin, "Could not launch default web browser: %d\n", status);
     }
 #else
-
-    uri = th_strdup_printf("openurl(" SET_PROFILE_PREFIX ",new-tab)", enc_name);
+    int status;
+    int fds[2];
+    pid_t pid;
 
     if (pipe(fds) == -1)
     {
@@ -631,13 +621,28 @@
     {
         dup2(fds[1], STDOUT_FILENO);
         dup2(fds[0], STDERR_FILENO);
+        char *url = th_strdup_printf("openurl(%s,new-tab)", uri);
         execlp(setBrowser, setBrowser, "-remote", uri, (void *)NULL);
+        th_free(url);
         _exit(errno);
     }
 
     wait(&status);
 #endif
 
+    return 0;
+}
+
+int nncmd_open_profile(nn_conn_t *conn, char *name)
+{
+    char *enc_name = nn_encode_str1(name);
+    char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name);
+    (void) conn;
+
+    printMsg(currWin, "Opening profile for: '%s'\n", name);
+    
+    nn_open_uri(uri);
+
     th_free(uri);
     th_free(enc_name);
     return 0;