gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_common(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_wsearch(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_isearch(GtkWidget *, GdkEvent *, gpointer);
+gboolean isearch_counted_matches(GtkWidget *, guint, gpointer);
gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
gchar *ensure_uri_scheme(const gchar *);
void changed_favicon(GObject *, GParamSpec *, gpointer);
struct Client {
GtkWidget *location;
- GtkWidget *search;
- GtkWidget *search_switch;
+ GtkWidget *wsearch;
GtkWidget *isearch;
+ GtkWidget *isearch_box;
+ GtkWidget *isearch_matches;
GtkWidget *tabicon;
GtkWidget *tablabel;
GtkWidget *vbox;
struct Client **client_arr;
int cooperative_pipe_fp = 0;
-gchar *search_text;
gchar *fifopath;
char **closed_tabs;
size_t num_closed = 0;
GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
c->location = gtk_entry_new();
- gtk_entry_set_placeholder_text(GTK_ENTRY(c->location), "Web address");
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->location), "URL");
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ "text-x-generic-symbolic");
gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 0);
- c->search = gtk_entry_new();
- gtk_entry_set_placeholder_text(GTK_ENTRY(c->search), "Search");
- gtk_box_pack_start(GTK_BOX(locbox), c->search, FALSE, TRUE, 0);
+ c->wsearch = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->wsearch), "Search the web");
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->wsearch),
+ GTK_ENTRY_ICON_PRIMARY,
+ "system-search-symbolic");
+ gtk_box_pack_start(GTK_BOX(locbox), c->wsearch, FALSE, TRUE, 0);
if (cfg.private) {
GtkWidget *privindicator = gtk_label_new("Private mode");
G_CALLBACK(key_location), c);
g_signal_connect(G_OBJECT(c->location), "icon-release",
G_CALLBACK(icon_location), c);
+ g_signal_connect(G_OBJECT(c->wsearch), "key-press-event",
+ G_CALLBACK(key_wsearch), c);
/*
- * XXX This is a workaround. Setting this to NULL (which is done in
- * grab_feeds_finished() if no feed has been detected) adds a little
- * padding left of the text. Not sure why. The point of this call
- * right here is to have that padding right from the start. This
- * avoids a graphical artifact.
- */
+ * XXX This is a workaround. Setting this to NULL (which is done in
+ * grab_feeds_finished() if no feed has been detected) adds a little
+ * padding left of the text. Not sure why. The point of this call
+ * right here is to have that padding right from the start. This
+ * avoids a graphical artifact.
+ */
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
GTK_ENTRY_ICON_SECONDARY, NULL);
+ c->isearch_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+ c->isearch = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->isearch), "Search page");
+ gtk_box_pack_start(GTK_BOX(c->isearch_box), c->isearch, FALSE, TRUE, 0);
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->isearch),
+ GTK_ENTRY_ICON_PRIMARY,
+ "system-search-symbolic");
+ g_signal_connect(G_OBJECT(c->isearch), "key-press-event",
+ G_CALLBACK(key_isearch), c);
+
+ c->isearch_matches = gtk_label_new("0 matches");
+ gtk_box_pack_start(GTK_BOX(c->isearch_box), c->isearch_matches, FALSE,
+ TRUE, 5);
+
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start(GTK_BOX(c->vbox), locbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0);
-
- GtkWidget *overlay = gtk_overlay_new();
- c->isearch = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(c->vbox), overlay);
- gtk_container_add(GTK_CONTAINER(overlay), c->isearch);
- gtk_widget_set_halign (overlay, GTK_ALIGN_CENTER);
- gtk_widget_set_valign (overlay, GTK_ALIGN_CENTER);
- gtk_widget_show_all(overlay);
+ gtk_box_pack_start(GTK_BOX(c->vbox), c->isearch_box, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(c->vbox), locbox, FALSE, FALSE, 0);
gtk_container_set_focus_child(GTK_CONTAINER(c->vbox), c->web_view);
gtk_widget_set_has_tooltip(c->tablabel, TRUE);
/*
- * XXX I don't own a HiDPI screen, so I don't know if scale_factor
- * does the right thing.
- */
+ * XXX I don't own a HiDPI screen, so I don't know if scale_factor
+ * does the right thing.
+ */
tabbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
5 * gtk_widget_get_scale_factor(mw.win));
gtk_box_pack_start(GTK_BOX(tabbox), c->tabicon, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(evbox), "scroll-event",
G_CALLBACK(key_tablabel), c);
- //For easy access, store a reference to our label.
+ // For easy access, store a reference to our label.
g_object_set_data(G_OBJECT(evbox), "chorizo-tab-label", c->tablabel);
/*
- * This only shows the event box and the label inside, nothing else.
- * Needed because the evbox/label is "internal" to the notebook and
- * not part of the normal "widget tree" (IIUC).
- */
+ * This only shows the event box and the label inside, nothing else.
+ * Needed because the evbox/label is "internal" to the notebook and
+ * not part of the normal "widget tree" (IIUC).
+ */
gtk_widget_show_all(evbox);
int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)) + 1;
client_arr[clients] = c;
- if (clients == 1 || uri == NULL) gtk_widget_grab_focus(c->location);
+ if (uri == NULL) gtk_widget_grab_focus(c->location);
return WEBKIT_WEB_VIEW(c->web_view);
}
} else {
if (write(cooperative_pipe_fp, "", 0) == -1) {
/*
- * Could not do an empty write to the FIFO which
- * means there's no one listening.
- */
+ * Could not do an empty write to the FIFO which
+ * means there's no one listening.
+ */
close(cooperative_pipe_fp);
towatch = g_io_channel_new_file(fifopath, "r+", NULL);
g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg,
p = 0;
/*
- * The page has loaded fully. We now run the short JavaScript
- * snippet above that operates on the DOM. It tries to grab
- * all occurences of <link rel="alternate" ...>, i.e.
- * RSS/Atom feed references.
- */
+ * The page has loaded fully. We now run the short JavaScript
+ * snippet above that operates on the DOM. It tries to grab
+ * all occurences of <link rel="alternate" ...>, i.e.
+ * RSS/Atom feed references.
+ */
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
grab_feeds, NULL,
grab_feeds_finished, c);
gchar *name = malloc(strlen(t) + 4);
if (!name) allocfail();
-
gboolean mute =
webkit_web_view_get_is_muted(WEBKIT_WEB_VIEW(c->web_view));
- gchar *muted = (mute) ? "[m] " : "";
+ gchar *muted = (mute) ? "[M] " : "";
sprintf(name, "%s%s", muted, t);
gtk_label_set_text(GTK_LABEL(c->tablabel), name);
g_free(name);
if (t != NULL && strlen(t) > 0) {
set_uri(t, c);
- //No g_get_user_state_dir unfortunately
+ // No g_get_user_state_dir unfortunately
gchar *state_env = getenv("XDG_STATE_DIR");
gchar *state_dir = (state_env) ?
state_env :
crashed_web_view(WebKitWebView *web_view, gpointer data)
{
struct Client *c = (struct Client *)data;
+
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
GtkWidget *dialog = gtk_message_dialog_new(
- GTK_WINDOW(c->vbox), flags, GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE, "ERROR: Web process %s crashed.",
+ GTK_WINDOW(mw.win), flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "ERROR: Web process %s crashed.\n%s",
webkit_web_view_get_uri(WEBKIT_WEB_VIEW(web_view)),
g_strerror(errno));
gtk_dialog_run(GTK_DIALOG(dialog));
return TRUE;
}
+
gboolean
decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
WebKitPolicyDecisionType type, gpointer data)
webkit_policy_decision_use(decision);
break;
default:
- //Use whatever default there is.
+ // Use whatever default there is.
return FALSE;
}
return TRUE;
c->feed_html = NULL;
/*
- * This was taken almost verbatim from the example in WebKit's
- * documentation:
- *
- * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
- */
+ * This was taken almost verbatim from the example in WebKit's
+ * documentation:
+ *
+ * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
+ */
js_result = webkit_web_view_run_javascript_finish(
WEBKIT_WEB_VIEW(object), result, &err);
"</html>";
if (c->feed_html != NULL) {
/*
- * What we're actually trying to do is show a simple HTML
- * page that lists all the feeds on the current page. The
- * function webkit_web_view_load_html() looks like the proper
- * way to do that. Sad thing is, it doesn't create a history
- * entry, but instead simply replaces the content of the
- * current page. This is not what we want.
- *
- * RFC 2397 [0] defines the data URI scheme [1]. We abuse this
- * mechanism to show my custom HTML snippet* and*create a
- * history entry.
- *
- * [0]: https://tools.ietf.org/html/rfc2397 [1]:
- * https://en.wikipedia.org/wiki/Data_URI_scheme
- */
+ * What we're actually trying to do is show a simple HTML
+ * page that lists all the feeds on the current page. The
+ * function webkit_web_view_load_html() looks like the proper
+ * way to do that. Sad thing is, it doesn't create a history
+ * entry, but instead simply replaces the content of the
+ * current page. This is not what we want.
+ *
+ * RFC 2397 [0] defines the data URI scheme [1]. We abuse this
+ * mechanism to show my custom HTML snippet* and*create a
+ * history entry.
+ *
+ * [0]: https://tools.ietf.org/html/rfc2397 [1]:
+ * https://en.wikipedia.org/wiki/Data_URI_scheme
+ */
d = g_strdup_printf(data_template, c->feed_html);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), d);
}
void
-search(gpointer data, gint direction)
+isearch(gpointer data, gint direction)
{
struct Client *c = (struct Client *)data;
WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
WebKitFindController *fc =
webkit_web_view_get_find_controller(web_view);
- if (search_text == NULL) return;
+ const gchar *isearch_text = gtk_entry_get_text(GTK_ENTRY(c->isearch));
+ if (isearch_text == NULL) return;
switch (direction) {
case 0:
- webkit_find_controller_search(
- fc, search_text,
- WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
- WEBKIT_FIND_OPTIONS_WRAP_AROUND,
- G_MAXUINT);
+ g_signal_connect(G_OBJECT(fc), "counted-matches",
+ G_CALLBACK(isearch_counted_matches), c);
+ webkit_find_controller_count_matches(
+ fc, isearch_text, cfg_isearch_options, G_MAXUINT);
+ webkit_find_controller_search(fc, isearch_text,
+ cfg_isearch_options, G_MAXUINT);
break;
case 1:
webkit_find_controller_search_next(fc);
}
void
-search_init(struct Client *c, int direction)
+isearch_init(struct Client *c, int direction)
{
- gtk_widget_grab_focus(c->location);
- const gchar *contents = gtk_entry_get_text(GTK_ENTRY(c->location));
- if (strcspn(contents, "s/")) {
- gtk_entry_set_text(GTK_ENTRY(c->location), "s/");
- gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
- } else {
- search(c, 0);
- search(c, -1);
- search(c, direction);
+ if (webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view))) {
+ gtk_widget_show(c->isearch_box);
+ gtk_widget_show(c->isearch);
+ gtk_widget_grab_focus(c->isearch);
}
}
+void
+reopen_tab(void)
+{
+ if (num_closed == 0) return;
+ client_new(closed_tabs[num_closed - 1], NULL, TRUE, TRUE);
+ num_closed--;
+ closed_tabs = realloc(closed_tabs, num_closed * sizeof(closed_tabs[0]));
+ if (!closed_tabs) allocfail();
+}
gboolean
key_common(GtkWidget *widget, GdkEvent *event, gpointer data)
{
struct Client *c = (struct Client *)data;
gdouble now;
if (event->type == GDK_KEY_PRESS) {
- if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) {
+ guint mask = gtk_accelerator_get_default_mod_mask();
+ int key = ((GdkEventKey *)event)->keyval;
+ if ((((GdkEventKey *)event)->state & mask) ==
+ GDK_CONTROL_MASK) {
const char *uri = webkit_web_view_get_uri(
WEBKIT_WEB_VIEW(c->web_view));
- int key = ((GdkEventKey *)event)->keyval;
if (GDK_KEY_y == key) {
downloadmanager_show();
return TRUE;
webkit_web_view_go_forward(
WEBKIT_WEB_VIEW(c->web_view));
return TRUE;
- } else if (GDK_KEY_o == key) {
+ } else if (GDK_KEY_s == key) {
gtk_widget_grab_focus(c->location);
return TRUE;
- } else if (GDK_KEY_Print == key) {
+ } else if (GDK_KEY_p == key) {
WebKitPrintOperation *operation =
webkit_print_operation_new(
WEBKIT_WEB_VIEW(c->web_view));
operation, GTK_WINDOW(toplevel));
return TRUE;
} else if (GDK_KEY_g == key) {
- search(c, 2);
+ isearch(c, 2);
gtk_widget_grab_focus(c->web_view);
- gtk_editable_set_position(
- GTK_EDITABLE(c->location), -1);
if (uri)
gtk_entry_set_text(
GTK_ENTRY(c->location), uri);
"window.getSelection().removeAllRanges();"
"document.activeElement.blur();",
NULL, NULL, c);
+ gtk_widget_hide(c->isearch_box);
+ gtk_editable_set_position(
+ GTK_EDITABLE(c->location), -1);
+ gtk_editable_set_position(
+ GTK_EDITABLE(c->wsearch), -1);
return TRUE;
- } else if (GDK_KEY_semicolon == key) {
+ } else if (GDK_KEY_r == key) {
webkit_web_view_reload_bypass_cache(
WEBKIT_WEB_VIEW(c->web_view));
return TRUE;
}
return TRUE;
} else if (GDK_KEY_f == key) {
- event->key.keyval = GDK_KEY_Page_Down;
- gdk_event_put(event);
- return TRUE;
- } else if (GDK_KEY_b == key) {
- event->key.keyval = GDK_KEY_Page_Up;
- gdk_event_put(event);
- return TRUE;
- } else if (GDK_KEY_s == key) {
- search_init(c, 1);
- return TRUE;
- } else if (GDK_KEY_r == key) {
- search_init(c, -1);
- return TRUE;
+ isearch_init(c, 1);
+ return FALSE;
} else if (GDK_KEY_q == key) {
client_destroy(NULL, c);
return TRUE;
client_new(cfg_home_uri, NULL, TRUE, TRUE);
return TRUE;
} else if (GDK_KEY_bracketleft == key) {
- if (num_closed == 0) return TRUE;
- client_new(closed_tabs[num_closed - 1], NULL,
- TRUE, TRUE);
- num_closed--;
- closed_tabs = realloc(
- closed_tabs,
- num_closed * sizeof(closed_tabs[0]));
- if (!closed_tabs) allocfail();
+ reopen_tab();
return TRUE;
- } else if (GDK_KEY_i == key) {
+ } else if ((GDK_KEY_i == key) || (GDK_KEY_Tab == key)) {
gtk_notebook_next_page(
GTK_NOTEBOOK(mw.notebook));
return TRUE;
} else if (GDK_KEY_d == key) {
- gtk_widget_grab_focus(c->location);
- gtk_entry_set_text(GTK_ENTRY(c->location),
- "w/");
- gtk_editable_set_position(
- GTK_EDITABLE(c->location), -1);
+ gtk_widget_grab_focus(c->wsearch);
return TRUE;
} else if (GDK_KEY_equal == key) {
now = webkit_web_view_get_zoom_level(
WEBKIT_WEB_VIEW(c->web_view), 1);
return TRUE;
}
+ } else if ((((GdkEventKey *)event)->state & mask) ==
+ (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) {
+ if (GDK_KEY_ISO_Left_Tab == key) {
+ gtk_notebook_prev_page(
+ GTK_NOTEBOOK(mw.notebook));
+ return TRUE;
+ } else if (GDK_KEY_T == key) {
+ reopen_tab();
+ return TRUE;
+ }
}
}
return FALSE;
}
+
+gboolean
+isearch_counted_matches(GtkWidget *widget, guint matches, gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ char *text = malloc(12);
+ sprintf(text, "%d matches", matches);
+ gtk_label_set_text(GTK_LABEL(c->isearch_matches), text);
+ free(text);
+ return TRUE;
+}
+
+gboolean
+key_isearch(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ if (key_common(widget, event, data)) return TRUE;
+
+ if (event->type == GDK_KEY_PRESS) {
+ int key = ((GdkEventKey *)event)->keyval;
+ if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) {
+ int direction = (((GdkEventKey *)event)->state &
+ GDK_SHIFT_MASK) ?
+ -1 :
+ 1;
+ isearch(c, 0);
+ isearch(c, -1);
+ isearch(c, direction);
+ return TRUE;
+ } else if (GDK_KEY_Escape == key) {
+ isearch(c, 2);
+ gtk_widget_hide(c->isearch_box);
+ gtk_widget_grab_focus(c->web_view);
+ }
+ }
+ return FALSE;
+}
+
+gboolean
+key_wsearch(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ if (key_common(widget, event, data)) return TRUE;
+
+ if (event->type == GDK_KEY_PRESS) {
+ int key = ((GdkEventKey *)event)->keyval;
+ if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) {
+ const gchar *t =
+ gtk_entry_get_text(GTK_ENTRY(c->wsearch));
+ int len = strlen(cfg_search_engine) + strlen(t);
+ gchar *f = malloc(len + 1);
+ if (!f) allocfail();
+
+ snprintf(f, len + 1, "%s%s", cfg_search_engine, t);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view),
+ f);
+ g_free(f);
+ gtk_widget_grab_focus(c->web_view);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
gboolean
key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
{
if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) {
gtk_widget_grab_focus(c->web_view);
t = gtk_entry_get_text(GTK_ENTRY(c->location));
- if (t != NULL && t[0] == 's' && t[1] == '/') {
- if (search_text != NULL) g_free(search_text);
- search_text = g_strdup(t + 2);
- search(c, 0);
- } else if (t != NULL && t[0] == 'w' && t[1] == '/') {
- int len = strlen(cfg_search_engine) +
- strlen(t) - 2;
- gchar *f = malloc(len + 1);
- if (!f) allocfail();
- snprintf(f, len + 1, "%s%s", cfg_search_engine,
- t + 2);
- webkit_web_view_load_uri(
- WEBKIT_WEB_VIEW(c->web_view), f);
- g_free(f);
- } else {
- webkit_web_view_load_uri(
- WEBKIT_WEB_VIEW(c->web_view),
- ensure_uri_scheme(t));
- }
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view),
+ ensure_uri_scheme(t));
return TRUE;
} else if (GDK_KEY_Escape == key) {
t = webkit_web_view_get_uri(
struct Client *c = (struct Client *)data;
gdouble dx, dy;
gfloat z;
- if (key_common(widget, event, data)) return TRUE;
+ if (key_common(c->web_view, event, data)) return TRUE;
if (event->type == GDK_KEY_PRESS) {
if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape) {
gtk_widget_show_all(mw.win);
+ // TODO: Fix this hack
+ for (int i = 1; i <= clients; i++)
+ gtk_widget_hide(client_arr[i]->isearch_box);
+ gtk_widget_hide(c->isearch_box);
+
if (c->focus_new_tab) {
idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
if (idx != -1)
{
int opt, i;
- //TODO:pretty this
+ // TODO:pretty this
cfg.noncooperative_instances = FALSE;
cfg.cooperative_alone = TRUE;
closed_tabs = malloc(0);
GtkToolItem *tb;
GtkWidget *chooser = gtk_file_chooser_dialog_new(
- "Choose download location", GTK_WINDOW(dm.win),
- GTK_FILE_CHOOSER_ACTION_SAVE, "Save file", GTK_RESPONSE_ACCEPT,
- "Cancel", GTK_RESPONSE_CANCEL, NULL);
+ "Save File", GTK_WINDOW(dm.win), GTK_FILE_CHOOSER_ACTION_SAVE,
+ "Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT,
+ NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
(char *)data);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser),
gtk_file_chooser_set_do_overwrite_confirmation(
GTK_FILE_CHOOSER(chooser), TRUE);
gint res = gtk_dialog_run(GTK_DIALOG(chooser));
- switch (res) {
- case GTK_RESPONSE_ACCEPT:
+
+ if (res != GTK_RESPONSE_ACCEPT) {
+ gtk_widget_destroy(chooser);
+ } else {
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(chooser));
- webkit_download_set_destination(
- download,
- gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(chooser)));
- break;
- case GTK_RESPONSE_CANCEL:
- return FALSE;
- default:
- return FALSE;
+ webkit_download_set_destination(download, uri);
+
+ remove(uri + 7); // Remove before overwrite
+
+ gtk_widget_destroy(chooser);
+
+ tb = gtk_tool_button_new(NULL, NULL);
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb),
+ "network-receive");
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), uri);
+ gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
+ gtk_widget_show_all(dm.win);
+
+ g_signal_connect(G_OBJECT(download),
+ "notify::estimated-progress",
+ G_CALLBACK(changed_download_progress), tb);
+
+ downloads++;
+ g_signal_connect(G_OBJECT(download), "finished",
+ G_CALLBACK(download_finished), tb);
+
+ g_object_ref(download);
+
+ struct DownloadItem *payload = malloc(sizeof(*payload));
+ payload->tb = (GtkToolButton *)tb;
+ payload->download = download;
+ g_signal_connect(G_OBJECT(tb), "clicked",
+ G_CALLBACK(download_click), payload);
+ g_signal_connect(G_OBJECT(payload->download), "failed",
+ G_CALLBACK(download_cancel), payload);
+ g_signal_connect(G_OBJECT(tb), "destroy_event",
+ G_CALLBACK(g_free), payload);
}
-
- gtk_widget_destroy(chooser);
-
- remove(uri + 7); // Remove before overwrite
- tb = gtk_tool_button_new(NULL, NULL);
- gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "network-receive");
- gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), uri);
- gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
- gtk_widget_show_all(dm.win);
-
- g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
- G_CALLBACK(changed_download_progress), tb);
-
- downloads++;
- g_signal_connect(G_OBJECT(download), "finished",
- G_CALLBACK(download_finished), tb);
-
- g_object_ref(download);
-
- struct DownloadItem *payload = malloc(sizeof(*payload));
- payload->tb = (GtkToolButton *)tb;
- payload->download = download;
- g_signal_connect(G_OBJECT(tb), "clicked", G_CALLBACK(download_click),
- payload);
- g_signal_connect(G_OBJECT(tb), "failed", G_CALLBACK(download_cancel),
- payload);
- g_signal_connect(G_OBJECT(tb), "destroy_event", G_CALLBACK(g_free),
- payload);
-
- //Propagate-- to whom it may concern.
return FALSE;
}