diff --git a/vfs-methods/fontilus/.cvsignore b/vfs-methods/fontilus/.cvsignore index 4e244b836..3194a5ed9 100644 --- a/vfs-methods/fontilus/.cvsignore +++ b/vfs-methods/fontilus/.cvsignore @@ -8,5 +8,8 @@ Makefile.in .deps gnome-thumbnail-font gnome-font-viewer +fontilus-context-menu font-method.directory fontilus.schemas +fontilus.server +fontilus.server.in diff --git a/vfs-methods/fontilus/ChangeLog b/vfs-methods/fontilus/ChangeLog index b70b451d7..dac699305 100644 --- a/vfs-methods/fontilus/ChangeLog +++ b/vfs-methods/fontilus/ChangeLog @@ -1,3 +1,12 @@ +2003-02-02 James Henstridge + + * src/fontilus.server.in.in: bonobo activation server file for the + fontilus component. + + * src/fontilus-context-menu.c: Bonobo listener component to + implement custom context menu items for fonts under fonts:///, + which allows us to set the default font for the desktop. + 2003-02-02 Daniel Yacob * configure.in: Added Amharic (am) to ALL_LINGUAS diff --git a/vfs-methods/fontilus/Makefile.am b/vfs-methods/fontilus/Makefile.am index 4aa449ef6..e00fae124 100644 --- a/vfs-methods/fontilus/Makefile.am +++ b/vfs-methods/fontilus/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = $(FONT_METHOD_CFLAGS) $(THUMBNAILER_CFLAGS) $(FONT_VIEW_CFLAGS) \ - -DDIRECTORY_DIR=\"$(vfsdirectorydir)\" + $(CONTEXT_MENU_CFLAGS) -DDIRECTORY_DIR=\"$(vfsdirectorydir)\" vfsmoduledir = $(libdir)/gnome-vfs-2.0/modules vfsmodule_LTLIBRARIES = libfont-method.la @@ -18,14 +18,16 @@ gnome_thumbnail_font_SOURCES = ftstream-vfs.c thumbnailer.c gnome_font_viewer_LDADD = $(FONT_VIEW_LIBS) gnome_font_viewer_SOURCES = ftstream-vfs.c font-view.c +libexec_PROGRAMS = fontilus-context-menu +fontilus_context_menu_LDADD = $(CONTEXT_MENU_LIBS) +fontilus_context_menu_SOURCES = fontilus-context-menu.c + vfsmoduleconfdir = $(sysconfdir)/gnome-vfs-2.0/modules vfsmoduleconf_DATA = font-method.conf vfsdirectorydir = $(datadir)/gnome/vfolders vfsdirectory_DATA = font-method.directory -@INTLTOOL_DIRECTORY_RULE@ - mimeinfodir = $(datadir)/mime-info mimeinfo_DATA = fontilus.keys fontilus.mime @@ -35,12 +37,19 @@ appreg_DATA = fontilus.applications schemasdir = $(sysconfdir)/gconf/schemas schemas_DATA = fontilus.schemas +serverdir = $(libdir)/bonobo/servers +server_DATA = fontilus.server +fontilus.server.in: fontilus.server.in.in + sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@ + install-data-local: if test -z "$(DESTDIR)"; then \ GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule fontilus.schemas; \ fi +@INTLTOOL_DIRECTORY_RULE@ @INTLTOOL_SCHEMAS_RULE@ +@INTLTOOL_SERVER_RULE@ EXTRA_DIST = \ font-method.conf \ diff --git a/vfs-methods/fontilus/font-view.c b/vfs-methods/fontilus/font-view.c index baa8361fd..8f5345733 100644 --- a/vfs-methods/fontilus/font-view.c +++ b/vfs-methods/fontilus/font-view.c @@ -364,7 +364,7 @@ set_icon(GtkWindow *window, const gchar *uri) if (!pixbuf) goto end; gtk_window_set_icon(window, pixbuf); -end: + end: if (pixbuf) g_object_unref(pixbuf); g_free(icon_file); g_free(icon_name); diff --git a/vfs-methods/fontilus/fontilus-context-menu.c b/vfs-methods/fontilus/fontilus-context-menu.c new file mode 100644 index 000000000..9aa0ae96e --- /dev/null +++ b/vfs-methods/fontilus/fontilus-context-menu.c @@ -0,0 +1,139 @@ +/* -*- mode: C; c-basic-offset: 4 -*- + * Copyright (C) 2002 James Henstridge + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#define GTK_FONT_KEY "/desktop/gnome/interface/font_name" + +static GConfClient *default_client; + +static gchar * +get_font_name(const gchar *uri) +{ + gchar *unescaped; + gchar *base; + + unescaped = gnome_vfs_unescape_string(uri, "/"); + if (!unescaped) return NULL; + + base = g_path_get_basename(unescaped); + g_free(unescaped); + if (!base) return NULL; + + return base; +} + +/* create a font string suitable to store in GTK_FONT_KEY using font_name. + * tries to preserve the font size from the old string */ +static gchar * +make_font_string(const gchar *old_string, const gchar *font_name) +{ + const gchar *space; + + if (!old_string) + return g_strdup(font_name); + + space = strrchr(old_string, ' '); + /* if no space, or the character after the last space is not a digit */ + if (!space || (space[1] < '0' || '9' < space[1])) + return g_strdup(font_name); + + /* if it looks like the last word is a number, append it to the + * font name to form the new name */ + return g_strconcat(font_name, space, NULL); +} + +static void +handle_event(BonoboListener *listener, const gchar *event_name, + const CORBA_any *args, CORBA_Environment *ev, gpointer user_data) +{ + const CORBA_sequence_CORBA_string *list; + gchar *font_name = NULL; + + if (!CORBA_TypeCode_equivalent(args->_type, TC_CORBA_sequence_CORBA_string, ev)) { + goto end; + } + list = (CORBA_sequence_CORBA_string *)args->_value; + + if (list->_length != 1) { + goto end; + } + + font_name = get_font_name(list->_buffer[0]); + if (!font_name) goto end; + + /* set font */ + if (!strcmp(event_name, "UseAsApplicationFont")) { + gchar *curval, *newval; + + curval = gconf_client_get_string(default_client, + GTK_FONT_KEY, NULL); + newval = make_font_string(curval, font_name); + gconf_client_set_string(default_client, GTK_FONT_KEY, newval, NULL); + g_free(newval); + g_free(curval); + } else { + goto end; + } + + end: + g_free(font_name); +} + +/* --- factory --- */ + +static BonoboObject * +view_factory(BonoboGenericFactory *this_factory, + const gchar *iid, + gpointer user_data) +{ + BonoboListener *listener; + + listener = bonobo_listener_new(handle_event, NULL); + + return BONOBO_OBJECT(listener); +} + +int +main(int argc, char *argv[]) +{ + bindtextdomain(GETTEXT_PACKAGE, FONTILUS_LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + BONOBO_FACTORY_INIT(_("Font context menu items"), VERSION, + &argc, argv); + + default_client = gconf_client_get_default(); + g_return_val_if_fail(default_client != NULL, -1); + + return bonobo_generic_factory_main("OAFIID:Fontilus_Context_Menu_Factory", + view_factory, NULL); +} diff --git a/vfs-methods/fontilus/fontilus.server.in.in b/vfs-methods/fontilus/fontilus.server.in.in new file mode 100644 index 000000000..361f117f8 --- /dev/null +++ b/vfs-methods/fontilus/fontilus.server.in.in @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +