Introduce WebItem, first step of refactoring web search

This commit is contained in:
Christian Dywan 2008-06-09 03:17:01 +02:00
parent 8e8e9f3663
commit f2aff5f290
8 changed files with 535 additions and 248 deletions

View file

@ -18,6 +18,7 @@ bin_PROGRAMS = \
midori_SOURCES = \ midori_SOURCES = \
main.c main.h \ main.c main.h \
midori-item.c midori-item.h \
midori-app.c midori-app.h \ midori-app.c midori-app.h \
midori-browser.c midori-browser.h \ midori-browser.c midori-browser.h \
midori-panel.c midori-panel.h \ midori-panel.c midori-panel.h \

View file

@ -62,7 +62,7 @@ midori_trash_class_init (MidoriTrashClass* class)
{ {
signals[INSERTED] = g_signal_new ( signals[INSERTED] = g_signal_new (
"inserted", "inserted",
G_TYPE_FROM_CLASS(class), G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST), (GSignalFlags)(G_SIGNAL_RUN_LAST),
G_STRUCT_OFFSET (MidoriTrashClass, inserted), G_STRUCT_OFFSET (MidoriTrashClass, inserted),
0, 0,
@ -73,7 +73,7 @@ midori_trash_class_init (MidoriTrashClass* class)
signals[REMOVED] = g_signal_new ( signals[REMOVED] = g_signal_new (
"removed", "removed",
G_TYPE_FROM_CLASS(class), G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST), (GSignalFlags)(G_SIGNAL_RUN_LAST),
G_STRUCT_OFFSET (MidoriTrashClass, removed), G_STRUCT_OFFSET (MidoriTrashClass, removed),
0, 0,
@ -93,7 +93,7 @@ midori_trash_class_init (MidoriTrashClass* class)
PROP_LIMIT, PROP_LIMIT,
g_param_spec_uint ( g_param_spec_uint (
"limit", "limit",
"Limit", _("Limit"),
_("The maximum number of items"), _("The maximum number of items"),
0, G_MAXUINT, 10, 0, G_MAXUINT, 10,
flags)); flags));

367
midori/midori-webitem.c Normal file
View file

@ -0,0 +1,367 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
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-webitem.h"
#include <glib/gi18n.h>
#include <katze/katze.h>
struct _MidoriWebItem
{
GObject parent_instance;
gchar* name;
gchar* description;
gchar* uri;
gchar* icon;
gchar* token;
};
G_DEFINE_TYPE (MidoriWebItem, midori_web_item, G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_NAME,
PROP_DESCRIPTION,
PROP_URI,
PROP_ICON,
PROP_TOKEN
};
static void
midori_web_item_finalize (GObject* object);
static void
midori_web_item_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec);
static void
midori_web_item_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec);
static void
midori_web_item_class_init (MidoriWebItemClass* class)
{
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_web_item_finalize;
gobject_class->set_property = midori_web_item_set_property;
gobject_class->get_property = midori_web_item_get_property;
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string (
"name",
_("Name"),
_("The name of the web item"),
NULL,
flags));
g_object_class_install_property (gobject_class,
PROP_DESCRIPTION,
g_param_spec_string (
"description",
_("Description"),
_("The description of the web item"),
NULL,
flags));
g_object_class_install_property (gobject_class,
PROP_URI,
g_param_spec_string (
"uri",
_("URI"),
_("The URI of the web item"),
NULL,
flags));
g_object_class_install_property (gobject_class,
PROP_ICON,
g_param_spec_string (
"icon",
_("Icon"),
_("The icon of the web item"),
NULL,
flags));
g_object_class_install_property (gobject_class,
PROP_TOKEN,
g_param_spec_string (
"token",
_("Token"),
_("The token of the web item"),
NULL,
flags));
}
static void
midori_web_item_init (MidoriWebItem* web_item)
{
// Nothing to do here
}
static void
midori_web_item_finalize (GObject* object)
{
G_OBJECT_CLASS (midori_web_item_parent_class)->finalize (object);
}
static void
midori_web_item_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
MidoriWebItem* web_item = MIDORI_WEB_ITEM (object);
switch (prop_id)
{
case PROP_NAME:
web_item->name = g_value_dup_string (value);
break;
case PROP_DESCRIPTION:
web_item->description = g_value_dup_string (value);
break;
case PROP_URI:
web_item->uri = g_value_dup_string (value);
break;
case PROP_ICON:
web_item->icon = g_value_dup_string (value);
break;
case PROP_TOKEN:
web_item->token = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
midori_web_item_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
MidoriWebItem* web_item = MIDORI_WEB_ITEM (object);
switch (prop_id)
{
case PROP_NAME:
g_value_set_string (value, web_item->name);
break;
case PROP_DESCRIPTION:
g_value_set_string (value, web_item->description);
break;
case PROP_URI:
g_value_set_string (value, web_item->uri);
break;
case PROP_ICON:
g_value_set_string (value, web_item->icon);
break;
case PROP_TOKEN:
g_value_set_string (value, web_item->token);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* midori_web_item_new:
*
* Creates a new #MidoriWebItem.
*
* Return value: a new #MidoriWebItem
**/
MidoriWebItem*
midori_web_item_new (void)
{
MidoriWebItem* web_item = g_object_new (MIDORI_TYPE_WEB_ITEM,
NULL);
return web_item;
}
/**
* midori_web_item_get_name:
* @web_item: a #MidoriWebItem
*
* Retrieves the name of @web_item.
*
* Return value: the name of the web item
**/
const gchar*
midori_web_item_get_name (MidoriWebItem* web_item)
{
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), NULL);
return web_item->name;
}
/**
* midori_web_item_set_name:
* @web_item: a #MidoriWebItem
* @name: a string
*
* Sets the name of @web_item.
**/
void
midori_web_item_set_name (MidoriWebItem* web_item,
const gchar* name)
{
g_return_if_fail (MIDORI_IS_WEB_ITEM (web_item));
katze_assign (web_item->name, g_strdup (name));
g_object_notify (G_OBJECT (web_item), "name");
}
/**
* midori_web_item_get_description:
* @web_item: a #MidoriWebItem
*
* Retrieves the description of @web_item.
*
* Return value: the description of the web item
**/
const gchar*
midori_web_item_get_description (MidoriWebItem* web_item)
{
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), NULL);
return web_item->description;
}
/**
* midori_web_item_set_description:
* @web_item: a #MidoriWebItem
* @description: a string
*
* Sets the description of @web_item.
**/
void
midori_web_item_set_description (MidoriWebItem* web_item,
const gchar* description)
{
g_return_if_fail (MIDORI_IS_WEB_ITEM (web_item));
katze_assign (web_item->description, g_strdup (description));
g_object_notify (G_OBJECT (web_item), "description");
}
/**
* midori_web_item_get_uri:
* @web_item: a #MidoriWebItem
*
* Retrieves the URI of @web_item.
*
* Return value: the URI of the web item
**/
const gchar*
midori_web_item_get_uri (MidoriWebItem* web_item)
{
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), NULL);
return web_item->uri;
}
/**
* midori_web_item_set_uri:
* @web_item: a #MidoriWebItem
* @uri: a string
*
* Sets the URI of @web_item.
**/
void
midori_web_item_set_uri (MidoriWebItem* web_item,
const gchar* uri)
{
g_return_if_fail (MIDORI_IS_WEB_ITEM (web_item));
katze_assign (web_item->uri, g_strdup (uri));
g_object_notify (G_OBJECT (web_item), "uri");
}
/**
* midori_web_item_get_icon:
* @web_item: a #MidoriWebItem
*
* Retrieves the icon of @web_item.
*
* Return value: the icon of the web item
**/
const gchar*
midori_web_item_get_icon (MidoriWebItem* web_item)
{
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), NULL);
return web_item->icon;
}
/**
* midori_web_item_set_icon:
* @web_item: a #MidoriWebItem
* @icon: a string
*
* Sets the icon of @web_item.
**/
void
midori_web_item_set_icon (MidoriWebItem* web_item,
const gchar* icon)
{
g_return_if_fail (MIDORI_IS_WEB_ITEM (web_item));
katze_assign (web_item->icon, g_strdup (icon));
g_object_notify (G_OBJECT (web_item), "icon");
}
/**
* midori_web_item_get_token:
* @web_item: a #MidoriWebItem
*
* Retrieves the token of @web_item.
*
* Return value: the token of the web item
**/
const gchar*
midori_web_item_get_token (MidoriWebItem* web_item)
{
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), NULL);
return web_item->token;
}
/**
* midori_web_item_set_token:
* @web_item: a #MidoriWebItem
* @token: a string
*
* Sets the token of @web_item.
**/
void
midori_web_item_set_token (MidoriWebItem* web_item,
const gchar* token)
{
g_return_if_fail (MIDORI_IS_WEB_ITEM (web_item));
katze_assign (web_item->token, g_strdup (token));
g_object_notify (G_OBJECT (web_item), "token");
}

83
midori/midori-webitem.h Normal file
View file

@ -0,0 +1,83 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
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_WEB_ITEM_H__
#define __MIDORI_WEB_ITEM_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_WEB_ITEM \
(midori_web_item_get_type ())
#define MIDORI_WEB_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_WEB_ITEM, MidoriWebItem))
#define MIDORI_WEB_ITEM_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_WEB_ITEM, MidoriWebItemClass))
#define MIDORI_IS_WEB_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_WEB_ITEM))
#define MIDORI_IS_WEB_ITEM_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_WEB_ITEM))
#define MIDORI_WEB_ITEM_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_WEB_ITEM, MidoriWebItemClass))
typedef struct _MidoriWebItem MidoriWebItem;
typedef struct _MidoriWebItemClass MidoriWebItemClass;
struct _MidoriWebItemClass
{
GObjectClass parent_class;
};
GType
midori_web_item_get_type (void);
MidoriWebItem*
midori_web_item_new (void);
const gchar*
midori_web_item_get_name (MidoriWebItem* web_item);
void
midori_web_item_set_name (MidoriWebItem* web_item,
const gchar* name);
const gchar*
midori_web_item_get_description (MidoriWebItem* web_item);
void
midori_web_item_set_description (MidoriWebItem* web_item,
const gchar* description);
const gchar*
midori_web_item_get_uri (MidoriWebItem* web_item);
void
midori_web_item_set_uri (MidoriWebItem* web_item,
const gchar* uri);
const gchar*
midori_web_item_get_icon (MidoriWebItem* web_item);
void
midori_web_item_set_icon (MidoriWebItem* web_item,
const gchar* icon);
const gchar*
midori_web_item_get_token (MidoriWebItem* web_item);
void
midori_web_item_set_token (MidoriWebItem* web_item,
const gchar* token);
G_END_DECLS
#endif /* __MIDORI_WEB_ITEM_H__ */

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2007 Christian Dywan <christian@twotoasts.de> Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -11,11 +11,9 @@
#include "search.h" #include "search.h"
#include "sokoke.h" #include "midori-webitem.h"
#include <katze/katze.h>
#include <stdio.h> #include "sokoke.h"
#include <string.h>
GList* search_engines_new(void) GList* search_engines_new(void)
{ {
@ -24,7 +22,7 @@ GList* search_engines_new(void)
void search_engines_free(GList* searchEngines) void search_engines_free(GList* searchEngines)
{ {
g_list_foreach(searchEngines, (GFunc)search_engine_free, NULL); g_list_foreach(searchEngines, (GFunc)g_object_unref, NULL);
g_list_free(searchEngines); g_list_free(searchEngines);
} }
@ -40,14 +38,19 @@ gboolean search_engines_from_file(GList** searchEngines, const gchar* filename
guint i; guint i;
for(i = 0; engines[i] != NULL; i++) for(i = 0; engines[i] != NULL; i++)
{ {
SearchEngine* engine = search_engine_new(); MidoriWebItem* web_item = midori_web_item_new ();
search_engine_set_short_name(engine, engines[i]); guint j, n_properties;
engine->description = g_key_file_get_string(keyFile, engines[i], "description", NULL); GParamSpec** pspecs = g_object_class_list_properties (
engine->url = g_key_file_get_string(keyFile, engines[i], "url", NULL); G_OBJECT_GET_CLASS (web_item), &n_properties);
engine->inputEncoding = g_key_file_get_string(keyFile, engines[i], "input-encoding", NULL); for (j = 0; j < n_properties; j++)
engine->icon = g_key_file_get_string(keyFile, engines[i], "icon", NULL); {
engine->keyword = g_key_file_get_string(keyFile, engines[i], "keyword", NULL); const gchar* property = g_param_spec_get_name (pspecs[j]);
*searchEngines = g_list_prepend(*searchEngines, engine); gchar* value = g_key_file_get_string (keyFile, engines[i],
property, NULL);
g_object_set (web_item, property, value, NULL);
g_free (value);
}
*searchEngines = g_list_prepend(*searchEngines, web_item);
} }
*searchEngines = g_list_reverse(*searchEngines); *searchEngines = g_list_reverse(*searchEngines);
g_strfreev(engines); g_strfreev(engines);
@ -71,129 +74,22 @@ gboolean search_engines_to_file(GList* searchEngines, const gchar* filename
guint i; guint i;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, i); MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data(searchEngines, i);
const gchar* name = search_engine_get_short_name(engine); const gchar* name = midori_web_item_get_name (web_item);
key_file_set_string(keyFile, name, "description", engine->description); guint j, n_properties;
key_file_set_string(keyFile, name, "url", engine->url); GParamSpec** pspecs = g_object_class_list_properties (
key_file_set_string(keyFile, name, "input-encoding", engine->inputEncoding); G_OBJECT_GET_CLASS (web_item), &n_properties);
key_file_set_string(keyFile, name, "icon", engine->icon); for (j = 0; j < n_properties; j++)
key_file_set_string(keyFile, name, "keyword", engine->keyword); {
const gchar* property = g_param_spec_get_name (pspecs[j]);
gchar* value;
g_object_get (web_item, property, &value, NULL);
key_file_set_string (keyFile, name, property, value);
g_free (value);
}
} }
gboolean bSaved = sokoke_key_file_save_to_file(keyFile, filename, error); gboolean bSaved = sokoke_key_file_save_to_file(keyFile, filename, error);
g_key_file_free(keyFile); g_key_file_free(keyFile);
return bSaved; return bSaved;
} }
SearchEngine* search_engine_new()
{
SearchEngine* engine = g_new0(SearchEngine, 1);
engine->shortName = g_strdup("");
return engine;
}
void search_engine_free(SearchEngine* engine)
{
g_return_if_fail(engine);
g_free(engine->shortName);
g_free(engine->description);
g_free(engine->url);
g_free(engine->inputEncoding);
g_free(engine->icon);
g_free(engine->keyword);
g_free(engine);
}
SearchEngine* search_engine_copy(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
SearchEngine* copy = search_engine_new();
search_engine_set_short_name(copy, engine->shortName);
search_engine_set_description(copy, engine->description);
search_engine_set_url(copy, engine->url);
search_engine_set_input_encoding(copy, engine->inputEncoding);
search_engine_set_icon(copy, engine->icon);
search_engine_set_keyword(copy, engine->keyword);
return engine;
}
GType search_engine_get_type()
{
static GType type = 0;
if(!type)
type = g_pointer_type_register_static("search_engine");
return type;
}
G_CONST_RETURN gchar* search_engine_get_short_name(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->shortName;
}
G_CONST_RETURN gchar* search_engine_get_description(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->description;
}
G_CONST_RETURN gchar* search_engine_get_url(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->url;
}
G_CONST_RETURN gchar* search_engine_get_input_encoding(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->inputEncoding;
}
G_CONST_RETURN gchar* search_engine_get_icon(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->icon;
}
G_CONST_RETURN gchar* search_engine_get_keyword(SearchEngine* engine)
{
g_return_val_if_fail(engine, NULL);
return engine->keyword;
}
void search_engine_set_short_name(SearchEngine* engine, const gchar* shortName)
{
g_return_if_fail(engine);
g_return_if_fail(shortName);
katze_assign(engine->shortName, g_strdup(shortName));
}
void search_engine_set_description(SearchEngine* engine, const gchar* description)
{
g_return_if_fail(engine);
katze_assign(engine->description, g_strdup(description));
}
void search_engine_set_url(SearchEngine* engine, const gchar* url)
{
g_return_if_fail(engine);
katze_assign(engine->url, g_strdup(url));
}
void search_engine_set_input_encoding(SearchEngine* engine, const gchar* inputEncoding)
{
g_return_if_fail(engine);
katze_assign(engine->inputEncoding, g_strdup(inputEncoding));
}
void search_engine_set_icon(SearchEngine* engine, const gchar* icon)
{
g_return_if_fail(engine);
katze_assign(engine->icon, g_strdup(icon));
}
void search_engine_set_keyword(SearchEngine* engine, const gchar* keyword)
{
g_return_if_fail(engine);
katze_assign(engine->keyword, g_strdup(keyword));
}

