2008-08-15 08:07:51 +00:00
|
|
|
/*
|
2010-04-13 21:44:21 +00:00
|
|
|
Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de>
|
2010-03-25 22:06:38 +00:00
|
|
|
Copyright (C) 2008-2010 Dale Whittaker <dayul@users.sf.net>
|
2008-08-15 08:07:51 +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-locationaction.h"
|
|
|
|
|
|
|
|
#include "gtkiconentry.h"
|
2009-01-08 01:29:07 +00:00
|
|
|
#include "marshal.h"
|
2008-11-09 18:09:35 +00:00
|
|
|
#include "sokoke.h"
|
2009-12-12 20:55:37 +00:00
|
|
|
#include "midori-browser.h"
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
#include <string.h>
|
2008-09-03 00:39:25 +00:00
|
|
|
#include <glib/gi18n.h>
|
2008-08-15 08:07:51 +00:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2010-01-17 17:12:28 +00:00
|
|
|
#if HAVE_SQLITE
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#endif
|
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
#define COMPLETION_DELAY 150
|
2008-11-09 18:09:35 +00:00
|
|
|
#define MAX_ITEMS 25
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
struct _MidoriLocationAction
|
|
|
|
{
|
|
|
|
GtkAction parent_instance;
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
gchar* text;
|
2008-08-15 08:07:51 +00:00
|
|
|
gchar* uri;
|
2010-01-28 21:19:00 +00:00
|
|
|
KatzeArray* search_engines;
|
2008-08-31 00:45:13 +00:00
|
|
|
gdouble progress;
|
2009-02-19 21:26:56 +00:00
|
|
|
gchar* secondary_icon;
|
2008-10-27 02:35:37 +00:00
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
guint completion_timeout;
|
|
|
|
gchar* key;
|
|
|
|
GtkWidget* popup;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
GtkTreeModel* completion_model;
|
2010-01-20 20:25:39 +00:00
|
|
|
gint completion_index;
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkWidget* entry;
|
2008-11-09 18:09:35 +00:00
|
|
|
GdkPixbuf* default_icon;
|
2009-06-01 04:41:23 +00:00
|
|
|
KatzeArray* history;
|
2008-08-15 08:07:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MidoriLocationActionClass
|
|
|
|
{
|
|
|
|
GtkActionClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MidoriLocationAction, midori_location_action, GTK_TYPE_ACTION)
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2008-08-31 00:45:13 +00:00
|
|
|
PROP_PROGRESS,
|
2009-06-01 03:14:36 +00:00
|
|
|
PROP_SECONDARY_ICON,
|
|
|
|
PROP_HISTORY
|
2008-08-15 08:07:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ACTIVE_CHANGED,
|
2009-06-13 01:45:11 +00:00
|
|
|
FOCUS_IN,
|
2008-08-15 08:07:51 +00:00
|
|
|
FOCUS_OUT,
|
|
|
|
SECONDARY_ICON_RELEASED,
|
|
|
|
RESET_URI,
|
|
|
|
SUBMIT_URI,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
FAVICON_COL,
|
|
|
|
URI_COL,
|
|
|
|
TITLE_COL,
|
|
|
|
VISITS_COL,
|
|
|
|
VISIBLE_COL,
|
2009-07-11 13:28:16 +00:00
|
|
|
YALIGN_COL,
|
2010-01-29 22:49:10 +00:00
|
|
|
BACKGROUND_COL,
|
2010-02-22 22:49:27 +00:00
|
|
|
STYLE_COL,
|
2008-11-09 18:09:35 +00:00
|
|
|
N_COLS
|
|
|
|
};
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_finalize (GObject* object);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
2009-02-19 21:26:56 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_activate (GtkAction* object);
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
midori_location_action_create_tool_item (GtkAction* action);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_connect_proxy (GtkAction* action,
|
|
|
|
GtkWidget* proxy);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_disconnect_proxy (GtkAction* action,
|
|
|
|
GtkWidget* proxy);
|
|
|
|
|
2009-06-01 04:27:36 +00:00
|
|
|
static void
|
2010-01-17 16:45:34 +00:00
|
|
|
midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data);
|
2009-06-01 04:27:36 +00:00
|
|
|
|
2010-01-20 20:25:39 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_popdown_completion (MidoriLocationAction* location_action);
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_class_init (MidoriLocationActionClass* class)
|
|
|
|
{
|
|
|
|
GObjectClass* gobject_class;
|
|
|
|
GtkActionClass* action_class;
|
|
|
|
|
|
|
|
signals[ACTIVE_CHANGED] = g_signal_new ("active-changed",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__INT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
2009-06-13 01:45:11 +00:00
|
|
|
/**
|
|
|
|
* MidoriLocationAction:focus-in:
|
|
|
|
*
|
|
|
|
* The focus-in signal is emitted when the entry obtains the focus.
|
|
|
|
*
|
|
|
|
* Since 0.1.8
|
|
|
|
*/
|
|
|
|
signals[FOCUS_IN] = g_signal_new ("focus-in",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
signals[FOCUS_OUT] = g_signal_new ("focus-out",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2009-08-16 21:35:29 +00:00
|
|
|
/**
|
|
|
|
* MidoriLocationAction:secondary-icon-released:
|
|
|
|
*
|
|
|
|
* The secondary-icon-released signal is emitted when the mouse button
|
|
|
|
* is released above the secondary icon.
|
|
|
|
*
|
|
|
|
* Since 0.1.10 a signal handler can return %TRUE to stop signal
|
|
|
|
* emission, for instance to suppress default behavior.
|
|
|
|
*/
|
2008-08-15 08:07:51 +00:00
|
|
|
signals[SECONDARY_ICON_RELEASED] = g_signal_new ("secondary-icon-released",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
2009-08-16 21:35:29 +00:00
|
|
|
g_signal_accumulator_true_handled,
|
2008-08-15 08:07:51 +00:00
|
|
|
NULL,
|
2009-08-16 21:35:29 +00:00
|
|
|
midori_cclosure_marshal_BOOLEAN__OBJECT,
|
|
|
|
G_TYPE_BOOLEAN, 1,
|
2008-08-15 08:07:51 +00:00
|
|
|
GTK_TYPE_WIDGET);
|
|
|
|
|
|
|
|
signals[RESET_URI] = g_signal_new ("reset-uri",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[SUBMIT_URI] = g_signal_new ("submit-uri",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags) (G_SIGNAL_RUN_LAST),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
2008-08-31 01:21:29 +00:00
|
|
|
midori_cclosure_marshal_VOID__STRING_BOOLEAN,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_BOOLEAN);
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
gobject_class->finalize = midori_location_action_finalize;
|
|
|
|
gobject_class->set_property = midori_location_action_set_property;
|
2009-02-19 21:26:56 +00:00
|
|
|
gobject_class->get_property = midori_location_action_get_property;
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
action_class = GTK_ACTION_CLASS (class);
|
|
|
|
action_class->activate = midori_location_action_activate;
|
|
|
|
action_class->create_tool_item = midori_location_action_create_tool_item;
|
|
|
|
action_class->connect_proxy = midori_location_action_connect_proxy;
|
|
|
|
action_class->disconnect_proxy = midori_location_action_disconnect_proxy;
|
|
|
|
|
2008-08-31 00:45:13 +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 progress of the action",
|
2008-08-31 00:45:13 +00:00
|
|
|
0.0, 1.0, 0.0,
|
2009-02-19 21:26:56 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-08-31 00:45:13 +00:00
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SECONDARY_ICON,
|
|
|
|
g_param_spec_string (
|
|
|
|
"secondary-icon",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Secondary",
|
|
|
|
"The stock ID of the secondary icon",
|
2008-08-15 08:07:51 +00:00
|
|
|
NULL,
|
2009-02-19 21:26:56 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-06-01 03:14:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MidoriLocationAction:history:
|
|
|
|
*
|
|
|
|
* The list of history items.
|
|
|
|
*
|
|
|
|
* This is actually a reference to a history instance.
|
|
|
|
*
|
|
|
|
* Since 0.1.8
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_HISTORY,
|
|
|
|
g_param_spec_object (
|
|
|
|
"history",
|
|
|
|
"History",
|
|
|
|
"The list of history items",
|
|
|
|
KATZE_TYPE_ARRAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-01-01 23:28:44 +00:00
|
|
|
|
|
|
|
/* We want location entries to have appears-as-list applied */
|
|
|
|
gtk_rc_parse_string ("style \"midori-location-entry-style\" {\n"
|
|
|
|
" GtkComboBox::appears-as-list = 1\n }\n"
|
|
|
|
"widget \"*MidoriLocationEntry\" "
|
|
|
|
"style \"midori-location-entry-style\"\n");
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
static GtkTreeModel*
|
|
|
|
midori_location_action_create_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model = (GtkTreeModel*) gtk_list_store_new (N_COLS,
|
|
|
|
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,
|
2010-02-22 22:49:27 +00:00
|
|
|
G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_FLOAT,
|
|
|
|
GDK_TYPE_COLOR, G_TYPE_BOOLEAN);
|
2010-01-17 16:45:34 +00:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2010-01-25 00:19:03 +00:00
|
|
|
#if HAVE_SQLITE
|
2010-01-17 16:45:34 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_popup_position (GtkWidget* popup,
|
|
|
|
GtkWidget* widget)
|
|
|
|
{
|
|
|
|
gint wx, wy;
|
|
|
|
GtkRequisition menu_req;
|
|
|
|
GtkRequisition widget_req;
|
2010-01-31 21:12:58 +00:00
|
|
|
GdkScreen* screen;
|
|
|
|
gint monitor_num;
|
|
|
|
GdkRectangle monitor;
|
2010-01-17 16:45:34 +00:00
|
|
|
|
2010-01-31 21:12:58 +00:00
|
|
|
gdk_window_get_origin (widget->window, &wx, &wy);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_widget_size_request (popup, &menu_req);
|
|
|
|
gtk_widget_size_request (widget, &widget_req);
|
|
|
|
|
2010-01-31 21:12:58 +00:00
|
|
|
screen = gtk_widget_get_screen (widget);
|
|
|
|
monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
|
|
|
|
|
|
if (wy + widget_req.height + menu_req.height <= monitor.y + monitor.height
|
|
|
|
|| wy - monitor.y < (monitor.y + monitor.height) - (wy + widget_req.height))
|
|
|
|
wy += widget_req.height;
|
|
|
|
else
|
|
|
|
wy -= menu_req.height;
|
|
|
|
gtk_window_move (GTK_WINDOW (popup), wx, wy);
|
|
|
|
gtk_window_resize (GTK_WINDOW (popup), widget->allocation.width, 1);
|
2010-01-17 16:45:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 06:42:40 +00:00
|
|
|
static gboolean
|
|
|
|
midori_location_action_treeview_button_press_cb (GtkWidget* treeview,
|
|
|
|
GdkEventButton* event,
|
|
|
|
MidoriLocationAction* action)
|
|
|
|
{
|
|
|
|
GtkTreePath* path;
|
|
|
|
|
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview),
|
|
|
|
event->x, event->y, &path, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar* uri;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (action->completion_model, &iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2010-01-20 20:25:39 +00:00
|
|
|
midori_location_action_popdown_completion (action);
|
2010-01-20 06:42:40 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (action->completion_model, &iter, URI_COL, &uri, -1);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
|
2010-01-20 20:25:39 +00:00
|
|
|
g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
|
2010-01-22 22:11:00 +00:00
|
|
|
MIDORI_MOD_NEW_TAB (event->state));
|
2010-01-20 06:42:40 +00:00
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
static gboolean
|
|
|
|
midori_location_action_popup_timeout_cb (gpointer data)
|
|
|
|
{
|
|
|
|
MidoriLocationAction* action = data;
|
|
|
|
GtkTreeViewColumn* column;
|
2010-01-17 17:12:28 +00:00
|
|
|
GtkListStore* store;
|
|
|
|
gint result;
|
2010-02-04 18:22:35 +00:00
|
|
|
static sqlite3_stmt* stmt;
|
|
|
|
const gchar* sqlcmd;
|
2010-03-04 22:47:05 +00:00
|
|
|
gint matches, searches, height, screen_height, browser_height, sep;
|
2010-03-06 18:18:09 +00:00
|
|
|
MidoriBrowser* browser;
|
2010-02-22 22:49:27 +00:00
|
|
|
GtkStyle* style;
|
2010-01-17 16:45:34 +00:00
|
|
|
|
2010-03-06 18:18:09 +00:00
|
|
|
if (!action->entry || !gtk_widget_has_focus (action->entry) || !action->history)
|
2010-01-19 05:34:53 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-02-10 23:38:17 +00:00
|
|
|
if (!(action->key && *action->key))
|
2010-01-24 22:53:18 +00:00
|
|
|
{
|
|
|
|
midori_location_action_popdown_completion (action);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-02-04 18:22:35 +00:00
|
|
|
if (!stmt)
|
2010-01-24 22:53:18 +00:00
|
|
|
{
|
2010-02-19 17:55:16 +00:00
|
|
|
sqlite3* db;
|
|
|
|
db = g_object_get_data (G_OBJECT (action->history), "db");
|
2010-02-22 22:49:27 +00:00
|
|
|
sqlcmd = "SELECT type, uri, title, count() AS ct FROM history_view "
|
|
|
|
"WHERE uri LIKE ?1 OR title LIKE ?1 GROUP BY uri "
|
|
|
|
"UNION ALL "
|
2010-02-25 22:09:31 +00:00
|
|
|
"SELECT type, replace(uri, '%s', title) AS uri, title, count() AS ct FROM search_view "
|
2010-02-22 22:49:27 +00:00
|
|
|
"WHERE title LIKE ?1 GROUP BY uri "
|
|
|
|
"ORDER BY ct DESC LIMIT ?2";
|
|
|
|
sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
|
2010-01-24 22:53:18 +00:00
|
|
|
}
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_bind_text (stmt, 1, g_strdup_printf ("%%%s%%", action->key), -1, g_free);
|
2010-02-22 22:49:27 +00:00
|
|
|
sqlite3_bind_int64 (stmt, 2, MAX_ITEMS);
|
2010-01-24 22:53:18 +00:00
|
|
|
|
2010-02-04 18:22:35 +00:00
|
|
|
result = sqlite3_step (stmt);
|
2010-01-28 21:19:00 +00:00
|
|
|
if (result != SQLITE_ROW && !action->search_engines)
|
2010-01-24 22:53:18 +00:00
|
|
|
{
|
2010-03-18 22:26:45 +00:00
|
|
|
if (result == SQLITE_ERROR)
|
|
|
|
g_print (_("Failed to select from history\n"));
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_reset (stmt);
|
|
|
|
sqlite3_clear_bindings (stmt);
|
2010-01-24 22:53:18 +00:00
|
|
|
midori_location_action_popdown_completion (action);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-20 22:11:25 +00:00
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
if (G_UNLIKELY (!action->popup))
|
|
|
|
{
|
2010-02-19 17:55:16 +00:00
|
|
|
GtkTreeModel* model = NULL;
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkWidget* popup;
|
2010-03-24 22:26:51 +00:00
|
|
|
GtkWidget* popup_frame;
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkWidget* scrolled;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
GtkCellRenderer* renderer;
|
|
|
|
|
2010-01-17 17:12:28 +00:00
|
|
|
model = midori_location_action_create_model ();
|
2010-01-17 16:45:34 +00:00
|
|
|
action->completion_model = model;
|
|
|
|
|
|
|
|
popup = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_window_set_type_hint (GTK_WINDOW (popup), GDK_WINDOW_TYPE_HINT_COMBO);
|
2010-03-24 22:26:51 +00:00
|
|
|
popup_frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (popup_frame), GTK_SHADOW_ETCHED_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (popup), popup_frame);
|
2010-01-17 16:45:34 +00:00
|
|
|
scrolled = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
|
|
|
|
"hscrollbar-policy", GTK_POLICY_NEVER,
|
|
|
|
"vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);
|
2010-03-24 22:26:51 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (popup_frame), scrolled);
|
2010-01-17 16:45:34 +00:00
|
|
|
treeview = gtk_tree_view_new_with_model (model);
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
2010-01-20 20:28:44 +00:00
|
|
|
gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (treeview), TRUE);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled), treeview);
|
2010-01-20 06:42:40 +00:00
|
|
|
g_signal_connect (treeview, "button-press-event",
|
|
|
|
G_CALLBACK (midori_location_action_treeview_button_press_cb), action);
|
2010-01-27 22:53:15 +00:00
|
|
|
/* a nasty hack to get the completions treeview to size nicely */
|
|
|
|
gtk_widget_set_size_request (gtk_scrolled_window_get_vscrollbar (
|
|
|
|
GTK_SCROLLED_WINDOW (scrolled)), -1, 0);
|
2010-01-17 16:45:34 +00:00
|
|
|
action->treeview = treeview;
|
|
|
|
|
|
|
|
column = gtk_tree_view_column_new ();
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
|
2010-01-29 22:49:10 +00:00
|
|
|
"pixbuf", FAVICON_COL, "yalign", YALIGN_COL,
|
|
|
|
"cell-background-gdk", BACKGROUND_COL,
|
|
|
|
NULL);
|
2010-01-17 16:45:34 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set_data (G_OBJECT (renderer), "location-action", action);
|
|
|
|
gtk_cell_renderer_set_fixed_size (renderer, 1, -1);
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
|
2010-01-29 22:49:10 +00:00
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
|
|
|
|
"cell-background-gdk", BACKGROUND_COL,
|
|
|
|
NULL);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), renderer,
|
|
|
|
midori_location_entry_render_text_cb,
|
2010-02-11 22:55:36 +00:00
|
|
|
action, NULL);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
|
|
|
|
|
|
|
|
action->popup = popup;
|
|
|
|
g_signal_connect (popup, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &action->popup);
|
|
|
|
}
|
|
|
|
|
2010-02-19 17:55:16 +00:00
|
|
|
store = GTK_LIST_STORE (action->completion_model);
|
2010-01-17 17:12:28 +00:00
|
|
|
gtk_list_store_clear (store);
|
|
|
|
|
2010-02-04 02:11:52 +00:00
|
|
|
matches = searches = 0;
|
2010-02-22 22:49:27 +00:00
|
|
|
style = gtk_widget_get_style (action->treeview);
|
2010-01-28 21:19:00 +00:00
|
|
|
while (result == SQLITE_ROW)
|
2010-01-17 17:12:28 +00:00
|
|
|
{
|
2010-02-22 22:49:27 +00:00
|
|
|
sqlite3_int64 type = sqlite3_column_int64 (stmt, 0);
|
|
|
|
const unsigned char* uri = sqlite3_column_text (stmt, 1);
|
|
|
|
const unsigned char* title = sqlite3_column_text (stmt, 2);
|
2010-01-24 22:53:18 +00:00
|
|
|
GdkPixbuf* icon = katze_load_cached_icon ((gchar*)uri, NULL);
|
|
|
|
if (!icon)
|
|
|
|
icon = action->default_icon;
|
2010-02-22 22:49:27 +00:00
|
|
|
if (type == 1 /* history_view */)
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, matches,
|
|
|
|
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
|
|
|
|
FAVICON_COL, icon, -1);
|
|
|
|
else if (type == 2 /* search_view */)
|
|
|
|
{
|
|
|
|
gchar* search_title = g_strdup_printf (_("Search for %s"), title);
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, matches,
|
2010-02-25 22:09:31 +00:00
|
|
|
URI_COL, uri, TITLE_COL, search_title, YALIGN_COL, 0.25,
|
2010-02-22 22:49:27 +00:00
|
|
|
STYLE_COL, 1, FAVICON_COL, icon, -1);
|
|
|
|
g_free (search_title);
|
|
|
|
}
|
|
|
|
|
2010-01-24 22:53:18 +00:00
|
|
|
matches++;
|
2010-02-04 18:22:35 +00:00
|
|
|
result = sqlite3_step (stmt);
|
2010-01-17 17:12:28 +00:00
|
|
|
}
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_reset (stmt);
|
|
|
|
sqlite3_clear_bindings (stmt);
|
2010-01-28 21:19:00 +00:00
|
|
|
|
|
|
|
if (action->search_engines)
|
|
|
|
{
|
|
|
|
gint i = 0;
|
|
|
|
KatzeItem* item;
|
|
|
|
while ((item = katze_array_get_nth_item (action->search_engines, i)))
|
|
|
|
{
|
|
|
|
gchar* uri;
|
|
|
|
gchar* title;
|
|
|
|
|
|
|
|
uri = sokoke_search_uri (katze_item_get_uri (item), action->key);
|
|
|
|
title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item));
|
2010-01-30 16:39:32 +00:00
|
|
|
gtk_list_store_insert_with_values (store, NULL, matches + i,
|
2010-01-28 21:19:00 +00:00
|
|
|
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
|
2010-01-29 22:49:10 +00:00
|
|
|
BACKGROUND_COL, style ? &style->bg[GTK_STATE_NORMAL] : NULL,
|
2010-02-22 22:49:27 +00:00
|
|
|
STYLE_COL, 1, FAVICON_COL, NULL, -1);
|
2010-01-28 21:19:00 +00:00
|
|
|
g_free (uri);
|
|
|
|
g_free (title);
|
|
|
|
i++;
|
|
|
|
}
|
2010-02-04 02:11:52 +00:00
|
|
|
searches += i;
|
2010-01-28 21:19:00 +00:00
|
|
|
}
|
2010-01-17 16:45:34 +00:00
|
|
|
|
2010-04-02 16:38:56 +00:00
|
|
|
if (!gtk_widget_get_visible (action->popup))
|
2010-01-17 16:45:34 +00:00
|
|
|
{
|
|
|
|
GtkWidget* toplevel = gtk_widget_get_toplevel (action->entry);
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (action->popup),
|
|
|
|
gtk_widget_get_screen (action->entry));
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (action->popup), GTK_WINDOW (toplevel));
|
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (action->treeview));
|
|
|
|
}
|
|
|
|
|
2010-03-06 18:18:09 +00:00
|
|
|
browser = midori_browser_get_for_widget (action->entry);
|
2010-01-17 16:45:34 +00:00
|
|
|
column = gtk_tree_view_get_column (GTK_TREE_VIEW (action->treeview), 0);
|
|
|
|
gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, NULL, &height);
|
|
|
|
screen_height = gdk_screen_get_height (gtk_widget_get_screen (action->popup));
|
2010-03-04 22:47:05 +00:00
|
|
|
gtk_window_get_size (GTK_WINDOW (browser), NULL, &browser_height);
|
|
|
|
screen_height = MIN (MIN (browser_height, screen_height / 1.5), screen_height / 1.5);
|
2010-02-04 02:11:52 +00:00
|
|
|
gtk_widget_style_get (action->treeview, "vertical-separator", &sep, NULL);
|
|
|
|
/* FIXME: Instead of 1.5 we should relate to the height of one line */
|
|
|
|
height = MIN (matches * height + (matches + searches) * sep
|
2010-03-04 22:47:05 +00:00
|
|
|
+ searches * height / 1.5, screen_height);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_widget_set_size_request (action->treeview, -1, height);
|
|
|
|
midori_location_action_popup_position (action->popup, action->entry);
|
2010-01-25 21:10:39 +00:00
|
|
|
gtk_widget_show_all (action->popup);
|
2010-01-17 16:45:34 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-25 00:19:03 +00:00
|
|
|
#endif
|
2010-01-17 16:45:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_popup_completion (MidoriLocationAction* action,
|
|
|
|
GtkWidget* entry,
|
2010-02-10 23:38:17 +00:00
|
|
|
gchar* key)
|
2010-01-17 16:45:34 +00:00
|
|
|
{
|
|
|
|
if (action->completion_timeout)
|
|
|
|
g_source_remove (action->completion_timeout);
|
2010-02-10 23:38:17 +00:00
|
|
|
katze_assign (action->key, key);
|
2010-01-17 16:45:34 +00:00
|
|
|
action->entry = entry;
|
|
|
|
g_signal_connect (entry, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &action->entry);
|
2010-01-25 00:19:03 +00:00
|
|
|
#if HAVE_SQLITE
|
2010-01-17 16:45:34 +00:00
|
|
|
action->completion_timeout = g_timeout_add (COMPLETION_DELAY,
|
|
|
|
midori_location_action_popup_timeout_cb, action);
|
|
|
|
/* TODO: Inline completion */
|
2010-01-25 00:19:03 +00:00
|
|
|
#endif
|
2010-01-17 16:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_popdown_completion (MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (location_action->popup))
|
|
|
|
{
|
|
|
|
gtk_widget_hide (location_action->popup);
|
2010-02-11 22:55:36 +00:00
|
|
|
katze_assign (location_action->key, NULL);
|
2010-01-17 16:45:34 +00:00
|
|
|
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (
|
|
|
|
GTK_TREE_VIEW (location_action->treeview)));
|
|
|
|
}
|
2010-01-20 22:11:25 +00:00
|
|
|
if (location_action->completion_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (location_action->completion_timeout);
|
|
|
|
location_action->completion_timeout = 0;
|
|
|
|
}
|
2010-01-20 20:25:39 +00:00
|
|
|
location_action->completion_index = -1;
|
2010-01-17 16:45:34 +00:00
|
|
|
}
|
|
|
|
|
2009-05-17 14:55:02 +00:00
|
|
|
/* Allow this to be used in tests, it's otherwise private */
|
|
|
|
/*static*/ GtkWidget*
|
2009-05-17 14:26:31 +00:00
|
|
|
midori_location_action_entry_for_proxy (GtkWidget* proxy)
|
|
|
|
{
|
|
|
|
GtkWidget* alignment = gtk_bin_get_child (GTK_BIN (proxy));
|
2009-06-13 01:45:11 +00:00
|
|
|
GtkWidget* entry = gtk_bin_get_child (GTK_BIN (alignment));
|
2009-05-17 14:26:31 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2008-12-12 20:06:33 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_freeze:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
*
|
2010-01-25 20:37:50 +00:00
|
|
|
* Freezing of the action doesn't do anything.
|
2008-12-12 20:06:33 +00:00
|
|
|
*
|
2010-01-25 20:37:50 +00:00
|
|
|
* Deprecated: 0.2.3
|
2008-12-12 20:06:33 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_location_action_freeze (MidoriLocationAction* location_action)
|
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
/* Nothing to do */
|
2010-01-17 21:36:44 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 20:06:33 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_thaw:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
*
|
2010-01-25 20:37:50 +00:00
|
|
|
* Thawing of the action doesn't do anything.
|
2008-12-12 20:06:33 +00:00
|
|
|
*
|
2010-01-25 20:37:50 +00:00
|
|
|
* Deprecated: 0.2.3
|
2008-12-12 20:06:33 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_location_action_thaw (MidoriLocationAction* location_action)
|
2008-08-15 08:07:51 +00:00
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
/* Nothing to do */
|
2008-12-12 20:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_init (MidoriLocationAction* location_action)
|
|
|
|
{
|
2009-10-04 00:32:50 +00:00
|
|
|
location_action->text = location_action->uri = NULL;
|
2010-01-28 21:19:00 +00:00
|
|
|
location_action->search_engines = NULL;
|
2008-12-12 20:06:33 +00:00
|
|
|
location_action->progress = 0.0;
|
2009-02-19 21:26:56 +00:00
|
|
|
location_action->secondary_icon = NULL;
|
2008-11-09 18:09:35 +00:00
|
|
|
location_action->default_icon = NULL;
|
2010-01-17 16:45:34 +00:00
|
|
|
location_action->completion_timeout = 0;
|
2010-01-20 20:25:39 +00:00
|
|
|
location_action->completion_index = -1;
|
2010-01-17 16:45:34 +00:00
|
|
|
location_action->key = NULL;
|
|
|
|
location_action->popup = NULL;
|
|
|
|
location_action->entry = NULL;
|
2009-06-01 04:41:23 +00:00
|
|
|
location_action->history = NULL;
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_finalize (GObject* object)
|
|
|
|
{
|
|
|
|
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
katze_assign (location_action->text, NULL);
|
2008-11-09 18:09:35 +00:00
|
|
|
katze_assign (location_action->uri, NULL);
|
2010-01-28 21:19:00 +00:00
|
|
|
katze_assign (location_action->search_engines, NULL);
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
katze_assign (location_action->key, NULL);
|
|
|
|
if (location_action->popup)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (location_action->popup);
|
|
|
|
location_action->popup = NULL;
|
|
|
|
}
|
2008-11-09 18:09:35 +00:00
|
|
|
katze_object_assign (location_action->default_icon, NULL);
|
2009-06-01 04:41:23 +00:00
|
|
|
katze_object_assign (location_action->history, NULL);
|
2008-12-12 20:06:33 +00:00
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
G_OBJECT_CLASS (midori_location_action_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-01-28 22:56:54 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_toggle_arrow_cb (GtkWidget* widget,
|
|
|
|
MidoriLocationAction* location_action)
|
2010-02-04 02:30:09 +00:00
|
|
|
{ gboolean show = FALSE;
|
|
|
|
|
|
|
|
#if HAVE_SQLITE
|
|
|
|
sqlite3* db;
|
|
|
|
const gchar* sqlcmd;
|
|
|
|
sqlite3_stmt* statement;
|
|
|
|
gint result;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!GTK_IS_BUTTON (widget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if HAVE_SQLITE
|
|
|
|
db = g_object_get_data (G_OBJECT (location_action->history), "db");
|
|
|
|
sqlcmd = "SELECT uri FROM history LIMIT 1";
|
|
|
|
sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL);
|
|
|
|
result = sqlite3_step (statement);
|
|
|
|
if (result == SQLITE_ROW)
|
|
|
|
show = TRUE;
|
|
|
|
sqlite3_finalize (statement);
|
|
|
|
#endif
|
|
|
|
sokoke_widget_set_visible (widget, show);
|
|
|
|
gtk_widget_set_size_request (widget, show ? -1 : 1, show ? -1 : 1);
|
2010-01-28 22:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_toggle_arrow (MidoriLocationAction* location_action)
|
|
|
|
{
|
2010-02-07 15:38:10 +00:00
|
|
|
GSList* proxies;
|
|
|
|
|
|
|
|
if (!location_action->history)
|
|
|
|
return;
|
|
|
|
|
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
2010-01-28 22:56:54 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
|
|
|
GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
|
|
|
|
gtk_container_forall (GTK_CONTAINER (entry),
|
|
|
|
(GtkCallback)midori_location_action_toggle_arrow_cb, location_action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-08-31 00:45:13 +00:00
|
|
|
case PROP_PROGRESS:
|
|
|
|
midori_location_action_set_progress (location_action,
|
|
|
|
g_value_get_double (value));
|
|
|
|
break;
|
2008-08-15 08:07:51 +00:00
|
|
|
case PROP_SECONDARY_ICON:
|
|
|
|
midori_location_action_set_secondary_icon (location_action,
|
|
|
|
g_value_get_string (value));
|
|
|
|
break;
|
2009-06-01 03:14:36 +00:00
|
|
|
case PROP_HISTORY:
|
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
katze_assign (location_action->history, g_value_dup_object (value));
|
2010-01-28 22:56:54 +00:00
|
|
|
|
|
|
|
midori_location_action_toggle_arrow (location_action);
|
2009-06-01 03:14:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-08-15 08:07:51 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 21:26:56 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PROGRESS:
|
|
|
|
g_value_set_double (value, location_action->progress);
|
|
|
|
break;
|
|
|
|
case PROP_SECONDARY_ICON:
|
|
|
|
g_value_set_string (value, location_action->secondary_icon);
|
|
|
|
break;
|
2009-06-01 04:41:23 +00:00
|
|
|
case PROP_HISTORY:
|
|
|
|
g_value_set_object (value, location_action->history);
|
|
|
|
break;
|
2009-02-19 21:26:56 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_activate (GtkAction* action)
|
|
|
|
{
|
|
|
|
GSList* proxies;
|
|
|
|
GtkWidget* entry;
|
|
|
|
|
|
|
|
proxies = gtk_action_get_proxies (action);
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2008-08-15 08:07:51 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
/* Obviously only one widget can end up with the focus.
|
|
|
|
Yet we can't predict which one that is, can we? */
|
|
|
|
gtk_widget_grab_focus (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_ACTION_CLASS (midori_location_action_parent_class)->activate)
|
|
|
|
GTK_ACTION_CLASS (midori_location_action_parent_class)->activate (action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
midori_location_action_create_tool_item (GtkAction* action)
|
|
|
|
{
|
|
|
|
GtkWidget* toolitem;
|
|
|
|
GtkWidget* alignment;
|
2009-05-17 14:26:31 +00:00
|
|
|
GtkWidget* location_entry;
|
2010-01-01 23:28:44 +00:00
|
|
|
GtkWidget* entry;
|
|
|
|
#if HAVE_HILDON
|
|
|
|
HildonGtkInputMode mode;
|
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
toolitem = GTK_WIDGET (gtk_tool_item_new ());
|
|
|
|
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2008-11-16 00:04:12 +00:00
|
|
|
alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
|
2008-08-15 08:07:51 +00:00
|
|
|
gtk_widget_show (alignment);
|
2009-05-17 14:26:31 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (toolitem), alignment);
|
2010-01-01 23:28:44 +00:00
|
|
|
location_entry = gtk_combo_box_entry_new ();
|
|
|
|
gtk_widget_set_name (location_entry, "MidoriLocationEntry");
|
2009-05-17 14:26:31 +00:00
|
|
|
gtk_widget_show (location_entry);
|
2009-06-13 01:45:11 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (alignment), location_entry);
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2010-01-01 23:28:44 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
mode = hildon_gtk_entry_get_input_mode (GTK_ENTRY (entry));
|
|
|
|
mode &= ~HILDON_GTK_INPUT_MODE_AUTOCAP;
|
|
|
|
hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry), mode);
|
|
|
|
#else
|
|
|
|
entry = gtk_icon_entry_new ();
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_FILE);
|
|
|
|
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_SECONDARY, TRUE);
|
|
|
|
#endif
|
|
|
|
gtk_widget_show (entry);
|
|
|
|
gtk_container_add (GTK_CONTAINER (location_entry), entry);
|
|
|
|
|
2008-10-13 16:29:46 +00:00
|
|
|
return toolitem;
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_changed_cb (GtkEntry* entry,
|
|
|
|
MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
katze_assign (location_action->text, g_strdup (gtk_entry_get_text (entry)));
|
|
|
|
}
|
|
|
|
|
2010-01-20 22:11:25 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_move_cursor_cb (GtkEntry* entry,
|
|
|
|
GtkMovementStep step,
|
|
|
|
gint count,
|
|
|
|
gboolean extend_selection,
|
|
|
|
MidoriLocationAction* action)
|
|
|
|
{
|
|
|
|
gchar* text = g_strdup (pango_layout_get_text (gtk_entry_get_layout (entry)));
|
|
|
|
/* Update entry with the completed text */
|
|
|
|
gtk_entry_set_text (entry, text);
|
|
|
|
g_free (text);
|
|
|
|
midori_location_action_popdown_completion (action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_backspace_cb (GtkWidget* entry,
|
|
|
|
MidoriLocationAction* action)
|
|
|
|
{
|
2010-02-10 23:38:17 +00:00
|
|
|
gchar* key = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
|
|
|
|
midori_location_action_popup_completion (action, entry, key);
|
2010-01-20 22:11:25 +00:00
|
|
|
action->completion_index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_paste_clipboard_cb (GtkWidget* entry,
|
|
|
|
MidoriLocationAction* action)
|
|
|
|
{
|
2010-02-10 23:38:17 +00:00
|
|
|
gchar* key = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
|
|
|
|
midori_location_action_popup_completion (action, entry, key);
|
2010-01-20 22:11:25 +00:00
|
|
|
action->completion_index = -1;
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:34:17 +00:00
|
|
|
static gboolean
|
|
|
|
midori_location_action_button_press_event_cb (GtkEntry* entry,
|
|
|
|
GdkEventKey* event,
|
|
|
|
MidoriLocationAction* action)
|
|
|
|
{
|
2010-04-02 16:38:56 +00:00
|
|
|
if (action->popup && gtk_widget_get_visible (action->popup))
|
2010-01-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
midori_location_action_popdown_completion (action);
|
|
|
|
|
2010-01-20 22:16:29 +00:00
|
|
|
/* Allow button handling, for context menu and selection */
|
|
|
|
return FALSE;
|
2010-01-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static gboolean
|
2009-10-04 00:32:50 +00:00
|
|
|
midori_location_action_key_press_event_cb (GtkEntry* entry,
|
2008-08-15 08:07:51 +00:00
|
|
|
GdkEventKey* event,
|
|
|
|
GtkAction* action)
|
|
|
|
{
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkWidget* widget = GTK_WIDGET (entry);
|
|
|
|
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action);
|
|
|
|
const gchar* text;
|
|
|
|
gboolean is_enter = FALSE;
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
switch (event->keyval)
|
|
|
|
{
|
|
|
|
case GDK_ISO_Enter:
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
case GDK_Return:
|
2010-01-17 16:45:34 +00:00
|
|
|
is_enter = TRUE;
|
|
|
|
case GDK_Left:
|
|
|
|
case GDK_KP_Left:
|
|
|
|
case GDK_Right:
|
|
|
|
case GDK_KP_Right:
|
|
|
|
|
2010-04-02 16:38:56 +00:00
|
|
|
if (location_action->popup && gtk_widget_get_visible (location_action->popup))
|
2008-08-15 08:07:51 +00:00
|
|
|
{
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkTreeModel* model = location_action->completion_model;
|
|
|
|
GtkTreeIter iter;
|
2010-01-20 20:25:39 +00:00
|
|
|
gint selected = location_action->completion_index;
|
2010-01-17 16:45:34 +00:00
|
|
|
midori_location_action_popdown_completion (location_action);
|
2010-01-17 17:12:28 +00:00
|
|
|
if (selected > -1 &&
|
|
|
|
gtk_tree_model_iter_nth_child (model, &iter, NULL, selected))
|
2010-01-17 16:45:34 +00:00
|
|
|
{
|
|
|
|
gchar* uri;
|
|
|
|
gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
|
|
|
|
gtk_entry_set_text (entry, uri);
|
|
|
|
|
|
|
|
if (is_enter)
|
|
|
|
g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
|
2010-01-22 22:11:00 +00:00
|
|
|
MIDORI_MOD_NEW_TAB (event->state));
|
2010-01-17 16:45:34 +00:00
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2010-01-17 16:45:34 +00:00
|
|
|
|
|
|
|
if (is_enter)
|
|
|
|
if ((text = gtk_entry_get_text (entry)) && *text)
|
|
|
|
g_signal_emit (action, signals[SUBMIT_URI], 0, text,
|
2010-01-22 22:11:00 +00:00
|
|
|
MIDORI_MOD_NEW_TAB (event->state));
|
2010-01-17 16:45:34 +00:00
|
|
|
break;
|
2008-08-15 08:07:51 +00:00
|
|
|
case GDK_Escape:
|
|
|
|
{
|
2010-04-02 16:38:56 +00:00
|
|
|
if (location_action->popup && gtk_widget_get_visible (location_action->popup))
|
2010-01-17 16:45:34 +00:00
|
|
|
{
|
|
|
|
midori_location_action_popdown_completion (location_action);
|
2010-01-20 22:11:25 +00:00
|
|
|
text = gtk_entry_get_text (entry);
|
|
|
|
pango_layout_set_text (gtk_entry_get_layout (entry), text, -1);
|
2010-01-17 16:45:34 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
g_signal_emit (action, signals[RESET_URI], 0);
|
2010-01-17 16:45:34 +00:00
|
|
|
/* Return FALSE to allow Escape to stop loading */
|
|
|
|
return FALSE;
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2010-01-17 16:45:34 +00:00
|
|
|
case GDK_Page_Up:
|
|
|
|
case GDK_Page_Down:
|
2010-04-02 16:38:56 +00:00
|
|
|
if (!(location_action->popup && gtk_widget_get_visible (location_action->popup)))
|
2010-01-17 16:45:34 +00:00
|
|
|
return TRUE;
|
2010-01-01 17:23:15 +00:00
|
|
|
case GDK_Down:
|
2010-01-17 16:45:34 +00:00
|
|
|
case GDK_KP_Down:
|
2010-01-01 17:23:15 +00:00
|
|
|
case GDK_Up:
|
2010-01-17 16:45:34 +00:00
|
|
|
case GDK_KP_Up:
|
2010-01-01 17:23:15 +00:00
|
|
|
{
|
2010-01-17 16:45:34 +00:00
|
|
|
GtkWidget* parent;
|
|
|
|
|
2010-04-02 16:38:56 +00:00
|
|
|
if (location_action->popup && gtk_widget_get_visible (location_action->popup))
|
2010-01-17 16:45:34 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel* model = location_action->completion_model;
|
|
|
|
gint matches = gtk_tree_model_iter_n_children (model, NULL);
|
|
|
|
GtkTreePath* path;
|
|
|
|
GtkTreeIter iter;
|
2010-01-20 20:25:39 +00:00
|
|
|
gint selected = location_action->completion_index;
|
2010-01-17 16:45:34 +00:00
|
|
|
|
|
|
|
if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
|
|
|
|
selected = MIN (selected + 1, matches -1);
|
|
|
|
else if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
|
2010-01-28 22:15:49 +00:00
|
|
|
{
|
|
|
|
if (selected == -1)
|
|
|
|
selected = matches - 1;
|
|
|
|
else
|
|
|
|
selected = MAX (selected - 1, 0);
|
|
|
|
}
|
2010-01-17 16:45:34 +00:00
|
|
|
else if (event->keyval == GDK_Page_Down)
|
|
|
|
selected = MIN (selected + 14, matches -1);
|
|
|
|
else if (event->keyval == GDK_Page_Up)
|
|
|
|
selected = MAX (selected - 14, 0);
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (selected, -1);
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (location_action->treeview),
|
|
|
|
path, NULL, FALSE);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, selected))
|
|
|
|
{
|
|
|
|
gchar* uri;
|
|
|
|
gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
|
2010-01-20 22:11:25 +00:00
|
|
|
/* Update the layout without actually changing the text */
|
|
|
|
pango_layout_set_text (gtk_entry_get_layout (entry), uri, -1);
|
2010-01-17 16:45:34 +00:00
|
|
|
g_free (uri);
|
|
|
|
}
|
2010-01-20 20:25:39 +00:00
|
|
|
location_action->completion_index = selected;
|
2010-01-17 16:45:34 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (widget);
|
2010-01-01 17:23:15 +00:00
|
|
|
if (!katze_object_get_boolean (parent, "popup-shown"))
|
|
|
|
gtk_combo_box_popup (GTK_COMBO_BOX (parent));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-01-17 16:45:34 +00:00
|
|
|
default:
|
2010-02-10 23:38:17 +00:00
|
|
|
{
|
|
|
|
gunichar character;
|
|
|
|
gchar buffer[7];
|
|
|
|
gint length;
|
|
|
|
gchar* key;
|
|
|
|
|
|
|
|
character = gdk_keyval_to_unicode (event->keyval);
|
2010-01-19 06:11:51 +00:00
|
|
|
/* Don't trigger completion on control characters */
|
2010-02-10 23:38:17 +00:00
|
|
|
if (!character || event->is_modifier)
|
2010-01-19 06:11:51 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-02-10 23:38:17 +00:00
|
|
|
length = g_unichar_to_utf8 (character, buffer);
|
|
|
|
buffer[length] = '\0';
|
|
|
|
key = g_strconcat (gtk_entry_get_text (entry), buffer, NULL);
|
|
|
|
midori_location_action_popup_completion (location_action, widget, key);
|
|
|
|
location_action->completion_index = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-17 16:45:34 +00:00
|
|
|
#if GTK_CHECK_VERSION (2, 19, 3)
|
|
|
|
static void
|
2010-02-10 23:38:17 +00:00
|
|
|
midori_location_action_preedit_changed_cb (GtkWidget* entry,
|
2010-01-17 16:45:34 +00:00
|
|
|
const gchar* preedit,
|
|
|
|
GtkAction* action)
|
|
|
|
{
|
|
|
|
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action);
|
2010-02-10 23:38:17 +00:00
|
|
|
gchar* key = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
|
|
|
|
midori_location_action_popup_completion (location_action, entry, key);
|
2010-01-17 16:45:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-13 01:45:11 +00:00
|
|
|
static gboolean
|
|
|
|
midori_location_action_focus_in_event_cb (GtkWidget* widget,
|
2009-10-04 00:32:50 +00:00
|
|
|
GdkEventKey* event,
|
|
|
|
GtkAction* action)
|
2009-06-13 01:45:11 +00:00
|
|
|
{
|
|
|
|
g_signal_emit (action, signals[FOCUS_IN], 0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static gboolean
|
|
|
|
midori_location_action_focus_out_event_cb (GtkWidget* widget,
|
|
|
|
GdkEventKey* event,
|
|
|
|
GtkAction* action)
|
|
|
|
{
|
2010-01-17 16:45:34 +00:00
|
|
|
midori_location_action_popdown_completion (MIDORI_LOCATION_ACTION (action));
|
2008-08-15 08:07:51 +00:00
|
|
|
g_signal_emit (action, signals[FOCUS_OUT], 0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_icon_released_cb (GtkWidget* widget,
|
|
|
|
GtkIconEntryPosition icon_pos,
|
|
|
|
gint button,
|
|
|
|
GtkAction* action)
|
|
|
|
{
|
|
|
|
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
|
2009-08-28 21:51:07 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
g_signal_emit (action, signals[SECONDARY_ICON_RELEASED], 0,
|
|
|
|
widget, &result);
|
|
|
|
}
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2010-02-11 22:55:36 +00:00
|
|
|
MidoriLocationAction* action = data;
|
2008-11-09 18:09:35 +00:00
|
|
|
gchar* uri;
|
|
|
|
gchar* title;
|
2010-02-04 02:11:52 +00:00
|
|
|
GdkColor* background;
|
2010-02-22 22:49:27 +00:00
|
|
|
gboolean style;
|
2008-11-09 18:09:35 +00:00
|
|
|
gchar* desc;
|
|
|
|
gchar* desc_uri;
|
|
|
|
gchar* desc_title;
|
2010-02-04 01:40:59 +00:00
|
|
|
const gchar* str;
|
2008-11-09 18:09:35 +00:00
|
|
|
gchar* key;
|
2008-11-18 02:01:33 +00:00
|
|
|
gchar* start;
|
|
|
|
gchar* skey;
|
2008-11-09 18:09:35 +00:00
|
|
|
gchar* temp;
|
|
|
|
gchar** parts;
|
2009-03-31 20:24:18 +00:00
|
|
|
size_t len;
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2010-02-04 02:11:52 +00:00
|
|
|
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title,
|
2010-02-22 22:49:27 +00:00
|
|
|
BACKGROUND_COL, &background, STYLE_COL, &style, -1);
|
2009-10-20 16:25:40 +00:00
|
|
|
|
2010-02-22 22:49:27 +00:00
|
|
|
if (style) /* A search engine action */
|
2010-02-04 02:11:52 +00:00
|
|
|
{
|
|
|
|
g_object_set (renderer, "text", title,
|
|
|
|
"ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
g_free (uri);
|
|
|
|
g_free (title);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-11 22:55:36 +00:00
|
|
|
desc = desc_uri = desc_title = key = NULL;
|
|
|
|
if (action->key)
|
|
|
|
str = action->key;
|
|
|
|
else
|
|
|
|
str = "";
|
|
|
|
|
2010-02-04 01:40:59 +00:00
|
|
|
key = g_utf8_strdown (str, -1);
|
|
|
|
len = strlen (key);
|
2009-11-16 22:51:34 +00:00
|
|
|
|
2009-12-26 13:22:25 +00:00
|
|
|
if (G_LIKELY (uri))
|
2008-11-09 18:09:35 +00:00
|
|
|
{
|
2009-11-16 22:51:34 +00:00
|
|
|
temp = g_utf8_strdown (uri, -1);
|
2009-12-26 13:22:25 +00:00
|
|
|
if ((start = strstr (temp, key)) && (start - temp))
|
2008-11-18 02:01:33 +00:00
|
|
|
{
|
2009-12-26 13:22:25 +00:00
|
|
|
skey = g_strndup (uri + (start - temp), len);
|
|
|
|
parts = g_strsplit (uri, skey, 2);
|
|
|
|
if (parts[0] && parts[1])
|
|
|
|
desc_uri = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
|
|
|
parts[0], skey, parts[1]);
|
|
|
|
g_strfreev (parts);
|
2009-08-24 21:15:57 +00:00
|
|
|
g_free (skey);
|
2008-11-18 02:01:33 +00:00
|
|
|
}
|
2010-02-04 01:40:59 +00:00
|
|
|
if (!desc_uri)
|
2009-12-26 13:22:25 +00:00
|
|
|
desc_uri = g_markup_escape_text (uri, -1);
|
2009-08-24 21:15:57 +00:00
|
|
|
g_free (temp);
|
|
|
|
}
|
2009-12-12 16:40:30 +00:00
|
|
|
|
2009-12-26 13:22:25 +00:00
|
|
|
if (G_LIKELY (title))
|
2009-08-24 21:15:57 +00:00
|
|
|
{
|
|
|
|
temp = g_utf8_strdown (title, -1);
|
2009-12-26 13:22:25 +00:00
|
|
|
if ((start = strstr (temp, key)) && (start - temp))
|
2009-08-20 21:39:38 +00:00
|
|
|
{
|
2009-12-26 13:22:25 +00:00
|
|
|
skey = g_strndup (title + (start - temp), len);
|
2009-08-24 21:15:57 +00:00
|
|
|
parts = g_strsplit (title, skey, 2);
|
2010-02-04 01:40:59 +00:00
|
|
|
if (parts[0] && parts[1])
|
2009-08-24 21:15:57 +00:00
|
|
|
desc_title = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
|
|
|
parts[0], skey, parts[1]);
|
|
|
|
g_strfreev (parts);
|
|
|
|
g_free (skey);
|
2009-08-20 21:39:38 +00:00
|
|
|
}
|
2010-02-04 01:40:59 +00:00
|
|
|
if (!desc_title)
|
2009-12-26 13:22:25 +00:00
|
|
|
desc_title = g_markup_escape_text (title, -1);
|
2009-08-24 21:15:57 +00:00
|
|
|
g_free (temp);
|
|
|
|
}
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2009-08-24 21:15:57 +00:00
|
|
|
if (desc_title)
|
|
|
|
{
|
|
|
|
desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>",
|
|
|
|
desc_title, desc_uri);
|
|
|
|
g_free (desc_uri);
|
|
|
|
g_free (desc_title);
|
2009-08-20 21:39:38 +00:00
|
|
|
}
|
2009-08-24 21:15:57 +00:00
|
|
|
else
|
|
|
|
desc = desc_uri;
|
|
|
|
|
|
|
|
g_object_set (renderer, "markup", desc,
|
|
|
|
"ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
g_free (uri);
|
|
|
|
g_free (title);
|
|
|
|
g_free (key);
|
|
|
|
g_free (desc);
|
|
|
|
}
|
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_entry_changed_cb (GtkComboBox* combo_box,
|
|
|
|
MidoriLocationAction* location_action)
|
2008-11-09 18:09:35 +00:00
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
GtkTreeIter iter;
|
2009-01-27 17:56:21 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
if (gtk_combo_box_get_active_iter (combo_box, &iter))
|
2009-02-09 20:37:10 +00:00
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
GtkIconEntry* entry;
|
2009-03-31 20:24:18 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
if ((entry = GTK_ICON_ENTRY (gtk_bin_get_child (GTK_BIN (combo_box)))))
|
2009-01-27 17:56:21 +00:00
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
GtkTreeModel* model;
|
|
|
|
gchar* uri;
|
2010-01-31 21:29:22 +00:00
|
|
|
#if !HAVE_HILDON
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
#endif
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
model = gtk_combo_box_get_model (combo_box);
|
|
|
|
gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
|
2008-12-15 22:17:12 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
#if !HAVE_HILDON
|
|
|
|
gtk_tree_model_get (model, &iter, FAVICON_COL, &pixbuf, -1);
|
|
|
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, pixbuf);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
#endif
|
|
|
|
katze_assign (location_action->text, uri);
|
|
|
|
katze_assign (location_action->uri, g_strdup (uri));
|
2008-12-15 22:17:12 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
g_signal_emit (location_action, signals[ACTIVE_CHANGED], 0,
|
|
|
|
gtk_combo_box_get_active (combo_box));
|
2009-02-09 20:37:10 +00:00
|
|
|
}
|
2008-11-09 18:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:52:21 +00:00
|
|
|
static void
|
2010-01-25 20:37:50 +00:00
|
|
|
midori_location_action_entry_popup_cb (GtkComboBox* combo_box,
|
|
|
|
MidoriLocationAction* location_action)
|
2009-08-10 21:52:21 +00:00
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
#if HAVE_SQLITE
|
|
|
|
GtkListStore* store;
|
|
|
|
gint result;
|
2010-02-04 18:22:35 +00:00
|
|
|
const gchar* sqlcmd;
|
|
|
|
static sqlite3_stmt* stmt;
|
2010-01-25 20:37:50 +00:00
|
|
|
gint matches;
|
2009-08-10 21:52:21 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (combo_box));
|
|
|
|
gtk_list_store_clear (store);
|
2009-10-04 01:52:01 +00:00
|
|
|
|
2010-02-04 18:22:35 +00:00
|
|
|
if (!stmt)
|
2009-10-04 01:52:01 +00:00
|
|
|
{
|
2010-02-19 17:55:16 +00:00
|
|
|
sqlite3* db;
|
|
|
|
db = g_object_get_data (G_OBJECT (location_action->history), "db");
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlcmd = "SELECT uri, title FROM history"
|
|
|
|
" GROUP BY uri ORDER BY count() DESC LIMIT ?";
|
|
|
|
sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
|
2009-10-04 01:52:01 +00:00
|
|
|
}
|
2009-08-10 21:52:21 +00:00
|
|
|
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_bind_int64 (stmt, 1, MAX_ITEMS);
|
|
|
|
result = sqlite3_step (stmt);
|
2010-01-25 20:37:50 +00:00
|
|
|
if (result != SQLITE_ROW)
|
2009-10-04 01:52:01 +00:00
|
|
|
{
|
2010-02-19 17:55:16 +00:00
|
|
|
g_print (_("Failed to execute database statement\n"));
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_reset (stmt);
|
|
|
|
sqlite3_clear_bindings (stmt);
|
2010-01-25 20:37:50 +00:00
|
|
|
return;
|
2009-10-04 01:52:01 +00:00
|
|
|
}
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
matches = 0;
|
|
|
|
do
|
2008-11-09 18:09:35 +00:00
|
|
|
{
|
2010-02-04 18:22:35 +00:00
|
|
|
const unsigned char* uri = sqlite3_column_text (stmt, 0);
|
|
|
|
const unsigned char* title = sqlite3_column_text (stmt, 1);
|
2010-01-25 20:37:50 +00:00
|
|
|
GdkPixbuf* icon = katze_load_cached_icon ((gchar*)uri, NULL);
|
|
|
|
if (!icon)
|
|
|
|
icon = location_action->default_icon;
|
|
|
|
gtk_list_store_insert_with_values (store, NULL, matches,
|
|
|
|
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
|
|
|
|
FAVICON_COL, icon, -1);
|
|
|
|
matches++;
|
2010-02-04 18:22:35 +00:00
|
|
|
result = sqlite3_step (stmt);
|
2008-11-09 18:09:35 +00:00
|
|
|
}
|
2010-01-25 20:37:50 +00:00
|
|
|
while (result == SQLITE_ROW);
|
2010-02-04 18:22:35 +00:00
|
|
|
sqlite3_reset (stmt);
|
|
|
|
sqlite3_clear_bindings (stmt);
|
2010-01-25 20:37:50 +00:00
|
|
|
#endif
|
2008-11-09 18:09:35 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 22:01:56 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_paste_proceed_cb (GtkWidget* menuitem,
|
|
|
|
GtkWidget* location_action)
|
|
|
|
{
|
|
|
|
GtkClipboard* clipboard = gtk_clipboard_get_for_display (
|
|
|
|
gtk_widget_get_display (GTK_WIDGET (menuitem)),GDK_SELECTION_CLIPBOARD);
|
|
|
|
gchar* uri;
|
|
|
|
|
|
|
|
if ((uri = gtk_clipboard_wait_for_text (clipboard)))
|
|
|
|
{
|
|
|
|
g_signal_emit (location_action, signals[SUBMIT_URI], 0, uri, FALSE);
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-12 20:55:37 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_populate_popup_cb (GtkWidget* entry,
|
|
|
|
GtkMenuShell* menu,
|
|
|
|
MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (entry);
|
|
|
|
GtkActionGroup* actions = midori_browser_get_action_group (browser);
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
gtk_menu_shell_append (menu, menuitem);
|
|
|
|
menuitem = sokoke_action_create_popup_menu_item (
|
|
|
|
gtk_action_group_get_action (actions, "ManageSearchEngines"));
|
|
|
|
gtk_menu_shell_append (menu, menuitem);
|
2010-01-09 22:08:40 +00:00
|
|
|
/* i18n: Right-click on Location, Open an URL from the clipboard */
|
2010-01-01 22:01:56 +00:00
|
|
|
menuitem = gtk_menu_item_new_with_mnemonic (_("Paste and p_roceed"));
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
gtk_menu_shell_append (menu, menuitem);
|
|
|
|
g_signal_connect (menuitem, "activate",
|
|
|
|
G_CALLBACK (midori_location_action_paste_proceed_cb), location_action);
|
2009-12-12 20:55:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
static void
|
|
|
|
midori_location_action_connect_proxy (GtkAction* action,
|
|
|
|
GtkWidget* proxy)
|
|
|
|
{
|
2008-10-27 02:35:37 +00:00
|
|
|
MidoriLocationAction* location_action;
|
2008-11-09 18:09:35 +00:00
|
|
|
GtkCellRenderer* renderer;
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
GTK_ACTION_CLASS (midori_location_action_parent_class)->connect_proxy (
|
|
|
|
action, proxy);
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
location_action = MIDORI_LOCATION_ACTION (action);
|
|
|
|
katze_object_assign (location_action->default_icon,
|
|
|
|
gtk_widget_render_icon (proxy, GTK_STOCK_FILE,
|
|
|
|
GTK_ICON_SIZE_MENU, NULL));
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxy))
|
|
|
|
{
|
2009-11-16 22:51:34 +00:00
|
|
|
GtkWidget* entry = midori_location_action_entry_for_proxy (proxy);
|
|
|
|
GtkWidget* child = gtk_bin_get_child (GTK_BIN (entry));
|
2010-01-25 20:37:50 +00:00
|
|
|
GtkTreeModel* model = midori_location_action_create_model ();
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2010-01-01 22:55:04 +00:00
|
|
|
gtk_icon_entry_set_progress_fraction (GTK_ICON_ENTRY (child),
|
2008-11-09 18:09:35 +00:00
|
|
|
MIDORI_LOCATION_ACTION (action)->progress);
|
2010-01-25 20:37:50 +00:00
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (entry), model);
|
|
|
|
#if GTK_CHECK_VERSION (2, 14, 0)
|
|
|
|
gtk_combo_box_set_button_sensitivity (GTK_COMBO_BOX (entry),
|
|
|
|
GTK_SENSITIVITY_ON);
|
|
|
|
#endif
|
2008-11-09 18:09:35 +00:00
|
|
|
gtk_combo_box_entry_set_text_column (
|
|
|
|
GTK_COMBO_BOX_ENTRY (entry), URI_COL);
|
|
|
|
gtk_cell_layout_clear (GTK_CELL_LAYOUT (entry));
|
|
|
|
|
|
|
|
/* Setup the renderer for the favicon */
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (entry), renderer, FALSE);
|
2009-07-11 13:28:16 +00:00
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (entry), renderer,
|
|
|
|
"pixbuf", FAVICON_COL, "yalign", YALIGN_COL, NULL);
|
2008-11-09 18:09:35 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
2009-11-16 22:51:34 +00:00
|
|
|
g_object_set_data (G_OBJECT (renderer), "location-action", action);
|
2008-11-09 18:09:35 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (entry), renderer, TRUE);
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry),
|
2010-02-11 22:55:36 +00:00
|
|
|
renderer, midori_location_entry_render_text_cb, action, NULL);
|
2008-11-09 18:09:35 +00:00
|
|
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (entry), -1);
|
2010-02-07 15:38:10 +00:00
|
|
|
if (location_action->history)
|
|
|
|
gtk_container_forall (GTK_CONTAINER (entry),
|
|
|
|
(GtkCallback)midori_location_action_toggle_arrow_cb, action);
|
2008-11-09 18:09:35 +00:00
|
|
|
g_signal_connect (entry, "changed",
|
|
|
|
G_CALLBACK (midori_location_action_entry_changed_cb), action);
|
2010-01-25 20:37:50 +00:00
|
|
|
g_signal_connect (entry, "popup",
|
|
|
|
G_CALLBACK (midori_location_action_entry_popup_cb), action);
|
2008-11-09 18:09:35 +00:00
|
|
|
|
2009-11-16 22:51:34 +00:00
|
|
|
g_object_connect (child,
|
2009-10-04 00:32:50 +00:00
|
|
|
"signal::changed",
|
|
|
|
midori_location_action_changed_cb, action,
|
2010-01-20 22:11:25 +00:00
|
|
|
"signal::move-cursor",
|
|
|
|
midori_location_action_move_cursor_cb, action,
|
2010-02-10 23:38:17 +00:00
|
|
|
"signal-after::backspace",
|
2010-01-20 22:11:25 +00:00
|
|
|
midori_location_action_backspace_cb, action,
|
2010-02-10 23:38:17 +00:00
|
|
|
"signal-after::paste-clipboard",
|
2010-01-20 22:11:25 +00:00
|
|
|
midori_location_action_paste_clipboard_cb, action,
|
2010-01-20 20:34:17 +00:00
|
|
|
"signal::button-press-event",
|
|
|
|
midori_location_action_button_press_event_cb, action,
|
2008-08-15 08:07:51 +00:00
|
|
|
"signal::key-press-event",
|
|
|
|
midori_location_action_key_press_event_cb, action,
|
2010-01-17 16:45:34 +00:00
|
|
|
#if GTK_CHECK_VERSION (2, 19, 3)
|
2010-02-10 23:38:17 +00:00
|
|
|
"signal-after::preedit-changed",
|
2010-01-17 16:45:34 +00:00
|
|
|
midori_location_action_preedit_changed_cb, action,
|
|
|
|
#endif
|
2009-06-13 01:45:11 +00:00
|
|
|
"signal::focus-in-event",
|
|
|
|
midori_location_action_focus_in_event_cb, action,
|
2008-08-15 08:07:51 +00:00
|
|
|
"signal::focus-out-event",
|
|
|
|
midori_location_action_focus_out_event_cb, action,
|
2009-04-11 05:05:28 +00:00
|
|
|
"signal::icon-release",
|
2008-08-15 08:07:51 +00:00
|
|
|
midori_location_action_icon_released_cb, action,
|
2009-12-12 20:55:37 +00:00
|
|
|
"signal::populate-popup",
|
|
|
|
midori_location_action_populate_popup_cb, action,
|
2008-08-15 08:07:51 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_location_action_disconnect_proxy (GtkAction* action,
|
|
|
|
GtkWidget* proxy)
|
|
|
|
{
|
2008-10-13 16:29:46 +00:00
|
|
|
/* FIXME: This is wrong */
|
2008-08-15 08:07:51 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (proxy,
|
|
|
|
G_CALLBACK (gtk_action_activate), action);
|
|
|
|
|
|
|
|
GTK_ACTION_CLASS (midori_location_action_parent_class)->disconnect_proxy
|
|
|
|
(action, proxy);
|
|
|
|
}
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_get_uri:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
*
|
|
|
|
* Retrieves the current URI. See also midori_location_action_get_text().
|
|
|
|
*
|
|
|
|
* Return value: the current URI
|
|
|
|
**/
|
2008-08-15 08:07:51 +00:00
|
|
|
const gchar*
|
|
|
|
midori_location_action_get_uri (MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_LOCATION_ACTION (location_action), NULL);
|
|
|
|
|
|
|
|
return location_action->uri;
|
|
|
|
}
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_get_text:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
*
|
|
|
|
* Retrieves the current text, which may be the current URI or
|
|
|
|
* anything typed in the entry.
|
|
|
|
*
|
|
|
|
* Return value: the current text
|
|
|
|
*
|
|
|
|
* Since: 0.2.0
|
|
|
|
**/
|
|
|
|
const gchar*
|
|
|
|
midori_location_action_get_text (MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_LOCATION_ACTION (location_action), NULL);
|
|
|
|
|
|
|
|
return location_action->text;
|
|
|
|
}
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_set_text:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
* @text: a string
|
|
|
|
*
|
|
|
|
* Sets the entry text to @text and, if applicable, updates the icon.
|
2009-10-04 00:32:50 +00:00
|
|
|
*
|
|
|
|
* Since: 0.2.0
|
2008-11-09 18:09:35 +00:00
|
|
|
**/
|
2009-10-04 00:32:50 +00:00
|
|
|
void
|
2008-11-09 18:09:35 +00:00
|
|
|
midori_location_action_set_text (MidoriLocationAction* location_action,
|
|
|
|
const gchar* text)
|
2008-08-15 08:07:51 +00:00
|
|
|
{
|
|
|
|
GSList* proxies;
|
2008-11-09 18:09:35 +00:00
|
|
|
GtkWidget* location_entry;
|
2008-08-15 08:07:51 +00:00
|
|
|
GtkWidget* entry;
|
2008-11-09 18:09:35 +00:00
|
|
|
GdkPixbuf* icon;
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
2010-01-20 22:20:28 +00:00
|
|
|
midori_location_action_popdown_completion (location_action);
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
katze_assign (location_action->text, g_strdup (text));
|
2010-01-25 20:37:50 +00:00
|
|
|
katze_assign (location_action->uri, g_strdup (text));
|
2009-10-04 00:32:50 +00:00
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
if (!(proxies = gtk_action_get_proxies (GTK_ACTION (location_action))))
|
2008-08-15 08:07:51 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
if (!(icon = katze_load_cached_icon (location_action->uri, NULL)))
|
2008-12-18 04:02:52 +00:00
|
|
|
icon = g_object_ref (location_action->default_icon);
|
|
|
|
|
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2008-08-15 08:07:51 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-11-09 18:09:35 +00:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), text);
|
2009-10-12 20:56:18 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-12-18 04:02:52 +00:00
|
|
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, icon);
|
2009-10-12 20:56:18 +00:00
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2008-12-18 04:02:52 +00:00
|
|
|
|
2010-01-25 20:37:50 +00:00
|
|
|
g_object_unref (icon);
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 00:32:50 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_set_uri:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
* @uri: an URI string
|
|
|
|
*
|
|
|
|
* Sets the entry URI to @uri and, if applicable, updates the icon.
|
|
|
|
*
|
|
|
|
* Deprecated: 0.2.0
|
|
|
|
**/
|
2008-08-15 08:07:51 +00:00
|
|
|
void
|
2008-11-09 18:09:35 +00:00
|
|
|
midori_location_action_set_uri (MidoriLocationAction* location_action,
|
2008-08-15 08:07:51 +00:00
|
|
|
const gchar* uri)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
|
|
|
|
katze_assign (location_action->uri, g_strdup (uri));
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
midori_location_action_set_text (location_action, uri);
|
|
|
|
}
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2009-07-24 15:01:02 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_set_icon:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
* @icon: a #GdkPixbuf or %NULL
|
|
|
|
*
|
|
|
|
* Sets the icon shown on the left hand side.
|
|
|
|
*
|
|
|
|
* Note: Since 0.1.8 %NULL can be passed to indicate that the
|
|
|
|
* visible URI refers to a target, not the current location.
|
|
|
|
**/
|
2008-11-10 23:51:28 +00:00
|
|
|
void
|
|
|
|
midori_location_action_set_icon (MidoriLocationAction* location_action,
|
|
|
|
GdkPixbuf* icon)
|
|
|
|
{
|
2009-10-23 16:08:25 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-11-10 23:51:28 +00:00
|
|
|
GSList* proxies;
|
|
|
|
GtkWidget* location_entry;
|
|
|
|
GtkWidget* entry;
|
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
2009-07-24 15:01:02 +00:00
|
|
|
g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
|
2008-11-10 23:51:28 +00:00
|
|
|
|
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2008-11-10 23:51:28 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-11-10 23:51:28 +00:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
|
|
|
|
2009-07-24 15:01:02 +00:00
|
|
|
if (icon)
|
|
|
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, icon);
|
|
|
|
else
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_JUMP_TO);
|
2008-11-10 23:51:28 +00:00
|
|
|
}
|
2009-10-12 20:56:18 +00:00
|
|
|
#endif
|
2008-11-10 23:51:28 +00:00
|
|
|
}
|
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
void
|
|
|
|
midori_location_action_add_uri (MidoriLocationAction* location_action,
|
|
|
|
const gchar* uri)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
katze_assign (location_action->uri, g_strdup (uri));
|
2010-01-28 22:56:54 +00:00
|
|
|
|
|
|
|
midori_location_action_toggle_arrow (location_action);
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2008-10-27 02:12:09 +00:00
|
|
|
void
|
|
|
|
midori_location_action_add_item (MidoriLocationAction* location_action,
|
|
|
|
const gchar* uri,
|
|
|
|
GdkPixbuf* icon,
|
|
|
|
const gchar* title)
|
|
|
|
{
|
2009-10-23 16:08:25 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-10-27 02:12:09 +00:00
|
|
|
GSList* proxies;
|
2008-11-09 18:09:35 +00:00
|
|
|
GtkWidget* location_entry;
|
2008-10-27 02:12:09 +00:00
|
|
|
GtkWidget* entry;
|
2009-10-23 16:08:25 +00:00
|
|
|
#endif
|
2008-10-27 02:12:09 +00:00
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
g_return_if_fail (title != NULL);
|
|
|
|
g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
|
|
|
|
|
2009-10-12 20:56:18 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-10-27 02:12:09 +00:00
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2009-10-04 01:52:01 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
2008-10-27 02:12:09 +00:00
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-11-09 18:09:35 +00:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
2008-10-27 02:12:09 +00:00
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, icon);
|
2008-10-27 02:12:09 +00:00
|
|
|
}
|
2009-10-12 20:56:18 +00:00
|
|
|
#endif
|
2008-10-27 02:12:09 +00:00
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
void
|
|
|
|
midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action,
|
|
|
|
GdkPixbuf* icon,
|
|
|
|
const gchar* uri)
|
|
|
|
{
|
2009-10-23 16:08:25 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-08-15 08:07:51 +00:00
|
|
|
GSList* proxies;
|
2008-11-09 18:09:35 +00:00
|
|
|
GtkWidget* location_entry;
|
2008-08-15 08:07:51 +00:00
|
|
|
GtkWidget* entry;
|
2009-10-23 16:08:25 +00:00
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (!icon || GDK_IS_PIXBUF (icon));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
|
2009-10-12 20:56:18 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-08-15 08:07:51 +00:00
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2009-10-04 01:52:01 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
2008-08-15 08:07:51 +00:00
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-11-09 18:09:35 +00:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
2008-08-15 08:07:51 +00:00
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY, icon);
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2009-10-12 20:56:18 +00:00
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
midori_location_action_set_title_for_uri (MidoriLocationAction* location_action,
|
|
|
|
const gchar* title,
|
|
|
|
const gchar* uri)
|
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
/* Nothing to do */
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
|
|
|
|
2009-04-11 20:24:56 +00:00
|
|
|
/**
|
|
|
|
* midori_location_action_set_search_engines:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
* @search_engines: a #KatzeArray
|
|
|
|
*
|
2010-01-28 21:19:00 +00:00
|
|
|
* Assigns the specified search engines to the location action.
|
|
|
|
* Search engines will appear as actions in the completion.
|
2009-04-11 20:24:56 +00:00
|
|
|
*
|
2010-01-28 21:19:00 +00:00
|
|
|
* Since: 0.1.6
|
2009-04-11 20:24:56 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_location_action_set_search_engines (MidoriLocationAction* location_action,
|
|
|
|
KatzeArray* search_engines)
|
|
|
|
{
|
2010-01-28 21:19:00 +00:00
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
|
|
|
|
if (search_engines)
|
|
|
|
g_object_ref (search_engines);
|
|
|
|
|
|
|
|
katze_object_assign (location_action->search_engines, search_engines);
|
2009-04-11 20:24:56 +00:00
|
|
|
}
|
|
|
|
|
2008-08-31 00:45:13 +00:00
|
|
|
gdouble
|
|
|
|
midori_location_action_get_progress (MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_LOCATION_ACTION (location_action), 0.0);
|
|
|
|
|
|
|
|
return location_action->progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
midori_location_action_set_progress (MidoriLocationAction* location_action,
|
|
|
|
gdouble progress)
|
|
|
|
{
|
|
|
|
GSList* proxies;
|
|
|
|
GtkWidget* entry;
|
2010-01-01 22:55:04 +00:00
|
|
|
GtkWidget* child;
|
2008-08-31 00:45:13 +00:00
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
|
|
|
|
location_action->progress = CLAMP (progress, 0.0, 1.0);
|
|
|
|
|
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2008-08-31 00:45:13 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
2010-01-01 22:55:04 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (entry));
|
2008-08-31 00:45:13 +00:00
|
|
|
|
2010-01-01 22:55:04 +00:00
|
|
|
gtk_icon_entry_set_progress_fraction (GTK_ICON_ENTRY (child),
|
|
|
|
location_action->progress);
|
2008-08-31 00:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 08:07:51 +00:00
|
|
|
void
|
|
|
|
midori_location_action_set_secondary_icon (MidoriLocationAction* location_action,
|
|
|
|
const gchar* stock_id)
|
|
|
|
{
|
2009-10-23 16:08:25 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-08-15 08:07:51 +00:00
|
|
|
GSList* proxies;
|
|
|
|
GtkWidget* entry;
|
|
|
|
GtkWidget* child;
|
2009-10-23 16:08:25 +00:00
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
GtkStockItem stock_item;
|
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
g_return_if_fail (!stock_id || gtk_stock_lookup (stock_id, &stock_item));
|
|
|
|
|
2009-02-19 21:26:56 +00:00
|
|
|
katze_assign (location_action->secondary_icon, g_strdup (stock_id));
|
|
|
|
|
2009-10-12 20:56:18 +00:00
|
|
|
#if !HAVE_HILDON
|
2008-08-15 08:07:51 +00:00
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
2008-12-18 04:02:52 +00:00
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
2008-08-15 08:07:51 +00:00
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2009-05-17 14:26:31 +00:00
|
|
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
2008-08-15 08:07:51 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (entry));
|
|
|
|
|
2009-04-26 23:11:58 +00:00
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),
|
|
|
|
GTK_ICON_ENTRY_SECONDARY, stock_id);
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2009-10-12 20:56:18 +00:00
|
|
|
#endif
|
2008-08-15 08:07:51 +00:00
|
|
|
}
|
2008-11-08 01:23:08 +00:00
|
|
|
|
2008-11-09 18:09:35 +00:00
|
|
|
/**
|
2009-07-11 13:30:48 +00:00
|
|
|
* midori_location_action_delete_item_from_uri:
|
2009-04-11 20:24:56 +00:00
|
|
|
* @location_action: a #MidoriLocationAction
|
2008-11-09 18:09:35 +00:00
|
|
|
* @uri: a string
|
|
|
|
*
|
|
|
|
* Finds the item from the list matching @uri
|
|
|
|
* and removes it if it is the last instance.
|
|
|
|
**/
|
2008-11-08 01:23:08 +00:00
|
|
|
void
|
|
|
|
midori_location_action_delete_item_from_uri (MidoriLocationAction* location_action,
|
|
|
|
const gchar* uri)
|
|
|
|
{
|
2010-01-25 20:37:50 +00:00
|
|
|
/* Nothing to do */
|
2008-11-08 01:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
midori_location_action_clear (MidoriLocationAction* location_action)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
|
2010-01-28 22:56:54 +00:00
|
|
|
midori_location_action_toggle_arrow (location_action);
|
2008-11-08 01:23:08 +00:00
|
|
|
}
|
2010-04-13 21:44:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* midori_location_action_set_security_hint:
|
|
|
|
* @location_action: a #MidoriLocationAction
|
|
|
|
* @hint: a security hint
|
|
|
|
*
|
|
|
|
* Sets a security hint on the action, so that the security status
|
|
|
|
* can be reflected visually.
|
|
|
|
*
|
|
|
|
* Since: 0.2.5
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_location_action_set_security_hint (MidoriLocationAction* location_action,
|
|
|
|
MidoriSecurity hint)
|
|
|
|
{
|
|
|
|
GSList* proxies;
|
|
|
|
GtkWidget* entry;
|
|
|
|
GtkWidget* child;
|
|
|
|
|
|
|
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
|
|
|
|
|
|
|
proxies = gtk_action_get_proxies (GTK_ACTION (location_action));
|
|
|
|
|
|
|
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
|
|
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
|
|
|
{
|
2010-04-20 21:32:28 +00:00
|
|
|
GdkColor bg_color = { 0, 1 };
|
|
|
|
GdkColor fg_color = { 0, 1 };
|
|
|
|
|
2010-04-13 21:44:21 +00:00
|
|
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (entry));
|
|
|
|
|
|
|
|
if (hint == MIDORI_SECURITY_UNKNOWN)
|
2010-04-20 21:32:28 +00:00
|
|
|
{
|
|
|
|
gdk_color_parse ("#ef7070", &bg_color);
|
|
|
|
gdk_color_parse ("#000", &fg_color);
|
|
|
|
#if !HAVE_HILDON
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),
|
|
|
|
GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_INFO);
|
|
|
|
#endif
|
|
|
|
}
|
2010-04-13 21:44:21 +00:00
|
|
|
else if (hint == MIDORI_SECURITY_TRUSTED)
|
2010-04-20 21:32:28 +00:00
|
|
|
{
|
|
|
|
gdk_color_parse ("#fcf19a", &bg_color);
|
|
|
|
gdk_color_parse ("#000", &fg_color);
|
|
|
|
#if !HAVE_HILDON
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),
|
|
|
|
GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_DIALOG_AUTHENTICATION);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_modify_base (child, GTK_STATE_NORMAL,
|
|
|
|
bg_color.red == 1 ? NULL : &bg_color);
|
|
|
|
gtk_widget_modify_text (child, GTK_STATE_NORMAL,
|
|
|
|
bg_color.red == 1 ? NULL : &fg_color);
|
2010-04-13 21:44:21 +00:00
|
|
|
}
|
|
|
|
}
|