Implement image properties page

2002-10-24  Alexander Larsson  <alexl@redhat.com>

	* components/Makefile.am:
	* components/image_properties/.cvsignore:
	* components/image_properties/Makefile.am:
	* components/image_properties/Nautilus_View_image_properties.server.in.in:
	* components/image_properties/libmain.c:
	* components/image_properties/nautilus-image-properties-view.[ch]:
	* configure.in:

	Implement image properties page

	Patch from James Willcox  <jwillcox@gnome.org>

	* libnautilus-private/nautilus-mime-actions.[ch]:
	Add nautilus_mime_get_all_components_for_file_extended

	* src/file-manager/fm-properties-window.c:
	Plug-in property pages.
This commit is contained in:
Alexander Larsson 2002-10-24 15:54:34 +00:00 committed by Alexander Larsson
parent b808be61aa
commit 6705233d05
12 changed files with 567 additions and 4 deletions

View file

@ -1,3 +1,23 @@
2002-10-24 Alexander Larsson <alexl@redhat.com>
* components/Makefile.am:
* components/image_properties/.cvsignore:
* components/image_properties/Makefile.am:
* components/image_properties/Nautilus_View_image_properties.server.in.in:
* components/image_properties/libmain.c:
* components/image_properties/nautilus-image-properties-view.[ch]:
* configure.in:
Implement image properties page
Patch from James Willcox <jwillcox@gnome.org>
* libnautilus-private/nautilus-mime-actions.[ch]:
Add nautilus_mime_get_all_components_for_file_extended
* src/file-manager/fm-properties-window.c:
Plug-in property pages.
2002-10-24 Stephen Browne <stephen.browne@sun.com>
* libnautilus-private/nautilus-file-operations.c:

View file

@ -12,6 +12,7 @@ SUBDIRS = \
throbber \
tree \
emblem \
image_properties \
$(NULL)

View file

@ -0,0 +1,8 @@
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
Nautilus_View_image_properties.server.in
Nautilus_View_image_properties.server

View file

@ -0,0 +1,39 @@
# WHAT YOU NEED TO CHANGE: Change all the filenames to refer to your
# component. Also add whatever libraries, include paths, etc you want,
# and change the G_LOG_DOMAIN.
INCLUDES = \
-DG_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
-DGNOME_DISABLE_DEPRECATED \
-DG_LOG_DOMAIN=\"Nautilus-Image-Properties\" \
-DDATADIR=\"$(datadir)\" \
-I$(top_srcdir) \
-I$(top_builddir) \
$(DISABLE_DEPRECATED_CFLAGS) \
$(COMPONENT_CFLAGS)
bonobodir = $(libdir)/bonobo
bonobo_LTLIBRARIES = libnautilus-image-properties-view.la
libnautilus_image_properties_view_la_SOURCES = \
nautilus-image-properties-view.h \
nautilus-image-properties-view.c \
libmain.c
libnautilus_image_properties_view_la_LIBADD = \
$(top_builddir)/libnautilus/libnautilus.la \
$(COMPONENT_LIBS)
libnautilus_image_properties_view_la_LDFLAGS = -module -avoid-version
server_in_files = Nautilus_View_image_properties.server.in.in
serverdir = $(libdir)/bonobo/servers
server_DATA = $(server_in_files:.server.in.in=.server)
$(server_in_files:.server.in.in=.server.in): $(server_in_files)
sed -e "s|\@BONOBODIR\@|$(bonobodir)|" $< > $@
@INTLTOOL_SERVER_RULE@
EXTRA_DIST = $(server_in_files)
CLEANFILES = $(server_DATA) $(server_DATA).in

View file

@ -0,0 +1,30 @@
<oaf_info>
<oaf_server iid="OAFIID:Nautilus_Image_Properties_View"
type="shlib" location="@BONOBODIR@/libnautilus-image-properties-view.so">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/Unknown:1.0"/>
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Nautilus/View:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" _value="Nautilus Image Properties view"/>
<oaf_attribute name="description" type="string" _value="Image Properties content view component"/>
<oaf_attribute name="bonobo:supported_mime_types" type="stringv">
<item value="image/x-bmp"/>
<item value="image/x-ico"/>
<item value="image/jpeg"/>
<item value="image/gif"/>
<item value="image/png"/>
<item value="image/pnm"/>
<item value="image/ras"/>
<item value="image/tga"/>
<item value="image/tiff"/>
<item value="image/wbmp"/>
<item value="image/x-xbitmap"/>
<item value="image/x-xpixmap"/>
</oaf_attribute>
<oaf_attribute name="nautilus:view_as_name" type="string" _value="Image"/>
<oaf_attribute name="nautilus:property_page_name" type="string" _value="Image"/>
</oaf_server>
</oaf_info>

