[PROPOSAL] Gnome Desktop Bookmarks



Hi all.

*** The story so far... ***

On the wiki[1] there's an ongoing discussion about recent files,
bookmarks and Gnome.

The libegg/recent-files lies in CVS, with some leaks, an API lacking of
auditing and a ton of open bugs in Bugzilla (many with patches[2]).  The
UI for recent files is, lacking a better word for it, bizarre.

The specification on the recent files storage needs some revision.

I mailed James Willcox, and offered my help - at least to apply some of
the patches lying around on bugzilla.gnome.org, and doing some API
changes in order to make the library a bit more "friendly" (also WRT
language bindings); until today, James has not yet replied, so here I
am, biting the bullet and mailing to desktop-devel, awaiting for
flames^Wcomments. :-)

*** What is needed ***

First of all, the issues on the table are: Gnome needs an API granting
access to a set of desktop-wide and per-application bookmarks.  The
current situation, with gnome-panel accessing the .gtk-bookmarks file is
really sub-optimal (Gtk bookmarks are just URIs, and the panel accessing
them blocks further development of the bookmarks in Gtk).

The libegg/recent-files stuff needs much love, and someone would like
for it to become a stand-alone platform library instead of being moved
inside Gtk (see bug #147434).

*** My proposal ***

Thus, I reviewed the recent files spec, and using the ideas expressed on
the wiki page, I came up with a specification for desktop-wide
bookmarks[3] - which also covers the recently used files list as a
corner case.

I'm also writing a platform library (on the lines of libgnome-desktop,
and borrowing some of the logic from the libegg/recent-files module),
which is coming along quite nicely.

The library (which, with a serious lack of imagination, I called
"libgnome-bookmark") exposes two objects: GnomeBookmarkItem, which is
the representation of a bookmark; and GnomeBookmarkModel, which is the
monitor for the bookmarks file and list.

Bookmark items are registered by applications, and stored inside the
model, which is also the way to access them.  The items might be
filtered and sorted using custom functions (I wrote some commodity
functions for common filters).

The library will also contain two widgets: a subclassed GtkMenuItem
bound to a bookmark, and a GtkMenu.

+++

I think I could have a first revision of the library out before GUADEC
(which I'm attending, by the way).

I'd like to hear some comments from the desktop hackers about the API
and about the spec.

Kind regards,
 Emmanuele.

+++

[1] http://live.gnome.org/RecentFilesAndBookmarks

[2]
http://bugzilla.gnome.org/buglist.cgi?product=libegg&component=recent-files&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED

[3] http://devel.emmanuelebassi.net/papers/bookmark-spec.html
    This could be a fd.o specification, but for the time being I'd
    settle for a Gnome-only solution.

-- 
Emmanuele Bassi <ebassi gmail com>
Web site: http://log.emmanuelebassi.net
/* gnome-bookmark-item.h - GNOME Desktop Bookmark Representation
 *
 * Copyright (C) 2002-2005 James Willcox
 * Copyright (C) 2005 Emmanuele Bassi
 * All rights reserved
 *
 * This file is part of the Gnome Desktop Bookmark Library
 *
 * Based on EggRecentItem, originally developed by James Willcox
 * <jwillcox gnome org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __GNOME_BOOKMARK_ITEM_H__
#define __GNOME_BOOKMARK_ITEM_H__

#include <time.h>
#include <glib-object.h>

G_BEGIN_DECLS

typedef enum { /*< prefix=GNOME_BOOKMARK_ITEM >*/
	GNOME_BOOKMARK_ITEM_UNCHANGED = 0,
	GNOME_BOOKMARK_ITEM_CHANGED,
	GNOME_BOOKMARK_ITEM_NOT_FOUND
} GnomeBookmarkItemStatus;

#define GNOME_BOOKMARK_ITEM	(gnome_bookmark_item_get_type ())

typedef struct _GnomeBookmarkItem	GnomeBookmarkItem;
typedef struct _GnomeBookmarkItemPriv	GnomeBookmarkItemPriv;

struct _GnomeBookmarkItem
{
	gchar *uri;
	
	/*< priv >*/
	gchar *display_name;
	gchar *mime_type;
	
	gboolean is_private;
	
	GnomeBookmarkItemPriv *priv;
	
