Rework MidoriWebList into KatzeList and KatzeArray

This commit is contained in:
Christian Dywan 2008-08-26 01:19:38 +02:00
parent 45e4db6c86
commit bf28e1097b
21 changed files with 821 additions and 485 deletions

View file

@ -15,5 +15,6 @@ libkatze_la_SOURCES = \
katze-throbber.c katze-throbber.h \ katze-throbber.c katze-throbber.h \
katze-utils.c katze-utils.h \ katze-utils.c katze-utils.h \
katze-item.c katze-item.h \ katze-item.c katze-item.h \
katze-weblist.c katze-weblist.h \ katze-list.c katze-list.h \
katze-array.c katze-array.h \
katze-xbel.c katze-xbel.h katze-xbel.c katze-xbel.h

305
katze/katze-array.c Normal file
View file

@ -0,0 +1,305 @@
/*
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 "katze-array.h"
#include "katze-utils.h"
#include <glib/gi18n.h>
#include <string.h>
/**
* SECTION:katze-array
* @short_description: A type aware item container
* @see_also: #KatzeArray
*
* #KatzeArray is a type aware container for items.
*/
struct _KatzeArray
{
KatzeList parent_instance;
GType type;
};
struct _KatzeArrayClass
{
KatzeListClass parent_class;
};
G_DEFINE_TYPE (KatzeArray, katze_array, KATZE_TYPE_LIST)
static void
katze_array_finalize (GObject* object);
static void
_katze_array_add_item (KatzeList* list,
gpointer item)
{
if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT))
g_object_ref (item);
KATZE_LIST_CLASS (katze_array_parent_class)->add_item (list, item);
}
static void
_katze_array_remove_item (KatzeList* list,
gpointer item)
{
KATZE_LIST_CLASS (katze_array_parent_class)->remove_item (list, item);
if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT))
g_object_unref (item);
}
static void
katze_array_class_init (KatzeArrayClass* class)
{
GObjectClass* gobject_class;
KatzeListClass* katzelist_class;
gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = katze_array_finalize;
katzelist_class = KATZE_LIST_CLASS (class);
katzelist_class->add_item = _katze_array_add_item;
katzelist_class->remove_item = _katze_array_remove_item;
}
static void
katze_array_init (KatzeArray* array)
{
array->type = G_TYPE_NONE;
}
static void
katze_array_finalize (GObject* object)
{
KatzeArray* array;
guint n, i;
array = KATZE_ARRAY (object);
if (katze_array_is_a (array, G_TYPE_OBJECT))
{
n = katze_list_get_length ((KatzeList*)array);
for (i = 0; i < n; i++)
g_object_unref (katze_list_get_nth_item ((KatzeList*)array, i));
}
G_OBJECT_CLASS (katze_array_parent_class)->finalize (object);
}
/**
* katze_array_new:
* @type: the expected item type
*
* Creates a new #KatzeArray for @type items.
*
* You may only add items of the given type or inherited
* from it to this array.
*
* The array will keep a reference on each object until
* it is removed from the array.
*
* Note: While you *can* (currently) use #KatzeList accessors
* to circumvent type safety, you are *encouraged* to use
* only #KatzeArray accessors, or behaviour is undefined.
*
* Return value: a new #KatzeArray
**/
KatzeArray*
katze_array_new (GType type)
{
KatzeArray* array = g_object_new (KATZE_TYPE_ARRAY, NULL);
array->type = type;
return array;
}
/**
*
* katze_array_is_a:
* @array: a #KatzeArray
* @is_a_type: type to compare with
*
* Checks whether the array is compatible
* with items of the specified type.
*
* Retur value: %TRUE if @array is compatible with @is_a_type
**/
gboolean
katze_array_is_a (KatzeArray* array,
GType is_a_type)
{
g_return_val_if_fail (KATZE_IS_ARRAY (array), FALSE);
return g_type_is_a (array->type, is_a_type);
}
/**
* katze_array_add_item:
* @array: a #KatzeArray
* @item: a #GObject
*
* Adds an item to the array.
**/
void
katze_array_add_item (KatzeArray* array,
gpointer item)
{
g_return_if_fail (KATZE_IS_ARRAY (array));
if (katze_array_is_a (array, G_TYPE_OBJECT))
g_return_if_fail (katze_array_is_a (array, G_OBJECT_TYPE (item)));
g_signal_emit_by_name (array, "add-item", item);
}
/**
* katze_array_add_item:
* @array: a #KatzeArray
* @item: a #GObject
*
* Removes an item from the array.
**/
void
katze_array_remove_item (KatzeArray* array,
gpointer item)
{
g_return_if_fail (KATZE_IS_ARRAY (array));
if (katze_array_is_a (array, G_TYPE_OBJECT))
g_return_if_fail (katze_array_is_a (array, G_OBJECT_TYPE (item)));
g_signal_emit_by_name (array, "remove-item", item);
}
/**
* katze_array_get_nth_item:
* @array: a #KatzeArray
* @n: an index in the array
*
* Retrieves the item in @array at the position @n.
*
* Return value: an item, or %NULL
**/
gpointer
katze_array_get_nth_item (KatzeArray* array,
guint n)
{
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
return katze_list_get_nth_item (KATZE_LIST (array), n);
}
/**
* katze_array_is_empty:
* @array: a #KatzeArray
*
* Determines if @array is empty.
*
* Return value: an item, or %NULL
**/
gboolean
katze_array_is_empty (KatzeArray* array)
{
g_return_val_if_fail (KATZE_IS_ARRAY (array), TRUE);
return katze_list_is_empty (KATZE_LIST (array));
}
/**
* katze_array_get_item_position:
* @array: a #KatzeArray
* @item: an item in the array
*
* Retrieves the index of the item in @array.
*
* Return value: an item, or -1
**/
gint
katze_array_get_item_index (KatzeArray* array,
gpointer item)
{
g_return_val_if_fail (KATZE_IS_ARRAY (array), -1);
if (katze_array_is_a (array, G_TYPE_OBJECT))
g_return_val_if_fail (katze_array_is_a (array, G_OBJECT_TYPE (item)), -1);
return katze_list_get_item_index (KATZE_LIST (array), item);
}
/**
* katze_array_find_token:
* @array: a #KatzeArray
* @token: a token string
*
* Looks up an item in the array which has the specified token.
*
* This function will silently fail if the type of the list
* is not based on #GObject and only #KatzeItem children
* are checked for their token, any other objects are skipped.
*
* Note that @token is by definition unique to one item.
*
* Return value: an item, or %NULL
**/
gpointer
katze_array_find_token (KatzeArray* array,
const gchar* token)
{
guint n, i;
gpointer item;
const gchar* found_token;
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
if (!katze_array_is_a (array, G_TYPE_OBJECT))
return NULL;
n = katze_list_get_length ((KatzeList*)array);
for (i = 0; i < n; i++)
{
item = katze_list_get_nth_item ((KatzeList*)array, i);
if (!g_type_is_a (G_OBJECT_TYPE (item), KATZE_TYPE_ITEM))
continue;
found_token = katze_item_get_token ((KatzeItem*)item);
if (found_token && !strcmp (found_token, token))
return item;
}
return NULL;
}
/**
* katze_array_get_length:
* @array: a #KatzeArray
*
* Retrieves the number of items in @array.
*
* Return value: the length of the list
**/
guint
katze_array_get_length (KatzeArray* array)
{
g_return_val_if_fail (KATZE_IS_ARRAY (array), 0);
return katze_list_get_length (KATZE_LIST (array));
}
/**
* katze_array_clear:
* @array: a #KatzeArray
*
* Deletes all items currently contained in @array.
**/
void
katze_array_clear (KatzeArray* array)
{
g_return_if_fail (KATZE_IS_ARRAY (array));
katze_list_clear (KATZE_LIST (array));
}

76
katze/katze-array.h Normal file
View file

@ -0,0 +1,76 @@
/*
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 __KATZE_ARRAY_H__
#define __KATZE_ARRAY_H__
#include "katze-list.h"
G_BEGIN_DECLS
#define KATZE_TYPE_ARRAY \
(katze_array_get_type ())
#define KATZE_ARRAY(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_ARRAY, KatzeArray))
#define KATZE_ARRAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_ARRAY, KatzeArrayClass))
#define KATZE_IS_ARRAY(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_ARRAY))
#define KATZE_IS_ARRAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_ARRAY))
#define KATZE_ARRAY_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_ARRAY, KatzeArrayClass))
typedef struct _KatzeArray KatzeArray;
typedef struct _KatzeArrayClass KatzeArrayClass;
GType
katze_array_get_type (void);
KatzeArray*
katze_array_new (GType type);
gboolean
katze_array_is_a (KatzeArray* array,
GType is_a_type);
void
katze_array_add_item (KatzeArray* array,
gpointer item);
void
katze_array_remove_item (KatzeArray* array,
gpointer item);
gpointer
katze_array_get_nth_item (KatzeArray* array,
guint n);
gboolean
katze_array_is_empty (KatzeArray* array);
gint
katze_array_get_item_index (KatzeArray* array,
gpointer item);
gpointer
katze_array_find_token (KatzeArray* array,
const gchar* token);
guint
katze_array_get_length (KatzeArray* array);
void
katze_array_clear (KatzeArray* array);
G_END_DECLS
#endif /* __KATZE_ARRAY_H__ */

View file

@ -18,7 +18,7 @@
/** /**
* SECTION:katze-item * SECTION:katze-item
* @short_description: A useful item * @short_description: A useful item
* @see_also: #MidoriWebList * @see_also: #KatzeArray
* *
* #KatzeItem is a particularly useful item that provides * #KatzeItem is a particularly useful item that provides
* several commonly needed properties. * several commonly needed properties.

View file

@ -9,8 +9,8 @@
See the file COPYING for the full license text. See the file COPYING for the full license text.
*/ */
#ifndef __MIDORI_WEB_ITEM_H__ #ifndef __KATZE_ITEM_H__
#define __MIDORI_WEB_ITEM_H__ #define __KATZE_ITEM_H__
#include <glib-object.h> #include <glib-object.h>

244
katze/katze-list.c Normal file
View file

