From 52f46ac78c67bef0c5f952a4d6f63522679b5706 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Sat, 27 Nov 2004 13:13:25 +0000 Subject: [PATCH] use libnautilus-extension for the context menu instead of Bonobo. 2004-11-27 James Henstridge * configure.in (FONT_CONTEXT_MENU): use libnautilus-extension for the context menu instead of Bonobo. 2004-11-27 James Henstridge * Makefile.am: fix build rules for Nautilus stuff. * fontilus-context-menu.c: convert to a Nautilus extension. --- ChangeLog | 5 + configure.in | 44 +++- vfs-methods/fontilus/ChangeLog | 6 + vfs-methods/fontilus/Makefile.am | 18 +- vfs-methods/fontilus/fontilus-context-menu.c | 246 +++++++++++++------ 5 files changed, 222 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7465563cd..3b7b2f0db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-11-27 James Henstridge + + * configure.in (FONT_CONTEXT_MENU): use libnautilus-extension for + the context menu instead of Bonobo. + 2004-11-24 Christoffer Olsen * All the 20 *.desktop.in files that contain Bugzilla information diff --git a/configure.in b/configure.in index 23df7d7bf..ea1e22c24 100644 --- a/configure.in +++ b/configure.in @@ -21,6 +21,7 @@ m4_define(xft_minver, 2.0.0) m4_define(gtk_minver, 2.0.0) m4_define(libbonobo_minver, 2.0.0) m4_define(libgnomeui_minver, 2.1.90) +m4_define(nautilus_minver, 2.6.0) changequote(,)dnl if test "x$GCC" = "xyes"; then @@ -172,7 +173,7 @@ if test ! -d "$srcdir/libgswitchit"; then AC_MSG_ERROR([Your checkout of gnome-control-center is out of date. The 'libgswitchit' module has been virtually included into gnome-control-center by CVS as a subdirectory. Please check - out again (this can be done on top of your existing checkout]) + out again (this can be done on top of your existing checkout)]) else AC_MSG_RESULT(yes) fi @@ -186,13 +187,40 @@ AC_ARG_ENABLE(vfs-methods, [ --disable-vfs-methods Do not build the font if test x$enable_vfs_methods = xyes; then - PKG_CHECK_MODULES(THEME_METHOD, gnome-vfs-module-2.0 >= 2.2.0 gnome-vfs-2.0 >= 2.2.0) - PKG_CHECK_MODULES(THEMUS_THUMBNAILER, gdk-2.0 >= 2.2.0 libgnomeui-2.0 >= 2.2.0 libmetacity-private gnome-vfs-2.0 >= 2.2.0) - PKG_CHECK_MODULES(THEMUS_COMPONENT, glib-2.0 >= 2.2.0 gtk+-2.0 >= 2.2.0 atk >= 1.2.0 libgnome-2.0 >= 2.2.0 libgnomeui-2.0 >= 2.2.0 gnome-vfs-2.0 >= 2.2.0 libbonobo-2.0 >= 2.2.0 libbonoboui-2.0 >= 2.2.0 libnautilus >= 2.2.0 libglade-2.0) - PKG_CHECK_MODULES(FONT_METHOD, [gnome-vfs-module-2.0 >= gnomevfs_minver fontconfig >= fontconfig_minver]) - PKG_CHECK_MODULES(FONT_THUMBNAILER, [gnome-vfs-2.0 >= gnomevfs_minver gdk-pixbuf-2.0 >= gtk_minver]) - PKG_CHECK_MODULES(FONT_CONTEXT_MENU, [gnome-vfs-2.0 >= gnomevfs_minver libbonobo-2.0 >= libbonobo_minver]) - PKG_CHECK_MODULES(FONT_VIEW, [gnome-vfs-2.0 >= gnomevfs_minver xft >= xft_minver gtk+-2.0 >= gtk_minver libgnomeui-2.0 >= libgnomeui_minver]) + PKG_CHECK_MODULES(THEME_METHOD, + [gnome-vfs-module-2.0 >= 2.2.0 dnl + gnome-vfs-2.0 >= 2.2.0]) + PKG_CHECK_MODULES(THEMUS_THUMBNAILER, + [gdk-2.0 >= 2.2.0 dnl + libgnomeui-2.0 >= 2.2.0 dnl + libmetacity-private dnl + gnome-vfs-2.0 >= 2.2.0]) + PKG_CHECK_MODULES(THEMUS_COMPONENT, + [glib-2.0 >= 2.2.0 dnl + gtk+-2.0 >= 2.2.0 dnl + atk >= 1.2.0 dnl + libgnome-2.0 >= 2.2.0 dnl + libgnomeui-2.0 >= 2.2.0 dnl + gnome-vfs-2.0 >= 2.2.0 dnl + libbonobo-2.0 >= 2.2.0 dnl + libbonoboui-2.0 >= 2.2.0 dnl + libnautilus >= 2.2.0 dnl + libglade-2.0]) + PKG_CHECK_MODULES(FONT_METHOD, + [gnome-vfs-module-2.0 >= gnomevfs_minver dnl + fontconfig >= fontconfig_minver]) + PKG_CHECK_MODULES(FONT_THUMBNAILER, + [gnome-vfs-2.0 >= gnomevfs_minver dnl + gdk-pixbuf-2.0 >= gtk_minver]) + PKG_CHECK_MODULES(FONT_CONTEXT_MENU, + [glib-2.0 >= 2.4.0 dnl + gnome-vfs-2.0 >= gnomevfs_minver dnl + libnautilus-extension >= nautilus_minver]) + PKG_CHECK_MODULES(FONT_VIEW, + [gnome-vfs-2.0 >= gnomevfs_minver dnl + xft >= xft_minver dnl + gtk+-2.0 >= gtk_minver dnl + libgnomeui-2.0 >= libgnomeui_minver]) # Add freetype flags to the thumbnailer script AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no) diff --git a/vfs-methods/fontilus/ChangeLog b/vfs-methods/fontilus/ChangeLog index 281ca0ca3..55695f6e9 100644 --- a/vfs-methods/fontilus/ChangeLog +++ b/vfs-methods/fontilus/ChangeLog @@ -1,3 +1,9 @@ +2004-11-27 James Henstridge + + * Makefile.am: fix build rules for Nautilus stuff. + + * fontilus-context-menu.c: convert to a Nautilus extension. + 2004-10-14 Jody Goldberg * Release 2.8.1 diff --git a/vfs-methods/fontilus/Makefile.am b/vfs-methods/fontilus/Makefile.am index 1350320ed..0e6bfcb7b 100644 --- a/vfs-methods/fontilus/Makefile.am +++ b/vfs-methods/fontilus/Makefile.am @@ -18,9 +18,12 @@ 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 = $(FONT_CONTEXT_MENU_LIBS) -fontilus_context_menu_SOURCES = fontilus-context-menu.c +nautilusdir = $(libdir)/nautilus/extensions-1.0 +nautilus_LTLIBRARIES = libnautilus-fontilus.la +libnautilus_fontilus_la_LDFLAGS = -module -avoid-version \ + -export-symbols-regex 'nautilus_module_.*' +libnautilus_fontilus_la_LIBADD = $(FONT_CONTEXT_MENU_LIBS) +libnautilus_fontilus_la_SOURCES = fontilus-context-menu.c vfsmoduleconfdir = $(sysconfdir)/gnome-vfs-2.0/modules vfsmoduleconf_DATA = font-method.conf @@ -37,15 +40,9 @@ appreg_DATA = fontilus.applications schemasdir = $(GCONF_SCHEMA_FILE_DIR) schemas_DATA = fontilus.schemas -serverdir = $(libdir)/bonobo/servers -server_DATA = fontilus.server -fontilus.server.in: fontilus.server.in.in - sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@ - desktopdir = $(datadir)/applications desktop_in_files = gnome-font-viewer.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) -@INTLTOOL_DESKTOP_RULE@ if GCONF_SCHEMAS_INSTALL install-data-local: @@ -56,9 +53,9 @@ else install-data-local: endif +@INTLTOOL_DESKTOP_RULE@ @INTLTOOL_DIRECTORY_RULE@ @INTLTOOL_SCHEMAS_RULE@ -@INTLTOOL_SERVER_RULE@ EXTRA_DIST = \ font-method.conf \ @@ -66,7 +63,6 @@ EXTRA_DIST = \ fontilus.keys \ fontilus.mime \ fontilus.applications \ - fontilus.server.in.in \ fontilus.schemas \ fontilus.schemas.in \ gnome-font-viewer.desktop.in diff --git a/vfs-methods/fontilus/fontilus-context-menu.c b/vfs-methods/fontilus/fontilus-context-menu.c index 180e045f1..fa7a84160 100644 --- a/vfs-methods/fontilus/fontilus-context-menu.c +++ b/vfs-methods/fontilus/fontilus-context-menu.c @@ -23,16 +23,124 @@ #include +#include #include -#include -#include -#include #include #include +#include +#include +#include #define GTK_FONT_KEY "/desktop/gnome/interface/font_name" -static GConfClient *default_client; +#define FONTILUS_TYPE_CONTEXT_MENU (fontilus_context_menu_get_type ()) +#define FONTILUS_CONTEXT_MENU(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), FONTILUS_TYPE_CONTEXT_MENU)) + +typedef struct { + GObject parent; +} FontilusContextMenu; +typedef struct { + GObjectClass parent_class; +} FontilusContextMenuClass; + +static GType fcm_type = 0; +static GObjectClass *parent_class = NULL; +static GConfClient *default_client = NULL; + +static void fontilus_context_menu_init (FontilusContextMenu *self); +static void fontilus_context_menu_class_init (FontilusContextMenuClass *class); +static void menu_provider_iface_init (NautilusMenuProviderIface *iface); + +static GList *fontilus_context_menu_get_file_items (NautilusMenuProvider *provider, + GtkWidget *window, + GList *files); +static void fontilus_context_menu_activate (NautilusMenuItem *item, + NautilusFileInfo *file); + +static GType +fontilus_context_menu_get_type (void) +{ + return fcm_type; +} + +static void +fontilus_context_menu_register_type (GTypeModule *module) +{ + static const GTypeInfo info = { + sizeof (FontilusContextMenuClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) fontilus_context_menu_class_init, + NULL, + NULL, + sizeof (FontilusContextMenu), + 0, + (GInstanceInitFunc) fontilus_context_menu_init + }; + static const GInterfaceInfo menu_provider_iface_info = { + (GInterfaceInitFunc)menu_provider_iface_init, + NULL, + NULL + }; + + fcm_type = g_type_module_register_type (module, + G_TYPE_OBJECT, + "FontilusContextMenu", + &info, 0); + g_type_module_add_interface (module, + fcm_type, + NAUTILUS_TYPE_MENU_PROVIDER, + &menu_provider_iface_info); +} + +static void +fontilus_context_menu_class_init (FontilusContextMenuClass *class) +{ + parent_class = g_type_class_peek_parent (class); +} +static void menu_provider_iface_init (NautilusMenuProviderIface *iface) +{ + iface->get_file_items = fontilus_context_menu_get_file_items; +} +static void +fontilus_context_menu_init (FontilusContextMenu *self) +{ +} + +static GList * +fontilus_context_menu_get_file_items (NautilusMenuProvider *provider, + GtkWidget *window, + GList *files) +{ + GList *items = NULL; + NautilusFileInfo *file; + NautilusMenuItem *item; + char *scheme = NULL; + + /* only add a menu item if a single file is selected */ + if (files == NULL || files->next != NULL) goto end; + + file = files->data; + scheme = nautilus_file_info_get_uri_scheme (file); + + /* only handle files under the fonts URI scheme */ + if (!scheme || g_ascii_strcasecmp (scheme, "fonts") != 0) goto end; + if (nautilus_file_info_is_directory (file)) goto end; + + /* create the context menu item */ + item = nautilus_menu_item_new ("fontilus-set-default-font", + _("Set as Application Font"), + _("Sets the default application font"), + NULL); + g_signal_connect_object (item, "activate", + G_CALLBACK (fontilus_context_menu_activate), + file, 0); + items = g_list_prepend (items, item); + end: + g_free (scheme); + + return items; +} static gchar * get_font_name(const gchar *uri) @@ -50,90 +158,72 @@ get_font_name(const gchar *uri) 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) +fontilus_context_menu_activate (NautilusMenuItem *item, + NautilusFileInfo *file) { - const CORBA_sequence_CORBA_string *list; - gchar *font_name = NULL; + char *uri, *font_name, *default_font; + PangoFontDescription *fontdesc, *new_fontdesc; - 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, "SetAsApplicationFont")) { - 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); + /* get the existing font */ + default_font = gconf_client_get_string(default_client, + GTK_FONT_KEY, NULL); + if (default_font) { + fontdesc = pango_font_description_from_string (default_font); } else { - goto end; + fontdesc = pango_font_description_new (); } + g_free (default_font); - end: - g_free(font_name); + /* get the new font name */ + uri = nautilus_file_info_get_uri (file); + font_name = get_font_name (uri); + g_free (uri); + if (font_name) { + new_fontdesc = pango_font_description_from_string (font_name); + } else { + new_fontdesc = pango_font_description_new (); + } + g_free (font_name); + + /* merge the new description into the old one */ + pango_font_description_merge (fontdesc, new_fontdesc, TRUE); + + default_font = pango_font_description_to_string (fontdesc); + pango_font_description_free (fontdesc); + pango_font_description_free (new_fontdesc); + + gconf_client_set_string(default_client, GTK_FONT_KEY, default_font, NULL); + g_free (default_font); } -/* --- factory --- */ - -static BonoboObject * -view_factory(BonoboGenericFactory *this_factory, - const gchar *iid, - gpointer user_data) +/* --- extension interface --- */ +void +nautilus_module_initialize (GTypeModule *module) { - 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); + fontilus_context_menu_register_type (module); 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); + /* set up translation catalog */ + bindtextdomain (GETTEXT_PACKAGE, FONTILUS_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +} + +void +nautilus_module_shutdown (void) +{ + if (default_client) + g_object_unref (default_client); + default_client = NULL; +} +void +nautilus_module_list_types (const GType **types, + int *num_types) +{ + static GType type_list[1]; + + type_list[0] = FONTILUS_TYPE_CONTEXT_MENU; + *types = type_list; + *num_types = G_N_ELEMENTS (type_list); }