static WebKitWebView *webview_new(Client *c, WebKitWebView *webview);
static void on_script_message_focus(WebKitUserContentManager *manager,
WebKitJavascriptResult *message, Client *c);
+static gboolean profileOptionArgFunc(const gchar *option_name,
+ const gchar *value, gpointer data, GError **error);
struct Vimb vb;
static void spawn_new_instance(const char *uri, gboolean embed)
{
guint i = 0;
- char xid[64];
- char *cmd[5];
+ /* memory allocation */
+ char **cmd = g_malloc_n(
+ 3 /* basename + uri + ending NULL */
+#ifndef FEATURE_NO_XEMBED
+ + (vb.embed && embed ? 2 : 0)
+#endif
+ + (vb.profile ? 2 : 0),
+ sizeof(char *)
+ );
cmd[i++] = vb.argv0;
+#ifndef FEATURE_NO_XEMBED
if (vb.embed && embed) {
+ char xid[64];
cmd[i++] = "-e";
snprintf(xid, LENGTH(xid), "%d", (int)vb.embed);
cmd[i++] = xid;
}
+#endif
+ if (vb.profile) {
+ cmd[i++] = "-p";
+ cmd[i++] = vb.profile;
+ }
cmd[i++] = (char*)uri;
cmd[i++] = NULL;
/* spawn a new browser instance */
g_spawn_async(NULL, cmd, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+
+ /* free commandline */
+ g_free(cmd);
}
/**
g_free(vb.files[i]);
}
}
+ g_free(vb.profile);
}
#endif
}
}
+static gboolean profileOptionArgFunc(const gchar *option_name,
+ const gchar *value, gpointer data, GError **error)
+{
+ vb.profile = util_sanitize_filename(g_strdup(value));
+
+ return TRUE;
+}
+
int main(int argc, char* argv[])
{
Client *c;
GOptionEntry opts[] = {
{"embed", 'e', 0, G_OPTION_ARG_STRING, &winid, "Reparents to window specified by xid", NULL},
{"config", 'c', 0, G_OPTION_ARG_FILENAME, &vb.configfile, "Custom configuration file", NULL},
+ {"profile", 'p', 0, G_OPTION_ARG_CALLBACK, profileOptionArgFunc, "Profile name", NULL},
{"version", 'v', 0, G_OPTION_ARG_NONE, &ver, "Print version", NULL},
{NULL}
};
char *config_dir;
} util;
+extern struct Vimb vb;
+
static void create_dir_if_not_exists(const char *dirpath);
/**
}
/**
- * Retrieves the config directory path.
- * Returnes string must be freed.
+ * Retrieves the config directory path according to current used profile.
+ * Returned string must be freed.
*/
char *util_get_config_dir(void)
{
- char *path = g_build_filename(g_get_user_config_dir(), PROJECT, NULL);
+ char *path = g_build_filename(g_get_user_config_dir(), PROJECT, vb.profile, NULL);
create_dir_if_not_exists(path);
return path;
return expanded;
}
+/**
+ * Sanituze filename by removeing directory separator by underscore.
+ *
+ * The string is modified in place.
+ */
+char *util_sanitize_filename(char *filename)
+{
+ return g_strdelimit(filename, G_DIR_SEPARATOR_S, '_');
+}
+
char *util_strcasestr(const char *haystack, const char *needle)
{
guchar c1, c2;
double util_js_result_as_number(WebKitJavascriptResult *result);
gboolean util_parse_expansion(Client *c, const char **input, GString *str,
int flags, const char *quoteable);
-char *util_str_replace(const char* search, const char* replace, const char* string);
+char *util_sanitize_filename(char *filename);
char *util_strcasestr(const char *haystack, const char *needle);
+char *util_str_replace(const char* search, const char* replace, const char* string);
#endif /* end of include guard: _UTIL_H */