Introduce MidoriLocationEntry and GtkIconEntry

This commit is contained in:
Dale Whittaker 2008-07-17 21:02:14 +02:00 committed by Christian Dywan
parent 9ba5513934
commit efb148f58e
11 changed files with 2292 additions and 66 deletions

2
README
View file

@ -9,7 +9,7 @@ Midori is a lightweight web browser.
* User scripts and user styles support. * User scripts and user styles support.
* Extensible via Javascript. * Extensible via Javascript.
Requirements: GTK+ 2.6, libsexy, WebkitGtk, libXML2 Requirements: GTK+ 2.6, WebkitGtk, libXML2
For installation instructions read INSTALL. For installation instructions read INSTALL.

View file

@ -51,14 +51,6 @@ fi
AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS) AC_SUBST(GTK_LIBS)
# Checks for libsexy
PKG_CHECK_MODULES(LIBSEXY, libsexy, have_libsexy=true, have_libsexy=false)
if test "x${have_libsexy}" = "xfalse" ; then
AC_MSG_ERROR([No Libsexy package information found])
fi
AC_SUBST(LIBSEXY_CFLAGS)
AC_SUBST(LIBSEXY_LIBS)
# Checks for gtksourceview # Checks for gtksourceview
PKG_CHECK_MODULES(GTKSOURCEVIEW, gtksourceview, have_gtksourceview=true, have_gtksourceview=false) PKG_CHECK_MODULES(GTKSOURCEVIEW, gtksourceview, have_gtksourceview=true, have_gtksourceview=false)
AC_SUBST(GTKSOURCEVIEW_CFLAGS) AC_SUBST(GTKSOURCEVIEW_CFLAGS)

View file

@ -1,7 +1,6 @@
INCLUDES = \ INCLUDES = \
$(GIO_CFLAGS) \ $(GIO_CFLAGS) \
$(GTK_CFLAGS) \ $(GTK_CFLAGS) \
$(LIBSEXY_CFLAGS) \
$(GTKSOURCEVIEW_CFLAGS) \ $(GTKSOURCEVIEW_CFLAGS) \
$(WEBKIT_CFLAGS) \ $(WEBKIT_CFLAGS) \
-I../katze -I../katze
@ -11,7 +10,6 @@ AM_CFLAGS = -DMIDORI_LOCALEDIR=\""$(localedir)"\"
LDADD = \ LDADD = \
$(GIO_LIBS) \ $(GIO_LIBS) \
$(GTK_LIBS) \ $(GTK_LIBS) \
$(LIBSEXY_LIBS) \
$(GTKSOURCEVIEW_LIBS)\ $(GTKSOURCEVIEW_LIBS)\
$(WEBKIT_LIBS) \ $(WEBKIT_LIBS) \
$(INTLLIBS) \ $(INTLLIBS) \
@ -22,6 +20,7 @@ bin_PROGRAMS = \
midori_SOURCES = \ midori_SOURCES = \
main.c main.h \ main.c main.h \
gtkiconentry.c gtkiconentry.h \
midori-webitem.c midori-webitem.h \ midori-webitem.c midori-webitem.h \
midori-weblist.c midori-weblist.h \ midori-weblist.c midori-weblist.h \
midori-app.c midori-app.h \ midori-app.c midori-app.h \
@ -33,6 +32,7 @@ midori_SOURCES = \
midori-websettings.c midori-websettings.h \ midori-websettings.c midori-websettings.h \
midori-preferences.c midori-preferences.h \ midori-preferences.c midori-preferences.h \
midori-searchentry.c midori-searchentry.h \ midori-searchentry.c midori-searchentry.h \
midori-locationentry.c midori-locationentry.h \
gjs.c gjs.h \ gjs.c gjs.h \
sokoke.c sokoke.h \ sokoke.c sokoke.h \
compat.c compat.h compat.c compat.h

1601
midori/gtkiconentry.c Normal file

File diff suppressed because it is too large Load diff

119
midori/gtkiconentry.h Normal file
View file

@ -0,0 +1,119 @@
/*
* Copyright (C) 2004-2006 Christian Hammond.
* Copyright (C) 2008 Cody Russell <bratsche@gnome.org>
*
* 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 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_ICON_ENTRY_H__
#define __GTK_ICON_ENTRY_H__
#include <glib.h>
#if GLIB_CHECK_VERSION (2, 16, 0)
#include <gio/gio.h>
#endif
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTK_TYPE_ICON_ENTRY (gtk_icon_entry_get_type())
#define GTK_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_ICON_ENTRY, GtkIconEntry))
#define GTK_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_ICON_ENTRY, GtkIconEntryClass))
#define GTK_IS_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_ICON_ENTRY))
#define GTK_IS_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_ICON_ENTRY))
#define GTK_ICON_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_ENTRY, GtkIconEntryClass))
typedef enum
{
GTK_ICON_ENTRY_PRIMARY,
GTK_ICON_ENTRY_SECONDARY
} GtkIconEntryPosition;
typedef struct _GtkIconEntry GtkIconEntry;
typedef struct _GtkIconEntryClass GtkIconEntryClass;
struct _GtkIconEntry
{
GtkEntry parent_object;
};
struct _GtkIconEntryClass
{
GtkEntryClass parent_class;
/* Signals */
void (*icon_pressed) (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
int button);
void (*icon_released) (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
int button);
void (*gtk_reserved1) (void);
void (*gtk_reserved2) (void);
void (*gtk_reserved3) (void);
void (*gtk_reserved4) (void);
};
GType gtk_icon_entry_get_type (void) G_GNUC_CONST;
GtkWidget* gtk_icon_entry_new (void);
void gtk_icon_entry_set_icon_from_pixbuf (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
GdkPixbuf *pixbuf);
void gtk_icon_entry_set_icon_from_stock (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
const gchar *stock_id);
void gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
const gchar *icon_name);
#if GLIB_CHECK_VERSION (2, 16, 0)
void gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
GIcon *icon);
#endif
GdkPixbuf* gtk_icon_entry_get_pixbuf (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos);
#if GLIB_CHECK_VERSION (2, 16, 0)
GIcon* gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos);
#endif
void gtk_icon_entry_set_icon_highlight (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
gboolean highlight);
gboolean gtk_icon_entry_get_icon_highlight (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos);
void gtk_icon_entry_set_cursor (const GtkIconEntry *icon_entry,
GtkIconEntryPosition icon_pos,
GdkCursorType cursor_type);
void gtk_icon_entry_set_tooltip (const GtkIconEntry *icon_entry,
GtkIconEntryPosition icon_pos,
const gchar *text);
void gtk_icon_entry_set_icon_sensitive (const GtkIconEntry *icon_entry,
GtkIconEntryPosition icon_pos,
gboolean sensitive);
G_END_DECLS
#endif /* __GTK_ICON_ENTRY_H__ */

View file

@ -14,6 +14,7 @@
#include "midori-browser.h" #include "midori-browser.h"
#include "main.h" #include "main.h"
#include "gtkiconentry.h"
#include "sokoke.h" #include "sokoke.h"
#include "midori-webview.h" #include "midori-webview.h"
#include "midori-preferences.h" #include "midori-preferences.h"
@ -21,6 +22,7 @@
#include "midori-addons.h" #include "midori-addons.h"
#include "midori-console.h" #include "midori-console.h"
#include "midori-searchentry.h" #include "midori-searchentry.h"
#include "midori-locationentry.h"
#include "compat.h" #include "compat.h"
#if GLIB_CHECK_VERSION (2, 16, 0) #if GLIB_CHECK_VERSION (2, 16, 0)
@ -29,7 +31,6 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libsexy/sexy.h>
#if HAVE_GTKSOURCEVIEW #if HAVE_GTKSOURCEVIEW
#include <gtksourceview/gtksourceview.h> #include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h> #include <gtksourceview/gtksourcelanguagemanager.h>
@ -50,7 +51,6 @@ struct _MidoriBrowser
GtkWidget* navigationbar; GtkWidget* navigationbar;
GtkWidget* button_tab_new; GtkWidget* button_tab_new;
GtkWidget* button_homepage; GtkWidget* button_homepage;
GtkWidget* location_icon;
GtkWidget* location; GtkWidget* location;
GtkWidget* search; GtkWidget* search;
GtkWidget* button_trash; GtkWidget* button_trash;
@ -123,12 +123,19 @@ midori_browser_set_property (GObject* object,
const GValue* value, const GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
static void
midori_browser_location_active_changed_cb (MidoriLocationEntry* location_entry,
gint index,
MidoriBrowser* browser);
static void static void
midori_browser_get_property (GObject* object, midori_browser_get_property (GObject* object,
guint prop_id, guint prop_id,
GValue* value, GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
static GtkAction* static GtkAction*
_action_by_name (MidoriBrowser* browser, _action_by_name (MidoriBrowser* browser,
const gchar* name) const gchar* name)
@ -278,7 +285,6 @@ _midori_browser_update_interface (MidoriBrowser* browser)
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading); katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
icon = katze_throbber_get_static_pixbuf (KATZE_THROBBER ( icon = katze_throbber_get_static_pixbuf (KATZE_THROBBER (
g_object_get_data (G_OBJECT (widget), "browser-tab-icon"))); g_object_get_data (G_OBJECT (widget), "browser-tab-icon")));
gtk_image_set_from_pixbuf (GTK_IMAGE (browser->location_icon), icon);
} }
static GtkWidget* static GtkWidget*
@ -411,12 +417,29 @@ midori_web_view_title_changed_cb (GtkWidget* web_view,
{ {
if (web_view == midori_browser_get_current_web_view (browser)) if (web_view == midori_browser_get_current_web_view (browser))
{ {
MidoriLocationEntryItem item;
const gchar* title = midori_web_view_get_display_title ( const gchar* title = midori_web_view_get_display_title (
MIDORI_WEB_VIEW (web_view)); MIDORI_WEB_VIEW (web_view));
gchar* window_title = g_strconcat (title, " - ", gchar* window_title = g_strconcat (title, " - ",
g_get_application_name (), NULL); g_get_application_name (), NULL);
gtk_window_set_title (GTK_WINDOW (browser), window_title); gtk_window_set_title (GTK_WINDOW (browser), window_title);
g_free (window_title); g_free (window_title);
item.favicon = midori_web_view_get_icon (MIDORI_WEB_VIEW (web_view));
item.uri = midori_location_entry_get_text (
MIDORI_LOCATION_ENTRY (browser->location));
item.title = title;
g_signal_handlers_block_by_func (browser->location,
midori_browser_location_active_changed_cb, browser);
midori_location_entry_add_item (MIDORI_LOCATION_ENTRY
(browser->location), &item);
g_signal_handlers_unblock_by_func (browser->location,
midori_browser_location_active_changed_cb, browser);
g_object_unref (item.favicon);
} }
} }
@ -444,7 +467,7 @@ midori_web_view_load_committed_cb (GtkWidget* web_view,
if (web_view == midori_browser_get_current_web_view (browser)) if (web_view == midori_browser_get_current_web_view (browser))
{ {
const gchar* uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view)); const gchar* uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view));
gtk_entry_set_text (GTK_ENTRY (browser->location), uri); midori_location_entry_set_text (MIDORI_LOCATION_ENTRY (browser->location), uri);
_midori_browser_set_statusbar_text (browser, NULL); _midori_browser_set_statusbar_text (browser, NULL);
} }
} }
@ -1611,10 +1634,8 @@ _action_find_activate(GtkAction* action,
} }
else else
{ {
GtkWidget* icon = gtk_image_new_from_stock (GTK_STOCK_FIND, gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
GTK_ICON_SIZE_MENU); GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_FIND);
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (browser->find_text),
SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE (icon));
gtk_entry_set_text (GTK_ENTRY (browser->find_text), ""); gtk_entry_set_text (GTK_ENTRY (browser->find_text), "");
gtk_widget_show (browser->find); gtk_widget_show (browser->find);
gtk_widget_grab_focus (GTK_WIDGET (browser->find_text)); gtk_widget_grab_focus (GTK_WIDGET (browser->find_text));
@ -1635,13 +1656,9 @@ _midori_browser_find (MidoriBrowser* browser,
text, case_sensitive, forward); text, case_sensitive, forward);
if (GTK_WIDGET_VISIBLE (browser->find)) if (GTK_WIDGET_VISIBLE (browser->find))
{ {
GtkWidget* icon; gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
if (found) GTK_ICON_ENTRY_PRIMARY,
icon = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU); (found) ? GTK_STOCK_FIND : GTK_STOCK_STOP);
else
icon = gtk_image_new_from_stock (GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (browser->find_text),
SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE (icon));
_midori_browser_tab_mark_text_matches (browser, widget, _midori_browser_tab_mark_text_matches (browser, widget,
text, case_sensitive); text, case_sensitive);
const gboolean highlight = gtk_toggle_tool_button_get_active ( const gboolean highlight = gtk_toggle_tool_button_get_active (
@ -1993,6 +2010,22 @@ _action_homepage_activate (GtkAction* action,
g_free (homepage); g_free (homepage);
} }
/* catch the active-changed signal so that we can display the pack
when selected from the list */
static void
midori_browser_location_active_changed_cb (MidoriLocationEntry* location_entry,
gint index,
MidoriBrowser* browser)
{
const gchar* uri;
if (index > -1)
{
uri = midori_location_entry_get_text (location_entry);
_midori_browser_open_uri (browser, uri);
}
}
static gboolean static gboolean
midori_browser_location_key_press_event_cb (GtkWidget* widget, midori_browser_location_key_press_event_cb (GtkWidget* widget,
GdkEventKey* event, GdkEventKey* event,
@ -2020,7 +2053,7 @@ midori_browser_location_key_press_event_cb (GtkWidget* widget,
/* TODO: Use new_uri intermediately when completion is better /* TODO: Use new_uri intermediately when completion is better
Completion should be generated from history, that is Completion should be generated from history, that is
the uri as well as the title. */ the uri as well as the title. */
sokoke_entry_append_completion (GTK_ENTRY (widget), uri); /* sokoke_entry_append_completion (GTK_ENTRY (widget), uri); */
_midori_browser_open_uri (browser, new_uri); _midori_browser_open_uri (browser, new_uri);
g_free (new_uri); g_free (new_uri);
gtk_widget_grab_focus (midori_browser_get_current_tab (browser)); gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
@ -2518,7 +2551,14 @@ gtk_notebook_switch_page_cb (GtkWidget* notebook,
widget = midori_browser_get_current_tab (browser); widget = midori_browser_get_current_tab (browser);
uri = _midori_browser_get_tab_uri (browser, widget); uri = _midori_browser_get_tab_uri (browser, widget);
gtk_entry_set_text (GTK_ENTRY (browser->location), uri);
g_signal_handlers_block_by_func (browser->location,
midori_browser_location_active_changed_cb, browser);
midori_location_entry_set_item_from_uri (MIDORI_LOCATION_ENTRY
(browser->location), uri);
g_signal_handlers_unblock_by_func (browser->location,
midori_browser_location_active_changed_cb, browser);
title = _midori_browser_get_tab_title (browser, widget); title = _midori_browser_get_tab_title (browser, widget);
window_title = g_strconcat (title, " - ", window_title = g_strconcat (title, " - ",
g_get_application_name (), NULL); g_get_application_name (), NULL);
@ -3095,6 +3135,16 @@ midori_browser_search_activate_cb (GtkWidget* widget,
g_free (location_entry_search); g_free (location_entry_search);
} }
static void
midori_browser_entry_clear_icon_released_cb (GtkIconEntry* entry,
gint icon_pos,
gint button,
gpointer user_data)
{
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
gtk_entry_set_text (GTK_ENTRY (entry), "");
}
static void static void
midori_browser_search_notify_current_item_cb (GObject *gobject, midori_browser_search_notify_current_item_cb (GObject *gobject,
GParamSpec *arg1, GParamSpec *arg1,
@ -3227,13 +3277,12 @@ midori_browser_init (MidoriBrowser* browser)
ui_manager, "/toolbar_navigation/Homepage"); ui_manager, "/toolbar_navigation/Homepage");
/* Location */ /* Location */
browser->location = sexy_icon_entry_new (); browser->location = midori_location_entry_new ();
sokoke_entry_setup_completion (GTK_ENTRY (browser->location)); /* FIXME: sokoke_entry_setup_completion (GTK_ENTRY (browser->location)); */
browser->location_icon = gtk_image_new ();
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (browser->location)
, SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE (browser->location_icon));
sexy_icon_entry_add_clear_button (SEXY_ICON_ENTRY (browser->location));
g_object_connect (browser->location, g_object_connect (browser->location,
"signal::active-changed",
midori_browser_location_active_changed_cb, browser, NULL);
g_object_connect (gtk_bin_get_child (GTK_BIN (browser->location)),
"signal::key-press-event", "signal::key-press-event",
midori_browser_location_key_press_event_cb, browser, midori_browser_location_key_press_event_cb, browser,
"signal::focus-out-event", "signal::focus-out-event",
@ -3243,7 +3292,9 @@ midori_browser_init (MidoriBrowser* browser)
NULL); NULL);
GtkToolItem* toolitem = gtk_tool_item_new (); GtkToolItem* toolitem = gtk_tool_item_new ();
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE); gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
gtk_container_add (GTK_CONTAINER(toolitem), browser->location); GtkWidget* align = gtk_alignment_new (0, 0.5, 1, 0.1);
gtk_container_add (GTK_CONTAINER (align), browser->location);
gtk_container_add (GTK_CONTAINER(toolitem), align);
gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar), toolitem, -1); gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar), toolitem, -1);
/* Search */ /* Search */
@ -3462,12 +3513,15 @@ midori_browser_init (MidoriBrowser* browser)
gtk_container_add (GTK_CONTAINER (toolitem), gtk_container_add (GTK_CONTAINER (toolitem),
gtk_label_new_with_mnemonic (_("_Inline find:"))); gtk_label_new_with_mnemonic (_("_Inline find:")));
gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1); gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
browser->find_text = sexy_icon_entry_new (); browser->find_text = gtk_icon_entry_new ();
GtkWidget* icon = gtk_image_new_from_stock (GTK_STOCK_FIND, gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY(browser->find_text),
GTK_ICON_SIZE_MENU); GTK_ICON_ENTRY_PRIMARY,
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY(browser->find_text), GTK_STOCK_FIND);
SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE (icon)); gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
sexy_icon_entry_add_clear_button (SEXY_ICON_ENTRY (browser->find_text)); GTK_ICON_ENTRY_SECONDARY,
GTK_STOCK_CLEAR);
g_signal_connect (browser->find_text, "icon_released",
G_CALLBACK (midori_browser_entry_clear_icon_released_cb), NULL);
g_signal_connect (browser->find_text, "activate", g_signal_connect (browser->find_text, "activate",
G_CALLBACK (_action_find_next_activate), browser); G_CALLBACK (_action_find_next_activate), browser);
toolitem = gtk_tool_item_new (); toolitem = gtk_tool_item_new ();

