summaryrefslogtreecommitdiff
path: root/src/nautilus-component-adapter-factory.c
diff options
context:
space:
mode:
authorMaciej Stachowiak <mstachow@src.gnome.org>2000-09-07 09:10:57 +0000
committerMaciej Stachowiak <mstachow@src.gnome.org>2000-09-07 09:10:57 +0000
commit4734551b9a3920259b5a3da9922bd8b7c84e12db (patch)
tree0002e0048a29c35394681b02ee43045849430367 /src/nautilus-component-adapter-factory.c
parent4c7dc0ab85521ec151129c2072fb36f6e36e848b (diff)
downloadnautilus-4734551b9a3920259b5a3da9922bd8b7c84e12db.tar.gz
Link against libnautilus.
* libnautilus-adapter/Makefile.am: Link against libnautilus. * src/nautilus-component-adapter-factory.h, src/nautilus-component-adapter-factory.c: Fist cut at the easy to use wrapper interface for the soon to come adapter component (part of the work for bugzilla.eazel.com 1994). I made this a singleton object with the object actually exposed, but maybe I should hide the object details completely and just expose the actually useful function (which will instantiate the singleton when/if appropriate). * src/Makefile.am: Add to the build. Link against libnautilus-adapter.
Diffstat (limited to 'src/nautilus-component-adapter-factory.c')
-rw-r--r--src/nautilus-component-adapter-factory.c194
1 files changed, 194 insertions, 0 deletions
diff --git a/src/nautilus-component-adapter-factory.c b/src/nautilus-component-adapter-factory.c
new file mode 100644
index 000000000..57a069024
--- /dev/null
+++ b/src/nautilus-component-adapter-factory.c
@@ -0,0 +1,194 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */
+
+/*
+ * Nautilus
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * Nautilus 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.
+ *
+ * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* nautilus-component-adapter-factory.c - client wrapper for the
+ * special adapter component, which wraps Bonobo components as
+ * Nautilus Views and in the process keeps evil syncrhonous I/O out of
+ * the Nautilus process itself.
+ */
+
+#include <config.h>
+#include "nautilus-component-adapter-factory.h"
+
+#include <libnautilus-adapter/nautilus-adapter-factory.h>
+
+#include <libnautilus-extensions/nautilus-gtk-macros.h>
+
+
+
+#define NAUTILUS_COMPONENT_ADAPTER_FACTORY_IID "OAFIID:fill_me_in"
+
+struct NautilusComponentAdapterFactoryDetails
+{
+ Nautilus_ComponentAdapterFactory corba_factory;
+};
+
+
+
+static void nautilus_component_adapter_factory_initialize_class (NautilusComponentAdapterFactoryClass *klass);
+static void nautilus_component_adapter_factory_initialize (NautilusComponentAdapterFactory *factory);
+static void nautilus_component_adapter_factory_destroy (GtkObject *object);
+
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusComponentAdapterFactory, nautilus_component_adapter_factory, GTK_TYPE_OBJECT)
+
+static void
+nautilus_component_adapter_factory_initialize_class (NautilusComponentAdapterFactoryClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass*) klass;
+ object_class->destroy = nautilus_component_adapter_factory_destroy;
+
+}
+
+static void
+nautilus_component_adapter_factory_initialize (NautilusComponentAdapterFactory *factory)
+{
+ BonoboObjectClient *object_client;
+
+ factory->details = g_new0 (NautilusComponentAdapterFactoryDetails, 0);
+
+ /* FIXME: what if activation fails? Is it valid for an
+ initialize function to fail, and if so, how should it do
+ so?? */
+
+ object_client = bonobo_object_activate (NAUTILUS_COMPONENT_ADAPTER_FACTORY_IID, 0);
+
+
+ /* FIXME: what if this query fails? Is it valid for an
+ initialize function to fail, and if so, how should it do
+ so?? */
+
+ factory->details->corba_factory = bonobo_object_client_query_interface
+ (object_client, "IDL:Nautilus/ComponentAdapterFactory:1.0", NULL);
+
+ /* FIXME: Do we want a gtk_object_unref or a bonobo_object_unref? */
+ bonobo_object_unref (BONOBO_OBJECT (object_client));
+}
+
+
+static void
+nautilus_component_adapter_factory_destroy (GtkObject *object)
+{
+ CORBA_Environment ev;
+ NautilusComponentAdapterFactory *factory;
+
+ factory = NAUTILUS_COMPONENT_ADAPTER_FACTORY (object);
+
+ CORBA_exception_init (&ev);
+ Bonobo_Unknown_unref (factory->details->corba_factory, &ev);
+ CORBA_exception_free (&ev);
+
+ g_free (factory->details);
+}
+
+
+
+static NautilusComponentAdapterFactory *global_component_adapter_factory = NULL;
+
+static void
+component_adapter_factory_at_exit_destructor (void)
+{
+ if (global_component_adapter_factory != NULL) {
+ gtk_object_unref (GTK_OBJECT (global_component_adapter_factory));
+ }
+}
+
+
+NautilusComponentAdapterFactory *
+nautilus_component_adapter_factory_get (void)
+{
+
+ if (global_component_adapter_factory == NULL)
+ {
+ global_component_adapter_factory = gtk_type_new (NAUTILUS_TYPE_COMPONENT_ADAPTER_FACTORY);
+
+ /* FIXME: is it OK to destroy CORBA objects in an atexit handler? */
+ g_atexit (component_adapter_factory_at_exit_destructor);
+ }
+
+ return global_component_adapter_factory;
+
+}
+
+Nautilus_View
+nautilus_component_adapter_factory_create_adapter (NautilusComponentAdapterFactory *factory,
+ BonoboObjectClient *component)
+{
+ Nautilus_View nautilus_view;
+ Bonobo_Control bonobo_control;
+ CORBA_Environment ev;
+
+ nautilus_view = bonobo_object_client_query_interface
+ (component, "IDL:Nautilus/View:1.0", NULL);
+
+ CORBA_exception_init (&ev);
+
+ if (!CORBA_Object_is_nil (nautilus_view, &ev)) {
+ /* Object has the View interface, great! We might not
+ need to adapt it. */
+
+
+ bonobo_control = bonobo_object_client_query_interface
+ (component, "IDL:Bonobo/Control:1.0", NULL);
+
+ if (!CORBA_Object_is_nil (bonobo_control, &ev)) {
+ /* It has the control interface too, so all is peachy. */
+
+ bonobo_object_release_unref (bonobo_control, &ev);
+ CORBA_exception_free (&ev);
+
+ return nautilus_view;
+ } else {
+ /* No control interface; we have no way to
+ support a View that doesn't also support
+ the Control interface, so fail. */
+
+ bonobo_object_release_unref (nautilus_view, &ev);
+ CORBA_exception_free (&ev);
+
+ return CORBA_OBJECT_NIL;
+ }
+ } else {
+ /* No View interface, we must adapt the object */
+
+ CORBA_exception_free (&ev);
+ CORBA_exception_init (&ev);
+
+ nautilus_view = Nautilus_ComponentAdapterFactory_create_adapter
+ (factory->details->corba_factory,
+ bonobo_object_corba_objref (BONOBO_OBJECT (component)),
+ &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ nautilus_view = CORBA_OBJECT_NIL;
+ }
+
+ CORBA_exception_free (&ev);
+
+ return CORBA_OBJECT_NIL;
+ }
+}
+
+
+