# HG changeset patch # User Matti Hamalainen # Date 1338007586 -10800 # Node ID 4ddc3d87242eed5257b7ce01dda1188eaf4209bd # Parent 06aa00ba32a28ac92342f104159ddd97910e353b Refactor web-browser launching into nn_open_uri(). diff -r 06aa00ba32a2 -r 4ddc3d87242e main.c --- 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;