📄 interface.c
字号:
if ( Op ){ struct stat st; fflush(Web->stream); fstat(fileno(Web->stream), &st); fclose(Web->stream); a_Interface_msg(Web->bw, "File saved (%d Bytes)", st.st_size); } else { if ( (Bytes = Client->BufSize - Web->SavedBytes) > 0 ) { Bytes = fwrite(Client->Buf + Web->SavedBytes, 1, Bytes, Web->stream); Web->SavedBytes += Bytes; } }}#endif/* * Save current page to a local file */#if 0static void Interface_file_save_url(GtkWidget *widget, BrowserWindow *bw){ const char *name; GtkFileSelection *choosefile; GtkEntry *entry_url; DilloUrl *url; FILE *out; choosefile = GTK_FILE_SELECTION(bw->save_dialog_window); entry_url = GTK_ENTRY(bw->location); name = gtk_file_selection_get_filename(choosefile); url = a_Url_dup(a_History_get_url(NAV_TOP(bw))); if ( strlen(name) && (out = fopen(name, "w")) != NULL ) { DilloWeb *Web = a_Web_new(url); Web->bw = bw; Web->stream = out; Web->flags |= WEB_Download; /* todo: keep track of this client */ a_Capi_open_url(Web, Interface_save_callback, Web); } a_Url_free(url); gtk_widget_destroy(bw->save_dialog_window);}#endif/* * Save the link-URL to a local file */#if 0static void Interface_file_save_link(GtkWidget *widget, BrowserWindow *bw){ const gchar *name; const DilloUrl *url; gchar *cmd, *buf; FILE *out; gint buf_size; name = gtk_file_selection_get_filename( GTK_FILE_SELECTION(bw->save_link_dialog_window)); url = a_Menu_popup_get_url(bw); if (!a_Capi_get_buf(url, &buf, &buf_size)) { /* Not cached, ask the downloads server to get it */ cmd = g_strdup_printf( "<dpi cmd='download' url='%s' destination='%s'>\n", URL_STR(url), name); a_Capi_dpi_send_cmd(NULL, bw, cmd, "downloads", 1); g_free(cmd); } else { /* Cached! Save from the cache */ if ( strlen(name) && (out = fopen(name, "w")) != NULL ) { DilloWeb *Web = a_Web_new(url); Web->bw = bw; Web->stream = out; Web->flags |= WEB_Download; /* todo: keep track of this client */ a_Capi_open_url(Web, Interface_save_callback, Web); } else g_printerr("Error trying to save: %s\n", name); } gtk_widget_destroy(bw->save_link_dialog_window);}#endif/* * Scan Url and return a local-filename suggestion for saving */static char *Interface_make_save_name(const DilloUrl *url){ gchar *FileName; if ((FileName = strrchr(URL_PATH(url), '/'))) return g_strndup(++FileName, MIN(strlen(FileName), 64)); return g_strdup("");}/* * Show the dialog interface for saving an URL */#if 0void a_Interface_save_dialog(GtkWidget *widget, BrowserWindow *bw){ gchar *SuggestedName; /* Suggested save name */ DilloUrl* url; if (!bw->save_dialog_window) { Interface_make_choose_file_dialog( &bw->save_dialog_window, "save_dialog", "Dillo", "Dillo: Save URL as File...", (GtkSignalFunc) Interface_file_save_url, (void *)bw ); } url = a_Url_new(a_Interface_get_location_text(bw), NULL, 0, 0, 0); SuggestedName = Interface_make_save_name(url); gtk_file_selection_set_filename( GTK_FILE_SELECTION(bw->save_dialog_window), SuggestedName); g_free(SuggestedName); a_Url_free(url); if (!GTK_WIDGET_VISIBLE(bw->save_dialog_window)) gtk_widget_show(bw->save_dialog_window); else gdk_window_raise(bw->save_dialog_window->window);}#endif/* * Show the dialog interface for saving a link */#if 0void a_Interface_save_link_dialog(GtkWidget *widget, BrowserWindow *bw){ char *SuggestedName; /* Suggested save name */ if (!bw->save_link_dialog_window) { Interface_make_choose_file_dialog( &bw->save_link_dialog_window, "save_link_dialog", "Dillo", "Dillo: Save link as File...", (GtkSignalFunc) Interface_file_save_link, (void *)bw); } SuggestedName = Interface_make_save_name(a_Menu_popup_get_url(bw)); gtk_file_selection_set_filename( GTK_FILE_SELECTION(bw->save_link_dialog_window), SuggestedName); g_free(SuggestedName); if (!GTK_WIDGET_VISIBLE(bw->save_link_dialog_window)) gtk_widget_show(bw->save_link_dialog_window); else gdk_window_raise(bw->save_link_dialog_window->window);}#endif/* * Scroll to an occurence of a string in the open page */#if 0static void Interface_entry_search(GtkWidget *widget, BrowserWindow* bw){ char *string; gboolean case_sens; string = gtk_editable_get_chars(GTK_EDITABLE(bw->findtext_dialog_entry), 0, -1); case_sens = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(bw->findtext_dialog_check)); switch(a_Dw_gtk_scrolled_window_search(GTK_DW_SCROLLED_WINDOW(bw->docwin), string, case_sens)) { case FINDTEXT_RESTART: a_Interface_message_window("Dillo: Find text", "No further occurence of \"%s\". " "Restarting from the beginning.", string); break; case FINDTEXT_NOT_FOUND: a_Interface_message_window("Dillo: Find text", "Cannot find \"%s\".", string); break; } g_free(string);}#endif/* * Show the dialog interface for finding text in a page */#if 0void a_Interface_findtext_dialog(BrowserWindow *bw){ if (!bw->findtext_dialog_window) { Interface_make_dialog(&(bw->findtext_dialog_window), "findtext_dialog", "Dillo", "Dillo: Find text in page", &(bw->findtext_dialog_entry), "", &(bw->findtext_dialog_check), "Case sensitive", "Find", (GtkSignalFunc) Interface_entry_search, (void *)bw); if (prefs.transient_dialogs) gtk_window_set_transient_for(GTK_WINDOW(bw->findtext_dialog_window), GTK_WINDOW(bw->main_window)); gtk_signal_connect_object (GTK_OBJECT(bw->findtext_dialog_window), "destroy", (GtkSignalFunc) a_Dw_gtk_scrolled_window_reset_search, (void*)bw->docwin); gtk_window_set_position(GTK_WINDOW(bw->findtext_dialog_window), GTK_WIN_POS_NONE); } a_Interface_set_nice_window_pos(bw->findtext_dialog_window, bw->main_window); if (!GTK_WIDGET_VISIBLE(bw->findtext_dialog_window)) gtk_widget_show(bw->findtext_dialog_window); else gdk_window_raise(bw->findtext_dialog_window->window);}#endif/* * Use the search dialog's entry to feed a web search engine. */#if 0static void Interface_search_callback(GtkWidget *widget, BrowserWindow *bw){ gchar *keyw, *url_str; keyw = gtk_editable_get_chars(GTK_EDITABLE(bw->search_dialog_entry), 0, -1); if (keyw) { url_str = Interface_make_search_url(keyw); Interface_open_url_string(url_str, bw); g_free(url_str); g_free(keyw); } if (bw->search_dialog_window != NULL) gtk_widget_hide(bw->search_dialog_window);}#endif/* * Show the dialog interface for web search engine. */#if 0void a_Interface_search_dialog(GtkWidget *widget, BrowserWindow *bw){ if (!bw->search_dialog_window) { Interface_make_dialog(&(bw->search_dialog_window), "search_dialog", "Dillo", "Dillo: Search the Web", &(bw->search_dialog_entry), "", NULL, NULL, "Search", (GtkSignalFunc)Interface_search_callback, (void *)bw); if (prefs.transient_dialogs) gtk_window_set_transient_for(GTK_WINDOW(bw->search_dialog_window), GTK_WINDOW(bw->main_window)); } if (!GTK_WIDGET_VISIBLE(bw->search_dialog_window)) gtk_widget_show(bw->search_dialog_window); else gdk_window_raise(bw->search_dialog_window->window);}#endif/* * This signal callback adjusts the position of a menu. * It's useful for very long menus. */#if 0void a_Interface_scroll_popup(GtkWidget *widget){ /* * todo: * 1) Scrolling menues should rather be the task of Gtk+. This is * a hack, and I don't know if it does not break anything. * 2) It could be improved, e.g. a timeout could be added for * better mouse navigation. */ int y, h, mx, my, sh; y = widget->allocation.y; h = widget->allocation.height; gdk_window_get_geometry (widget->parent->parent->window, &mx, &my, NULL, NULL, NULL); sh = gdk_screen_height (); if (y + my < 0) gdk_window_move (widget->parent->parent->window, mx, - y + 1); else if (y + my > sh - h) gdk_window_move (widget->parent->parent->window, mx, sh - h - y - 1);}#endif/* * A general purpose message window. */void a_Interface_message_window(const char *title, const char *format, ... ){#if 0 GtkAccelGroup *accel_group; GtkWidget *window, *frame, *label, *button, *box; static char msg[1024]; va_list argp; va_start(argp, format); vsnprintf(msg, 1024, format, argp); va_end(argp); window = gtk_window_new(GTK_WINDOW_DIALOG); gtk_window_set_wmclass(GTK_WINDOW(window), "question_dialog", "dillo"); gtk_window_set_title(GTK_WINDOW(window), title); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_container_border_width(GTK_CONTAINER(window), 10); gtk_signal_connect_object(GTK_OBJECT(window), "delete_event", (GtkSignalFunc)gtk_widget_destroy, (void*)window); /* accel_group for the message window */ accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); box = gtk_vbox_new(FALSE, 5); frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); label = gtk_label_new(msg); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL); gtk_misc_set_padding(GTK_MISC(label), 20, 20); gtk_container_add(GTK_CONTAINER(frame), label); gtk_widget_show(label); gtk_widget_show(frame); gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0); button = gtk_button_new_with_label("Close"); gtk_signal_connect_object(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gtk_widget_destroy, (void*)window); gtk_widget_add_accelerator(button, "clicked", accel_group, GDK_Escape, 0, GTK_ACCEL_LOCKED); gtk_widget_show(button); gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0); gtk_widget_show(button); gtk_container_add(GTK_CONTAINER(window), box); gtk_widget_show(box); gtk_widget_grab_focus(button); gtk_widget_show(window);#endif}/* * A general purpose window for long text display. */#if 0void a_Interface_text_window (GtkWidget **text_widget, gchar *title, gchar *wm_class, gchar *buf, gint buf_size, gint xsize_max, gint ysize_max){ gint xsize, ysize; GtkWidget *window, *box1, *button, *scrolled_window, *text; if (*text_widget) gtk_widget_destroy (*text_widget); /* -RL :: This code is adapted from testgtk. */ if ( !*text_widget ) { window = *text_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_wmclass(GTK_WINDOW(window), wm_class, "Dillo"); gtk_widget_set_name (window, "text window"); xsize = (prefs.width < xsize_max) ? prefs.width : xsize_max; ysize = (prefs.height < ysize_max) ? prefs.height : ysize_max; gtk_widget_set_usize (window, xsize, ysize); gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, FALSE); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), text_widget); gtk_window_set_title (GTK_WINDOW (window), title); gtk_container_border_width (GTK_CONTAINER (window), 0); box1 = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), box1); gtk_widget_show (box1); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_box_pack_start (GTK_BOX (box1), scrolled_window, TRUE, TRUE, 0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_widget_show (scrolled_window); text = gtk_text_new (NULL, NULL); gtk_text_set_editable (GTK_TEXT (text), FALSE); gtk_container_add (GTK_CONTAINER (scrolled_window), text); gtk_widget_show (text); gtk_text_freeze (GTK_TEXT (text)); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, buf, buf_size); gtk_text_thaw (GTK_TEXT (text)); button = gtk_button_new_with_label ("close"); gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (window)); gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_widget_grab_default (button); gtk_widget_show (button); } if (!GTK_WIDGET_VISIBLE (*text_widget)) gtk_widget_show (*text_widget);}#endif/* * Places win1 in a way that it does not, or as less as possible, cover win2. */#if 0void a_Interface_set_nice_window_pos(GtkWidget *win1, GtkWidget *win2){ gint w1, h1, x2, y2, w2, h2, sw, sh, sr, sl, sb, st, max; gtk_widget_realize(win1); gdk_window_get_geometry(win1->window, NULL, NULL, &w1, &h1, NULL); gdk_window_get_origin(win2->window, &x2, &y2); gdk_window_get_geometry(win2->window, NULL, NULL, &w2, &h2, NULL); sw = gdk_screen_width(); sh = gdk_screen_height(); /* space (excluding win1 space) at right, left, bottom and top */ sr = sw - (x2 + w2 + w1); sl = x2 - w1; sb = sh - (y2 + h2 + h1); st = y2 - h1; /* First, we test, whether win1 can be placed so that it does not * covor win2. */ if (sr >= 0) gtk_widget_set_uposition(win1, x2 + w2, (sh - h1) / 2); else if (sl >= 0) gtk_widget_set_uposition(win1, x2 - w1, (sh - h1) / 2); else if (sb >= 0) gtk_widget_set_uposition(win1, (sh - h1) / 2, y2 + h2); else if (st >= 0) gtk_widget_set_uposition(win1, (sh - h1) / 2, y2 - h1); else { /* Second, we search for the position where the covered space * is (more or less) minimized. */ max = MAX(MAX(sr, sl), MAX(sb, st)); if (sr == max) gtk_widget_set_uposition(win1, sw - w1, (sh - h1) / 2); else if (sl == max) gtk_widget_set_uposition(win1, 0, (sh - h1) / 2); else if (sb == max) gtk_widget_set_uposition(win1, (sh - h1) / 2, sh - h1); else gtk_widget_set_uposition(win1, (sh - h1) / 2, 0); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -