9 #include <JavaScriptCore/JavaScript.h>
10 #include <gdk/gdkkeysyms.h>
14 #include <webkit2/webkit2.h>
16 void client_destroy(GtkWidget *, gpointer);
17 WebKitWebView *client_new(const gchar *, WebKitWebView *, gboolean,
19 WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
21 void cooperation_setup(void);
22 void changed_download_progress(GObject *, GParamSpec *, gpointer);
23 void changed_load_progress(GObject *, GParamSpec *, gpointer);
24 void changed_favicon(GObject *, GParamSpec *, gpointer);
25 void changed_title(GObject *, GParamSpec *, gpointer);
26 void changed_uri(GObject *, GParamSpec *, gpointer);
27 gboolean crashed_web_view(WebKitWebView *, gpointer);
28 gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
29 WebKitPolicyDecisionType, gpointer);
30 gboolean download_handle(WebKitDownload *, gchar *, gpointer);
31 void download_click(GtkToolButton *, gpointer);
32 void download_start(WebKitWebView *, WebKitDownload *, gpointer);
33 void download_cancel(GtkMenuItem *, gpointer);
34 gboolean downloadmanager_delete(GtkWidget *, gpointer);
35 void downloadmanager_setup(void);
36 gchar *ensure_uri_scheme(const gchar *);
37 void grab_environment_configuration(void);
38 void grab_feeds_finished(GObject *, GAsyncResult *, gpointer);
39 void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
40 void icon_location(GtkEntry *, GtkEntryIconPosition, GdkEvent *, gpointer);
41 void init_default_web_context(void);
42 gboolean key_common(GtkWidget *, GdkEvent *, gpointer);
43 gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
44 gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
45 gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
46 gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
47 void mainwindow_setup(void);
48 void mainwindow_title(gint);
49 void notebook_switch_page(GtkNotebook *, GtkWidget *, guint, gpointer);
50 gboolean quit_if_nothing_active(void);
51 gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
52 void run_user_scripts(WebKitWebView *);
53 void search(gpointer, gint);
54 void show_web_view(WebKitWebView *, gpointer);
55 void trust_user_certs(WebKitWebContext *);
56 GKeyFile *get_ini(void);
61 gchar *external_handler_uri;
69 gboolean focus_new_tab;
78 struct DownloadManager
87 WebKitCookieAcceptPolicy cookie_policy;
88 const gchar *accepted_language[2];
89 gboolean cooperative_alone;
90 gboolean cooperative_instances;
91 gboolean enable_console_to_stdout;
92 gboolean javascript_disabled;
93 gboolean spellcheck_disabled;
99 gchar *spellcheck_language;
102 gint tab_width_chars;
108 WebKitDownload *download;
111 gint clients = 0, downloads = 0;
112 int cooperative_pipe_fp = 0;
116 client_destroy(GtkWidget *widget, gpointer data)
118 struct Client *c = (struct Client *)data;
121 g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
122 changed_load_progress, c);
124 idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
126 fprintf(stderr, __NAME__": Tab index was -1, bamboozled\n");
128 gtk_notebook_remove_page(GTK_NOTEBOOK(mw.notebook), idx);
133 quit_if_nothing_active();
137 client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
142 GtkWidget *evbox, *tabbox;
144 if (uri != NULL && cfg.cooperative_instances && !cfg.cooperative_alone) {
145 f = ensure_uri_scheme(uri);
146 write(cooperative_pipe_fp, f, strlen(f));
147 write(cooperative_pipe_fp, "\n", 1);
152 c = calloc(1, sizeof(struct Client));
154 fprintf(stderr, __NAME__": fatal: calloc failed\n");
158 c->focus_new_tab = focus_tab;
160 if (related_wv == NULL)
161 c->web_view = webkit_web_view_new();
163 c->web_view = webkit_web_view_new_with_related_view(related_wv);
165 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), cfg.global_zoom);
166 WebKitSettings *settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
167 webkit_settings_set_enable_javascript(settings, !cfg.javascript_disabled);
168 g_signal_connect(G_OBJECT(c->web_view), "notify::favicon",
169 G_CALLBACK(changed_favicon), c);
170 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
171 G_CALLBACK(changed_title), c);
172 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
173 G_CALLBACK(changed_uri), c);
174 g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
175 G_CALLBACK(changed_load_progress), c);
176 g_signal_connect(G_OBJECT(c->web_view), "create",
177 G_CALLBACK(client_new_request), NULL);
178 g_signal_connect(G_OBJECT(c->web_view), "close",
179 G_CALLBACK(client_destroy), c);
180 g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
181 G_CALLBACK(decide_policy), NULL);
182 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
183 G_CALLBACK(key_web_view), c);
184 g_signal_connect(G_OBJECT(c->web_view), "button-release-event",
185 G_CALLBACK(key_web_view), c);
186 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
187 G_CALLBACK(key_web_view), c);
188 g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
189 G_CALLBACK(hover_web_view), c);
190 g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
191 G_CALLBACK(crashed_web_view), c);
193 if (cfg.user_agent != NULL)
194 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
195 "user-agent", cfg.user_agent, NULL);
197 if (cfg.enable_console_to_stdout)
198 webkit_settings_set_enable_write_console_messages_to_stdout(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
200 webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
202 c->location = gtk_entry_new();
203 g_signal_connect(G_OBJECT(c->location), "key-press-event",
204 G_CALLBACK(key_location), c);
205 g_signal_connect(G_OBJECT(c->location), "icon-release",
206 G_CALLBACK(icon_location), c);
207 /* XXX This is a workaround. Setting this to NULL (which is done in
208 * grab_feeds_finished() if no feed has been detected) adds a little
209 * padding left of the text. Not sure why. The point of this call
210 * right here is to have that padding right from the start. This
211 * avoids a graphical artifact. */
212 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
213 GTK_ENTRY_ICON_PRIMARY,
216 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
217 gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0);
218 gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0);
219 gtk_container_set_focus_child(GTK_CONTAINER(c->vbox), c->web_view);
221 c->tabicon = gtk_image_new_from_icon_name("text-html", GTK_ICON_SIZE_SMALL_TOOLBAR);
223 c->tablabel = gtk_label_new(__NAME__);
224 gtk_label_set_ellipsize(GTK_LABEL(c->tablabel), PANGO_ELLIPSIZE_END);
225 gtk_label_set_width_chars(GTK_LABEL(c->tablabel), cfg.tab_width_chars);
226 gtk_widget_set_has_tooltip(c->tablabel, TRUE);
228 /* XXX I don't own a HiDPI screen, so I don't know if scale_factor
229 * does the right thing. */
230 tabbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
231 5 * gtk_widget_get_scale_factor(mw.win));
232 gtk_box_pack_start(GTK_BOX(tabbox), c->tabicon, FALSE, FALSE, 0);
233 gtk_box_pack_start(GTK_BOX(tabbox), c->tablabel, TRUE, TRUE, 0);
235 evbox = gtk_event_box_new();
236 gtk_container_add(GTK_CONTAINER(evbox), tabbox);
237 g_signal_connect(G_OBJECT(evbox), "button-release-event",
238 G_CALLBACK(key_tablabel), c);
240 gtk_widget_add_events(evbox, GDK_SCROLL_MASK);
241 g_signal_connect(G_OBJECT(evbox), "scroll-event",
242 G_CALLBACK(key_tablabel), c);
244 /* For easy access, store a reference to our label. */
245 g_object_set_data(G_OBJECT(evbox), "lariza-tab-label", c->tablabel);
247 /* This only shows the event box and the label inside, nothing else.
248 * Needed because the evbox/label is "internal" to the notebook and
249 * not part of the normal "widget tree" (IIUC). */
250 gtk_widget_show_all(evbox);
252 gtk_notebook_insert_page(GTK_NOTEBOOK(mw.notebook), c->vbox, evbox,
253 gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)) + 1);
254 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(mw.notebook), c->vbox, TRUE);
257 show_web_view(NULL, c);
259 g_signal_connect(G_OBJECT(c->web_view), "ready-to-show",
260 G_CALLBACK(show_web_view), c);
263 f = ensure_uri_scheme(uri);
264 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
270 return WEBKIT_WEB_VIEW(c->web_view);
274 client_new_request(WebKitWebView *web_view,
275 WebKitNavigationAction *navigation_action, gpointer data)
277 return client_new(NULL, web_view, FALSE, FALSE);
281 cooperation_setup(void)
284 gchar *fifofilename, *fifopath;
286 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", cfg.fifo_suffix);
287 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
288 g_free(fifofilename);
290 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
291 mkfifo(fifopath, 0600);
293 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
294 if (!cooperative_pipe_fp) {
295 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
297 if (write(cooperative_pipe_fp, "", 0) == -1) {
298 /* Could not do an empty write to the FIFO which means there's
299 * no one listening. */
300 close(cooperative_pipe_fp);
301 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
302 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
304 cfg.cooperative_alone = FALSE;
312 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
314 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
315 WebKitURIResponse *resp;
316 GtkToolItem *tb = GTK_TOOL_ITEM(data);
319 gchar *t, *filename, *base;
321 p = webkit_download_get_estimated_progress(download);
325 resp = webkit_download_get_response(download);
326 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
328 uri = webkit_download_get_destination(download);
329 filename = g_filename_from_uri(uri, NULL, NULL);
330 if (filename == NULL) {
331 /* This really should not happen because WebKit uses that URI to
332 * write to a file... */
333 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
334 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
335 webkit_uri_response_get_uri(resp), p, size_mb);
337 base = g_path_get_basename(filename);
338 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
342 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
347 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
349 struct Client *c = (struct Client *)data;
352 "a = document.querySelectorAll('"
353 " html > head > link[rel=\"alternate\"][href][type=\"application/atom+xml\"],"
354 " html > head > link[rel=\"alternate\"][href][type=\"application/rss+xml\"]"
361 " for (i = 0; i < a.length; i++)"
363 " url = encodeURIComponent(a[i].href);"
364 " if ('title' in a[i] && a[i].title != '')"
365 " title = encodeURIComponent(a[i].title);"
368 " out += '<li><a href=\"' + url + '\">' + title + '</a></li>';"
374 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
378 /* The page has loaded fully. We now run the short JavaScript
379 * snippet above that operates on the DOM. It tries to grab all
380 * occurences of <link rel="alternate" ...>, i.e. RSS/Atom feed
382 webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
384 grab_feeds_finished, c);
386 run_user_scripts(WEBKIT_WEB_VIEW(c->web_view));
388 gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), p);
392 changed_favicon(GObject *obj, GParamSpec *pspec, gpointer data)
394 struct Client *c = (struct Client *)data;
396 int w, h, w_should, h_should;
397 GdkPixbuf *pb, *pb_scaled;
399 f = webkit_web_view_get_favicon(WEBKIT_WEB_VIEW(c->web_view));
401 gtk_image_set_from_icon_name(GTK_IMAGE(c->tabicon), "text-html",
402 GTK_ICON_SIZE_SMALL_TOOLBAR);
404 w = cairo_image_surface_get_width(f);
405 h = cairo_image_surface_get_height(f);
406 pb = gdk_pixbuf_get_from_surface(f, 0, 0, w, h);
408 w_should = 16 * gtk_widget_get_scale_factor(c->tabicon);
409 h_should = 16 * gtk_widget_get_scale_factor(c->tabicon);
410 pb_scaled = gdk_pixbuf_scale_simple(pb, w_should, h_should,
411 GDK_INTERP_BILINEAR);
412 gtk_image_set_from_pixbuf(GTK_IMAGE(c->tabicon), pb_scaled);
414 g_object_unref(pb_scaled);
421 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
424 struct Client *c = (struct Client *)data;
426 u = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
427 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
429 u = u == NULL ? __NAME__ : u;
430 u = u[0] == 0 ? __NAME__ : u;
432 t = t == NULL ? u : t;
433 t = t[0] == 0 ? u : t;
435 gtk_label_set_text(GTK_LABEL(c->tablabel), t);
436 gtk_widget_set_tooltip_text(c->tablabel, t);
437 mainwindow_title(gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)));
441 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
444 struct Client *c = (struct Client *)data;
447 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
449 /* When a web process crashes, we get a "notify::uri" signal, but we
450 * can no longer read a meaningful URI. It's just an empty string
451 * now. Not updating the location bar in this scenario is important,
452 * because we would override the "WEB PROCESS CRASHED" message. */
453 if (t != NULL && strlen(t) > 0) {
454 gtk_entry_set_text(GTK_ENTRY(c->location), t);
456 if (cfg.history_file != NULL) {
457 fp = fopen(cfg.history_file, "a");
459 fprintf(fp, "%s\n", t);
462 perror(__NAME__": Error opening history file");
469 crashed_web_view(WebKitWebView *web_view, gpointer data)
472 struct Client *c = (struct Client *)data;
474 t = g_strdup_printf("WEB PROCESS CRASHED: %s",
475 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(web_view)));
476 gtk_entry_set_text(GTK_ENTRY(c->location), t);
483 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
484 WebKitPolicyDecisionType type, gpointer data)
486 WebKitResponsePolicyDecision *r;
489 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
490 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
491 if (!webkit_response_policy_decision_is_mime_type_supported(r))
492 webkit_policy_decision_download(decision);
494 webkit_policy_decision_use(decision);
497 /* Use whatever default there is. */
504 download_finished(WebKitDownload *download, gpointer data)
506 if (strcmp(gtk_tool_button_get_icon_name(GTK_TOOL_BUTTON(data)),
507 "dialog-error") != 0)
508 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(data), "emblem-downloads");
513 download_start(WebKitWebView *web_view, WebKitDownload *download,
516 g_signal_connect(G_OBJECT(download), "decide-destination",
517 G_CALLBACK(download_handle), data);
521 download_handle(WebKitDownload *download, gchar *suggested_filename,
524 gchar *sug_clean, *path, *path2 = NULL, *uri;
529 sug_clean = g_strdup(suggested_filename);
530 for (i = 0; i < strlen(sug_clean); i++)
531 if (sug_clean[i] == G_DIR_SEPARATOR)
534 path = g_build_filename(cfg.download_dir, sug_clean, NULL);
535 path2 = g_strdup(path);
536 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000) {
539 path2 = g_strdup_printf("%s.%d", path, suffix);
543 if (suffix == 1000) {
544 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
545 webkit_download_cancel(download);
547 uri = g_filename_to_uri(path2, NULL, NULL);
548 webkit_download_set_destination(download, uri);
551 tb = gtk_tool_button_new(NULL, NULL);
552 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "network-receive");
553 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), sug_clean);
554 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
555 gtk_widget_show_all(dm.win);
557 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
558 G_CALLBACK(changed_download_progress), tb);
561 g_signal_connect(G_OBJECT(download), "finished",
562 G_CALLBACK(download_finished), tb);
564 g_object_ref(download);
566 struct DownloadItem *payload = malloc(sizeof(*payload));
567 payload->tb = (GtkToolButton *)tb;
568 payload->download = download;
569 g_signal_connect(G_OBJECT(tb), "clicked", G_CALLBACK(download_click),
571 g_signal_connect(G_OBJECT(tb), "failed", G_CALLBACK(download_cancel),
573 g_signal_connect(G_OBJECT(tb), "destroy_event", G_CALLBACK(g_free),
581 /* Propagate -- to whom it may concern. */
586 download_cancel(GtkMenuItem *tb, gpointer data)
588 struct DownloadItem *payload = data;
589 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(payload->tb), "dialog-error");
590 webkit_download_cancel(payload->download);
594 download_remove(GtkMenuItem *tb, gpointer data)
596 struct DownloadItem *payload = data;
597 g_object_unref(payload->download);
598 gtk_widget_destroy(GTK_WIDGET(payload->tb));
602 download_copy_url(GtkMenuItem *tb, gpointer data)
604 struct DownloadItem *payload = data;
605 WebKitURIRequest *req = webkit_download_get_request(payload->download);
606 const gchar *uri = webkit_uri_request_get_uri(req);
607 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri,
612 download_copy_path(GtkMenuItem *tb, gpointer data)
614 struct DownloadItem *payload = data;
615 const gchar *path = webkit_download_get_destination(payload->download);
616 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), path + 7,
617 strlen(path) - 7); // Offset by 7 to remove "file://"
621 download_click(GtkToolButton *tb, gpointer data)
623 GtkWidget *pmenu = gtk_menu_new();
626 if (strcmp(gtk_tool_button_get_icon_name(GTK_TOOL_BUTTON(tb)),
627 "network-receive") == 0) {
628 option = gtk_menu_item_new_with_label("Cancel download");
629 g_signal_connect(G_OBJECT(option), "activate",
630 G_CALLBACK(download_cancel), data);
632 option = gtk_menu_item_new_with_label("Remove download");
633 g_signal_connect(G_OBJECT(option), "activate",
634 G_CALLBACK(download_remove), data);
636 gtk_widget_show(option);
637 gtk_menu_shell_append(GTK_MENU_SHELL(pmenu), option);
639 option = gtk_menu_item_new_with_label("Copy download URL");
640 gtk_widget_show(option);
641 gtk_menu_shell_append(GTK_MENU_SHELL(pmenu), option);
642 g_signal_connect(G_OBJECT(option), "activate",
643 G_CALLBACK(download_copy_url), data);
645 option = gtk_menu_item_new_with_label("Copy local path");
646 gtk_widget_show(option);
647 gtk_menu_shell_append(GTK_MENU_SHELL(pmenu), option);
648 g_signal_connect(G_OBJECT(option), "activate",
649 G_CALLBACK(download_copy_path), data);
651 gtk_menu_popup_at_pointer(GTK_MENU(pmenu), NULL);
655 downloadmanager_delete(GtkWidget *obj, gpointer data)
657 if (!quit_if_nothing_active())
658 gtk_widget_hide(dm.win);
664 downloadmanager_setup(void)
666 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
667 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
668 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
669 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
670 g_signal_connect(G_OBJECT(dm.win), "delete-event",
671 G_CALLBACK(downloadmanager_delete), NULL);
672 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
673 G_CALLBACK(key_downloadmanager), NULL);
675 dm.toolbar = gtk_toolbar_new();
676 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
677 GTK_ORIENTATION_VERTICAL);
678 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
679 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
681 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
682 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
683 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
684 gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
686 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
690 ensure_uri_scheme(const gchar *t)
694 f = g_ascii_strdown(t, -1);
695 if (!g_str_has_prefix(f, "http:") &&
696 !g_str_has_prefix(f, "https:") &&
697 !g_str_has_prefix(f, "file:") &&
698 !g_str_has_prefix(f, "about:") &&
699 !g_str_has_prefix(f, "data:") &&
700 !g_str_has_prefix(f, "webkit:")) {
702 fabs = realpath(t, NULL);
704 f = g_strdup_printf("file://%s", fabs);
707 f = g_strdup_printf("http://%s", t);
717 cfg.accepted_language[0] = NULL;
718 cfg.accepted_language[1] = NULL;
719 cfg.cooperative_alone = TRUE;
720 cfg.cooperative_alone = TRUE;
721 cfg.fifo_suffix = "main";
723 const char *e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
725 cfg.fifo_suffix = g_strdup(e);
727 char *xdg_down = getenv("XDG_DOWNLOAD_DIR");
728 cfg.download_dir = (xdg_down) ? xdg_down : "/var/tmp";
731 cfg.accepted_language[0] = g_key_file_get_string(config, "browser",
732 "accepted_language", NULL);
733 cfg.history_file = g_key_file_get_string(config, "browser", "history_file",
735 cfg.home_uri = g_key_file_get_string(config, "browser", "homepage", NULL);
736 cfg.home_uri = (cfg.home_uri) ? cfg.home_uri : "about:blank";
737 cfg.enable_console_to_stdout = g_key_file_get_boolean(config, "browser",
740 cfg.user_agent = g_key_file_get_string(config, "browser", "user_agent", NULL);
741 cfg.javascript_disabled = g_key_file_get_boolean(config, "browser",
742 "javascript_disabled", NULL);
743 char *input_cookie_policy = g_key_file_get_string(config, "browser",
744 "cookie_policy", NULL);
745 cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
746 if (input_cookie_policy) {
747 if (strcmp(input_cookie_policy, "all") == 0) {
748 cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS;
749 } else if (strcmp(input_cookie_policy, "none") == 0) {
750 cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_NEVER;
754 cfg.tab_width_chars = g_key_file_get_integer(config, "ui", "tab_width", NULL);
755 cfg.tab_width_chars = (cfg.tab_width_chars) ? cfg.tab_width_chars : 20;
756 cfg.global_zoom = g_key_file_get_double(config, "ui", "zoom_level", NULL);
757 cfg.global_zoom = (cfg.global_zoom) ? cfg.global_zoom : 1.0;
758 cfg.search_engine = g_key_file_get_string(config, "ui", "search_engine",
760 cfg.search_engine = (cfg.search_engine) ? cfg.search_engine :
761 "https://duckduckgo.com?q=";
762 cfg.spellcheck_disabled = g_key_file_get_boolean(config, "ui",
763 "spellcheck_disabled", NULL);
764 cfg.spellcheck_language = g_key_file_get_string(config, "ui",
765 "spellcheck_language",
767 cfg.spellcheck_language = (cfg.spellcheck_language) ? cfg.spellcheck_language
772 grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data)
774 struct Client *c = (struct Client *)data;
775 WebKitJavascriptResult *js_result;
777 JSCException *exception;
781 g_free(c->feed_html);
784 /* This was taken almost verbatim from the example in WebKit's
787 * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript-finish */
789 js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object),
792 fprintf(stderr, __NAME__": Error running javascript: %s\n", err->message);
797 value = webkit_javascript_result_get_js_value(js_result);
798 if (jsc_value_is_string(value)) {
799 str_value = jsc_value_to_string(value);
800 exception = jsc_context_get_exception(jsc_value_get_context(value));
801 if (exception != NULL) {
802 fprintf(stderr, __NAME__": Error running javascript: %s\n",
803 jsc_exception_get_message(exception));
805 c->feed_html = str_value;
808 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
809 GTK_ENTRY_ICON_PRIMARY,
810 "application-rss+xml-symbolic");
811 gtk_entry_set_icon_activatable(GTK_ENTRY(c->location),
812 GTK_ENTRY_ICON_PRIMARY,
815 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
816 GTK_ENTRY_ICON_PRIMARY,
820 webkit_javascript_result_unref(js_result);
824 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
827 struct Client *c = (struct Client *)data;
830 g_free(c->hover_uri);
832 if (webkit_hit_test_result_context_is_link(ht)) {
833 to_show = webkit_hit_test_result_get_link_uri(ht);
834 c->hover_uri = g_strdup(to_show);
836 to_show = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
840 if (!gtk_widget_is_focus(c->location))
841 gtk_entry_set_text(GTK_ENTRY(c->location), to_show);
845 icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
848 struct Client *c = (struct Client *)data;
850 gchar *data_template =
855 " <meta charset=\"UTF-8\">"
856 " <title>Feeds</title>"
859 " <p>Feeds found on this page:</p>"
866 if (c->feed_html != NULL)
868 /* What we're actually trying to do is show a simple HTML page
869 * that lists all the feeds on the current page. The function
870 * webkit_web_view_load_html() looks like the proper way to do
871 * that. Sad thing is, it doesn't create a history entry, but
872 * instead simply replaces the content of the current page. This
873 * is not what we want.
875 * RFC 2397 [0] defines the data URI scheme [1]. We abuse this
876 * mechanism to show my custom HTML snippet *and* create a
879 * [0]: https://tools.ietf.org/html/rfc2397
880 * [1]: https://en.wikipedia.org/wiki/Data_URI_scheme */
881 d = g_strdup_printf(data_template, c->feed_html);
882 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), d);
888 init_default_web_context(void)
891 WebKitWebContext *wc;
892 WebKitCookieManager *cm;
894 wc = webkit_web_context_get_default();
896 p = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock", NULL);
897 webkit_web_context_set_sandbox_enabled(wc, TRUE);
898 webkit_web_context_add_path_to_sandbox(wc, p, TRUE);
901 webkit_web_context_set_process_model(wc,
902 WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
904 p = g_build_filename(g_get_user_data_dir(), __NAME__, "web_extensions",
906 webkit_web_context_set_web_extensions_directory(wc, p);
909 if (cfg.accepted_language[0] != NULL)
910 webkit_web_context_set_preferred_languages(wc, cfg.accepted_language);
912 g_signal_connect(G_OBJECT(wc), "download-started",
913 G_CALLBACK(download_start), NULL);
915 trust_user_certs(wc);
917 cm = webkit_web_context_get_cookie_manager(wc);
918 webkit_cookie_manager_set_accept_policy(cm, cfg.cookie_policy);
920 webkit_web_context_set_favicon_database_directory(wc, NULL);
921 webkit_cookie_manager_set_persistent_storage(cm,
922 g_build_filename("/",
923 g_get_user_cache_dir(),
927 WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
929 const gchar * const languages[2] = {(const gchar *)cfg.spellcheck_language,
931 webkit_web_context_set_spell_checking_languages(wc, languages);
932 webkit_web_context_set_spell_checking_enabled(wc, !cfg.spellcheck_disabled);
936 search(gpointer data, gint direction)
938 struct Client *c = (struct Client *)data;
939 WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
940 WebKitFindController *fc = webkit_web_view_get_find_controller(web_view);
942 if (search_text == NULL)
947 webkit_find_controller_search(fc, search_text,
948 WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
949 WEBKIT_FIND_OPTIONS_WRAP_AROUND,
953 webkit_find_controller_search_next(fc);
956 webkit_find_controller_search_previous(fc);
959 webkit_find_controller_search_finish(fc);
965 search_init(struct Client *c, int direction)
967 gtk_widget_grab_focus(c->location);
968 const gchar *contents = gtk_entry_get_text(GTK_ENTRY(c->location));
969 if (strcspn(contents, "s/")) {
970 gtk_entry_set_text(GTK_ENTRY(c->location), "s/");
972 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
975 search(c, direction);
979 def_key(char *key, unsigned int def)
981 char *conf = g_key_file_get_string(config, "keybindings", key, NULL);
982 return (conf) ? gdk_keyval_from_name((conf) ? conf : NULL) : def;
986 key_common(GtkWidget *widget, GdkEvent *event, gpointer data)
988 struct Client *c = (struct Client *)data;
992 if (event->type == GDK_KEY_PRESS) {
993 if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) {
994 WebKitSettings *settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
995 gboolean js = webkit_settings_get_enable_javascript(settings);
996 int key = ((GdkEventKey *)event)->keyval;
997 if (def_key("download_manager", GDK_KEY_y) == key) {
998 gtk_widget_show_all(dm.win);
1000 } else if (def_key("history_back", GDK_KEY_h) == key) {
1001 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
1003 } else if (def_key("history_forwards", GDK_KEY_l) == key) {
1004 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
1006 } else if (def_key("location", GDK_KEY_t) == key) {
1007 gtk_widget_grab_focus(c->location);
1008 const char *uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
1009 const char *goal = (uri) ? uri : "https://";
1010 gtk_entry_set_text(GTK_ENTRY(c->location), goal);
1011 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
1013 } else if (def_key("print", GDK_KEY_Print) == key) {
1014 webkit_print_operation_run_dialog(webkit_print_operation_new(WEBKIT_WEB_VIEW(c->web_view)),
1015 GTK_WINDOW(gtk_widget_get_toplevel(mw.win)));
1017 } else if (def_key("quit", GDK_KEY_g) == key) {
1019 gtk_widget_grab_focus(c->web_view);
1020 gtk_entry_set_text(GTK_ENTRY(c->location),
1021 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
1022 webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
1023 "window.getSelection().removeAllRanges();"
1024 "document.activeElement.blur();",
1027 } else if (def_key("reload", GDK_KEY_e) == key) {
1028 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(c->web_view));
1030 } else if (def_key("scroll_line_down", GDK_KEY_j) == key) {
1031 for (int i = 0; i < 2; i++) {
1032 event->key.keyval = GDK_KEY_Down;
1033 gdk_event_put(event);
1036 } else if (def_key("scroll_line_up", GDK_KEY_k) == key) {
1037 event->key.keyval = GDK_KEY_Up;
1038 gdk_event_put(event);
1040 } else if (def_key("scroll_page_down", GDK_KEY_f) == key) {
1041 event->key.keyval = GDK_KEY_Page_Down;
1042 gdk_event_put(event);
1044 } else if (def_key("scroll_page_up", GDK_KEY_b) == key) {
1045 event->key.keyval = GDK_KEY_Page_Up;
1046 gdk_event_put(event);
1048 } else if (def_key("search_forwards", GDK_KEY_s) == key) {
1051 } else if (def_key("search_backwards", GDK_KEY_r) == key) {
1054 } else if (def_key("tab_close", GDK_KEY_q) == key) {
1055 client_destroy(NULL, c);
1057 } else if (def_key("tab_switch_1", GDK_KEY_1) == key) {
1058 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 0);
1060 } else if (def_key("tab_switch_2", GDK_KEY_2) == key) {
1061 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 1);
1063 } else if (def_key("tab_switch_3", GDK_KEY_3) == key) {
1064 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 2);
1066 } else if (def_key("tab_switch_4", GDK_KEY_4) == key) {
1067 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 3);
1069 } else if (def_key("tab_switch_5", GDK_KEY_5) == key) {
1070 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 4);
1072 } else if (def_key("tab_switch_6", GDK_KEY_6) == key) {
1073 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 5);
1075 } else if (def_key("tab_switch_7", GDK_KEY_7) == key) {
1076 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 6);
1078 } else if (def_key("tab_switch_8", GDK_KEY_8) == key) {
1079 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 7);
1081 } else if (def_key("tab_switch_9", GDK_KEY_9) == key) {
1082 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), 8);
1084 } else if (def_key("tab_previous", GDK_KEY_u) == key) {
1085 gtk_notebook_prev_page(GTK_NOTEBOOK(mw.notebook));
1087 } else if (def_key("tab_new", GDK_KEY_w) == key) {
1088 f = ensure_uri_scheme(cfg.home_uri);
1089 client_new(f, NULL, TRUE, TRUE);
1092 } else if (def_key("tab_next", GDK_KEY_i) == key) {
1093 gtk_notebook_next_page(GTK_NOTEBOOK(mw.notebook));
1095 } else if (def_key("toggle_js", GDK_KEY_o) == key) {
1096 webkit_settings_set_enable_javascript(settings, (js) ? FALSE : TRUE);
1097 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), settings);
1099 } else if (def_key("web_search", GDK_KEY_d) == key) {
1100 gtk_widget_grab_focus(c->location);
1101 gtk_entry_set_text(GTK_ENTRY(c->location), "w/");
1102 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
1104 } else if (def_key("zoom_in", GDK_KEY_equal) == key) {
1105 now = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
1106 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), now + 0.1);
1108 } else if (def_key("zoom_out", GDK_KEY_minus) == key) {
1109 now = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
1110 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), now - 0.1);
1112 } else if (def_key("zoom_reset", GDK_KEY_0) == key) {
1113 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
1123 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
1125 if (event->type == GDK_KEY_PRESS) {
1126 if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) {
1127 int key = ((GdkEventKey *)event)->keyval;
1128 if ((def_key("close_tab", GDK_KEY_q) == key) ||
1129 (def_key("download_manager", GDK_KEY_y) == key)) {
1130 downloadmanager_delete(dm.win, NULL);
1140 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
1142 struct Client *c = (struct Client *)data;
1146 if (key_common(widget, event, data))
1149 if (event->type == GDK_KEY_PRESS) {
1150 int key = ((GdkEventKey *)event)->keyval;
1151 if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) {
1152 gtk_widget_grab_focus(c->web_view);
1153 t = gtk_entry_get_text(GTK_ENTRY(c->location));
1154 if (t != NULL && t[0] == 's' && t[1] == '/') {
1155 if (search_text != NULL)
1156 g_free(search_text);
1157 search_text = g_strdup(t + 2);
1159 } else if (t != NULL && t[0] == 'w' && t[1] == '/') {
1160 const char *engine = cfg.search_engine;
1161 int len = strlen(engine) + strlen(t) - 2;
1162 char *f = (char *) malloc(len);
1163 snprintf(f, len + 1, "%s%s", engine, t + 2);
1164 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
1167 f = ensure_uri_scheme(t);
1168 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
1172 } else if ((GDK_KEY_Escape == key) ||
1173 (def_key("quit", GDK_KEY_g) == key)) {
1174 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
1175 gtk_entry_set_text(GTK_ENTRY(c->location),
1176 (t == NULL ? __NAME__ : t));
1184 key_tablabel(GtkWidget *widget, GdkEvent *event, gpointer data)
1186 GdkScrollDirection direction;
1188 if (event->type == GDK_BUTTON_RELEASE) {
1189 switch (((GdkEventButton *)event)->button) {
1191 client_destroy(NULL, data);
1194 } else if (event->type == GDK_SCROLL) {
1195 gdk_event_get_scroll_direction(event, &direction);
1196 switch (direction) {
1198 gtk_notebook_prev_page(GTK_NOTEBOOK(mw.notebook));
1200 case GDK_SCROLL_DOWN:
1201 gtk_notebook_next_page(GTK_NOTEBOOK(mw.notebook));
1212 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
1214 struct Client *c = (struct Client *)data;
1218 if (key_common(widget, event, data))
1221 if (event->type == GDK_KEY_PRESS) {
1222 if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape) {
1223 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
1224 gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), 0);
1226 } else if (event->type == GDK_BUTTON_RELEASE) {
1227 switch (((GdkEventButton *)event)->button) {
1229 if (c->hover_uri != NULL) {
1230 client_new(c->hover_uri, NULL, TRUE, FALSE);
1235 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
1238 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
1241 } else if (event->type == GDK_SCROLL) {
1242 if (((GdkEventScroll *)event)->state & GDK_CONTROL_MASK ||
1243 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK) {
1244 gdk_event_get_scroll_deltas(event, &dx, &dy);
1245 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
1247 z = dx != 0 ? cfg.global_zoom : z;
1248 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
1257 mainwindow_setup(void)
1259 mw.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1260 gtk_window_set_default_size(GTK_WINDOW(mw.win), 800, 600);
1261 g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
1262 gtk_window_set_title(GTK_WINDOW(mw.win), __NAME__);
1264 mw.notebook = gtk_notebook_new();
1265 gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
1266 gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
1267 g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
1268 G_CALLBACK(notebook_switch_page), NULL);
1272 mainwindow_title(gint idx)
1274 GtkWidget *child, *widg, *tablabel;
1277 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
1281 widg = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
1282 tablabel = (GtkWidget *)g_object_get_data(G_OBJECT(widg), "lariza-tab-label");
1283 text = gtk_label_get_text(GTK_LABEL(tablabel));
1284 gtk_window_set_title(GTK_WINDOW(mw.win), text);
1288 notebook_switch_page(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
1290 mainwindow_title(idx);
1294 quit_if_nothing_active(void)
1297 if (downloads == 0) {
1301 gtk_widget_show_all(dm.win);
1309 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
1313 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
1316 client_new(uri, NULL, TRUE, TRUE);
1323 run_user_scripts(WebKitWebView *web_view)
1325 gchar *base = NULL, *path = NULL, *contents = NULL;
1326 const gchar *entry = NULL;
1327 GDir *scriptdir = NULL;
1329 base = g_build_filename(g_get_user_data_dir(), __NAME__, "user-scripts",
1331 scriptdir = g_dir_open(base, 0, NULL);
1332 if (scriptdir != NULL) {
1333 while ((entry = g_dir_read_name(scriptdir)) != NULL) {
1334 path = g_build_filename(base, entry, NULL);
1335 char *jscmd = malloc(strlen(path) + 36);
1336 sprintf(jscmd, "console.log(\"Running userscript %s\");", path);
1337 if (g_str_has_suffix(path, ".js")) {
1338 if (g_file_get_contents(path, &contents, NULL, NULL)) {
1339 webkit_web_view_run_javascript(web_view, jscmd, NULL, NULL, NULL);
1340 webkit_web_view_run_javascript(web_view, contents, NULL, NULL, NULL);
1347 g_dir_close(scriptdir);
1354 show_web_view(WebKitWebView *web_view, gpointer data)
1356 struct Client *c = (struct Client *)data;
1361 gtk_widget_show_all(mw.win);
1363 if (c->focus_new_tab) {
1364 idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
1366 gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), idx);
1368 gtk_widget_grab_focus(c->web_view);
1373 trust_user_certs(WebKitWebContext *wc)
1375 GTlsCertificate *cert;
1376 const gchar *basedir, *file, *absfile;
1379 basedir = g_build_filename(g_get_user_data_dir(), __NAME__, "certs", NULL);
1380 dir = g_dir_open(basedir, 0, NULL);
1382 file = g_dir_read_name(dir);
1383 while (file != NULL) {
1384 absfile = g_build_filename(g_get_user_data_dir(), __NAME__, "certs",
1387 cert = g_tls_certificate_new_from_file(absfile, NULL);
1389 fprintf(stderr, __NAME__": Could not load trusted cert '%s'\n", file);
1391 webkit_web_context_allow_tls_certificate_for_host(wc, cert, file);
1392 file = g_dir_read_name(dir);
1401 GKeyFileFlags flags = G_KEY_FILE_NONE;
1402 g_autoptr(GError) error = NULL;
1403 config = g_key_file_new();
1406 if (!g_key_file_load_from_file(config,
1407 g_build_filename(g_get_user_config_dir(),
1408 __NAME__, "lariza.ini",
1409 NULL), flags, &error)) {
1410 // Load global config
1411 if (!g_key_file_load_from_file(config, "/etc/lariza.ini", flags,
1413 fprintf(stderr, "Could not load lariza.ini: %s", error->message);
1420 main(int argc, char **argv)
1424 gtk_init(&argc, &argv);
1427 while ((opt = getopt(argc, argv, "C")) != -1) {
1430 cfg.cooperative_instances = FALSE;
1433 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
1438 if (cfg.cooperative_instances)
1439 cooperation_setup();
1441 if (!cfg.cooperative_instances || cfg.cooperative_alone)
1442 init_default_web_context();
1444 downloadmanager_setup();
1447 if (optind >= argc) {
1448 client_new(cfg.home_uri, NULL, TRUE, TRUE);
1450 for (i = optind; i < argc; i++)
1451 client_new(argv[i], NULL, TRUE, TRUE);
1454 if (!cfg.cooperative_instances || cfg.cooperative_alone)