@ -0,0 +1,244 @@
/*
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 "katze-list.h"
#include "katze-utils.h"
#include <glib/gi18n.h>
#include <string.h>
/**
* SECTION:katze-list
* @short_description: A verbose and versatile item container
* @see_also: #KatzeItem
*
* #KatzeList is a verbose and versatile container for items.
*/
G_DEFINE_TYPE (KatzeList, katze_list, KATZE_TYPE_ITEM)
enum {
ADD_ITEM,
REMOVE_ITEM,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
katze_list_finalize (GObject* object);
static void
_katze_list_add_item (KatzeList* list,
gpointer item)
{
list->items = g_list_append (list->items, item);
}
static void
_katze_list_remove_item (KatzeList* list,
gpointer item)
{
list->items = g_list_remove (list->items, item);
}
static void
katze_list_class_init (KatzeListClass* class)
{
GObjectClass* gobject_class;
signals[ADD_ITEM] = g_signal_new (
"add-item",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (KatzeListClass, add_item),
0,
NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[REMOVE_ITEM] = g_signal_new (
"remove-item",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (KatzeListClass, remove_item),
0,
NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = katze_list_finalize;
class->add_item = _katze_list_add_item;
class->remove_item = _katze_list_remove_item;
}
static void
katze_list_init (KatzeList* list)
{
list->items = NULL;
}
static void
katze_list_finalize (GObject* object)
{
KatzeList* list;
list = KATZE_LIST (object);
g_list_free (list->items);
G_OBJECT_CLASS (katze_list_parent_class)->finalize (object);
}
/**
* katze_list_new:
*
* Creates a new #KatzeList.
*
* Return value: a new #KatzeList
**/
KatzeList*
katze_list_new (void)
{
KatzeList* list = g_object_new (KATZE_TYPE_LIST, NULL);
return list;
}
/**
* katze_list_add_item:
* @list: a #KatzeList
* @item: a #GObject
*
* Adds an item to the list.
**/
void
katze_list_add_item (KatzeList* list,
gpointer item)
{
g_return_if_fail (KATZE_IS_LIST (list));
g_signal_emit (list, signals[ADD_ITEM], 0, item);
}
/**
* katze_list_add_item:
* @list: a #KatzeList
* @item: a #GObject
*
* Removes an item from the list.
**/
void
katze_list_remove_item (KatzeList* list,
gpointer item)
{
g_return_if_fail (KATZE_IS_LIST (list));
g_signal_emit (list, signals[REMOVE_ITEM], 0, item);
}
/**
* katze_list_get_nth_item:
* @list: a #KatzeList
* @n: an index in the list
*
* Retrieves the item in @list at the position @n.
*
* Return value: an item, or %NULL
**/
gpointer
katze_list_get_nth_item (KatzeList* list,
guint n)
{
g_return_val_if_fail (KATZE_IS_LIST (list), NULL);
return g_list_nth_data (list->items, n);
}
/**
* katze_list_is_empty:
* @list: a #KatzeList
*
* Determines if @list is empty.
*
* Return value: an item, or %NULL
**/
gboolean
katze_list_is_empty (KatzeList* list)
{
g_return_val_if_fail (KATZE_IS_LIST (list), TRUE);
return !g_list_nth_data (list->items, 0);
}
/**
* katze_list_get_item_position:
* @list: a #KatzeList
* @item: an item in the list
*
* Retrieves the index of the item in @list.
*
* Return value: an item, or -1
**/
gint
katze_list_get_item_index (KatzeList* list,
gpointer item)
{
g_return_val_if_fail (KATZE_IS_LIST (list), -1);
return g_list_index (list->items, item);
}
/**
* katze_list_get_length:
* @list: a #KatzeList
*
* Retrieves the number of items in @list.
*
* Return value: the length of the list
**/
guint
katze_list_get_length (KatzeList* list)
{
g_return_val_if_fail (KATZE_IS_LIST (list), 0);
return g_list_length (list->items);
}
/**
* katze_list_clear:
* @list: a #KatzeList
*
* Deletes all items currently contained in @list.
**/
void
katze_list_clear (KatzeList* list)
{
guint n;
guint i;
GObject* item;
g_return_if_fail (KATZE_IS_LIST (list));
n = g_list_length (list->items);
for (i = 0; i < n; i++)
{
if ((item = g_list_nth_data (list->items, i)))
katze_list_remove_item (list, item);
}
g_list_free (list->items);
list->items = NULL;
}

88
katze/katze-list.h Normal file
View file

@ -0,0 +1,88 @@
/*
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 __KATZE_LIST_H__
#define __KATZE_LIST_H__
#include "katze-item.h"
G_BEGIN_DECLS
#define KATZE_TYPE_LIST \
(katze_list_get_type ())
#define KATZE_LIST(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_LIST, KatzeList))
#define KATZE_LIST_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_LIST, KatzeListClass))
#define KATZE_IS_LIST(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_LIST))
#define KATZE_IS_LIST_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_LIST))
#define KATZE_LIST_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_LIST, KatzeListClass))
typedef struct _KatzeList KatzeList;
typedef struct _KatzeListClass KatzeListClass;
struct _KatzeList
{
KatzeItem parent_instance;
GList* items;
};
struct _KatzeListClass
{
KatzeItemClass parent_class;
/* Signals */
void
(*add_item) (KatzeList* list,
gpointer item);
void
(*remove_item) (KatzeList* list,
gpointer item);
};
GType
katze_list_get_type (void);
KatzeList*
katze_list_new (void);
void
katze_list_add_item (KatzeList* list,
gpointer item);
void
katze_list_remove_item (KatzeList* list,
gpointer item);
gpointer
katze_list_get_nth_item (KatzeList* list,
guint n);
gboolean
katze_list_is_empty (KatzeList* list);
gint
katze_list_get_item_index (KatzeList* list,
gpointer item);
guint
katze_list_get_length (KatzeList* list);
void
katze_list_clear (KatzeList* list);
G_END_DECLS
#endif /* __KATZE_LIST_H__ */

View file

@ -1,308 +0,0 @@
/*
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 "katze-weblist.h"
#include "katze-utils.h"
#include <glib/gi18n.h>
#include <string.h>
/**
* SECTION:midori-weblist
* @short_description: A versatile object container
* @see_also: #KatzeItem
*
* #MidoriWebList is a versatile container for objects.
*/
struct _MidoriWebList
{
KatzeItem parent_instance;
GList* items;
};
struct _MidoriWebListClass
{
KatzeItemClass parent_class;
/* Signals */
void
(*add_item) (MidoriWebList* web_list,
GObject* item);
void
(*remove_item) (MidoriWebList* web_list,
GObject* item);
};
G_DEFINE_TYPE (MidoriWebList, midori_web_list, KATZE_TYPE_ITEM)
enum {
ADD_ITEM,
REMOVE_ITEM,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void
midori_web_list_finalize (GObject* object);
static void
_midori_web_list_add_item (MidoriWebList* web_list,
GObject* item)
{
g_object_ref (item);
web_list->items = g_list_append (web_list->items, item);
}
static void
_midori_web_list_remove_item (MidoriWebList* web_list,
GObject* item)
{
web_list->items = g_list_remove (web_list->items, item);
g_object_unref (item);
}
static void
midori_web_list_class_init (MidoriWebListClass* class)
{
signals[ADD_ITEM] = g_signal_new (
"add-item",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriWebListClass, add_item),
0,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[REMOVE_ITEM] = g_signal_new (
"remove-item",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriWebListClass, remove_item),
0,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
class->add_item = _midori_web_list_add_item;
class->remove_item = _midori_web_list_remove_item;
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_web_list_finalize;
}
static void
midori_web_list_init (MidoriWebList* web_list)
{
web_list->items = NULL;
}
static void
midori_web_list_finalize (GObject* object)
{
MidoriWebList* web_list = MIDORI_WEB_LIST (object);
guint n, i;
/* Scruffily remove all items, no need for signals */
n = g_list_length (web_list->items);
for (i = 0; i < n; i++)
g_object_unref (g_list_nth_data (web_list->items, i));
g_list_free (web_list->items);
G_OBJECT_CLASS (midori_web_list_parent_class)->finalize (object);
}
/**
* midori_web_list_new:
*
* Creates a new #MidoriWebList.
*
* Return value: a new #MidoriWebList
**/
MidoriWebList*
midori_web_list_new (void)
{
MidoriWebList* web_list = g_object_new (MIDORI_TYPE_WEB_LIST,
NULL);
return web_list;
}
/**
* midori_web_list_add_item:
* @web_list: a #MidoriWebList
* @item: a #GObject
*
* Adds an item to the list.
**/
void
midori_web_list_add_item (MidoriWebList* web_list,
gpointer item)
{
g_return_if_fail (MIDORI_IS_WEB_LIST (web_list));
g_return_if_fail (G_IS_OBJECT (item));
g_signal_emit (web_list, signals[ADD_ITEM], 0, item);
}
/**
* midori_web_list_add_item:
* @web_list: a #MidoriWebList
* @item: a #GObject
*
* Removes an item from the list.
**/
void
midori_web_list_remove_item (MidoriWebList* web_list,
gpointer item)
{
g_return_if_fail (MIDORI_IS_WEB_LIST (web_list));
g_return_if_fail (G_IS_OBJECT (item));
g_signal_emit (web_list, signals[REMOVE_ITEM], 0, item);
}
/**
* midori_web_list_get_nth_item:
* @web_list: a #MidoriWebList
* @n: an index in the list
*
* Retrieves the item in @web_list at the position @n.
*
* Return value: an item, or %NULL
**/
gpointer
midori_web_list_get_nth_item (MidoriWebList* web_list,
guint n)
{
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), NULL);
return g_list_nth_data (web_list->items, n);
}
/**
* midori_web_list_is_empty:
* @web_list: a #MidoriWebList
*
* Determines if @web_list is empty.
*
* Return value: an item, or %NULL
**/
gboolean
midori_web_list_is_empty (MidoriWebList* web_list)
{
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), TRUE);
return !g_list_nth_data (web_list->items, 0);
}
/**
* midori_web_list_get_item_position:
* @web_list: a #MidoriWebList
* @item: an item in the list
*
* Retrieves the index of the item in @web_list.
*
* Return value: an item, or -1
**/
gint
midori_web_list_get_item_index (MidoriWebList* web_list,
gpointer item)
{
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), -1);
g_return_val_if_fail (G_IS_OBJECT (item), -1);
return g_list_index (web_list->items, item);
}
/**
* midori_web_list_find_token:
* @web_list: a #MidoriWebList
* @token: a token string
*
* Looks up an item in the list which has the specified token.
*
* Currently only #KatzeItem is supported.
*
* Note that @token is by definition unique to one item.
*
* Return value: an item, or %NULL
**/
gpointer
midori_web_list_find_token (MidoriWebList* web_list,
const gchar* token)
{
guint n, i;
gpointer item;
const gchar* found_token;
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), NULL);
n = g_list_length (web_list->items);
for (i = 0; i < n; i++)
{
item = g_list_nth_data (web_list->items, i);
if (!KATZE_IS_ITEM (item))
continue;
found_token = katze_item_get_token ((KatzeItem*)item);
if (found_token && !strcmp (found_token, token))
return item;
}
return NULL;
}
/**
* midori_web_list_get_length:
* @web_list: a #MidoriWebList
*
* Retrieves the number of items in @web_list.
*
* Return value: the length of the list
**/
guint
midori_web_list_get_length (MidoriWebList* web_list)
{
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), 0);
return g_list_length (web_list->items);
}
/**
* midori_web_list_clear:
* @web_list: a #MidoriWebList
*
* Deletes all items currently contained in @web_list.
**/
void
midori_web_list_clear (MidoriWebList* web_list)
{
guint n;
guint i;
GObject* item;
g_return_if_fail (MIDORI_IS_WEB_LIST (web_list));
n = g_list_length (web_list->items);
for (i = 0; i < n; i++)
{
if ((item = g_list_nth_data (web_list->items, i)))
midori_web_list_remove_item (web_list, item);
}
g_list_free (web_list->items);
web_list->items = NULL;
}