View file

@ -0,0 +1,384 @@
/*
Copyright (C) 2008 Dale Whittaker <dayul@users.sf.net>
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-locationentry.h"
#include "gtkiconentry.h"
#include "sokoke.h"
#include <gdk/gdkkeysyms.h>
#define DEFAULT_ICON GTK_STOCK_FILE
G_DEFINE_TYPE (MidoriLocationEntry, midori_location_entry, GTK_TYPE_COMBO_BOX_ENTRY)
enum
{
FAVICON_COL,
URI_COL,
TITLE_COL,
N_COLS
};
enum
{
ACTIVE_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
entry_icon_released (GtkIconEntry* entry,
gint icon_pos,
gint button,
gpointer user_data);
static gboolean
entry_key_press_event (GtkWidget* widget,
GdkEventKey* event,
MidoriLocationEntry* location_entry);
static void
midori_location_entry_active_changed (GtkComboBox* combo_box,
gpointer user_data);
static void
midori_location_entry_class_init (MidoriLocationEntryClass* 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);
}
static void
midori_location_entry_init (MidoriLocationEntry* location_entry)
{
GtkWidget* entry;
GtkListStore* store;
GtkCellRenderer* renderer;
/* we want the widget to have appears-as-list applied */
gtk_rc_parse_string ("style \"midori-location-entry-style\" {\n"
" GtkComboBox::appears-as-list = 1\n }\n"
"widget_class \"*MidoriLocationEntry\" "
"style \"midori-location-entry-style\"\n");
entry = gtk_icon_entry_new ();
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, DEFAULT_ICON);
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_CLEAR);
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, TRUE);
g_signal_connect (entry, "icon_released", G_CALLBACK (entry_icon_released), NULL);
g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_key_press_event), location_entry);
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (location_entry), entry);
store = gtk_list_store_new (N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
g_object_set (G_OBJECT (location_entry), "model", GTK_TREE_MODEL (store), NULL);
g_object_unref(store);
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (location_entry), URI_COL);
gtk_cell_layout_clear (GTK_CELL_LAYOUT (location_entry));
/* setup the renderer for the favicon */
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (location_entry), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (location_entry), renderer, "pixbuf", FAVICON_COL, NULL);
g_object_set (G_OBJECT (renderer), "xpad", 5, "ypad", 5, "yalign", 0.0, NULL);
/* setup the renderer for the uri/title */
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (location_entry), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (location_entry), renderer, "markup", TITLE_COL, NULL);
g_object_set (G_OBJECT (renderer), "xpad", 5, "ypad", 5, NULL);
g_object_set (G_OBJECT (renderer), "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (location_entry), -1);
g_signal_connect (location_entry, "changed", G_CALLBACK (midori_location_entry_active_changed), NULL);
}
static gboolean
entry_key_press_event (GtkWidget* widget,
GdkEventKey* event,
MidoriLocationEntry* location_entry)
{
switch (event->keyval)
{
case GDK_Down:
case GDK_Up:
{
if (!sokoke_object_get_boolean (location_entry, "popup-shown"))
gtk_combo_box_popup (GTK_COMBO_BOX (location_entry));
return TRUE;
}
}
return FALSE;
}
static void
entry_icon_released (GtkIconEntry* entry,
gint icon_pos,
gint button,
gpointer user_data)
{
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
gtk_entry_set_text (GTK_ENTRY (entry), "");
}
static void
midori_location_entry_active_changed (GtkComboBox* combo_box,
gpointer user_data)
{
GtkTreeIter iter;
GtkIconEntry* entry;
GtkTreeModel* model;
GdkPixbuf* pixbuf;
if (gtk_combo_box_get_active_iter (combo_box, &iter))
{
entry = GTK_ICON_ENTRY (GTK_BIN (combo_box)->child);
if (entry)
{
pixbuf = NULL;
model = gtk_combo_box_get_model (combo_box);
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);
g_signal_emit (MIDORI_LOCATION_ENTRY (combo_box),
signals[ACTIVE_CHANGED], 0, gtk_combo_box_get_active (combo_box));
}
}
}
static void
midori_location_entry_set_item (GtkTreeModel* model,
GtkTreeIter* iter,
MidoriLocationEntryItem* item)
{
gchar* desc = NULL;
if (item->title)
desc = g_strdup_printf ("<b>%s</b> - %s", item->uri, item->title);
else
desc = g_strdup_printf ("<b>%s</b>", item->uri);
gtk_list_store_set (GTK_LIST_STORE (model), iter,
FAVICON_COL, item->favicon, URI_COL, item->uri, TITLE_COL, desc, -1);
g_free (desc);
}
/**
* midori_location_entry_new:
*
* Creates a new #MidoriLocationEntry.
*
* Return value: a new #MidoriLocationEntry
**/
GtkWidget*
midori_location_entry_new (void)
{
return (g_object_new (MIDORI_TYPE_LOCATION_ENTRY, NULL));
}
/**
* midori_location_entry_item_index:
* @location_entry: a #MidoriLocationEntry
* @uri: a string
*
* Gets the index of the item matching @uri.
*
* Return value: an integer
**/
gint
midori_location_entry_item_index (MidoriLocationEntry* location_entry,
const gchar* uri)
{
GtkTreeModel* model;
GtkTreeIter iter;
gint index;
gchar* tmpuri;
gint tmpindex;
g_return_val_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry), -1);
g_return_val_if_fail (uri != NULL, -1);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry));
index = -1;
if (gtk_tree_model_get_iter_first (model, &iter))
{
tmpuri = NULL;
tmpindex = 0;
do
{
gtk_tree_model_get (model, &iter, URI_COL, &tmpuri, -1);
if (g_ascii_strcasecmp (uri, tmpuri) == 0)
{
g_free (tmpuri);
index = tmpindex;
break;
}
g_free (tmpuri);
tmpindex++;
}
while (gtk_tree_model_iter_next (model, &iter));
}
return index;
}
/**
* midori_location_entry_get_text:
* @location_entry: a #MidoriLocationEntry
*
* Gets the entry text.
*
* Return value: a string
**/
const gchar*
midori_location_entry_get_text (MidoriLocationEntry* location_entry)
{
GtkWidget* entry;
g_return_val_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry), NULL);
entry = gtk_bin_get_child (GTK_BIN (location_entry));
g_return_val_if_fail (GTK_IS_ICON_ENTRY (entry), NULL);
return gtk_entry_get_text (GTK_ENTRY (entry));
}
/**
* midori_location_entry_set_text:
* @location_entry: a #MidoriLocationEntry
* @text: a string
*
* Sets the entry text to @text.
**/
void
midori_location_entry_set_text (MidoriLocationEntry* location_entry,
const gchar* text)
{
GtkWidget* entry;
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
entry = gtk_bin_get_child (GTK_BIN (location_entry));
g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
gtk_entry_set_text (GTK_ENTRY (entry), text);
}
/**
* midori_location_entry_clear:
* @location_entry: a #MidoriLocationEntry
*
* Clears the entry text and resets the entry favicon.
**/
void
midori_location_entry_clear (MidoriLocationEntry* location_entry)
{
GtkWidget* entry;
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
entry = gtk_bin_get_child (GTK_BIN (location_entry));
g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_PRIMARY, DEFAULT_ICON);
}
/**
* midori_location_entry_set_item_from_uri:
* @location_entry: a #MidoriLocationEntry
* @uri: a string
*
* Finds the item from the list matching @uri and sets it as the active item.
* If @uri is not found it clears the active item.
**/
void
midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry,
const gchar* uri)
{
gint index;
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
index = midori_location_entry_item_index (
MIDORI_LOCATION_ENTRY (location_entry), uri);
gtk_combo_box_set_active (GTK_COMBO_BOX (location_entry), index);
if(index == -1)
midori_location_entry_clear (location_entry);
}
/**
* midori_location_entry_add_item:
* @location_entry: a #MidoriLocationEntry
* @item: a MidoriLocationItem
*
* Adds @item if it is not already in the list.
* Sets @item to be active.
**/
void
midori_location_entry_add_item (MidoriLocationEntry* location_entry,
MidoriLocationEntryItem* item)
{
GtkTreeModel* model;
GtkTreeIter iter;
gboolean item_exists = FALSE;
gchar* uri;
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
g_return_if_fail (item->uri != NULL);
g_return_if_fail (item->favicon != NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry));
if (gtk_tree_model_get_iter_first (model, &iter))
{
uri = NULL;
do
{
gtk_tree_model_get (model, &iter, URI_COL, &uri, -1);
if (g_ascii_strcasecmp (item->uri, uri) == 0)
{
item_exists = TRUE;
g_free (uri);
break;
}
g_free (uri);
}
while (gtk_tree_model_iter_next (model, &iter));
}
if (!item_exists)
gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
midori_location_entry_set_item (model, &iter, item);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (location_entry), &iter);
}