View file

@ -0,0 +1,63 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2000, 2001 Eazel, Inc
*
* 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.
*
* Author: Maciej Stachowiak
*/
/* libmain.c - object activation infrastructure for shared library
version of tree view. */
#include <config.h>
#include <string.h>
#include "nautilus-image-properties-view.h"
#include <bonobo.h>
#include <bonobo-activation/bonobo-activation.h>
#define VIEW_IID "OAFIID:Nautilus_Image_Properties_View"
static CORBA_Object
image_shlib_make_object (PortableServer_POA poa,
const char *iid,
gpointer impl_ptr,
CORBA_Environment *ev)
{
NautilusImagePropertiesView *view;
if (strcmp (iid, VIEW_IID) != 0) {
return CORBA_OBJECT_NIL;
}
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (g_object_new (NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW, NULL));
bonobo_activation_plugin_use (poa, impl_ptr);
return CORBA_Object_duplicate (BONOBO_OBJREF (view), ev);
}
static const BonoboActivationPluginObject image_plugin_list[] = {
{ VIEW_IID, image_shlib_make_object },
{ NULL }
};
const BonoboActivationPlugin Bonobo_Plugin_info = {
image_plugin_list,
"Nautilus Image Properties Page"
};

View file

@ -0,0 +1,241 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2002 James Willcox
*
* 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.
*
* Author: James Willcox <jwillcox@gnome.org>
*/
#include <config.h>
#include "nautilus-image-properties-view.h"
#include <gtk/gtkvbox.h>
#include <gtk/gtklabel.h>
#include <libgnome/gnome-macros.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-async-ops.h>
#include <eel/eel-gnome-extensions.h>
#include <string.h>
#define LOAD_BUFFER_SIZE 8192
struct NautilusImagePropertiesViewDetails {
char *location;
GtkWidget *vbox;
GtkWidget *resolution;
GnomeVFSAsyncHandle *vfs_handle;
GdkPixbufLoader *loader;
gboolean got_size;
char buffer[LOAD_BUFFER_SIZE];
};
BONOBO_CLASS_BOILERPLATE (NautilusImagePropertiesView, nautilus_image_properties_view,
NautilusView, NAUTILUS_TYPE_VIEW)
static void
nautilus_image_properties_view_finalize (GObject *object)
{
NautilusImagePropertiesView *view;
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (object);
if (view->details->vfs_handle != NULL)
gnome_vfs_async_cancel (view->details->vfs_handle);
view->details->vfs_handle = NULL;
g_free (view->details);
G_OBJECT_CLASS (object)->finalize (object);
}
static void
file_closed_callback (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
gpointer callback_data)
{
}
static void
load_finished (NautilusImagePropertiesView *view)
{
if (view->details->loader != NULL) {
gdk_pixbuf_loader_close (view->details->loader, NULL);
g_object_unref (view->details->loader);
view->details->loader = NULL;
}
if (view->details->vfs_handle != NULL) {
gnome_vfs_async_close (view->details->vfs_handle, file_closed_callback, NULL);
view->details->vfs_handle = NULL;
}
if (!view->details->got_size) {
gtk_label_set_text (GTK_LABEL (view->details->resolution), _("Failed to load image information"));
}
}
static void
file_read_callback (GnomeVFSAsyncHandle *vfs_handle,
GnomeVFSResult result,
gpointer buffer,
GnomeVFSFileSize bytes_requested,
GnomeVFSFileSize bytes_read,
gpointer callback_data)
{
NautilusImagePropertiesView *view;
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (callback_data);
if (result == GNOME_VFS_OK && bytes_read != 0) {
if (!gdk_pixbuf_loader_write (view->details->loader,
buffer,
bytes_read,
NULL)) {
result = GNOME_VFS_ERROR_WRONG_FORMAT;
} else if (!view->details->got_size) {
gnome_vfs_async_read (view->details->vfs_handle,
view->details->buffer,
sizeof (view->details->buffer),
file_read_callback,
view);
return;
}
}
load_finished (view);
}
static void
size_prepared_callback (GdkPixbufLoader *loader,
int width,
int height,
gpointer callback_data)
{
NautilusImagePropertiesView *view;
GdkPixbufFormat *format;
char *str;
char *name, *desc;
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (callback_data);
format = gdk_pixbuf_loader_get_format (loader);
name = gdk_pixbuf_format_get_name (format);
desc = gdk_pixbuf_format_get_description (format);
str = g_strdup_printf (_("<b>Image Type:</b> %s (%s)\n<b>Resolution:</b> %dx%d pixels\n"),
name, desc, width, height);
gtk_label_set_markup (GTK_LABEL (view->details->resolution), str);
g_free (str);
g_free (name);
g_free (desc);
view->details->got_size = TRUE;
}
static void
file_opened_callback (GnomeVFSAsyncHandle *vfs_handle,
GnomeVFSResult result,
gpointer callback_data)
{
NautilusImagePropertiesView *view;
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (callback_data);
if (result != GNOME_VFS_OK) {
view->details->vfs_handle = NULL;
return;
}
view->details->loader = gdk_pixbuf_loader_new ();
g_signal_connect (view->details->loader, "size_prepared",
G_CALLBACK (size_prepared_callback), view);
gnome_vfs_async_read (vfs_handle,
view->details->buffer,
sizeof (view->details->buffer),
file_read_callback,
view);
}
static void
load_location (NautilusImagePropertiesView *view,
const char *location)
{
g_assert (NAUTILUS_IS_IMAGE_PROPERTIES_VIEW (view));
g_assert (location != NULL);
if (view->details->vfs_handle != NULL)
gnome_vfs_async_cancel (view->details->vfs_handle);
gnome_vfs_async_open (&view->details->vfs_handle,
location,
GNOME_VFS_OPEN_READ,
-2,
file_opened_callback,
view);
}
static void
image_load_location_callback (NautilusView *nautilus_view,
const char *location,
gpointer user_data)
{
NautilusImagePropertiesView *view;
g_assert (NAUTILUS_IS_VIEW (nautilus_view));
g_assert (location != NULL);
view = NAUTILUS_IMAGE_PROPERTIES_VIEW (nautilus_view);
nautilus_view_report_load_underway (nautilus_view);
/* Do the actual load. */
load_location (view, location);
nautilus_view_report_load_complete (nautilus_view);
}
static void
nautilus_image_properties_view_class_init (NautilusImagePropertiesViewClass *class)
{
G_OBJECT_CLASS (class)->finalize = nautilus_image_properties_view_finalize;
}
static void
nautilus_image_properties_view_instance_init (NautilusImagePropertiesView *view)
{
view->details = g_new0 (NautilusImagePropertiesViewDetails, 1);
view->details->vbox = gtk_vbox_new (FALSE, 2);
view->details->resolution = gtk_label_new (_("loading..."));
gtk_box_pack_start (GTK_BOX (view->details->vbox),
view->details->resolution,
FALSE, TRUE, 2);
gtk_widget_show_all (view->details->vbox);
nautilus_view_construct (NAUTILUS_VIEW (view), view->details->vbox);
g_signal_connect (view, "load_location",
G_CALLBACK (image_load_location_callback), NULL);
}

View file

@ -0,0 +1,48 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2000 Eazel, Inc
*
* 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.
*
* Author: Maciej Stachowiak <mjs@eazel.com>
*/
#ifndef NAUTILUS_IMAGE_PROPERTIES_VIEW_H
#define NAUTILUS_IMAGE_PROPERTIES_VIEW_H
#include <libnautilus/nautilus-view.h>
#define NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW (nautilus_image_properties_view_get_type ())
#define NAUTILUS_IMAGE_PROPERTIES_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW, NautilusImagePropertiesView))
#define NAUTILUS_IMAGE_PROPERTIES_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW, NautilusImagePropertiesViewClass))
#define NAUTILUS_IS_IMAGE_PROPERTIES_VIEW(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW))
#define NAUTILUS_IS_IMAGE_PROPERTIES_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_IMAGE_PROPERTIES_VIEW))
typedef struct NautilusImagePropertiesViewDetails NautilusImagePropertiesViewDetails;
typedef struct {
NautilusView parent;
NautilusImagePropertiesViewDetails *details;
} NautilusImagePropertiesView;
typedef struct {
NautilusViewClass parent;
} NautilusImagePropertiesViewClass;
GType nautilus_image_properties_view_get_type (void);
#endif /* NAUTILUS_IMAGE_PROPERTIES_VIEW_H */

View file

@ -357,6 +357,7 @@ components/text/services/Makefile
components/throbber/Makefile
components/tree/Makefile
components/emblem/Makefile
components/image_properties/Makefile
cut-n-paste-code/Makefile
cut-n-paste-code/widgets/Makefile
cut-n-paste-code/widgets/gimphwrapbox/Makefile

View file

