comparison main.c @ 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 4dca76db9e1f
comparison
equal deleted inserted replaced
473:06aa00ba32a2 474:4ddc3d87242e
589 else 589 else
590 return 1; 590 return 1;
591 } 591 }
592 592
593 593
594 int nncmd_open_profile(nn_conn_t *conn, char *name) 594 int nn_open_uri(const char *uri)
595 { 595 {
596 char *uri, *enc_name = nn_encode_str1(name);
597 #ifdef __WIN32 596 #ifdef __WIN32
598 HINSTANCE status; 597 HINSTANCE status;
598
599 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA);
600 if (status <= (HINSTANCE) 32)
601 {
602 printMsgQ(currWin, "Could not launch default web browser: %d\n", status);
603 }
599 #else 604 #else
600 int status; 605 int status;
601 int fds[2]; 606 int fds[2];
602 pid_t pid; 607 pid_t pid;
603 #endif
604 (void) conn;
605
606 printMsg(currWin, "Opening profile for: '%s'\n", name);
607
608 #ifdef __WIN32
609 uri = th_strdup_printf(SET_PROFILE_PREFIX, enc_name);
610 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA);
611 if (status <= (HINSTANCE) 32)
612 {
613 printMsgQ(currWin, "Could not launch default web browser: %d\n", status);
614 }
615 #else
616
617 uri = th_strdup_printf("openurl(" SET_PROFILE_PREFIX ",new-tab)", enc_name);
618 608
619 if (pipe(fds) == -1) 609 if (pipe(fds) == -1)
620 { 610 {
621 int ret = errno; 611 int ret = errno;
622 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret)); 612 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret));
629 } 619 }
630 else if (pid == 0) 620 else if (pid == 0)
631 { 621 {
632 dup2(fds[1], STDOUT_FILENO); 622 dup2(fds[1], STDOUT_FILENO);
633 dup2(fds[0], STDERR_FILENO); 623 dup2(fds[0], STDERR_FILENO);
624 char *url = th_strdup_printf("openurl(%s,new-tab)", uri);
634 execlp(setBrowser, setBrowser, "-remote", uri, (void *)NULL); 625 execlp(setBrowser, setBrowser, "-remote", uri, (void *)NULL);
626 th_free(url);
635 _exit(errno); 627 _exit(errno);
636 } 628 }
637 629
638 wait(&status); 630 wait(&status);
639 #endif 631 #endif
632
633 return 0;
634 }
635
636 int nncmd_open_profile(nn_conn_t *conn, char *name)
637 {
638 char *enc_name = nn_encode_str1(name);
639 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name);
640 (void) conn;
641
642 printMsg(currWin, "Opening profile for: '%s'\n", name);
643
644 nn_open_uri(uri);
640 645
641 th_free(uri); 646 th_free(uri);
642 th_free(enc_name); 647 th_free(enc_name);
643 return 0; 648 return 0;
644 } 649 }