	GHashTable *applications;
	GList *groups;
	
	guint mime_type_is_explicit : 1;
	
	gint ref_count;
};

GType			gnome_bookmark_item_get_type 	       (void) G_GNUC_CONST;

GnomeBookmarkItem*	gnome_bookmark_item_new		       (void);
GnomeBookmarkItem*	gnome_bookmark_item_new_from_uri       (const gchar        *uri,
								GError            **err);
GnomeBookmarkItem*	gnome_bookmark_item_new_full	       (const gchar        *uri,
							        const gchar        *display_name,
							        const gchar        *mime_type,
							        const gchar        *group,
							        const gchar        *application_name,
							        const gchar        *application_exec,
							        gboolean            is_private);
void			gnome_bookmark_item_ref		       (GnomeBookmarkItem  *item);
void			gnome_bookmark_item_unref	       (GnomeBookmarkItem  *item);

gboolean		gnome_bookmark_item_set_uri	       (GnomeBookmarkItem  *item,
							        const gchar        *uri,
								GError            **err);
gchar*			gnome_bookmark_item_get_uri	       (GnomeBookmarkItem  *item) G_GNUC_MALLOC;
gboolean		gnome_bookmark_item_set_display_name   (GnomeBookmarkItem  *item,
							        const gchar        *display_name,
								GError            **err);
gchar*			gnome_bookmark_item_get_display_name   (GnomeBookmarkItem  *item) G_GNUC_MALLOC;
void			gnome_bookmark_item_set_mime_type      (GnomeBookmarkItem  *item,
							        const gchar        *mime_type);
gchar*			gnome_bookmark_item_get_mime_type      (GnomeBookmarkItem  *item) G_GNUC_MALLOC;
time_t			gnome_bookmark_item_get_last_timestamp (GnomeBookmarkItem  *item,
								const gchar        *app_name);
G_CONST_RETURN GList*	gnome_bookmark_item_get_groups	       (GnomeBookmarkItem  *item);
gboolean		gnome_bookmark_item_in_group	       (GnomeBookmarkItem  *item,
							        const gchar        *group);
void			gnome_bookmark_item_add_group	       (GnomeBookmarkItem  *item,
							        const gchar        *group);
void			gnome_bookmark_item_remove_group       (GnomeBookmarkItem *item,
							        const gchar       *group);
G_CONST_RETURN GList*	gnome_bookmark_item_get_applications   (GnomeBookmarkItem *item);
gboolean		gnome_bookmark_item_has_application    (GnomeBookmarkItem *item,
							        const gchar       *application);
void			gnome_bookmark_item_add_application    (GnomeBookmarkItem *item,
							        const gchar       *application_name,
							        const gchar       *application_exec);
void			gnome_bookmark_item_remove_application (GnomeBookmarkItem *item,
							        const gchar       *application_name);
void			gnome_bookmark_item_set_private_hint   (GnomeBookmarkItem *item,
							        gboolean           is_private);
gboolean		gnome_bookmark_item_get_private_hint   (GnomeBookmarkItem *item);
GnomeBookmarkItemStatus	gnome_bookmark_item_get_status	       (GnomeBookmarkItem  *item);
gboolean		gnome_bookmark_item_match	       (GnomeBookmarkItem  *a,
							        GnomeBookmarkItem  *b);

int			gnome_bookmark_item_open	       (GnomeBookmarkItem  *item,
								GError            **err);
int			gnome_bookmark_item_open_with_app      (GnomeBookmarkItem  *item,
								const gchar        *app_name,
								GError            **err);
int			gnome_bookmark_item_open_with_env      (GnomeBookmarkItem  *item,
								char              **envp,
								GError            **err);

gchar*			gnome_bookmark_item_serialize	       (GnomeBookmarkItem  *item) G_GNUC_MALLOC;

void			gnome_bookmark_item_list_ref	       (GList              *item_list);
void			gnome_bookmark_item_list_unref	       (GList              *item_list);

G_END_DECLS

