Finally obsolete KatzeXbelItem

This commit is contained in:
Christian Dywan 2008-10-01 04:00:16 +02:00
parent 353533c8a7
commit fb320cc0b6
12 changed files with 493 additions and 1320 deletions

View file

@ -16,5 +16,4 @@ libkatze_la_SOURCES = \
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-list.c katze-list.h \ katze-list.c katze-list.h \
katze-array.c katze-array.h \ katze-array.c katze-array.h
katze-xbel.c katze-xbel.h

View file

@ -19,7 +19,7 @@
/** /**
* SECTION:katze-array * SECTION:katze-array
* @short_description: A type aware item container * @short_description: A type aware item container
* @see_also: #KatzeArray * @see_also: #KatzeList
* *
* #KatzeArray is a type aware container for items. * #KatzeArray is a type aware container for items.
*/ */
@ -46,7 +46,11 @@ _katze_array_add_item (KatzeList* list,
gpointer item) gpointer item)
{ {
if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT)) if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT))
{
g_object_ref (item); g_object_ref (item);
if (KATZE_IS_ITEM (item))
katze_item_set_parent (item, list);
}
KATZE_LIST_CLASS (katze_array_parent_class)->add_item (list, item); KATZE_LIST_CLASS (katze_array_parent_class)->add_item (list, item);
} }
@ -56,8 +60,12 @@ _katze_array_remove_item (KatzeList* list,
{ {
KATZE_LIST_CLASS (katze_array_parent_class)->remove_item (list, item); KATZE_LIST_CLASS (katze_array_parent_class)->remove_item (list, item);
if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT)) if (katze_array_is_a ((KatzeArray*)list, G_TYPE_OBJECT))
{
if (KATZE_IS_ITEM (item))
katze_item_set_parent (item, NULL);
g_object_unref (item); g_object_unref (item);
} }
}
static void static void
katze_array_class_init (KatzeArrayClass* class) katze_array_class_init (KatzeArrayClass* class)
@ -149,6 +157,8 @@ katze_array_is_a (KatzeArray* array,
* @item: a #GObject * @item: a #GObject
* *
* Adds an item to the array. * Adds an item to the array.
*
* If @item is a #KatzeItem its parent is set accordingly.
**/ **/
void void
katze_array_add_item (KatzeArray* array, katze_array_add_item (KatzeArray* array,
@ -167,6 +177,8 @@ katze_array_add_item (KatzeArray* array,
* @item: a #GObject * @item: a #GObject
* *
* Removes an item from the array. * Removes an item from the array.
*
* If @item is a #KatzeItem its parent is unset accordingly.
**/ **/
void void
katze_array_remove_item (KatzeArray* array, katze_array_remove_item (KatzeArray* array,

View file

@ -374,3 +374,41 @@ katze_item_set_token (KatzeItem* item,
katze_assign (item->token, g_strdup (token)); katze_assign (item->token, g_strdup (token));
g_object_notify (G_OBJECT (item), "token"); g_object_notify (G_OBJECT (item), "token");
} }
/**
* katze_item_get_parent:
* @item: a #KatzeItem
*
* Determines the parent of @item.
*
* Return value: the parent of the item
**/
gpointer
katze_item_get_parent (KatzeItem* item)
{
g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
return item->parent;
}
/**
* katze_item_set_parent:
* @item: a #KatzeItem
* @parent: the new parent
*
* Sets the parent of @item.
*
* This is intended for item container implementations and
* should not be used otherwise.
**/
void
katze_item_set_parent (KatzeItem* item,
gpointer parent)
{
g_return_if_fail (KATZE_IS_ITEM (item));
if (parent)
g_object_ref (parent);
katze_object_assign (item->parent, parent);
/* g_object_notify (G_OBJECT (item), "parent"); */
}

View file

@ -41,6 +41,8 @@ struct _KatzeItem
gchar* uri; gchar* uri;
gchar* icon; gchar* icon;
gchar* token; gchar* token;
KatzeItem* parent;
}; };
struct _KatzeItemClass struct _KatzeItemClass
@ -89,6 +91,13 @@ void
katze_item_set_token (KatzeItem* item, katze_item_set_token (KatzeItem* item,
const gchar* token); const gchar* token);
gpointer
katze_item_get_parent (KatzeItem* item);
void
katze_item_set_parent (KatzeItem* item,
gpointer parent);
G_END_DECLS G_END_DECLS
#endif /* __MIDORI_WEB_ITEM_H__ */ #endif /* __MIDORI_WEB_ITEM_H__ */

View file

@ -1,906 +0,0 @@
/*
Copyright (C) 2007-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.
*/
/**
* TODO:
* - Support info > metadata, alias, added, modified, visited
* - Compatibility: The Nokia 770 *requires* metadata and folder
* - Compatibility: Kazehakase's bookmarks
* - Compatibility: Epiphany's bookmarks
* - XML Indentation
**/
#include "katze-xbel.h"
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <glib/gi18n.h>
#include "katze-utils.h"
struct _KatzeXbelItem
{
GObject parent_instance;
guint refs;
KatzeXbelItemKind kind;
KatzeXbelItem* parent;
GList* items;
gboolean folded;
gchar* title;
gchar* desc;
gchar* href;
};
G_DEFINE_TYPE (KatzeXbelItem, katze_xbel_item, G_TYPE_OBJECT)
static void
katze_xbel_item_finalize (GObject* object);
static void
katze_xbel_item_class_init (KatzeXbelItemClass* class)
{
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = katze_xbel_item_finalize;
}
static void
katze_xbel_item_init (KatzeXbelItem* item)
{
item->parent = NULL;
}
static void
katze_xbel_item_finalize (GObject* object)
{
KatzeXbelItem* item = KATZE_XBEL_ITEM (object);
if (item->parent)
katze_xbel_folder_remove_item (item->parent, item);
if (item->kind == KATZE_XBEL_ITEM_KIND_FOLDER)
{
guint n = katze_xbel_folder_get_n_items (item);
guint i;
for (i = 0; i < n; i++)
{
KatzeXbelItem* _item = katze_xbel_folder_get_nth_item (item, i);
_item->parent = NULL;
katze_xbel_item_unref (_item);
}
g_list_free (item->items);
}
if (item->kind != KATZE_XBEL_ITEM_KIND_SEPARATOR)
{
g_free (item->title);
g_free (item->desc);
}
if (item->kind == KATZE_XBEL_ITEM_KIND_BOOKMARK)
g_free (item->href);
G_OBJECT_CLASS (katze_xbel_item_parent_class)->finalize (object);
}
/* Create a new item of a certain type */
static KatzeXbelItem*
katze_xbel_item_new (KatzeXbelItemKind kind)
{
KatzeXbelItem* item = g_object_new (KATZE_TYPE_XBEL_ITEM, NULL);
item->kind = kind;
if (kind == KATZE_XBEL_ITEM_KIND_FOLDER)
{
item->items = NULL;
item->folded = TRUE;
}
if (kind != KATZE_XBEL_ITEM_KIND_SEPARATOR)
{
item->title = NULL;
item->desc = NULL;
}
if (kind == KATZE_XBEL_ITEM_KIND_BOOKMARK)
item->href = g_strdup ("");
return item;
}
/**
* katze_xbel_bookmark_new:
*
* Create a new empty bookmark.
*
* Return value: a newly allocated bookmark
**/
KatzeXbelItem*
katze_xbel_bookmark_new (void)
{
return katze_xbel_item_new (KATZE_XBEL_ITEM_KIND_BOOKMARK);
}
static KatzeXbelItem*
katze_xbel_bookmark_from_xmlNodePtr (xmlNodePtr cur)
{
g_return_val_if_fail (cur, NULL);
KatzeXbelItem* bookmark = katze_xbel_bookmark_new ();
xmlChar* key = xmlGetProp (cur, (xmlChar*)"href");
katze_xbel_bookmark_set_href (bookmark, (gchar*)key);
cur = cur->xmlChildrenNode;
while (cur)
{
if (!xmlStrcmp (cur->name, (const xmlChar*)"title"))
{
xmlChar* key = xmlNodeGetContent (cur);
katze_xbel_item_set_title (bookmark, g_strstrip ((gchar*)key));
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"desc"))
{
xmlChar* key = xmlNodeGetContent (cur);
katze_xbel_item_set_desc (bookmark, g_strstrip ((gchar*)key));
}
cur = cur->next;
}
return bookmark;
}
/**
* katze_katze_xbel_separator_new:
*
* Create a new separator.
*
* The returned item must be freed eventually.
*
* Return value: a newly allocated separator.
**/
KatzeXbelItem*
katze_xbel_separator_new (void)
{
return katze_xbel_item_new (KATZE_XBEL_ITEM_KIND_SEPARATOR);
}
/**
* katze_xbel_folder_new:
*
* Create a new empty folder.
*
* The returned item must be freed eventually.
*
* Return value: a newly allocated folder.
**/
KatzeXbelItem*
katze_xbel_folder_new (void)
{
return katze_xbel_item_new (KATZE_XBEL_ITEM_KIND_FOLDER);
}
/* Create a folder from an xmlNodePtr */
static KatzeXbelItem*
katze_xbel_folder_from_xmlNodePtr (xmlNodePtr cur)
{
g_return_val_if_fail (cur, NULL);
KatzeXbelItem* folder = katze_xbel_folder_new ();
xmlChar* key = xmlGetProp (cur, (xmlChar*)"folded");
if (key)
{
if (!g_ascii_strncasecmp ((gchar*)key, "yes", 3))
folder->folded = TRUE;
else if (!g_ascii_strncasecmp ((gchar*)key, "no", 2))
folder->folded = FALSE;
else
g_warning ("XBEL: Unknown value for folded.");
xmlFree (key);
}
cur = cur->xmlChildrenNode;
while (cur)
{
if (!xmlStrcmp (cur->name, (const xmlChar*)"title"))
{
xmlChar* key = xmlNodeGetContent (cur);
katze_assign (folder->title, g_strstrip ((gchar*)key));
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"desc"))
{
xmlChar* key = xmlNodeGetContent (cur);
katze_assign (folder->desc, g_strstrip ((gchar*)key));
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"folder"))
{
KatzeXbelItem* item = katze_xbel_folder_from_xmlNodePtr (cur);
item->parent = folder;
folder->items = g_list_prepend (folder->items, item);
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"bookmark"))
{
KatzeXbelItem* item = katze_xbel_bookmark_from_xmlNodePtr (cur);
item->parent = folder;
folder->items = g_list_prepend (folder->items, item);
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"separator"))
{
KatzeXbelItem* item = katze_xbel_separator_new ();
item->parent = folder;
folder->items = g_list_prepend (folder->items, item);
}
cur = cur->next;
}
/* Prepending and reversing is faster than appending */
folder->items = g_list_reverse (folder->items);
return folder;
}
/* Loads the contents from an xmlNodePtr into a folder. */
static gboolean
katze_xbel_folder_from_xmlDocPtr (KatzeXbelItem* folder,
xmlDocPtr doc)
{
g_return_val_if_fail (katze_xbel_folder_is_empty (folder), FALSE);
g_return_val_if_fail (doc, FALSE);
xmlNodePtr cur = xmlDocGetRootElement (doc);
xmlChar* version = xmlGetProp (cur, (xmlChar*)"version");
if (xmlStrcmp (version, (xmlChar*)"1.0"))
g_warning ("XBEL version is not 1.0.");
xmlFree (version);
katze_assign (folder->title, (gchar*)xmlGetProp (cur, (xmlChar*)"title"));
katze_assign (folder->desc, (gchar*)xmlGetProp (cur, (xmlChar*)"desc"));
if ((cur = xmlDocGetRootElement (doc)) == NULL)
{
/* Empty document */
return FALSE;
}
if (xmlStrcmp (cur->name, (const xmlChar*)"xbel"))
{
/* Wrong document kind */
return FALSE;
}
cur = cur->xmlChildrenNode;
while (cur)
{
KatzeXbelItem* item = NULL;
if (!xmlStrcmp (cur->name, (const xmlChar*)"folder"))
item = katze_xbel_folder_from_xmlNodePtr (cur);
else if (!xmlStrcmp (cur->name, (const xmlChar*)"bookmark"))
item = katze_xbel_bookmark_from_xmlNodePtr (cur);
else if (!xmlStrcmp (cur->name, (const xmlChar*)"separator"))
item = katze_xbel_separator_new ();
/*else if (!xmlStrcmp (cur->name, (const xmlChar*)"info"))
item = katze_xbel_parse_info (xbel, cur);*/
if (item)
{
item->parent = folder;
folder->items = g_list_prepend (folder->items, item);
}
cur = cur->next;
}
/* Prepending and reversing is faster than appending */
folder->items = g_list_reverse (folder->items);
return TRUE;
}
/**
* katze_xbel_item_ref:
* @item: a valid item
*
* Ref an KatzeXbelItem.
*
* Ref means that the reference count is increased by one.
*
* This has no effect on children of a folder.
**/
void
katze_xbel_item_ref (KatzeXbelItem* item)
{
g_return_if_fail (KATZE_IS_XBEL_ITEM (item));
g_object_ref (item);
}
/**
* katze_xbel_item_unref:
* @item: a valid item
*
* Unref an KatzeXbelItem. If @item is a folder all of its children will also
* be unreffed automatically.
*
* Unref means that the reference count is decreased. If there are no
* references left, the memory will be freed and if needed removed from
* its containing folder.
**/
void
katze_xbel_item_unref (KatzeXbelItem* item)
{
g_return_if_fail (KATZE_IS_XBEL_ITEM (item));
g_object_unref (item);
}
/**
* katze_xbel_item_copy:
* @item: the item to copy
*
* Copy an KatzeXbelItem.
*
* The returned item must be unreffed eventually.
*
* Return value: a copy of @item
**/
KatzeXbelItem*
katze_xbel_item_copy (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), NULL);
KatzeXbelItem* copy = katze_xbel_item_new (item->kind);
if (katze_xbel_item_is_folder (item))
{
guint n = katze_xbel_folder_get_n_items (item);
guint i;
for (i = 0; i < n; i++)
{
KatzeXbelItem* _item = katze_xbel_folder_get_nth_item (item, i);
katze_xbel_folder_append_item (copy, katze_xbel_item_copy (_item));
}
}
if (item->kind != KATZE_XBEL_ITEM_KIND_SEPARATOR)
{
katze_xbel_item_set_title (copy, item->title);
katze_xbel_item_set_desc (copy, item->desc);
}
if (item->kind == KATZE_XBEL_ITEM_KIND_BOOKMARK)
katze_xbel_bookmark_set_href (copy, item->href);
return copy;
}
/**
* katze_xbel_folder_append_item:
* @folder: a folder
* @item: the item to append
*
* Append the given item to a folder.
*
* The item is actually moved and must not be contained in another folder.
*
**/
void
katze_xbel_folder_append_item (KatzeXbelItem* folder,
KatzeXbelItem* item)
{
g_return_if_fail (!katze_xbel_item_get_parent (item));
g_return_if_fail (katze_xbel_item_is_folder (folder));
folder->items = g_list_append (folder->items, item);
item->parent = folder;
}
/**
* katze_xbel_folder_prepend_item:
* @folder: a folder
* @item: the item to prepend
*
* Prepend the given item to a folder.
*
* The item is actually moved and must not be contained in another folder.
*
**/
void
katze_xbel_folder_prepend_item (KatzeXbelItem* folder,
KatzeXbelItem* item)
{
g_return_if_fail (!katze_xbel_item_get_parent (item));
g_return_if_fail (katze_xbel_item_is_folder (folder));
folder->items = g_list_prepend (folder->items, item);
item->parent = folder;
}
/**
* katze_xbel_folder_remove_item:
* @folder: a folder
* @item: the item to remove
*
* Remove the given @item from a @folder.
**/
void
katze_xbel_folder_remove_item (KatzeXbelItem* folder,
KatzeXbelItem* item)
{
g_return_if_fail (KATZE_IS_XBEL_ITEM (item));
g_return_if_fail (katze_xbel_item_get_parent(folder) != item);
/* Fortunately we know that items are unique */
folder->items = g_list_remove (folder->items, item);
item->parent = NULL;
}
/**
* katze_xbel_folder_get_n_items:
* @folder: a folder
*
* Retrieve the number of items contained in the given @folder.
*
* Return value: number of items
**/
guint
katze_xbel_folder_get_n_items (KatzeXbelItem* folder)
{
g_return_val_if_fail (katze_xbel_item_is_folder (folder), 0);
return g_list_length (folder->items);
}
/**
* katze_xbel_folder_get_nth_item:
* @folder: a folder
* @n: the index of an item
*
* Retrieve an item contained in the given @folder by its index.
*
* Return value: the item at the given index or %NULL
**/
KatzeXbelItem*
katze_xbel_folder_get_nth_item (KatzeXbelItem* folder,
guint n)
{
g_return_val_if_fail (katze_xbel_item_is_folder(folder), NULL);
return (KatzeXbelItem*) g_list_nth_data (folder->items, n);
}
/**
* katze_xbel_folder_is_empty:
* @folder: A folder.
*
* Determines wether or not a folder contains no items. This is significantly
* faster than katze_xbel_folder_get_n_items for this particular purpose.
*
* Return value: Wether the given @folder is folded.
**/
gboolean
katze_xbel_folder_is_empty (KatzeXbelItem* folder)
{
return !katze_xbel_folder_get_nth_item (folder, 0);
}
/**
* katze_xbel_folder_get_folded:
* @folder: A folder.
*
* Determines wether or not a folder is folded. If a folder is not folded
* it should not be exposed in a user interface.
*
* New folders are folded by default.
*
* Return value: Wether the given @folder is folded.
**/
gboolean
katze_xbel_folder_get_folded (KatzeXbelItem* folder)
{
g_return_val_if_fail (katze_xbel_item_is_folder (folder), TRUE);
return folder->folded;
}
/**
* katze_xbel_item_get_kind:
* @item: A item.
*
* Determines the kind of an item.
*
* Return value: The kind of the given @item.
**/
KatzeXbelItemKind
katze_xbel_item_get_kind (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), KATZE_XBEL_ITEM_KIND_BOOKMARK);
return item->kind;
}
/**
* katze_xbel_item_get_parent:
* @item: A valid item.
*
* Retrieves the parent folder of an item.
*
* Return value: The parent folder of the given @item or %NULL.
**/
KatzeXbelItem*
katze_xbel_item_get_parent (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), NULL);
return item->parent;
}
/**
* katze_xbel_item_get_title:
* @item: A valid item.
*
* Retrieves the title of an item.
*
* Return value: The title of the given @item or %NULL.
**/
G_CONST_RETURN gchar*
katze_xbel_item_get_title (KatzeXbelItem* item)
{
g_return_val_if_fail (!katze_xbel_item_is_separator (item), NULL);
return item->title;
}
/**
* katze_xbel_item_get_desc:
* @item: A valid item.
*
* Retrieves the description of an item.
*
* Return value: The description of the @item or %NULL.
**/
G_CONST_RETURN gchar*
katze_xbel_item_get_desc (KatzeXbelItem* item)
{
g_return_val_if_fail (!katze_xbel_item_is_separator (item), NULL);
return item->desc;
}
/**
* katze_xbel_bookmark_get_href:
* @bookmark: A bookmark.
*
* Retrieves the uri of a bookmark. The value is guaranteed to not be %NULL.
*
* Return value: The uri of the @bookmark.
**/
G_CONST_RETURN gchar*
katze_xbel_bookmark_get_href (KatzeXbelItem* bookmark)
{
g_return_val_if_fail (katze_xbel_item_is_bookmark (bookmark), NULL);
return bookmark->href;
}
/**
* katze_xbel_item_is_bookmark:
* @item: A valid item.
*
* Determines wether or not an item is a bookmark.
*
* Return value: %TRUE if the @item is a bookmark.
**/
gboolean
katze_xbel_item_is_bookmark (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), FALSE);
return item->kind == KATZE_XBEL_ITEM_KIND_BOOKMARK;
}
/**
* katze_xbel_item_is_separator:
* @item: A valid item.
*
* Determines wether or not an item is a separator.
*
* Return value: %TRUE if the @item is a separator.
**/
gboolean katze_xbel_item_is_separator (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), FALSE);
return item->kind == KATZE_XBEL_ITEM_KIND_SEPARATOR;
}
/**
* katze_xbel_item_is_folder:
* @item: A valid item.
*
* Determines wether or not an item is a folder.
*
* Return value: %TRUE if the item is a folder.
**/
gboolean
katze_xbel_item_is_folder (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), FALSE);
return item->kind == KATZE_XBEL_ITEM_KIND_FOLDER;
}
/**
* katze_xbel_folder_set_folded:
* @folder: A folder.
* @folded: TRUE if the folder is folded.
*
* Sets the foldedness of the @folder.
**/
void
katze_xbel_folder_set_folded (KatzeXbelItem* folder,
gboolean folded)
{
g_return_if_fail (katze_xbel_item_is_folder (folder));
folder->folded = folded;
}
/**
* katze_xbel_item_set_title:
* @item: A valid item.
* @title: A string to use for the title.
*
* Sets the title of the @item.
**/
void
katze_xbel_item_set_title (KatzeXbelItem* item,
const gchar* title)
{
g_return_if_fail (!katze_xbel_item_is_separator (item));
katze_assign (item->title, g_strdup (title));
}
/**
* katze_xbel_item_set_desc:
* @item: A valid item.
* @title: A string to use for the description.
*
* Sets the description of the @item.
**/
void
katze_xbel_item_set_desc (KatzeXbelItem* item,
const gchar* desc)
{
g_return_if_fail (!katze_xbel_item_is_separator (item));
katze_assign (item->desc, g_strdup (desc));
}
/**
* katze_xbel_bookmark_set_href:
* @bookmark: A bookmark.
* @href: A string containing a valid uri.
*
* Sets the uri of the bookmark.
*
* The uri must not be %NULL.
*
* This uri is not currently validated in any way. This may change in the future.
**/
void
katze_xbel_bookmark_set_href (KatzeXbelItem* bookmark,
const gchar* href)
{
g_return_if_fail (katze_xbel_item_is_bookmark (bookmark));
g_return_if_fail (href);
katze_assign (bookmark->href, g_strdup (href));
}
gboolean
katze_xbel_folder_from_data (KatzeXbelItem* folder,
const gchar* data,
GError** error)
{
g_return_val_if_fail (katze_xbel_folder_is_empty (folder), FALSE);
g_return_val_if_fail (data, FALSE);
xmlDocPtr doc;
if((doc = xmlParseMemory (data, strlen (data))) == NULL)
{
/* No valid xml or broken encoding */
*error = g_error_new_literal (KATZE_XBEL_ERROR, KATZE_XBEL_ERROR_READ,
_("Malformed document."));
return FALSE;
}
if (!katze_xbel_folder_from_xmlDocPtr (folder, doc))
{
/* Parsing failed */
xmlFreeDoc(doc);
*error = g_error_new_literal (KATZE_XBEL_ERROR, KATZE_XBEL_ERROR_READ,
_("Malformed document."));
return FALSE;
}
xmlFreeDoc(doc);
return TRUE;
}
/**
* katze_xbel_folder_from_file:
* @folder: An empty folder.
* @file: A relative path to a file.
* @error: return location for a GError or %NULL
*
* Tries to load @file.
*
* Return value: %TRUE on success or %FALSE when an error occured.
**/
gboolean
katze_xbel_folder_from_file (KatzeXbelItem* folder,
const gchar* file,
GError** error)
{
g_return_val_if_fail (katze_xbel_folder_is_empty (folder), FALSE);
g_return_val_if_fail (file, FALSE);
if (!g_file_test (file, G_FILE_TEST_EXISTS))
{
/* File doesn't exist */
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_NOENT,
_("File not found."));
return FALSE;
}
xmlDocPtr doc;
if ((doc = xmlParseFile (file)) == NULL)
{
/* No valid xml or broken encoding */
*error = g_error_new_literal (KATZE_XBEL_ERROR, KATZE_XBEL_ERROR_READ,
_("Malformed document."));
return FALSE;
}
if (!katze_xbel_folder_from_xmlDocPtr (folder, doc))
{
/* Parsing failed */
xmlFreeDoc (doc);
*error = g_error_new_literal (KATZE_XBEL_ERROR, KATZE_XBEL_ERROR_READ,
_("Malformed document."));
return FALSE;
}
xmlFreeDoc (doc);
return TRUE;
}
static gchar*
katze_xbel_xml_element (const gchar* name,
const gchar* value)
{
if (!value)
return g_strdup ("");
gchar* valueEscaped = g_markup_escape_text (value, -1);
gchar* markup = g_strdup_printf ("<%s>%s</%s>\n",
name, valueEscaped, name);
g_free (valueEscaped);
return markup;
}
gchar*
katze_xbel_item_to_data (KatzeXbelItem* item)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (item), NULL);
gchar* markup = NULL;
switch (item->kind)
{
case KATZE_XBEL_ITEM_KIND_FOLDER:
{
GString* _markup = g_string_new (NULL);
guint n = katze_xbel_folder_get_n_items (item);
guint i;
for (i = 0; i < n; i++)
{
KatzeXbelItem* _item = katze_xbel_folder_get_nth_item (item, i);
gchar* item_markup = katze_xbel_item_to_data (_item);
g_string_append (_markup, item_markup);
g_free (item_markup);
}
gchar* folded = item->folded ? NULL : g_strdup_printf (" folded=\"no\"");
gchar* title = katze_xbel_xml_element ("title", item->title);
gchar* desc = katze_xbel_xml_element ("desc", item->desc);
markup = g_strdup_printf ("<folder%s>\n%s%s%s</folder>\n",
folded ? folded : "",
title, desc,
g_string_free (_markup, FALSE));
g_free (folded);
g_free (title);
g_free (desc);
break;
}
case KATZE_XBEL_ITEM_KIND_BOOKMARK:
{
gchar* href_escaped = g_markup_escape_text (item->href, -1);
gchar* href = g_strdup_printf (" href=\"%s\"", href_escaped);
g_free (href_escaped);
gchar* title = katze_xbel_xml_element ("title", item->title);
gchar* desc = katze_xbel_xml_element ("desc", item->desc);
markup = g_strdup_printf ("<bookmark%s>\n%s%s%s</bookmark>\n",
href,
title, desc,
"");
g_free (href);
g_free (title);
g_free (desc);
break;
}
case KATZE_XBEL_ITEM_KIND_SEPARATOR:
markup = g_strdup ("<separator/>\n");
break;
default:
g_warning ("XBEL: Unknown item kind");
}
return markup;
}
static gchar*
katze_xbel_folder_to_data (KatzeXbelItem* folder,
gsize* length,
GError** error)
{
g_return_val_if_fail (katze_xbel_item_is_folder (folder), FALSE);
GString* inner_markup = g_string_new (NULL);
guint n = katze_xbel_folder_get_n_items (folder);
guint i;
for (i = 0; i < n; i++)
{
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (folder, i);
gchar* sItem = katze_xbel_item_to_data (item);
g_string_append (inner_markup, sItem);
g_free (sItem);
}
gchar* title = katze_xbel_xml_element ("title", folder->title);
gchar* desc = katze_xbel_xml_element ("desc", folder->desc);
gchar* outer_markup;
outer_markup = g_strdup_printf (
"%s%s<xbel version=\"1.0\">\n%s%s%s</xbel>\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
"<!DOCTYPE xbel PUBLIC \"+//IDN python.org//DTD "
"XML Bookmark Exchange Language 1.0//EN//XML\" "
"\"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd\">\n",
title,
desc,
g_string_free (inner_markup, FALSE));
g_free (title);
g_free (desc);
if (length)
*length = strlen (outer_markup);
return outer_markup;
}
/**
* katze_xbel_folder_to_file:
* @folder: A folder.
* @file: The destination filename.
* @error: return location for a GError or %NULL
*
* Write the contents of @folder to the specified file, creating it if necessary.
*
* Return value: %TRUE on success or %FALSE when an error occured.
**/
gboolean
katze_xbel_folder_to_file (KatzeXbelItem* folder,
const gchar* file,
GError** error)
{
g_return_val_if_fail (KATZE_IS_XBEL_ITEM (folder), FALSE);
g_return_val_if_fail (file, FALSE);
gchar* data;
if (!(data = katze_xbel_folder_to_data (folder, NULL, error)))
return FALSE;
FILE* fp;
if (!(fp = fopen (file, "w")))
{
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_ACCES,
_("Writing failed."));
return FALSE;
}
fputs (data, fp);
fclose (fp);
g_free (data);
return TRUE;
}

View file

@ -1,166 +0,0 @@
/*
Copyright (C) 2007-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_XBEL_H__
#define __KATZE_XBEL_H__ 1
#include <glib-object.h>
G_BEGIN_DECLS
#define KATZE_TYPE_XBEL_ITEM \
(katze_xbel_item_get_type ())
#define KATZE_XBEL_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_XBEL_ITEM, KatzeXbelItem))
#define KATZE_IS_XBEL_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_XBEL_ITEM))
typedef struct _KatzeXbelItem KatzeXbelItem;
typedef struct _KatzeXbelItemClass KatzeXbelItemClass;
struct _KatzeXbelItemClass
{
GObjectClass parent_class;
};
#define KATZE_XBEL_ERROR g_quark_from_string("KATZE_XBEL_ERROR")
typedef enum
{
KATZE_XBEL_ERROR_INVALID_URI, /* Malformed uri */
KATZE_XBEL_ERROR_INVALID_VALUE, /* Requested field not found */
KATZE_XBEL_ERROR_URI_NOT_FOUND, /* Requested uri not found */
KATZE_XBEL_ERROR_READ, /* Malformed document */
KATZE_XBEL_ERROR_UNKNOWN_ENCODING, /* Parsed text was in an unknown encoding */
KATZE_XBEL_ERROR_WRITE, /* Writing failed. */
} KatzeXbelError;
typedef enum
{
KATZE_XBEL_ITEM_KIND_FOLDER,
KATZE_XBEL_ITEM_KIND_BOOKMARK,
KATZE_XBEL_ITEM_KIND_SEPARATOR
} KatzeXbelItemKind;
GType
katze_xbel_item_get_type (void) G_GNUC_CONST;
KatzeXbelItem*
katze_xbel_bookmark_new (void);
KatzeXbelItem*
katze_xbel_separator_new (void);
KatzeXbelItem*
katze_xbel_folder_new (void);
void
katze_xbel_item_ref (KatzeXbelItem* item);
void
katze_xbel_item_unref (KatzeXbelItem* item);
KatzeXbelItem*
katze_xbel_item_copy (KatzeXbelItem* item);
void
katze_xbel_folder_append_item (KatzeXbelItem* folder,
KatzeXbelItem* item);
void
katze_xbel_folder_prepend_item (KatzeXbelItem* folder,
KatzeXbelItem* item);
void
katze_xbel_folder_remove_item (KatzeXbelItem* folder,
KatzeXbelItem* item);
guint
katze_xbel_folder_get_n_items (KatzeXbelItem* folder);
KatzeXbelItem*
katze_xbel_folder_get_nth_item (KatzeXbelItem* folder,
guint n);
gboolean
katze_xbel_folder_is_empty (KatzeXbelItem* folder);
gboolean
katze_xbel_folder_get_folded (KatzeXbelItem* folder);
KatzeXbelItemKind
katze_xbel_item_get_kind (KatzeXbelItem* item);
KatzeXbelItem*
katze_xbel_item_get_parent (KatzeXbelItem* item);
G_CONST_RETURN gchar*
katze_xbel_item_get_title (KatzeXbelItem* item);
G_CONST_RETURN gchar*
katze_xbel_item_get_desc (KatzeXbelItem* item);
G_CONST_RETURN gchar*
katze_xbel_bookmark_get_href (KatzeXbelItem* bookmark);
/*time_t
katze_xbel_bookmark_get_added (KatzeXbelItem* bookmark);
time_t
katze_xbel_bookmark_get_modified (KatzeXbelItem* bookmark);
time_t
katze_xbel_bookmark_get_visited (KatzeXbelItem* bookmark);*/
gboolean
katze_xbel_item_is_bookmark (KatzeXbelItem* bookmark);
gboolean
katze_xbel_item_is_separator (KatzeXbelItem* bookmark);
gboolean
katze_xbel_item_is_folder (KatzeXbelItem* bookmark);
void
katze_xbel_folder_set_folded (KatzeXbelItem* folder,
gboolean folded);
void
katze_xbel_item_set_title (KatzeXbelItem* item,
const gchar* title);
void
katze_xbel_item_set_desc (KatzeXbelItem* item,
const gchar* desc);
void
katze_xbel_bookmark_set_href (KatzeXbelItem* bookmark,
const gchar* href);
gboolean
katze_xbel_folder_from_data (KatzeXbelItem* folder,
const gchar* data,
GError** error);
gboolean
katze_xbel_folder_from_file (KatzeXbelItem* folder,
const gchar* file,
GError** error);
gchar*
katze_xbel_item_to_data (KatzeXbelItem* item);
gboolean
katze_xbel_folder_to_file (KatzeXbelItem* folder,
const gchar* file,
GError** error);
#endif /* !__KATZE_XBEL_H__ */