View file

@ -15,17 +15,6 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
// Note: This structure is entirely private.
typedef struct
{
gchar* shortName;
gchar* description;
gchar* url;
gchar* inputEncoding;
gchar* icon;
gchar* keyword;
} SearchEngine;
GList* GList*
search_engines_new(void); search_engines_new(void);
@ -38,54 +27,4 @@ search_engines_from_file(GList**, const gchar*, GError**);
gboolean gboolean
search_engines_to_file(GList*, const gchar*, GError**); search_engines_to_file(GList*, const gchar*, GError**);
SearchEngine*
search_engine_new(void);
void
search_engine_free(SearchEngine*);
SearchEngine*
search_engine_copy(SearchEngine*);
GType
search_engine_get_type();
#define G_TYPE_SEARCH_ENGINE search_engine_get_type()
G_CONST_RETURN gchar*
search_engine_get_short_name(SearchEngine*);
G_CONST_RETURN gchar*
search_engine_get_description(SearchEngine*);
G_CONST_RETURN gchar*
search_engine_get_url(SearchEngine*);
G_CONST_RETURN gchar*
search_engine_get_input_encoding(SearchEngine*);
G_CONST_RETURN gchar*
search_engine_get_icon(SearchEngine*);
G_CONST_RETURN gchar*
search_engine_get_keyword(SearchEngine*);
void
search_engine_set_short_name(SearchEngine*, const gchar*);
void
search_engine_set_description(SearchEngine*, const gchar*);
void
search_engine_set_url(SearchEngine*, const gchar*);
void
search_engine_set_input_encoding(SearchEngine*, const gchar*);
void
search_engine_set_icon(SearchEngine*, const gchar*);
void
search_engine_set_keyword(SearchEngine*, const gchar*);
#endif /* !__SEARCH_H__ */ #endif /* !__SEARCH_H__ */