#endif /* __GNOME_BOOKMARK_ITEM_H__ */
/* gnome-bookmark-model.h - GNOME Bookmark Model
 *
 * Copyright (C) 2005 Emmanuele Bassi
 * All rights reserved
 *
 * This file is part of the Gnome Bookmark Library
 *
 * Originally developed by James Willcox <jwillcox gnome org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __GNOME_BOOKMARK_MODEL_H__
#define __GNOME_BOOKMARK_MODEL_H__

#include <glib-object.h>
#include <libgnome/gnome-bookmark-item.h>

G_BEGIN_DECLS

#define GNOME_TYPE_BOOKMARK_MODEL		(gnome_bookmark_model_get_type ())
#define GNOME_BOOKMARK_MODEL(obj)		(G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_BOOKMARK_MODEL, GnomeBookmarkModel))
#define GNOME_BOOKMARK_MODEL_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST (klass, GNOME_TYPE_BOOKMARK_MODEL, GnomeBookmarkModelClass))
#define GNOME_IS_BOOKMARK_MODEL(obj)		(G_TYPE_CHECK_INSTANCE_TYPE (obj, GNOME_TYPE_BOOKMARK_MODEL))

typedef struct _GnomeBookmarkModel	GnomeBookmarkModel;
typedef struct _GnomeBookmarkModelClass	GnomeBookmarkModelClass;
typedef struct _GnomeBookmarkModelPriv	GnomeBookmarkModelPriv;

struct _GnomeBookmarkModel
{
	GObject		parent_instance;
};

struct _GnomeBookmarkModelClass
{
	GObjectClass	parent_class;

	void (* changed) (GnomeBookmarkModel *model);
};

typedef enum { /*< prefix=GNOME_BOOKMARK_MODEL >*/
	GNOME_BOOKMARK_MODEL_SORT_LRU,
	GNOME_BOOKMARK_MODEL_SORT_MRU,
	GNOME_BOOKMARK_MODEL_SORT_CUSTOM,
	GNOME_BOOKMARK_MODEL_SORT_NONE
} GnomeBookmarkModelSort;

typedef gint (* GnomeBookmarkSortFunc) (GnomeBookmarkModel *model,
					GnomeBookmarkItem  *a,
					GnomeBookmarkItem  *b,
					gpointer            user_data);

/* filter_func: will affect these functions:
 * 	gnome_bookmark_model_purge
 * 	gnome_bookmark_model_get_list
 * If filter_func returns FALSE, the item will be filtered; e.g., when getting
 * the list, the item will not be included, when purging the item will be kept.
 * We provide some commodity filter functions.
 */
typedef gboolean (* GnomeBookmarkFilterFunc) (GnomeBookmarkModel *model,
					      GnomeBookmarkItem  *item,
					      gpointer            user_data);

/* these are defined by the spec */
#define GNOME_BOOKMARK_GROUP_BOOKMARKS	"Bookmarks"
#define GNOME_BOOKMARK_GROUP_RECENT	"Recent"

GType			gnome_bookmark_model_get_type		(void) G_GNUC_CONST;

GnomeBookmarkModel*	gnome_bookmark_model_new		(void);
GnomeBookmarkModelSort	gnome_bookmark_model_get_sort_type	(GnomeBookmarkModel      *model);
void			gnome_bookmark_model_set_sort_type	(GnomeBookmarkModel      *model,
								 GnomeBookmarkModelSort   sort_type);
void			gnome_bookmark_model_set_sort_func	(GnomeBookmarkModel	 *model,
								 GnomeBookmarkSortFunc    sort_func,
								 gpointer                 sort_data,
								 GDestroyNotify           data_destroy);
void			gnome_bookmark_model_set_filter_func	(GnomeBookmarkModel      *model,
								 GnomeBookmarkFilterFunc  filter_func,
								 gpointer                 filter_data,
								 GDestroyNotify           data_destroy);
void			gnome_bookmark_model_set_group_filter	(GnomeBookmarkModel      *model,
								 const gchar             *group_name);
void			gnome_bookmark_model_set_mime_filter	(GnomeBookmarkModel      *model,
								 const gchar             *mime_type);
void			gnome_bookmark_model_set_app_filter	(GnomeBookmarkModel      *model,
								 const gchar             *app_name);
void			gnome_bookmark_model_set_age_filter	(GnomeBookmarkModel      *model,
								 guint                     days); 
void			gnome_bookmark_model_set_status_filter	(GnomeBookmarkModel	 *model,
								 GnomeBookmarkItemStatus  status);
gboolean		gnome_bookmark_model_add		(GnomeBookmarkModel      *model,
								 GnomeBookmarkItem       *item);
gboolean		gnome_bookmark_model_remove		(GnomeBookmarkModel      *model,
								 GnomeBookmarkItem	 *item);
gboolean		gnome_bookmark_model_remove_from_uri	(GnomeBookmarkModel      *model,
								 const gchar             *uri);
GnomeBookmarkItem*	gnome_bookmark_model_get_from_uri	(GnomeBookmarkModel	 *model,
								 const gchar             *uri);
GList*			gnome_bookmark_model_get_list		(GnomeBookmarkModel      *model,
								 gint                     limit);
void			gnome_bookmark_model_purge		(GnomeBookmarkModel	 *model);
void			gnome_bookmark_model_foreach		(GnomeBookmarkModel	 *model,
								 GnomeBookmarkFilterFunc  filter_func,
								 gpointer                 user_data);
void			gnome_bookmark_model_changed		(GnomeBookmarkModel	 *model);

G_END_DECLS

#endif /* __GNOME_BOOKMARK_MODEL_H__ */
/* gnome-bookmark-menuitem.h
 *
 * Copyright (C) 2005 Emmanuele Bassi
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __GNOME_BOOKMARK_MENU_ITEM_H__
#define __GNOME_BOOKMARK_MENU_ITEM_H__

#include <gtk/gtkmenuitem.h>
#include <gtk/gtktooltips.h>
#include <libgnome/gnome-bookmark-item.h>

G_BEGIN_DECLS

#define GNOME_TYPE_BOOKMARK_MENU_ITEM		(gnome_bookmark_menu_item_get_type ())
#define GNOME_BOOKMARK_MENU_ITEM(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_BOOKMARK_MENU_ITEM, GnomeBookmarkMenuItem))
#define GNOME_BOOKMARK_MENU_ITEM_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_BOOKMARK_MENU_ITEM, GnomeBookmarkMenuItemClass))
#define GNOME_IS_BOOKMARK_MENU_ITEM(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_BOOKMARK_MENU_ITEM))
#define GNOME_IS_BOOKMARK_MENU_ITEM_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_BOOKMARK_MENU_ITEM))
#define GNOME_BOOKMARK_MENU_ITEM_GET_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_BOOKMARK_MENU_ITEM, GnomeBookmarkMenuItemClass))

typedef struct _GnomeBookmarkMenuItem		GnomeBookmarkMenuItem;
typedef struct _GnomeBookmarkMenuItemClass	GnomeBookmarkMenuItemClass;

struct _GnomeBookmarkMenuItem
{
	GtkMenuItem item;
	
	/*< priv >*/
	GnomeBookmarkItem *bookmark;

	GtkTooltips *tips;
	gchar *tip_text;
	
	guint show_tooltip : 1;
	guint show_icon : 1;
};

struct _GnomeBookmarkMenuItemClass
{
	GtkMenuItemClass item_class;

	void (* bookmark_set) (GnomeBookmarkMenuItem *menu_item,
			       GnomeBookmarkItem     *old_bookmark);
	
	/* padding for future expansion */
	void (* _gnome_bookmark_reserved1) (void);
	void (* _gnome_bookmark_reserved2) (void);
	void (* _gnome_bookmark_reserved3) (void);
};

GType			gnome_bookmark_menu_item_get_type	(void) G_GNUC_CONST;
GnomeBookmarkMenuItem*	gnome_bookmark_menu_item_new		(GnomeBookmarkItem     *item);
void			gnome_bookmark_menu_item_set_item	(GnomeBookmarkMenuItem *menu_item,
								 GnomeBookmarkItem     *item);
GnomeBookmarkItem*	gnome_bookmark_menu_item_get_item	(GnomeBookmarkMenuItem *menu_item);
void			gnome_bookmark_menu_item_set_show_icon	(GnomeBookmarkMenuItem *menu_item,
								 gboolean               show_icon);
gboolean		gnome_bookmark_menu_item_get_show_icon	(GnomeBookmarkMenuItem *menu_item);
void			gnome_bookmark_menu_item_set_show_tip	(GnomeBookmarkMenuItem *menu_item,
								 gboolean               show_tip);