View file

@ -1,72 +0,0 @@
/*
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_LIST_H__
#define __MIDORI_WEB_LIST_H__
#include "katze-item.h"
G_BEGIN_DECLS
#define MIDORI_TYPE_WEB_LIST \
(midori_web_list_get_type ())
#define MIDORI_WEB_LIST(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_WEB_LIST, MidoriWebList))
#define MIDORI_WEB_LIST_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_WEB_LIST, MidoriWebListClass))
#define MIDORI_IS_WEB_LIST(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_WEB_LIST))
#define MIDORI_IS_WEB_LIST_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_WEB_LIST))
#define MIDORI_WEB_LIST_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_WEB_LIST, MidoriWebListClass))
typedef struct _MidoriWebList MidoriWebList;
typedef struct _MidoriWebListClass MidoriWebListClass;
GType
midori_web_list_get_type (void);
MidoriWebList*
midori_web_list_new (void);
void
midori_web_list_add_item (MidoriWebList* web_list,
gpointer item);
void
midori_web_list_remove_item (MidoriWebList* web_list,
gpointer item);
gpointer
midori_web_list_get_nth_item (MidoriWebList* web_list,
guint n);
gboolean
midori_web_list_is_empty (MidoriWebList* web_list);
gint
midori_web_list_get_item_index (MidoriWebList* web_list,
gpointer item);
gpointer
midori_web_list_find_token (MidoriWebList* web_list,
const gchar* token);
guint
midori_web_list_get_length (MidoriWebList* web_list);
void
midori_web_list_clear (MidoriWebList* web_list);
G_END_DECLS
#endif /* __MIDORI_WEB_LIST_H__ */

View file

@ -9,13 +9,14 @@
See the file COPYING for the full license text. See the file COPYING for the full license text.
*/ */
#ifndef __KATZE__ #ifndef __KATZE_H__
#define __KATZE__ #define __KATZE_H__
#include "katze-throbber.h" #include "katze-throbber.h"
#include "katze-utils.h" #include "katze-utils.h"
#include "katze-item.h" #include "katze-item.h"
#include "katze-weblist.h" #include "katze-list.h"
#include "katze-array.h"
#include "katze-xbel.h" #include "katze-xbel.h"
#endif /* __KATZE_H__ */ #endif /* __KATZE_H__ */

View file

@ -257,11 +257,11 @@ settings_save_to_file (MidoriWebSettings* settings,
return saved; return saved;
} }
static MidoriWebList* static KatzeArray*
search_engines_new_from_file (const gchar* filename, search_engines_new_from_file (const gchar* filename,
GError** error) GError** error)
{ {
MidoriWebList* search_engines; KatzeArray* search_engines;
GKeyFile* key_file; GKeyFile* key_file;
gchar** engines; gchar** engines;
guint i, j, n_properties; guint i, j, n_properties;
@ -270,7 +270,7 @@ search_engines_new_from_file (const gchar* filename,
const gchar* property; const gchar* property;
gchar* value; gchar* value;
search_engines = midori_web_list_new (); search_engines = katze_array_new (KATZE_TYPE_ITEM);
key_file = g_key_file_new (); key_file = g_key_file_new ();
g_key_file_load_from_file (key_file, filename, g_key_file_load_from_file (key_file, filename,
G_KEY_FILE_KEEP_COMMENTS, error); G_KEY_FILE_KEEP_COMMENTS, error);
@ -290,7 +290,7 @@ search_engines_new_from_file (const gchar* filename,
g_object_set (item, property, value, NULL); g_object_set (item, property, value, NULL);
g_free (value); g_free (value);
} }
midori_web_list_add_item (search_engines, item); katze_array_add_item (search_engines, item);
} }
g_strfreev (engines); g_strfreev (engines);
g_key_file_free (key_file); g_key_file_free (key_file);
@ -298,7 +298,7 @@ search_engines_new_from_file (const gchar* filename,
} }
static gboolean static gboolean
search_engines_save_to_file (MidoriWebList* search_engines, search_engines_save_to_file (KatzeArray* search_engines,
const gchar* filename, const gchar* filename,
GError** error) GError** error)
{ {
@ -312,12 +312,12 @@ search_engines_save_to_file (MidoriWebList* search_engines,
gboolean saved; gboolean saved;
key_file = g_key_file_new (); key_file = g_key_file_new ();
n = midori_web_list_get_length (search_engines); n = katze_array_get_length (search_engines);
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines), pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines),
&n_properties); &n_properties);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
item = midori_web_list_get_nth_item (search_engines, i); item = katze_array_get_nth_item (search_engines, i);
name = katze_item_get_name (item); name = katze_item_get_name (item);
for (j = 0; j < n_properties; j++) for (j = 0; j < n_properties; j++)
{ {
@ -335,13 +335,16 @@ search_engines_save_to_file (MidoriWebList* search_engines,
} }
static void static void
midori_web_list_add_item_cb (MidoriWebList* trash, midori_web_list_add_item_cb (KatzeArray* trash,
GObject* item) GObject* item)
{ {
guint n = midori_web_list_get_length (trash); guint n;
GObject* obsolete_item;
n = katze_array_get_length (trash);
if (n > 10) if (n > 10)
{ {
GObject* obsolete_item = midori_web_list_get_nth_item (trash, 0); obsolete_item = katze_array_get_nth_item (trash, 0);
g_object_unref (obsolete_item); g_object_unref (obsolete_item);
} }
} }
@ -395,7 +398,7 @@ main (int argc,
}; };
MidoriStartup load_on_startup; MidoriStartup load_on_startup;
gchar* homepage; gchar* homepage;
MidoriWebList* search_engines; KatzeArray* search_engines;
#if ENABLE_NLS #if ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, MIDORI_LOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, MIDORI_LOCALEDIR);
@ -598,13 +601,13 @@ main (int argc,
stock_items_init (); stock_items_init ();
MidoriWebList* trash = midori_web_list_new (); KatzeArray* trash = katze_array_new (KATZE_TYPE_XBEL_ITEM);
guint n = katze_xbel_folder_get_n_items (xbel_trash); guint n = katze_xbel_folder_get_n_items (xbel_trash);
guint i; guint i;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (xbel_trash, i); KatzeXbelItem* item = katze_xbel_folder_get_nth_item (xbel_trash, i);
midori_web_list_add_item (trash, item); katze_array_add_item (trash, item);
} }
g_signal_connect_after (trash, "add-item", g_signal_connect_after (trash, "add-item",
G_CALLBACK (midori_web_list_add_item_cb), NULL); G_CALLBACK (midori_web_list_add_item_cb), NULL);

