static void statusbar_features_toolbar_notify_toolbar_style_cb (GtkWidget* toolbar, GParamSpec* pspec, GtkWidget* button) { GtkToolbarStyle style = katze_object_get_enum (toolbar, "toolbar-style"); const gchar* text = g_object_get_data (G_OBJECT (button), "feature-label"); switch (style) { case GTK_TOOLBAR_BOTH: case GTK_TOOLBAR_BOTH_HORIZ: gtk_button_set_label (GTK_BUTTON (button), text); gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button))); break; case GTK_TOOLBAR_TEXT: gtk_button_set_label (GTK_BUTTON (button), text); gtk_widget_hide (gtk_button_get_image (GTK_BUTTON (button))); break; case GTK_TOOLBAR_ICONS: gtk_button_set_label (GTK_BUTTON (button), ""); gtk_widget_show (gtk_button_get_image (GTK_BUTTON (button))); break; default: g_assert_not_reached (); } }
static void katze_http_cookies_jar_changed_cb (SoupCookieJar* jar, SoupCookie* old_cookie, SoupCookie* new_cookie, KatzeHttpCookies* http_cookies) { GObject* settings; guint accept_cookies; if (old_cookie) soup_cookie_set_max_age (old_cookie, 0); if (new_cookie) { settings = g_object_get_data (G_OBJECT (jar), "midori-settings"); accept_cookies = katze_object_get_enum (settings, "accept-cookies"); if (accept_cookies == 2 /* MIDORI_ACCEPT_COOKIES_NONE */) { soup_cookie_set_max_age (new_cookie, 0); } else if (accept_cookies == 1 /* MIDORI_ACCEPT_COOKIES_SESSION */ && new_cookie->expires) { soup_cookie_set_max_age (new_cookie, -1); } else if (new_cookie->expires) { gint age = katze_object_get_int (settings, "maximum-cookie-age"); if (age > 0) { SoupDate* max_date = soup_date_new_from_now ( age * SOUP_COOKIE_MAX_AGE_ONE_DAY); if (soup_date_to_time_t (new_cookie->expires) > soup_date_to_time_t (max_date)) soup_cookie_set_expires (new_cookie, max_date); } else { /* An age of 0 to SoupCookie means already-expired A user choosing 0 days probably expects 1 hour. */ soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); } } } if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL) http_cookies->counter++; if (!http_cookies->timeout && (old_cookie || new_cookie->expires)) http_cookies->timeout = g_timeout_add_seconds (5, (GSourceFunc)katze_http_cookies_update_jar, http_cookies); }
MidoriApp* midori_normal_app_new (const gchar* config, gchar* nickname, gboolean diagnostic_dialog, gchar** open_uris, gchar** execute_commands, gint inactivity_reset, const gchar* block_uris) { if (g_str_has_suffix (nickname, "portable")) midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config); else if (g_str_has_suffix (nickname, "normal")) midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config); else g_assert_not_reached (); MidoriApp* app = midori_app_new (nickname); if (midori_app_instance_is_running (app)) { /* midori_debug makes no sense on a running instance */ if (g_getenv ("MIDORI_DEBUG")) g_warning ("MIDORI_DEBUG only works for a new instance"); /* It makes no sense to show a crash dialog while running */ if (!diagnostic_dialog) { if (execute_commands != NULL) midori_app_send_command (app, execute_commands); if (open_uris != NULL) midori_app_instance_send_uris (app, open_uris); if (!execute_commands && !open_uris) midori_app_instance_send_new_browser (app); if (g_application_get_is_registered (G_APPLICATION (app))) return NULL; } /* FIXME: We mustn't lose the URL here; either instance is freezing or inside a crash dialog */ sokoke_message_dialog (GTK_MESSAGE_INFO, _("An instance of Midori is already running but not responding.\n"), open_uris ? *open_uris : "", TRUE); return (void*)0xdeadbeef; } GString* error_messages = g_string_new (NULL); GError* error = NULL; gchar** extensions; MidoriWebSettings* settings = midori_settings_new_full (&extensions); g_object_set (settings, "enable-developer-extras", TRUE, "enable-html5-database", TRUE, "block-uris", block_uris, NULL); if (inactivity_reset > 0) g_object_set (settings, "inactivity-reset", inactivity_reset, NULL); KatzeArray* search_engines = midori_search_engines_new_from_folder (error_messages); /* Pick first search engine as default if not set */ gchar* uri = katze_object_get_string (settings, "location-entry-search"); if (!(uri && *uri) && !katze_array_is_empty (search_engines)) { KatzeItem* item = katze_array_get_nth_item (search_engines, 0); g_object_set (settings, "location-entry-search", katze_item_get_uri (item), NULL); } g_free (uri); MidoriBookmarksDb* bookmarks; gchar* errmsg = NULL; if (!(bookmarks = midori_bookmarks_db_new (&errmsg))) { g_string_append_printf (error_messages, _("Bookmarks couldn't be loaded: %s\n"), errmsg); katze_assign (errmsg, NULL); } gchar* config_file = NULL; KatzeArray* session = katze_array_new (KATZE_TYPE_ITEM); MidoriStartup load_on_startup = katze_object_get_enum (settings, "load-on-startup"); if (load_on_startup >= MIDORI_STARTUP_LAST_OPEN_PAGES) { katze_assign (config_file, midori_paths_get_config_filename_for_reading ("session.xbel")); error = NULL; if (!midori_array_from_file (session, config_file, "xbel-tiny", &error)) { if (error->code != G_FILE_ERROR_NOENT) g_string_append_printf (error_messages, _("The session couldn't be loaded: %s\n"), error->message); g_error_free (error); } } KatzeArray* trash = katze_array_new (KATZE_TYPE_ITEM); g_signal_connect_after (trash, "add-item", G_CALLBACK (midori_trash_add_item_cb), NULL); g_signal_connect_after (trash, "remove-item", G_CALLBACK (midori_trash_remove_item_cb), NULL); katze_assign (config_file, g_build_filename (config, "tabtrash.xbel", NULL)); error = NULL; if (!midori_array_from_file (trash, config_file, "xbel-tiny", &error)) { if (error->code != G_FILE_ERROR_NOENT) g_string_append_printf (error_messages, _("The trash couldn't be loaded: %s\n"), error->message); g_error_free (error); } KatzeArray* history; if (!(history = midori_history_new (&errmsg))) { g_string_append_printf (error_messages, _("The history couldn't be loaded: %s\n"), errmsg); katze_assign (errmsg, NULL); } //add by zgh 20150206 KatzeArray* download; if (!(download = midori_download_db_new (&errmsg))) { g_string_append_printf (error_messages, _("The download couldn't be loaded: %s\n"), errmsg); katze_assign (errmsg, NULL); } katze_assign (config_file, midori_paths_get_config_filename_for_reading ("speeddial")); MidoriSpeedDial* dial = midori_speed_dial_new (config_file, NULL); if (error_messages->len) { GtkWidget* dialog = gtk_message_dialog_new ( NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE, _("The following errors occured:")); gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG (dialog), "%s", error_messages->str); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Ignore"), GTK_RESPONSE_ACCEPT, NULL); if (midori_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) return (void*)0xdeadbeef; gtk_widget_destroy (dialog); } g_string_free (error_messages, TRUE); g_object_set_data (G_OBJECT (app), "execute-commands", execute_commands); g_object_set_data (G_OBJECT (app), "open-uris", open_uris); g_object_set_data_full (G_OBJECT (app), "extensions", extensions, (GDestroyNotify)g_strfreev); katze_item_set_parent (KATZE_ITEM (session), app); katze_assign (config_file, midori_paths_get_config_filename_for_reading ("search")); midori_search_engines_set_filename (search_engines, config_file); if ((midori_app_get_crashed (app) && katze_object_get_boolean (settings, "show-crash-dialog") && open_uris && !execute_commands) || diagnostic_dialog) { gint response = midori_frontend_diagnostic_dialog (app, settings, session); if (response == G_MAXINT) return NULL; load_on_startup = response; } katze_item_set_parent (KATZE_ITEM (session), NULL); g_object_unref (session); g_object_set_data (G_OBJECT (settings), "load-on-startup", GINT_TO_POINTER (load_on_startup)); g_object_set (app, "settings", settings, "bookmarks", bookmarks, "trash", trash, "search-engines", search_engines, "history", history, "download", download, "speed-dial", dial, NULL); g_signal_connect (app, "add-browser", G_CALLBACK (midori_app_add_browser_cb), NULL); midori_session_persistent_settings (settings, app); g_idle_add (midori_load_soup_session_full, settings); g_idle_add (midori_load_extensions, app); return app; }
static gint midori_frontend_diagnostic_dialog (MidoriApp* app, MidoriWebSettings* settings, KatzeArray* session) { GtkWidget* dialog; GtkWidget* content_area; GtkWidget* align; GtkWidget* box; GtkWidget* button; MidoriStartup load_on_startup = katze_object_get_enum (settings, "load-on-startup"); gint response; dialog = gtk_message_dialog_new ( NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("CDOS crashed the last time it was opened. You can report the problem at %s."), PACKAGE_BUGREPORT); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE); gtk_window_set_title (GTK_WINDOW (dialog), g_get_application_name ()); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); align = gtk_alignment_new (0.5, 0.5, 0.5, 0.5); gtk_box_pack_start (GTK_BOX (content_area), align, FALSE, TRUE, 0); box = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (align), box); button = gtk_button_new_with_mnemonic (_("Modify _preferences")); g_signal_connect (button, "clicked", G_CALLBACK (button_modify_preferences_clicked_cb), settings); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4); button = gtk_button_new_with_mnemonic (_("Disable all _extensions")); if (g_object_get_data (G_OBJECT (app), "extensions")) g_signal_connect (button, "clicked", G_CALLBACK (button_disable_extensions_clicked_cb), app); else gtk_widget_set_sensitive (button, FALSE); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4); gtk_widget_show_all (align); button = katze_property_proxy (settings, "show-crash-dialog", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Show a dialog after Midori crashed")); gtk_widget_show (button); gtk_box_pack_start (GTK_BOX (content_area), button, FALSE, TRUE, 0); gtk_container_set_focus_child (GTK_CONTAINER (dialog), gtk_dialog_get_action_area (GTK_DIALOG (dialog))); gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("Discard old tabs"), MIDORI_STARTUP_BLANK_PAGE, _("Show last tabs without loading"), MIDORI_STARTUP_DELAYED_PAGES, _("Show last open tabs"), MIDORI_STARTUP_LAST_OPEN_PAGES, NULL); gchar* crash_log = g_build_filename (midori_paths_get_runtime_dir (), "gdb.bt", NULL); if (g_access (crash_log, F_OK) == 0) { GtkWidget* log_button = gtk_button_new_with_mnemonic (_("Show last crash _log")); g_signal_connect_data (log_button, "clicked", G_CALLBACK (midori_frontend_crash_log_cb), crash_log, (GClosureNotify)g_free, 0); gtk_widget_show (log_button); gtk_box_pack_start (GTK_BOX (box), log_button, FALSE, FALSE, 4); } else g_free (crash_log); gchar* gdb = g_find_program_in_path ("gdb"); if (gdb != NULL) { GtkWidget* gdb_button = gtk_button_new_with_mnemonic (_("Run in _debugger")); g_signal_connect (button, "clicked", G_CALLBACK (midori_frontend_debugger_cb), dialog); gtk_widget_show (gdb_button); gtk_box_pack_start (GTK_BOX (box), gdb_button, FALSE, FALSE, 4); } gtk_dialog_set_default_response (GTK_DIALOG (dialog), load_on_startup == MIDORI_STARTUP_HOMEPAGE ? MIDORI_STARTUP_BLANK_PAGE : load_on_startup); /* GtkLabel can't wrap the text properly. Until some day this works, we implement this hack to do it ourselves. */ GList* ch = gtk_container_get_children (GTK_CONTAINER (content_area)); GtkWidget* hbox = (GtkWidget*)g_list_nth_data (ch, 0); g_list_free (ch); ch = gtk_container_get_children (GTK_CONTAINER (hbox)); GtkWidget* vbox = (GtkWidget*)g_list_nth_data (ch, 1); g_list_free (ch); ch = gtk_container_get_children (GTK_CONTAINER (vbox)); GtkWidget* label = (GtkWidget*)g_list_nth_data (ch, 0); g_list_free (ch); GtkRequisition req; gtk_widget_size_request (content_area, &req); gtk_widget_set_size_request (label, req.width * 0.9, -1); response = midori_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (response == GTK_RESPONSE_DELETE_EVENT) response = G_MAXINT; else if (response == GTK_RESPONSE_HELP) { sokoke_spawn_gdb (gdb, FALSE); response = G_MAXINT; } else if (response == MIDORI_STARTUP_BLANK_PAGE) katze_array_clear (session); return response; }
static void colorful_tabs_view_notify_uri_cb (MidoriView* view, GParamSpec* pspec, MidoriExtension* extension) { GtkWidget* box; GtkWidget* label; SoupURI* uri; gchar* colorstr; GdkColor color; GdkColor fgcolor; GdkPixbuf* icon; label = midori_view_get_proxy_tab_label (view); if ((uri = soup_uri_new (midori_view_get_display_uri (view))) && uri->host && (katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)) { icon = midori_view_get_icon (view); if (midori_view_get_icon_uri (view) != NULL) { GdkPixbuf* newpix; guchar* pixels; newpix = gdk_pixbuf_scale_simple (icon, 1, 1, GDK_INTERP_BILINEAR); g_return_if_fail (gdk_pixbuf_get_bits_per_sample (newpix) == 8); pixels = gdk_pixbuf_get_pixels (newpix); color.red = pixels[0] * 225; color.green = pixels[1] * 225; color.blue = pixels[2] * 225; } else { gchar* hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri->host, 1); colorstr = g_strndup (hash, 6 + 1); g_free (hash); colorstr[0] = '#'; gdk_color_parse (colorstr, &color); } soup_uri_free (uri); if ((color.red < 35000) && (color.green < 35000) && (color.blue < 35000)) { color.red += 20000; color.green += 20000; color.blue += 20000; } /* Ensure high contrast by enforcing black/ white text colour. */ if ((color.red < 41000) && (color.green < 41000) && (color.blue < 41000)) gdk_color_parse ("#fff", &fgcolor); else gdk_color_parse ("#000", &fgcolor); box = gtk_bin_get_child (GTK_BIN (label)); gtk_event_box_set_visible_window (GTK_EVENT_BOX (label), TRUE); gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) colorful_tabs_modify_fg, &fgcolor); gtk_widget_modify_bg (label, GTK_STATE_NORMAL, &color); if (color.red < 10000) color.red = 5000; else color.red -= 5000; if (color.blue < 10000) color.blue = 5000; else color.blue -= 5000; if (color.green < 10000) color.green = 5000; else color.green -= 5000; gtk_widget_modify_bg (label, GTK_STATE_ACTIVE, &color); } else { gtk_widget_modify_bg (label, GTK_STATE_NORMAL, NULL); gtk_widget_modify_bg (label, GTK_STATE_ACTIVE, NULL); gtk_container_foreach (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (label))), (GtkCallback) colorful_tabs_modify_fg, NULL); } }