View file

@ -11,7 +11,7 @@
#include "sokoke.h" #include "sokoke.h"
#include "search.h" #include "midori-webitem.h"
#include "config.h" #include "config.h"
#include "main.h" #include "main.h"
@ -57,11 +57,10 @@ sokoke_magic_uri (const gchar* uri, const gchar* default_search_uri)
guint i; guint i;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
SearchEngine* search_engine = (SearchEngine*)g_list_nth_data ( MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data (
searchEngines, i); searchEngines, i);
if (!strcmp (search_engine_get_keyword (search_engine), if (!strcmp (midori_web_item_get_token (web_item), parts[0]))
parts[0])) search_uri = midori_web_item_get_uri (web_item);
search_uri = search_engine->url;
} }
if (search_uri) if (search_uri)
search = g_strdup_printf (search_uri, parts[1]); search = g_strdup_printf (search_uri, parts[1]);

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2007 Christian Dywan <christian@twotoasts.de> Copyright (C) 2007-2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -16,6 +16,8 @@
#include "main.h" #include "main.h"
#include "sokoke.h" #include "sokoke.h"
#include "midori-webitem.h"
#include <string.h> #include <string.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
@ -66,14 +68,14 @@ void update_searchEngine(guint index, GtkWidget* search)
// Reset in case the index is out of range // Reset in case the index is out of range
if(index >= n) if(index >= n)
index = 0; index = 0;
SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, index); MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data (searchEngines, index);
GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine) GdkPixbuf* pixbuf = load_web_icon (midori_web_item_get_icon (web_item),
, GTK_ICON_SIZE_MENU, search); GTK_ICON_SIZE_MENU, search);
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search) sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search)
, SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf))); , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf)));
g_object_unref(pixbuf); g_object_unref(pixbuf);
sokoke_entry_set_default_text(GTK_ENTRY(search) sokoke_entry_set_default_text (GTK_ENTRY (search),
, search_engine_get_short_name(engine)); midori_web_item_get_name (web_item));
// config->searchEngine = index; // config->searchEngine = index;
} }
} }
@ -95,11 +97,11 @@ void on_webSearch_icon_released(GtkWidget* widget, SexyIconEntryPosition* pos
guint i; guint i;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, i); MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data (searchEngines, i);
menuitem = gtk_image_menu_item_new_with_label( menuitem = gtk_image_menu_item_new_with_label (
search_engine_get_short_name(engine)); midori_web_item_get_name (web_item));
GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine) GdkPixbuf* pixbuf = load_web_icon (midori_web_item_get_icon (web_item),
, GTK_ICON_SIZE_MENU, menuitem); GTK_ICON_SIZE_MENU, menuitem);
GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), icon); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), icon);
g_object_unref(pixbuf); g_object_unref(pixbuf);
@ -134,12 +136,12 @@ static void on_webSearch_engines_render_icon(GtkTreeViewColumn* column
, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter , GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter
, GtkWidget* treeview) , GtkWidget* treeview)
{ {
SearchEngine* searchEngine; MidoriWebItem* web_item;
gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &searchEngine, -1); gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &web_item, -1);
// TODO: Would it be better to not do this on every redraw? // TODO: Would it be better to not do this on every redraw?
const gchar* icon = search_engine_get_icon(searchEngine); const gchar* icon = midori_web_item_get_icon (web_item);
if(icon) if (icon)
{ {
GdkPixbuf* pixbuf = load_web_icon(icon, GTK_ICON_SIZE_DND, treeview); GdkPixbuf* pixbuf = load_web_icon(icon, GTK_ICON_SIZE_DND, treeview);
g_object_set(renderer, "pixbuf", pixbuf, NULL); g_object_set(renderer, "pixbuf", pixbuf, NULL);
@ -154,10 +156,10 @@ static void on_webSearch_engines_render_text(GtkTreeViewColumn* column
, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter , GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter
, GtkWidget* treeview) , GtkWidget* treeview)
{ {
SearchEngine* searchEngine; MidoriWebItem* web_item;
gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &searchEngine, -1); gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &web_item, -1);
const gchar* name = search_engine_get_short_name(searchEngine); const gchar* name = midori_web_item_get_name (web_item);
const gchar* description = search_engine_get_description(searchEngine); const gchar* description = midori_web_item_get_description (web_item);
gchar* markup = g_markup_printf_escaped("<b>%s</b>\n%s", name, description); gchar* markup = g_markup_printf_escaped("<b>%s</b>\n%s", name, description);
g_object_set(renderer, "markup", markup, NULL); g_object_set(renderer, "markup", markup, NULL);
g_free(markup); g_free(markup);
@ -196,12 +198,12 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 5); gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 5);
GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
SearchEngine* searchEngine; MidoriWebItem* web_item;
GtkTreeModel* liststore; GtkTreeModel* liststore;
GtkTreeIter iter; GtkTreeIter iter;
if(newEngine) if(newEngine)
{ {
searchEngine = search_engine_new(); web_item = midori_web_item_new ();
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog) gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog)
, GTK_RESPONSE_ACCEPT, FALSE); , GTK_RESPONSE_ACCEPT, FALSE);
} }
@ -209,7 +211,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
{ {
GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(webSearch->treeview)); GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(webSearch->treeview));
gtk_tree_selection_get_selected(selection, &liststore, &iter); gtk_tree_selection_get_selected(selection, &liststore, &iter);
gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &searchEngine, -1); gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &web_item, -1);
} }
GtkWidget* hbox = gtk_hbox_new(FALSE, 8); GtkWidget* hbox = gtk_hbox_new(FALSE, 8);
@ -223,7 +225,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_entry_set_activates_default(GTK_ENTRY(entry_shortName), TRUE); gtk_entry_set_activates_default(GTK_ENTRY(entry_shortName), TRUE);
if(!newEngine) if(!newEngine)
gtk_entry_set_text(GTK_ENTRY(entry_shortName) gtk_entry_set_text(GTK_ENTRY(entry_shortName)
, search_engine_get_short_name(searchEngine)); , STR_NON_NULL (midori_web_item_get_name (web_item)));
gtk_box_pack_start(GTK_BOX(hbox), entry_shortName, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry_shortName, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
gtk_widget_show_all(hbox); gtk_widget_show_all(hbox);
@ -237,7 +239,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_entry_set_activates_default(GTK_ENTRY(entry_description), TRUE); gtk_entry_set_activates_default(GTK_ENTRY(entry_description), TRUE);
if(!newEngine) if(!newEngine)
gtk_entry_set_text(GTK_ENTRY(entry_description) gtk_entry_set_text(GTK_ENTRY(entry_description)
, STR_NON_NULL(search_engine_get_description(searchEngine))); , STR_NON_NULL (midori_web_item_get_description (web_item)));
gtk_box_pack_start(GTK_BOX(hbox), entry_description, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry_description, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
gtk_widget_show_all(hbox); gtk_widget_show_all(hbox);
@ -251,7 +253,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_entry_set_activates_default(GTK_ENTRY(entry_url), TRUE); gtk_entry_set_activates_default(GTK_ENTRY(entry_url), TRUE);
if(!newEngine) if(!newEngine)
gtk_entry_set_text(GTK_ENTRY(entry_url) gtk_entry_set_text(GTK_ENTRY(entry_url)
, STR_NON_NULL(search_engine_get_url(searchEngine))); , STR_NON_NULL (midori_web_item_get_uri (web_item)));
gtk_box_pack_start(GTK_BOX(hbox), entry_url, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry_url, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
gtk_widget_show_all(hbox); gtk_widget_show_all(hbox);
@ -265,7 +267,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_entry_set_activates_default(GTK_ENTRY(entry_icon), TRUE); gtk_entry_set_activates_default(GTK_ENTRY(entry_icon), TRUE);
if(!newEngine) if(!newEngine)
gtk_entry_set_text(GTK_ENTRY(entry_icon) gtk_entry_set_text(GTK_ENTRY(entry_icon)
, STR_NON_NULL(search_engine_get_icon(searchEngine))); , STR_NON_NULL (midori_web_item_get_icon (web_item)));
gtk_box_pack_start(GTK_BOX(hbox), entry_icon, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry_icon, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
gtk_widget_show_all(hbox); gtk_widget_show_all(hbox);
@ -279,7 +281,7 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_entry_set_activates_default(GTK_ENTRY(entry_keyword), TRUE); gtk_entry_set_activates_default(GTK_ENTRY(entry_keyword), TRUE);
if(!newEngine) if(!newEngine)
gtk_entry_set_text(GTK_ENTRY(entry_keyword) gtk_entry_set_text(GTK_ENTRY(entry_keyword)
, STR_NON_NULL(search_engine_get_keyword(searchEngine))); , STR_NON_NULL(midori_web_item_get_token (web_item)));
gtk_box_pack_start(GTK_BOX(hbox), entry_keyword, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry_keyword, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
gtk_widget_show_all(hbox); gtk_widget_show_all(hbox);
@ -287,27 +289,27 @@ static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webS
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{ {
search_engine_set_short_name(searchEngine midori_web_item_set_name (web_item
, gtk_entry_get_text(GTK_ENTRY(entry_shortName))); , gtk_entry_get_text(GTK_ENTRY(entry_shortName)));
search_engine_set_description(searchEngine midori_web_item_set_description (web_item
, gtk_entry_get_text(GTK_ENTRY(entry_description))); , gtk_entry_get_text(GTK_ENTRY(entry_description)));
search_engine_set_url(searchEngine midori_web_item_set_uri (web_item
, gtk_entry_get_text(GTK_ENTRY(entry_url))); , gtk_entry_get_text(GTK_ENTRY(entry_url)));
/*search_engine_set_input_encoding(searchEngine /*search_engine_set_input_encoding(searchEngine
, gtk_entry_get_text(GTK_ENTRY(entry_inputEncoding)));*/ , gtk_entry_get_text(GTK_ENTRY(entry_inputEncoding)));*/
search_engine_set_icon(searchEngine midori_web_item_set_icon (web_item
, gtk_entry_get_text(GTK_ENTRY(entry_icon))); , gtk_entry_get_text(GTK_ENTRY(entry_icon)));
search_engine_set_keyword(searchEngine midori_web_item_set_token (web_item
, gtk_entry_get_text(GTK_ENTRY(entry_keyword))); , gtk_entry_get_text(GTK_ENTRY(entry_keyword)));
if(newEngine) if(newEngine)
{ {
searchEngines = g_list_append(searchEngines, searchEngine); searchEngines = g_list_append(searchEngines, web_item);
liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(webSearch->treeview)); liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(webSearch->treeview));
gtk_list_store_append(GTK_LIST_STORE(liststore), &iter); gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
} }
gtk_list_store_set(GTK_LIST_STORE(liststore), &iter gtk_list_store_set(GTK_LIST_STORE(liststore), &iter
, ENGINES_COL_ENGINE, searchEngine, -1); , ENGINES_COL_ENGINE, web_item, -1);
webSearch_toggle_edit_buttons(TRUE, webSearch); webSearch_toggle_edit_buttons(TRUE, webSearch);
} }
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
@ -329,11 +331,11 @@ static void on_webSearch_remove(GtkWidget* widget, CWebSearch* webSearch)
GtkTreeModel* liststore; GtkTreeModel* liststore;
GtkTreeIter iter; GtkTreeIter iter;
gtk_tree_selection_get_selected(selection, &liststore, &iter); gtk_tree_selection_get_selected(selection, &liststore, &iter);
SearchEngine* searchEngine; MidoriWebItem* web_item;
gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &searchEngine, -1); gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &web_item, -1);
gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter); gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter);
search_engine_free(searchEngine); g_object_unref (web_item);
searchEngines = g_list_remove(searchEngines, searchEngine); searchEngines = g_list_remove (searchEngines, web_item);
//update_searchEngine(config->searchEngine, webSearch->browser); //update_searchEngine(config->searchEngine, webSearch->browser);
webSearch_toggle_edit_buttons(g_list_nth(searchEngines, 0) != NULL, webSearch); webSearch_toggle_edit_buttons(g_list_nth(searchEngines, 0) != NULL, webSearch);
// FIXME: we want to allow undo of some kind // FIXME: we want to allow undo of some kind
@ -370,7 +372,7 @@ GtkWidget* webSearch_manageSearchEngines_dialog_new(MidoriBrowser* browser)
GtkTreeViewColumn* column; GtkTreeViewColumn* column;
GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_pixbuf; GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_pixbuf;
GtkListStore* liststore = gtk_list_store_new(ENGINES_COL_N GtkListStore* liststore = gtk_list_store_new(ENGINES_COL_N
, G_TYPE_SEARCH_ENGINE); , MIDORI_TYPE_WEB_ITEM);
GtkWidget* treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); GtkWidget* treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
column = gtk_tree_view_column_new(); column = gtk_tree_view_column_new();
@ -393,9 +395,9 @@ GtkWidget* webSearch_manageSearchEngines_dialog_new(MidoriBrowser* browser)
guint i; guint i;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
SearchEngine* searchEngine = (SearchEngine*)g_list_nth_data(searchEngines, i); MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data (searchEngines, i);
gtk_list_store_insert_with_values(GTK_LIST_STORE(liststore), NULL, i gtk_list_store_insert_with_values(GTK_LIST_STORE(liststore), NULL, i
, ENGINES_COL_ENGINE, searchEngine, -1); , ENGINES_COL_ENGINE, web_item, -1);
} }
g_object_unref(liststore); g_object_unref(liststore);
CWebSearch* webSearch = g_new0(CWebSearch, 1); CWebSearch* webSearch = g_new0(CWebSearch, 1);
@ -459,10 +461,10 @@ gboolean on_webSearch_scroll(GtkWidget* webView, GdkEventScroll* event, MidoriBr
void on_webSearch_activate(GtkWidget* widget, MidoriBrowser* browser) void on_webSearch_activate(GtkWidget* widget, MidoriBrowser* browser)
{ {
const gchar* keywords = gtk_entry_get_text(GTK_ENTRY(widget)); const gchar* keywords = gtk_entry_get_text(GTK_ENTRY(widget));
gchar* url; const gchar* url;
SearchEngine* searchEngine = (SearchEngine*)g_list_nth_data(searchEngines, 0/*config->searchEngine*/); MidoriWebItem* web_item = (MidoriWebItem*)g_list_nth_data (searchEngines, 0/*config->searchEngine*/);
if(searchEngine) if (web_item)
url = searchEngine->url; url = midori_web_item_get_uri (web_item);
else // The location search is our fallback else // The location search is our fallback
url = "";//config->locationSearch; url = "";//config->locationSearch;
gchar* search; gchar* search;