View file

@ -17,6 +17,5 @@
#include "katze-item.h" #include "katze-item.h"
#include "katze-list.h" #include "katze-list.h"
#include "katze-array.h" #include "katze-array.h"
#include "katze-xbel.h"
#endif /* __KATZE_H__ */ #endif /* __KATZE_H__ */

View file

@ -25,6 +25,8 @@
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#if ENABLE_NLS #if ENABLE_NLS
#include <libintl.h> #include <libintl.h>
@ -352,6 +354,216 @@ midori_web_list_add_item_cb (KatzeArray* trash,
} }
} }
static KatzeItem*
katze_item_from_xmlNodePtr (xmlNodePtr cur)
{
KatzeItem* item;
xmlChar* key;
item = katze_item_new ();
key = xmlGetProp (cur, (xmlChar*)"href");
katze_item_set_uri (item, (gchar*)key);
g_free (key);
cur = cur->xmlChildrenNode;
while (cur)
{
if (!xmlStrcmp (cur->name, (const xmlChar*)"title"))
{
key = xmlNodeGetContent (cur);
katze_item_set_name (item, g_strstrip ((gchar*)key));
g_free (key);
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"desc"))
{
key = xmlNodeGetContent (cur);
katze_item_set_text (item, g_strstrip ((gchar*)key));
g_free (key);
}
cur = cur->next;
}
return item;
}
/* Create an array from an xmlNodePtr */
static KatzeArray*
katze_array_from_xmlNodePtr (xmlNodePtr cur)
{
KatzeArray* array;
xmlChar* key;
KatzeItem* item;
array = katze_array_new (KATZE_TYPE_ARRAY);
key = xmlGetProp (cur, (xmlChar*)"folded");
if (key)
{
/* if (!g_ascii_strncasecmp ((gchar*)key, "yes", 3))
folder->folded = TRUE;
else if (!g_ascii_strncasecmp ((gchar*)key, "no", 2))
folder->folded = FALSE;
else
g_warning ("XBEL: Unknown value for folded."); */
xmlFree (key);
}
cur = cur->xmlChildrenNode;
while (cur)
{
if (!xmlStrcmp (cur->name, (const xmlChar*)"title"))
{
key = xmlNodeGetContent (cur);
katze_item_set_name (KATZE_ITEM (array), g_strstrip ((gchar*)key));
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"desc"))
{
key = xmlNodeGetContent (cur);
katze_item_set_text (KATZE_ITEM (array), g_strstrip ((gchar*)key));
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"folder"))
{
item = (KatzeItem*)katze_array_from_xmlNodePtr (cur);
katze_array_add_item (array, item);
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"bookmark"))
{
item = katze_item_from_xmlNodePtr (cur);
katze_array_add_item (array, item);
}
else if (!xmlStrcmp (cur->name, (const xmlChar*)"separator"))
{
item = katze_item_new ();
katze_array_add_item (array, item);
}
cur = cur->next;
}
return array;
}
/* Loads the contents from an xmlNodePtr into an array. */
static gboolean
katze_array_from_xmlDocPtr (KatzeArray* array,
xmlDocPtr doc)
{
xmlNodePtr cur;
xmlChar* version;
gchar* value;
KatzeItem* item;
cur = xmlDocGetRootElement (doc);
version = xmlGetProp (cur, (xmlChar*)"version");
if (xmlStrcmp (version, (xmlChar*)"1.0"))
g_warning ("XBEL version is not 1.0.");
xmlFree (version);
value = (gchar*)xmlGetProp (cur, (xmlChar*)"title");
katze_item_set_name (KATZE_ITEM (array), value);
g_free (value);
value = (gchar*)xmlGetProp (cur, (xmlChar*)"desc");
katze_item_set_text (KATZE_ITEM (array), value);
g_free (value);
if ((cur = xmlDocGetRootElement (doc)) == NULL)
{
/* Empty document */
return FALSE;
}
if (xmlStrcmp (cur->name, (const xmlChar*)"xbel"))
{
/* Wrong document kind */
return FALSE;
}
cur = cur->xmlChildrenNode;
while (cur)
{
item = NULL;
if (!xmlStrcmp (cur->name, (const xmlChar*)"folder"))
item = (KatzeItem*)katze_array_from_xmlNodePtr (cur);
else if (!xmlStrcmp (cur->name, (const xmlChar*)"bookmark"))
item = katze_item_from_xmlNodePtr (cur);
else if (!xmlStrcmp (cur->name, (const xmlChar*)"separator"))
item = katze_item_new ();
/*else if (!xmlStrcmp (cur->name, (const xmlChar*)"info"))
item = katze_xbel_parse_info (xbel, cur);*/
if (item)
katze_array_add_item (array, item);
cur = cur->next;
}
return TRUE;
}
#if 0
static gboolean
katze_array_from_data (KatzeArray* array,
const gchar* data,
GError** error)
{
xmlDocPtr doc;
g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), FALSE);
g_return_val_if_fail (data != NULL, FALSE);
katze_array_clear (array);
if((doc = xmlParseMemory (data, strlen (data))) == NULL)
{
/* No valid xml or broken encoding */
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Malformed document."));
return FALSE;
}
if (!katze_array_from_xmlDocPtr (array, doc))
{
/* Parsing failed */
xmlFreeDoc (doc);
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Malformed document."));
return FALSE;
}
xmlFreeDoc (doc);
return TRUE;
}
#endif
static gboolean
katze_array_from_file (KatzeArray* array,
const gchar* filename,
GError** error)
{
xmlDocPtr doc;
g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
{
/* File doesn't exist */
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_NOENT,
_("File not found."));
return FALSE;
}
if ((doc = xmlParseFile (filename)) == NULL)
{
/* No valid xml or broken encoding */
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Malformed document."));
return FALSE;
}
if (!katze_array_from_xmlDocPtr (array, doc))
{
/* Parsing failed */
xmlFreeDoc (doc);
*error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Malformed document."));
return FALSE;
}
xmlFreeDoc (doc);
return TRUE;
}
static gchar* static gchar*
_simple_xml_element (const gchar* name, _simple_xml_element (const gchar* name,
const gchar* value) const gchar* value)
@ -510,7 +722,7 @@ midori_browser_session_cb (MidoriBrowser* browser,
static void static void
midori_browser_weak_notify_cb (MidoriBrowser* browser, midori_browser_weak_notify_cb (MidoriBrowser* browser,
KatzeXbelItem* session) KatzeArray* session)
{ {
g_object_disconnect (browser, "any-signal", g_object_disconnect (browser, "any-signal",
G_CALLBACK (midori_browser_session_cb), session, NULL); G_CALLBACK (midori_browser_session_cb), session, NULL);
@ -543,10 +755,14 @@ main (int argc,
MidoriStartup load_on_startup; MidoriStartup load_on_startup;
gchar* homepage; gchar* homepage;
KatzeArray* search_engines; KatzeArray* search_engines;
KatzeXbelItem* bookmarks; KatzeArray* bookmarks;
guint i; KatzeArray* _session;
KatzeArray* trash;
MidoriBrowser* browser;
KatzeArray* session;
guint n, i;
gchar* uri; gchar* uri;
KatzeXbelItem* item; KatzeItem* item;
gchar* uri_ready; gchar* uri_ready;
#if ENABLE_NLS #if ENABLE_NLS
@ -658,9 +874,9 @@ main (int argc,
} }
katze_assign (config_file, g_build_filename (config_path, "bookmarks.xbel", katze_assign (config_file, g_build_filename (config_path, "bookmarks.xbel",
NULL)); NULL));
bookmarks = katze_xbel_folder_new (); bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
error = NULL; error = NULL;
if (!katze_xbel_folder_from_file (bookmarks, config_file, &error)) if (!katze_array_from_file (bookmarks, config_file, &error))
{ {
if (error->code != G_FILE_ERROR_NOENT) if (error->code != G_FILE_ERROR_NOENT)
g_string_append_printf (error_messages, g_string_append_printf (error_messages,
@ -668,13 +884,13 @@ main (int argc,
g_error_free (error); g_error_free (error);
} }
g_free (config_file); g_free (config_file);
KatzeXbelItem* _session = katze_xbel_folder_new (); _session = katze_array_new (KATZE_TYPE_ITEM);
g_object_get (settings, "load-on-startup", &load_on_startup, NULL); g_object_get (settings, "load-on-startup", &load_on_startup, NULL);
if (load_on_startup == MIDORI_STARTUP_LAST_OPEN_PAGES) if (load_on_startup == MIDORI_STARTUP_LAST_OPEN_PAGES)
{ {
config_file = g_build_filename (config_path, "session.xbel", NULL); config_file = g_build_filename (config_path, "session.xbel", NULL);
error = NULL; error = NULL;
if (!katze_xbel_folder_from_file (_session, config_file, &error)) if (!katze_array_from_file (_session, config_file, &error))
{ {
if (error->code != G_FILE_ERROR_NOENT) if (error->code != G_FILE_ERROR_NOENT)
g_string_append_printf (error_messages, g_string_append_printf (error_messages,
@ -684,9 +900,9 @@ main (int argc,
g_free (config_file); g_free (config_file);
} }
config_file = g_build_filename (config_path, "tabtrash.xbel", NULL); config_file = g_build_filename (config_path, "tabtrash.xbel", NULL);
KatzeXbelItem* xbel_trash = katze_xbel_folder_new (); trash = katze_array_new (KATZE_TYPE_ITEM);
error = NULL; error = NULL;
if (!katze_xbel_folder_from_file (xbel_trash, config_file, &error)) if (!katze_array_from_file (trash, config_file, &error))
{ {
if (error->code != G_FILE_ERROR_NOENT) if (error->code != G_FILE_ERROR_NOENT)
g_string_append_printf (error_messages, g_string_append_printf (error_messages,
@ -724,9 +940,9 @@ main (int argc,
{ {
g_object_unref (settings); g_object_unref (settings);
g_object_unref (search_engines); g_object_unref (search_engines);
katze_xbel_item_unref (bookmarks); g_object_unref (bookmarks);
katze_xbel_item_unref (_session); g_object_unref (_session);
katze_xbel_item_unref (xbel_trash); g_object_unref (trash);
g_string_free (error_messages, TRUE); g_string_free (error_messages, TRUE);
return 0; return 0;
} }
@ -743,47 +959,32 @@ main (int argc,
uri = strtok (g_strdup (uris[i]), "|"); uri = strtok (g_strdup (uris[i]), "|");
while (uri != NULL) while (uri != NULL)
{ {
item = katze_xbel_bookmark_new (); item = katze_item_new ();
uri_ready = sokoke_magic_uri (uri, NULL); uri_ready = sokoke_magic_uri (uri, NULL);
katze_xbel_bookmark_set_href (item, uri_ready); katze_item_set_uri (item, uri_ready);
g_free (uri_ready); g_free (uri_ready);
katze_xbel_folder_append_item (_session, item); katze_array_add_item (_session, item);
uri = strtok (NULL, "|"); uri = strtok (NULL, "|");
} }
g_free (uri); g_free (uri);
i++; i++;
} }
if (katze_xbel_folder_is_empty (_session)) if (katze_array_is_empty (_session))
{ {
KatzeXbelItem* item = katze_xbel_bookmark_new (); item = katze_item_new ();
if (load_on_startup == MIDORI_STARTUP_BLANK_PAGE) if (load_on_startup == MIDORI_STARTUP_BLANK_PAGE)
katze_xbel_bookmark_set_href (item, ""); katze_item_set_uri (item, "");
else else
{ {
g_object_get (settings, "homepage", &homepage, NULL); g_object_get (settings, "homepage", &homepage, NULL);
katze_xbel_bookmark_set_href (item, homepage); katze_item_set_uri (item, homepage);
g_free (homepage); g_free (homepage);
} }
katze_xbel_folder_prepend_item (_session, item); katze_array_add_item (_session, item);
} }
g_free (config_path); g_free (config_path);
KatzeArray* trash = katze_array_new (KATZE_TYPE_ITEM);
guint n = katze_xbel_folder_get_n_items (xbel_trash);
for (i = 0; i < n; i++)
{
KatzeXbelItem* xbel_item = katze_xbel_folder_get_nth_item (xbel_trash, i);
if (!katze_xbel_item_is_separator (xbel_item))
{
KatzeItem* item = g_object_new (KATZE_TYPE_ITEM,
"name", katze_xbel_item_get_title (xbel_item),
"uri", katze_xbel_bookmark_get_href (xbel_item),
NULL);
katze_array_add_item (trash, item);
}
}
katze_xbel_item_unref (xbel_trash);
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);
@ -793,7 +994,7 @@ main (int argc,
"search-engines", search_engines, "search-engines", search_engines,
NULL); NULL);
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER, browser = g_object_new (MIDORI_TYPE_BROWSER,
"settings", settings, "settings", settings,
"bookmarks", bookmarks, "bookmarks", bookmarks,
"trash", trash, "trash", trash,
@ -802,18 +1003,18 @@ main (int argc,
midori_app_add_browser (app, browser); midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser)); gtk_widget_show (GTK_WIDGET (browser));
KatzeArray* session = midori_browser_get_proxy_array (browser); session = midori_browser_get_proxy_array (browser);
n = katze_xbel_folder_get_n_items (_session); n = katze_array_get_length (_session);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (_session, i); item = katze_array_get_nth_item (_session, i);
midori_browser_add_xbel_item (browser, item); midori_browser_add_item (browser, item);
} }
/* FIXME: Switch to the last active page */ /* FIXME: Switch to the last active page */
item = katze_xbel_folder_get_nth_item (_session, 0); item = katze_array_get_nth_item (_session, 0);
if (!strcmp (katze_xbel_bookmark_get_href (item), "")) if (!strcmp (katze_item_get_uri (item), ""))
midori_browser_activate_action (browser, "Location"); midori_browser_activate_action (browser, "Location");
katze_xbel_item_unref (_session); g_object_unref (_session);
g_signal_connect_after (browser, "notify::uri", g_signal_connect_after (browser, "notify::uri",
G_CALLBACK (midori_browser_session_cb), session); G_CALLBACK (midori_browser_session_cb), session);
@ -870,12 +1071,12 @@ main (int argc,
g_free (config_file); g_free (config_file);
config_file = g_build_filename (config_path, "bookmarks.xbel", NULL); config_file = g_build_filename (config_path, "bookmarks.xbel", NULL);
error = NULL; error = NULL;
if (!katze_xbel_folder_to_file (bookmarks, config_file, &error)) if (!katze_array_to_file (bookmarks, config_file, &error))
{ {
g_warning (_("The bookmarks couldn't be saved. %s"), error->message); g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
g_error_free (error); g_error_free (error);
} }
katze_xbel_item_unref (bookmarks); g_object_unref (bookmarks);
g_free (config_file); g_free (config_file);
config_file = g_build_filename (config_path, "tabtrash.xbel", NULL); config_file = g_build_filename (config_path, "tabtrash.xbel", NULL);
error = NULL; error = NULL;

View file

@ -32,7 +32,7 @@ struct _MidoriApp
GtkAccelGroup* accel_group; GtkAccelGroup* accel_group;
MidoriWebSettings* settings; MidoriWebSettings* settings;
KatzeXbelItem* bookmarks; KatzeArray* bookmarks;
KatzeArray* trash; KatzeArray* trash;
KatzeArray* search_engines; KatzeArray* search_engines;
@ -134,7 +134,7 @@ midori_app_class_init (MidoriAppClass* class)
"bookmarks", "bookmarks",
_("Bookmarks"), _("Bookmarks"),
_("The bookmarks folder, containing all bookmarks"), _("The bookmarks folder, containing all bookmarks"),
KATZE_TYPE_XBEL_ITEM, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,

View file

@ -72,7 +72,7 @@ struct _MidoriBrowser
gchar* statusbar_text; gchar* statusbar_text;
MidoriWebSettings* settings; MidoriWebSettings* settings;
KatzeXbelItem* bookmarks; KatzeArray* bookmarks;
KatzeArray* proxy_array; KatzeArray* proxy_array;
KatzeArray* trash; KatzeArray* trash;
@ -458,10 +458,25 @@ midori_view_notify_statusbar_text_cb (MidoriView* view,
static void static void
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
KatzeXbelItem* bookmark) KatzeItem* bookmark)
{ {
gboolean new_bookmark = !bookmark; gboolean new_bookmark;
GtkWidget* dialog = gtk_dialog_new_with_buttons ( GtkWidget* dialog;
GtkSizeGroup* sizegroup;
GtkWidget* view;
GtkWidget* hbox;
GtkWidget* label;
const gchar* value;
GtkWidget* entry_title;
GtkWidget* entry_desc;
GtkWidget* entry_uri;
GtkWidget* combo_folder;
GtkTreeView* treeview;
GtkTreeModel* treemodel;
GtkTreeIter iter;
new_bookmark = bookmark == NULL;
dialog = gtk_dialog_new_with_buttons (
new_bookmark ? _("New bookmark") : _("Edit bookmark"), new_bookmark ? _("New bookmark") : _("Edit bookmark"),
GTK_WINDOW (browser), GTK_WINDOW (browser),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
@ -472,27 +487,25 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
new_bookmark ? GTK_STOCK_ADD : GTK_STOCK_REMOVE); new_bookmark ? GTK_STOCK_ADD : GTK_STOCK_REMOVE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
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); sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
if (new_bookmark) if (new_bookmark)
{ {
GtkWidget* view = midori_browser_get_current_tab (browser); view = midori_browser_get_current_tab (browser);
bookmark = katze_xbel_bookmark_new (); bookmark = g_object_new (KATZE_TYPE_ITEM,
katze_xbel_item_set_title (bookmark, "uri", midori_view_get_display_uri (MIDORI_VIEW (view)),
midori_view_get_display_title (MIDORI_VIEW (view))); "name", midori_view_get_display_title (MIDORI_VIEW (view)), NULL);
katze_xbel_bookmark_set_href (bookmark,
midori_view_get_display_uri (MIDORI_VIEW (view)));
} }
GtkWidget* hbox = gtk_hbox_new (FALSE, 8); hbox = gtk_hbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
GtkWidget* label = gtk_label_new_with_mnemonic (_("_Title:")); label = gtk_label_new_with_mnemonic (_("_Title:"));
gtk_size_group_add_widget (sizegroup, label); gtk_size_group_add_widget (sizegroup, label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
GtkWidget* entry_title = gtk_entry_new (); entry_title = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_title), TRUE); gtk_entry_set_activates_default (GTK_ENTRY (entry_title), TRUE);
const gchar* title = katze_xbel_item_get_title (bookmark); value = katze_item_get_name (bookmark);
gtk_entry_set_text (GTK_ENTRY (entry_title), title ? title : ""); gtk_entry_set_text (GTK_ENTRY (entry_title), value ? value : "");
gtk_box_pack_start (GTK_BOX (hbox), entry_title, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry_title, 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);
@ -502,19 +515,19 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
label = gtk_label_new_with_mnemonic (_("_Description:")); label = gtk_label_new_with_mnemonic (_("_Description:"));
gtk_size_group_add_widget (sizegroup, label); gtk_size_group_add_widget (sizegroup, label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
GtkWidget* entry_desc = gtk_entry_new (); entry_desc = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_desc), TRUE); gtk_entry_set_activates_default (GTK_ENTRY (entry_desc), TRUE);
if (!new_bookmark) if (!new_bookmark)
{ {
const gchar* desc = katze_xbel_item_get_desc (bookmark); value = katze_item_get_text (bookmark);
gtk_entry_set_text (GTK_ENTRY (entry_desc), desc ? desc : ""); gtk_entry_set_text (GTK_ENTRY (entry_desc), value ? value : "");
} }
gtk_box_pack_start (GTK_BOX (hbox), entry_desc, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry_desc, 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);
GtkWidget* entry_uri = NULL; entry_uri = NULL;
if (katze_xbel_item_is_bookmark (bookmark)) if (!KATZE_IS_ARRAY (bookmark))
{ {
hbox = gtk_hbox_new (FALSE, 8); hbox = gtk_hbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
@ -523,14 +536,13 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
entry_uri = gtk_entry_new (); entry_uri = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry_uri), TRUE); gtk_entry_set_activates_default (GTK_ENTRY (entry_uri), TRUE);
gtk_entry_set_text (GTK_ENTRY (entry_uri), gtk_entry_set_text (GTK_ENTRY (entry_uri), katze_item_get_uri (bookmark));
katze_xbel_bookmark_get_href (bookmark));
gtk_box_pack_start (GTK_BOX (hbox), entry_uri, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry_uri, 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);
} }
GtkWidget* combo_folder = NULL; combo_folder = NULL;
if (new_bookmark) if (new_bookmark)
{ {
hbox = gtk_hbox_new (FALSE, 8); hbox = gtk_hbox_new (FALSE, 8);
@ -549,27 +561,26 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
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)
{ {
katze_xbel_item_set_title (bookmark, katze_item_set_name (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_title))); gtk_entry_get_text (GTK_ENTRY (entry_title)));
katze_xbel_item_set_desc (bookmark, katze_item_set_text (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_desc))); gtk_entry_get_text (GTK_ENTRY (entry_desc)));
if (katze_xbel_item_is_bookmark (bookmark)) if (!KATZE_IS_ARRAY (bookmark))
katze_xbel_bookmark_set_href (bookmark, katze_item_set_uri (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_uri))); gtk_entry_get_text (GTK_ENTRY (entry_uri)));
/* FIXME: We want to choose a folder */ /* FIXME: We want to choose a folder */
if (new_bookmark) if (new_bookmark)
{ {
katze_xbel_folder_append_item (browser->bookmarks, bookmark); katze_array_add_item (browser->bookmarks, bookmark);
GtkTreeView* treeview = GTK_TREE_VIEW (browser->panel_bookmarks); treeview = GTK_TREE_VIEW (browser->panel_bookmarks);
GtkTreeModel* treemodel = gtk_tree_view_get_model (treeview); treemodel = gtk_tree_view_get_model (treeview);
GtkTreeIter iter;
gtk_tree_store_insert_with_values (GTK_TREE_STORE (treemodel), gtk_tree_store_insert_with_values (GTK_TREE_STORE (treemodel),
&iter, NULL, G_MAXINT, 0, bookmark, -1); &iter, NULL, G_MAXINT, 0, bookmark, -1);
katze_xbel_item_ref (bookmark); g_object_ref (bookmark);
} }
/* FIXME: update navigationbar */ /* FIXME: Update navigationbar */
/* FIXME: Update panel in other windows */ /* FIXME: Update panel in other windows */
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
@ -580,13 +591,13 @@ midori_view_add_bookmark_cb (GtkWidget* menuitem,
const gchar* uri, const gchar* uri,
GtkWidget* view) GtkWidget* view)
{ {
KatzeXbelItem* xbel_item; KatzeItem* item;
MidoriBrowser* browser; MidoriBrowser* browser;
xbel_item = katze_xbel_bookmark_new (); item = katze_item_new ();
katze_xbel_bookmark_set_href (xbel_item, uri); katze_item_set_uri (item, uri);
browser = (MidoriBrowser*)gtk_widget_get_toplevel (menuitem); browser = (MidoriBrowser*)gtk_widget_get_toplevel (menuitem);
midori_browser_edit_bookmark_dialog_new (browser, xbel_item); midori_browser_edit_bookmark_dialog_new (browser, item);
} }
static gboolean static gboolean
@ -1021,7 +1032,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
"bookmarks", "bookmarks",
_("Bookmarks"), _("Bookmarks"),
_("The bookmarks folder, containing all bookmarks"), _("The bookmarks folder, containing all bookmarks"),
KATZE_TYPE_XBEL_ITEM, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/** /**
@ -1726,6 +1737,7 @@ midori_browser_search_focus_out_event_cb (GtkWidget* widget,
{ {
gboolean show_navigationbar; gboolean show_navigationbar;
gboolean show_web_search; gboolean show_web_search;
g_object_get (browser->settings, g_object_get (browser->settings,
"show-navigationbar", &show_navigationbar, "show-navigationbar", &show_navigationbar,
"show-web-search", &show_web_search, "show-web-search", &show_web_search,
@ -1743,19 +1755,21 @@ midori_panel_bookmarks_row_activated_cb (GtkTreeView* treeview,
GtkTreeViewColumn* column, GtkTreeViewColumn* column,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkTreeModel* model = gtk_tree_view_get_model (treeview); GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeItem* item;
const gchar* uri;
model = gtk_tree_view_get_model (treeview);
if (gtk_tree_model_get_iter (model, &iter, path)) if (gtk_tree_model_get_iter (model, &iter, path))
{ {
KatzeXbelItem* item;
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (katze_xbel_item_is_bookmark (item)) uri = katze_item_get_uri (item);
{ if (uri && *uri)
const gchar* uri = katze_xbel_bookmark_get_href (item);
_midori_browser_open_uri (browser, uri); _midori_browser_open_uri (browser, uri);
} }
} }
}
static void static void
midori_panel_bookmarks_cursor_or_row_changed_cb (GtkTreeView* tree_view, midori_panel_bookmarks_cursor_or_row_changed_cb (GtkTreeView* tree_view,
@ -1763,14 +1777,14 @@ midori_panel_bookmarks_cursor_or_row_changed_cb (GtkTreeView* tree_view,
{ {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
gboolean is_separator; gboolean is_separator;
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
is_separator = katze_xbel_item_is_separator (item); is_separator = !KATZE_IS_ARRAY (item) && !katze_item_get_uri (item);
_action_set_sensitive (browser, "BookmarkEdit", !is_separator); _action_set_sensitive (browser, "BookmarkEdit", !is_separator);
_action_set_sensitive (browser, "BookmarkDelete", TRUE); _action_set_sensitive (browser, "BookmarkDelete", TRUE);
} }
@ -1784,14 +1798,16 @@ midori_panel_bookmarks_cursor_or_row_changed_cb (GtkTreeView* tree_view,
static void static void
_midori_panel_bookmarks_popup (GtkWidget* widget, _midori_panel_bookmarks_popup (GtkWidget* widget,
GdkEventButton* event, GdkEventButton* event,
KatzeXbelItem* item, KatzeItem* item,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
gboolean is_bookmark = katze_xbel_item_is_bookmark (item); const gchar* uri;
_action_set_sensitive (browser, "BookmarkOpen", is_bookmark); uri = katze_item_get_uri (item);
_action_set_sensitive (browser, "BookmarkOpenTab", is_bookmark);
_action_set_sensitive (browser, "BookmarkOpenWindow", is_bookmark); _action_set_sensitive (browser, "BookmarkOpen", uri != NULL);
_action_set_sensitive (browser, "BookmarkOpenTab", uri != NULL);
_action_set_sensitive (browser, "BookmarkOpenWindow", uri != NULL);
sokoke_widget_popup (widget, GTK_MENU (browser->popup_bookmark), sokoke_widget_popup (widget, GTK_MENU (browser->popup_bookmark),
event, SOKOKE_MENU_POSITION_CURSOR); event, SOKOKE_MENU_POSITION_CURSOR);
@ -1804,7 +1820,9 @@ midori_panel_bookmarks_button_release_event_cb (GtkWidget* widget,
{ {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
const gchar* uri;
gint n;
if (event->button != 2 && event->button != 3) if (event->button != 2 && event->button != 3)
return FALSE; return FALSE;
@ -1812,12 +1830,15 @@ midori_panel_bookmarks_button_release_event_cb (GtkWidget* widget,
if (sokoke_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter)) if (sokoke_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (event->button == 2 && katze_xbel_item_is_bookmark (item)) uri = katze_item_get_uri (item);
if (event->button == 2)
{ {
const gchar* uri = katze_xbel_bookmark_get_href (item); if (uri && *uri)
gint n = midori_browser_add_uri (browser, uri); {
n = midori_browser_add_uri (browser, uri);
midori_browser_set_current_page (browser, n); midori_browser_set_current_page (browser, n);
} }
}
else else
_midori_panel_bookmarks_popup (widget, event, item, browser); _midori_panel_bookmarks_popup (widget, event, item, browser);
return TRUE; return TRUE;
@ -1831,7 +1852,7 @@ midori_panel_bookmarks_popup_menu_cb (GtkWidget* widget,
{ {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
if (sokoke_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter)) if (sokoke_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
{ {
@ -1843,19 +1864,21 @@ midori_panel_bookmarks_popup_menu_cb (GtkWidget* widget,
static void static void
_tree_store_insert_folder (GtkTreeStore* treestore, _tree_store_insert_folder (GtkTreeStore* treestore,
GtkTreeIter* parent, GtkTreeIter* parent,
KatzeXbelItem* folder) KatzeArray* array)
{ {
guint n = katze_xbel_folder_get_n_items (folder); guint n, i;
guint i; KatzeItem* item;
GtkTreeIter iter;
n = katze_array_get_length (array);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (folder, i); item = katze_array_get_nth_item (array, i);
GtkTreeIter iter;
gtk_tree_store_insert_with_values (treestore, &iter, parent, n, gtk_tree_store_insert_with_values (treestore, &iter, parent, n,
0, item, -1); 0, item, -1);
katze_xbel_item_ref (item); g_object_ref (item);
if (katze_xbel_item_is_folder (item)) if (KATZE_IS_ARRAY (item))
_tree_store_insert_folder (treestore, &iter, item); _tree_store_insert_folder (treestore, &iter, KATZE_ARRAY (item));
} }
} }
@ -1866,27 +1889,28 @@ midori_browser_bookmarks_item_render_icon_cb (GtkTreeViewColumn* column,
GtkTreeIter* iter, GtkTreeIter* iter,
GtkWidget* treeview) GtkWidget* treeview)
{ {
KatzeXbelItem* item; KatzeItem* item;
GdkPixbuf* pixbuf;
gtk_tree_model_get (model, iter, 0, &item, -1); gtk_tree_model_get (model, iter, 0, &item, -1);
if (G_UNLIKELY (!item)) if (G_UNLIKELY (!item))
return; return;
if (G_UNLIKELY (!katze_xbel_item_get_parent (item))) if (G_UNLIKELY (!katze_item_get_parent (item)))
{ {
gtk_tree_store_remove (GTK_TREE_STORE (model), iter); gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
katze_xbel_item_unref (item); g_object_unref (item);
return; return;
} }
/* TODO: Would it be better to not do this on every redraw? */ /* TODO: Would it be better to not do this on every redraw? */
GdkPixbuf* pixbuf = NULL; pixbuf = NULL;
if (katze_xbel_item_is_bookmark (item)) if (KATZE_IS_ARRAY (item))
pixbuf = gtk_widget_render_icon (treeview, STOCK_BOOKMARK,
GTK_ICON_SIZE_MENU, NULL);
else if (katze_xbel_item_is_folder (item))
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY, pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_MENU, NULL); GTK_ICON_SIZE_MENU, NULL);
else if (katze_item_get_uri (item))
pixbuf = gtk_widget_render_icon (treeview, STOCK_BOOKMARK,
GTK_ICON_SIZE_MENU, NULL);
g_object_set (renderer, "pixbuf", pixbuf, NULL); g_object_set (renderer, "pixbuf", pixbuf, NULL);
if (pixbuf) if (pixbuf)
g_object_unref (pixbuf); g_object_unref (pixbuf);
@ -1899,39 +1923,42 @@ midori_browser_bookmarks_item_render_text_cb (GtkTreeViewColumn* column,
GtkTreeIter* iter, GtkTreeIter* iter,
GtkWidget* treeview) GtkWidget* treeview)
{ {
KatzeXbelItem* item; KatzeItem* item;
gtk_tree_model_get (model, iter, 0, &item, -1); gtk_tree_model_get (model, iter, 0, &item, -1);
if (G_UNLIKELY (!item)) if (G_UNLIKELY (!item))
return; return;
if (G_UNLIKELY (!katze_xbel_item_get_parent (item))) if (G_UNLIKELY (!katze_item_get_parent (item)))
{ {
gtk_tree_store_remove (GTK_TREE_STORE (model), iter); gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
katze_xbel_item_unref (item); g_object_unref (item);
return; return;
} }
if (katze_xbel_item_is_separator (item)) if (KATZE_IS_ARRAY (item) || katze_item_get_uri (item))
g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL);
else
g_object_set (renderer, "markup", NULL, g_object_set (renderer, "markup", NULL,
"text", katze_xbel_item_get_title (item), NULL); "text", katze_item_get_name (item), NULL);
else
g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL);
} }
static void static void
_midori_browser_create_bookmark_menu (MidoriBrowser* browser, _midori_browser_create_bookmark_menu (MidoriBrowser* browser,
KatzeXbelItem* folder, KatzeArray* array,
GtkWidget* menu); GtkWidget* menu);
static void static void
midori_browser_bookmark_menu_folder_activate_cb (GtkWidget* menuitem, midori_browser_bookmark_menu_folder_activate_cb (GtkWidget* menuitem,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem)); GtkWidget* menu;
KatzeArray* array;
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem));
gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback) gtk_widget_destroy, NULL); gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback) gtk_widget_destroy, NULL);
KatzeXbelItem* folder = (KatzeXbelItem*)g_object_get_data(G_OBJECT (menuitem), "KatzeXbelItem"); array = (KatzeArray*)g_object_get_data (G_OBJECT (menuitem), "KatzeArray");
_midori_browser_create_bookmark_menu (browser, folder, menu); _midori_browser_create_bookmark_menu (browser, array, menu);
/* Remove all menuitems when the menu is hidden. /* Remove all menuitems when the menu is hidden.
FIXME: We really *want* the line below, but it won't work like that FIXME: We really *want* the line below, but it won't work like that
g_signal_connect_after (menu, "hide", G_CALLBACK (gtk_container_foreach), gtk_widget_destroy); */ g_signal_connect_after (menu, "hide", G_CALLBACK (gtk_container_foreach), gtk_widget_destroy); */
@ -1942,10 +1969,12 @@ static void
midori_browser_bookmarkbar_folder_activate_cb (GtkToolItem* toolitem, midori_browser_bookmarkbar_folder_activate_cb (GtkToolItem* toolitem,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* menu = gtk_menu_new (); GtkWidget* menu;
KatzeXbelItem* folder = (KatzeXbelItem*)g_object_get_data ( KatzeArray* array;
G_OBJECT (toolitem), "KatzeXbelItem");
_midori_browser_create_bookmark_menu (browser, folder, menu); menu = gtk_menu_new ();
array = (KatzeArray*)g_object_get_data (G_OBJECT (toolitem), "KatzeArray");
_midori_browser_create_bookmark_menu (browser, array, menu);
/* Remove all menuitems when the menu is hidden. /* Remove all menuitems when the menu is hidden.
FIXME: We really *should* run the line below, but it won't work like that FIXME: We really *should* run the line below, but it won't work like that
g_signal_connect (menu, "hide", G_CALLBACK (gtk_container_foreach), g_signal_connect (menu, "hide", G_CALLBACK (gtk_container_foreach),
@ -1958,35 +1987,34 @@ static void
midori_browser_menu_bookmarks_item_activate_cb (GtkWidget* widget, midori_browser_menu_bookmarks_item_activate_cb (GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
KatzeXbelItem* item = (KatzeXbelItem*)g_object_get_data (G_OBJECT (widget), KatzeItem* item;
"KatzeXbelItem");
_midori_browser_open_uri (browser, katze_xbel_bookmark_get_href (item)); item = (KatzeItem*)g_object_get_data (G_OBJECT (widget), "KatzeItem");
_midori_browser_open_uri (browser, katze_item_get_uri (item));
gtk_widget_grab_focus (midori_browser_get_current_tab (browser)); gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
} }
static void static void
_midori_browser_create_bookmark_menu (MidoriBrowser* browser, _midori_browser_create_bookmark_menu (MidoriBrowser* browser,
KatzeXbelItem* folder, KatzeArray* array,
GtkWidget* menu) GtkWidget* menu)
{ {
guint i, n; guint i, n;
KatzeXbelItem* item; KatzeItem* item;
const gchar* title; const gchar* title;
GtkWidget* menuitem; GtkWidget* menuitem;
GtkWidget* submenu; GtkWidget* submenu;
GtkWidget* icon; GtkWidget* icon;
n = katze_xbel_folder_get_n_items (folder); n = katze_array_get_length (array);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
item = katze_xbel_folder_get_nth_item (folder, i); item = katze_array_get_nth_item (array, i);
title = katze_xbel_item_is_separator (item) title = katze_item_get_name (item);
? "" : katze_xbel_item_get_title (item);
switch (katze_xbel_item_get_kind (item)) if (KATZE_IS_ARRAY (item))
{ {
case KATZE_XBEL_ITEM_KIND_FOLDER: /* FIXME: what about the "folded" status */
/* FIXME: what about katze_xbel_folder_is_folded? */
menuitem = sokoke_image_menu_item_new_ellipsized (title); menuitem = sokoke_image_menu_item_new_ellipsized (title);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, gtk_image_new_from_stock (GTK_STOCK_DIRECTORY,
@ -1996,9 +2024,10 @@ _midori_browser_create_bookmark_menu (MidoriBrowser* browser,
g_signal_connect (menuitem, "activate", g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_browser_bookmark_menu_folder_activate_cb), G_CALLBACK (midori_browser_bookmark_menu_folder_activate_cb),
browser); browser);
g_object_set_data (G_OBJECT (menuitem), "KatzeXbelItem", item); g_object_set_data (G_OBJECT (menuitem), "KatzeArray", item);
break; }
case KATZE_XBEL_ITEM_KIND_BOOKMARK: else if (katze_item_get_uri (item))
{
menuitem = sokoke_image_menu_item_new_ellipsized (title); menuitem = sokoke_image_menu_item_new_ellipsized (title);
icon = gtk_image_new_from_stock (STOCK_BOOKMARK, GTK_ICON_SIZE_MENU); icon = gtk_image_new_from_stock (STOCK_BOOKMARK, GTK_ICON_SIZE_MENU);
gtk_widget_show (icon); gtk_widget_show (icon);
@ -2006,15 +2035,10 @@ _midori_browser_create_bookmark_menu (MidoriBrowser* browser,
g_signal_connect (menuitem, "activate", g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_browser_menu_bookmarks_item_activate_cb), G_CALLBACK (midori_browser_menu_bookmarks_item_activate_cb),
browser); browser);
g_object_set_data (G_OBJECT (menuitem), "KatzeXbelItem", item); g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
break;
case KATZE_XBEL_ITEM_KIND_SEPARATOR:
menuitem = gtk_separator_menu_item_new ();
break;
default:
menuitem = NULL;
g_warning ("Unknown XBEL item kind");
} }
else
menuitem = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
gtk_widget_show (menuitem); gtk_widget_show (menuitem);
} }
@ -2187,15 +2211,16 @@ _action_bookmark_open_activate (GtkAction* action,
GtkTreeView* tree_view; GtkTreeView* tree_view;
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
const gchar* uri;
tree_view = GTK_TREE_VIEW (browser->panel_bookmarks); tree_view = GTK_TREE_VIEW (browser->panel_bookmarks);
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (katze_xbel_item_is_bookmark (item)) uri = katze_item_get_uri (item);
_midori_browser_open_uri (browser, if (uri && *uri)
katze_xbel_bookmark_get_href (item)); _midori_browser_open_uri (browser, uri);
} }
} }
@ -2206,16 +2231,18 @@ _action_bookmark_open_tab_activate (GtkAction* action,
GtkTreeView* tree_view; GtkTreeView* tree_view;
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
const gchar* uri;
gint n; gint n;
tree_view = GTK_TREE_VIEW (browser->panel_bookmarks); tree_view = GTK_TREE_VIEW (browser->panel_bookmarks);
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (katze_xbel_item_is_bookmark (item)) uri = katze_item_get_uri (item);
if (uri && *uri)
{ {
n = midori_browser_add_xbel_item (browser, item); n = midori_browser_add_item (browser, item);
_midori_browser_set_current_page_smartly (browser, n); _midori_browser_set_current_page_smartly (browser, n);
} }
} }
@ -2228,16 +2255,18 @@ _action_bookmark_open_window_activate (GtkAction* action,
GtkTreeView* tree_view; GtkTreeView* tree_view;
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
const gchar* uri;
gint n; gint n;
tree_view = GTK_TREE_VIEW (browser->panel_bookmarks); tree_view = GTK_TREE_VIEW (browser->panel_bookmarks);
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (katze_xbel_item_is_bookmark (item)) uri = katze_item_get_uri (item);
if (uri && *uri)
{ {
n = midori_browser_add_xbel_item (browser, item); n = midori_browser_add_item (browser, item);
_midori_browser_set_current_page_smartly (browser, n); _midori_browser_set_current_page_smartly (browser, n);
} }
} }
@ -2250,13 +2279,13 @@ _action_bookmark_edit_activate (GtkAction* action,
GtkTreeView* tree_view; GtkTreeView* tree_view;
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
tree_view = GTK_TREE_VIEW (browser->panel_bookmarks); tree_view = GTK_TREE_VIEW (browser->panel_bookmarks);
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
if (!katze_xbel_item_is_separator (item)) /* if (katze_item_get_uri (item)) */
midori_browser_edit_bookmark_dialog_new (browser, item); midori_browser_edit_bookmark_dialog_new (browser, item);
} }
} }
@ -2293,18 +2322,18 @@ _action_bookmark_delete_activate (GtkAction* action,
GtkTreeView* tree_view; GtkTreeView* tree_view;
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
KatzeXbelItem* item; KatzeItem* item;
KatzeXbelItem* parent; KatzeArray* parent;
tree_view = GTK_TREE_VIEW (browser->panel_bookmarks); tree_view = GTK_TREE_VIEW (browser->panel_bookmarks);
if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter)) if (sokoke_tree_view_get_selected_iter (tree_view, &model, &iter))
{ {
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
parent = katze_xbel_item_get_parent (item); parent = katze_item_get_parent (item);
katze_xbel_folder_remove_item (parent, item); katze_array_remove_item (parent, item);
/* This is a preliminary hack, until we fix it properly again */ /* FIXME: This is a preliminary hack, until we fix it properly again */
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
katze_xbel_item_unref (item); g_object_unref (item);
} }
} }
@ -2982,7 +3011,7 @@ midori_browser_init (MidoriBrowser* browser)
GtkTreeViewColumn* column; GtkTreeViewColumn* column;
GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_text;
GtkCellRenderer* renderer_pixbuf; GtkCellRenderer* renderer_pixbuf;
GtkTreeStore* treestore = gtk_tree_store_new (1, KATZE_TYPE_XBEL_ITEM); GtkTreeStore* treestore = gtk_tree_store_new (1, KATZE_TYPE_ITEM);
GtkWidget* treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (treestore)); GtkWidget* treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (treestore));
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 ();
@ -3364,7 +3393,7 @@ static void
midori_browser_load_bookmarks (MidoriBrowser* browser) midori_browser_load_bookmarks (MidoriBrowser* browser)
{ {
guint i, n; guint i, n;
KatzeXbelItem* item; KatzeItem* item;
const gchar* title; const gchar* title;
const gchar* desc; const gchar* desc;
GtkToolItem* toolitem; GtkToolItem* toolitem;
@ -3381,17 +3410,15 @@ midori_browser_load_bookmarks (MidoriBrowser* browser)
_midori_browser_create_bookmark_menu (browser, browser->bookmarks, _midori_browser_create_bookmark_menu (browser, browser->bookmarks,
browser->menu_bookmarks); browser->menu_bookmarks);
n = katze_xbel_folder_get_n_items (browser->bookmarks); n = katze_array_get_length (browser->bookmarks);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
item = katze_xbel_folder_get_nth_item (browser->bookmarks, i); item = katze_array_get_nth_item (browser->bookmarks, i);
title = katze_xbel_item_is_separator (item) title = katze_item_get_name (item);
? "" : katze_xbel_item_get_title (item); desc = katze_item_get_text (item);
desc = katze_xbel_item_is_separator (item)
? "" : katze_xbel_item_get_desc (item); if (KATZE_IS_ARRAY (item))
switch (katze_xbel_item_get_kind (item))
{ {
case KATZE_XBEL_ITEM_KIND_FOLDER:
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DIRECTORY); toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DIRECTORY);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title); gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title);
gtk_tool_item_set_is_important (toolitem, TRUE); gtk_tool_item_set_is_important (toolitem, TRUE);
@ -3400,9 +3427,10 @@ midori_browser_load_bookmarks (MidoriBrowser* browser)
browser); browser);
if (desc && *desc) if (desc && *desc)
gtk_tool_item_set_tooltip_text (toolitem, desc); gtk_tool_item_set_tooltip_text (toolitem, desc);
g_object_set_data (G_OBJECT (toolitem), "KatzeXbelItem", item); g_object_set_data (G_OBJECT (toolitem), "KatzeArray", item);
break; }
case KATZE_XBEL_ITEM_KIND_BOOKMARK: else if (katze_item_get_uri (item))
{
toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK); toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title); gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title);
gtk_tool_item_set_is_important (toolitem, TRUE); gtk_tool_item_set_is_important (toolitem, TRUE);
@ -3411,14 +3439,10 @@ midori_browser_load_bookmarks (MidoriBrowser* browser)
browser); browser);
if (desc && *desc) if (desc && *desc)
gtk_tool_item_set_tooltip_text (toolitem, desc); gtk_tool_item_set_tooltip_text (toolitem, desc);
g_object_set_data (G_OBJECT (toolitem), "KatzeXbelItem", item); g_object_set_data (G_OBJECT (toolitem), "KatzeItem", item);
break;
case KATZE_XBEL_ITEM_KIND_SEPARATOR:
toolitem = gtk_separator_tool_item_new ();
break;
default:
g_warning ("Unknown item kind");
} }
else
toolitem = gtk_separator_tool_item_new ();
gtk_toolbar_insert (GTK_TOOLBAR (browser->bookmarkbar), toolitem, -1); gtk_toolbar_insert (GTK_TOOLBAR (browser->bookmarkbar), toolitem, -1);
} }
sokoke_container_show_children (GTK_CONTAINER (browser->bookmarkbar)); sokoke_container_show_children (GTK_CONTAINER (browser->bookmarkbar));
@ -3600,39 +3624,6 @@ midori_browser_remove_tab (MidoriBrowser* browser,
g_signal_emit (browser, signals[REMOVE_TAB], 0, view); g_signal_emit (browser, signals[REMOVE_TAB], 0, view);
} }
/**
* midori_browser_add_item:
* @browser: a #MidoriBrowser
* @xbel_item: an XBEL item
*
* Appends a new view as described by @item.
*
* Note: Currently this will always be a #MidoriWebView.
*
* Return value: the index of the new view, or -1 in case of an error
**/
gint
midori_browser_add_xbel_item (MidoriBrowser* browser,
KatzeXbelItem* item)
{
const gchar* uri;
const gchar* title;
GtkWidget* view;
g_return_val_if_fail (katze_xbel_item_is_bookmark (item), -1);
uri = katze_xbel_bookmark_get_href (item);
title = katze_xbel_item_get_title (item);
view = g_object_new (MIDORI_TYPE_VIEW,
"title", title,
"settings", browser->settings,
NULL);
midori_view_set_uri (MIDORI_VIEW (view), uri);
gtk_widget_show (view);
return midori_browser_add_tab (browser, view);
}
/** /**
* midori_browser_add_item: * midori_browser_add_item:
* @browser: a #MidoriBrowser * @browser: a #MidoriBrowser

View file

@ -81,10 +81,6 @@ void
midori_browser_remove_tab (MidoriBrowser* browser, midori_browser_remove_tab (MidoriBrowser* browser,
GtkWidget* widget); GtkWidget* widget);
gint
midori_browser_add_xbel_item (MidoriBrowser* browser,
KatzeXbelItem* xbel_item);
gint gint
midori_browser_add_item (MidoriBrowser* browser, midori_browser_add_item (MidoriBrowser* browser,
KatzeItem* item); KatzeItem* item);

View file

@ -8,7 +8,8 @@ midori/midori-console.c
midori/midori-browser.c midori/midori-browser.c
midori/midori-panel.c midori/midori-panel.c
midori/midori-websettings.c midori/midori-websettings.c
midori/midori-webview.c midori/midori-view.c
midori/midori-source.c
midori/midori-preferences.c midori/midori-preferences.c
midori/midori-searchentry.c midori/midori-searchentry.c
midori/sokoke.c midori/sokoke.c
@ -18,4 +19,3 @@ katze/katze-utils.c
katze/katze-item.c katze/katze-item.c
katze/katze-list.c katze/katze-list.c
katze/katze-array.c katze/katze-array.c
katze/katze-xbel.c