View file

@ -0,0 +1,77 @@
/*
Copyright (C) 2008 Dale Whittaker <dayul@users.sf.net>
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.
*/
#ifndef __MIDORI_LOCATION_ENTRY_H__
#define __MIDORI_LOCATION_ENTRY_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_LOCATION_ENTRY (midori_location_entry_get_type ())
#define MIDORI_LOCATION_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_LOCATION_ENTRY, MidoriLocationEntry))
#define MIDORI_LOCATION_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_LOCATION_ENTRY, MidoriLocationEntryClass))
#define MIDORI_IS_LOCATION_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_LOCATION_ENTRY))
#define MIDORI_IS_LOCATION_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_LOCATION_ENTRY))
#define MIDORI_LOCATION_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_LOCATION_ENTRY, MidoriLocationEntryClass))
typedef struct _MidoriLocationEntry MidoriLocationEntry;
typedef struct _MidoriLocationEntryClass MidoriLocationEntryClass;
typedef struct _MidoriLocationEntryItem MidoriLocationEntryItem;
struct _MidoriLocationEntry
{
GtkComboBoxEntry parent_instance;
};
struct _MidoriLocationEntryClass
{
GtkComboBoxEntryClass parent_class;
};
struct _MidoriLocationEntryItem
{
GdkPixbuf* favicon;
const gchar* uri;
const gchar* title;
};
GType
midori_location_entry_get_type (void);
GtkWidget*
midori_location_entry_new (void);
gint
midori_location_entry_item_index (MidoriLocationEntry* location_entry,
const gchar* uri);
const gchar*
midori_location_entry_get_text (MidoriLocationEntry* location_entry);
void
midori_location_entry_set_text (MidoriLocationEntry* location_entry,
const gchar* text);
void
midori_location_entry_clear (MidoriLocationEntry* location_entry);
void
midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry,
const gchar* uri);
void
midori_location_entry_add_item (MidoriLocationEntry* location_entry,
MidoriLocationEntryItem* item);
G_END_DECLS
#endif /* __MIDORI_LOCATION_ENTRY_H__ */

View file

@ -19,13 +19,13 @@
struct _MidoriSearchEntry struct _MidoriSearchEntry
{ {
SexyIconEntry parent_instance; GtkIconEntry parent_instance;
MidoriWebList* search_engines; MidoriWebList* search_engines;
MidoriWebItem* current_item; MidoriWebItem* current_item;
}; };
G_DEFINE_TYPE (MidoriSearchEntry, midori_search_entry, SEXY_TYPE_ICON_ENTRY) G_DEFINE_TYPE (MidoriSearchEntry, midori_search_entry, GTK_TYPE_ICON_ENTRY)
enum enum
{ {
@ -112,7 +112,7 @@ midori_search_entry_manage_activate_cb (GtkWidget* menuitem,
static void static void
midori_search_entry_icon_released_cb (GtkWidget* widget, midori_search_entry_icon_released_cb (GtkWidget* widget,
SexyIconEntryPosition* pos, GtkIconEntryPosition* pos,
gint button) gint button)
{ {
MidoriSearchEntry* search_entry; MidoriSearchEntry* search_entry;
@ -240,8 +240,8 @@ midori_search_entry_engines_remove_item_cb (MidoriWebList* web_list,
midori_search_entry_set_current_item (search_entry, web_item); midori_search_entry_set_current_item (search_entry, web_item);
else else
{ {
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (search_entry), gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (search_entry),
SEXY_ICON_ENTRY_PRIMARY, NULL); GTK_ICON_ENTRY_PRIMARY, NULL);
sokoke_entry_set_default_text (GTK_ENTRY (search_entry), ""); sokoke_entry_set_default_text (GTK_ENTRY (search_entry), "");
katze_object_assign (search_entry->current_item, NULL); katze_object_assign (search_entry->current_item, NULL);
@ -256,8 +256,8 @@ midori_search_entry_init (MidoriSearchEntry* search_entry)
search_entry->search_engines = midori_web_list_new (); search_entry->search_engines = midori_web_list_new ();
search_entry->current_item = NULL; search_entry->current_item = NULL;
sexy_icon_entry_set_icon_highlight (SEXY_ICON_ENTRY (search_entry), gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (search_entry),
SEXY_ICON_ENTRY_PRIMARY, TRUE); GTK_ICON_ENTRY_PRIMARY, TRUE);
g_object_connect (search_entry, g_object_connect (search_entry,
"signal::icon-released", "signal::icon-released",
midori_search_entry_icon_released_cb, NULL, midori_search_entry_icon_released_cb, NULL,
@ -412,9 +412,9 @@ midori_search_entry_set_current_item (MidoriSearchEntry* search_entry,
pixbuf = sokoke_web_icon (midori_web_item_get_icon (web_item), pixbuf = sokoke_web_icon (midori_web_item_get_icon (web_item),
GTK_ICON_SIZE_MENU, GTK_WIDGET (search_entry)); GTK_ICON_SIZE_MENU, GTK_WIDGET (search_entry));
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (search_entry), gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (search_entry),
SEXY_ICON_ENTRY_PRIMARY, GTK_ICON_ENTRY_PRIMARY,
GTK_IMAGE (gtk_image_new_from_pixbuf (pixbuf))); pixbuf);
g_object_unref (pixbuf); g_object_unref (pixbuf);
sokoke_entry_set_default_text (GTK_ENTRY (search_entry), sokoke_entry_set_default_text (GTK_ENTRY (search_entry),
midori_web_item_get_name (web_item)); midori_web_item_get_name (web_item));

View file

@ -13,9 +13,9 @@
#define __MIDORI_SEARCH_ENTRY_H__ #define __MIDORI_SEARCH_ENTRY_H__
#include "midori-weblist.h" #include "midori-weblist.h"
#include "gtkiconentry.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libsexy/sexy.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -37,7 +37,7 @@ typedef struct _MidoriSearchEntryClass MidoriSearchEntryClass;
struct _MidoriSearchEntryClass struct _MidoriSearchEntryClass
{ {
SexyIconEntryClass parent_class; GtkIconEntryClass parent_class;
}; };
GType GType

View file

@ -37,7 +37,6 @@ def configure (conf):
conf.check_pkg ('gio-2.0', destvar='GIO', vnum='2.16.0', mandatory=False) conf.check_pkg ('gio-2.0', destvar='GIO', vnum='2.16.0', mandatory=False)
conf.check_pkg ('gtk+-2.0', destvar='GTK', vnum='2.6.0', mandatory=True) conf.check_pkg ('gtk+-2.0', destvar='GTK', vnum='2.6.0', mandatory=True)
conf.check_pkg ('libsexy', destvar='LIBSEXY', vnum='0.1', mandatory=True)
conf.check_pkg ('gtksourceview-2.0', destvar='GTKSOURCEVIEW', vnum='2.0', mandatory=False) conf.check_pkg ('gtksourceview-2.0', destvar='GTKSOURCEVIEW', vnum='2.0', mandatory=False)
conf.check_pkg ('webkit-1.0', destvar='WEBKIT', vnum='0.1', mandatory=True) conf.check_pkg ('webkit-1.0', destvar='WEBKIT', vnum='0.1', mandatory=True)
conf.check_pkg ('libxml-2.0', destvar='LIBXML', vnum='2.6', mandatory=True) conf.check_pkg ('libxml-2.0', destvar='LIBXML', vnum='2.6', mandatory=True)