2008-09-26 21:13:46 +00:00
|
|
|
|
/*
|
2010-04-13 21:44:21 +00:00
|
|
|
|
Copyright (C) 2007-2010 Christian Dywan <christian@twotoasts.de>
|
2009-05-07 20:22:43 +00:00
|
|
|
|
Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "midori-view.h"
|
2009-06-19 00:58:06 +00:00
|
|
|
|
#include "midori-browser.h"
|
2011-05-01 16:49:09 +00:00
|
|
|
|
#include "midori-searchaction.h"
|
2011-09-21 21:03:00 +00:00
|
|
|
|
#include "midori-platform.h"
|
2011-10-19 07:53:18 +00:00
|
|
|
|
#include "midori-core.h"
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-01-08 01:29:07 +00:00
|
|
|
|
#include "marshal.h"
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
2009-05-07 20:22:43 +00:00
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
#include <glib/gstdio.h>
|
2009-05-31 01:43:15 +00:00
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2008-09-26 21:13:46 +00:00
|
|
|
|
#include <webkit/webkit.h>
|
|
|
|
|
|
2011-10-31 21:10:39 +00:00
|
|
|
|
#include <config.h>
|
2009-12-19 09:39:24 +00:00
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
2010-01-07 20:12:36 +00:00
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-10-05 18:50:31 +00:00
|
|
|
|
#if !WEBKIT_CHECK_VERSION (1, 4, 3)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/* This is unstable API, so we need to declare it */
|
|
|
|
|
gchar*
|
|
|
|
|
webkit_web_view_get_selected_text (WebKitWebView* web_view);
|
2011-09-21 21:50:51 +00:00
|
|
|
|
#endif
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-05-17 18:29:31 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_construct_web_view (MidoriView* view);
|
|
|
|
|
|
2009-07-21 21:57:57 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_item_meta_data_changed (KatzeItem* item,
|
|
|
|
|
const gchar* key,
|
|
|
|
|
MidoriView* view);
|
|
|
|
|
|
2011-01-11 19:44:34 +00:00
|
|
|
|
static void
|
|
|
|
|
_midori_view_set_settings (MidoriView* view,
|
|
|
|
|
MidoriWebSettings* settings);
|
|
|
|
|
|
2011-10-09 12:28:06 +00:00
|
|
|
|
static GdkPixbuf*
|
|
|
|
|
midori_view_web_view_get_snapshot (GtkWidget* web_view,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
|
|
|
|
|
2011-10-29 01:33:43 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_speed_dial_get_thumb (MidoriView* view,
|
|
|
|
|
gchar* dial_id,
|
|
|
|
|
gchar* url);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
struct _MidoriView
|
|
|
|
|
{
|
2010-03-30 20:45:49 +00:00
|
|
|
|
GtkVBox parent_instance;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
gchar* uri;
|
2010-03-13 15:46:45 +00:00
|
|
|
|
gboolean special;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gchar* title;
|
2010-04-13 21:44:21 +00:00
|
|
|
|
MidoriSecurity security;
|
2009-01-02 01:28:04 +00:00
|
|
|
|
gchar* mime_type;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
GdkPixbuf* icon;
|
2010-03-11 22:27:37 +00:00
|
|
|
|
gchar* icon_uri;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gdouble progress;
|
|
|
|
|
MidoriLoadStatus load_status;
|
2009-07-21 21:57:57 +00:00
|
|
|
|
gboolean minimized;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gchar* statusbar_text;
|
2009-09-19 19:18:25 +00:00
|
|
|
|
WebKitHitTestResult* hit_test;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gchar* link_uri;
|
|
|
|
|
gboolean has_selection;
|
|
|
|
|
gchar* selected_text;
|
|
|
|
|
MidoriWebSettings* settings;
|
|
|
|
|
GtkWidget* web_view;
|
2009-05-03 01:11:33 +00:00
|
|
|
|
KatzeArray* news_feeds;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-10-02 22:49:16 +00:00
|
|
|
|
gboolean middle_click_opens_selection;
|
|
|
|
|
gboolean open_tabs_in_the_background;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gboolean close_buttons_on_tabs;
|
2008-12-03 03:16:19 +00:00
|
|
|
|
MidoriNewPage open_new_pages_in;
|
2010-10-25 21:54:19 +00:00
|
|
|
|
gint find_links;
|
2011-04-04 00:59:16 +00:00
|
|
|
|
gint alerts;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget* menu_item;
|
|
|
|
|
GtkWidget* tab_label;
|
|
|
|
|
GtkWidget* tab_icon;
|
|
|
|
|
GtkWidget* tab_title;
|
|
|
|
|
GtkWidget* tab_close;
|
|
|
|
|
KatzeItem* item;
|
2009-09-16 20:02:30 +00:00
|
|
|
|
gint scrollh, scrollv;
|
2009-09-25 21:57:44 +00:00
|
|
|
|
gboolean back_forward_set;
|
2010-03-11 22:27:37 +00:00
|
|
|
|
GHashTable* memory;
|
2010-03-30 20:45:49 +00:00
|
|
|
|
GtkWidget* scrolled_window;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _MidoriViewClass
|
|
|
|
|
{
|
2010-03-30 20:45:49 +00:00
|
|
|
|
GtkVBoxClass parent_class;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-03-30 20:45:49 +00:00
|
|
|
|
G_DEFINE_TYPE (MidoriView, midori_view, GTK_TYPE_VBOX);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-12-03 03:16:19 +00:00
|
|
|
|
GType
|
|
|
|
|
midori_new_view_get_type (void)
|
|
|
|
|
{
|
|
|
|
|
static GType type = 0;
|
|
|
|
|
if (!type)
|
|
|
|
|
{
|
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
|
{ MIDORI_NEW_VIEW_TAB, "MIDORI_NEW_VIEW_TAB", "New view in a tab" },
|
|
|
|
|
{ MIDORI_NEW_VIEW_BACKGROUND, "MIDORI_NEW_VIEW_BACKGROUND",
|
|
|
|
|
"New view in a background tab" },
|
|
|
|
|
{ MIDORI_NEW_VIEW_WINDOW, "MIDORI_NEW_VIEW_WINDOW",
|
|
|
|
|
"New view in a window" },
|
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
|
};
|
|
|
|
|
type = g_enum_register_static ("MidoriNewView", values);
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-13 21:44:21 +00:00
|
|
|
|
GType
|
|
|
|
|
midori_security_get_type (void)
|
|
|
|
|
{
|
|
|
|
|
static GType type = 0;
|
|
|
|
|
if (!type)
|
|
|
|
|
{
|
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
|
{ MIDORI_SECURITY_NONE, "MIDORI_SECURITY_NONE", "No security" },
|
|
|
|
|
{ MIDORI_SECURITY_UNKNOWN, "MIDORI_SECURITY_UNKNOWN", "Security unknown" },
|
|
|
|
|
{ MIDORI_SECURITY_TRUSTED, "MIDORI_SECURITY_TRUSTED", "Trusted security" },
|
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
|
};
|
|
|
|
|
type = g_enum_register_static ("MidoriSecurity", values);
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
|
|
PROP_URI,
|
|
|
|
|
PROP_TITLE,
|
2010-04-13 21:44:21 +00:00
|
|
|
|
PROP_SECURITY,
|
2009-01-02 01:28:04 +00:00
|
|
|
|
PROP_MIME_TYPE,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
PROP_ICON,
|
|
|
|
|
PROP_LOAD_STATUS,
|
|
|
|
|
PROP_PROGRESS,
|
2009-07-21 21:57:57 +00:00
|
|
|
|
PROP_MINIMIZED,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
PROP_ZOOM_LEVEL,
|
2009-05-03 01:11:33 +00:00
|
|
|
|
PROP_NEWS_FEEDS,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
PROP_STATUSBAR_TEXT,
|
2010-10-12 20:51:01 +00:00
|
|
|
|
PROP_SETTINGS
|
2008-09-26 21:13:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ACTIVATE_ACTION,
|
|
|
|
|
CONSOLE_MESSAGE,
|
2008-11-01 18:15:58 +00:00
|
|
|
|
ATTACH_INSPECTOR,
|
2011-04-04 19:56:21 +00:00
|
|
|
|
DETACH_INSPECTOR,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
NEW_TAB,
|
|
|
|
|
NEW_WINDOW,
|
2008-12-03 03:16:19 +00:00
|
|
|
|
NEW_VIEW,
|
2009-03-19 17:28:50 +00:00
|
|
|
|
DOWNLOAD_REQUESTED,
|
2008-09-28 14:29:41 +00:00
|
|
|
|
SEARCH_TEXT,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
ADD_BOOKMARK,
|
2008-11-09 21:07:42 +00:00
|
|
|
|
SAVE_AS,
|
2009-05-10 12:39:20 +00:00
|
|
|
|
ADD_SPEED_DIAL,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
2011-08-06 22:46:06 +00:00
|
|
|
|
static gchar* speeddial_markup = NULL;
|
2011-10-09 12:28:06 +00:00
|
|
|
|
static GtkWidget* thumb_view = NULL;
|
2011-10-29 01:33:43 +00:00
|
|
|
|
static GList* thumb_queue = NULL;
|
2011-08-06 22:46:06 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_finalize (GObject* object);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_set_property (GObject* object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue* value,
|
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_get_property (GObject* object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue* value,
|
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
2010-05-06 20:27:29 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_focus_in_event (GtkWidget* widget,
|
|
|
|
|
GdkEventFocus* event);
|
|
|
|
|
|
2008-10-17 19:12:16 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_settings_notify_cb (MidoriWebSettings* settings,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view);
|
|
|
|
|
|
2009-05-07 20:22:43 +00:00
|
|
|
|
static void
|
2011-03-22 21:59:56 +00:00
|
|
|
|
midori_view_speed_dial_save (MidoriView* view,
|
2009-05-13 21:56:55 +00:00
|
|
|
|
const gchar* message);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_class_init (MidoriViewClass* class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass* gobject_class;
|
2010-05-06 20:27:29 +00:00
|
|
|
|
GtkWidgetClass* gtkwidget_class;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
GParamFlags flags;
|
|
|
|
|
|
|
|
|
|
signals[ACTIVATE_ACTION] = g_signal_new (
|
|
|
|
|
"activate-action",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
|
|
|
|
signals[CONSOLE_MESSAGE] = g_signal_new (
|
|
|
|
|
"console-message",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
midori_cclosure_marshal_VOID__STRING_INT_STRING,
|
|
|
|
|
G_TYPE_NONE, 3,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_INT,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
2008-11-23 04:19:43 +00:00
|
|
|
|
signals[ATTACH_INSPECTOR] = g_signal_new (
|
|
|
|
|
"attach-inspector",
|
2008-10-15 01:07:38 +00:00
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
2008-11-23 04:19:43 +00:00
|
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
GTK_TYPE_WIDGET);
|
2008-10-15 01:07:38 +00:00
|
|
|
|
|
2011-04-04 19:56:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::detach-inspector:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
*
|
|
|
|
|
* Emitted when an open inspector that was previously
|
|
|
|
|
* attached to the window is now detached again.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.3.4
|
|
|
|
|
*/
|
|
|
|
|
signals[DETACH_INSPECTOR] = g_signal_new (
|
|
|
|
|
"detach-inspector",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
GTK_TYPE_WIDGET);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
signals[NEW_TAB] = g_signal_new (
|
|
|
|
|
"new-tab",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
2008-10-02 22:49:16 +00:00
|
|
|
|
midori_cclosure_marshal_VOID__STRING_BOOLEAN,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_BOOLEAN);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
signals[NEW_WINDOW] = g_signal_new (
|
|
|
|
|
"new-window",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
2008-12-03 03:16:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::new-view:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
* @new_view: a newly created view
|
|
|
|
|
* @where: where to open the view
|
2011-04-19 21:16:34 +00:00
|
|
|
|
* @user_initiated: %TRUE if the user actively opened the new view
|
2008-12-03 03:16:19 +00:00
|
|
|
|
*
|
|
|
|
|
* Emitted when a new view is created. The value of
|
|
|
|
|
* @where determines where to open the view according
|
|
|
|
|
* to how it was opened and user preferences.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.2
|
2011-04-19 21:16:34 +00:00
|
|
|
|
*
|
|
|
|
|
* Since 0.3.4 a boolean argument was added.
|
2008-12-03 03:16:19 +00:00
|
|
|
|
*/
|
|
|
|
|
signals[NEW_VIEW] = g_signal_new (
|
|
|
|
|
"new-view",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
2011-04-19 21:16:34 +00:00
|
|
|
|
midori_cclosure_marshal_VOID__OBJECT_ENUM_BOOLEAN,
|
|
|
|
|
G_TYPE_NONE, 3,
|
2008-12-03 03:16:19 +00:00
|
|
|
|
MIDORI_TYPE_VIEW,
|
2011-04-19 21:16:34 +00:00
|
|
|
|
MIDORI_TYPE_NEW_VIEW,
|
|
|
|
|
G_TYPE_BOOLEAN);
|
2008-12-03 03:16:19 +00:00
|
|
|
|
|
2009-03-19 17:28:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::download-requested:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
* @download: a new download
|
|
|
|
|
*
|
|
|
|
|
* Emitted when a new download is requested, if a
|
|
|
|
|
* file cannot be displayed or a download was started
|
|
|
|
|
* from the context menu.
|
|
|
|
|
*
|
|
|
|
|
* If the download should be accepted, a callback
|
|
|
|
|
* has to return %TRUE, and the download will also
|
|
|
|
|
* be started automatically.
|
|
|
|
|
*
|
|
|
|
|
* Note: This requires WebKitGTK 1.1.3.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE if the download was handled
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.5
|
|
|
|
|
*/
|
|
|
|
|
signals[DOWNLOAD_REQUESTED] = g_signal_new (
|
|
|
|
|
"download-requested",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
g_signal_accumulator_true_handled,
|
|
|
|
|
NULL,
|
|
|
|
|
midori_cclosure_marshal_BOOLEAN__OBJECT,
|
|
|
|
|
G_TYPE_BOOLEAN, 1,
|
|
|
|
|
G_TYPE_OBJECT);
|
|
|
|
|
|
2009-02-22 00:45:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::search-text:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
* @found: whether the search was successful
|
|
|
|
|
* @typing: whether the search was initiated by typing
|
|
|
|
|
*
|
|
|
|
|
* Emitted when a search is performed. Either manually
|
|
|
|
|
* invoked or automatically by typing. The value of typing
|
|
|
|
|
* is actually the text the user typed.
|
|
|
|
|
*
|
|
|
|
|
* Note that in 0.1.3 the argument @typing was introduced.
|
|
|
|
|
*/
|
2008-09-28 14:29:41 +00:00
|
|
|
|
signals[SEARCH_TEXT] = g_signal_new (
|
|
|
|
|
"search-text",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
2009-02-22 00:45:22 +00:00
|
|
|
|
midori_cclosure_marshal_VOID__BOOLEAN_STRING,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
|
G_TYPE_STRING);
|
2008-09-28 14:29:41 +00:00
|
|
|
|
|
2010-06-25 04:11:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::add-bookmark:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
* @uri: the bookmark URI
|
|
|
|
|
*
|
|
|
|
|
* Emitted when a bookmark is added.
|
|
|
|
|
*
|
|
|
|
|
* Deprecated: 0.2.7
|
|
|
|
|
*/
|
2008-09-26 21:13:46 +00:00
|
|
|
|
signals[ADD_BOOKMARK] = g_signal_new (
|
|
|
|
|
"add-bookmark",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
2008-11-09 21:07:42 +00:00
|
|
|
|
signals[SAVE_AS] = g_signal_new (
|
|
|
|
|
"save-as",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
2009-05-10 12:39:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView::add-speed-dial:
|
|
|
|
|
* @view: the object on which the signal is emitted
|
|
|
|
|
* @uri: the URI to add to the speed dial
|
|
|
|
|
*
|
|
|
|
|
* Emitted when an URI is added to the spee dial page.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.7
|
|
|
|
|
*/
|
|
|
|
|
signals[ADD_SPEED_DIAL] = g_signal_new (
|
|
|
|
|
"add-speed-dial",
|
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
gobject_class->finalize = midori_view_finalize;
|
|
|
|
|
gobject_class->set_property = midori_view_set_property;
|
|
|
|
|
gobject_class->get_property = midori_view_get_property;
|
|
|
|
|
|
2010-05-06 20:27:29 +00:00
|
|
|
|
gtkwidget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
gtkwidget_class->focus_in_event = midori_view_focus_in_event;
|
|
|
|
|
|
2009-01-16 04:19:43 +00:00
|
|
|
|
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_URI,
|
|
|
|
|
g_param_spec_string (
|
|
|
|
|
"uri",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Uri",
|
|
|
|
|
"The URI of the currently loaded page",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
"about:blank",
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_TITLE,
|
|
|
|
|
g_param_spec_string (
|
|
|
|
|
"title",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Title",
|
|
|
|
|
"The title of the currently loaded page",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
NULL,
|
2011-01-11 19:44:34 +00:00
|
|
|
|
flags));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2010-04-13 21:44:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView:security:
|
|
|
|
|
*
|
|
|
|
|
* The security status of the loaded page.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.5
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SECURITY,
|
|
|
|
|
g_param_spec_enum (
|
|
|
|
|
"security",
|
|
|
|
|
"Security",
|
|
|
|
|
"The security of the currently loaded page",
|
|
|
|
|
MIDORI_TYPE_SECURITY,
|
|
|
|
|
MIDORI_SECURITY_NONE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2009-01-02 01:28:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView:mime-type:
|
|
|
|
|
*
|
|
|
|
|
* The MIME type of the currently loaded page.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.2
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_MIME_TYPE,
|
|
|
|
|
g_param_spec_string (
|
|
|
|
|
"mime-type",
|
|
|
|
|
"MIME Type",
|
|
|
|
|
"The MIME type of the currently loaded page",
|
|
|
|
|
"text/html",
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2009-01-02 01:28:04 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_ICON,
|
|
|
|
|
g_param_spec_object (
|
|
|
|
|
"icon",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Icon",
|
|
|
|
|
"The icon of the view",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
GDK_TYPE_PIXBUF,
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_LOAD_STATUS,
|
|
|
|
|
g_param_spec_enum (
|
|
|
|
|
"load-status",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Load Status",
|
|
|
|
|
"The current loading status",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
MIDORI_TYPE_LOAD_STATUS,
|
|
|
|
|
MIDORI_LOAD_FINISHED,
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_PROGRESS,
|
|
|
|
|
g_param_spec_double (
|
|
|
|
|
"progress",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Progress",
|
|
|
|
|
"The current loading progress",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
0.0, 1.0, 0.0,
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-07-21 21:57:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView:minimized:
|
|
|
|
|
*
|
|
|
|
|
* Whether the view is minimized or in normal state.
|
|
|
|
|
*
|
|
|
|
|
* Minimizing a view indicates that only the icon should
|
|
|
|
|
* be advertised rather than the full blown tab label and
|
|
|
|
|
* it might otherwise be presented specially.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.8
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_MINIMIZED,
|
|
|
|
|
g_param_spec_boolean (
|
|
|
|
|
"minimized",
|
|
|
|
|
"Minimized",
|
|
|
|
|
"Whether the view is minimized or in normal state",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_ZOOM_LEVEL,
|
|
|
|
|
g_param_spec_float (
|
|
|
|
|
"zoom-level",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Zoom Level",
|
|
|
|
|
"The current zoom level",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
G_MINFLOAT,
|
|
|
|
|
G_MAXFLOAT,
|
|
|
|
|
1.0f,
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-05-03 01:11:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* MidoriView:news-feeds:
|
|
|
|
|
*
|
|
|
|
|
* The news feeds advertised by the currently loaded page.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.7
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2008-11-23 04:19:43 +00:00
|
|
|
|
PROP_NEWS_FEEDS,
|
|
|
|
|
g_param_spec_object (
|
|
|
|
|
"news-feeds",
|
|
|
|
|
"News Feeds",
|
|
|
|
|
"The list of available news feeds",
|
|
|
|
|
KATZE_TYPE_ARRAY,
|
2009-05-03 01:11:33 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-23 04:19:43 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_STATUSBAR_TEXT,
|
|
|
|
|
g_param_spec_string (
|
|
|
|
|
"statusbar-text",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Statusbar Text",
|
|
|
|
|
"The text displayed in the statusbar",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
"",
|
2009-01-16 04:19:43 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SETTINGS,
|
|
|
|
|
g_param_spec_object (
|
|
|
|
|
"settings",
|
2008-10-15 01:32:11 +00:00
|
|
|
|
"Settings",
|
|
|
|
|
"The associated settings",
|
2008-09-26 21:13:46 +00:00
|
|
|
|
MIDORI_TYPE_WEB_SETTINGS,
|
2009-01-02 01:28:04 +00:00
|
|
|
|
flags));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-15 15:26:09 +00:00
|
|
|
|
static void
|
2011-01-11 19:44:34 +00:00
|
|
|
|
midori_view_set_title (MidoriView* view, const gchar* title)
|
2009-05-15 15:26:09 +00:00
|
|
|
|
{
|
2011-04-25 19:04:28 +00:00
|
|
|
|
const gchar* display_title;
|
|
|
|
|
|
|
|
|
|
if (!title)
|
2011-04-29 00:58:45 +00:00
|
|
|
|
title = view->uri;
|
2011-10-19 07:26:58 +00:00
|
|
|
|
/* Work-around libSoup not setting a proper directory title */
|
|
|
|
|
else if (!strcmp (title, "OMG!") && g_str_has_prefix (view->uri, "file://"))
|
|
|
|
|
title = view->uri;
|
2011-04-25 19:04:28 +00:00
|
|
|
|
|
2011-01-11 19:44:34 +00:00
|
|
|
|
katze_assign (view->title, g_strdup (title));
|
2011-04-25 19:04:28 +00:00
|
|
|
|
|
|
|
|
|
/* Render filename as title of patches */
|
|
|
|
|
if (title && (g_str_has_suffix (title, ".diff")
|
|
|
|
|
|| g_str_has_suffix (title, ".patch")))
|
|
|
|
|
{
|
|
|
|
|
gchar* prefix = strrchr (title, '/');
|
|
|
|
|
if (prefix != NULL)
|
|
|
|
|
katze_assign (view->title, g_strdup (prefix + 1));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 05:49:04 +00:00
|
|
|
|
#ifndef G_OS_WIN32
|
2009-05-22 02:01:56 +00:00
|
|
|
|
/* If left-to-right text is combined with right-to-left text the default
|
|
|
|
|
behaviour of Pango can result in awkwardly aligned text. For example
|
|
|
|
|
"بستيان نوصر (hadess) | An era comes to an end - Midori" becomes
|
|
|
|
|
"hadess) | An era comes to an end - Midori) بستيان نوصر". So to prevent
|
|
|
|
|
this we insert an LRE character before the title which indicates that
|
|
|
|
|
we want left-to-right but retains the direction of right-to-left text. */
|
2011-04-25 19:04:28 +00:00
|
|
|
|
if (title && !g_str_has_prefix (title, ""))
|
2009-05-22 02:01:56 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* new_title = g_strconcat ("", view->title, NULL);
|
|
|
|
|
katze_assign (view->title, new_title);
|
|
|
|
|
}
|
2009-07-20 05:49:04 +00:00
|
|
|
|
#endif
|
2011-04-25 19:04:28 +00:00
|
|
|
|
|
|
|
|
|
display_title = midori_view_get_display_title (view);
|
2009-05-15 15:26:09 +00:00
|
|
|
|
if (view->tab_label)
|
|
|
|
|
{
|
|
|
|
|
/* If the title starts with the presumed name of the website, we
|
|
|
|
|
ellipsize differently, to emphasize the subtitle */
|
|
|
|
|
if (gtk_label_get_angle (GTK_LABEL (view->tab_title)) == 0.0)
|
|
|
|
|
{
|
|
|
|
|
SoupURI* uri = soup_uri_new (view->uri);
|
|
|
|
|
const gchar* host = uri ? (uri->host ? uri->host : "") : "";
|
|
|
|
|
const gchar* name = g_str_has_prefix (host, "www.") ? &host[4] : host;
|
|
|
|
|
guint i = 0;
|
|
|
|
|
while (name[i++])
|
|
|
|
|
if (name[i] == '.')
|
|
|
|
|
break;
|
2011-04-25 19:04:28 +00:00
|
|
|
|
if (!g_ascii_strncasecmp (display_title, name, i))
|
2009-05-15 15:26:09 +00:00
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (view->tab_title), PANGO_ELLIPSIZE_START);
|
|
|
|
|
else
|
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (view->tab_title), PANGO_ELLIPSIZE_END);
|
|
|
|
|
if (uri)
|
|
|
|
|
soup_uri_free (uri);
|
|
|
|
|
}
|
2011-04-25 19:04:28 +00:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->tab_title), display_title);
|
|
|
|
|
gtk_widget_set_tooltip_text (view->tab_icon, display_title);
|
|
|
|
|
gtk_widget_set_tooltip_text (view->tab_title, display_title);
|
2009-05-15 15:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (view->menu_item)
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (
|
2011-04-25 19:04:28 +00:00
|
|
|
|
view->menu_item))), display_title);
|
|
|
|
|
katze_item_set_name (view->item, display_title);
|
2009-05-15 15:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-26 12:59:54 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_apply_icon (MidoriView* view,
|
|
|
|
|
GdkPixbuf* icon,
|
|
|
|
|
const gchar* icon_name)
|
|
|
|
|
{
|
2010-07-22 02:12:20 +00:00
|
|
|
|
katze_item_set_icon (view->item, icon_name);
|
2009-12-26 12:59:54 +00:00
|
|
|
|
katze_object_assign (view->icon, icon);
|
|
|
|
|
g_object_notify (G_OBJECT (view), "icon");
|
|
|
|
|
|
|
|
|
|
if (view->tab_icon)
|
|
|
|
|
{
|
|
|
|
|
if (icon_name)
|
|
|
|
|
katze_throbber_set_static_icon_name (KATZE_THROBBER (view->tab_icon),
|
|
|
|
|
icon_name);
|
|
|
|
|
else
|
|
|
|
|
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
|
|
|
|
|
view->icon);
|
|
|
|
|
}
|
|
|
|
|
if (view->menu_item)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* image;
|
|
|
|
|
if (icon_name)
|
|
|
|
|
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
|
|
|
|
|
else
|
|
|
|
|
image = gtk_image_new_from_pixbuf (view->icon);
|
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (view->menu_item), image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_mime_icon (MidoriView* view,
|
|
|
|
|
GtkIconTheme* icon_theme,
|
2009-01-02 01:28:04 +00:00
|
|
|
|
const gchar* format,
|
|
|
|
|
const gchar* part1,
|
2009-12-26 12:59:54 +00:00
|
|
|
|
const gchar* part2)
|
2009-01-02 01:28:04 +00:00
|
|
|
|
{
|
2009-12-26 12:59:54 +00:00
|
|
|
|
gchar* icon_name;
|
2009-01-02 01:28:04 +00:00
|
|
|
|
GdkPixbuf* icon;
|
|
|
|
|
|
2009-12-26 12:59:54 +00:00
|
|
|
|
icon_name = part2 ? g_strdup_printf (format, part1, part2)
|
2009-01-02 01:28:04 +00:00
|
|
|
|
: g_strdup_printf (format, part1);
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (!(icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 16, 0, NULL)))
|
|
|
|
|
{
|
|
|
|
|
g_free (icon_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_ref (icon);
|
|
|
|
|
midori_view_apply_icon (view, icon, icon_name);
|
|
|
|
|
g_free (icon_name);
|
|
|
|
|
return TRUE;
|
2009-01-02 01:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_icon (MidoriView* view,
|
|
|
|
|
GdkPixbuf* icon)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2009-12-26 12:59:54 +00:00
|
|
|
|
GdkScreen* screen;
|
|
|
|
|
GtkIconTheme* theme;
|
|
|
|
|
gchar** parts = NULL;
|
|
|
|
|
|
|
|
|
|
if (icon)
|
2009-01-02 01:28:04 +00:00
|
|
|
|
{
|
2009-12-26 12:59:54 +00:00
|
|
|
|
midori_view_apply_icon (view, icon, NULL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-02 01:28:04 +00:00
|
|
|
|
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (!((screen = gtk_widget_get_screen (GTK_WIDGET (view)))
|
|
|
|
|
&& (theme = gtk_icon_theme_get_for_screen (screen))))
|
|
|
|
|
return;
|
2011-10-10 19:58:19 +00:00
|
|
|
|
if (view->mime_type == NULL)
|
|
|
|
|
return;
|
2009-01-02 01:28:04 +00:00
|
|
|
|
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (!((parts = g_strsplit (view->mime_type, "/", 2)) && (*parts && parts[1])))
|
|
|
|
|
{
|
|
|
|
|
/* This is a hack to have a Find icon in the location while the
|
|
|
|
|
blank page has a File icon. */
|
|
|
|
|
icon = gtk_widget_render_icon (GTK_WIDGET (view),
|
|
|
|
|
GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
|
|
|
|
|
midori_view_apply_icon (view, icon, GTK_STOCK_FILE);
|
2011-10-10 19:55:12 +00:00
|
|
|
|
goto free_parts;
|
2009-01-02 01:28:04 +00:00
|
|
|
|
}
|
2008-12-21 16:52:10 +00:00
|
|
|
|
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (midori_view_mime_icon (view, theme, "%s-%s", *parts, parts[1]))
|
2011-10-10 19:55:12 +00:00
|
|
|
|
goto free_parts;
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (midori_view_mime_icon (view, theme, "gnome-mime-%s-%s", *parts, parts[1]))
|
2011-10-10 19:55:12 +00:00
|
|
|
|
goto free_parts;
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (midori_view_mime_icon (view, theme, "%s-x-generic", *parts, NULL))
|
2011-10-10 19:55:12 +00:00
|
|
|
|
goto free_parts;
|
2009-12-26 12:59:54 +00:00
|
|
|
|
if (midori_view_mime_icon (view, theme, "gnome-mime-%s-x-generic", *parts, NULL))
|
2011-10-10 19:55:12 +00:00
|
|
|
|
goto free_parts;
|
2009-12-26 12:59:54 +00:00
|
|
|
|
|
|
|
|
|
icon = gtk_widget_render_icon (GTK_WIDGET (view),
|
|
|
|
|
GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
|
|
|
|
|
midori_view_apply_icon (view, icon, NULL);
|
2011-10-10 19:55:12 +00:00
|
|
|
|
|
|
|
|
|
free_parts:
|
|
|
|
|
g_strfreev (parts);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-01 19:57:59 +00:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
gchar* icon_file;
|
|
|
|
|
gchar* icon_uri;
|
|
|
|
|
MidoriView* view;
|
|
|
|
|
} KatzeNetIconPriv;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
katze_net_icon_priv_free (KatzeNetIconPriv* priv)
|
|
|
|
|
{
|
|
|
|
|
g_free (priv->icon_file);
|
|
|
|
|
g_free (priv->icon_uri);
|
|
|
|
|
g_slice_free (KatzeNetIconPriv, priv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
katze_net_icon_status_cb (KatzeNetRequest* request,
|
|
|
|
|
KatzeNetIconPriv* priv)
|
|
|
|
|
{
|
|
|
|
|
switch (request->status)
|
|
|
|
|
{
|
|
|
|
|
case KATZE_NET_VERIFIED:
|
|
|
|
|
if (request->mime_type && strncmp (request->mime_type, "image/", 6))
|
|
|
|
|
{
|
|
|
|
|
katze_net_icon_priv_free (priv);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case KATZE_NET_MOVED:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
katze_net_icon_priv_free (priv);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
katze_net_icon_transfer_cb (KatzeNetRequest* request,
|
|
|
|
|
KatzeNetIconPriv* priv)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
|
FILE* fp;
|
|
|
|
|
GdkPixbuf* pixbuf_scaled;
|
|
|
|
|
gint icon_width, icon_height;
|
|
|
|
|
size_t ret;
|
|
|
|
|
GtkSettings* settings;
|
|
|
|
|
|
|
|
|
|
if (request->status == KATZE_NET_MOVED)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pixbuf = NULL;
|
|
|
|
|
if (request->data)
|
|
|
|
|
{
|
|
|
|
|
if ((fp = fopen (priv->icon_file, "wb")))
|
|
|
|
|
{
|
|
|
|
|
ret = fwrite (request->data, 1, request->length, fp);
|
|
|
|
|
fclose (fp);
|
|
|
|
|
if ((ret - request->length != 0))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Error writing to file %s "
|
|
|
|
|
"in katze_net_icon_transfer_cb()", priv->icon_file);
|
|
|
|
|
}
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (priv->icon_file, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
|
|
|
|
|
request->length, request->mime_type, NULL);
|
|
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (priv->view->memory,
|
|
|
|
|
g_strdup (priv->icon_file), pixbuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pixbuf)
|
|
|
|
|
{
|
|
|
|
|
midori_view_update_icon (priv->view, NULL);
|
|
|
|
|
katze_net_icon_priv_free (priv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings = gtk_widget_get_settings (priv->view->web_view);
|
|
|
|
|
gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
|
|
|
|
|
pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width, icon_height, GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
|
|
katze_assign (priv->view->icon_uri, g_strdup (priv->icon_uri));
|
|
|
|
|
midori_view_update_icon (priv->view, pixbuf_scaled);
|
|
|
|
|
katze_net_icon_priv_free (priv);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
_midori_web_view_load_icon (MidoriView* view)
|
|
|
|
|
{
|
2010-03-11 22:27:37 +00:00
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
|
gchar* icon_uri;
|
|
|
|
|
gchar* icon_file;
|
|
|
|
|
gint icon_width, icon_height;
|
|
|
|
|
GdkPixbuf* pixbuf_scaled;
|
|
|
|
|
GtkSettings* settings;
|
|
|
|
|
|
|
|
|
|
pixbuf = NULL;
|
|
|
|
|
icon_uri = g_strdup (view->icon_uri);
|
|
|
|
|
|
2011-10-28 20:47:17 +00:00
|
|
|
|
if (midori_uri_is_http (icon_uri) || midori_uri_is_http (view->uri))
|
2010-03-11 22:27:37 +00:00
|
|
|
|
{
|
|
|
|
|
if (!icon_uri)
|
|
|
|
|
{
|
|
|
|
|
guint i = 8;
|
|
|
|
|
while (view->uri[i] != '\0' && view->uri[i] != '/')
|
|
|
|
|
i++;
|
|
|
|
|
if (view->uri[i] == '/')
|
|
|
|
|
{
|
2010-10-14 19:06:45 +00:00
|
|
|
|
gchar* path = g_strndup (view->uri, i);
|
|
|
|
|
icon_uri = g_strdup_printf ("%s/favicon.ico", path);
|
|
|
|
|
g_free (path);
|
2010-03-11 22:27:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
icon_uri = g_strdup_printf ("%s/favicon.ico", view->uri);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-25 16:50:16 +00:00
|
|
|
|
icon_file = katze_net_get_cached_path (NULL, icon_uri, "icons");
|
2010-03-11 22:27:37 +00:00
|
|
|
|
if (g_hash_table_lookup_extended (view->memory,
|
|
|
|
|
icon_file, NULL, (gpointer)&pixbuf))
|
|
|
|
|
{
|
|
|
|
|
g_free (icon_file);
|
|
|
|
|
if (pixbuf)
|
|
|
|
|
{
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
katze_assign (view->icon_uri, icon_uri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
|
|
|
|
|
{
|
|
|
|
|
g_free (icon_file);
|
|
|
|
|
katze_assign (view->icon_uri, icon_uri);
|
|
|
|
|
}
|
2011-08-01 19:57:59 +00:00
|
|
|
|
else if (!view->special)
|
|
|
|
|
{
|
|
|
|
|
KatzeNetIconPriv* priv;
|
|
|
|
|
|
|
|
|
|
priv = g_slice_new (KatzeNetIconPriv);
|
|
|
|
|
priv->icon_file = icon_file;
|
|
|
|
|
priv->icon_uri = icon_uri;
|
|
|
|
|
priv->view = view;
|
|
|
|
|
|
|
|
|
|
katze_net_load_uri (NULL, icon_uri,
|
|
|
|
|
(KatzeNetStatusCb)katze_net_icon_status_cb,
|
|
|
|
|
(KatzeNetTransferCb)katze_net_icon_transfer_cb, priv);
|
|
|
|
|
}
|
2010-03-11 22:27:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
|
{
|
|
|
|
|
settings = gtk_widget_get_settings (view->web_view);
|
|
|
|
|
gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
|
|
|
|
|
&icon_width, &icon_height);
|
|
|
|
|
pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width,
|
|
|
|
|
icon_height, GDK_INTERP_BILINEAR);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
pixbuf = pixbuf_scaled;
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_icon (view, pixbuf);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_load_status (MidoriView* view,
|
|
|
|
|
MidoriLoadStatus load_status)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2008-12-21 16:52:10 +00:00
|
|
|
|
if (view->load_status == load_status)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-03-13 15:46:45 +00:00
|
|
|
|
if (load_status == MIDORI_LOAD_FINISHED)
|
|
|
|
|
view->special = FALSE;
|
|
|
|
|
|
2008-12-21 16:52:10 +00:00
|
|
|
|
view->load_status = load_status;
|
|
|
|
|
g_object_notify (G_OBJECT (view), "load-status");
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->tab_icon)
|
|
|
|
|
katze_throbber_set_animated (KATZE_THROBBER (view->tab_icon),
|
|
|
|
|
view->load_status != MIDORI_LOAD_FINISHED);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-20 18:56:52 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_view_navigation_decision_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
WebKitNetworkRequest* request,
|
|
|
|
|
WebKitWebNavigationAction* action,
|
|
|
|
|
WebKitWebPolicyDecision* decision,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-04-04 22:13:13 +00:00
|
|
|
|
JSContextRef js_context;
|
|
|
|
|
gchar* result;
|
2009-09-20 18:56:52 +00:00
|
|
|
|
const gchar* uri = webkit_network_request_get_uri (request);
|
2011-07-03 16:17:16 +00:00
|
|
|
|
if (g_str_has_prefix (uri, "geo:") && strstr (uri, ","))
|
2011-05-05 19:49:51 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* new_uri = sokoke_magic_uri (uri);
|
|
|
|
|
midori_view_set_uri (view, new_uri);
|
|
|
|
|
g_free (new_uri);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri))
|
2009-09-20 18:56:52 +00:00
|
|
|
|
{
|
2009-11-24 22:54:29 +00:00
|
|
|
|
if (sokoke_show_uri (gtk_widget_get_screen (GTK_WIDGET (web_view)),
|
|
|
|
|
uri, GDK_CURRENT_TIME, NULL))
|
|
|
|
|
{
|
|
|
|
|
webkit_web_policy_decision_ignore (decision);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2009-09-20 18:56:52 +00:00
|
|
|
|
}
|
2010-03-13 15:46:45 +00:00
|
|
|
|
view->special = FALSE;
|
2011-04-04 22:13:13 +00:00
|
|
|
|
|
|
|
|
|
/* Remove link labels */
|
|
|
|
|
js_context = webkit_web_frame_get_global_context (web_frame);
|
|
|
|
|
result = sokoke_js_script_eval (js_context,
|
2011-04-14 19:46:01 +00:00
|
|
|
|
"(function (links) {"
|
2011-04-04 22:13:13 +00:00
|
|
|
|
"if (links != undefined && links.length > 0) {"
|
|
|
|
|
" for (var i = links.length - 1; i >= 0; i--) {"
|
|
|
|
|
" var parent = links[i].parentNode;"
|
2011-04-14 19:46:01 +00:00
|
|
|
|
" parent.removeChild(links[i]); } } }) ("
|
|
|
|
|
"document.getElementsByClassName ('midoriHKD87346'));",
|
2011-04-04 22:13:13 +00:00
|
|
|
|
NULL);
|
|
|
|
|
g_free (result);
|
2011-04-04 22:40:15 +00:00
|
|
|
|
result = sokoke_js_script_eval (js_context,
|
2011-04-14 19:46:01 +00:00
|
|
|
|
"(function (links) {"
|
2011-04-04 22:40:15 +00:00
|
|
|
|
"if (links != undefined && links.length > 0) {"
|
|
|
|
|
" for (var i = links.length - 1; i >= 0; i--) {"
|
|
|
|
|
" var parent = links[i].parentNode;"
|
2011-04-14 19:46:01 +00:00
|
|
|
|
" parent.removeChild(links[i]); } } }) ("
|
|
|
|
|
"document.getElementsByClassName ('midori_access_key_fc04de'));",
|
2011-04-04 22:40:15 +00:00
|
|
|
|
NULL);
|
|
|
|
|
g_free (result);
|
2011-04-04 22:13:13 +00:00
|
|
|
|
view->find_links = -1;
|
|
|
|
|
|
2009-09-20 18:56:52 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_load_started_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2008-12-21 16:52:10 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_load_status (view, MIDORI_LOAD_PROVISIONAL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
view->progress = 0.0;
|
|
|
|
|
g_object_notify (G_OBJECT (view), "progress");
|
2008-12-21 16:52:10 +00:00
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_load_committed_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* uri;
|
2010-10-19 21:11:43 +00:00
|
|
|
|
GList* children;
|
2008-12-21 16:52:10 +00:00
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
uri = webkit_web_frame_get_uri (web_frame);
|
2009-01-17 18:38:00 +00:00
|
|
|
|
g_return_if_fail (uri != NULL);
|
2010-03-11 22:27:37 +00:00
|
|
|
|
katze_assign (view->icon_uri, NULL);
|
2009-09-25 21:57:44 +00:00
|
|
|
|
|
2010-10-19 21:11:43 +00:00
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (view));
|
|
|
|
|
for (; children; children = g_list_next (children))
|
|
|
|
|
if (g_object_get_data (G_OBJECT (children->data), "midori-infobar-cb"))
|
|
|
|
|
gtk_widget_destroy (children->data);
|
2011-04-13 21:56:00 +00:00
|
|
|
|
view->alerts = 0;
|
2010-10-11 20:52:07 +00:00
|
|
|
|
|
2010-07-22 02:12:20 +00:00
|
|
|
|
if (g_strcmp0 (uri, katze_item_get_uri (view->item)))
|
|
|
|
|
{
|
2011-10-19 07:53:18 +00:00
|
|
|
|
katze_assign (view->uri, midori_uri_format_for_display (uri));
|
2010-07-22 02:12:20 +00:00
|
|
|
|
katze_item_set_uri (view->item, uri);
|
|
|
|
|
}
|
2009-09-25 21:57:44 +00:00
|
|
|
|
|
2010-07-21 19:28:45 +00:00
|
|
|
|
katze_item_set_added (view->item, time (NULL));
|
2010-07-23 21:11:38 +00:00
|
|
|
|
katze_item_set_meta_integer (view->item, "history-step", -1);
|
2009-09-25 21:57:44 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "uri");
|
|
|
|
|
g_object_set (view, "title", NULL, NULL);
|
|
|
|
|
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_icon (view, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2010-04-13 21:44:21 +00:00
|
|
|
|
if (!strncmp (uri, "https", 5))
|
|
|
|
|
{
|
2011-06-08 22:45:34 +00:00
|
|
|
|
#if defined (HAVE_LIBSOUP_2_29_91)
|
2010-04-13 21:44:21 +00:00
|
|
|
|
WebKitWebDataSource *source;
|
|
|
|
|
WebKitNetworkRequest *request;
|
|
|
|
|
SoupMessage *message;
|
|
|
|
|
|
|
|
|
|
source = webkit_web_frame_get_data_source (web_frame);
|
|
|
|
|
request = webkit_web_data_source_get_request (source);
|
|
|
|
|
message = webkit_network_request_get_message (request);
|
|
|
|
|
|
|
|
|
|
if (message
|
|
|
|
|
&& soup_message_get_flags (message) & SOUP_MESSAGE_CERTIFICATE_TRUSTED)
|
|
|
|
|
view->security = MIDORI_SECURITY_TRUSTED;
|
|
|
|
|
else
|
2010-10-20 21:48:36 +00:00
|
|
|
|
#endif
|
2010-04-13 21:44:21 +00:00
|
|
|
|
view->security = MIDORI_SECURITY_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
view->security = MIDORI_SECURITY_NONE;
|
|
|
|
|
g_object_notify (G_OBJECT (view), "security");
|
|
|
|
|
|
2010-10-25 21:54:19 +00:00
|
|
|
|
view->find_links = -1;
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_load_status (view, MIDORI_LOAD_COMMITTED);
|
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (view));
|
2010-04-13 21:44:21 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_progress_changed_cb (WebKitWebView* web_view,
|
|
|
|
|
gint progress,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
view->progress = progress ? progress / 100.0 : 0.0;
|
|
|
|
|
g_object_notify (G_OBJECT (view), "progress");
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-21 20:56:00 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_web_view_resource_request_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
WebKitWebResource* web_resource,
|
|
|
|
|
WebKitNetworkRequest* request,
|
|
|
|
|
WebKitNetworkResponse* response,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* uri = webkit_network_request_get_uri (request);
|
|
|
|
|
|
|
|
|
|
/* Only apply custom URIs to special pages for security purposes */
|
2010-03-13 15:46:45 +00:00
|
|
|
|
if (!view->special)
|
2009-10-21 20:56:00 +00:00
|
|
|
|
return;
|
2010-02-03 21:18:51 +00:00
|
|
|
|
|
2009-10-21 20:56:00 +00:00
|
|
|
|
if (g_str_has_prefix (uri, "res://"))
|
|
|
|
|
{
|
2011-10-28 23:16:08 +00:00
|
|
|
|
gchar* filepath = sokoke_find_data_filename (&uri[6], TRUE);
|
|
|
|
|
gchar* file_uri = g_filename_to_uri (filepath, NULL, NULL);
|
2009-10-21 20:56:00 +00:00
|
|
|
|
g_free (filepath);
|
|
|
|
|
webkit_network_request_set_uri (request, file_uri);
|
|
|
|
|
g_free (file_uri);
|
|
|
|
|
}
|
|
|
|
|
else if (g_str_has_prefix (uri, "stock://"))
|
|
|
|
|
{
|
2010-05-20 23:17:43 +00:00
|
|
|
|
GdkPixbuf* pixbuf;
|
2009-10-21 20:56:00 +00:00
|
|
|
|
const gchar* icon_name = &uri[8] ? &uri[8] : "";
|
2010-05-20 23:17:43 +00:00
|
|
|
|
gint icon_size = GTK_ICON_SIZE_MENU;
|
2011-04-17 01:32:35 +00:00
|
|
|
|
GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (view));
|
|
|
|
|
GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
|
gint real_icon_size;
|
|
|
|
|
GtkIconInfo* icon_info;
|
|
|
|
|
const gchar* icon_filename;
|
2009-10-21 20:56:00 +00:00
|
|
|
|
|
|
|
|
|
if (g_ascii_isalpha (icon_name[0]))
|
2010-05-20 23:17:43 +00:00
|
|
|
|
icon_size = strstr (icon_name, "dialog") ?
|
|
|
|
|
GTK_ICON_SIZE_DIALOG : GTK_ICON_SIZE_BUTTON;
|
2009-10-21 20:56:00 +00:00
|
|
|
|
else if (g_ascii_isdigit (icon_name[0]))
|
|
|
|
|
{
|
|
|
|
|
guint i = 0;
|
|
|
|
|
while (icon_name[i])
|
|
|
|
|
if (icon_name[i++] == '/')
|
|
|
|
|
{
|
|
|
|
|
gchar* size = g_strndup (icon_name, i - 1);
|
|
|
|
|
icon_size = atoi (size);
|
2010-05-20 23:17:43 +00:00
|
|
|
|
/* Compatibility: map pixel to symbolic size */
|
|
|
|
|
if (icon_size == 16)
|
|
|
|
|
icon_size = GTK_ICON_SIZE_MENU;
|
2009-10-21 20:56:00 +00:00
|
|
|
|
g_free (size);
|
|
|
|
|
icon_name = &icon_name[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 01:32:35 +00:00
|
|
|
|
/* If available, load SVG icon as SVG markup */
|
2011-05-05 23:26:37 +00:00
|
|
|
|
gtk_icon_size_lookup_for_settings (
|
2011-04-17 01:32:35 +00:00
|
|
|
|
gtk_widget_get_settings (GTK_WIDGET (view)),
|
|
|
|
|
icon_size, &real_icon_size, &real_icon_size);
|
|
|
|
|
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name,
|
|
|
|
|
real_icon_size, GTK_ICON_LOOKUP_FORCE_SVG);
|
|
|
|
|
icon_filename = icon_info ? gtk_icon_info_get_filename (icon_info) : NULL;
|
|
|
|
|
if (icon_filename && g_str_has_suffix (icon_filename, ".svg"))
|
|
|
|
|
{
|
|
|
|
|
gchar* buffer;
|
|
|
|
|
gsize buffer_size;
|
|
|
|
|
if (g_file_get_contents (icon_filename, &buffer, &buffer_size, NULL))
|
|
|
|
|
{
|
|
|
|
|
gchar* encoded = g_base64_encode ((guchar*)buffer, buffer_size);
|
|
|
|
|
gchar* data_uri = g_strconcat ("data:image/svg+xml;base64,", encoded, NULL);
|
|
|
|
|
g_free (buffer);
|
|
|
|
|
g_free (encoded);
|
|
|
|
|
webkit_network_request_set_uri (request, data_uri);
|
|
|
|
|
g_free (data_uri);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Render icon as a PNG at the desired size */
|
2010-05-20 23:17:43 +00:00
|
|
|
|
pixbuf = gtk_widget_render_icon (GTK_WIDGET (view), icon_name, icon_size, NULL);
|
|
|
|
|
if (!pixbuf)
|
|
|
|
|
pixbuf = gtk_widget_render_icon (GTK_WIDGET (view),
|
|
|
|
|
GTK_STOCK_MISSING_IMAGE, icon_size, NULL);
|
|
|
|
|
if (pixbuf)
|
2009-10-21 20:56:00 +00:00
|
|
|
|
{
|
2010-05-20 23:17:43 +00:00
|
|
|
|
gboolean success;
|
|
|
|
|
gchar* buffer;
|
|
|
|
|
gsize buffer_size;
|
|
|
|
|
gchar* encoded;
|
|
|
|
|
gchar* data_uri;
|
|
|
|
|
|
|
|
|
|
success = gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &buffer_size, "png", NULL, NULL);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
if (!success)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
encoded = g_base64_encode ((guchar*)buffer, buffer_size);
|
|
|
|
|
g_free (buffer);
|
|
|
|
|
data_uri = g_strconcat ("data:image/png;base64,", encoded, NULL);
|
|
|
|
|
g_free (encoded);
|
|
|
|
|
webkit_network_request_set_uri (request, data_uri);
|
|
|
|
|
g_free (data_uri);
|
|
|
|
|
return;
|
2009-10-21 20:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-13 23:31:10 +00:00
|
|
|
|
#define HAVE_GTK_INFO_BAR GTK_CHECK_VERSION (2, 18, 0)
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#define HAVE_OFFSCREEN GTK_CHECK_VERSION (2, 20, 0)
|
2010-10-13 23:31:10 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_GTK_INFO_BAR
|
2010-10-11 20:52:07 +00:00
|
|
|
|
static void
|
2010-10-13 23:31:10 +00:00
|
|
|
|
midori_view_infobar_response_cb (GtkWidget* infobar,
|
|
|
|
|
gint response,
|
|
|
|
|
gpointer data_object)
|
2010-10-11 20:52:07 +00:00
|
|
|
|
{
|
2010-10-13 23:31:10 +00:00
|
|
|
|
void (*response_cb) (GtkWidget*, gint, gpointer);
|
|
|
|
|
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
|
|
|
|
|
response_cb (infobar, response, data_object);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
gtk_widget_destroy (infobar);
|
|
|
|
|
}
|
2010-10-13 23:31:10 +00:00
|
|
|
|
#else
|
2010-10-11 20:52:07 +00:00
|
|
|
|
static void
|
2010-10-13 23:31:10 +00:00
|
|
|
|
midori_view_info_bar_button_cb (GtkWidget* button,
|
|
|
|
|
gpointer data_object)
|
2010-10-11 20:52:07 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget* infobar = gtk_widget_get_parent (gtk_widget_get_parent (button));
|
2010-10-13 23:31:10 +00:00
|
|
|
|
gint response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "midori-infobar-response"));
|
|
|
|
|
void (*response_cb) (GtkWidget*, gint, gpointer);
|
|
|
|
|
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
|
|
|
|
|
response_cb (infobar, response, data_object);
|
|
|
|
|
gtk_widget_destroy (infobar);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-10-19 21:11:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_add_info_bar
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @message_type: a #GtkMessageType
|
|
|
|
|
* @message: a message string
|
|
|
|
|
* @response_cb: a response callback
|
|
|
|
|
* @user_data: user data passed to the callback
|
|
|
|
|
* @first_button_text: button text or stock ID
|
|
|
|
|
* @...: first response ID, then more text - response ID pairs
|
|
|
|
|
*
|
|
|
|
|
* Adds an infobar (or equivalent) to the view. Activation of a
|
|
|
|
|
* button invokes the specified callback. The infobar is
|
|
|
|
|
* automatically destroyed if the location changes or reloads.
|
|
|
|
|
*
|
|
|
|
|
* Return value: an infobar widget
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.9
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
2010-10-13 23:31:10 +00:00
|
|
|
|
midori_view_add_info_bar (MidoriView* view,
|
|
|
|
|
GtkMessageType message_type,
|
|
|
|
|
const gchar* message,
|
|
|
|
|
GCallback response_cb,
|
2010-10-19 21:11:43 +00:00
|
|
|
|
gpointer data_object,
|
|
|
|
|
const gchar* first_button_text,
|
|
|
|
|
...)
|
2010-10-11 20:52:07 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget* infobar;
|
|
|
|
|
GtkWidget* action_area;
|
|
|
|
|
GtkWidget* content_area;
|
2011-04-21 18:51:03 +00:00
|
|
|
|
GtkWidget* label;
|
2010-10-19 21:11:43 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
const gchar* button_text;
|
2011-04-04 00:59:16 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (message != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (response_cb != NULL, NULL);
|
|
|
|
|
|
2010-10-19 21:11:43 +00:00
|
|
|
|
va_start (args, first_button_text);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_GTK_INFO_BAR
|
2010-10-19 21:11:43 +00:00
|
|
|
|
infobar = gtk_info_bar_new ();
|
|
|
|
|
for (button_text = first_button_text; button_text;
|
|
|
|
|
button_text = va_arg (args, const gchar*))
|
|
|
|
|
{
|
|
|
|
|
gint response_id = va_arg (args, gint);
|
|
|
|
|
gtk_info_bar_add_button (GTK_INFO_BAR (infobar),
|
|
|
|
|
button_text, response_id);
|
|
|
|
|
}
|
2010-10-13 23:31:10 +00:00
|
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), message_type);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar));
|
|
|
|
|
action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (infobar));
|
2010-10-19 21:11:43 +00:00
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
|
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
g_signal_connect (infobar, "response",
|
2010-10-19 21:11:43 +00:00
|
|
|
|
G_CALLBACK (midori_view_infobar_response_cb), data_object);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
#else
|
|
|
|
|
infobar = gtk_hbox_new (FALSE, 0);
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (infobar), 4);
|
2010-10-19 21:11:43 +00:00
|
|
|
|
|
2010-10-11 20:52:07 +00:00
|
|
|
|
content_area = gtk_hbox_new (FALSE, 0);
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (infobar), content_area, TRUE, TRUE, 0);
|
2010-10-19 21:11:43 +00:00
|
|
|
|
action_area = gtk_hbutton_box_new ();
|
|
|
|
|
for (button_text = first_button_text; button_text;
|
|
|
|
|
button_text = va_arg (args, const gchar*))
|
|
|
|
|
{
|
|
|
|
|
gint response_id = va_arg (args, gint);
|
|
|
|
|
GtkWidget* button = gtk_button_new_with_mnemonic (button_text);
|
|
|
|
|
g_object_set_data (G_OBJECT (button), "midori-infobar-response",
|
|
|
|
|
GINT_TO_POINTER (response_id));
|
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
|
G_CALLBACK (midori_view_info_bar_button_cb), data_object);
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (action_area), button, FALSE, FALSE, 0);
|
|
|
|
|
if (response_id == GTK_RESPONSE_HELP)
|
|
|
|
|
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area),
|
|
|
|
|
button, TRUE);
|
|
|
|
|
}
|
2010-10-11 20:52:07 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (infobar), action_area, FALSE, FALSE, 0);
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-10-19 21:11:43 +00:00
|
|
|
|
va_end (args);
|
2011-04-21 18:51:03 +00:00
|
|
|
|
label = gtk_label_new (message);
|
2011-07-26 19:44:17 +00:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2011-04-21 18:51:03 +00:00
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (content_area), label);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
gtk_widget_show_all (infobar);
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (view), infobar, FALSE, FALSE, 0);
|
|
|
|
|
gtk_box_reorder_child (GTK_BOX (view), infobar, 0);
|
2010-10-13 23:31:10 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (infobar), "midori-infobar-cb", response_cb);
|
|
|
|
|
return infobar;
|
|
|
|
|
}
|
2010-10-11 20:52:07 +00:00
|
|
|
|
|
2010-10-13 23:31:10 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_database_response_cb (GtkWidget* infobar,
|
|
|
|
|
gint response,
|
|
|
|
|
WebKitWebDatabase* database)
|
|
|
|
|
{
|
|
|
|
|
if (response != GTK_RESPONSE_ACCEPT)
|
|
|
|
|
{
|
|
|
|
|
WebKitSecurityOrigin* origin = webkit_web_database_get_security_origin (database);
|
|
|
|
|
webkit_security_origin_set_web_database_quota (origin, 0);
|
|
|
|
|
webkit_web_database_remove (database);
|
|
|
|
|
}
|
|
|
|
|
/* TODO: Remember the decision */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_web_view_database_quota_exceeded_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
WebKitWebDatabase* database,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* uri = webkit_web_frame_get_uri (web_frame);
|
2011-11-18 00:42:02 +00:00
|
|
|
|
gchar* hostname = midori_uri_parse_hostname (uri, NULL);
|
2010-10-13 23:31:10 +00:00
|
|
|
|
gchar* message = g_strdup_printf (_("%s wants to save an HTML5 database."),
|
|
|
|
|
hostname && *hostname ? hostname : uri);
|
|
|
|
|
midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION, message,
|
2010-10-19 21:11:43 +00:00
|
|
|
|
G_CALLBACK (midori_view_database_response_cb), database,
|
2010-10-13 23:31:10 +00:00
|
|
|
|
_("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
|
2010-10-19 21:11:43 +00:00
|
|
|
|
NULL);
|
2011-11-18 00:42:02 +00:00
|
|
|
|
g_free (hostname);
|
2010-10-13 23:31:10 +00:00
|
|
|
|
g_free (message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 23)
|
|
|
|
|
static void
|
|
|
|
|
midori_view_location_response_cb (GtkWidget* infobar,
|
|
|
|
|
gint response,
|
|
|
|
|
WebKitGeolocationPolicyDecision* decision)
|
|
|
|
|
{
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
|
webkit_geolocation_policy_allow (decision);
|
|
|
|
|
else
|
|
|
|
|
webkit_geolocation_policy_deny (decision);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_view_geolocation_decision_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
WebKitGeolocationPolicyDecision* decision,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* uri = webkit_web_frame_get_uri (web_frame);
|
2011-11-18 00:42:02 +00:00
|
|
|
|
gchar* hostname = midori_uri_parse_hostname (uri, NULL);
|
2010-10-13 23:31:10 +00:00
|
|
|
|
gchar* message = g_strdup_printf (_("%s wants to know your location."),
|
|
|
|
|
hostname && *hostname ? hostname : uri);
|
2010-10-19 21:11:43 +00:00
|
|
|
|
midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION,
|
|
|
|
|
message, G_CALLBACK (midori_view_location_response_cb), decision,
|
2010-10-13 23:31:10 +00:00
|
|
|
|
_("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
|
2010-10-19 21:11:43 +00:00
|
|
|
|
NULL);
|
2011-11-18 00:42:02 +00:00
|
|
|
|
g_free (hostname);
|
2010-10-11 20:52:07 +00:00
|
|
|
|
g_free (message);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-05-15 21:32:59 +00:00
|
|
|
|
static void
|
2010-05-20 21:19:02 +00:00
|
|
|
|
midori_view_load_alternate_string (MidoriView* view,
|
|
|
|
|
const gchar* data,
|
|
|
|
|
const gchar* uri,
|
|
|
|
|
WebKitWebFrame* web_frame)
|
2010-05-15 21:32:59 +00:00
|
|
|
|
{
|
|
|
|
|
WebKitWebView* web_view = WEBKIT_WEB_VIEW (view->web_view);
|
2010-05-20 21:19:02 +00:00
|
|
|
|
if (!web_frame)
|
|
|
|
|
web_frame = webkit_web_view_get_main_frame (web_view);
|
2010-05-15 21:32:59 +00:00
|
|
|
|
view->special = TRUE;
|
|
|
|
|
webkit_web_frame_load_alternate_string (
|
2010-05-20 21:19:02 +00:00
|
|
|
|
web_frame, data, uri, uri);
|
2010-05-15 21:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-02 19:44:20 +00:00
|
|
|
|
static gboolean
|
2010-05-20 21:19:02 +00:00
|
|
|
|
midori_view_display_error (MidoriView* view,
|
|
|
|
|
const gchar* uri,
|
|
|
|
|
const gchar* title,
|
|
|
|
|
const gchar* message,
|
|
|
|
|
const gchar* description,
|
|
|
|
|
const gchar* try_again,
|
|
|
|
|
WebKitWebFrame* web_frame)
|
2009-05-02 19:44:20 +00:00
|
|
|
|
{
|
2011-10-28 23:16:08 +00:00
|
|
|
|
gchar* path = sokoke_find_data_filename ("error.html", TRUE);
|
2009-05-02 19:44:20 +00:00
|
|
|
|
gchar* template;
|
|
|
|
|
|
2009-07-20 06:43:23 +00:00
|
|
|
|
if (g_file_get_contents (path, &template, NULL, NULL))
|
2009-05-02 19:44:20 +00:00
|
|
|
|
{
|
2011-02-17 18:38:11 +00:00
|
|
|
|
gchar* title_escaped;
|
2009-05-02 19:44:20 +00:00
|
|
|
|
gchar* result;
|
|
|
|
|
|
2011-02-17 18:38:11 +00:00
|
|
|
|
title_escaped = g_markup_escape_text (title, -1);
|
2009-05-02 19:44:20 +00:00
|
|
|
|
result = sokoke_replace_variables (template,
|
2011-02-17 18:38:11 +00:00
|
|
|
|
"{title}", title_escaped,
|
2009-05-02 19:44:20 +00:00
|
|
|
|
"{message}", message,
|
2010-05-15 21:32:59 +00:00
|
|
|
|
"{description}", description,
|
|
|
|
|
"{tryagain}", try_again,
|
2011-05-20 20:04:11 +00:00
|
|
|
|
"{uri}", uri,
|
2009-05-08 11:13:39 +00:00
|
|
|
|
NULL);
|
2011-02-17 18:38:11 +00:00
|
|
|
|
g_free (title_escaped);
|
2009-05-02 19:44:20 +00:00
|
|
|
|
g_free (template);
|
|
|
|
|
|
2010-05-15 21:32:59 +00:00
|
|
|
|
midori_view_load_alternate_string (view,
|
2011-08-07 10:13:45 +00:00
|
|
|
|
result, uri, web_frame);
|
2010-05-15 21:32:59 +00:00
|
|
|
|
|
2009-05-02 19:44:20 +00:00
|
|
|
|
g_free (result);
|
2009-07-20 06:43:23 +00:00
|
|
|
|
g_free (path);
|
2009-05-02 19:44:20 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2009-07-20 06:43:23 +00:00
|
|
|
|
g_free (path);
|
2009-05-02 19:44:20 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2010-05-15 21:32:59 +00:00
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
webkit_web_view_load_error_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
const gchar* uri,
|
|
|
|
|
GError* error,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-04-07 18:59:08 +00:00
|
|
|
|
gchar* title;
|
|
|
|
|
gchar* message;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
switch (error->code)
|
|
|
|
|
{
|
|
|
|
|
case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD:
|
|
|
|
|
/* A plugin will take over. That's expected, it's not fatal. */
|
|
|
|
|
return FALSE;
|
2011-05-13 14:07:28 +00:00
|
|
|
|
case WEBKIT_NETWORK_ERROR_CANCELLED:
|
|
|
|
|
/* Mostly initiated by JS redirects. */
|
|
|
|
|
return FALSE;
|
2011-04-07 18:59:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
title = g_strdup_printf (_("Error - %s"), uri);
|
|
|
|
|
message = g_strdup_printf (_("The page '%s' couldn't be loaded."), uri);
|
|
|
|
|
result = midori_view_display_error (view, uri, title,
|
2010-05-20 21:19:02 +00:00
|
|
|
|
message, error->message, _("Try again"), web_frame);
|
2010-05-15 21:32:59 +00:00
|
|
|
|
g_free (message);
|
|
|
|
|
g_free (title);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-10-07 21:51:35 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_apply_scroll_position (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
if (view->scrollh > -2)
|
|
|
|
|
{
|
|
|
|
|
if (view->scrollh > 0)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (view->scrolled_window);
|
|
|
|
|
GtkAdjustment* adjustment = gtk_scrolled_window_get_hadjustment (scrolled);
|
2009-10-07 21:51:35 +00:00
|
|
|
|
gtk_adjustment_set_value (adjustment, view->scrollh);
|
|
|
|
|
}
|
|
|
|
|
view->scrollh = -3;
|
|
|
|
|
}
|
|
|
|
|
if (view->scrollv > -2)
|
|
|
|
|
{
|
|
|
|
|
if (view->scrollv > 0)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (view->scrolled_window);
|
|
|
|
|
GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment (scrolled);
|
2009-10-07 21:51:35 +00:00
|
|
|
|
gtk_adjustment_set_value (adjustment, view->scrollv);
|
|
|
|
|
}
|
|
|
|
|
view->scrollv = -3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_load_finished_cb (WebKitWebView* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2008-12-21 16:52:10 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (view));
|
|
|
|
|
|
2009-10-07 21:51:35 +00:00
|
|
|
|
midori_view_apply_scroll_position (view);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
view->progress = 1.0;
|
|
|
|
|
g_object_notify (G_OBJECT (view), "progress");
|
2008-12-21 16:52:10 +00:00
|
|
|
|
midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
|
|
|
|
|
|
2009-08-14 21:28:18 +00:00
|
|
|
|
if (1)
|
2009-04-13 20:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
|
2011-04-25 19:04:28 +00:00
|
|
|
|
/* Join news feeds into like this: URI1|title1,URI2|title2 */
|
2009-04-13 20:40:57 +00:00
|
|
|
|
gchar* value = sokoke_js_script_eval (js_context,
|
2009-12-07 21:31:43 +00:00
|
|
|
|
"(function (l) { var f = new Array (); for (i in l) "
|
2009-09-15 19:15:57 +00:00
|
|
|
|
"{ var t = l[i].type; var r = l[i].rel; "
|
2009-04-13 20:40:57 +00:00
|
|
|
|
"if (t && (t.indexOf ('rss') != -1 || t.indexOf ('atom') != -1)) "
|
2009-09-15 19:15:57 +00:00
|
|
|
|
"f.push (l[i].href + '|' + l[i].title);"
|
2010-05-02 10:09:54 +00:00
|
|
|
|
#if !WEBKIT_CHECK_VERSION (1, 1, 18)
|
|
|
|
|
"else if (r && r.indexOf ('icon') != -1) f.push (l[i].href); "
|
|
|
|
|
#endif
|
|
|
|
|
"} return f; })("
|
2009-12-07 21:31:43 +00:00
|
|
|
|
"document.getElementsByTagName ('link'));", NULL);
|
2009-05-03 01:11:33 +00:00
|
|
|
|
gchar** items = g_strsplit (value, ",", 0);
|
2009-06-19 01:06:22 +00:00
|
|
|
|
guint i = 0;
|
2009-08-14 21:28:18 +00:00
|
|
|
|
gchar* default_uri = NULL;
|
2009-05-03 01:11:33 +00:00
|
|
|
|
|
2011-10-10 19:58:19 +00:00
|
|
|
|
if (view->news_feeds != NULL)
|
|
|
|
|
katze_array_clear (view->news_feeds);
|
|
|
|
|
else
|
|
|
|
|
view->news_feeds = katze_array_new (KATZE_TYPE_ITEM);
|
2009-06-19 01:06:22 +00:00
|
|
|
|
if (items != NULL)
|
|
|
|
|
while (items[i] != NULL)
|
2009-05-03 01:11:33 +00:00
|
|
|
|
{
|
2009-06-19 01:06:22 +00:00
|
|
|
|
gchar** parts = g_strsplit (items[i], "|", 2);
|
2009-09-15 19:15:57 +00:00
|
|
|
|
if (parts == NULL)
|
|
|
|
|
;
|
|
|
|
|
else if (*parts && parts[1])
|
|
|
|
|
{
|
|
|
|
|
KatzeItem* item = g_object_new (KATZE_TYPE_ITEM,
|
|
|
|
|
"uri", parts[0], "name", parts[1], NULL);
|
|
|
|
|
katze_array_add_item (view->news_feeds, item);
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
if (!default_uri)
|
|
|
|
|
default_uri = g_strdup (parts[0]);
|
|
|
|
|
}
|
2010-05-02 10:09:54 +00:00
|
|
|
|
#if !WEBKIT_CHECK_VERSION (1, 1, 18)
|
2009-09-15 19:15:57 +00:00
|
|
|
|
else
|
2010-03-11 22:27:37 +00:00
|
|
|
|
katze_assign (view->icon_uri, g_strdup (*parts));
|
2010-05-02 10:09:54 +00:00
|
|
|
|
#endif
|
2009-09-15 19:15:57 +00:00
|
|
|
|
|
2009-05-03 01:11:33 +00:00
|
|
|
|
g_strfreev (parts);
|
2009-06-19 01:06:22 +00:00
|
|
|
|
i++;
|
2009-05-03 01:11:33 +00:00
|
|
|
|
}
|
|
|
|
|
g_strfreev (items);
|
2009-08-14 21:28:18 +00:00
|
|
|
|
g_object_set_data_full (G_OBJECT (view), "news-feeds", default_uri, g_free);
|
2009-05-14 22:58:58 +00:00
|
|
|
|
g_free (value);
|
2009-04-13 20:40:57 +00:00
|
|
|
|
/* Ensure load-status is notified again, whether it changed or not */
|
|
|
|
|
g_object_notify (G_OBJECT (view), "load-status");
|
|
|
|
|
}
|
2008-11-23 04:19:43 +00:00
|
|
|
|
|
2009-09-15 19:15:57 +00:00
|
|
|
|
_midori_web_view_load_icon (view);
|
|
|
|
|
|
2009-04-13 20:40:57 +00:00
|
|
|
|
g_object_thaw_notify (G_OBJECT (view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-02 10:09:54 +00:00
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 18)
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_notify_icon_uri_cb (WebKitWebView* web_view,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
const gchar* icon_uri = webkit_web_view_get_icon_uri (web_view);
|
|
|
|
|
katze_assign (view->icon_uri, g_strdup (icon_uri));
|
2010-05-02 10:09:54 +00:00
|
|
|
|
_midori_web_view_load_icon (view);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-02-27 00:48:06 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_notify_uri_cb (WebKitWebView* web_view,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
katze_assign (view->uri, g_strdup (webkit_web_view_get_uri (web_view)));
|
|
|
|
|
g_object_notify (G_OBJECT (view), "uri");
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-14 23:18:14 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_notify_title_cb (WebKitWebView* web_view,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
const gchar* title = webkit_web_view_get_title (web_view);
|
2011-01-11 19:44:34 +00:00
|
|
|
|
midori_view_set_title (view, title);
|
2009-05-14 23:18:14 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "title");
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_statusbar_text_changed_cb (WebKitWebView* web_view,
|
|
|
|
|
const gchar* text,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_object_set (G_OBJECT (view), "statusbar-text", text, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-22 21:58:16 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_view_leave_notify_event_cb (WebKitWebView* web_view,
|
|
|
|
|
GdkEventCrossing* event,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_object_set (G_OBJECT (view), "statusbar-text", NULL, NULL);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_hovering_over_link_cb (WebKitWebView* web_view,
|
|
|
|
|
const gchar* tooltip,
|
|
|
|
|
const gchar* link_uri,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-04-17 20:29:51 +00:00
|
|
|
|
#if !(WEBKIT_CHECK_VERSION (1, 3, 1) && defined (HAVE_LIBSOUP_2_29_3))
|
|
|
|
|
sokoke_prefetch_uri (view->settings, link_uri, NULL, NULL);
|
2010-01-01 16:53:58 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
katze_assign (view->link_uri, g_strdup (link_uri));
|
2009-09-30 21:54:40 +00:00
|
|
|
|
if (link_uri && g_str_has_prefix (link_uri, "mailto:"))
|
|
|
|
|
{
|
|
|
|
|
gchar* text = g_strdup_printf (_("Send a message to %s"), &link_uri[7]);
|
2009-12-23 22:13:25 +00:00
|
|
|
|
g_object_set (view, "statusbar-text", text, NULL);
|
2009-09-30 21:54:40 +00:00
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
else
|
2009-12-23 22:13:25 +00:00
|
|
|
|
g_object_set (view, "statusbar-text", link_uri, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-20 22:08:10 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_ensure_link_uri (MidoriView* view,
|
|
|
|
|
gint *x,
|
2011-01-02 00:24:50 +00:00
|
|
|
|
gint *y,
|
|
|
|
|
GdkEventButton* event)
|
2010-09-20 22:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2010-10-18 20:42:10 +00:00
|
|
|
|
if (view->web_view && gtk_widget_get_window (view->web_view))
|
2010-09-20 22:08:10 +00:00
|
|
|
|
{
|
2011-01-02 00:24:50 +00:00
|
|
|
|
GdkEventButton ev;
|
|
|
|
|
|
|
|
|
|
if (!event) {
|
|
|
|
|
gint ex, ey;
|
|
|
|
|
event = &ev;
|
|
|
|
|
gdk_window_get_pointer (gtk_widget_get_window (view->web_view), &ex, &ey, NULL);
|
|
|
|
|
event->x = ex;
|
|
|
|
|
event->y = ey;
|
|
|
|
|
}
|
2010-09-20 22:08:10 +00:00
|
|
|
|
|
|
|
|
|
if (x != NULL)
|
2011-01-02 00:24:50 +00:00
|
|
|
|
*x = event->x;
|
2010-09-20 22:08:10 +00:00
|
|
|
|
if (y != NULL)
|
2011-01-02 00:24:50 +00:00
|
|
|
|
*y = event->y;
|
2010-09-20 22:08:10 +00:00
|
|
|
|
|
2010-11-23 21:57:47 +00:00
|
|
|
|
katze_object_assign (view->hit_test,
|
|
|
|
|
g_object_ref (
|
|
|
|
|
webkit_web_view_get_hit_test_result (
|
2011-01-02 00:24:50 +00:00
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view), event)));
|
2010-09-20 22:08:10 +00:00
|
|
|
|
katze_assign (view->link_uri,
|
|
|
|
|
katze_object_get_string (view->hit_test, "link-uri"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-11 23:16:03 +00:00
|
|
|
|
#define MIDORI_KEYS_MODIFIER_MASK (GDK_SHIFT_MASK | GDK_CONTROL_MASK \
|
2011-04-16 02:08:16 +00:00
|
|
|
|
| GDK_MOD1_MASK | GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK )
|
2008-11-11 23:16:03 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_widget_button_press_event_cb (WebKitWebView* web_view,
|
|
|
|
|
GdkEventButton* event,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
GtkClipboard* clipboard;
|
|
|
|
|
gchar* uri;
|
|
|
|
|
gchar* new_uri;
|
|
|
|
|
const gchar* link_uri;
|
2008-10-02 22:49:16 +00:00
|
|
|
|
gboolean background;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-11-11 23:16:03 +00:00
|
|
|
|
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
|
2011-01-02 00:24:50 +00:00
|
|
|
|
midori_view_ensure_link_uri (view, NULL, NULL, event);
|
2010-07-21 17:47:08 +00:00
|
|
|
|
link_uri = midori_view_get_link_uri (view);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
switch (event->button)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
if (!link_uri)
|
|
|
|
|
return FALSE;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (MIDORI_MOD_NEW_TAB (event->state))
|
2008-11-11 21:12:26 +00:00
|
|
|
|
{
|
|
|
|
|
/* Open link in new tab */
|
|
|
|
|
background = view->open_tabs_in_the_background;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (MIDORI_MOD_BACKGROUND (event->state))
|
2008-11-11 23:47:09 +00:00
|
|
|
|
background = !background;
|
2009-04-13 01:38:28 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
|
2008-11-11 21:12:26 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2010-01-22 22:11:00 +00:00
|
|
|
|
else if (MIDORI_MOD_NEW_WINDOW (event->state))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
/* Open link in new window */
|
2009-04-13 01:38:28 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_WINDOW], 0, link_uri);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (link_uri)
|
|
|
|
|
{
|
|
|
|
|
/* Open link in new tab */
|
2008-10-02 22:49:16 +00:00
|
|
|
|
background = view->open_tabs_in_the_background;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (MIDORI_MOD_BACKGROUND (event->state))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
background = !background;
|
2009-04-13 01:38:28 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2010-01-22 22:11:00 +00:00
|
|
|
|
else if (MIDORI_MOD_SCROLL (event->state))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0);
|
|
|
|
|
return FALSE; /* Allow Ctrl + Middle click */
|
|
|
|
|
}
|
2008-10-02 22:49:16 +00:00
|
|
|
|
else if (view->middle_click_opens_selection)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2009-09-20 19:49:57 +00:00
|
|
|
|
gboolean is_editable;
|
2009-09-18 21:47:31 +00:00
|
|
|
|
WebKitHitTestResult* result;
|
|
|
|
|
WebKitHitTestResultContext context;
|
|
|
|
|
|
|
|
|
|
result = webkit_web_view_get_hit_test_result (web_view, event);
|
|
|
|
|
context = katze_object_get_int (result, "context");
|
|
|
|
|
is_editable = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
|
|
|
|
|
g_object_unref (result);
|
|
|
|
|
if (is_editable)
|
2009-09-04 21:37:00 +00:00
|
|
|
|
return FALSE;
|
2009-09-18 21:47:31 +00:00
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
clipboard = gtk_clipboard_get_for_display (
|
|
|
|
|
gtk_widget_get_display (GTK_WIDGET (view)),
|
|
|
|
|
GDK_SELECTION_PRIMARY);
|
2009-12-07 19:35:11 +00:00
|
|
|
|
if ((uri = gtk_clipboard_wait_for_text (clipboard)))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2009-09-18 21:47:31 +00:00
|
|
|
|
guint i = 0;
|
2009-04-13 01:38:28 +00:00
|
|
|
|
while (uri[i++] != '\0')
|
|
|
|
|
if (uri[i] == '\n' || uri[i] == '\r')
|
|
|
|
|
uri[i] = ' ';
|
2010-01-22 22:11:00 +00:00
|
|
|
|
g_strstrip (uri);
|
|
|
|
|
|
|
|
|
|
/* Hold Alt to search for the selected word */
|
|
|
|
|
if (event->state & GDK_MOD1_MASK)
|
2009-12-07 19:35:11 +00:00
|
|
|
|
{
|
2010-02-09 17:13:47 +00:00
|
|
|
|
new_uri = sokoke_magic_uri (uri);
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (!new_uri)
|
|
|
|
|
{
|
2011-04-25 23:29:26 +00:00
|
|
|
|
gchar* search = katze_object_get_string (
|
|
|
|
|
view->settings, "location-entry-search");
|
2011-10-19 07:53:18 +00:00
|
|
|
|
new_uri = midori_uri_for_search (search, uri);
|
2011-04-25 23:29:26 +00:00
|
|
|
|
g_free (search);
|
2010-01-22 22:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
katze_assign (uri, new_uri);
|
2009-12-07 19:35:11 +00:00
|
|
|
|
}
|
2011-10-19 07:53:18 +00:00
|
|
|
|
else if (!midori_uri_is_location (uri))
|
2010-03-02 23:31:35 +00:00
|
|
|
|
{
|
|
|
|
|
g_free (uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2010-01-22 22:11:00 +00:00
|
|
|
|
|
|
|
|
|
if (MIDORI_MOD_NEW_TAB (event->state))
|
2008-10-02 22:49:16 +00:00
|
|
|
|
{
|
|
|
|
|
background = view->open_tabs_in_the_background;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (MIDORI_MOD_BACKGROUND (event->state))
|
2008-10-02 22:49:16 +00:00
|
|
|
|
background = !background;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, uri, background);
|
2008-10-02 22:49:16 +00:00
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2010-01-22 22:11:00 +00:00
|
|
|
|
midori_view_set_uri (MIDORI_VIEW (view), uri);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (view));
|
|
|
|
|
}
|
2010-03-02 23:31:35 +00:00
|
|
|
|
g_free (uri);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return TRUE;
|
2010-01-22 22:11:00 +00:00
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2010-01-03 22:57:21 +00:00
|
|
|
|
case 3:
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
|
{
|
|
|
|
|
/* Ctrl + Right-click suppresses javascript button handling */
|
|
|
|
|
GtkWidget* menu = gtk_menu_new ();
|
|
|
|
|
midori_view_populate_popup (view, menu, TRUE);
|
|
|
|
|
katze_widget_popup (GTK_WIDGET (web_view), GTK_MENU (menu), event,
|
|
|
|
|
KATZE_MENU_POSITION_CURSOR);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-12-08 22:45:38 +00:00
|
|
|
|
case 8:
|
|
|
|
|
midori_view_go_back (view);
|
|
|
|
|
return TRUE;
|
|
|
|
|
case 9:
|
|
|
|
|
midori_view_go_forward (view);
|
|
|
|
|
return TRUE;
|
2009-04-23 02:08:28 +00:00
|
|
|
|
/*
|
|
|
|
|
* On some fancier mice the scroll wheel can be used to scroll horizontally.
|
|
|
|
|
* A middle click usually registers both a middle click (2) and a
|
|
|
|
|
* horizontal scroll (11 or 12).
|
|
|
|
|
* We catch horizontal scrolls and ignore them to prevent middle clicks from
|
|
|
|
|
* accidentally being interpreted as first button clicks.
|
|
|
|
|
*/
|
|
|
|
|
case 11:
|
|
|
|
|
return TRUE;
|
|
|
|
|
case 12:
|
|
|
|
|
return TRUE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-06 22:48:19 +00:00
|
|
|
|
/* We propagate the event, since it may otherwise be stuck in WebKit */
|
|
|
|
|
g_signal_emit_by_name (view, "event", event, &background);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 16:01:51 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_inspector_window_key_press_event_cb (GtkWidget* window,
|
|
|
|
|
GdkEventKey* event,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* Close window on Ctrl+W */
|
|
|
|
|
if (event->keyval == 'w' && (event->state & GDK_CONTROL_MASK))
|
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 00:45:22 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_widget_key_press_event_cb (WebKitWebView* web_view,
|
|
|
|
|
GdkEventKey* event,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-02-28 22:41:54 +00:00
|
|
|
|
guint character;
|
2010-10-25 21:54:19 +00:00
|
|
|
|
gint digit = g_ascii_digit_value (event->keyval);
|
2009-02-22 00:45:22 +00:00
|
|
|
|
|
2010-10-26 20:57:34 +00:00
|
|
|
|
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
|
|
|
|
|
|
2010-12-14 21:43:56 +00:00
|
|
|
|
/* Handle oddities in Russian keyboard layouts */
|
|
|
|
|
if (event->hardware_keycode == ';')
|
|
|
|
|
event->keyval = ',';
|
|
|
|
|
else if (event->hardware_keycode == '<')
|
|
|
|
|
event->keyval = '.';
|
|
|
|
|
|
2010-10-25 21:54:19 +00:00
|
|
|
|
/* Find links by number: . to show links, type number, Return to go */
|
|
|
|
|
if (event->keyval == '.'
|
2010-11-02 21:10:57 +00:00
|
|
|
|
|| (view->find_links > -1
|
2011-10-01 13:12:04 +00:00
|
|
|
|
&& (digit != -1 || event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_Escape)))
|
2010-10-25 21:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (web_view);
|
|
|
|
|
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
|
|
|
|
|
gchar* result;
|
|
|
|
|
|
|
|
|
|
if (view->find_links == -1)
|
|
|
|
|
{
|
|
|
|
|
result = sokoke_js_script_eval (js_context,
|
2011-04-04 22:40:15 +00:00
|
|
|
|
" var style_func = (function (selector, rule) { "
|
2010-10-26 21:50:59 +00:00
|
|
|
|
" var style = document.createElement ('style');"
|
|
|
|
|
" style.setAttribute ('type', 'text/css');"
|
|
|
|
|
" var heads = document.getElementsByTagName ('head');"
|
|
|
|
|
" heads[0].appendChild (style);"
|
|
|
|
|
" document.styleSheets[0].insertRule (selector + ' ' + rule);"
|
2011-04-04 22:40:15 +00:00
|
|
|
|
" } );"
|
|
|
|
|
" style_func ('.midoriHKD87346', '{ "
|
2010-10-26 19:56:12 +00:00
|
|
|
|
" font-size:small !important; font-weight:bold !important;"
|
|
|
|
|
" z-index:500; border-radius:0.3em; line-height:1 !important;"
|
|
|
|
|
" background: white !important; color: black !important;"
|
|
|
|
|
" border:1px solid gray; padding:0 0.1em !important;"
|
|
|
|
|
" position:absolute; display:inline !important; }');"
|
2011-04-04 22:40:15 +00:00
|
|
|
|
" style_func ('.midori_access_key_fc04de', '{ "
|
|
|
|
|
" font-size:small !important; font-weight:bold !important;"
|
|
|
|
|
" z-index:500; border-radius:0.3em; line-height:1 !important;"
|
|
|
|
|
" background: black !important; color: white !important;"
|
|
|
|
|
" border:1px solid gray; padding:0 0.1em 0.2em 0.1em !important;"
|
|
|
|
|
" position:absolute; display:inline !important; }');"
|
|
|
|
|
" var label_count = 0;"
|
|
|
|
|
" for (i in document.links) {"
|
|
|
|
|
" if (document.links[i].href && document.links[i].insertBefore) {"
|
|
|
|
|
" var child = document.createElement ('span');"
|
|
|
|
|
" if (document.links[i].accessKey && isNaN (document.links[i].accessKey)) {"
|
|
|
|
|
" child.setAttribute ('class', 'midori_access_key_fc04de');"
|
|
|
|
|
" child.appendChild (document.createTextNode (document.links[i].accessKey));"
|
|
|
|
|
" } else {"
|
|
|
|
|
" child.setAttribute ('class', 'midoriHKD87346');"
|
|
|
|
|
" child.appendChild (document.createTextNode (label_count));"
|
|
|
|
|
" label_count++;"
|
|
|
|
|
" }"
|
|
|
|
|
" document.links[i].insertBefore (child); } }",
|
2010-10-25 21:54:19 +00:00
|
|
|
|
NULL);
|
|
|
|
|
view->find_links = 0;
|
|
|
|
|
}
|
2011-10-01 13:12:04 +00:00
|
|
|
|
else if (digit != -1 && event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_Escape)
|
2011-03-04 23:12:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (view->find_links > -1)
|
|
|
|
|
view->find_links *= 10;
|
|
|
|
|
view->find_links += digit;
|
|
|
|
|
}
|
2011-10-01 13:12:04 +00:00
|
|
|
|
else if (event->keyval == GDK_KEY_Escape)
|
2011-03-04 23:12:44 +00:00
|
|
|
|
{
|
|
|
|
|
view->find_links = 0;
|
|
|
|
|
}
|
2011-10-01 13:12:04 +00:00
|
|
|
|
else if (event->keyval == GDK_KEY_Return)
|
2010-10-25 21:54:19 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* script;
|
|
|
|
|
script = g_strdup_printf (
|
|
|
|
|
"var links = document.getElementsByClassName ('midoriHKD87346');"
|
|
|
|
|
"var i = %d; var return_key = %d;"
|
2011-03-04 23:12:44 +00:00
|
|
|
|
"if (return_key) {"
|
2011-01-01 18:03:00 +00:00
|
|
|
|
" if (typeof links[i] != 'undefined')"
|
|
|
|
|
" links[i].parentNode.href; }",
|
2011-10-01 13:12:04 +00:00
|
|
|
|
view->find_links, event->keyval == GDK_KEY_Return
|
|
|
|
|
);
|
2010-10-25 21:54:19 +00:00
|
|
|
|
result = sokoke_js_script_eval (js_context, script, NULL);
|
2011-10-19 07:53:18 +00:00
|
|
|
|
if (midori_uri_is_location (result))
|
2010-10-26 20:57:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (MIDORI_MOD_NEW_TAB (event->state))
|
|
|
|
|
{
|
|
|
|
|
gboolean background = view->open_tabs_in_the_background;
|
|
|
|
|
if (MIDORI_MOD_BACKGROUND (event->state))
|
|
|
|
|
background = !background;
|
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, result, background);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
midori_view_set_uri (view, result);
|
|
|
|
|
}
|
2010-10-25 21:54:19 +00:00
|
|
|
|
g_free (script);
|
2011-03-04 23:12:44 +00:00
|
|
|
|
g_free (result);
|
|
|
|
|
view->find_links = 0;
|
2010-10-25 21:54:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = sokoke_js_script_eval (js_context,
|
|
|
|
|
"var links = document.getElementsByClassName ('midoriHKD87346');"
|
2011-03-04 23:12:44 +00:00
|
|
|
|
"for (var i = links.length - 1; i >= 0; i--) {"
|
|
|
|
|
" var parent = links[i].parentNode;"
|
|
|
|
|
" parent.removeChild(links[i]); }",
|
2010-10-25 21:54:19 +00:00
|
|
|
|
NULL);
|
2011-03-04 23:12:44 +00:00
|
|
|
|
g_free (result);
|
2011-04-04 22:40:15 +00:00
|
|
|
|
result = sokoke_js_script_eval (js_context,
|
|
|
|
|
"var links = document.getElementsByClassName ('midori_access_key_fc04de');"
|
|
|
|
|
"if (links != undefined && links.length > 0) {"
|
|
|
|
|
" for (var i = links.length - 1; i >= 0; i--) {"
|
|
|
|
|
" var parent = links[i].parentNode;"
|
|
|
|
|
" parent.removeChild(links[i]); } }",
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (result);
|
2010-10-25 21:54:19 +00:00
|
|
|
|
view->find_links = -1;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find inline */
|
2011-10-01 13:12:04 +00:00
|
|
|
|
if (event->keyval == ',' || event->keyval == '/' || event->keyval == GDK_KEY_KP_Divide)
|
2009-05-18 20:40:13 +00:00
|
|
|
|
character = '\0';
|
2010-02-28 22:41:54 +00:00
|
|
|
|
else
|
2009-05-18 20:40:13 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2009-05-31 01:43:15 +00:00
|
|
|
|
/* Skip control characters */
|
|
|
|
|
if (character == (event->keyval | 0x01000000))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2009-05-18 20:40:13 +00:00
|
|
|
|
if (!webkit_web_view_can_cut_clipboard (web_view)
|
2009-02-22 00:45:22 +00:00
|
|
|
|
&& !webkit_web_view_can_paste_clipboard (web_view))
|
|
|
|
|
{
|
2011-12-11 01:57:04 +00:00
|
|
|
|
gchar* text = character ? g_strdup_printf ("%c", character) : NULL;
|
|
|
|
|
g_signal_emit (view, signals[SEARCH_TEXT], 0, TRUE, text ? text : "");
|
2009-02-22 00:45:22 +00:00
|
|
|
|
g_free (text);
|
2009-12-23 14:24:51 +00:00
|
|
|
|
return TRUE;
|
2009-02-22 00:45:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_widget_scroll_event_cb (WebKitWebView* web_view,
|
|
|
|
|
GdkEventScroll* event,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2008-11-11 23:16:03 +00:00
|
|
|
|
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
|
|
|
|
|
|
2010-01-22 22:11:00 +00:00
|
|
|
|
if (MIDORI_MOD_SCROLL (event->state))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (event->direction == GDK_SCROLL_DOWN)
|
2009-04-07 00:39:11 +00:00
|
|
|
|
midori_view_set_zoom_level (view,
|
2011-07-09 19:43:02 +00:00
|
|
|
|
midori_view_get_zoom_level (view) - 0.10f);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
else if(event->direction == GDK_SCROLL_UP)
|
2009-04-07 00:39:11 +00:00
|
|
|
|
midori_view_set_zoom_level (view,
|
2011-07-09 19:43:02 +00:00
|
|
|
|
midori_view_get_zoom_level (view) + 0.10f);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 19:18:25 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_new_window_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (view, signals[NEW_WINDOW], 0, view->link_uri);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-02 20:59:34 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_web_app_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-10-13 21:41:11 +00:00
|
|
|
|
sokoke_spawn_app (view->link_uri, FALSE);
|
2010-01-02 20:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-19 19:18:25 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_link_copy_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-02-26 15:05:39 +00:00
|
|
|
|
if (g_str_has_prefix (view->link_uri, "mailto:"))
|
2011-03-06 17:13:54 +00:00
|
|
|
|
sokoke_widget_copy_clipboard (widget, view->link_uri + 7);
|
2011-02-26 15:05:39 +00:00
|
|
|
|
else
|
2011-03-06 17:13:54 +00:00
|
|
|
|
sokoke_widget_copy_clipboard (widget, view->link_uri);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_save_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
WebKitNetworkRequest* request = webkit_network_request_new (view->link_uri);
|
|
|
|
|
WebKitDownload* download = webkit_download_new (request);
|
|
|
|
|
gboolean handled;
|
|
|
|
|
g_object_unref (request);
|
2011-02-02 00:17:18 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_image_new_tab_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
|
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
|
|
|
|
view->open_tabs_in_the_background);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_image_copy_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
|
2011-03-06 17:13:54 +00:00
|
|
|
|
sokoke_widget_copy_clipboard (widget, uri);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_image_save_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = katze_object_get_string (view->hit_test, "image-uri");
|
|
|
|
|
WebKitNetworkRequest* request = webkit_network_request_new (uri);
|
|
|
|
|
WebKitDownload* download = webkit_download_new (request);
|
|
|
|
|
gboolean handled;
|
|
|
|
|
g_object_unref (request);
|
2011-02-02 00:17:18 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_video_copy_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = katze_object_get_string (view->hit_test, "media-uri");
|
2011-03-06 17:13:54 +00:00
|
|
|
|
sokoke_widget_copy_clipboard (widget, uri);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_video_save_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = katze_object_get_string (view->hit_test, "media-uri");
|
|
|
|
|
WebKitNetworkRequest* request = webkit_network_request_new (uri);
|
|
|
|
|
WebKitDownload* download = webkit_download_new (request);
|
|
|
|
|
gboolean handled;
|
|
|
|
|
g_object_unref (request);
|
2011-02-02 00:17:18 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (download), "save-as-download", (void*)0xdeadbeef);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_new_tab_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2009-07-30 21:30:07 +00:00
|
|
|
|
if (view->link_uri)
|
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, view->link_uri,
|
|
|
|
|
view->open_tabs_in_the_background);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gchar* data = (gchar*)g_object_get_data (G_OBJECT (widget), "uri");
|
2009-09-30 21:38:18 +00:00
|
|
|
|
if (strchr (data, '@'))
|
|
|
|
|
{
|
|
|
|
|
gchar* uri = g_strconcat ("mailto:", data, NULL);
|
|
|
|
|
sokoke_show_uri (gtk_widget_get_screen (widget),
|
|
|
|
|
uri, GDK_CURRENT_TIME, NULL);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-09 17:13:47 +00:00
|
|
|
|
gchar* uri = sokoke_magic_uri (data);
|
|
|
|
|
if (!uri)
|
|
|
|
|
uri = g_strdup (data);
|
2009-09-30 21:38:18 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
|
|
|
|
view->open_tabs_in_the_background);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
2009-07-30 21:30:07 +00:00
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-11-14 22:54:28 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_background_tab_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, view->link_uri,
|
|
|
|
|
!view->open_tabs_in_the_background);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-12 22:38:48 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_search_web_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2009-04-11 23:32:06 +00:00
|
|
|
|
gchar* search;
|
2009-02-12 22:38:48 +00:00
|
|
|
|
gchar* uri;
|
|
|
|
|
|
2009-04-11 23:32:06 +00:00
|
|
|
|
if ((search = g_object_get_data (G_OBJECT (widget), "search")))
|
|
|
|
|
search = g_strdup (search);
|
|
|
|
|
else
|
|
|
|
|
g_object_get (view->settings, "location-entry-search",
|
|
|
|
|
&search, NULL);
|
2011-10-19 07:53:18 +00:00
|
|
|
|
uri = midori_uri_for_search (search, view->selected_text);
|
2009-04-14 17:19:50 +00:00
|
|
|
|
g_free (search);
|
2009-02-12 22:38:48 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
|
|
|
|
view->open_tabs_in_the_background);
|
|
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 21:56:05 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_copy_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-03-06 17:13:54 +00:00
|
|
|
|
sokoke_widget_copy_clipboard (widget, view->selected_text);
|
2009-10-01 21:56:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-21 19:24:01 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_menu_window_new_cb (GtkWidget* menuitem,
|
|
|
|
|
GtkWidget* view)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (view, signals[NEW_WINDOW], 0,
|
|
|
|
|
midori_view_get_display_uri (MIDORI_VIEW (view)));
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-27 15:58:37 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_web_view_menu_inspect_element_activate_cb (GtkWidget* widget,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
WebKitWebInspector* inspector;
|
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
|
|
inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
x = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "x"));
|
|
|
|
|
y = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "y"));
|
|
|
|
|
webkit_web_inspector_inspect_coordinates (inspector, x, y);
|
2010-08-14 19:12:02 +00:00
|
|
|
|
webkit_web_inspector_show (inspector);
|
2009-12-27 15:58:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 21:47:31 +00:00
|
|
|
|
static GtkWidget*
|
|
|
|
|
midori_view_insert_menu_item (GtkMenuShell* menu,
|
|
|
|
|
gint position,
|
|
|
|
|
const gchar* label,
|
|
|
|
|
const gchar* stock_id,
|
|
|
|
|
GCallback callback,
|
|
|
|
|
GtkWidget* widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
|
{
|
|
|
|
|
menuitem = gtk_image_menu_item_new_with_mnemonic (label);
|
|
|
|
|
if (stock_id)
|
|
|
|
|
{
|
|
|
|
|
GdkScreen* screen = gtk_widget_get_screen (widget);
|
|
|
|
|
GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
|
if (gtk_icon_theme_has_icon (icon_theme, stock_id))
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* icon = gtk_image_new_from_stock (stock_id,
|
|
|
|
|
GTK_ICON_SIZE_MENU);
|
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
|
|
|
|
|
icon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, position);
|
|
|
|
|
if (callback)
|
|
|
|
|
g_signal_connect (menuitem, "activate", callback, widget);
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_set_sensitive (menuitem, FALSE);
|
|
|
|
|
return menuitem;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-29 00:19:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_populate_popup:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @menu: a #GtkMenu
|
|
|
|
|
* @manual: %TRUE if this a manually created popup
|
|
|
|
|
*
|
|
|
|
|
* Populates the given @menu with context menu items
|
|
|
|
|
* according to the position of the mouse pointer. This
|
|
|
|
|
* can be used in situations where a custom hotkey
|
|
|
|
|
* opens the context menu or the default behaviour
|
|
|
|
|
* needs to be intercepted.
|
|
|
|
|
*
|
|
|
|
|
* @manual should usually be %TRUE, except for the
|
|
|
|
|
* case where @menu was created by the #WebKitWebView.
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.5
|
|
|
|
|
*/
|
|
|
|
|
void
|
2010-01-03 22:57:21 +00:00
|
|
|
|
midori_view_populate_popup (MidoriView* view,
|
|
|
|
|
GtkWidget* menu,
|
|
|
|
|
gboolean manual)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2010-01-03 22:57:21 +00:00
|
|
|
|
WebKitWebView* web_view = WEBKIT_WEB_VIEW (view->web_view);
|
|
|
|
|
GtkWidget* widget = GTK_WIDGET (view);
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (widget);
|
2009-06-19 00:58:06 +00:00
|
|
|
|
GtkActionGroup* actions = midori_browser_get_action_group (browser);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
GtkMenuShell* menu_shell = GTK_MENU_SHELL (menu);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
GtkWidget* icon;
|
|
|
|
|
gchar* stock_id;
|
|
|
|
|
GList* items;
|
2008-10-18 20:50:58 +00:00
|
|
|
|
gboolean has_selection;
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gboolean is_editable;
|
|
|
|
|
gboolean is_document;
|
2009-02-14 12:30:10 +00:00
|
|
|
|
GtkWidget* label;
|
2009-09-26 19:36:41 +00:00
|
|
|
|
guint i;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gint x, y;
|
|
|
|
|
WebKitHitTestResultContext context;
|
|
|
|
|
gboolean is_image;
|
|
|
|
|
gboolean is_media;
|
|
|
|
|
|
2011-01-02 00:24:50 +00:00
|
|
|
|
midori_view_ensure_link_uri (view, &x, &y, NULL);
|
2009-09-19 19:18:25 +00:00
|
|
|
|
context = katze_object_get_int (view->hit_test, "context");
|
2009-09-18 21:47:31 +00:00
|
|
|
|
has_selection = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
|
|
|
|
|
/* Ensure view->selected_text */
|
|
|
|
|
midori_view_has_selection (view);
|
|
|
|
|
is_editable = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
|
|
|
|
|
is_image = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
|
|
|
|
|
is_media = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
|
|
|
|
|
is_document = !view->link_uri && !has_selection && !is_image && !is_media;
|
|
|
|
|
|
|
|
|
|
if (is_editable)
|
|
|
|
|
{
|
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_menu_shell_prepend (menu_shell, menuitem);
|
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Redo"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_redo (web_view));
|
|
|
|
|
gtk_menu_shell_prepend (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Undo"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_undo (web_view));
|
|
|
|
|
gtk_menu_shell_prepend (menu_shell, menuitem);
|
2010-01-03 22:57:21 +00:00
|
|
|
|
if (manual)
|
|
|
|
|
{
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Cut"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_cut_clipboard (web_view));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Copy"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_copy_clipboard (web_view));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Paste"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_paste_clipboard (web_view));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Delete"));
|
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
|
|
|
|
webkit_web_view_can_cut_clipboard (web_view));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "SelectAll"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
/* FIXME: We are missing Font, Input Methods and Insert Character */
|
|
|
|
|
if (katze_object_get_boolean (view->settings, "enable-developer-extras"))
|
|
|
|
|
{
|
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Inspect _Element"), NULL,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_inspect_element_activate_cb),
|
|
|
|
|
widget);
|
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "x", GINT_TO_POINTER (x));
|
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "y", GINT_TO_POINTER (y));
|
2010-10-20 21:48:36 +00:00
|
|
|
|
}
|
2010-01-03 22:57:21 +00:00
|
|
|
|
}
|
2009-09-18 21:47:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-23 22:13:25 +00:00
|
|
|
|
items = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
menuitem = (GtkWidget*)g_list_nth_data (items, 0);
|
|
|
|
|
/* Form control: no items */
|
2010-01-03 22:57:21 +00:00
|
|
|
|
if (!manual && !menuitem)
|
2009-12-23 22:13:25 +00:00
|
|
|
|
{
|
|
|
|
|
g_list_free (items);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* Form control: separator and Inspect element */
|
2010-01-03 22:57:21 +00:00
|
|
|
|
if (!manual && GTK_IS_SEPARATOR_MENU_ITEM (menuitem) && g_list_length (items) == 2)
|
2009-12-23 22:13:25 +00:00
|
|
|
|
{
|
2009-12-27 15:58:37 +00:00
|
|
|
|
gtk_widget_destroy (menuitem);
|
2009-12-23 22:13:25 +00:00
|
|
|
|
g_list_free (items);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
g_list_free (items);
|
|
|
|
|
/* Link and/ or image, but falsely reported as document */
|
|
|
|
|
if (is_document)
|
|
|
|
|
{
|
|
|
|
|
if (GTK_IS_IMAGE_MENU_ITEM (menuitem))
|
|
|
|
|
{
|
|
|
|
|
icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menuitem));
|
|
|
|
|
gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
|
|
|
|
|
if (stock_id && !strcmp (stock_id, GTK_STOCK_OPEN))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-26 19:36:41 +00:00
|
|
|
|
if (!is_document)
|
|
|
|
|
{
|
|
|
|
|
items = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
i = 0;
|
|
|
|
|
while ((menuitem = g_list_nth_data (items, i++)))
|
|
|
|
|
gtk_widget_destroy (menuitem);
|
|
|
|
|
g_list_free (items);
|
|
|
|
|
}
|
2009-09-18 21:47:31 +00:00
|
|
|
|
if (view->link_uri)
|
|
|
|
|
{
|
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Open Link in New _Tab"), STOCK_TAB_NEW,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), widget);
|
2009-11-14 22:54:28 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
view->open_tabs_in_the_background
|
|
|
|
|
? _("Open Link in _Foreground Tab")
|
2009-12-23 22:13:25 +00:00
|
|
|
|
: _("Open Link in _Background Tab"), NULL,
|
2009-11-14 22:54:28 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_background_tab_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Open Link in New _Window"), STOCK_WINDOW_NEW,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_new_window_activate_cb), widget);
|
2010-01-02 20:59:34 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Open Link as Web A_pplication"), NULL,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_web_app_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
2010-01-02 21:03:32 +00:00
|
|
|
|
_("Copy Link de_stination"), NULL,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_link_copy_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
2011-02-21 18:42:10 +00:00
|
|
|
|
NULL, GTK_STOCK_SAVE_AS,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_save_activate_cb), widget);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 21:47:31 +00:00
|
|
|
|
if (is_image)
|
|
|
|
|
{
|
|
|
|
|
if (view->link_uri)
|
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Open _Image in New Tab"), STOCK_TAB_NEW,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_image_new_tab_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Copy Image _Address"), NULL,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_image_copy_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
2011-02-02 00:17:18 +00:00
|
|
|
|
_("Save I_mage"), GTK_STOCK_SAVE,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_image_save_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_media)
|
|
|
|
|
{
|
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Copy Video _Address"), NULL,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_video_copy_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
FALSE ? _("Save _Video") : _("Download _Video"), GTK_STOCK_SAVE,
|
2009-09-19 19:18:25 +00:00
|
|
|
|
G_CALLBACK (midori_web_view_menu_video_save_activate_cb), widget);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
}
|
2009-12-27 15:58:37 +00:00
|
|
|
|
|
|
|
|
|
if (has_selection)
|
|
|
|
|
{
|
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
|
|
|
|
midori_view_insert_menu_item (menu_shell, -1, NULL, GTK_STOCK_COPY,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_copy_activate_cb), widget);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-10-18 20:50:58 +00:00
|
|
|
|
if (!view->link_uri && has_selection)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2009-04-11 23:32:06 +00:00
|
|
|
|
GtkWidget* window;
|
2010-09-24 21:35:01 +00:00
|
|
|
|
KatzeArray* search_engines = NULL;
|
2009-04-11 23:32:06 +00:00
|
|
|
|
|
|
|
|
|
window = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
|
|
|
|
|
i = 0;
|
|
|
|
|
if (katze_object_has_property (window, "search-engines"))
|
2010-09-24 21:35:01 +00:00
|
|
|
|
search_engines = katze_object_get_object (window, "search-engines");
|
|
|
|
|
|
|
|
|
|
if (search_engines != NULL)
|
2009-04-11 23:32:06 +00:00
|
|
|
|
{
|
|
|
|
|
KatzeItem* item;
|
2009-04-18 17:26:42 +00:00
|
|
|
|
GtkWidget* sub_menu = gtk_menu_new ();
|
|
|
|
|
|
|
|
|
|
menuitem = gtk_image_menu_item_new_with_mnemonic (_("Search _with"));
|
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), sub_menu);
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_insert (menu_shell, menuitem, 1);
|
2009-04-11 23:32:06 +00:00
|
|
|
|
|
2010-09-11 21:39:51 +00:00
|
|
|
|
KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
|
2009-04-11 23:32:06 +00:00
|
|
|
|
{
|
|
|
|
|
GdkPixbuf* pixbuf;
|
2009-11-28 22:47:29 +00:00
|
|
|
|
const gchar* icon_name;
|
|
|
|
|
|
2009-04-18 17:26:42 +00:00
|
|
|
|
menuitem = gtk_image_menu_item_new_with_mnemonic (katze_item_get_name (item));
|
2009-11-28 22:47:29 +00:00
|
|
|
|
pixbuf = midori_search_action_get_icon (item,
|
2011-05-01 16:49:09 +00:00
|
|
|
|
GTK_WIDGET (web_view), &icon_name, FALSE);
|
2009-11-28 22:47:29 +00:00
|
|
|
|
if (pixbuf)
|
|
|
|
|
{
|
|
|
|
|
icon = gtk_image_new_from_pixbuf (pixbuf);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
|
2009-04-11 23:32:06 +00:00
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon);
|
2009-07-25 21:04:15 +00:00
|
|
|
|
gtk_image_menu_item_set_always_show_image (
|
|
|
|
|
GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
|
2010-09-11 21:39:51 +00:00
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (sub_menu), menuitem, i);
|
2009-04-11 23:32:06 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "search",
|
|
|
|
|
(gchar*)katze_item_get_uri (item));
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view);
|
2010-09-11 21:39:51 +00:00
|
|
|
|
i++;
|
2009-04-11 23:32:06 +00:00
|
|
|
|
}
|
|
|
|
|
g_object_unref (search_engines);
|
|
|
|
|
}
|
2009-09-18 21:47:31 +00:00
|
|
|
|
midori_view_insert_menu_item (menu_shell, 0,
|
|
|
|
|
_("_Search the Web"), GTK_STOCK_FIND,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_search_web_activate_cb), widget);
|
2009-04-18 17:26:42 +00:00
|
|
|
|
|
2009-09-30 21:38:18 +00:00
|
|
|
|
g_strstrip (view->selected_text);
|
2011-10-19 07:53:18 +00:00
|
|
|
|
if (midori_uri_is_valid (view->selected_text))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2011-10-19 07:53:18 +00:00
|
|
|
|
if (midori_uri_is_email (view->selected_text))
|
2009-09-30 21:38:18 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);
|
|
|
|
|
menuitem = midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
text, GTK_STOCK_JUMP_TO,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), widget);
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
menuitem = midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Open Address in New _Tab"), GTK_STOCK_JUMP_TO,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), widget);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "uri", view->selected_text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 21:47:31 +00:00
|
|
|
|
if (is_document)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2010-01-03 22:57:21 +00:00
|
|
|
|
if (manual)
|
|
|
|
|
{
|
2009-09-18 21:47:31 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Back"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Forward"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Stop"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Reload"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2010-01-03 22:57:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-02-14 12:30:10 +00:00
|
|
|
|
items = gtk_container_get_children (GTK_CONTAINER (menu));
|
2009-10-13 00:40:38 +00:00
|
|
|
|
#if HAVE_HILDON
|
|
|
|
|
gtk_widget_hide (g_list_nth_data (items, 2));
|
|
|
|
|
gtk_widget_set_no_show_all (g_list_nth_data (items, 2), TRUE);
|
|
|
|
|
gtk_widget_hide (g_list_nth_data (items, 3));
|
|
|
|
|
gtk_widget_set_no_show_all (g_list_nth_data (items, 3), TRUE);
|
|
|
|
|
#endif
|
2009-02-14 12:30:10 +00:00
|
|
|
|
menuitem = (GtkWidget*)g_list_nth_data (items, 3);
|
|
|
|
|
/* hack to localize menu item */
|
2009-04-10 13:52:01 +00:00
|
|
|
|
if (GTK_IS_BIN (menuitem))
|
|
|
|
|
{
|
2009-04-28 22:16:26 +00:00
|
|
|
|
GtkStockItem stock_item;
|
|
|
|
|
if (gtk_stock_lookup (GTK_STOCK_REFRESH, &stock_item))
|
|
|
|
|
{
|
|
|
|
|
label = gtk_bin_get_child (GTK_BIN (menuitem));
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), stock_item.label);
|
|
|
|
|
}
|
2009-04-10 13:52:01 +00:00
|
|
|
|
}
|
2009-02-14 12:30:10 +00:00
|
|
|
|
g_list_free (items);
|
2010-01-03 22:57:21 +00:00
|
|
|
|
}
|
2009-09-18 21:47:31 +00:00
|
|
|
|
|
2009-12-27 15:58:37 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
2009-06-19 00:58:06 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
2010-06-21 19:24:01 +00:00
|
|
|
|
gtk_action_group_get_action (actions, "UndoTabClose"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2010-06-21 19:24:01 +00:00
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (STOCK_WINDOW_NEW, NULL);
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), _("Open in New _Window"));
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_window_new_cb), view);
|
2009-05-09 14:41:01 +00:00
|
|
|
|
|
2009-11-27 22:42:07 +00:00
|
|
|
|
#if !HAVE_HILDON
|
2009-06-22 19:29:39 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "ZoomIn"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-06-22 19:29:39 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "ZoomOut"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-11-27 22:42:07 +00:00
|
|
|
|
#endif
|
2009-06-22 19:29:39 +00:00
|
|
|
|
|
2009-06-22 20:18:16 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Encoding"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2010-04-02 16:54:29 +00:00
|
|
|
|
if (gtk_widget_get_sensitive (menuitem))
|
2009-06-22 20:18:16 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget* sub_menu;
|
|
|
|
|
static const GtkActionEntry encodings[] = {
|
|
|
|
|
{ "EncodingAutomatic" },
|
|
|
|
|
{ "EncodingChinese" },
|
|
|
|
|
{ "EncodingJapanese" },
|
2009-10-31 21:51:35 +00:00
|
|
|
|
{ "EncodingKorean" },
|
2009-06-22 20:18:16 +00:00
|
|
|
|
{ "EncodingRussian" },
|
|
|
|
|
{ "EncodingUnicode" },
|
|
|
|
|
{ "EncodingWestern" },
|
|
|
|
|
{ "EncodingCustom" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sub_menu = gtk_menu_new ();
|
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), sub_menu);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (encodings); i++)
|
|
|
|
|
{
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, encodings[i].name));
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menuitem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-27 22:42:07 +00:00
|
|
|
|
#if HAVE_HILDON
|
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "CompactAdd"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Fullscreen"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-12-12 20:56:11 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "PrivateBrowsing"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-11-27 22:42:07 +00:00
|
|
|
|
#else
|
2009-09-19 19:18:25 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
2009-06-19 00:58:06 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "BookmarkAdd"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-05-09 14:41:01 +00:00
|
|
|
|
|
2011-10-11 00:48:47 +00:00
|
|
|
|
if (!midori_view_is_blank (view) && !sokoke_is_app_or_private ())
|
2009-05-10 12:57:26 +00:00
|
|
|
|
{
|
2009-06-19 00:58:06 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "AddSpeedDial"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-05-10 12:57:26 +00:00
|
|
|
|
}
|
2009-10-12 20:57:35 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "AddDesktopShortcut"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2009-10-13 00:40:38 +00:00
|
|
|
|
#endif
|
2009-05-09 14:41:01 +00:00
|
|
|
|
|
2009-06-19 00:58:06 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "SaveAs"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2008-11-09 21:07:42 +00:00
|
|
|
|
/* Currently views that don't support source, don't support
|
|
|
|
|
saving either. If that changes, we need to think of something. */
|
|
|
|
|
if (!midori_view_can_view_source (view))
|
|
|
|
|
gtk_widget_set_sensitive (menuitem, FALSE);
|
2009-06-19 00:58:06 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "SourceView"));
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
2011-02-24 20:23:23 +00:00
|
|
|
|
|
|
|
|
|
if (!g_object_get_data (G_OBJECT (browser), "midori-toolbars-visible"))
|
|
|
|
|
{
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Navigationbar"));
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
2009-09-18 21:47:31 +00:00
|
|
|
|
|
2010-01-03 22:57:21 +00:00
|
|
|
|
if ((!is_document || manual)
|
|
|
|
|
&& katze_object_get_boolean (view->settings, "enable-developer-extras"))
|
2009-12-27 15:58:37 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
|
|
|
|
|
menuitem = midori_view_insert_menu_item (menu_shell, -1,
|
|
|
|
|
_("Inspect _Element"), NULL,
|
|
|
|
|
G_CALLBACK (midori_web_view_menu_inspect_element_activate_cb), widget);
|
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "x", GINT_TO_POINTER (x));
|
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "y", GINT_TO_POINTER (y));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-11 00:22:15 +00:00
|
|
|
|
GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (browser)));
|
|
|
|
|
if (state & GDK_WINDOW_STATE_FULLSCREEN)
|
|
|
|
|
{
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "Fullscreen"));
|
|
|
|
|
|
|
|
|
|
gtk_image_menu_item_set_use_stock (GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), GTK_STOCK_LEAVE_FULLSCREEN);
|
|
|
|
|
gtk_menu_shell_append (menu_shell, menuitem);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 21:47:31 +00:00
|
|
|
|
gtk_widget_show_all (menu);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-03 22:57:21 +00:00
|
|
|
|
static void
|
|
|
|
|
webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
|
|
|
|
|
GtkWidget* menu,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
midori_view_populate_popup (view, menu, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 20:58:50 +00:00
|
|
|
|
#if HAVE_HILDON
|
|
|
|
|
static void
|
|
|
|
|
midori_view_web_view_tap_and_hold_cb (GtkWidget* web_view,
|
2009-12-23 15:46:14 +00:00
|
|
|
|
gpointer data)
|
2009-10-13 20:58:50 +00:00
|
|
|
|
{
|
|
|
|
|
gint x, y;
|
|
|
|
|
GdkEvent event;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
/* Emulate a pointer motion above the tap position
|
|
|
|
|
and a right click at the according position. */
|
2010-10-18 20:42:10 +00:00
|
|
|
|
event.any.window = gtk_widget_get_window (web_view);
|
|
|
|
|
gdk_window_get_pointer (event.any.window, &x, &y, NULL);
|
2009-10-13 20:58:50 +00:00
|
|
|
|
event.any.type = GDK_MOTION_NOTIFY;
|
|
|
|
|
event.motion.x = x;
|
|
|
|
|
event.motion.y = y;
|
|
|
|
|
g_signal_emit_by_name (web_view, "motion-notify-event", &event, &result);
|
|
|
|
|
|
|
|
|
|
event.any.type = GDK_BUTTON_PRESS;
|
|
|
|
|
event.button.axes = NULL;
|
|
|
|
|
event.button.x = x;
|
|
|
|
|
event.button.y = y;
|
|
|
|
|
event.button.button = 3;
|
|
|
|
|
g_signal_emit_by_name (web_view, "button-press-event", &event, &result);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-12-03 03:16:19 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
webkit_web_view_web_view_ready_cb (GtkWidget* web_view,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-04-02 17:14:22 +00:00
|
|
|
|
GtkWidget* new_view = gtk_widget_get_parent (gtk_widget_get_parent (web_view));
|
2008-12-03 03:16:19 +00:00
|
|
|
|
MidoriNewView where = MIDORI_NEW_VIEW_TAB;
|
2009-11-10 19:04:48 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: Open windows opened by scripts in tabs if they otherwise
|
|
|
|
|
would be replacing the page the user opened. */
|
|
|
|
|
if (view->open_new_pages_in == MIDORI_NEW_PAGE_CURRENT)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2008-12-03 03:16:19 +00:00
|
|
|
|
if (view->open_new_pages_in == MIDORI_NEW_PAGE_TAB)
|
|
|
|
|
{
|
|
|
|
|
if (view->open_tabs_in_the_background)
|
|
|
|
|
where = MIDORI_NEW_VIEW_BACKGROUND;
|
|
|
|
|
}
|
|
|
|
|
else if (view->open_new_pages_in == MIDORI_NEW_PAGE_WINDOW)
|
|
|
|
|
where = MIDORI_NEW_VIEW_WINDOW;
|
|
|
|
|
|
|
|
|
|
gtk_widget_show (new_view);
|
2011-04-19 21:16:34 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where, FALSE);
|
2008-12-03 03:16:19 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
|
webkit_web_view_create_web_view_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2009-11-10 19:04:48 +00:00
|
|
|
|
MidoriView* new_view;
|
|
|
|
|
|
|
|
|
|
if (view->open_new_pages_in == MIDORI_NEW_PAGE_CURRENT)
|
|
|
|
|
new_view = view;
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-12-08 20:14:06 +00:00
|
|
|
|
new_view = (MidoriView*)midori_view_new_with_item (NULL, view->settings);
|
2009-11-10 19:04:48 +00:00
|
|
|
|
g_signal_connect (new_view->web_view, "web-view-ready",
|
|
|
|
|
G_CALLBACK (webkit_web_view_web_view_ready_cb), view);
|
|
|
|
|
}
|
|
|
|
|
return new_view->web_view;
|
2008-12-03 03:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-02 01:28:04 +00:00
|
|
|
|
static gboolean
|
2009-03-16 00:54:22 +00:00
|
|
|
|
webkit_web_view_mime_type_decision_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
WebKitNetworkRequest* request,
|
|
|
|
|
const gchar* mime_type,
|
|
|
|
|
WebKitWebPolicyDecision* decision,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2009-03-21 14:06:57 +00:00
|
|
|
|
GtkWidget* dialog;
|
|
|
|
|
gchar* content_type;
|
|
|
|
|
gchar* description;
|
2011-03-12 20:02:48 +00:00
|
|
|
|
gchar* file_type;
|
|
|
|
|
WebKitWebDataSource* datasource;
|
|
|
|
|
WebKitNetworkRequest* original_request;
|
|
|
|
|
const gchar* original_uri;
|
2011-11-07 22:07:57 +00:00
|
|
|
|
gchar* fingerprint;
|
|
|
|
|
gchar* fplabel;
|
2009-03-26 23:40:28 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (2, 14, 0)
|
|
|
|
|
GIcon* icon;
|
|
|
|
|
GtkWidget* image;
|
|
|
|
|
#endif
|
2009-03-21 14:06:57 +00:00
|
|
|
|
gchar* title;
|
|
|
|
|
GdkScreen* screen;
|
|
|
|
|
GtkIconTheme* icon_theme;
|
|
|
|
|
gint response;
|
2009-01-11 23:26:45 +00:00
|
|
|
|
|
2009-01-02 01:28:04 +00:00
|
|
|
|
if (web_frame != webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2009-01-11 23:26:45 +00:00
|
|
|
|
if (webkit_web_view_can_show_mime_type (WEBKIT_WEB_VIEW (web_view), mime_type))
|
2009-03-21 14:06:57 +00:00
|
|
|
|
{
|
2010-06-29 05:36:45 +00:00
|
|
|
|
gboolean view_source = FALSE;
|
|
|
|
|
/* Dedicated source code views are always pseudo-blank pages */
|
|
|
|
|
if (midori_view_is_blank (view))
|
|
|
|
|
view_source = webkit_web_view_get_view_source_mode (WEBKIT_WEB_VIEW (web_view));
|
2010-04-13 21:19:16 +00:00
|
|
|
|
|
2010-05-07 18:31:41 +00:00
|
|
|
|
/* Render raw XML, including news feeds, as source */
|
|
|
|
|
if (!view_source && (!strcmp (mime_type, "application/xml")
|
|
|
|
|
|| !strcmp (mime_type, "text/xml")))
|
|
|
|
|
view_source = TRUE;
|
2010-04-13 21:19:16 +00:00
|
|
|
|
webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (web_view), view_source);
|
|
|
|
|
|
2009-03-21 14:06:57 +00:00
|
|
|
|
katze_assign (view->mime_type, g_strdup (mime_type));
|
|
|
|
|
midori_view_update_icon (view, NULL);
|
|
|
|
|
g_object_notify (G_OBJECT (view), "mime-type");
|
2010-04-13 21:19:16 +00:00
|
|
|
|
|
2009-02-28 21:33:37 +00:00
|
|
|
|
return FALSE;
|
2009-03-21 14:06:57 +00:00
|
|
|
|
}
|
2009-01-11 23:26:45 +00:00
|
|
|
|
|
2009-03-21 14:06:57 +00:00
|
|
|
|
dialog = gtk_message_dialog_new (
|
|
|
|
|
NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
|
|
|
|
|
_("Open or download file"));
|
|
|
|
|
content_type = g_content_type_from_mime_type (mime_type);
|
2009-11-20 00:34:16 +00:00
|
|
|
|
if (!content_type)
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
content_type = g_content_type_get_mime_type ("*");
|
|
|
|
|
#else
|
|
|
|
|
content_type = g_strdup ("application/octet-stream");
|
|
|
|
|
#endif
|
2009-03-21 14:06:57 +00:00
|
|
|
|
description = g_content_type_get_description (content_type);
|
2009-03-26 23:40:28 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (2, 14, 0)
|
|
|
|
|
icon = g_content_type_get_icon (content_type);
|
2011-02-15 20:31:39 +00:00
|
|
|
|
g_themed_icon_append_name (G_THEMED_ICON (icon), "document-x-generic");
|
|
|
|
|
image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
|
2009-03-26 23:40:28 +00:00
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
|
|
|
|
|
#endif
|
2009-06-13 01:43:49 +00:00
|
|
|
|
g_free (content_type);
|
2009-03-26 21:37:33 +00:00
|
|
|
|
if (g_strrstr (description, mime_type))
|
2011-03-12 20:02:48 +00:00
|
|
|
|
file_type = g_strdup_printf (_("File Type: '%s'"), mime_type);
|
2009-03-26 21:37:33 +00:00
|
|
|
|
else
|
2011-03-12 20:02:48 +00:00
|
|
|
|
file_type = g_strdup_printf (_("File Type: %s ('%s')"), description, mime_type);
|
2009-03-21 14:06:57 +00:00
|
|
|
|
g_free (description);
|
2011-03-12 20:02:48 +00:00
|
|
|
|
|
|
|
|
|
/* Link Fingerprint */
|
|
|
|
|
/* We look at the original URI because redirection would lose the fragment */
|
|
|
|
|
datasource = webkit_web_frame_get_provisional_data_source (web_frame);
|
|
|
|
|
original_request = webkit_web_data_source_get_initial_request (datasource);
|
|
|
|
|
original_uri = webkit_network_request_get_uri (original_request);
|
2011-11-07 22:07:57 +00:00
|
|
|
|
midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel);
|
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
|
"%s\n%s %s", file_type, fplabel ? fplabel : "", fingerprint ? fingerprint : "");
|
|
|
|
|
g_free (fingerprint);
|
|
|
|
|
g_free (fplabel);
|
2011-03-12 20:02:48 +00:00
|
|
|
|
g_free (file_type);
|
|
|
|
|
|
2009-03-21 14:06:57 +00:00
|
|
|
|
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
/* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */
|
|
|
|
|
title = g_strdup_printf (_("Open %s"),
|
|
|
|
|
webkit_network_request_get_uri (request));
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), title);
|
|
|
|
|
g_free (title);
|
|
|
|
|
screen = gtk_widget_get_screen (dialog);
|
|
|
|
|
if (screen)
|
|
|
|
|
{
|
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
|
if (gtk_icon_theme_has_icon (icon_theme, STOCK_TRANSFER))
|
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), STOCK_TRANSFER);
|
|
|
|
|
else
|
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_OPEN);
|
|
|
|
|
}
|
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
|
|
|
|
GTK_STOCK_SAVE, 1,
|
2009-06-01 17:33:44 +00:00
|
|
|
|
GTK_STOCK_SAVE_AS, 4,
|
2009-03-21 14:06:57 +00:00
|
|
|
|
GTK_STOCK_CANCEL, 2,
|
2009-06-13 01:43:49 +00:00
|
|
|
|
GTK_STOCK_OPEN, 3,
|
2009-03-21 14:06:57 +00:00
|
|
|
|
NULL);
|
|
|
|
|
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
|
|
|
|
|
switch (response)
|
|
|
|
|
{
|
2009-06-01 17:33:44 +00:00
|
|
|
|
case 4:
|
|
|
|
|
g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)1);
|
|
|
|
|
webkit_web_policy_decision_download (decision);
|
|
|
|
|
webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
return TRUE;
|
2009-03-21 14:06:57 +00:00
|
|
|
|
case 3:
|
|
|
|
|
g_object_set_data (G_OBJECT (view), "open-download", (gpointer)1);
|
|
|
|
|
case 1:
|
|
|
|
|
webkit_web_policy_decision_download (decision);
|
|
|
|
|
/* Apparently WebKit will continue loading which ends in an error.
|
|
|
|
|
It's unclear whether it's a bug or we are doing something wrong. */
|
|
|
|
|
webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
return TRUE;
|
|
|
|
|
case 2:
|
|
|
|
|
default:
|
|
|
|
|
/* Apparently WebKit will continue loading which ends in an error.
|
|
|
|
|
It's unclear whether it's a bug or we are doing something wrong. */
|
|
|
|
|
webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2009-01-02 01:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 17:28:50 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
webkit_web_view_download_requested_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitDownload* download,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gboolean handled;
|
2011-03-12 20:02:48 +00:00
|
|
|
|
/* Propagate original URI to make it available when the download finishes */
|
|
|
|
|
WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
|
|
|
|
|
WebKitWebDataSource* datasource = webkit_web_frame_get_provisional_data_source (web_frame);
|
|
|
|
|
WebKitNetworkRequest* original_request = webkit_web_data_source_get_initial_request (datasource);
|
|
|
|
|
const gchar* original_uri = webkit_network_request_get_uri (original_request);
|
|
|
|
|
WebKitNetworkRequest* request = webkit_download_get_network_request (download);
|
|
|
|
|
g_object_set_data_full (G_OBJECT (request), "midori-original-uri",
|
|
|
|
|
g_strdup (original_uri), g_free);
|
2009-03-21 14:06:57 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (download), "open-download",
|
|
|
|
|
g_object_get_data (G_OBJECT (view), "open-download"));
|
2009-06-01 17:33:44 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (download), "save-as-download",
|
|
|
|
|
g_object_get_data (G_OBJECT (view), "save-as-download"));
|
2009-03-21 19:07:38 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (view), "open-download", (gpointer)0);
|
2009-06-01 17:33:44 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (view), "save-as-download", (gpointer)0);
|
2009-03-19 17:28:50 +00:00
|
|
|
|
g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-07 20:22:43 +00:00
|
|
|
|
static gboolean
|
2008-09-26 21:13:46 +00:00
|
|
|
|
webkit_web_view_console_message_cb (GtkWidget* web_view,
|
|
|
|
|
const gchar* message,
|
|
|
|
|
guint line,
|
|
|
|
|
const gchar* source_id,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2011-10-19 07:15:47 +00:00
|
|
|
|
if (g_object_get_data (G_OBJECT (webkit_get_default_session ()),
|
|
|
|
|
"pass-through-console"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
if (!strncmp (message, "speed_dial-save", 13))
|
|
|
|
|
midori_view_speed_dial_save (view, message);
|
2009-05-07 20:22:43 +00:00
|
|
|
|
else
|
|
|
|
|
g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
|
|
|
|
|
return TRUE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 00:59:16 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_script_response_cb (GtkWidget* infobar,
|
|
|
|
|
gint response,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
view->alerts--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_view_script_alert_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
const gchar* message,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar* text;
|
|
|
|
|
|
|
|
|
|
/* Allow a maximum of 5 alerts */
|
|
|
|
|
if (view->alerts > 4)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
view->alerts++;
|
|
|
|
|
/* i18n: The text of an infobar for JavaScript alert messages */
|
|
|
|
|
text = g_strdup_printf ("JavaScript: %s", message);
|
|
|
|
|
midori_view_add_info_bar (view, GTK_MESSAGE_WARNING, text,
|
|
|
|
|
G_CALLBACK (midori_view_script_response_cb), view,
|
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
|
|
|
|
|
g_free (text);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-24 18:10:58 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_view_print_requested_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
midori_view_print (view);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_window_object_cleared_cb (GtkWidget* web_view,
|
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
|
JSContextRef js_context,
|
|
|
|
|
JSObjectRef js_window,
|
|
|
|
|
MidoriView* view)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2011-12-02 23:53:30 +00:00
|
|
|
|
const gchar* page_uri;
|
|
|
|
|
|
|
|
|
|
page_uri = webkit_web_frame_get_uri (web_frame);
|
|
|
|
|
if (!midori_uri_is_http (page_uri))
|
|
|
|
|
return;
|
|
|
|
|
|
2011-04-19 21:07:22 +00:00
|
|
|
|
if (katze_object_get_boolean (view->settings, "enable-private-browsing"))
|
|
|
|
|
{
|
|
|
|
|
/* Mask language, architecture, no plugin list */
|
|
|
|
|
gchar* result = sokoke_js_script_eval (js_context,
|
|
|
|
|
"navigator = { 'appName': 'Netscape',"
|
|
|
|
|
"'appCodeName': 'Mozilla',"
|
|
|
|
|
"'appVersion': '5.0 (X11)',"
|
|
|
|
|
"'userAgent': navigator.userAgent,"
|
|
|
|
|
"'language': 'en-US',"
|
|
|
|
|
"'platform': 'Linux i686',"
|
|
|
|
|
"'cookieEnabled': true,"
|
2011-11-13 19:31:02 +00:00
|
|
|
|
"'javaEnabled': function () { return true; },"
|
|
|
|
|
"'mimeTypes': {},"
|
2011-04-19 21:07:22 +00:00
|
|
|
|
"'plugins': {'refresh': function () { } } };",
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (result);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-16 20:02:30 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_hadjustment_notify_value_cb (GtkAdjustment* hadjustment,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gint value = (gint)gtk_adjustment_get_value (hadjustment);
|
2010-07-22 02:12:20 +00:00
|
|
|
|
katze_item_set_meta_integer (view->item, "scrollh", value);
|
2009-09-16 20:02:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_notify_hadjustment_cb (MidoriView* view,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (view->scrolled_window);
|
|
|
|
|
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment (scrolled);
|
2009-09-16 20:02:30 +00:00
|
|
|
|
g_signal_connect (hadjustment, "notify::value",
|
|
|
|
|
G_CALLBACK (midori_view_hadjustment_notify_value_cb), view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_vadjustment_notify_value_cb (GtkAdjustment* vadjustment,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gint value = (gint)gtk_adjustment_get_value (vadjustment);
|
2010-07-22 02:12:20 +00:00
|
|
|
|
katze_item_set_meta_integer (view->item, "scrollv", value);
|
2009-09-16 20:02:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_notify_vadjustment_cb (MidoriView* view,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (view->scrolled_window);
|
|
|
|
|
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment (scrolled);
|
2009-09-16 20:02:30 +00:00
|
|
|
|
g_signal_connect (vadjustment, "notify::value",
|
|
|
|
|
G_CALLBACK (midori_view_vadjustment_notify_value_cb), view);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-20 21:48:36 +00:00
|
|
|
|
static void
|
2010-03-11 22:27:37 +00:00
|
|
|
|
katze_net_object_maybe_unref (gpointer object)
|
|
|
|
|
{
|
|
|
|
|
if (object)
|
|
|
|
|
g_object_unref (object);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-13 14:11:02 +00:00
|
|
|
|
static GHashTable* midori_view_get_memory (void)
|
|
|
|
|
{
|
|
|
|
|
static GHashTable* memory = NULL;
|
|
|
|
|
if (!memory)
|
|
|
|
|
memory = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
|
g_free, katze_net_object_maybe_unref);
|
|
|
|
|
return g_hash_table_ref (memory);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_init (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
view->uri = NULL;
|
|
|
|
|
view->title = NULL;
|
2010-04-13 21:44:21 +00:00
|
|
|
|
view->security = MIDORI_SECURITY_NONE;
|
2011-10-10 19:58:19 +00:00
|
|
|
|
view->mime_type = NULL;
|
2009-12-26 12:59:54 +00:00
|
|
|
|
view->icon = NULL;
|
2010-03-11 22:27:37 +00:00
|
|
|
|
view->icon_uri = NULL;
|
2010-11-13 14:11:02 +00:00
|
|
|
|
view->memory = midori_view_get_memory ();
|
2008-09-26 21:13:46 +00:00
|
|
|
|
view->progress = 0.0;
|
|
|
|
|
view->load_status = MIDORI_LOAD_FINISHED;
|
2009-07-21 21:57:57 +00:00
|
|
|
|
view->minimized = FALSE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
view->statusbar_text = NULL;
|
2009-09-19 19:18:25 +00:00
|
|
|
|
view->hit_test = NULL;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
view->link_uri = NULL;
|
|
|
|
|
view->selected_text = NULL;
|
2011-10-10 19:58:19 +00:00
|
|
|
|
view->news_feeds = NULL;
|
2010-10-25 21:54:19 +00:00
|
|
|
|
view->find_links = -1;
|
2011-04-04 00:59:16 +00:00
|
|
|
|
view->alerts = 0;
|
2009-05-03 01:11:33 +00:00
|
|
|
|
|
2010-07-22 02:12:20 +00:00
|
|
|
|
view->item = katze_item_new ();
|
|
|
|
|
|
2009-10-07 21:51:35 +00:00
|
|
|
|
view->scrollh = view->scrollv = -2;
|
2009-09-25 21:57:44 +00:00
|
|
|
|
view->back_forward_set = FALSE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2011-11-20 21:14:30 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (3, 2, 0)
|
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (view), GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
view->web_view = NULL;
|
2009-09-16 20:02:30 +00:00
|
|
|
|
/* Adjustments are not created initially, but overwritten later */
|
2010-03-30 20:45:49 +00:00
|
|
|
|
view->scrolled_window = katze_scrolled_new (NULL, NULL);
|
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->scrolled_window),
|
2010-07-16 19:23:11 +00:00
|
|
|
|
GTK_SHADOW_NONE);
|
2011-11-20 21:14:30 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (view), view->scrolled_window, TRUE, TRUE, 0);
|
2010-03-30 20:45:49 +00:00
|
|
|
|
|
2010-07-22 02:12:20 +00:00
|
|
|
|
g_signal_connect (view->item, "meta-data-changed",
|
|
|
|
|
G_CALLBACK (midori_view_item_meta_data_changed), view);
|
2010-03-30 20:45:49 +00:00
|
|
|
|
g_signal_connect (view->scrolled_window, "notify::hadjustment",
|
2009-09-16 20:02:30 +00:00
|
|
|
|
G_CALLBACK (midori_view_notify_hadjustment_cb), view);
|
2010-03-30 20:45:49 +00:00
|
|
|
|
g_signal_connect (view->scrolled_window, "notify::vadjustment",
|
2009-09-16 20:02:30 +00:00
|
|
|
|
G_CALLBACK (midori_view_notify_vadjustment_cb), view);
|
2011-01-01 20:43:29 +00:00
|
|
|
|
|
|
|
|
|
midori_view_construct_web_view (view);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_finalize (GObject* object)
|
|
|
|
|
{
|
|
|
|
|
MidoriView* view;
|
|
|
|
|
|
|
|
|
|
view = MIDORI_VIEW (object);
|
|
|
|
|
|
2009-01-04 20:50:07 +00:00
|
|
|
|
if (view->settings)
|
|
|
|
|
g_signal_handlers_disconnect_by_func (view->settings,
|
|
|
|
|
midori_view_settings_notify_cb, view);
|
2010-07-22 02:12:20 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (view->item,
|
|
|
|
|
midori_view_item_meta_data_changed, view);
|
2008-10-17 19:12:16 +00:00
|
|
|
|
|
2008-10-27 03:23:41 +00:00
|
|
|
|
katze_assign (view->uri, NULL);
|
|
|
|
|
katze_assign (view->title, NULL);
|
|
|
|
|
katze_object_assign (view->icon, NULL);
|
2010-03-11 22:27:37 +00:00
|
|
|
|
katze_assign (view->icon_uri, NULL);
|
2010-11-13 14:11:02 +00:00
|
|
|
|
|
|
|
|
|
if (view->memory)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_unref (view->memory);
|
|
|
|
|
view->memory = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-27 03:23:41 +00:00
|
|
|
|
katze_assign (view->statusbar_text, NULL);
|
|
|
|
|
katze_assign (view->link_uri, NULL);
|
|
|
|
|
katze_assign (view->selected_text, NULL);
|
2009-05-03 01:11:33 +00:00
|
|
|
|
katze_object_assign (view->news_feeds, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2008-10-27 03:23:41 +00:00
|
|
|
|
katze_object_assign (view->settings, NULL);
|
|
|
|
|
katze_object_assign (view->item, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (midori_view_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_set_property (GObject* object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue* value,
|
|
|
|
|
GParamSpec* pspec)
|
|
|
|
|
{
|
|
|
|
|
MidoriView* view;
|
|
|
|
|
|
|
|
|
|
view = MIDORI_VIEW (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_TITLE:
|
2011-01-11 19:44:34 +00:00
|
|
|
|
midori_view_set_title (view, g_value_get_string (value));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
break;
|
2009-07-21 21:57:57 +00:00
|
|
|
|
case PROP_MINIMIZED:
|
|
|
|
|
view->minimized = g_value_get_boolean (value);
|
2010-07-22 02:12:20 +00:00
|
|
|
|
g_signal_handlers_block_by_func (view->item,
|
|
|
|
|
midori_view_item_meta_data_changed, view);
|
|
|
|
|
katze_item_set_meta_integer (view->item, "minimized",
|
|
|
|
|
view->minimized ? 1 : -1);
|
|
|
|
|
g_signal_handlers_unblock_by_func (view->item,
|
|
|
|
|
midori_view_item_meta_data_changed, view);
|
2009-07-21 21:57:57 +00:00
|
|
|
|
if (view->tab_label)
|
|
|
|
|
sokoke_widget_set_visible (view->tab_title, !view->minimized);
|
|
|
|
|
break;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
case PROP_ZOOM_LEVEL:
|
|
|
|
|
midori_view_set_zoom_level (view, g_value_get_float (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_STATUSBAR_TEXT:
|
|
|
|
|
katze_assign (view->statusbar_text, g_value_dup_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SETTINGS:
|
2011-01-11 19:44:34 +00:00
|
|
|
|
_midori_view_set_settings (view, g_value_get_object (value));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_get_property (GObject* object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue* value,
|
|
|
|
|
GParamSpec* pspec)
|
|
|
|
|
{
|
|
|
|
|
MidoriView* view = MIDORI_VIEW (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_URI:
|
|
|
|
|
g_value_set_string (value, view->uri);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_TITLE:
|
|
|
|
|
g_value_set_string (value, view->title);
|
|
|
|
|
break;
|
2010-04-13 21:44:21 +00:00
|
|
|
|
case PROP_SECURITY:
|
|
|
|
|
g_value_set_enum (value, view->security);
|
|
|
|
|
break;
|
2009-02-19 22:04:47 +00:00
|
|
|
|
case PROP_MIME_TYPE:
|
|
|
|
|
g_value_set_string (value, view->mime_type);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ICON:
|
|
|
|
|
g_value_set_object (value, view->icon);
|
|
|
|
|
break;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
case PROP_PROGRESS:
|
|
|
|
|
g_value_set_double (value, midori_view_get_progress (view));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_LOAD_STATUS:
|
|
|
|
|
g_value_set_enum (value, midori_view_get_load_status (view));
|
|
|
|
|
break;
|
2009-07-21 21:57:57 +00:00
|
|
|
|
case PROP_MINIMIZED:
|
|
|
|
|
g_value_set_boolean (value, view->minimized);
|
|
|
|
|
break;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
case PROP_ZOOM_LEVEL:
|
|
|
|
|
g_value_set_float (value, midori_view_get_zoom_level (view));
|
|
|
|
|
break;
|
2009-05-03 19:41:31 +00:00
|
|
|
|
case PROP_NEWS_FEEDS:
|
|
|
|
|
g_value_set_object (value, view->news_feeds);
|
|
|
|
|
break;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
case PROP_STATUSBAR_TEXT:
|
|
|
|
|
g_value_set_string (value, view->statusbar_text);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SETTINGS:
|
|
|
|
|
g_value_set_object (value, view->settings);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-06 20:27:29 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_focus_in_event (GtkWidget* widget,
|
|
|
|
|
GdkEventFocus* event)
|
|
|
|
|
{
|
2011-01-01 20:43:29 +00:00
|
|
|
|
/* Always propagate focus to the child web view */
|
2011-03-06 16:25:32 +00:00
|
|
|
|
gtk_widget_grab_focus (midori_view_get_web_view (MIDORI_VIEW (widget)));
|
2010-05-06 20:27:29 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_new:
|
2010-09-17 18:03:11 +00:00
|
|
|
|
* @net: %NULL
|
2008-09-26 21:13:46 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new view.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a new #MidoriView
|
2010-09-17 18:03:11 +00:00
|
|
|
|
*
|
2011-12-08 20:14:06 +00:00
|
|
|
|
* Deprecated: 0.2.8: Use midori_view_new_with_item() instead.
|
2008-09-26 21:13:46 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
2008-10-27 03:23:41 +00:00
|
|
|
|
midori_view_new (KatzeNet* net)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2010-05-25 16:50:16 +00:00
|
|
|
|
return g_object_new (MIDORI_TYPE_VIEW, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-01-11 19:44:34 +00:00
|
|
|
|
_midori_view_set_settings (MidoriView* view,
|
|
|
|
|
MidoriWebSettings* settings)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2009-09-27 21:48:08 +00:00
|
|
|
|
gboolean zoom_text_and_images, kinetic_scrolling;
|
2009-01-16 04:05:50 +00:00
|
|
|
|
|
2011-01-11 19:44:34 +00:00
|
|
|
|
if (view->settings)
|
|
|
|
|
g_signal_handlers_disconnect_by_func (view->settings,
|
|
|
|
|
midori_view_settings_notify_cb, view);
|
|
|
|
|
|
|
|
|
|
katze_object_assign (view->settings, settings);
|
|
|
|
|
if (!settings)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_ref (settings);
|
|
|
|
|
g_signal_connect (settings, "notify",
|
|
|
|
|
G_CALLBACK (midori_view_settings_notify_cb), view);
|
|
|
|
|
|
|
|
|
|
g_object_set (view->web_view, "settings", settings, NULL);
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_get (view->settings,
|
2009-01-16 04:05:50 +00:00
|
|
|
|
"zoom-text-and-images", &zoom_text_and_images,
|
2009-09-27 21:48:08 +00:00
|
|
|
|
"kinetic-scrolling", &kinetic_scrolling,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
"close-buttons-on-tabs", &view->close_buttons_on_tabs,
|
2008-12-03 03:16:19 +00:00
|
|
|
|
"open-new-pages-in", &view->open_new_pages_in,
|
2008-10-02 22:49:16 +00:00
|
|
|
|
"middle-click-opens-selection", &view->middle_click_opens_selection,
|
|
|
|
|
"open-tabs-in-the-background", &view->open_tabs_in_the_background,
|
2008-09-26 21:13:46 +00:00
|
|
|
|
NULL);
|
2009-01-16 04:05:50 +00:00
|
|
|
|
|
|
|
|
|
if (view->web_view)
|
2009-09-27 21:48:08 +00:00
|
|
|
|
g_object_set (view->web_view,
|
|
|
|
|
"full-content-zoom", zoom_text_and_images, NULL);
|
2010-03-30 20:45:49 +00:00
|
|
|
|
g_object_set (view->scrolled_window, "kinetic-scrolling", kinetic_scrolling, NULL);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-17 18:03:11 +00:00
|
|
|
|
/**
|
2011-01-01 19:05:34 +00:00
|
|
|
|
* midori_view_new_with_title:
|
2010-09-17 18:03:11 +00:00
|
|
|
|
* @title: a title, or %NULL
|
|
|
|
|
* @settings: a #MidoriWebSettings, or %NULL
|
2011-01-01 19:05:34 +00:00
|
|
|
|
* @append: if %TRUE, the view should be appended
|
2010-09-17 18:03:11 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new view with the specified parameters that
|
|
|
|
|
* is visible by default.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a new #MidoriView
|
|
|
|
|
*
|
2011-01-01 19:05:34 +00:00
|
|
|
|
* Since: 0.3.0
|
2011-12-08 20:14:06 +00:00
|
|
|
|
* Deprecated: 0.4.3
|
2010-09-17 18:03:11 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
2011-01-01 19:05:34 +00:00
|
|
|
|
midori_view_new_with_title (const gchar* title,
|
|
|
|
|
MidoriWebSettings* settings,
|
|
|
|
|
gboolean append)
|
2010-09-17 18:03:11 +00:00
|
|
|
|
{
|
2011-12-07 20:27:38 +00:00
|
|
|
|
KatzeItem* item = katze_item_new ();
|
|
|
|
|
item->name = g_strdup (title);
|
2011-12-07 22:15:04 +00:00
|
|
|
|
if (append)
|
|
|
|
|
katze_item_set_meta_integer (item, "append", 1);
|
|
|
|
|
return midori_view_new_with_item (item, settings);
|
2011-12-07 20:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_new_with_item:
|
|
|
|
|
* @item: a #KatzeItem, or %NULL
|
|
|
|
|
* @settings: a #MidoriWebSettings, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Creates a new view from an item that is visible by default.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a new #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.4.3
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
midori_view_new_with_item (KatzeItem* item,
|
2011-12-07 22:15:04 +00:00
|
|
|
|
MidoriWebSettings* settings)
|
2011-12-07 20:27:38 +00:00
|
|
|
|
{
|
2011-12-11 01:27:11 +00:00
|
|
|
|
MidoriView* view = g_object_new (MIDORI_TYPE_VIEW,
|
|
|
|
|
"title", item ? item->name : NULL,
|
|
|
|
|
NULL);
|
2010-09-17 18:03:11 +00:00
|
|
|
|
if (settings)
|
2011-01-11 19:44:34 +00:00
|
|
|
|
_midori_view_set_settings (view, settings);
|
2011-12-07 20:27:38 +00:00
|
|
|
|
if (item)
|
|
|
|
|
katze_object_assign (view->item, katze_item_copy (item));
|
2010-09-17 18:03:11 +00:00
|
|
|
|
gtk_widget_show ((GtkWidget*)view);
|
|
|
|
|
return (GtkWidget*)view;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_settings_notify_cb (MidoriWebSettings* settings,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* name;
|
|
|
|
|
GValue value = { 0, };
|
|
|
|
|
|
|
|
|
|
name = g_intern_string (g_param_spec_get_name (pspec));
|
|
|
|
|
g_value_init (&value, pspec->value_type);
|
|
|
|
|
g_object_get_property (G_OBJECT (view->settings), name, &value);
|
|
|
|
|
|
2011-05-01 04:59:00 +00:00
|
|
|
|
if (name == g_intern_string ("zoom-text-and-images"))
|
2009-01-16 04:05:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (view->web_view)
|
|
|
|
|
g_object_set (view->web_view, "full-content-zoom",
|
|
|
|
|
g_value_get_boolean (&value), NULL);
|
|
|
|
|
}
|
2009-09-27 21:48:08 +00:00
|
|
|
|
else if (name == g_intern_string ("kinetic-scrolling"))
|
|
|
|
|
{
|
|
|
|
|
g_object_set (view, "kinetic-scrolling",
|
|
|
|
|
g_value_get_boolean (&value), NULL);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
else if (name == g_intern_string ("close-buttons-on-tabs"))
|
|
|
|
|
{
|
|
|
|
|
view->close_buttons_on_tabs = g_value_get_boolean (&value);
|
|
|
|
|
sokoke_widget_set_visible (view->tab_close,
|
|
|
|
|
view->close_buttons_on_tabs);
|
|
|
|
|
}
|
2008-12-03 03:16:19 +00:00
|
|
|
|
else if (name == g_intern_string ("open-new-pages-in"))
|
|
|
|
|
view->open_new_pages_in = g_value_get_enum (&value);
|
2008-10-02 22:49:16 +00:00
|
|
|
|
else if (name == g_intern_string ("middle-click-opens-selection"))
|
|
|
|
|
view->middle_click_opens_selection = g_value_get_boolean (&value);
|
|
|
|
|
else if (name == g_intern_string ("open-tabs-in-the-background"))
|
|
|
|
|
view->open_tabs_in_the_background = g_value_get_boolean (&value);
|
2011-10-11 00:48:47 +00:00
|
|
|
|
else if (name == g_intern_string ("enable-scripts"))
|
|
|
|
|
{
|
|
|
|
|
/* Speed dial is only editable with scripts, so regenerate it */
|
|
|
|
|
if (midori_view_is_blank (view))
|
|
|
|
|
midori_view_reload (view, FALSE);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_set_settings:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @settings: a #MidoriWebSettings
|
|
|
|
|
*
|
|
|
|
|
* Assigns a settings instance to the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_set_settings (MidoriView* view,
|
|
|
|
|
MidoriWebSettings* settings)
|
|
|
|
|
{
|
2008-12-21 16:52:10 +00:00
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
2011-01-11 19:44:34 +00:00
|
|
|
|
g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings));
|
2008-12-21 16:52:10 +00:00
|
|
|
|
|
|
|
|
|
if (view->settings == settings)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-01-11 19:44:34 +00:00
|
|
|
|
_midori_view_set_settings (view, settings);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "settings");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_load_status:
|
|
|
|
|
* @web_view: a #MidoriView
|
|
|
|
|
*
|
2011-10-30 13:29:04 +00:00
|
|
|
|
* Determines the current loading status of a view. There is no
|
|
|
|
|
* error state, unlike webkit_web_view_get_load_status().
|
2008-09-26 21:13:46 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: the current #MidoriLoadStatus
|
|
|
|
|
**/
|
|
|
|
|
MidoriLoadStatus
|
|
|
|
|
midori_view_get_load_status (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), MIDORI_LOAD_FINISHED);
|
|
|
|
|
|
|
|
|
|
return view->load_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_progress:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the current loading progress as
|
|
|
|
|
* a fraction between 0.0 and 1.0.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the current loading progress
|
|
|
|
|
**/
|
|
|
|
|
gdouble
|
|
|
|
|
midori_view_get_progress (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), 0.0);
|
|
|
|
|
|
|
|
|
|
return view->progress;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-23 15:46:14 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_web_inspector_construct_window (gpointer inspector,
|
|
|
|
|
WebKitWebView* web_view,
|
|
|
|
|
GtkWidget* inspector_view,
|
|
|
|
|
MidoriView* view)
|
2008-11-01 18:15:58 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* title;
|
2011-02-17 20:38:54 +00:00
|
|
|
|
gchar* label;
|
2008-11-01 18:15:58 +00:00
|
|
|
|
GtkWidget* window;
|
|
|
|
|
GtkWidget* toplevel;
|
|
|
|
|
GdkScreen* screen;
|
|
|
|
|
gint width, height;
|
|
|
|
|
GtkIconTheme* icon_theme;
|
|
|
|
|
GdkPixbuf* icon;
|
|
|
|
|
GdkPixbuf* gray_icon;
|
|
|
|
|
|
2011-02-17 20:38:54 +00:00
|
|
|
|
label = g_strdup (midori_view_get_display_title (view));
|
|
|
|
|
title = g_strdup_printf (_("Inspect page - %s"), label);
|
2008-11-01 18:15:58 +00:00
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), title);
|
|
|
|
|
g_free (title);
|
2011-02-17 20:38:54 +00:00
|
|
|
|
g_free (label);
|
2008-11-01 18:15:58 +00:00
|
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
|
2010-01-29 21:44:34 +00:00
|
|
|
|
if (gtk_widget_is_toplevel (toplevel))
|
2008-11-01 18:15:58 +00:00
|
|
|
|
{
|
|
|
|
|
screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
|
|
|
|
|
width = gdk_screen_get_width (screen) / 1.7;
|
|
|
|
|
height = gdk_screen_get_height (screen) / 1.7;
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Attempt to make a gray version of the icon on the fly */
|
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (
|
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (view)));
|
|
|
|
|
icon = gtk_icon_theme_load_icon (icon_theme, "midori", 32,
|
|
|
|
|
GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
|
|
|
|
|
if (icon)
|
|
|
|
|
{
|
|
|
|
|
gray_icon = gdk_pixbuf_copy (icon);
|
|
|
|
|
if (gray_icon)
|
|
|
|
|
{
|
2008-11-16 00:04:12 +00:00
|
|
|
|
gdk_pixbuf_saturate_and_pixelate (gray_icon, gray_icon, 0.1f, FALSE);
|
2008-11-01 18:15:58 +00:00
|
|
|
|
gtk_window_set_icon (GTK_WINDOW (window), gray_icon);
|
|
|
|
|
g_object_unref (gray_icon);
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (window), "midori");
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), inspector_view);
|
|
|
|
|
gtk_widget_show_all (window);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
|
2011-09-28 16:01:51 +00:00
|
|
|
|
g_signal_connect (window, "key-press-event",
|
|
|
|
|
G_CALLBACK (midori_view_inspector_window_key_press_event_cb), NULL);
|
|
|
|
|
|
2009-12-23 15:46:14 +00:00
|
|
|
|
/* FIXME: Update window title with URI */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WebKitWebView*
|
|
|
|
|
midori_view_web_inspector_inspect_web_view_cb (gpointer inspector,
|
|
|
|
|
WebKitWebView* web_view,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* inspector_view = webkit_web_view_new ();
|
|
|
|
|
#if HAVE_HILDON
|
|
|
|
|
gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0);
|
|
|
|
|
g_signal_connect (view->web_view, "tap-and-hold",
|
|
|
|
|
G_CALLBACK (midori_view_web_view_tap_and_hold_cb), NULL);
|
|
|
|
|
#endif
|
|
|
|
|
midori_view_web_inspector_construct_window (inspector,
|
|
|
|
|
web_view, inspector_view, view);
|
2008-11-01 18:15:58 +00:00
|
|
|
|
return WEBKIT_WEB_VIEW (inspector_view);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-25 20:24:41 +00:00
|
|
|
|
static gboolean
|
2010-11-01 15:48:07 +00:00
|
|
|
|
midori_view_web_inspector_show_window_cb (WebKitWebInspector* inspector,
|
|
|
|
|
MidoriView* view)
|
2010-05-25 20:24:41 +00:00
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
WebKitWebView* inspector_view = webkit_web_inspector_get_web_view (inspector);
|
|
|
|
|
GtkWidget* window = gtk_widget_get_toplevel (GTK_WIDGET (inspector_view));
|
2010-05-25 20:24:41 +00:00
|
|
|
|
if (!window)
|
|
|
|
|
return FALSE;
|
|
|
|
|
gtk_window_present (GTK_WINDOW (window));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-23 15:46:14 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_inspector_attach_window_cb (gpointer inspector,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
WebKitWebView* inspector_view = webkit_web_inspector_get_web_view (inspector);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
g_signal_emit (view, signals[ATTACH_INSPECTOR], 0, inspector_view);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_inspector_detach_window_cb (gpointer inspector,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
2010-11-01 15:48:07 +00:00
|
|
|
|
WebKitWebView* inspector_view = webkit_web_inspector_get_web_view (inspector);
|
|
|
|
|
GtkWidget* parent = gtk_widget_get_parent (GTK_WIDGET (inspector_view));
|
2009-12-23 15:46:14 +00:00
|
|
|
|
if (GTK_IS_WINDOW (parent))
|
|
|
|
|
return FALSE;
|
2010-11-01 15:48:07 +00:00
|
|
|
|
|
2009-12-23 15:46:14 +00:00
|
|
|
|
gtk_widget_hide (parent);
|
2011-04-04 19:56:21 +00:00
|
|
|
|
g_signal_emit (view, signals[DETACH_INSPECTOR], 0, inspector_view);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
midori_view_web_inspector_construct_window (inspector,
|
2010-11-01 15:48:07 +00:00
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view), GTK_WIDGET (inspector_view), view);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-13 21:57:47 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
midori_view_web_inspector_close_window_cb (gpointer inspector,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
WebKitWebView* inspector_view = webkit_web_inspector_get_web_view (inspector);
|
|
|
|
|
GtkWidget* scrolled = gtk_widget_get_parent (GTK_WIDGET (inspector_view));
|
|
|
|
|
if (!scrolled)
|
|
|
|
|
return FALSE;
|
2011-04-19 21:21:31 +00:00
|
|
|
|
gtk_widget_hide (gtk_widget_get_parent (scrolled));
|
2011-04-13 21:57:47 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_construct_web_view (MidoriView* view)
|
|
|
|
|
{
|
2008-12-03 03:16:19 +00:00
|
|
|
|
gpointer inspector;
|
2008-10-15 01:07:38 +00:00
|
|
|
|
|
2009-05-17 18:29:31 +00:00
|
|
|
|
g_return_if_fail (!view->web_view);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
view->web_view = webkit_web_view_new ();
|
|
|
|
|
|
2009-03-04 01:03:38 +00:00
|
|
|
|
/* Load something to avoid a bug where WebKit might not set a main frame */
|
|
|
|
|
webkit_web_view_open (WEBKIT_WEB_VIEW (view->web_view), "");
|
2008-10-15 01:07:38 +00:00
|
|
|
|
|
2009-10-13 20:58:50 +00:00
|
|
|
|
#if HAVE_HILDON
|
|
|
|
|
gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
g_signal_connect (view->web_view, "tap-and-hold",
|
|
|
|
|
G_CALLBACK (midori_view_web_view_tap_and_hold_cb), NULL);
|
2009-10-13 20:58:50 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
g_object_connect (view->web_view,
|
2009-09-20 18:56:52 +00:00
|
|
|
|
"signal::navigation-policy-decision-requested",
|
|
|
|
|
midori_view_web_view_navigation_decision_cb, view,
|
2009-10-21 20:56:00 +00:00
|
|
|
|
"signal::resource-request-starting",
|
|
|
|
|
midori_view_web_view_resource_request_cb, view,
|
2010-10-13 23:31:10 +00:00
|
|
|
|
"signal::database-quota-exceeded",
|
|
|
|
|
midori_view_web_view_database_quota_exceeded_cb, view,
|
2010-10-11 20:52:07 +00:00
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 23)
|
|
|
|
|
"signal::geolocation-policy-decision-requested",
|
|
|
|
|
midori_view_web_view_geolocation_decision_cb, view,
|
|
|
|
|
#endif
|
2008-10-15 01:07:38 +00:00
|
|
|
|
"signal::load-started",
|
|
|
|
|
webkit_web_view_load_started_cb, view,
|
|
|
|
|
"signal::load-committed",
|
|
|
|
|
webkit_web_view_load_committed_cb, view,
|
|
|
|
|
"signal::load-progress-changed",
|
|
|
|
|
webkit_web_view_progress_changed_cb, view,
|
|
|
|
|
"signal::load-finished",
|
|
|
|
|
webkit_web_view_load_finished_cb, view,
|
2010-05-02 10:09:54 +00:00
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 18)
|
|
|
|
|
"signal::notify::icon-uri",
|
|
|
|
|
midori_web_view_notify_icon_uri_cb, view,
|
|
|
|
|
#endif
|
2011-02-27 00:48:06 +00:00
|
|
|
|
"signal::notify::uri",
|
|
|
|
|
webkit_web_view_notify_uri_cb, view,
|
2009-05-14 23:18:14 +00:00
|
|
|
|
"signal::notify::title",
|
|
|
|
|
webkit_web_view_notify_title_cb, view,
|
2008-10-15 01:07:38 +00:00
|
|
|
|
"signal::status-bar-text-changed",
|
|
|
|
|
webkit_web_view_statusbar_text_changed_cb, view,
|
2009-09-22 21:58:16 +00:00
|
|
|
|
"signal::leave-notify-event",
|
|
|
|
|
midori_view_web_view_leave_notify_event_cb, view,
|
2008-10-15 01:07:38 +00:00
|
|
|
|
"signal::hovering-over-link",
|
|
|
|
|
webkit_web_view_hovering_over_link_cb, view,
|
|
|
|
|
"signal::button-press-event",
|
|
|
|
|
gtk_widget_button_press_event_cb, view,
|
2009-05-18 00:43:56 +00:00
|
|
|
|
"signal-after::key-press-event",
|
2009-02-22 00:45:22 +00:00
|
|
|
|
gtk_widget_key_press_event_cb, view,
|
2008-10-15 01:07:38 +00:00
|
|
|
|
"signal::scroll-event",
|
|
|
|
|
gtk_widget_scroll_event_cb, view,
|
|
|
|
|
"signal::populate-popup",
|
|
|
|
|
webkit_web_view_populate_popup_cb, view,
|
|
|
|
|
"signal::console-message",
|
|
|
|
|
webkit_web_view_console_message_cb, view,
|
2011-04-04 00:59:16 +00:00
|
|
|
|
"signal::script-alert",
|
|
|
|
|
midori_view_web_view_script_alert_cb, view,
|
2008-10-15 01:07:38 +00:00
|
|
|
|
"signal::window-object-cleared",
|
|
|
|
|
webkit_web_view_window_object_cleared_cb, view,
|
2008-12-03 03:16:19 +00:00
|
|
|
|
"signal::create-web-view",
|
|
|
|
|
webkit_web_view_create_web_view_cb, view,
|
2010-06-01 20:19:11 +00:00
|
|
|
|
"signal-after::mime-type-policy-decision-requested",
|
2009-01-02 01:28:04 +00:00
|
|
|
|
webkit_web_view_mime_type_decision_cb, view,
|
2009-03-19 17:28:50 +00:00
|
|
|
|
"signal::download-requested",
|
|
|
|
|
webkit_web_view_download_requested_cb, view,
|
2009-08-24 18:10:58 +00:00
|
|
|
|
"signal::print-requested",
|
|
|
|
|
midori_view_web_view_print_requested_cb, view,
|
2009-10-21 20:19:23 +00:00
|
|
|
|
"signal-after::load-error",
|
2009-05-02 19:44:20 +00:00
|
|
|
|
webkit_web_view_load_error_cb, view,
|
2008-10-15 01:07:38 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
2009-02-28 13:03:23 +00:00
|
|
|
|
if (view->settings)
|
|
|
|
|
{
|
2009-03-16 00:54:22 +00:00
|
|
|
|
g_object_set (view->web_view, "settings", view->settings,
|
|
|
|
|
"full-content-zoom", katze_object_get_boolean (view->settings,
|
|
|
|
|
"zoom-text-and-images"), NULL);
|
2009-02-28 13:03:23 +00:00
|
|
|
|
}
|
2008-10-15 01:07:38 +00:00
|
|
|
|
|
2010-03-30 20:45:49 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (view->scrolled_window), view->web_view);
|
|
|
|
|
gtk_widget_show_all (view->scrolled_window);
|
2008-11-01 18:15:58 +00:00
|
|
|
|
|
2010-11-01 15:48:07 +00:00
|
|
|
|
inspector = webkit_web_view_get_inspector ((WebKitWebView*)view->web_view);
|
2009-12-23 15:46:14 +00:00
|
|
|
|
g_object_connect (inspector,
|
|
|
|
|
"signal::inspect-web-view",
|
|
|
|
|
midori_view_web_inspector_inspect_web_view_cb, view,
|
2010-05-25 20:24:41 +00:00
|
|
|
|
"signal::show-window",
|
|
|
|
|
midori_view_web_inspector_show_window_cb, view,
|
2009-12-23 15:46:14 +00:00
|
|
|
|
"signal::attach-window",
|
|
|
|
|
midori_view_web_inspector_attach_window_cb, view,
|
|
|
|
|
"signal::detach-window",
|
|
|
|
|
midori_view_web_inspector_detach_window_cb, view,
|
2011-04-13 21:57:47 +00:00
|
|
|
|
"signal::close-window",
|
|
|
|
|
midori_view_web_inspector_close_window_cb, view,
|
2009-12-23 15:46:14 +00:00
|
|
|
|
NULL);
|
2008-10-15 01:07:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 02:31:52 +00:00
|
|
|
|
static gchar* list_netscape_plugins ()
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* web_view = webkit_web_view_new ();
|
|
|
|
|
WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
|
|
|
|
|
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
|
2011-04-25 19:04:28 +00:00
|
|
|
|
/* Joins available plugins like this: URI1|title1,URI2|title2 */
|
2011-02-26 02:31:52 +00:00
|
|
|
|
gchar* value = sokoke_js_script_eval (js_context,
|
|
|
|
|
"function plugins (l) { var f = new Array (); for (i in l) "
|
|
|
|
|
"{ var p = l[i].name + '|' + l[i].filename; "
|
|
|
|
|
"if (f.indexOf (p) == -1) f.push (p); } return f; }"
|
|
|
|
|
"plugins (navigator.plugins)", NULL);
|
|
|
|
|
gchar** items = g_strsplit (value, ",", 0);
|
|
|
|
|
guint i = 0;
|
|
|
|
|
GString* ns_plugins = g_string_new (NULL);
|
|
|
|
|
if (items != NULL)
|
|
|
|
|
while (items[i] != NULL)
|
|
|
|
|
{
|
|
|
|
|
gchar** parts = g_strsplit (items[i], "|", 2);
|
|
|
|
|
if (parts && *parts && !g_str_equal (parts[1], "undefined"))
|
|
|
|
|
{
|
|
|
|
|
g_string_append (ns_plugins, "<tr><td>");
|
|
|
|
|
g_string_append (ns_plugins, parts[1]);
|
|
|
|
|
g_string_append (ns_plugins, "</td><td>");
|
|
|
|
|
g_string_append (ns_plugins, parts[0]);
|
|
|
|
|
g_string_append (ns_plugins, "</tr>");
|
|
|
|
|
}
|
|
|
|
|
g_strfreev (parts);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if (g_str_has_prefix (value, "undefined"))
|
|
|
|
|
g_string_append (ns_plugins, "<tr><td>No plugins found</td></tr>");
|
|
|
|
|
g_strfreev (items);
|
|
|
|
|
g_free (value);
|
2011-04-17 23:28:38 +00:00
|
|
|
|
gtk_widget_destroy (web_view);
|
2011-02-26 02:31:52 +00:00
|
|
|
|
return g_string_free (ns_plugins, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 23:28:38 +00:00
|
|
|
|
static gchar*
|
|
|
|
|
list_video_formats ()
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* web_view = webkit_web_view_new ();
|
|
|
|
|
WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
|
|
|
|
|
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
|
|
|
|
|
gchar* value = sokoke_js_script_eval (js_context,
|
|
|
|
|
"var supported = function (format) { "
|
|
|
|
|
"var video = document.createElement('video');"
|
|
|
|
|
"return !!video.canPlayType && video.canPlayType (format) != 'no' };"
|
2011-10-31 23:28:41 +00:00
|
|
|
|
"' H264: ' + "
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"supported('video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"') + "
|
2011-10-31 23:28:41 +00:00
|
|
|
|
"' Ogg Theora: ' + "
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"supported('video/ogg; codecs=\"theora, vorbis\"') + "
|
2011-10-31 23:28:41 +00:00
|
|
|
|
"' WebM: ' + "
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"supported('video/webm; codecs=\"vp8, vorbis\"')"
|
2011-04-17 23:28:38 +00:00
|
|
|
|
"", NULL);
|
|
|
|
|
gtk_widget_destroy (web_view);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
static gchar*
|
2011-11-10 22:17:18 +00:00
|
|
|
|
prepare_speed_dial_html (MidoriView* view,
|
|
|
|
|
gboolean load_missing)
|
2011-03-22 21:59:56 +00:00
|
|
|
|
{
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
|
|
|
GKeyFile* key_file;
|
2011-06-24 22:05:46 +00:00
|
|
|
|
GString* markup = NULL;
|
2011-10-09 23:38:39 +00:00
|
|
|
|
guint slot_count = 1, i, grid_index = 3, slot_size;
|
2011-06-24 22:05:46 +00:00
|
|
|
|
gchar* speed_dial_head;
|
|
|
|
|
gchar* file_path;
|
2011-10-09 23:38:39 +00:00
|
|
|
|
gchar** groups;
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
|
|
|
|
g_object_get (browser, "speed-dial", &key_file, NULL);
|
2011-10-28 23:16:08 +00:00
|
|
|
|
file_path = sokoke_find_data_filename ("speeddial-head-" MIDORI_VERSION ".html", TRUE);
|
2011-06-24 22:05:46 +00:00
|
|
|
|
|
2011-10-28 23:16:08 +00:00
|
|
|
|
if (key_file != NULL
|
|
|
|
|
&& g_access (file_path, F_OK) == 0
|
2011-06-24 22:05:46 +00:00
|
|
|
|
&& g_file_get_contents (file_path, &speed_dial_head, NULL, NULL))
|
|
|
|
|
{
|
|
|
|
|
gchar* header = sokoke_replace_variables (speed_dial_head,
|
|
|
|
|
"{title}", _("Speed Dial"),
|
|
|
|
|
"{click_to_add}", _("Click to add a shortcut"),
|
|
|
|
|
"{enter_shortcut_address}", _("Enter shortcut address"),
|
2011-10-18 17:04:14 +00:00
|
|
|
|
"{enter_shortcut_name}", _("Enter shortcut title"),
|
2011-06-24 22:05:46 +00:00
|
|
|
|
"{are_you_sure}", _("Are you sure you want to delete this shortcut?"),
|
2011-10-09 23:38:39 +00:00
|
|
|
|
NULL);
|
2011-06-24 22:05:46 +00:00
|
|
|
|
|
|
|
|
|
markup = g_string_new (header);
|
|
|
|
|
|
|
|
|
|
g_free (speed_dial_head);
|
|
|
|
|
g_free (file_path);
|
|
|
|
|
g_free (header);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_free (file_path);
|
2011-12-11 01:57:04 +00:00
|
|
|
|
return NULL;
|
2011-06-24 22:05:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-09 23:38:39 +00:00
|
|
|
|
groups = g_key_file_get_groups (key_file, NULL);
|
|
|
|
|
for (i = 0; groups[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (g_key_file_has_key (key_file, groups[i], "uri", NULL))
|
|
|
|
|
slot_count++;
|
|
|
|
|
}
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
2011-10-09 23:38:39 +00:00
|
|
|
|
/* try to guess the best X by X grid size */
|
|
|
|
|
while ((grid_index * grid_index) < slot_count)
|
|
|
|
|
grid_index++;
|
|
|
|
|
|
|
|
|
|
/* percent width size of one slot */
|
|
|
|
|
slot_size = (100 / grid_index);
|
2011-10-11 00:48:47 +00:00
|
|
|
|
/* No editing in private/ app mode or without scripts */
|
2011-10-09 23:38:39 +00:00
|
|
|
|
g_string_append_printf (markup,
|
2011-10-11 00:48:47 +00:00
|
|
|
|
"%s<style>.cross { display:none }</style>%s"
|
2011-10-09 23:38:39 +00:00
|
|
|
|
"<style> div.shortcut { height: %d%%; width: %d%%; }</style>\n",
|
2011-10-11 00:48:47 +00:00
|
|
|
|
sokoke_is_app_or_private () ? "" : "<noscript>",
|
|
|
|
|
sokoke_is_app_or_private () ? "" : "</noscript>",
|
2011-10-09 23:38:39 +00:00
|
|
|
|
slot_size + 1, slot_size - 4);
|
|
|
|
|
|
2011-11-10 21:24:21 +00:00
|
|
|
|
/* Combined width of slots should always be less than 100%.
|
|
|
|
|
* Use half of the remaining percentage as a margin size */
|
|
|
|
|
g_string_append_printf (markup,
|
|
|
|
|
"<style> body { overflow:hidden } #content { margin-left: %d%%; }</style>",
|
|
|
|
|
(100 - ((slot_size - 4) * grid_index)) / 2);
|
|
|
|
|
|
2011-10-12 23:40:39 +00:00
|
|
|
|
if (katze_object_get_boolean (view->settings, "close-buttons-left"))
|
|
|
|
|
g_string_append_printf (markup,
|
|
|
|
|
"<style>.cross { left: -14px }</style>");
|
|
|
|
|
|
2011-11-18 21:17:39 +00:00
|
|
|
|
for (i = 0; groups[i]; i++)
|
2011-03-22 21:59:56 +00:00
|
|
|
|
{
|
2011-11-18 21:17:39 +00:00
|
|
|
|
gchar* uri = g_key_file_get_string (key_file, groups[i], "uri", NULL);
|
|
|
|
|
if (uri && strstr (uri, "://"))
|
2011-03-22 21:59:56 +00:00
|
|
|
|
{
|
2011-11-18 21:17:39 +00:00
|
|
|
|
gchar* title = g_key_file_get_string (key_file, groups[i], "title", NULL);
|
2011-04-08 19:18:41 +00:00
|
|
|
|
gchar* thumb_file = sokoke_build_thumbnail_path (uri);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
gchar* encoded;
|
2011-11-18 22:54:49 +00:00
|
|
|
|
guint slot = atoi (groups[i] + strlen ("Dial "));
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
2011-03-23 21:32:49 +00:00
|
|
|
|
if (g_access (thumb_file, F_OK) == 0)
|
|
|
|
|
{
|
2011-03-24 09:55:12 +00:00
|
|
|
|
gsize sz;
|
|
|
|
|
gchar* thumb_content;
|
2011-03-23 21:32:49 +00:00
|
|
|
|
g_file_get_contents (thumb_file, &thumb_content, &sz, NULL);
|
|
|
|
|
encoded = g_base64_encode ((guchar*)thumb_content, sz);
|
|
|
|
|
g_free (thumb_content);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-12-11 01:57:04 +00:00
|
|
|
|
encoded = NULL;
|
2011-11-10 22:17:18 +00:00
|
|
|
|
if (load_missing)
|
2011-11-18 21:17:39 +00:00
|
|
|
|
midori_view_speed_dial_get_thumb (view, groups[i], uri);
|
2011-03-23 21:32:49 +00:00
|
|
|
|
}
|
2011-03-24 09:55:12 +00:00
|
|
|
|
g_free (thumb_file);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
|
|
|
|
g_string_append_printf (markup,
|
2011-10-09 23:38:39 +00:00
|
|
|
|
"<div class=\"shortcut\" id=\"s%d\"><div class=\"preview\">"
|
2011-10-10 23:52:39 +00:00
|
|
|
|
"<a class=\"cross\" href=\"#\" onclick='clearShortcut(\"s%d\");'></a>"
|
2011-11-15 21:42:03 +00:00
|
|
|
|
"<a href=\"%s\"><img src=\"data:image/png;base64,%s\"></a>"
|
2011-10-10 23:52:39 +00:00
|
|
|
|
"</div><div class=\"title\" onclick='renameShortcut(\"s%d\");'>%s</div></div>\n",
|
2011-12-11 01:57:04 +00:00
|
|
|
|
slot, slot, uri, encoded ? encoded : "", slot, title ? title : "");
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
|
|
|
|
g_free (title);
|
2011-03-24 09:55:12 +00:00
|
|
|
|
g_free (encoded);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
}
|
2011-11-18 22:54:49 +00:00
|
|
|
|
else if (strcmp (groups[i], "settings"))
|
2011-11-18 21:17:39 +00:00
|
|
|
|
g_key_file_remove_group (key_file, groups[i], NULL);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
2011-05-05 23:55:39 +00:00
|
|
|
|
g_free (uri);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
}
|
2011-11-18 21:17:39 +00:00
|
|
|
|
g_strfreev (groups);
|
|
|
|
|
|
|
|
|
|
g_string_append_printf (markup,
|
|
|
|
|
"<div class=\"shortcut\" id=\"s%d\"><div class=\"preview new\">"
|
|
|
|
|
"<a class=\"add\" href=\"#\" onclick='return getAction(\"s%d\");'></a>"
|
|
|
|
|
"</div><div class=\"title\">%s</div></div>\n",
|
2011-11-18 22:54:49 +00:00
|
|
|
|
slot_count + 1, slot_count + 1, _("Click to add a shortcut"));
|
2011-03-22 21:59:56 +00:00
|
|
|
|
g_string_append_printf (markup,
|
2011-10-09 23:38:39 +00:00
|
|
|
|
"</div>\n</body>\n</html>\n");
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
|
|
|
|
return g_string_free (markup, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_set_uri:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Opens the specified URI in the view.
|
2011-01-01 19:05:34 +00:00
|
|
|
|
*
|
|
|
|
|
* Since 0.3.0 a warning is shown if the view is not yet
|
|
|
|
|
* contained in a browser. This is because extensions
|
|
|
|
|
* can't monitor page loading if that happens.
|
2008-09-26 21:13:46 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_set_uri (MidoriView* view,
|
|
|
|
|
const gchar* uri)
|
|
|
|
|
{
|
|
|
|
|
gchar* data;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2011-01-01 19:05:34 +00:00
|
|
|
|
if (!gtk_widget_get_parent (GTK_WIDGET (view)))
|
|
|
|
|
g_warning ("Calling %s() before adding the view to a browser. This "
|
|
|
|
|
"breaks extensions that monitor page loading.", G_STRFUNC);
|
|
|
|
|
|
2010-06-07 19:48:23 +00:00
|
|
|
|
if (g_getenv ("MIDORI_UNARMED") == NULL)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2011-12-07 20:27:38 +00:00
|
|
|
|
if (!uri || !strcmp (uri, "") || !strcmp (uri, "about:blank"))
|
2009-05-07 20:22:43 +00:00
|
|
|
|
{
|
2011-03-22 21:59:56 +00:00
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
GTimer* timer = NULL;
|
|
|
|
|
|
|
|
|
|
if (g_getenv ("MIDORI_STARTTIME") != NULL)
|
|
|
|
|
timer = g_timer_new ();
|
|
|
|
|
#endif
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-12-11 01:27:11 +00:00
|
|
|
|
katze_assign (view->uri, NULL);
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-09-21 22:27:55 +00:00
|
|
|
|
if (speeddial_markup == NULL)
|
2011-11-10 22:17:18 +00:00
|
|
|
|
speeddial_markup = prepare_speed_dial_html (view, TRUE);
|
2011-08-06 22:46:06 +00:00
|
|
|
|
|
2011-08-05 20:50:05 +00:00
|
|
|
|
midori_view_load_alternate_string (view,
|
2011-12-11 01:57:04 +00:00
|
|
|
|
speeddial_markup ? speeddial_markup : "", "about:blank", NULL);
|
2009-05-09 21:29:35 +00:00
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
if (g_getenv ("MIDORI_STARTTIME") != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("Speed Dial: \t%fs", g_timer_elapsed (timer, NULL));
|
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2009-05-07 20:22:43 +00:00
|
|
|
|
}
|
2010-01-07 20:12:36 +00:00
|
|
|
|
/* This is not prefectly elegant, but creating
|
|
|
|
|
special pages inline is the simplest solution. */
|
2011-10-19 07:53:18 +00:00
|
|
|
|
else if (g_str_has_prefix (uri, "error:") || midori_uri_is_blank (uri))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
data = NULL;
|
2009-05-02 19:44:20 +00:00
|
|
|
|
if (!strncmp (uri, "error:nodocs ", 13))
|
2008-10-03 20:23:00 +00:00
|
|
|
|
{
|
2008-11-30 01:08:28 +00:00
|
|
|
|
gchar* title;
|
|
|
|
|
|
2008-10-03 20:23:00 +00:00
|
|
|
|
katze_assign (view->uri, g_strdup (&uri[13]));
|
2008-11-30 01:08:28 +00:00
|
|
|
|
title = g_strdup_printf (_("No documentation installed"));
|
2008-10-03 20:23:00 +00:00
|
|
|
|
data = g_strdup_printf (
|
2008-11-30 01:08:28 +00:00
|
|
|
|
"<html><head><title>%s</title></head>"
|
|
|
|
|
"<body><h1>%s</h1>"
|
2011-08-09 17:48:50 +00:00
|
|
|
|
"<img src=\"res://logo-shade.png\" "
|
2010-01-07 23:42:23 +00:00
|
|
|
|
"style=\"position: absolute; right: 15px; bottom: 15px; z-index: -9;\">"
|
2011-08-01 22:02:00 +00:00
|
|
|
|
"<p />There is no documentation installed at %s. "
|
2008-10-03 20:23:00 +00:00
|
|
|
|
"You may want to ask your distribution or "
|
|
|
|
|
"package maintainer for it or if this a custom build "
|
2011-08-01 22:02:00 +00:00
|
|
|
|
"verify that the build is setup properly. "
|
|
|
|
|
"<a href=\"http://wiki.xfce.org/midori/faq\">View the FAQ online</a>"
|
2008-10-03 20:23:00 +00:00
|
|
|
|
"</body></html>",
|
2011-08-09 17:48:50 +00:00
|
|
|
|
title, title, view->uri);
|
2008-11-30 01:08:28 +00:00
|
|
|
|
g_free (title);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
2011-03-21 19:56:13 +00:00
|
|
|
|
else if (!strcmp (uri, "about:") || !strcmp (uri, "about:version"))
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
2011-10-31 23:29:31 +00:00
|
|
|
|
gchar* arguments = g_strjoinv (" ", sokoke_get_argv (NULL));
|
|
|
|
|
gchar* command_line = sokoke_replace_variables (
|
|
|
|
|
arguments, g_get_home_dir (), "~", NULL);
|
2011-10-31 02:57:51 +00:00
|
|
|
|
gchar* architecture, *platform;
|
|
|
|
|
const gchar* sys_name = midori_web_settings_get_system_name (
|
|
|
|
|
&architecture, &platform);
|
2010-01-31 21:10:24 +00:00
|
|
|
|
gchar* ident = katze_object_get_string (view->settings, "user-agent");
|
2011-02-26 02:31:52 +00:00
|
|
|
|
gchar* netscape_plugins = list_netscape_plugins ();
|
2011-04-17 23:28:38 +00:00
|
|
|
|
gchar* video_formats = list_video_formats ();
|
2010-01-07 20:12:36 +00:00
|
|
|
|
|
|
|
|
|
katze_assign (view->uri, g_strdup (uri));
|
|
|
|
|
data = g_strdup_printf (
|
|
|
|
|
"<html><head><title>about:version</title></head>"
|
|
|
|
|
"<body><h1>about:version</h1>"
|
2011-02-02 00:46:14 +00:00
|
|
|
|
"<p>%s</p>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"<img src=\"res://logo-shade.png\" "
|
2010-01-07 23:42:23 +00:00
|
|
|
|
"style=\"position: absolute; right: 15px; bottom: 15px; z-index: -9;\">"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"<table>"
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"<tr><td>Command line</td><td>%s</td></tr>"
|
|
|
|
|
"<tr><td>Midori</td><td>%s</td></tr>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"<tr><td>WebKitGTK+</td><td>%d.%d.%d (%d.%d.%d)</td></tr>"
|
|
|
|
|
"<tr><td>GTK+</td><td>%d.%d.%d (%d.%d.%d)</td></tr>"
|
|
|
|
|
"<tr><td>Glib</td><td>%d.%d.%d (%d.%d.%d)</td></tr>"
|
|
|
|
|
"<tr><td>libsoup</td><td>%s</td></tr>"
|
2011-12-01 18:56:16 +00:00
|
|
|
|
"<tr><td>cairo</td><td>%s (%s)</td></tr>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"<tr><td>libnotify</td><td>%s</td></tr>"
|
|
|
|
|
"<tr><td>libunique</td><td>%s</td></tr>"
|
|
|
|
|
"<tr><td>libhildon</td><td>%s</td></tr>"
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"<tr><td>Platform</td><td>%s %s %s</td></tr>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"<tr><td>Identification</td><td>%s</td></tr>"
|
2011-10-31 02:57:51 +00:00
|
|
|
|
"<tr><td>Video Formats</td><td>%s</td></tr>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"</table>"
|
2011-02-26 02:31:52 +00:00
|
|
|
|
"<h2>Netscape Plugins:</h2><table>%s</table>"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"</body></html>",
|
2011-02-02 00:46:14 +00:00
|
|
|
|
_("Version numbers in brackets show the version used at runtime."),
|
2010-01-12 22:22:50 +00:00
|
|
|
|
command_line,
|
2011-10-31 02:57:51 +00:00
|
|
|
|
PACKAGE_VERSION,
|
|
|
|
|
WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, WEBKIT_MICRO_VERSION,
|
2010-01-07 20:12:36 +00:00
|
|
|
|
webkit_major_version (),
|
|
|
|
|
webkit_minor_version (),
|
|
|
|
|
webkit_micro_version (),
|
|
|
|
|
GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
|
|
|
|
|
gtk_major_version, gtk_minor_version, gtk_micro_version,
|
|
|
|
|
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
|
|
|
|
|
glib_major_version, glib_minor_version, glib_micro_version,
|
|
|
|
|
LIBSOUP_VERSION,
|
2011-12-01 18:56:16 +00:00
|
|
|
|
CAIRO_VERSION_STRING, cairo_version_string (),
|
2011-10-31 02:57:51 +00:00
|
|
|
|
LIBNOTIFY_VERSION,
|
|
|
|
|
UNIQUE_VERSION,
|
2010-01-07 20:12:36 +00:00
|
|
|
|
HAVE_HILDON ? "Yes" : "No",
|
2011-10-31 02:57:51 +00:00
|
|
|
|
platform, sys_name, architecture ? architecture : "", ident,
|
|
|
|
|
video_formats, netscape_plugins);
|
2010-01-12 22:22:50 +00:00
|
|
|
|
g_free (command_line);
|
2011-10-31 23:29:31 +00:00
|
|
|
|
g_free (arguments);
|
2010-01-12 22:22:50 +00:00
|
|
|
|
g_free (ident);
|
2011-02-26 02:31:52 +00:00
|
|
|
|
g_free (netscape_plugins);
|
2011-04-17 23:28:38 +00:00
|
|
|
|
g_free (video_formats);
|
2011-02-26 02:31:52 +00:00
|
|
|
|
}
|
2010-01-07 20:12:36 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
katze_assign (view->uri, g_strdup (uri));
|
|
|
|
|
data = g_strdup_printf (
|
|
|
|
|
"<html><head><title>%s</title></head><body><h1>%s</h1>"
|
2011-08-09 17:48:50 +00:00
|
|
|
|
"<img src=\"res://logo-shade.png\" "
|
2010-01-07 23:42:23 +00:00
|
|
|
|
"style=\"position: absolute; right: 15px; bottom: 15px; z-index: -9;\">"
|
2010-01-07 20:12:36 +00:00
|
|
|
|
"</body></html>", view->uri, view->uri);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
2010-01-07 20:12:36 +00:00
|
|
|
|
|
|
|
|
|
webkit_web_view_load_html_string (
|
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view), data, view->uri);
|
|
|
|
|
g_free (data);
|
2011-12-11 01:27:11 +00:00
|
|
|
|
if (g_strcmp0 (view->item->uri, view->uri))
|
2011-12-07 22:19:32 +00:00
|
|
|
|
katze_item_set_uri (view->item, view->uri);
|
2010-07-23 20:24:11 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "uri");
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
2011-12-11 01:57:04 +00:00
|
|
|
|
else if (katze_item_get_meta_boolean (view->item, "delay"))
|
2010-05-31 21:39:02 +00:00
|
|
|
|
{
|
2011-12-07 22:08:11 +00:00
|
|
|
|
katze_assign (view->uri, g_strdup (uri));
|
|
|
|
|
katze_item_set_meta_integer (view->item, "delay", -1);
|
2010-05-31 21:39:02 +00:00
|
|
|
|
midori_view_display_error (
|
2011-07-28 20:58:16 +00:00
|
|
|
|
view, view->uri, view->title ? view->title : view->uri,
|
2010-05-31 21:39:02 +00:00
|
|
|
|
_("Page loading delayed"),
|
|
|
|
|
_("Loading delayed either due to a recent crash or startup preferences."),
|
|
|
|
|
_("Load Page"),
|
|
|
|
|
NULL);
|
2011-12-11 01:27:11 +00:00
|
|
|
|
if (g_strcmp0 (view->item->uri, uri))
|
2011-12-07 22:19:32 +00:00
|
|
|
|
katze_item_set_uri (view->item, uri);
|
2010-07-23 20:24:11 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "uri");
|
2010-05-31 21:39:02 +00:00
|
|
|
|
}
|
2008-12-08 23:02:38 +00:00
|
|
|
|
else if (g_str_has_prefix (uri, "javascript:"))
|
|
|
|
|
{
|
2009-12-30 22:53:58 +00:00
|
|
|
|
gboolean result;
|
|
|
|
|
gchar* exception;
|
|
|
|
|
|
|
|
|
|
result = midori_view_execute_script (view, &uri[11], &exception);
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
2011-02-02 00:10:02 +00:00
|
|
|
|
sokoke_message_dialog (GTK_MESSAGE_ERROR, "javascript:",
|
|
|
|
|
exception, FALSE);
|
2009-12-30 22:53:58 +00:00
|
|
|
|
g_free (exception);
|
|
|
|
|
}
|
2008-12-08 23:02:38 +00:00
|
|
|
|
}
|
2010-10-20 18:56:05 +00:00
|
|
|
|
else if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri))
|
2009-03-26 22:46:36 +00:00
|
|
|
|
{
|
2009-04-20 17:10:13 +00:00
|
|
|
|
sokoke_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL);
|
2009-03-26 22:46:36 +00:00
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2011-10-19 07:53:18 +00:00
|
|
|
|
katze_assign (view->uri, midori_uri_format_for_display (uri));
|
2011-12-11 01:27:11 +00:00
|
|
|
|
if (g_strcmp0 (view->item->uri, view->uri))
|
2011-12-07 22:19:32 +00:00
|
|
|
|
katze_item_set_uri (view->item, view->uri);
|
2010-07-23 20:24:11 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "uri");
|
2008-09-26 21:13:46 +00:00
|
|
|
|
webkit_web_view_open (WEBKIT_WEB_VIEW (view->web_view), uri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_is_blank:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether the view is currently empty.
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_is_blank (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), TRUE);
|
|
|
|
|
|
2011-10-19 07:53:18 +00:00
|
|
|
|
return midori_uri_is_blank (midori_view_get_display_uri (view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_icon:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
2010-03-11 22:27:37 +00:00
|
|
|
|
* Retrieves the icon of the view, or a default icon. See
|
|
|
|
|
* midori_view_get_icon_uri() if you need to distinguish
|
|
|
|
|
* the origin of an icon.
|
2008-09-26 21:13:46 +00:00
|
|
|
|
*
|
2009-06-20 21:47:40 +00:00
|
|
|
|
* The returned icon is owned by the @view and must not be modified.
|
|
|
|
|
*
|
2010-03-11 22:27:37 +00:00
|
|
|
|
* Return value: a #GdkPixbuf, or %NULL
|
2008-09-26 21:13:46 +00:00
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf*
|
|
|
|
|
midori_view_get_icon (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
return view->icon;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-11 22:27:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_icon_uri:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the address of the icon of the view
|
|
|
|
|
* if the loaded website has an icon, otherwise
|
|
|
|
|
* %NULL.
|
|
|
|
|
* Note that if there is no icon uri, midori_view_get_icon()
|
|
|
|
|
* will still return a default icon.
|
|
|
|
|
*
|
|
|
|
|
* The returned string is owned by the @view and must not be freed.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a string, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.5
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_icon_uri (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
return view->icon_uri;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_display_uri:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
2008-10-07 20:30:09 +00:00
|
|
|
|
* Retrieves a string that is suitable for displaying.
|
|
|
|
|
*
|
|
|
|
|
* Note that "about:blank" is represented as "".
|
2008-09-26 21:13:46 +00:00
|
|
|
|
*
|
|
|
|
|
* You can assume that the string is not %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Return value: an URI string
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_display_uri (MidoriView* view)
|
|
|
|
|
{
|
2008-10-07 20:30:09 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), "");
|
|
|
|
|
|
|
|
|
|
/* Something in the stack tends to turn "" into "about:blank".
|
|
|
|
|
Yet for practical purposes we prefer "". */
|
|
|
|
|
if (view->uri && !strcmp (view->uri, "about:blank"))
|
|
|
|
|
return "";
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
if (view->uri && *view->uri)
|
|
|
|
|
return view->uri;
|
2008-10-07 20:30:09 +00:00
|
|
|
|
return "";
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_display_title:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves a string that is suitable for displaying
|
|
|
|
|
* as a title. Most of the time this will be the title
|
|
|
|
|
* or the current URI.
|
|
|
|
|
*
|
|
|
|
|
* You can assume that the string is not %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a title string
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_display_title (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), "about:blank");
|
|
|
|
|
|
|
|
|
|
if (view->title && *view->title)
|
|
|
|
|
return view->title;
|
2009-05-15 16:51:54 +00:00
|
|
|
|
if (midori_view_is_blank (view))
|
|
|
|
|
return _("Blank page");
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return midori_view_get_display_uri (view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_link_uri:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the uri of the currently focused link,
|
|
|
|
|
* particularly while the mouse hovers a link or a
|
|
|
|
|
* context menu is being opened.
|
|
|
|
|
*
|
|
|
|
|
* Return value: an URI string, or %NULL if there is no link focussed
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_link_uri (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
return view->link_uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_has_selection:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether something in the view is selected.
|
|
|
|
|
*
|
|
|
|
|
* This function returns %FALSE if there is a selection
|
|
|
|
|
* that effectively only consists of whitespace.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE if effectively there is a selection
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_has_selection (MidoriView* view)
|
|
|
|
|
{
|
2011-10-05 18:50:31 +00:00
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 4, 3)
|
2011-09-21 21:50:51 +00:00
|
|
|
|
WebKitDOMDocument* doc;
|
|
|
|
|
WebKitDOMDOMWindow* window;
|
|
|
|
|
WebKitDOMDOMSelection* selection;
|
|
|
|
|
WebKitDOMRange* range;
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2011-09-21 21:50:51 +00:00
|
|
|
|
|
2011-10-05 18:50:31 +00:00
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 4, 3)
|
2011-09-21 21:50:51 +00:00
|
|
|
|
doc = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
window = webkit_dom_document_get_default_view (doc);
|
|
|
|
|
selection = webkit_dom_dom_window_get_selection (window);
|
2011-10-28 21:12:40 +00:00
|
|
|
|
if (selection == NULL
|
|
|
|
|
|| webkit_dom_dom_selection_get_range_count (selection) == 0)
|
2011-09-21 21:50:51 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
|
|
|
|
|
if (range == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
katze_assign (view->selected_text, webkit_dom_range_get_text (range));
|
|
|
|
|
#else
|
2009-02-12 21:43:31 +00:00
|
|
|
|
katze_assign (view->selected_text, webkit_web_view_get_selected_text (
|
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view)));
|
2011-09-21 21:50:51 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->selected_text && *view->selected_text)
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
2008-09-26 21:13:46 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_selected_text:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the currently selected text.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the selected text, or %NULL
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_selected_text (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (midori_view_has_selection (view))
|
2009-02-12 21:37:08 +00:00
|
|
|
|
return view->selected_text;
|
|
|
|
|
return NULL;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_can_cut_clipboard:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether a selection can be cut.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE if a selection can be cut
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_cut_clipboard (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->web_view)
|
|
|
|
|
return webkit_web_view_can_cut_clipboard (
|
2008-09-26 21:13:46 +00:00
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view));
|
2008-10-15 01:07:38 +00:00
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_can_copy_clipboard:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether a selection can be copied.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE if a selection can be copied
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_copy_clipboard (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->web_view)
|
|
|
|
|
return webkit_web_view_can_copy_clipboard (
|
2008-09-26 21:13:46 +00:00
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view));
|
2008-10-15 01:07:38 +00:00
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_can_paste_clipboard:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether a selection can be pasted.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE if a selection can be pasted
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_paste_clipboard (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->web_view)
|
|
|
|
|
return webkit_web_view_can_paste_clipboard (
|
2008-09-26 21:13:46 +00:00
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view));
|
2008-10-15 01:07:38 +00:00
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_proxy_menu_item:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves a proxy menu item that is typically added to a Window menu
|
|
|
|
|
* and which on activation switches to the right window/ tab.
|
|
|
|
|
*
|
|
|
|
|
* The item is created on the first call and will be updated to reflect
|
|
|
|
|
* changes to the icon and title automatically.
|
|
|
|
|
*
|
|
|
|
|
* The menu item is valid until it is removed from its container.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the proxy #GtkMenuItem
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
midori_view_get_proxy_menu_item (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
const gchar* title;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
if (!view->menu_item)
|
|
|
|
|
{
|
|
|
|
|
title = midori_view_get_display_title (view);
|
2009-11-15 16:58:43 +00:00
|
|
|
|
view->menu_item = katze_image_menu_item_new_ellipsized (title);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (view->menu_item),
|
|
|
|
|
gtk_image_new_from_pixbuf (view->icon));
|
|
|
|
|
|
|
|
|
|
g_signal_connect (view->menu_item, "destroy",
|
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
|
&view->menu_item);
|
|
|
|
|
}
|
|
|
|
|
return view->menu_item;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 20:54:55 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_menu_duplicate_tab_cb (GtkWidget* menuitem,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
MidoriNewView where = MIDORI_NEW_VIEW_TAB;
|
2011-12-08 20:14:06 +00:00
|
|
|
|
GtkWidget* new_view = midori_view_new_with_item (view->item, view->settings);
|
2011-04-19 21:16:34 +00:00
|
|
|
|
g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where, TRUE);
|
2011-12-08 20:14:06 +00:00
|
|
|
|
midori_view_set_uri (MIDORI_VIEW (new_view), view->uri);
|
2009-06-30 20:54:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 01:49:19 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_browser_close_tabs_cb (GtkWidget* view,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* remaining_view = data;
|
|
|
|
|
if (view != remaining_view)
|
|
|
|
|
gtk_widget_destroy (view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_menu_close_other_tabs_cb (GtkWidget* menuitem,
|
|
|
|
|
GtkWidget* view)
|
|
|
|
|
{
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (view);
|
|
|
|
|
midori_browser_foreach (browser, midori_view_browser_close_tabs_cb, view);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 21:57:57 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_menu_minimize_tab_cb (GtkWidget* menuitem,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_object_set (view, "minimized", !view->minimized, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-24 21:58:37 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_menu_close_cb (GtkWidget* menuitem,
|
|
|
|
|
GtkWidget* view)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_destroy (view);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-27 21:52:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_tab_menu:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves a menu that is typically shown when right-clicking
|
|
|
|
|
* a tab label or equivalent representation.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a #GtkMenu
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.8
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
midori_view_get_tab_menu (MidoriView* view)
|
|
|
|
|
{
|
2009-10-22 20:54:52 +00:00
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
|
GtkActionGroup* actions;
|
2009-06-27 21:52:48 +00:00
|
|
|
|
GtkWidget* menu;
|
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
2009-10-22 20:54:52 +00:00
|
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
|
|
|
actions = midori_browser_get_action_group (browser);
|
|
|
|
|
|
2009-06-27 21:52:48 +00:00
|
|
|
|
menu = gtk_menu_new ();
|
2009-10-22 20:54:52 +00:00
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "TabNew"));
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
|
gtk_action_group_get_action (actions, "UndoTabClose"));
|
2009-07-22 21:56:16 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
2009-06-27 21:52:48 +00:00
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (STOCK_WINDOW_NEW, NULL);
|
2010-06-21 19:24:01 +00:00
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (menuitem), _("Open in New _Window"));
|
2009-06-27 21:52:48 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_window_new_cb), view);
|
2009-06-30 20:54:55 +00:00
|
|
|
|
menuitem = gtk_menu_item_new_with_mnemonic (_("_Duplicate Tab"));
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_duplicate_tab_cb), view);
|
2009-07-21 21:57:57 +00:00
|
|
|
|
menuitem = gtk_menu_item_new_with_mnemonic (
|
2010-08-22 19:59:11 +00:00
|
|
|
|
view->minimized ? _("Show Tab _Label") : _("Show Tab _Icon Only"));
|
2009-07-21 21:57:57 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_minimize_tab_cb), view);
|
2009-06-27 21:52:48 +00:00
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
2010-01-14 01:49:19 +00:00
|
|
|
|
menuitem = gtk_menu_item_new_with_mnemonic (_("Close ot_her Tabs"));
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_close_other_tabs_cb), view);
|
2009-06-27 21:52:48 +00:00
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_menu_close_cb), view);
|
|
|
|
|
gtk_widget_show_all (menu);
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
static gboolean
|
2010-11-19 21:51:50 +00:00
|
|
|
|
midori_view_tab_label_button_press_event (GtkWidget* tab_label,
|
|
|
|
|
GdkEventButton* event,
|
|
|
|
|
GtkWidget* widget)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (event->button == 2)
|
|
|
|
|
{
|
|
|
|
|
/* Close the widget on middle click */
|
|
|
|
|
gtk_widget_destroy (widget);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2011-09-21 21:03:00 +00:00
|
|
|
|
else if (MIDORI_EVENT_CONTEXT_MENU (event))
|
2009-06-24 21:58:37 +00:00
|
|
|
|
{
|
|
|
|
|
/* Show a context menu on right click */
|
2009-06-27 21:52:48 +00:00
|
|
|
|
GtkWidget* menu = midori_view_get_tab_menu (MIDORI_VIEW (widget));
|
2009-06-24 21:58:37 +00:00
|
|
|
|
|
2009-06-27 21:52:48 +00:00
|
|
|
|
katze_widget_popup (widget, GTK_MENU (menu),
|
2009-11-15 17:00:33 +00:00
|
|
|
|
event, KATZE_MENU_POSITION_CURSOR);
|
2009-06-24 21:58:37 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_close_clicked (GtkWidget* tab_close,
|
|
|
|
|
GtkWidget* widget)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_destroy (widget);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-21 00:40:19 +00:00
|
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2008-10-30 21:17:19 +00:00
|
|
|
|
static void
|
2010-01-10 20:56:53 +00:00
|
|
|
|
midori_view_tab_icon_style_set_cb (GtkWidget* tab_close,
|
2008-10-30 21:17:19 +00:00
|
|
|
|
GtkStyle* previous_style)
|
|
|
|
|
{
|
2010-01-10 20:56:53 +00:00
|
|
|
|
GtkRequisition size;
|
|
|
|
|
gtk_widget_size_request (gtk_bin_get_child (GTK_BIN (tab_close)), &size);
|
|
|
|
|
gtk_widget_set_size_request (tab_close, size.width, size.height);
|
2008-10-30 21:17:19 +00:00
|
|
|
|
}
|
2011-10-21 00:40:19 +00:00
|
|
|
|
#endif
|
2008-10-30 21:17:19 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2008-11-25 22:51:10 +00:00
|
|
|
|
midori_view_update_tab_title (GtkWidget* label,
|
|
|
|
|
gint size,
|
|
|
|
|
gdouble angle)
|
2008-10-30 21:17:19 +00:00
|
|
|
|
{
|
2008-11-25 22:51:10 +00:00
|
|
|
|
if (angle == 0.0 || angle == 360.0)
|
|
|
|
|
{
|
2009-05-11 23:27:51 +00:00
|
|
|
|
if (gtk_label_get_ellipsize (GTK_LABEL (label)) != PANGO_ELLIPSIZE_START)
|
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
2008-11-25 22:51:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_NONE);
|
|
|
|
|
}
|
|
|
|
|
gtk_label_set_angle (GTK_LABEL (label), angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_box_repack (GtkBox* box,
|
|
|
|
|
GtkWidget* child)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* old_box;
|
|
|
|
|
gboolean expand, fill;
|
|
|
|
|
guint padding;
|
|
|
|
|
GtkPackType pack_type;
|
|
|
|
|
|
|
|
|
|
old_box = gtk_widget_get_parent (child);
|
|
|
|
|
g_return_if_fail (GTK_IS_BOX (old_box));
|
|
|
|
|
|
|
|
|
|
gtk_box_query_child_packing (GTK_BOX (old_box), child,
|
|
|
|
|
&expand, &fill, &padding, &pack_type);
|
|
|
|
|
|
|
|
|
|
g_object_ref (child);
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (old_box), child);
|
|
|
|
|
if (pack_type == GTK_PACK_START)
|
|
|
|
|
gtk_box_pack_start (box, child, expand, fill, padding);
|
|
|
|
|
else
|
|
|
|
|
gtk_box_pack_end (box, child, expand, fill, padding);
|
|
|
|
|
g_object_unref (child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
midori_view_tab_label_parent_set (GtkWidget* tab_label,
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
|
|
|
GObject* old_parent,
|
|
|
|
|
#else
|
2008-11-25 22:51:10 +00:00
|
|
|
|
GtkObject* old_parent,
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#endif
|
2008-11-25 22:51:10 +00:00
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* parent;
|
|
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
|
/* FIXME: Disconnect orientation notification
|
2008-11-25 22:51:10 +00:00
|
|
|
|
if (old_parent)
|
2009-01-09 21:54:40 +00:00
|
|
|
|
; */
|
2008-11-25 22:51:10 +00:00
|
|
|
|
|
|
|
|
|
if (!(parent = gtk_widget_get_parent (tab_label)))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (GTK_IS_NOTEBOOK (parent))
|
|
|
|
|
{
|
|
|
|
|
GtkPositionType pos;
|
|
|
|
|
gdouble old_angle, angle;
|
|
|
|
|
GtkWidget* box;
|
|
|
|
|
|
|
|
|
|
pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (parent));
|
|
|
|
|
old_angle = gtk_label_get_angle (GTK_LABEL (view->tab_title));
|
|
|
|
|
switch (pos)
|
|
|
|
|
{
|
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
|
angle = 90.0;
|
|
|
|
|
break;
|
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
|
angle = 270.0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
angle = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (old_angle != angle)
|
|
|
|
|
{
|
2011-08-18 16:08:24 +00:00
|
|
|
|
GtkWidget* align;
|
|
|
|
|
|
2008-11-25 22:51:10 +00:00
|
|
|
|
if (angle == 0.0)
|
|
|
|
|
box = gtk_hbox_new (FALSE, 1);
|
|
|
|
|
else
|
|
|
|
|
box = gtk_vbox_new (FALSE, 1);
|
|
|
|
|
gtk_box_repack (GTK_BOX (box), view->tab_icon);
|
|
|
|
|
gtk_box_repack (GTK_BOX (box), view->tab_title);
|
2011-08-18 16:08:24 +00:00
|
|
|
|
align = gtk_widget_get_parent (view->tab_close);
|
|
|
|
|
gtk_box_repack (GTK_BOX (box), align);
|
2008-11-25 22:51:10 +00:00
|
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (tab_label),
|
|
|
|
|
gtk_bin_get_child (GTK_BIN (tab_label)));
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (tab_label), GTK_WIDGET (box));
|
|
|
|
|
gtk_widget_show (box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
midori_view_update_tab_title (view->tab_title, 10, angle);
|
|
|
|
|
|
|
|
|
|
/* FIXME: Connect orientation notification */
|
|
|
|
|
}
|
2008-10-30 21:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-26 21:50:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_label_ellipsize:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines how labels representing the view should be
|
|
|
|
|
* ellipsized, which is helpful for alternative labels.
|
|
|
|
|
*
|
|
|
|
|
* Return value: how to ellipsize the label
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.1.9
|
|
|
|
|
**/
|
|
|
|
|
PangoEllipsizeMode
|
|
|
|
|
midori_view_get_label_ellipsize (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), PANGO_ELLIPSIZE_END);
|
|
|
|
|
|
|
|
|
|
if (view->tab_label)
|
|
|
|
|
return gtk_label_get_ellipsize (GTK_LABEL (view->tab_title));
|
|
|
|
|
return PANGO_ELLIPSIZE_END;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 21:05:40 +00:00
|
|
|
|
static void midori_view_tab_label_data_received (GtkWidget* widget,
|
|
|
|
|
GdkDragContext* context,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
GtkSelectionData* data,
|
|
|
|
|
guint ttype,
|
|
|
|
|
guint timestamp,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
gchar **uri;
|
|
|
|
|
gchar* text;
|
|
|
|
|
|
|
|
|
|
uri = gtk_selection_data_get_uris (data);
|
|
|
|
|
if (uri != NULL)
|
|
|
|
|
{
|
|
|
|
|
midori_view_set_uri (view, uri[0]);
|
|
|
|
|
g_strfreev (uri);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-04-10 03:38:46 +00:00
|
|
|
|
text = (gchar*) gtk_selection_data_get_text (data);
|
2011-03-23 21:05:40 +00:00
|
|
|
|
midori_view_set_uri (view, text);
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_proxy_tab_label:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves a proxy tab label that is typically used when
|
|
|
|
|
* adding the view to a notebook.
|
|
|
|
|
*
|
2008-11-25 22:51:10 +00:00
|
|
|
|
* Note that the label actually adjusts its orientation
|
|
|
|
|
* to the according tab position when used in a notebook.
|
|
|
|
|
*
|
2008-09-26 21:13:46 +00:00
|
|
|
|
* The label is created on the first call and will be updated to reflect
|
|
|
|
|
* changes of the loading progress and title.
|
|
|
|
|
*
|
|
|
|
|
* The label is valid until it is removed from its container.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the proxy #GtkEventBox
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
midori_view_get_proxy_tab_label (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* event_box;
|
|
|
|
|
GtkWidget* hbox;
|
2011-10-21 00:40:19 +00:00
|
|
|
|
static const gchar style_fixup[] =
|
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
|
"* {\n"
|
|
|
|
|
"-GtkButton-default-border : 0;\n"
|
|
|
|
|
"-GtkButton-default-outside-border : 0;\n"
|
|
|
|
|
"-GtkButton-inner-border: 0;\n"
|
|
|
|
|
"-GtkWidget-focus-line-width : 0;\n"
|
|
|
|
|
"-GtkWidget-focus-padding : 0;\n"
|
|
|
|
|
"padding: 0;\n"
|
|
|
|
|
"}";
|
|
|
|
|
GtkStyleContext* context;
|
|
|
|
|
GtkCssProvider* css_provider;
|
|
|
|
|
#else
|
|
|
|
|
"style \"midori-close-button-style\"\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
"GtkWidget::focus-padding = 0\n"
|
|
|
|
|
"GtkWidget::focus-line-width = 0\n"
|
|
|
|
|
"xthickness = 0\n"
|
|
|
|
|
"ythickness = 0\n"
|
|
|
|
|
"}\n"
|
|
|
|
|
"widget \"*.midori-close-button\" style \"midori-close-button-style\"";
|
|
|
|
|
#endif
|
2008-09-26 21:13:46 +00:00
|
|
|
|
GtkWidget* image;
|
2010-01-10 20:56:53 +00:00
|
|
|
|
GtkWidget* align;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
if (!view->tab_label)
|
|
|
|
|
{
|
|
|
|
|
view->tab_icon = katze_throbber_new ();
|
|
|
|
|
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
|
|
|
|
|
midori_view_get_icon (view));
|
|
|
|
|
|
|
|
|
|
view->tab_title = gtk_label_new (midori_view_get_display_title (view));
|
2008-10-30 21:17:19 +00:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (view->tab_title), 0.0, 0.5);
|
2011-10-21 00:40:19 +00:00
|
|
|
|
gtk_misc_set_padding (GTK_MISC (view->tab_title), 0, 0);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
event_box = gtk_event_box_new ();
|
|
|
|
|
gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 1);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (event_box), GTK_WIDGET (hbox));
|
2008-11-25 22:51:10 +00:00
|
|
|
|
midori_view_update_tab_title (view->tab_title, 10, 0.0);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
|
|
|
|
view->tab_close = gtk_button_new ();
|
|
|
|
|
gtk_button_set_relief (GTK_BUTTON (view->tab_close), GTK_RELIEF_NONE);
|
|
|
|
|
gtk_button_set_focus_on_click (GTK_BUTTON (view->tab_close), FALSE);
|
2011-10-21 00:40:19 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
|
|
|
context = gtk_widget_get_style_context (view->tab_close);
|
|
|
|
|
css_provider = gtk_css_provider_new ();
|
|
|
|
|
gtk_css_provider_load_from_data (css_provider, style_fixup, -1, NULL);
|
|
|
|
|
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (css_provider),
|
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
|
#else
|
|
|
|
|
gtk_rc_parse_string (style_fixup);
|
|
|
|
|
gtk_widget_set_name (view->tab_close, "midori-close-button");
|
|
|
|
|
g_signal_connect (view->tab_close, "style-set",
|
|
|
|
|
G_CALLBACK (midori_view_tab_icon_style_set_cb), NULL);
|
|
|
|
|
#endif
|
2008-10-25 23:36:15 +00:00
|
|
|
|
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
|
2010-01-10 20:56:53 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (view->tab_close), image);
|
2011-10-21 00:40:19 +00:00
|
|
|
|
align = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
|
2010-01-10 20:56:53 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (align), view->tab_close);
|
2008-10-25 22:54:57 +00:00
|
|
|
|
|
2011-02-17 19:55:12 +00:00
|
|
|
|
if (katze_object_get_boolean (view->settings, "close-buttons-left"))
|
|
|
|
|
{
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), view->tab_icon, FALSE, FALSE, 0);
|
2011-03-23 19:41:40 +00:00
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), view->tab_title, TRUE, TRUE, 0);
|
2011-02-17 19:55:12 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), view->tab_icon, FALSE, FALSE, 0);
|
2011-03-23 19:41:40 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), view->tab_title, TRUE, TRUE, 0);
|
2011-02-17 19:55:12 +00:00
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), align, FALSE, FALSE, 0);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (event_box));
|
|
|
|
|
|
2010-05-08 22:30:24 +00:00
|
|
|
|
if (view->minimized)
|
|
|
|
|
gtk_widget_hide (view->tab_title);
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (!view->close_buttons_on_tabs)
|
2008-09-26 21:13:46 +00:00
|
|
|
|
gtk_widget_hide (view->tab_close);
|
|
|
|
|
|
2010-11-19 21:51:50 +00:00
|
|
|
|
g_signal_connect (event_box, "button-press-event",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_button_press_event), view);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_signal_connect (view->tab_close, "clicked",
|
|
|
|
|
G_CALLBACK (midori_view_tab_close_clicked), view);
|
|
|
|
|
|
|
|
|
|
view->tab_label = event_box;
|
2008-11-10 21:02:43 +00:00
|
|
|
|
g_signal_connect (view->tab_icon, "destroy",
|
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
|
&view->tab_icon);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_signal_connect (view->tab_label, "destroy",
|
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
|
&view->tab_label);
|
2008-11-25 22:51:10 +00:00
|
|
|
|
|
|
|
|
|
g_signal_connect (view->tab_label, "parent-set",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_parent_set),
|
|
|
|
|
view);
|
2011-03-23 21:05:40 +00:00
|
|
|
|
gtk_drag_dest_set (view->tab_label, GTK_DEST_DEFAULT_ALL, NULL,
|
|
|
|
|
0, GDK_ACTION_COPY);
|
|
|
|
|
gtk_drag_dest_add_text_targets (view->tab_label);
|
|
|
|
|
gtk_drag_dest_add_uri_targets (view->tab_label);
|
|
|
|
|
g_signal_connect (view->tab_label, "drag-data-received",
|
|
|
|
|
G_CALLBACK (midori_view_tab_label_data_received),
|
|
|
|
|
view);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
return view->tab_label;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 21:57:57 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_item_meta_data_changed (KatzeItem* item,
|
|
|
|
|
const gchar* key,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
if (g_str_equal (key, "minimized"))
|
|
|
|
|
g_object_set (view, "minimized",
|
|
|
|
|
katze_item_get_meta_string (item, key) != NULL, NULL);
|
2009-09-16 20:02:30 +00:00
|
|
|
|
else if (g_str_has_prefix (key, "scroll"))
|
|
|
|
|
{
|
|
|
|
|
gint value = katze_item_get_meta_integer (item, key);
|
2009-10-07 21:51:35 +00:00
|
|
|
|
if (view->scrollh == -2 && key[6] == 'h')
|
2009-09-16 20:02:30 +00:00
|
|
|
|
view->scrollh = value > -1 ? value : 0;
|
2009-10-07 21:51:35 +00:00
|
|
|
|
else if (view->scrollv == -2 && key[6] == 'v')
|
2009-09-16 20:02:30 +00:00
|
|
|
|
view->scrollv = value > -1 ? value : 0;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-07-21 21:57:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_proxy_item:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Retrieves a proxy item that can be used for bookmark storage as
|
|
|
|
|
* well as session management.
|
|
|
|
|
*
|
2010-07-22 02:12:20 +00:00
|
|
|
|
* The item reflects changes to the title and uri automatically.
|
2008-09-26 21:13:46 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: the proxy #KatzeItem
|
|
|
|
|
**/
|
|
|
|
|
KatzeItem*
|
|
|
|
|
midori_view_get_proxy_item (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
return view->item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_zoom_level:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines the current zoom level of the view.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the current zoom level
|
|
|
|
|
**/
|
|
|
|
|
gfloat
|
|
|
|
|
midori_view_get_zoom_level (MidoriView* view)
|
|
|
|
|
{
|
2009-03-05 21:45:34 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), 1.0f);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
|
2009-03-05 22:09:22 +00:00
|
|
|
|
if (view->web_view != NULL)
|
|
|
|
|
return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
return 1.0f;
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_set_zoom_level:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @zoom_level: the new zoom level
|
|
|
|
|
*
|
|
|
|
|
* Sets the current zoom level of the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_set_zoom_level (MidoriView* view,
|
|
|
|
|
gfloat zoom_level)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_set_zoom_level (
|
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view), zoom_level);
|
2009-03-05 21:45:34 +00:00
|
|
|
|
g_object_notify (G_OBJECT (view), "zoom-level");
|
2008-10-15 01:07:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_zoom_in (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2011-01-05 18:21:50 +00:00
|
|
|
|
return view->web_view != NULL
|
|
|
|
|
&& (katze_object_get_boolean (view->settings, "zoom-text-and-images")
|
2011-10-10 19:58:19 +00:00
|
|
|
|
|| !g_str_has_prefix (view->mime_type ? view->mime_type : "", "image/"));
|
2008-10-15 01:07:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_zoom_out (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2011-01-05 18:21:50 +00:00
|
|
|
|
return view->web_view != NULL
|
|
|
|
|
&& (katze_object_get_boolean (view->settings, "zoom-text-and-images")
|
2011-10-10 19:58:19 +00:00
|
|
|
|
|| !g_str_has_prefix (view->mime_type ? view->mime_type : "", "image/"));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-19 22:13:41 +00:00
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_view_source (MidoriView* view)
|
|
|
|
|
{
|
2010-01-02 22:32:52 +00:00
|
|
|
|
gchar* content_type;
|
|
|
|
|
gchar* text_type;
|
2010-05-07 18:17:53 +00:00
|
|
|
|
gboolean is_text;
|
2008-10-19 22:13:41 +00:00
|
|
|
|
|
2009-03-17 20:35:05 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2011-10-10 19:58:19 +00:00
|
|
|
|
if (midori_view_is_blank (view) || view->mime_type == NULL)
|
2009-01-02 01:28:04 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2010-01-02 22:32:52 +00:00
|
|
|
|
content_type = g_content_type_from_mime_type (view->mime_type);
|
|
|
|
|
text_type = g_content_type_from_mime_type ("text/plain");
|
2010-05-07 18:17:53 +00:00
|
|
|
|
is_text = g_content_type_is_a (content_type, text_type);
|
|
|
|
|
g_free (content_type);
|
|
|
|
|
g_free (text_type);
|
|
|
|
|
return is_text;
|
2008-10-19 22:13:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
#define can_do(what) \
|
|
|
|
|
gboolean \
|
|
|
|
|
midori_view_can_##what (MidoriView* view) \
|
|
|
|
|
{ \
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE); \
|
|
|
|
|
\
|
2008-10-15 01:07:38 +00:00
|
|
|
|
return view->web_view != NULL; \
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
can_do (reload)
|
|
|
|
|
can_do (print)
|
|
|
|
|
can_do (find)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_reload:
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @from_cache: whether to allow caching
|
|
|
|
|
*
|
|
|
|
|
* Reloads the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_reload (MidoriView* view,
|
|
|
|
|
gboolean from_cache)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2011-12-07 20:27:38 +00:00
|
|
|
|
if (midori_uri_is_blank (view->uri))
|
2010-01-07 20:12:36 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* uri = g_strdup (view->uri);
|
|
|
|
|
midori_view_set_uri (view, uri);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
2009-04-13 02:05:05 +00:00
|
|
|
|
else if (from_cache)
|
2009-03-04 22:23:23 +00:00
|
|
|
|
webkit_web_view_reload (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
else
|
|
|
|
|
webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW (view->web_view));
|
2010-08-23 18:08:43 +00:00
|
|
|
|
katze_item_set_meta_integer (view->item, "delay", -1);
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_stop_loading
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Stops loading the view if it is currently loading.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_stop_loading (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_stop_loading (WEBKIT_WEB_VIEW (view->web_view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-28 09:00:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_can_go_back
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether the view can go back.
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_go_back (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->web_view)
|
2008-09-28 09:00:31 +00:00
|
|
|
|
return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_go_back
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Goes back one page in the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_go_back (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_go_back (WEBKIT_WEB_VIEW (view->web_view));
|
2011-04-10 04:37:24 +00:00
|
|
|
|
/* Force the speed dial to kick in if going back to a blank page */
|
|
|
|
|
if (midori_view_is_blank (view))
|
|
|
|
|
midori_view_set_uri (view, "");
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-28 09:00:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_can_go_forward
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines whether the view can go forward.
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_can_go_forward (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
if (view->web_view)
|
2008-09-28 09:00:31 +00:00
|
|
|
|
return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_go_forward
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Goes forward one page in the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_go_forward (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_go_forward (WEBKIT_WEB_VIEW (view->web_view));
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-24 17:27:34 +00:00
|
|
|
|
static gchar*
|
|
|
|
|
midori_view_get_related_page (MidoriView* view,
|
|
|
|
|
const gchar* rel,
|
|
|
|
|
const gchar* local)
|
2009-12-26 22:12:36 +00:00
|
|
|
|
{
|
2011-10-24 17:27:34 +00:00
|
|
|
|
gchar* script;
|
2009-12-26 22:12:36 +00:00
|
|
|
|
static gchar* uri = NULL;
|
|
|
|
|
WebKitWebFrame* web_frame;
|
|
|
|
|
JSContextRef js_context;
|
|
|
|
|
|
2010-06-07 19:48:23 +00:00
|
|
|
|
if (!view->web_view)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2009-12-26 22:12:36 +00:00
|
|
|
|
web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
js_context = webkit_web_frame_get_global_context (web_frame);
|
2011-10-24 17:27:34 +00:00
|
|
|
|
script = g_strdup_printf (
|
2011-03-13 13:53:25 +00:00
|
|
|
|
"(function (tags) {"
|
2011-04-14 19:46:01 +00:00
|
|
|
|
"for (var tag in tags) {"
|
2011-03-13 13:53:25 +00:00
|
|
|
|
"var l = document.getElementsByTagName (tag);"
|
2011-04-14 19:46:01 +00:00
|
|
|
|
"for (var i in l) { "
|
2011-10-24 17:27:34 +00:00
|
|
|
|
"if ((l[i].rel && l[i].rel.toLowerCase () == '%s') "
|
2010-10-30 19:53:44 +00:00
|
|
|
|
" || (l[i].innerHTML"
|
2011-10-24 17:27:34 +00:00
|
|
|
|
" && (l[i].innerHTML.toLowerCase ().indexOf ('%s') != -1 "
|
|
|
|
|
" || l[i].innerHTML.toLowerCase ().indexOf ('%s') != -1)))"
|
2011-03-13 13:53:25 +00:00
|
|
|
|
"{ return l[i].href; } } } return 0; })("
|
2011-10-24 17:27:34 +00:00
|
|
|
|
"{ link:'link', a:'a' });", rel, rel, local);
|
|
|
|
|
katze_assign (uri, sokoke_js_script_eval (js_context, script, NULL));
|
|
|
|
|
g_free (script);
|
2009-12-26 22:12:36 +00:00
|
|
|
|
return uri && uri[0] != '0' ? uri : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-24 17:27:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_previous_page
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines the previous sub-page in the view.
|
|
|
|
|
*
|
|
|
|
|
* Return value: an URI, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.3
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_previous_page (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
/* i18n: word stem of "previous page" type links, case is not important */
|
|
|
|
|
return midori_view_get_related_page (view, "prev", _("previous"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-26 22:12:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_next_page
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Determines the next sub-page in the view.
|
|
|
|
|
*
|
|
|
|
|
* Return value: an URI, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.3
|
|
|
|
|
**/
|
|
|
|
|
const gchar*
|
|
|
|
|
midori_view_get_next_page (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
2011-10-24 17:27:34 +00:00
|
|
|
|
/* i18n: word stem of "next page" type links, case is not important */
|
|
|
|
|
return midori_view_get_related_page (view, "next", _("next"));
|
2009-12-26 22:12:36 +00:00
|
|
|
|
}
|
2010-10-20 21:48:36 +00:00
|
|
|
|
|
2009-08-24 18:10:58 +00:00
|
|
|
|
static GtkWidget*
|
|
|
|
|
midori_view_print_create_custom_widget_cb (GtkPrintOperation* operation,
|
|
|
|
|
MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* box;
|
|
|
|
|
GtkWidget* button;
|
|
|
|
|
|
|
|
|
|
box = gtk_vbox_new (FALSE, 0);
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (box), 4);
|
2010-11-24 18:07:05 +00:00
|
|
|
|
button = katze_property_proxy (view->settings, "print-backgrounds", NULL);
|
2009-08-24 18:10:58 +00:00
|
|
|
|
gtk_button_set_label (GTK_BUTTON (button), _("Print background images"));
|
|
|
|
|
gtk_widget_set_tooltip_text (button, _("Whether background images should be printed"));
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
|
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
|
|
|
|
|
|
return box;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-29 22:49:10 +00:00
|
|
|
|
static void
|
|
|
|
|
midori_view_print_response_cb (GtkWidget* dialog,
|
|
|
|
|
gint response,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_print
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Prints the contents of the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_print (MidoriView* view)
|
|
|
|
|
{
|
2009-08-24 18:10:58 +00:00
|
|
|
|
WebKitWebFrame* frame;
|
|
|
|
|
GtkPrintOperation* operation;
|
|
|
|
|
GError* error;
|
|
|
|
|
|
2008-09-26 21:13:46 +00:00
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2009-08-24 18:10:58 +00:00
|
|
|
|
frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
operation = gtk_print_operation_new ();
|
|
|
|
|
gtk_print_operation_set_custom_tab_label (operation, _("Features"));
|
2010-10-20 21:48:36 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (2, 18, 0)
|
2009-10-05 18:52:34 +00:00
|
|
|
|
gtk_print_operation_set_embed_page_setup (operation, TRUE);
|
2010-10-20 21:48:36 +00:00
|
|
|
|
#endif
|
2009-08-24 18:10:58 +00:00
|
|
|
|
g_signal_connect (operation, "create-custom-widget",
|
|
|
|
|
G_CALLBACK (midori_view_print_create_custom_widget_cb), view);
|
|
|
|
|
error = NULL;
|
|
|
|
|
webkit_web_frame_print_full (frame, operation,
|
|
|
|
|
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error);
|
|
|
|
|
g_object_unref (operation);
|
|
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget* window = gtk_widget_get_toplevel (GTK_WIDGET (view));
|
|
|
|
|
GtkWidget* dialog = gtk_message_dialog_new (
|
2010-01-29 21:44:34 +00:00
|
|
|
|
gtk_widget_is_toplevel (window) ? GTK_WINDOW (window) : NULL,
|
2009-08-24 18:10:58 +00:00
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
|
|
|
|
|
GTK_BUTTONS_CLOSE, "%s", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
2009-12-29 22:49:10 +00:00
|
|
|
|
G_CALLBACK (midori_view_print_response_cb), NULL);
|
2009-08-24 18:10:58 +00:00
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
}
|
2008-09-26 21:13:46 +00:00
|
|
|
|
}
|
2008-09-28 14:29:41 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_unmark_text_matches
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Unmarks the text matches in the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_unmark_text_matches (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view->web_view));
|
2008-09-28 14:29:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_search_text
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @text: a string
|
|
|
|
|
* @case_sensitive: case sensitivity
|
|
|
|
|
* @forward: whether to search forward
|
|
|
|
|
*
|
|
|
|
|
* Searches a text within the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_search_text (MidoriView* view,
|
|
|
|
|
const gchar* text,
|
|
|
|
|
gboolean case_sensitive,
|
|
|
|
|
gboolean forward)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
g_signal_emit (view, signals[SEARCH_TEXT], 0,
|
|
|
|
|
webkit_web_view_search_text (WEBKIT_WEB_VIEW (view->web_view),
|
2009-02-22 00:45:22 +00:00
|
|
|
|
text, case_sensitive, forward, TRUE), NULL);
|
2008-09-28 14:29:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_mark_text_matches
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @text: a string
|
|
|
|
|
* @case_sensitive: case sensitivity
|
|
|
|
|
*
|
|
|
|
|
* Marks all text matches within the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_mark_text_matches (MidoriView* view,
|
|
|
|
|
const gchar* text,
|
|
|
|
|
gboolean case_sensitive)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view->web_view),
|
|
|
|
|
text, case_sensitive, 0);
|
2008-09-28 14:29:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_set_highlight_text_matches
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @highlight: whether to highlight matches
|
|
|
|
|
*
|
|
|
|
|
* Whether to highlight all matches within the view.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
midori_view_set_highlight_text_matches (MidoriView* view,
|
|
|
|
|
gboolean highlight)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (MIDORI_IS_VIEW (view));
|
|
|
|
|
|
2008-10-15 01:07:38 +00:00
|
|
|
|
webkit_web_view_set_highlight_text_matches (
|
|
|
|
|
WEBKIT_WEB_VIEW (view->web_view), highlight);
|
2008-09-28 14:29:41 +00:00
|
|
|
|
}
|
2008-11-23 04:19:43 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* midori_view_execute_script
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @script: script code
|
|
|
|
|
* @exception: location to store an exception message
|
|
|
|
|
*
|
|
|
|
|
* Execute a script on the view.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the script was executed successfully
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
midori_view_execute_script (MidoriView* view,
|
|
|
|
|
const gchar* script,
|
|
|
|
|
gchar** exception)
|
|
|
|
|
{
|
2009-02-28 23:29:44 +00:00
|
|
|
|
WebKitWebFrame* web_frame;
|
|
|
|
|
JSContextRef js_context;
|
|
|
|
|
gchar* script_decoded;
|
2009-12-30 22:53:58 +00:00
|
|
|
|
gchar* result;
|
|
|
|
|
gboolean success;
|
2009-02-28 23:29:44 +00:00
|
|
|
|
|
2008-11-23 04:19:43 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
|
|
|
|
|
g_return_val_if_fail (script != NULL, FALSE);
|
|
|
|
|
|
2009-02-28 23:29:44 +00:00
|
|
|
|
web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view));
|
|
|
|
|
js_context = webkit_web_frame_get_global_context (web_frame);
|
|
|
|
|
if ((script_decoded = soup_uri_decode (script)))
|
|
|
|
|
{
|
2009-12-30 22:53:58 +00:00
|
|
|
|
result = sokoke_js_script_eval (js_context, script_decoded, exception);
|
2009-02-28 23:29:44 +00:00
|
|
|
|
g_free (script_decoded);
|
|
|
|
|
}
|
|
|
|
|
else
|
2009-12-30 22:53:58 +00:00
|
|
|
|
result = sokoke_js_script_eval (js_context, script, exception);
|
|
|
|
|
success = result != NULL;
|
|
|
|
|
g_free (result);
|
|
|
|
|
return success;
|
2008-11-23 04:19:43 +00:00
|
|
|
|
}
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2009-10-27 21:58:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_snapshot
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @width: the desired width
|
|
|
|
|
* @height: the desired height
|
|
|
|
|
*
|
|
|
|
|
* Take a snapshot of the view at the given dimensions. The
|
|
|
|
|
* view has to be mapped on the screen.
|
|
|
|
|
*
|
|
|
|
|
* If width and height are negative, the resulting
|
|
|
|
|
* image is going to be optimized for speed.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a newly allocated #GdkPixbuf
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.1
|
|
|
|
|
**/
|
2009-05-27 21:38:51 +00:00
|
|
|
|
GdkPixbuf*
|
|
|
|
|
midori_view_get_snapshot (MidoriView* view,
|
2009-06-03 23:00:50 +00:00
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
2009-05-27 21:38:51 +00:00
|
|
|
|
{
|
2011-10-09 12:28:06 +00:00
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
return midori_view_web_view_get_snapshot ((GtkWidget*)view->web_view, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GdkPixbuf*
|
|
|
|
|
midori_view_web_view_get_snapshot (GtkWidget* web_view,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
|
|
|
|
{
|
2010-10-18 20:42:10 +00:00
|
|
|
|
GtkAllocation allocation;
|
2009-06-03 23:00:50 +00:00
|
|
|
|
gboolean fast;
|
|
|
|
|
gint x, y, w, h;
|
2009-05-27 21:38:51 +00:00
|
|
|
|
GdkRectangle rect;
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#if !GTK_CHECK_VERSION (3, 0, 0)
|
2011-11-20 21:36:55 +00:00
|
|
|
|
GdkWindow* window;
|
2009-05-27 21:38:51 +00:00
|
|
|
|
GdkPixmap* pixmap;
|
|
|
|
|
GdkEvent event;
|
|
|
|
|
gboolean result;
|
|
|
|
|
GdkColormap* colormap;
|
2011-11-20 21:36:55 +00:00
|
|
|
|
#else
|
|
|
|
|
cairo_surface_t* surface;
|
|
|
|
|
cairo_t* cr;
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#endif
|
2009-05-27 21:38:51 +00:00
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
|
|
2011-10-09 12:28:06 +00:00
|
|
|
|
g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), NULL);
|
2009-05-27 21:38:51 +00:00
|
|
|
|
|
2010-10-18 20:42:10 +00:00
|
|
|
|
gtk_widget_get_allocation (web_view, &allocation);
|
|
|
|
|
x = allocation.x;
|
|
|
|
|
y = allocation.y;
|
|
|
|
|
w = allocation.width;
|
|
|
|
|
h = allocation.height;
|
2009-05-27 21:38:51 +00:00
|
|
|
|
|
2009-06-03 23:00:50 +00:00
|
|
|
|
/* If width and height are both negative, we try to render faster at
|
|
|
|
|
the cost of correctness or beauty. Only a part of the page is
|
|
|
|
|
rendered which makes it a lot faster and scaling isn't as nice. */
|
|
|
|
|
fast = FALSE;
|
|
|
|
|
if (width < 0 && height < 0)
|
|
|
|
|
{
|
|
|
|
|
width *= -1;
|
|
|
|
|
height *= -1;
|
|
|
|
|
w = w > 320 ? 320 : w;
|
|
|
|
|
h = h > 240 ? 240 : h;
|
|
|
|
|
fast = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#if GTK_CHECK_VERSION (3, 0, 0)
|
2011-11-20 21:36:55 +00:00
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
|
|
|
|
|
allocation.width, allocation.height);
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
cairo_rectangle (cr, x, y, width, height);
|
|
|
|
|
cairo_clip (cr);
|
2011-10-01 13:12:04 +00:00
|
|
|
|
gtk_widget_draw (web_view, cr);
|
2011-11-20 21:36:55 +00:00
|
|
|
|
pixbuf = gdk_pixbuf_get_from_surface (surface, x, y, width, height);
|
|
|
|
|
cairo_surface_destroy (surface);
|
2011-10-01 13:12:04 +00:00
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
#else
|
2009-06-03 23:00:50 +00:00
|
|
|
|
rect.x = x;
|
|
|
|
|
rect.y = y;
|
|
|
|
|
rect.width = w;
|
|
|
|
|
rect.height = h;
|
|
|
|
|
|
2011-11-20 21:36:55 +00:00
|
|
|
|
window = gtk_widget_get_window (web_view);
|
|
|
|
|
g_return_val_if_fail (window != NULL, NULL);
|
|
|
|
|
|
2010-10-18 20:42:10 +00:00
|
|
|
|
pixmap = gdk_pixmap_new (window, w, h, gdk_drawable_get_depth (window));
|
2009-05-27 21:38:51 +00:00
|
|
|
|
event.expose.type = GDK_EXPOSE;
|
|
|
|
|
event.expose.window = pixmap;
|
|
|
|
|
event.expose.send_event = FALSE;
|
|
|
|
|
event.expose.count = 0;
|
|
|
|
|
event.expose.area.x = 0;
|
|
|
|
|
event.expose.area.y = 0;
|
2010-10-18 20:42:10 +00:00
|
|
|
|
gdk_drawable_get_size (GDK_DRAWABLE (window),
|
2009-05-27 21:38:51 +00:00
|
|
|
|
&event.expose.area.width, &event.expose.area.height);
|
|
|
|
|
event.expose.region = gdk_region_rectangle (&event.expose.area);
|
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (web_view, "expose-event", &event, &result);
|
|
|
|
|
|
|
|
|
|
colormap = gdk_drawable_get_colormap (pixmap);
|
|
|
|
|
pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap, 0, 0,
|
|
|
|
|
0, 0, rect.width, rect.height);
|
|
|
|
|
g_object_unref (pixmap);
|
2011-10-01 13:12:04 +00:00
|
|
|
|
#endif
|
2009-05-27 21:38:51 +00:00
|
|
|
|
|
|
|
|
|
if (width || height)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf* scaled;
|
|
|
|
|
if (!width)
|
|
|
|
|
width = rect.width;
|
|
|
|
|
if (!height)
|
|
|
|
|
height = rect.height;
|
2009-06-03 23:00:50 +00:00
|
|
|
|
|
2009-05-27 21:38:51 +00:00
|
|
|
|
scaled = gdk_pixbuf_scale_simple (pixbuf, width, height,
|
2009-06-03 23:00:50 +00:00
|
|
|
|
fast ? GDK_INTERP_NEAREST : GDK_INTERP_TILES);
|
2009-05-27 21:38:51 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
return scaled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
|
}
|
2009-05-09 14:41:01 +00:00
|
|
|
|
|
2010-03-30 20:38:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_web_view
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Returns: The #WebKitWebView for this view
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.5
|
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
midori_view_get_web_view (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
|
|
|
|
|
|
|
|
|
|
return view->web_view;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-13 21:44:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* midori_view_get_security
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
*
|
|
|
|
|
* Returns: The #MidoriSecurity for this view
|
|
|
|
|
*
|
|
|
|
|
* Since: 0.2.5
|
|
|
|
|
**/
|
|
|
|
|
MidoriSecurity
|
|
|
|
|
midori_view_get_security (MidoriView* view)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_VIEW (view), MIDORI_SECURITY_NONE);
|
|
|
|
|
|
|
|
|
|
return view->security;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-07 20:22:43 +00:00
|
|
|
|
static void
|
2011-10-09 12:28:06 +00:00
|
|
|
|
thumb_view_load_status_cb (WebKitWebView* thumb_view_,
|
|
|
|
|
GParamSpec* pspec,
|
|
|
|
|
MidoriView* view)
|
2009-05-07 20:22:43 +00:00
|
|
|
|
{
|
2009-05-27 21:57:29 +00:00
|
|
|
|
GdkPixbuf* img;
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#if HAVE_OFFSCREEN
|
|
|
|
|
GdkPixbuf* pixbuf_scaled;
|
|
|
|
|
#endif
|
2011-03-22 21:59:56 +00:00
|
|
|
|
gchar* file_path;
|
2011-04-05 17:52:59 +00:00
|
|
|
|
gchar* thumb_dir;
|
2011-10-29 01:33:43 +00:00
|
|
|
|
gchar* spec;
|
|
|
|
|
gchar* url;
|
|
|
|
|
gchar* dial_id;
|
2011-03-22 23:07:52 +00:00
|
|
|
|
MidoriBrowser* browser;
|
2011-10-07 19:07:21 +00:00
|
|
|
|
GKeyFile* key_file;
|
2011-10-10 23:53:12 +00:00
|
|
|
|
const gchar* title;
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-11-10 18:45:23 +00:00
|
|
|
|
if (webkit_web_view_get_load_status (thumb_view_) != WEBKIT_LOAD_FINISHED)
|
|
|
|
|
return;
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-10-29 01:33:43 +00:00
|
|
|
|
spec = g_object_get_data (G_OBJECT (thumb_view), "spec");
|
|
|
|
|
url = strstr (spec, "|") + 1;
|
|
|
|
|
dial_id = g_strndup (spec, url - spec - 1);
|
|
|
|
|
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#if HAVE_OFFSCREEN
|
|
|
|
|
img = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (
|
|
|
|
|
gtk_widget_get_parent (GTK_WIDGET (thumb_view))));
|
|
|
|
|
pixbuf_scaled = gdk_pixbuf_scale_simple (img, 240, 160, GDK_INTERP_TILES);
|
|
|
|
|
katze_object_assign (img, pixbuf_scaled);
|
|
|
|
|
#else
|
|
|
|
|
gtk_widget_realize (thumb_view);
|
|
|
|
|
img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
|
|
|
|
|
#endif
|
2011-10-29 01:33:43 +00:00
|
|
|
|
file_path = sokoke_build_thumbnail_path (url);
|
2011-04-05 17:52:59 +00:00
|
|
|
|
thumb_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_cache_dir (),
|
|
|
|
|
PACKAGE_NAME, "thumbnails", NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_file_test (thumb_dir, G_FILE_TEST_EXISTS))
|
|
|
|
|
katze_mkdir_with_parents (thumb_dir, 0700);
|
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
gdk_pixbuf_save (img, file_path, "png", NULL, "compression", "7", NULL);
|
|
|
|
|
|
2009-05-07 20:22:43 +00:00
|
|
|
|
g_object_unref (img);
|
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
g_free (file_path);
|
2011-04-05 17:52:59 +00:00
|
|
|
|
g_free (thumb_dir);
|
2009-05-27 21:57:29 +00:00
|
|
|
|
|
2011-03-22 23:07:52 +00:00
|
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
2011-10-07 19:07:21 +00:00
|
|
|
|
g_object_get (browser, "speed-dial", &key_file, NULL);
|
2011-10-10 23:53:12 +00:00
|
|
|
|
title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (thumb_view));
|
2011-10-29 01:33:43 +00:00
|
|
|
|
g_key_file_set_string (key_file, dial_id, "title", title ? title : url);
|
2011-10-07 19:07:21 +00:00
|
|
|
|
midori_view_save_speed_dial_config (view, key_file);
|
2011-10-29 01:33:43 +00:00
|
|
|
|
|
|
|
|
|
thumb_queue = g_list_remove (thumb_queue, spec);
|
|
|
|
|
if (thumb_queue != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_object_set_data_full (G_OBJECT (thumb_view), "spec",
|
|
|
|
|
thumb_queue->data, (GDestroyNotify)g_free);
|
|
|
|
|
webkit_web_view_open (WEBKIT_WEB_VIEW (thumb_view),
|
|
|
|
|
strstr (thumb_queue->data, "|") + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
|
thumb_view, thumb_view_load_status_cb, view);
|
2009-05-27 21:57:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-22 22:41:52 +00:00
|
|
|
|
* midori_view_speed_dial_get_thumb
|
2009-05-27 21:57:29 +00:00
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @dom_id: Id of the shortcut on speed_dial page in wich to inject content
|
|
|
|
|
* @url: url of the shortcut
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2011-03-22 22:41:52 +00:00
|
|
|
|
midori_view_speed_dial_get_thumb (MidoriView* view,
|
2011-10-10 23:53:12 +00:00
|
|
|
|
gchar* dial_id,
|
2011-03-22 22:41:52 +00:00
|
|
|
|
gchar* url)
|
2009-05-27 21:57:29 +00:00
|
|
|
|
{
|
2011-10-09 12:28:06 +00:00
|
|
|
|
WebKitWebSettings* settings;
|
2009-05-27 21:57:29 +00:00
|
|
|
|
GtkWidget* browser;
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#if !HAVE_OFFSCREEN
|
2009-05-27 21:57:29 +00:00
|
|
|
|
GtkWidget* notebook;
|
|
|
|
|
GtkWidget* label;
|
|
|
|
|
|
|
|
|
|
browser = gtk_widget_get_toplevel (GTK_WIDGET (view));
|
|
|
|
|
if (!GTK_IS_WINDOW (browser))
|
|
|
|
|
return;
|
2009-10-14 19:29:04 +00:00
|
|
|
|
|
2009-05-27 21:57:29 +00:00
|
|
|
|
/* What we are doing here is a bit of a hack. In order to render a
|
|
|
|
|
thumbnail we need a new view and load the url in it. But it has
|
|
|
|
|
to be visible and packed in a container. So we secretly pack it
|
|
|
|
|
into the notebook of the parent browser. */
|
|
|
|
|
notebook = katze_object_get_object (browser, "notebook");
|
|
|
|
|
if (!notebook)
|
|
|
|
|
return;
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#endif
|
2009-10-14 19:29:04 +00:00
|
|
|
|
|
2011-10-09 12:28:06 +00:00
|
|
|
|
if (!thumb_view)
|
2009-10-14 19:29:04 +00:00
|
|
|
|
{
|
2011-10-09 12:28:06 +00:00
|
|
|
|
thumb_view = webkit_web_view_new ();
|
2011-10-29 01:33:43 +00:00
|
|
|
|
settings = g_object_new (WEBKIT_TYPE_WEB_SETTINGS,
|
|
|
|
|
"enable-scripts", FALSE,
|
|
|
|
|
"enable-plugins", FALSE, "auto-load-images", TRUE,
|
|
|
|
|
"enable-html5-database", FALSE, "enable-html5-local-storage", FALSE,
|
|
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 22)
|
|
|
|
|
"enable-java-applet", FALSE,
|
|
|
|
|
#endif
|
|
|
|
|
NULL);
|
|
|
|
|
webkit_web_view_set_settings (WEBKIT_WEB_VIEW (thumb_view), settings);
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#if HAVE_OFFSCREEN
|
|
|
|
|
browser = gtk_offscreen_window_new ();
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (browser), thumb_view);
|
|
|
|
|
gtk_widget_set_size_request (thumb_view, 800, 600);
|
|
|
|
|
gtk_widget_show_all (browser);
|
|
|
|
|
#else
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (notebook), thumb_view);
|
|
|
|
|
g_signal_connect (thumb_view, "destroy",
|
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
|
&thumb_view);
|
2009-10-14 19:29:04 +00:00
|
|
|
|
/* We use an empty label. It's not invisible but at least hard to spot. */
|
|
|
|
|
label = gtk_event_box_new ();
|
2011-10-09 12:28:06 +00:00
|
|
|
|
gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), thumb_view, label);
|
|
|
|
|
gtk_widget_show (thumb_view);
|
2011-10-29 01:33:43 +00:00
|
|
|
|
#endif
|
2009-10-14 19:29:04 +00:00
|
|
|
|
}
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#if !HAVE_OFFSCREEN
|
2010-02-15 23:56:14 +00:00
|
|
|
|
g_object_unref (notebook);
|
2011-10-09 12:28:06 +00:00
|
|
|
|
#endif
|
2009-10-14 19:29:04 +00:00
|
|
|
|
|
2011-11-10 18:45:23 +00:00
|
|
|
|
thumb_queue = g_list_append (thumb_queue, g_strconcat (dial_id, "|", url, NULL));
|
2011-10-29 01:33:43 +00:00
|
|
|
|
if (g_list_nth_data (thumb_queue, 1) != NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (thumb_view), "spec",
|
|
|
|
|
thumb_queue->data, (GDestroyNotify)g_free);
|
2009-05-27 21:57:29 +00:00
|
|
|
|
g_signal_connect (thumb_view, "notify::load-status",
|
|
|
|
|
G_CALLBACK (thumb_view_load_status_cb), view);
|
2011-10-09 12:28:06 +00:00
|
|
|
|
webkit_web_view_open (WEBKIT_WEB_VIEW (thumb_view), url);
|
2009-05-07 20:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-22 21:59:56 +00:00
|
|
|
|
* midori_view_speed_dial_save
|
|
|
|
|
* @view: a #MidoriView
|
|
|
|
|
* @message: message from JavaScript
|
2009-05-09 14:41:01 +00:00
|
|
|
|
*
|
2011-03-22 21:59:56 +00:00
|
|
|
|
* Save speed_dial settings
|
2009-05-07 20:22:43 +00:00
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
static void
|
2011-03-22 21:59:56 +00:00
|
|
|
|
midori_view_speed_dial_save (MidoriView* view,
|
|
|
|
|
const gchar* message)
|
2009-05-07 20:22:43 +00:00
|
|
|
|
{
|
2011-03-22 21:59:56 +00:00
|
|
|
|
gchar* action;
|
|
|
|
|
GKeyFile* key_file;
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
|
|
|
gchar* msg = g_strdup (message + 16);
|
|
|
|
|
gchar** parts = g_strsplit (msg, " ", 4);
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
g_object_get (browser, "speed-dial", &key_file, NULL);
|
|
|
|
|
action = parts[0];
|
2009-05-07 20:22:43 +00:00
|
|
|
|
|
2011-10-27 15:40:15 +00:00
|
|
|
|
if (g_str_equal (action, "add") || g_str_equal (action, "rename")
|
|
|
|
|
|| g_str_equal (action, "delete"))
|
2011-03-22 21:59:56 +00:00
|
|
|
|
{
|
|
|
|
|
gchar* tmp = g_strdup (parts[1] + 1);
|
|
|
|
|
guint slot_id = atoi (tmp);
|
|
|
|
|
gchar* dial_id = g_strdup_printf ("Dial %d", slot_id);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (action, "delete"))
|
|
|
|
|
{
|
2011-04-13 20:09:22 +00:00
|
|
|
|
gchar* uri = g_key_file_get_string (key_file, dial_id, "uri", NULL);
|
|
|
|
|
gchar* file_path = sokoke_build_thumbnail_path (uri);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
|
|
|
|
|
g_key_file_remove_group (key_file, dial_id, NULL);
|
|
|
|
|
g_unlink (file_path);
|
|
|
|
|
|
2011-04-13 20:09:22 +00:00
|
|
|
|
g_free (uri);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
g_free (file_path);
|
|
|
|
|
}
|
|
|
|
|
else if (g_str_equal (action, "add"))
|
|
|
|
|
{
|
|
|
|
|
g_key_file_set_string (key_file, dial_id, "uri", parts[2]);
|
2011-10-10 23:53:12 +00:00
|
|
|
|
midori_view_speed_dial_get_thumb (view, dial_id, parts[2]);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
}
|
|
|
|
|
else if (g_str_equal (action, "rename"))
|
|
|
|
|
{
|
2011-07-03 23:48:43 +00:00
|
|
|
|
guint offset = strlen (parts[0]) + strlen (parts[1]) + 2;
|
|
|
|
|
gchar* title = g_strdup (msg + offset);
|
|
|
|
|
g_key_file_set_string (key_file, dial_id, "title", title);
|
|
|
|
|
g_free (title);
|
2011-03-22 21:59:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (dial_id);
|
|
|
|
|
}
|
2009-05-15 21:49:01 +00:00
|
|
|
|
|
2011-10-07 19:07:21 +00:00
|
|
|
|
midori_view_save_speed_dial_config (view, key_file);
|
|
|
|
|
|
|
|
|
|
g_free (msg);
|
|
|
|
|
g_free (action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
midori_view_save_speed_dial_config (MidoriView* view,
|
|
|
|
|
GKeyFile* key_file)
|
|
|
|
|
{
|
|
|
|
|
gchar* config_file;
|
|
|
|
|
guint i = 0;
|
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
|
|
|
GtkWidget* tab;
|
|
|
|
|
|
2011-03-22 21:59:56 +00:00
|
|
|
|
config_file = g_build_filename (sokoke_set_config_dir (NULL), "speeddial", NULL);
|
|
|
|
|
sokoke_key_file_save_to_file (key_file, config_file, NULL);
|
2011-10-07 19:07:21 +00:00
|
|
|
|
g_free (config_file);
|
|
|
|
|
|
2011-11-10 22:17:18 +00:00
|
|
|
|
katze_assign (speeddial_markup, prepare_speed_dial_html (view, FALSE));
|
2009-05-15 21:49:01 +00:00
|
|
|
|
|
2011-03-22 23:07:52 +00:00
|
|
|
|
while ((tab = midori_browser_get_nth_tab (browser, i++)))
|
|
|
|
|
if (midori_view_is_blank (MIDORI_VIEW (tab)))
|
|
|
|
|
midori_view_reload (MIDORI_VIEW (tab), FALSE);
|
|
|
|
|
|
2009-05-07 20:22:43 +00:00
|
|
|
|
}
|