示例#1
0
static void
tab_panel_browser_add_tab_cb (MidoriBrowser*   browser,
                              GtkWidget*       view,
                              MidoriExtension* extension)
{
    GtkWidget* notebook = katze_object_get_object (browser, "notebook");
    gint page = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), view);
    MidoriWebSettings* settings = midori_browser_get_settings (browser);
    gboolean minimized = katze_object_get_boolean (view, "minimized");
    GdkPixbuf* icon = midori_view_get_icon (MIDORI_VIEW (view));
    const gchar* title = midori_view_get_display_title (MIDORI_VIEW (view));
    GtkTreeModel* model = tab_panel_get_model_for_browser (browser);

    if (minimized)
    {
        GtkWidget* toolbar = tab_panel_get_toolbar_for_browser (browser);
        GtkWidget* image = gtk_image_new_from_pixbuf (
            midori_view_get_icon (MIDORI_VIEW (view)));
        GtkToolItem* toolitem = gtk_tool_button_new (image, NULL);
        gtk_tool_item_set_tooltip_text (toolitem, title);
        gtk_widget_show (image);
        g_object_set_data (G_OBJECT (view), "tab-panel-ext-toolitem", toolitem);
        gtk_widget_show (GTK_WIDGET (toolitem));
        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
        tab_panel_toggle_toolbook (toolbar);
        g_signal_connect (toolitem, "clicked",
            G_CALLBACK (tab_panel_toolitem_clicked_cb), view);
        g_signal_connect (gtk_bin_get_child (GTK_BIN (toolitem)), "button-press-event",
            G_CALLBACK (tab_panel_toolitem_button_press_event_cb), view);
    }
    else
    {
        GtkTreeIter iter;
        gboolean buttons = katze_object_get_boolean (settings, "close-buttons-on-tabs");
        gint ellipsize = midori_view_get_label_ellipsize (MIDORI_VIEW (view));

        gtk_tree_store_insert_with_values (GTK_TREE_STORE (model),
            &iter, NULL, page, 0, view, 1, GTK_STOCK_CLOSE, 2, buttons,
            3, icon, 4, title, 5, ellipsize, 6, NULL, -1);
    }

    if (!g_signal_handler_find (view, G_SIGNAL_MATCH_FUNC,
        g_signal_lookup ("notify", MIDORI_TYPE_VIEW), 0, NULL,
        tab_panel_view_notify_minimized_cb, extension))
    {
        g_signal_connect (settings, "notify::close-buttons-on-tabs",
            G_CALLBACK (tab_panel_settings_notify_cb), model);
        g_signal_connect (view, "notify::minimized",
            G_CALLBACK (tab_panel_view_notify_minimized_cb), extension);
        g_signal_connect (view, "notify::icon",
            G_CALLBACK (tab_panel_view_notify_icon_cb), extension);
        g_signal_connect (view, "notify::title",
            G_CALLBACK (tab_panel_view_notify_title_cb), extension);
    }

    g_object_unref (notebook);
}
示例#2
0
static void
tab_panel_view_notify_title_cb (GtkWidget*       view,
                                GParamSpec*      pspec,
                                MidoriExtension* extension)
{
    MidoriBrowser* browser = midori_browser_get_for_widget (view);
    gboolean minimized = katze_object_get_boolean (view, "minimized");
    const gchar* title = midori_view_get_display_title (MIDORI_VIEW (view));

    if (minimized)
    {
        GtkToolItem* toolitem = tab_panel_get_toolitem_for_view (view);
        gtk_tool_item_set_tooltip_text (toolitem, title);
    }
    else
    {
        GtkTreeModel* model = tab_panel_get_model_for_browser (browser);
        GtkTreeIter iter;
        if (tab_panel_get_iter_for_view (model, &iter, view))
        {
            gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
                4, title,
                5, midori_view_get_label_ellipsize (MIDORI_VIEW (view)),
                -1);
        }
    }
}
示例#3
0
static void
tab_panel_view_notify_icon_cb (GtkWidget*       view,
                               GParamSpec*      pspec,
                               MidoriExtension* extension)
{
    MidoriBrowser* browser = midori_browser_get_for_widget (view);
    gboolean minimized = katze_object_get_boolean (view, "minimized");
    GdkPixbuf* icon = midori_view_get_icon (MIDORI_VIEW (view));

    if (minimized)
    {
        GtkToolItem* toolitem = tab_panel_get_toolitem_for_view (view);
        GtkWidget* image = gtk_tool_button_get_icon_widget (GTK_TOOL_BUTTON (toolitem));
        gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon);
    }
    else
    {
        GtkTreeModel* model = tab_panel_get_model_for_browser (browser);
        GtkTreeIter iter;
        GtkWidget* label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
        GtkStyle* style = gtk_widget_get_style (label);
        if (tab_panel_get_iter_for_view (model, &iter, view))
            gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
                3, icon,
                6, &style->bg[GTK_STATE_NORMAL],
                7, &style->fg[GTK_STATE_NORMAL],
                -1);
    }
}
示例#4
0
static void
tab_panel_browser_remove_tab_cb (MidoriBrowser*   browser,
                                 GtkWidget*       view,
                                 MidoriExtension* extension)
{
    gboolean minimized = katze_object_get_boolean (view, "minimized");

    if (!g_object_get_data (G_OBJECT (browser), "midori-browser-destroyed"))
        tab_panel_remove_view (browser, view, minimized);
}
示例#5
0
static void
tab_panel_view_notify_minimized_cb (GtkWidget*       view,
                                    GParamSpec*      pspec,
                                    MidoriExtension* extension)
{
    MidoriBrowser* browser = midori_browser_get_for_widget (view);
    gboolean minimized = katze_object_get_boolean (view, "minimized");

    tab_panel_remove_view (browser, view, !minimized);
    tab_panel_browser_add_tab_cb (browser, view, extension);
}
示例#6
0
static void
tab_panel_settings_notify_cb (MidoriWebSettings* settings,
                              GParamSpec*        pspec,
                              GtkTreeModel*      model)
{
    gboolean buttons = katze_object_get_boolean (settings, "close-buttons-on-tabs");
    guint i;
    GtkTreeIter iter;

    i = 0;
    while (gtk_tree_model_iter_nth_child (model, &iter, NULL, i++))
        gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 2, buttons, -1);
}
示例#7
0
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;
}