View file

@ -32,8 +32,8 @@ struct _MidoriApp
GtkAccelGroup* accel_group; GtkAccelGroup* accel_group;
MidoriWebSettings* settings; MidoriWebSettings* settings;
MidoriWebList* trash; KatzeArray* trash;
MidoriWebList* search_engines; KatzeArray* search_engines;
gpointer instance; gpointer instance;
}; };
@ -131,7 +131,7 @@ midori_app_class_init (MidoriAppClass* class)
"trash", "trash",
_("Trash"), _("Trash"),
_("The trash, collecting recently closed tabs and windows"), _("The trash, collecting recently closed tabs and windows"),
MIDORI_TYPE_WEB_LIST, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
@ -158,7 +158,7 @@ midori_app_class_init (MidoriAppClass* class)
"search-engines", "search-engines",
_("Search Engines"), _("Search Engines"),
_("The list of search engines"), _("The list of search engines"),
MIDORI_TYPE_WEB_LIST, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
@ -188,24 +188,20 @@ midori_browser_message_received_cb (UniqueApp* instance,
switch (command) switch (command)
{ {
case UNIQUE_ACTIVATE: case UNIQUE_ACTIVATE:
g_print("activate\n");
gtk_window_set_screen (GTK_WINDOW (app->browser), gtk_window_set_screen (GTK_WINDOW (app->browser),
unique_message_data_get_screen (message)); unique_message_data_get_screen (message));
gtk_window_present (GTK_WINDOW (app->browser)); gtk_window_present (GTK_WINDOW (app->browser));
response = UNIQUE_RESPONSE_OK; response = UNIQUE_RESPONSE_OK;
break; break;
case UNIQUE_OPEN: case UNIQUE_OPEN:
g_print("open\n");
uris = unique_message_data_get_uris (message); uris = unique_message_data_get_uris (message);
if (!uris) if (!uris)
response = UNIQUE_RESPONSE_FAIL; response = UNIQUE_RESPONSE_FAIL;
else else
{ {
g_print("open uris\n");
while (*uris) while (*uris)
{ {
midori_browser_add_uri (app->browser, *uris); midori_browser_add_uri (app->browser, *uris);
g_print ("uri: %s\n", *uris);
uris++; uris++;
} }
/* g_strfreev (uris); */ /* g_strfreev (uris); */
@ -213,7 +209,6 @@ midori_browser_message_received_cb (UniqueApp* instance,
} }
break; break;
default: default:
g_print("fail\n");
response = UNIQUE_RESPONSE_FAIL; response = UNIQUE_RESPONSE_FAIL;
break; break;
} }
@ -238,8 +233,8 @@ midori_app_init (MidoriApp* app)
app->accel_group = gtk_accel_group_new (); app->accel_group = gtk_accel_group_new ();
app->settings = midori_web_settings_new (); app->settings = midori_web_settings_new ();
app->trash = midori_web_list_new (); app->trash = katze_array_new (KATZE_TYPE_XBEL_ITEM);
app->search_engines = midori_web_list_new (); app->search_engines = katze_array_new (KATZE_TYPE_ITEM);
#if HAVE_UNIQUE #if HAVE_UNIQUE
display_name = g_strdup (gdk_display_get_name (gdk_display_get_default ())); display_name = g_strdup (gdk_display_get_name (gdk_display_get_default ()));
@ -572,7 +567,7 @@ midori_app_set_settings (MidoriApp* app,
* *
* Return value: the assigned #MidoriTrash * Return value: the assigned #MidoriTrash
**/ **/
MidoriWebList* KatzeArray*
midori_app_get_trash (MidoriApp* app) midori_app_get_trash (MidoriApp* app)
{ {
g_return_val_if_fail (MIDORI_IS_APP (app), NULL); g_return_val_if_fail (MIDORI_IS_APP (app), NULL);

View file

@ -74,7 +74,7 @@ void
midori_app_set_settings (MidoriApp* app, midori_app_set_settings (MidoriApp* app,
MidoriWebSettings* settings); MidoriWebSettings* settings);
MidoriWebList* KatzeArray*
midori_app_get_trash (MidoriApp* app); midori_app_get_trash (MidoriApp* app);
void void

View file

@ -78,8 +78,8 @@ struct _MidoriBrowser
GList* close_buttons; GList* close_buttons;
KatzeXbelItem* proxy_xbel_folder; KatzeXbelItem* proxy_xbel_folder;
MidoriWebList* trash; KatzeArray* trash;
MidoriWebList* search_engines; KatzeArray* search_engines;
}; };
G_DEFINE_TYPE (MidoriBrowser, midori_browser, GTK_TYPE_WINDOW) G_DEFINE_TYPE (MidoriBrowser, midori_browser, GTK_TYPE_WINDOW)
@ -216,6 +216,7 @@ static void
_midori_browser_update_actions (MidoriBrowser* browser) _midori_browser_update_actions (MidoriBrowser* browser)
{ {
guint n; guint n;
gboolean trash_empty;
n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook)); n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), n > 1); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), n > 1);
@ -225,7 +226,7 @@ _midori_browser_update_actions (MidoriBrowser* browser)
if (browser->trash) if (browser->trash)
{ {
gboolean trash_empty = midori_web_list_is_empty (browser->trash); trash_empty = katze_array_is_empty (browser->trash);
_action_set_sensitive (browser, "UndoTabClose", !trash_empty); _action_set_sensitive (browser, "UndoTabClose", !trash_empty);
_action_set_sensitive (browser, "Trash", !trash_empty); _action_set_sensitive (browser, "Trash", !trash_empty);
} }
@ -790,7 +791,7 @@ midori_browser_tab_destroy_cb (GtkWidget* widget,
MIDORI_WEB_VIEW (widget)); MIDORI_WEB_VIEW (widget));
uri = katze_xbel_bookmark_get_href (xbel_item); uri = katze_xbel_bookmark_get_href (xbel_item);
if (browser->trash && uri && *uri) if (browser->trash && uri && *uri)
midori_web_list_add_item (browser->trash, xbel_item); katze_array_add_item (browser->trash, xbel_item);
katze_xbel_folder_remove_item (browser->proxy_xbel_folder, xbel_item); katze_xbel_folder_remove_item (browser->proxy_xbel_folder, xbel_item);
katze_xbel_item_unref (xbel_item); katze_xbel_item_unref (xbel_item);
} }
@ -1318,7 +1319,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
"trash", "trash",
_("Trash"), _("Trash"),
_("The trash, collecting recently closed tabs and windows"), _("The trash, collecting recently closed tabs and windows"),
MIDORI_TYPE_WEB_LIST, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/** /**
@ -1332,7 +1333,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
"search-engines", "search-engines",
_("Search Engines"), _("Search Engines"),
_("The list of search engines to be used for web search"), _("The list of search engines to be used for web search"),
MIDORI_TYPE_WEB_LIST, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
} }
@ -1685,7 +1686,7 @@ midori_browser_menu_trash_item_activate_cb (GtkWidget* menuitem,
"KatzeXbelItem"); "KatzeXbelItem");
gint n = midori_browser_add_xbel_item (browser, item); gint n = midori_browser_add_xbel_item (browser, item);
midori_browser_set_current_page (browser, n); midori_browser_set_current_page (browser, n);
midori_web_list_remove_item (browser->trash, item); katze_array_remove_item (browser->trash, item);
_midori_browser_update_actions (browser); _midori_browser_update_actions (browser);
} }
@ -1694,12 +1695,12 @@ midori_browser_menu_trash_activate_cb (GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* menu = gtk_menu_new (); GtkWidget* menu = gtk_menu_new ();
guint n = midori_web_list_get_length (browser->trash); guint n = katze_array_get_length (browser->trash);
GtkWidget* menuitem; GtkWidget* menuitem;
guint i; guint i;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
KatzeXbelItem* item = midori_web_list_get_nth_item (browser->trash, i); KatzeXbelItem* item = katze_array_get_nth_item (browser->trash, i);
const gchar* title = katze_xbel_item_get_title (item); const gchar* title = katze_xbel_item_get_title (item);
const gchar* uri = katze_xbel_bookmark_get_href (item); const gchar* uri = katze_xbel_bookmark_get_href (item);
menuitem = gtk_image_menu_item_new_with_label (title ? title : uri); menuitem = gtk_image_menu_item_new_with_label (title ? title : uri);
@ -2048,7 +2049,7 @@ _action_location_secondary_icon_released (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
MidoriWebView* web_view; MidoriWebView* web_view;
MidoriWebList* news_feeds; KatzeArray* news_feeds;
GtkWidget* menu; GtkWidget* menu;
guint n, i; guint n, i;
GjsValue* feed; GjsValue* feed;
@ -2060,13 +2061,13 @@ _action_location_secondary_icon_released (GtkAction* action,
if (web_view) if (web_view)
{ {
news_feeds = midori_web_view_get_news_feeds (web_view); news_feeds = midori_web_view_get_news_feeds (web_view);
n = news_feeds ? midori_web_list_get_length (news_feeds) : 0; n = news_feeds ? katze_array_get_length (news_feeds) : 0;
if (n) if (n)
{ {
menu = gtk_menu_new (); menu = gtk_menu_new ();
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
if (!(feed = midori_web_list_get_nth_item (news_feeds, i))) if (!(feed = katze_array_get_nth_item (news_feeds, i)))
continue; continue;
uri = gjs_value_get_attribute_string (feed, "href"); uri = gjs_value_get_attribute_string (feed, "href");
@ -2655,11 +2656,11 @@ _action_undo_tab_close_activate (GtkAction* action,
guint n; guint n;
/* Reopen the most recent trash item */ /* Reopen the most recent trash item */
last = midori_web_list_get_length (browser->trash) - 1; last = katze_array_get_length (browser->trash) - 1;
item = midori_web_list_get_nth_item (browser->trash, last); item = katze_array_get_nth_item (browser->trash, last);
n = midori_browser_add_xbel_item (browser, item); n = midori_browser_add_xbel_item (browser, item);
midori_browser_set_current_page (browser, n); midori_browser_set_current_page (browser, n);
midori_web_list_remove_item (browser->trash, item); katze_array_remove_item (browser->trash, item);
_midori_browser_update_actions (browser); _midori_browser_update_actions (browser);
} }
@ -2667,7 +2668,7 @@ static void
_action_trash_empty_activate (GtkAction* action, _action_trash_empty_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
midori_web_list_clear (browser->trash); katze_array_clear (browser->trash);
_midori_browser_update_actions (browser); _midori_browser_update_actions (browser);
} }
@ -3099,7 +3100,7 @@ static void
midori_browser_search_activate_cb (GtkWidget* widget, midori_browser_search_activate_cb (GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
MidoriWebList* search_engines; KatzeArray* search_engines;
const gchar* keywords; const gchar* keywords;
guint last_web_search; guint last_web_search;
KatzeItem* item; KatzeItem* item;
@ -3110,7 +3111,7 @@ midori_browser_search_activate_cb (GtkWidget* widget,
search_engines = browser->search_engines; search_engines = browser->search_engines;
keywords = gtk_entry_get_text (GTK_ENTRY (widget)); keywords = gtk_entry_get_text (GTK_ENTRY (widget));
g_object_get (browser->settings, "last-web-search", &last_web_search, NULL); g_object_get (browser->settings, "last-web-search", &last_web_search, NULL);
item = midori_web_list_get_nth_item (search_engines, last_web_search); item = katze_array_get_nth_item (search_engines, last_web_search);
if (item) if (item)
{ {
location_entry_search = NULL; location_entry_search = NULL;
@ -3154,7 +3155,7 @@ midori_browser_search_notify_current_item_cb (GObject* gobject,
search_entry = MIDORI_SEARCH_ENTRY (browser->search); search_entry = MIDORI_SEARCH_ENTRY (browser->search);
item = midori_search_entry_get_current_item (search_entry); item = midori_search_entry_get_current_item (search_entry);
if (item) if (item)
index = midori_web_list_get_item_index (browser->search_engines, item); index = katze_array_get_item_index (browser->search_engines, item);
else else
index = 0; index = 0;
@ -3734,7 +3735,7 @@ _midori_browser_update_settings (MidoriBrowser* browser)
if (browser->search_engines) if (browser->search_engines)
{ {
item = midori_web_list_get_nth_item (browser->search_engines, item = katze_array_get_nth_item (browser->search_engines,
last_web_search); last_web_search);
if (item) if (item)
midori_search_entry_set_current_item ( midori_search_entry_set_current_item (
@ -3872,7 +3873,7 @@ midori_browser_set_property (GObject* object,
{ {
g_object_get (browser->settings, "last-web-search", g_object_get (browser->settings, "last-web-search",
&last_web_search, NULL); &last_web_search, NULL);
item = midori_web_list_get_nth_item (browser->search_engines, item = katze_array_get_nth_item (browser->search_engines,
last_web_search); last_web_search);
if (item) if (item)
g_object_set (browser->search, "current-item", item, NULL); g_object_set (browser->search, "current-item", item, NULL);

View file

@ -20,7 +20,7 @@ struct _MidoriSearchEntry
{ {
GtkIconEntry parent_instance; GtkIconEntry parent_instance;
MidoriWebList* search_engines; KatzeArray* search_engines;
KatzeItem* current_item; KatzeItem* current_item;
}; };
@ -64,7 +64,7 @@ midori_search_entry_class_init (MidoriSearchEntryClass* class)
"search-engines", "search-engines",
_("Search Engines"), _("Search Engines"),
_("The list of search engines"), _("The list of search engines"),
MIDORI_TYPE_WEB_LIST, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
@ -115,7 +115,7 @@ midori_search_entry_icon_released_cb (GtkWidget* widget,
gint button) gint button)
{ {
MidoriSearchEntry* search_entry; MidoriSearchEntry* search_entry;
MidoriWebList* search_engines; KatzeArray* search_engines;
GtkWidget* menu; GtkWidget* menu;
guint n, i; guint n, i;
GtkWidget* menuitem; GtkWidget* menuitem;
@ -126,12 +126,12 @@ midori_search_entry_icon_released_cb (GtkWidget* widget,
search_entry = MIDORI_SEARCH_ENTRY (widget); search_entry = MIDORI_SEARCH_ENTRY (widget);
search_engines = search_entry->search_engines; search_engines = search_entry->search_engines;
menu = gtk_menu_new (); menu = gtk_menu_new ();
n = midori_web_list_get_length (search_engines); n = katze_array_get_length (search_engines);
if (n) if (n)
{ {
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
item = midori_web_list_get_nth_item (search_engines, i); item = katze_array_get_nth_item (search_engines, i);
menuitem = gtk_image_menu_item_new_with_label ( menuitem = gtk_image_menu_item_new_with_label (
katze_item_get_name (item)); katze_item_get_name (item));
pixbuf = sokoke_web_icon (katze_item_get_icon (item), pixbuf = sokoke_web_icon (katze_item_get_icon (item),
@ -175,9 +175,9 @@ _midori_search_entry_move_index (MidoriSearchEntry* search_entry,
gint i; gint i;
KatzeItem* item; KatzeItem* item;
i = midori_web_list_get_item_index (search_entry->search_engines, i = katze_array_get_item_index (search_entry->search_engines,
search_entry->current_item); search_entry->current_item);
item = midori_web_list_get_nth_item (search_entry->search_engines, i + n); item = katze_array_get_nth_item (search_entry->search_engines, i + n);
if (item) if (item)
midori_search_entry_set_current_item (search_entry, item); midori_search_entry_set_current_item (search_entry, item);
} }
@ -216,7 +216,7 @@ midori_search_entry_scroll_event_cb (MidoriSearchEntry* search_entry,
} }
static void static void
midori_search_entry_engines_add_item_cb (MidoriWebList* web_list, midori_search_entry_engines_add_item_cb (KatzeArray* list,
KatzeItem* item, KatzeItem* item,
MidoriSearchEntry* search_entry) MidoriSearchEntry* search_entry)
{ {
@ -225,7 +225,7 @@ midori_search_entry_engines_add_item_cb (MidoriWebList* web_list,
} }
static void static void
midori_search_entry_engines_remove_item_cb (MidoriWebList* web_list, midori_search_entry_engines_remove_item_cb (KatzeArray* list,
KatzeItem* item, KatzeItem* item,
MidoriSearchEntry* search_entry) MidoriSearchEntry* search_entry)
{ {
@ -233,7 +233,7 @@ midori_search_entry_engines_remove_item_cb (MidoriWebList* web_list,
if (search_entry->current_item == item) if (search_entry->current_item == item)
{ {
found_item = midori_web_list_get_nth_item (web_list, 0); found_item = katze_array_get_nth_item (list, 0);
if (found_item) if (found_item)
midori_search_entry_set_current_item (search_entry, found_item); midori_search_entry_set_current_item (search_entry, found_item);
else else
@ -251,7 +251,7 @@ midori_search_entry_engines_remove_item_cb (MidoriWebList* web_list,
static void static void
midori_search_entry_init (MidoriSearchEntry* search_entry) midori_search_entry_init (MidoriSearchEntry* search_entry)
{ {
search_entry->search_engines = midori_web_list_new (); search_entry->search_engines = katze_array_new (KATZE_TYPE_ITEM);
search_entry->current_item = NULL; search_entry->current_item = NULL;
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (search_entry), gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (search_entry),
@ -357,7 +357,7 @@ midori_search_entry_new (void)
* *
* Return value: the list of search engines * Return value: the list of search engines
**/ **/
MidoriWebList* KatzeArray*
midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry) midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry)
{ {
g_return_val_if_fail (MIDORI_IS_SEARCH_ENTRY (search_entry), NULL); g_return_val_if_fail (MIDORI_IS_SEARCH_ENTRY (search_entry), NULL);
@ -374,9 +374,10 @@ midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry)
**/ **/
void void
midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry, midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry,
MidoriWebList* search_engines) KatzeArray* search_engines)
{ {
g_return_if_fail (MIDORI_IS_SEARCH_ENTRY (search_entry)); g_return_if_fail (MIDORI_IS_SEARCH_ENTRY (search_entry));
g_return_if_fail (katze_array_is_a (search_engines, KATZE_TYPE_ITEM));
g_object_ref (search_engines); g_object_ref (search_engines);
katze_object_assign (search_entry->search_engines, search_engines); katze_object_assign (search_entry->search_engines, search_engines);
@ -629,7 +630,7 @@ midori_search_entry_get_editor (GtkWidget* treeview,
search_entry = g_object_get_data (G_OBJECT (treeview), "search-entry"); search_entry = g_object_get_data (G_OBJECT (treeview), "search-entry");
if (new_engine) if (new_engine)
midori_web_list_add_item (search_entry->search_engines, item); katze_array_add_item (search_entry->search_engines, item);
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
@ -666,7 +667,7 @@ midori_search_entry_dialog_remove_cb (GtkWidget* widget,
GtkTreeModel* liststore; GtkTreeModel* liststore;
GtkTreeIter iter; GtkTreeIter iter;
KatzeItem* item; KatzeItem* item;
MidoriWebList* search_engines; KatzeArray* search_engines;
search_entry = g_object_get_data (G_OBJECT (treeview), "search-entry"); search_entry = g_object_get_data (G_OBJECT (treeview), "search-entry");
search_engines = search_entry->search_engines; search_engines = search_entry->search_engines;
@ -674,7 +675,7 @@ midori_search_entry_dialog_remove_cb (GtkWidget* widget,
if (gtk_tree_selection_get_selected (selection, &liststore, &iter)) if (gtk_tree_selection_get_selected (selection, &liststore, &iter))
{ {
gtk_tree_model_get (liststore, &iter, 0, &item, -1); gtk_tree_model_get (liststore, &iter, 0, &item, -1);
midori_web_list_remove_item (search_engines, item); katze_array_remove_item (search_engines, item);
g_object_unref (item); g_object_unref (item);
/* FIXME: we want to allow undo of some kind */ /* FIXME: we want to allow undo of some kind */
} }
@ -698,7 +699,7 @@ midori_search_entry_treeview_selection_cb (GtkTreeSelection* selection,
} }
static void static void
midori_search_entry_dialog_engines_add_item_cb (MidoriWebList* web_list, midori_search_entry_dialog_engines_add_item_cb (KatzeArray* list,
KatzeItem* item, KatzeItem* item,
GtkWidget* treeview) GtkWidget* treeview)
{ {
@ -711,7 +712,7 @@ midori_search_entry_dialog_engines_add_item_cb (MidoriWebList* web_list,
} }
static void static void
midori_search_entry_dialog_engines_remove_item_cb (MidoriWebList* web_list, midori_search_entry_dialog_engines_remove_item_cb (KatzeArray* list,
KatzeItem* item, KatzeItem* item,
GtkWidget* treeview) GtkWidget* treeview)
{ {
@ -838,10 +839,10 @@ midori_search_entry_get_dialog (MidoriSearchEntry* search_entry)
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
GTK_SHADOW_IN); GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox), scrolled, TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox), scrolled, TRUE, TRUE, 5);
n = midori_web_list_get_length (search_entry->search_engines); n = katze_array_get_length (search_entry->search_engines);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
item = midori_web_list_get_nth_item (search_entry->search_engines, i); item = katze_array_get_nth_item (search_entry->search_engines, i);
gtk_list_store_insert_with_values (GTK_LIST_STORE (liststore), gtk_list_store_insert_with_values (GTK_LIST_STORE (liststore),
NULL, i, 0, item, -1); NULL, i, 0, item, -1);
} }

View file

@ -47,12 +47,12 @@ midori_search_entry_get_type (void);
GtkWidget* GtkWidget*
midori_search_entry_new (void); midori_search_entry_new (void);
MidoriWebList* KatzeArray*
midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry); midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry);
void void
midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry, midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry,
MidoriWebList* name); KatzeArray* name);
KatzeItem* KatzeItem*
midori_search_entry_get_current_item (MidoriSearchEntry* search_entry); midori_search_entry_get_current_item (MidoriSearchEntry* search_entry);

View file

@ -42,7 +42,7 @@ struct _MidoriWebView
MidoriLoadStatus load_status; MidoriLoadStatus load_status;
gchar* statusbar_text; gchar* statusbar_text;
gchar* link_uri; gchar* link_uri;
MidoriWebList* news_feeds; KatzeArray* news_feeds;
MidoriWebSettings* settings; MidoriWebSettings* settings;
@ -487,7 +487,7 @@ gjs_value_links_foreach_cb (GjsValue* link,
|| !strcmp (type, "application/x.atom+xml") || !strcmp (type, "application/x.atom+xml")
|| !strcmp (type, "application/atom+xml")) || !strcmp (type, "application/atom+xml"))
{ {
midori_web_list_add_item (web_view->news_feeds, link); katze_array_add_item (web_view->news_feeds, link);
g_signal_emit (web_view, signals[NEWS_FEED_READY], 0, g_signal_emit (web_view, signals[NEWS_FEED_READY], 0,
gjs_value_get_attribute_string (link, "href"), type, gjs_value_get_attribute_string (link, "href"), type,
gjs_value_has_attribute (link, "title") gjs_value_has_attribute (link, "title")
@ -534,7 +534,7 @@ webkit_web_frame_load_done (WebKitWebFrame* web_frame,
value = gjs_value_new (webkit_web_frame_get_global_context (web_frame), NULL); value = gjs_value_new (webkit_web_frame_get_global_context (web_frame), NULL);
document = gjs_value_get_by_name (value, "document"); document = gjs_value_get_by_name (value, "document");
links = gjs_value_get_elements_by_tag_name (document, "link"); links = gjs_value_get_elements_by_tag_name (document, "link");
midori_web_list_clear (web_view->news_feeds); katze_array_clear (web_view->news_feeds);
gjs_value_foreach (links, (GjsCallback)gjs_value_links_foreach_cb, web_view); gjs_value_foreach (links, (GjsCallback)gjs_value_links_foreach_cb, web_view);
g_object_unref (links); g_object_unref (links);
g_object_unref (document); g_object_unref (document);
@ -760,7 +760,7 @@ midori_web_view_init (MidoriWebView* web_view)
GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
web_view->progress = 0.0; web_view->progress = 0.0;
web_view->load_status = MIDORI_LOAD_FINISHED; web_view->load_status = MIDORI_LOAD_FINISHED;
web_view->news_feeds = midori_web_list_new (); web_view->news_feeds = katze_array_new (GJS_TYPE_VALUE);
web_view->settings = midori_web_settings_new (); web_view->settings = midori_web_settings_new ();
g_object_set (web_view, "WebKitWebView::settings", web_view->settings, NULL); g_object_set (web_view, "WebKitWebView::settings", web_view->settings, NULL);
@ -1168,14 +1168,14 @@ midori_web_view_get_link_uri (MidoriWebView* web_view)
* Retrieves a list of news feeds for the current page * Retrieves a list of news feeds for the current page
* or %NULL if there are no feeds at all. * or %NULL if there are no feeds at all.
* *
* Return value: a #MidoriWebList, or %NULL * Return value: a #KatzeArray, or %NULL
**/ **/
MidoriWebList* KatzeArray*
midori_web_view_get_news_feeds (MidoriWebView* web_view) midori_web_view_get_news_feeds (MidoriWebView* web_view)
{ {
g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), NULL); g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), NULL);
if (!midori_web_list_is_empty (web_view->news_feeds)) if (!katze_array_is_empty (web_view->news_feeds))
return web_view->news_feeds; return web_view->news_feeds;
return NULL; return NULL;
} }

View file

@ -114,7 +114,7 @@ midori_web_view_get_display_title (MidoriWebView* web_view);
const gchar* const gchar*
midori_web_view_get_link_uri (MidoriWebView* web_view); midori_web_view_get_link_uri (MidoriWebView* web_view);
MidoriWebList* KatzeArray*
midori_web_view_get_news_feeds (MidoriWebView* web_view); midori_web_view_get_news_feeds (MidoriWebView* web_view);
gboolean gboolean

View file

@ -81,7 +81,7 @@ sokoke_spawn_program (const gchar* command,
gchar* gchar*
sokoke_magic_uri (const gchar* uri, sokoke_magic_uri (const gchar* uri,
MidoriWebList* search_engines) KatzeArray* search_engines)
{ {
gchar* current_dir; gchar* current_dir;
gchar* result; gchar* result;
@ -92,7 +92,7 @@ sokoke_magic_uri (const gchar* uri,
g_return_val_if_fail (uri, NULL); g_return_val_if_fail (uri, NULL);
if (search_engines) if (search_engines)
g_return_val_if_fail (MIDORI_IS_WEB_LIST (search_engines), NULL); g_return_val_if_fail (katze_array_is_a (search_engines, KATZE_TYPE_ITEM), NULL);
/* Add file:// if we have a local path */ /* Add file:// if we have a local path */
if (g_path_is_absolute (uri)) if (g_path_is_absolute (uri))
@ -122,7 +122,7 @@ sokoke_magic_uri (const gchar* uri,
parts = g_strsplit (uri, " ", 2); parts = g_strsplit (uri, " ", 2);
if (parts[0] && parts[1]) if (parts[0] && parts[1])
{ {
item = midori_web_list_find_token (search_engines, parts[0]); item = katze_array_find_token (search_engines, parts[0]);
if (item) if (item)
search_uri = katze_item_get_uri (item); search_uri = katze_item_get_uri (item);
} }

View file

@ -25,7 +25,7 @@ sokoke_spawn_program (const gchar* command,
gchar* gchar*
sokoke_magic_uri (const gchar* uri, sokoke_magic_uri (const gchar* uri,
MidoriWebList* search_engines); KatzeArray* search_engines);
void void
sokoke_entry_setup_completion (GtkEntry* entry); sokoke_entry_setup_completion (GtkEntry* entry);

View file

@ -16,5 +16,6 @@ midori/gjs.c
katze/katze-throbber.c katze/katze-throbber.c
katze/katze-utils.c katze/katze-utils.c
katze/katze-item.c katze/katze-item.c
katze/katze-weblist.c katze/katze-list.c
katze/katze-array.c
katze/katze-xbel.c katze/katze-xbel.c