10 #include <gdk/gdkkeysyms.h>
12 #include <webkit2/webkit2.h>
15 static void client_destroy(GtkWidget *, gpointer);
16 static gboolean client_destroy_request(WebKitWebView *, gpointer);
17 static WebKitWebView *client_new(const gchar *);
18 static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
20 static void cooperation_setup(void);
21 static void changed_download_progress(GObject *, GParamSpec *, gpointer);
22 static void changed_load_progress(GObject *, GParamSpec *, gpointer);
23 static void changed_title(GObject *, GParamSpec *, gpointer);
24 static void changed_uri(GObject *, GParamSpec *, gpointer);
25 static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
26 WebKitPolicyDecisionType, gpointer);
27 static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
28 static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
29 static gboolean download_reset_indicator(gpointer);
30 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
31 static void downloadmanager_setup(void);
32 static gchar *ensure_uri_scheme(const gchar *);
33 static void grab_environment_configuration(void);
34 static void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
35 static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
36 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
37 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
38 static void keywords_load(void);
39 static gboolean keywords_try_search(WebKitWebView *, const gchar *);
40 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
41 static void search(gpointer, gint);
42 static Window tabbed_launch(void);
43 static void usage(void);
59 struct DownloadManager
67 static gchar *accepted_language = "en-US";
68 static gint clients = 0;
69 static gboolean cooperative_alone = TRUE;
70 static gboolean cooperative_instances = TRUE;
71 static int cooperative_pipe_fp = 0;
72 static gchar *download_dir = "/tmp";
73 static gint downloads_indicated = 0;
74 static Window embed = 0;
75 static gchar *fifo_suffix = "main";
76 static gdouble global_zoom = 1.0;
77 static gchar *home_uri = "about:blank";
78 static GHashTable *keywords = NULL;
79 static gboolean language_is_set = FALSE;
80 static gchar *search_text = NULL;
81 static gboolean show_all_requests = FALSE;
82 static gboolean tabbed_automagic = TRUE;
83 static gchar *user_agent = "Mozilla/5.0 (X11; U; Unix; en-US) "
84 "AppleWebKit/537.15 (KHTML, like Gecko) "
86 "Safari/537.15 "__NAME_CAPITALIZED__"/git";
90 client_destroy(GtkWidget *obj, gpointer data)
92 struct Client *c = (struct Client *)data;
94 g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
95 changed_load_progress, c);
105 client_destroy_request(WebKitWebView *web_view, gpointer data)
107 struct Client *c = (struct Client *)data;
109 gtk_widget_destroy(c->win);
115 client_new(const gchar *uri)
118 WebKitWebContext *wc;
121 if (uri != NULL && cooperative_instances && !cooperative_alone)
123 write(cooperative_pipe_fp, uri, strlen(uri));
124 write(cooperative_pipe_fp, "\n", 1);
128 c = malloc(sizeof(struct Client));
131 fprintf(stderr, __NAME__": fatal: malloc failed\n");
139 c->win = gtk_plug_new(embed);
140 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
142 fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
143 gtk_widget_destroy(c->win);
151 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
152 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
155 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
156 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
158 c->web_view = webkit_web_view_new();
159 wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
161 /* XXX I really do want to enable this option. However, I get
162 * reproducible crashes with it enabled. I've seen bug reports from
163 * 2010 about this... WebKit crashes in libpixman, so maybe it's not
165 * Yeah, well. I'll turn it off for now. */
166 /*webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(c->web_view), TRUE);*/
168 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
169 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
170 G_CALLBACK(changed_title), c);
171 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
172 G_CALLBACK(changed_uri), c);
173 g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
174 G_CALLBACK(changed_load_progress), c);
175 g_signal_connect(G_OBJECT(c->web_view), "create",
176 G_CALLBACK(client_new_request), NULL);
177 g_signal_connect(G_OBJECT(c->web_view), "close",
178 G_CALLBACK(client_destroy_request), c);
179 g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
180 G_CALLBACK(decide_policy), NULL);
181 g_signal_connect(G_OBJECT(wc), "download-started",
182 G_CALLBACK(download_handle_start), c);
183 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
184 G_CALLBACK(key_web_view), c);
185 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
186 G_CALLBACK(key_web_view), c);
187 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
188 G_CALLBACK(key_web_view), c);
189 g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
190 G_CALLBACK(hover_web_view), c);
192 if (!language_is_set)
194 /* XXX make this pretty */
195 const gchar *languages[2];
196 languages[0] = accepted_language;
198 webkit_web_context_set_preferred_languages(wc, languages);
199 language_is_set = TRUE;
203 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
204 "user-agent", user_agent, NULL);
207 c->scroll = gtk_scrolled_window_new(NULL, NULL);
209 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
211 c->location = gtk_entry_new();
212 g_signal_connect(G_OBJECT(c->location), "key-press-event",
213 G_CALLBACK(key_location), c);
215 /* XXX Progress bars don't work/look as intended anymore. Level bars
216 * are a dirty workaround (kind of). */
217 c->progress = gtk_level_bar_new();
218 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
219 gtk_widget_set_size_request(c->progress, 100, -1);
221 c->status = gtk_level_bar_new();
222 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
223 gtk_widget_set_size_request(c->status, 20, -1);
225 c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
226 gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
227 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
228 gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
230 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
231 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
232 gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 2);
234 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
236 gtk_widget_grab_focus(c->web_view);
237 gtk_widget_show_all(c->win);
241 f = ensure_uri_scheme(uri);
242 if (show_all_requests)
243 fprintf(stderr, "====> %s\n", uri);
244 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
250 return WEBKIT_WEB_VIEW(c->web_view);
254 client_new_request(WebKitWebView *web_view,
255 WebKitNavigationAction *navigation_action, gpointer data)
257 return client_new(NULL);
261 cooperation_setup(void)
264 gchar *fifofilename, *fifopath;
266 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
267 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
268 g_free(fifofilename);
270 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
271 mkfifo(fifopath, 0600);
273 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
274 if (!cooperative_pipe_fp)
276 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
280 if (write(cooperative_pipe_fp, "", 0) == -1)
282 /* Could not do an empty write to the FIFO which means there's
283 * no one listening. */
284 close(cooperative_pipe_fp);
285 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
286 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
289 cooperative_alone = FALSE;
296 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
298 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
299 WebKitURIResponse *resp;
300 GtkToolItem *tb = GTK_TOOL_ITEM(data);
303 gchar *t, *filename, *base;
305 p = webkit_download_get_estimated_progress(download) * 100;
306 resp = webkit_download_get_response(download);
307 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
309 uri = webkit_download_get_destination(download);
310 filename = g_filename_from_uri(uri, NULL, NULL);
311 if (filename == NULL)
313 /* This really should not happen because WebKit uses that URI to
314 * write to a file... */
315 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
316 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
317 webkit_uri_response_get_uri(resp), p, size_mb);
321 base = g_path_get_basename(filename);
322 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
326 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
331 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
333 struct Client *c = (struct Client *)data;
336 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
337 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
341 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
344 struct Client *c = (struct Client *)data;
346 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
347 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
351 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
354 struct Client *c = (struct Client *)data;
356 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
357 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
361 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
362 WebKitPolicyDecisionType type, gpointer data)
364 WebKitResponsePolicyDecision *r;
368 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
369 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
370 if (!webkit_response_policy_decision_is_mime_type_supported(r))
371 webkit_policy_decision_download(decision);
373 webkit_policy_decision_use(decision);
376 /* Use whatever default there is. */
383 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
386 g_signal_connect(G_OBJECT(download), "decide-destination",
387 G_CALLBACK(download_handle), data);
391 download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
393 struct Client *c = (struct Client *)data;
394 gchar *path, *path2 = NULL, *uri;
398 path = g_build_filename(download_dir, suggested_filename, NULL);
399 path2 = g_strdup(path);
400 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
404 path2 = g_strdup_printf("%s.%d", path, suffix);
410 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
411 webkit_download_cancel(download);
415 uri = g_filename_to_uri(path2, NULL, NULL);
416 webkit_download_set_destination(download, uri);
419 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 1);
420 downloads_indicated++;
421 g_timeout_add(500, download_reset_indicator, c);
423 tb = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
424 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
425 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
426 gtk_widget_show_all(dm.toolbar);
428 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
429 G_CALLBACK(changed_download_progress), tb);
431 g_object_ref(download);
432 g_signal_connect(G_OBJECT(tb), "clicked",
433 G_CALLBACK(downloadmanager_cancel), download);
439 /* Propagate -- to whom it may concern. */
444 download_reset_indicator(gpointer data)
446 struct Client *c = (struct Client *)data;
448 downloads_indicated--;
449 if (downloads_indicated == 0)
450 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
456 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
458 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
460 webkit_download_cancel(download);
461 g_object_unref(download);
463 gtk_widget_destroy(GTK_WIDGET(tb));
467 downloadmanager_setup(void)
469 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
470 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
471 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
472 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
473 g_signal_connect(G_OBJECT(dm.win), "delete-event",
474 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
475 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
476 G_CALLBACK(key_downloadmanager), NULL);
478 dm.toolbar = gtk_toolbar_new();
479 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
480 GTK_ORIENTATION_VERTICAL);
481 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
482 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
484 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
485 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
486 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
487 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(dm.scroll),
490 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
494 ensure_uri_scheme(const gchar *t)
498 f = g_ascii_strdown(t, -1);
499 if (!g_str_has_prefix(f, "http:") &&
500 !g_str_has_prefix(f, "https:") &&
501 !g_str_has_prefix(f, "file:") &&
502 !g_str_has_prefix(f, "about:"))
505 f = g_strdup_printf("http://%s", t);
513 grab_environment_configuration(void)
517 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
519 accepted_language = g_strdup(e);
521 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
523 download_dir = g_strdup(e);
525 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
527 fifo_suffix = g_strdup(e);
529 e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
531 home_uri = g_strdup(e);
533 e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
535 user_agent = g_strdup(e);
537 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
539 global_zoom = atof(e);
543 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
546 struct Client *c = (struct Client *)data;
548 if (!gtk_widget_is_focus(c->location))
550 if (webkit_hit_test_result_context_is_link(ht))
552 gtk_entry_set_text(GTK_ENTRY(c->location),
553 webkit_hit_test_result_get_link_uri(ht));
555 if (c->hover_uri != NULL)
556 g_free(c->hover_uri);
557 c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht));
561 gtk_entry_set_text(GTK_ENTRY(c->location),
562 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
564 if (c->hover_uri != NULL)
565 g_free(c->hover_uri);
572 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
574 if (event->type == GDK_KEY_PRESS)
576 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
578 switch (((GdkEventKey *)event)->keyval)
580 case GDK_KEY_d: /* close window (left hand) */
581 gtk_widget_hide(dm.win);
591 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
593 struct Client *c = (struct Client *)data;
597 if (event->type == GDK_KEY_PRESS)
599 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
601 switch (((GdkEventKey *)event)->keyval)
603 case GDK_KEY_q: /* close window (left hand) */
604 gtk_widget_destroy(c->win);
606 case GDK_KEY_d: /* download manager (left hand) */
607 gtk_widget_show_all(dm.win);
609 case GDK_KEY_r: /* reload (left hand) */
610 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
613 case GDK_KEY_k: /* initiate search (BOTH hands) */
614 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
615 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
621 switch (((GdkEventKey *)event)->keyval)
624 gtk_widget_grab_focus(c->web_view);
625 t = gtk_entry_get_text(GTK_ENTRY(c->location));
626 if (t != NULL && t[0] == '/')
628 if (search_text != NULL)
630 search_text = g_strdup(t + 1); /* XXX whacky */
633 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
635 f = ensure_uri_scheme(t);
636 if (show_all_requests)
637 fprintf(stderr, "====> %s\n", f);
638 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
643 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
644 gtk_entry_set_text(GTK_ENTRY(c->location),
645 (t == NULL ? __NAME__ : t));
655 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
657 struct Client *c = (struct Client *)data;
662 if (event->type == GDK_KEY_PRESS)
664 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
666 switch (((GdkEventKey *)event)->keyval)
668 case GDK_KEY_q: /* close window (left hand) */
669 gtk_widget_destroy(c->win);
671 case GDK_KEY_w: /* home (left hand) */
672 f = ensure_uri_scheme(home_uri);
673 if (show_all_requests)
674 fprintf(stderr, "====> %s\n", f);
675 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
678 case GDK_KEY_e: /* new tab (left hand) */
679 f = ensure_uri_scheme(home_uri);
680 if (show_all_requests)
681 fprintf(stderr, "====> %s\n", f);
685 case GDK_KEY_r: /* reload (left hand) */
686 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
690 case GDK_KEY_s: /* toggle source view (left hand) */
691 b = webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(
694 webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(
696 webkit_web_view_reload(WEBKIT_WEB_VIEW(c->web_view));
699 case GDK_KEY_d: /* download manager (left hand) */
700 gtk_widget_show_all(dm.win);
702 case GDK_KEY_2: /* search forward (left hand) */
703 case GDK_KEY_n: /* search forward (maybe both hands) */
706 case GDK_KEY_3: /* search backward (left hand) */
709 case GDK_KEY_l: /* location (BOTH hands) */
710 gtk_widget_grab_focus(c->location);
712 case GDK_KEY_k: /* initiate search (BOTH hands) */
713 gtk_widget_grab_focus(c->location);
714 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
715 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
719 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
721 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
722 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
725 else if (event->type == GDK_BUTTON_PRESS)
727 switch (((GdkEventButton *)event)->button)
730 if (c->hover_uri != NULL)
732 client_new(c->hover_uri);
737 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
740 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
744 else if (event->type == GDK_SCROLL)
746 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
747 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
749 switch (((GdkEventScroll *)event)->direction)
752 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
754 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
756 case GDK_SCROLL_DOWN:
757 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
759 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
774 GIOChannel *channel = NULL;
775 gchar *path = NULL, *buf = NULL;
776 gchar **tokens = NULL;
778 keywords = g_hash_table_new(g_str_hash, g_str_equal);
780 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
782 channel = g_io_channel_new_file(path, "r", &err);
785 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
786 == G_IO_STATUS_NORMAL)
791 tokens = g_strsplit(buf, " ", 2);
792 if (tokens[0] != NULL && tokens[1] != NULL)
793 g_hash_table_insert(keywords, g_strdup(tokens[0]),
794 g_strdup(tokens[1]));
799 g_io_channel_shutdown(channel, FALSE, NULL);
805 keywords_try_search(WebKitWebView *web_view, const gchar *t)
807 gboolean ret = FALSE;
808 gchar **tokens = NULL;
809 gchar *val = NULL, *uri = NULL;
811 tokens = g_strsplit(t, " ", 2);
812 if (tokens[0] != NULL && tokens[1] != NULL)
814 val = g_hash_table_lookup(keywords, tokens[0]);
817 uri = g_strdup_printf((gchar *)val, tokens[1]);
818 if (show_all_requests)
819 fprintf(stderr, "====> %s\n", uri);
820 webkit_web_view_load_uri(web_view, uri);
831 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
835 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
846 search(gpointer data, gint direction)
848 struct Client *c = (struct Client *)data;
850 if (search_text == NULL)
854 webkit_web_view_search_text(WEBKIT_WEB_VIEW(c->web_view), search_text,
855 FALSE, direction == 1, TRUE);
863 GIOChannel *tabbed_stdout_channel;
865 gchar *output = NULL;
866 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
869 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
870 NULL, NULL, NULL, &tabbed_stdout, NULL,
873 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
878 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
879 if (tabbed_stdout_channel == NULL)
881 fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
884 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
885 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
888 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
892 plug_into = strtol(output, NULL, 16);
895 fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
902 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
908 main(int argc, char **argv)
912 gtk_init(&argc, &argv);
914 grab_environment_configuration();
916 while ((opt = getopt(argc, argv, "e:rCT")) != -1)
921 embed = atol(optarg);
922 tabbed_automagic = FALSE;
925 show_all_requests = TRUE;
928 cooperative_instances = FALSE;
931 tabbed_automagic = FALSE;
940 downloadmanager_setup();
942 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
943 embed = tabbed_launch();
946 client_new(home_uri);
949 for (i = optind; i < argc; i++)
953 if (!cooperative_instances || cooperative_alone)