gboolean		gnome_bookmark_menu_item_get_show_tip	(GnomeBookmarkMenuItem *menu_item);
void			gnome_bookmark_menu_item_set_tip_text	(GnomeBookmarkMenuItem *menu_item,
								 const gchar           *tip_text);
gchar*			gnome_bookmark_menu_item_get_tip_text	(GnomeBookmarkMenuItem *menu_item) G_GNUC_MALLOC;

G_END_DECLS

#endif /* __GNOME_BOOKMARK_MENU_ITEM_H__ */
/* gnome-bookmark-menu.h
 *
 * Copyright (C) 2005 Emmanuele Bassi
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __GNOME_BOOKMARK_MENU_H__
#define __GNOME_BOOKMARK_MENU_H__

#include <gtkmenu.h>
#include <gtktooltips.h>
#include <libgnome/gnome-bookmark-model.h>
#include <libgnomeui/gnome-bookmark-menuitem.h>

G_BEGIN_DECLS

#define GNOME_TYPE_BOOKMARK_MENU		(gnome_bookmark_menu_get_type ())
#define GNOME_BOOKMARK_MENU(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_BOOKMARK_MENU, GnomeBookmarkMenu))
#define GNOME_BOOKMARK_MENU_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_BOOKMARK_MENU, GnomeBookmarkMenuClass))
#define GNOME_IS_BOOKMARK_MENU(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_BOOKMARK_MENU))
#define GNOME_IS_BOOKMARK_MENU_CLASS(klass)  	(G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_BOOKMARK_MENU))
#define GNOME_BOOKMARK_MENU_GET_CLASS(klass) 	(G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_BOOKMARK_MENU, GnomeBookmarkMenuClass))

typedef struct _GnomeBookmarkMenu	GnomeBookmarkMenu;
typedef struct _GnomeBookmarkMenuClass	GnomeBookmarkMenuClass;

struct _GnomeBookmarkMenu
{
	GtkMenu menu;

	/*< priv >*/
	GnomeBookmarkModel *model;

	GtkTooltips *tips;
	gchar *tip_text;

	GtkWidget *trailing_sep;

	guint show_trailing_sep : 1;
	guint show_tooltips : 1;
	guint show_icons : 1;
};

struct _GnomeBoomarkMenuClass
{
	GtkMenuClass menu_class;
	
	/* proxy used when a bookmark menu item has been activated */
	void (* bookmark_activate) (GnomeBookmarkMenu     *menu,
				    GnomeBookmarkMenuItem *menu_item);
	
	/* fired when changing model */
	void (* model_set)         (GnomeBookmarkMenu  *menu,
			            GnomeBookmarkModel *old_model);

	/* padding for future expansion */
	void (* _gnome_bookmark_reserved1) (void);
	void (* _gnome_bookmark_reserved2) (void);
	void (* _gnome_bookmark_reserved3) (void);
	void (* _gnome_bookmark_reserved4) (void);
};

GType			gnome_bookmark_menu_get_type		  (void) G_GNUC_CONST;
GnomeBookmarkMenu*	gnome_bookmark_menu_new			  (void);
GnomeBookmarkMenu*	gnome_bookmark_menu_new_with_model	  (GnomeBookmarkModel    *model);
void			gnome_bookmark_menu_set_model		  (GnomeBookmarkMenu     *menu,
								   GnomeBookmarkModel    *model);
GnomeBookmarkModel*	gnome_bookmark_menu_get_model		  (GnomeBookmarkMenu     *menu);
void			gnome_bookmark_menu_set_show_trailing_sep (GnomeBookmarkMenu     *menu,
								   gboolean               show_trailing_sep);
gboolean		gnome_bookmark_menu_get_show_trailing_sep (GnomeBookmarkMenu     *menu);
void			gnome_bookmark_menu_set_show_icons	  (GnomeBookmarkMenu     *menu,
								   gboolean               show_icons);
gboolean		gnome_bookmark_menu_get_show_icons	  (GnomeBookmarkMenu     *menu);

/* this function emits a signal */
void			gnome_bookmark_menu_bookmark_activate	  (GnomeBookmarkMenu     *menu,
								   GnomeBookmarkMenuItem *menu_item);

G_END_DECLS

#endif /* __GNOME_BOOKMARK_MENU_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]