Allow to set a home page.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 5 Jan 2013 14:57:01 +0000 (15:57 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 5 Jan 2013 14:57:01 +0000 (15:57 +0100)
Added also commands and keybinds to easily open the home page into current or
new window.

src/command.c
src/command.h
src/config.h
src/main.c
src/main.h
src/setting.c

index 80ba1dc..10801a6 100644 (file)
@@ -28,6 +28,8 @@ static CommandInfo cmd_list[] = {
     /* command              function             arg                                                                                 mode */
     {"open",                command_open,        {VP_TARGET_CURRENT, ""},                                                            VP_MODE_NORMAL},
     {"tabopen",             command_open,        {VP_TARGET_NEW, ""},                                                                VP_MODE_NORMAL},
+    {"open-home",           command_open_home,   {VP_TARGET_CURRENT, ""},                                                            VP_MODE_NORMAL},
+    {"tabopen-home",        command_open_home,   {VP_TARGET_NEW, ""},                                                                VP_MODE_NORMAL},
     {"input",               command_input,       {0, ":"},                                                                           VP_MODE_COMMAND},
     {"inputopen",           command_input,       {0, ":open "},                                                                      VP_MODE_COMMAND},
     {"inputtabopen",        command_input,       {0, ":tabopen "},                                                                   VP_MODE_COMMAND},
@@ -126,6 +128,16 @@ gboolean command_open(const Arg* arg)
     return vp_load_uri(arg);
 }
 
+gboolean command_open_home(const Arg* arg)
+{
+    gboolean result;
+
+    Arg a = {.i = arg->i, .s = vp.config.home_page};
+    result = vp_load_uri(&a);
+
+    return result;
+}
+
 gboolean command_input(const Arg* arg)
 {
     const gchar* url;
index 3a6fa10..62fc6d7 100644 (file)
@@ -43,6 +43,7 @@ gboolean command_exists(const gchar* name);
 gboolean command_run(const gchar* name, const gchar* param);
 
 gboolean command_open(const Arg* arg);
+gboolean command_open_home(const Arg* arg);
 gboolean command_input(const Arg* arg);
 gboolean command_close(const Arg* arg);
 gboolean command_view_source(const Arg* arg);
index 2a6b992..045ed54 100644 (file)
@@ -22,9 +22,6 @@
 
 #include "stdlib.h"
 
-#define START_PAGE      "https://github.com/fanglingsu/vimp"
-
-#define SETTING_DEFAUL_FONT_SIZE    12
 #define SETTING_MAX_CONNS           25
 #define SETTING_MAX_CONNS_PER_HOST  5
 
@@ -37,6 +34,8 @@ const struct {
     {"nmap t=inputtabopen"},
     {"nmap O=inputopencurrent"},
     {"nmap T=inputtabopencurrent"},
+    {"nmap gh=open-home"},
+    {"nmap gH=tabopen-home"},
     {"nmap d=quit"},
     {"nmap <ctrl-o>=back"},
     {"nmap <ctrl-i>=forward"},
index 27165a0..538e2c9 100644 (file)
@@ -814,7 +814,7 @@ int main(int argc, char* argv[])
     if (argc > 1) {
         arg.s = g_strdup(argv[argc - 1]);
     } else {
-        arg.s = g_strdup(START_PAGE);
+        arg.s = g_strdup(vp.config.home_page);
     }
     vp_load_uri(&arg);
     g_free(arg.s);
index 54bf697..298841c 100644 (file)
@@ -223,6 +223,7 @@ typedef struct {
     time_t cookie_timeout;
     gint   scrollstep;
     guint  max_completion_items;
+    gchar* home_page;
 } Config;
 
 typedef struct {
index 36621e6..317bce6 100644 (file)
@@ -35,6 +35,7 @@ static gboolean setting_completion_style(const Setting* s, const gboolean get);
 static gboolean setting_hint_style(const Setting* s, const gboolean get);
 static gboolean setting_strict_ssl(const Setting* s, const gboolean get);
 static gboolean setting_ca_bundle(const Setting* s, const gboolean get);
+static gboolean setting_home_page(const Setting* s, const gboolean get);
 
 static Setting default_settings[] = {
     /* webkit settings */
@@ -114,6 +115,7 @@ static Setting default_settings[] = {
     {NULL, "hint-style", TYPE_CHAR, setting_hint_style, {.s = "font-family:monospace;font-weight:bold;color:#000;background-color:#fff;margin:0;padding:0px 1px;border:1px solid #444;opacity:0.7;"}},
     {NULL, "strict-ssl", TYPE_BOOLEAN, setting_strict_ssl, {.i = 1}},
     {NULL, "ca-bundle", TYPE_CHAR, setting_ca_bundle, {.s = "/etc/ssl/certs/ca-certificates.crt"}},
+    {NULL, "home-page", TYPE_CHAR, setting_home_page, {.s = "https://github.com/fanglingsu/vimp"}},
 };
 
 
@@ -542,3 +544,14 @@ static gboolean setting_ca_bundle(const Setting* s, const gboolean get)
 
     return TRUE;
 }
+
+static gboolean setting_home_page(const Setting* s, const gboolean get)
+{
+    if (get) {
+        setting_print_value(s, vp.config.home_page);
+    } else {
+        OVERWRITE_STRING(vp.config.home_page, s->arg.s);
+    }
+
+    return TRUE;
+}