@ -767,7 +767,8 @@ nautilus_mime_actions_file_needs_full_file_attributes (NautilusFile *file)
GList *
nautilus_mime_get_all_components_for_file (NautilusFile *file)
nautilus_mime_get_all_components_for_file_extended (NautilusFile *file,
char *extra_reqs)
{
char *mime_type;
char *uri_scheme;
@ -789,8 +790,10 @@ nautilus_mime_get_all_components_for_file (NautilusFile *file)
item_mime_types = NULL;
}
info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, FALSE,
explicit_iids, NULL, NULL);
info_list = nautilus_do_component_query (mime_type, uri_scheme,
item_mime_types, FALSE,
explicit_iids, NULL,
extra_reqs);
eel_g_list_free_deep (explicit_iids);
eel_g_list_free_deep (item_mime_types);
@ -801,6 +804,12 @@ nautilus_mime_get_all_components_for_file (NautilusFile *file)
return info_list;
}
GList *
nautilus_mime_get_all_components_for_file (NautilusFile *file)
{
return nautilus_mime_get_all_components_for_file_extended (file, NULL);
}
gboolean
nautilus_mime_has_any_components_for_file (NautilusFile *file)
{

View file

@ -43,7 +43,8 @@ GList * nautilus_mime_get_short_list_applications_for_file
GList * nautilus_mime_get_short_list_components_for_file (NautilusFile *file);
GList * nautilus_mime_get_all_applications_for_file (NautilusFile *file);
GList * nautilus_mime_get_all_components_for_file (NautilusFile *file);
gboolean nautilus_mime_has_any_components_for_file (NautilusFile *file);
GList * nautilus_mime_get_all_components_for_file_extended (NautilusFile *file, char *extra_requirements);
gboolean nautilus_mime_has_any_components_for_file (NautilusFile *file);
gboolean nautilus_mime_has_any_applications_for_file (NautilusFile *file);
gboolean nautilus_mime_has_any_applications_for_file_type (NautilusFile *file);
GnomeVFSResult nautilus_mime_set_default_action_type_for_file (NautilusFile *file,

View file

@ -68,7 +68,12 @@
#include <libnautilus-private/nautilus-link.h>
#include <libnautilus-private/nautilus-metadata.h>
#include <libnautilus-private/nautilus-undo-signal-handlers.h>
#include <libnautilus-private/nautilus-mime-actions.h>
#include <libnautilus-private/nautilus-view-identifier.h>
#include <libnautilus/nautilus-undo.h>
#include <libnautilus/nautilus-view.h>
#include <bonobo/bonobo-widget.h>
#include <bonobo/bonobo-exception.h>
#include <string.h>
static GHashTable *windows;
@ -2101,6 +2106,100 @@ create_permissions_page (FMPropertiesWindow *window)
}
}
static GtkWidget *
bonobo_page_error_message (NautilusViewIdentifier *view_id,
CORBA_Environment *ev)
{
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *image;
char *msg;
hbox = gtk_hbox_new (FALSE, GNOME_PAD);
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
GTK_ICON_SIZE_DIALOG);
msg = g_strdup_printf ("There was an error while trying to create the view named `%s': %s", view_id->name, CORBA_exception_id (ev));
label = gtk_label_new (msg);
g_free (msg);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
return hbox;
}
static void
append_bonobo_pages (FMPropertiesWindow *window)
{
GList *components, *l;
CORBA_Environment ev;
/* find all the property page views for this file */
components = nautilus_mime_get_all_components_for_file_extended
(window->details->target_file,
"nautilus:property_page_name.defined()");
CORBA_exception_init (&ev);
l = components;
while (l != NULL) {
NautilusViewIdentifier *view_id;
Bonobo_ServerInfo *server;
GtkWidget *vbox, *widget;
Bonobo_Unknown obj;
widget = NULL;
server = l->data;
l = l->next;
view_id = nautilus_view_identifier_new_from_property_page (server);
obj = bonobo_activation_activate_from_id (view_id->iid,
0, NULL, &ev);
if (!BONOBO_EX (&ev)) {
Bonobo_Control control;
Nautilus_View view;
char *uri;
control = Bonobo_Unknown_queryInterface
(obj, "IDL:Bonobo/Control:1.0", &ev);
view = Bonobo_Unknown_queryInterface
(control, "IDL:Nautilus/View:1.0", &ev);
uri = nautilus_file_get_uri
(window->details->target_file);
Nautilus_View_load_location (view, uri, &ev);
if (!BONOBO_EX (&ev)) {
widget = bonobo_widget_new_control_from_objref
(control, CORBA_OBJECT_NIL);
}
g_free (uri);
}
if (widget == NULL) {
widget = bonobo_page_error_message (view_id, &ev);
}
vbox = create_page_with_vbox (window->details->notebook,
view_id->name);
gtk_container_add (GTK_CONTAINER (vbox), widget);
gtk_widget_show_all (vbox);
nautilus_view_identifier_free (view_id);
}
}
static gboolean
should_show_emblems (FMPropertiesWindow *window)
{
@ -2222,6 +2321,9 @@ create_properties_window (StartupData *startup_data)
if (should_show_permissions (window)) {
create_permissions_page (window);
}
/* append pages from available views */
append_bonobo_pages (window);
/* Create box for close button. */
hbox = gtk_hbutton_box_new ();