summaryrefslogtreecommitdiff
path: root/libnautilus
diff options
context:
space:
mode:
authorMaciej Stachowiak <mstachow@src.gnome.org>2000-12-21 21:41:46 +0000
committerMaciej Stachowiak <mstachow@src.gnome.org>2000-12-21 21:41:46 +0000
commit8c61df40034dacad8c71806c8065eda240ae47ef (patch)
treeb9e8ceaaa007bf16cfed8779b0f141d050e43d17 /libnautilus
parent114bc35edc42f6ef278befba53832ce772d80dc3 (diff)
downloadnautilus-8c61df40034dacad8c71806c8065eda240ae47ef.tar.gz
reviewed by: Darin Adler <darin@eazel.com>
* libnautilus/nautilus-view.c, libnautilus/nautilus-view.h (nautilus_view_construct, nautilus_view_construct_from_bonobo_control): New construct functions so it's possible for view implementations to be subclasses of NautilusView. (nautilus_view_new_from_bonobo_control): Implement in terms of construct function. * libnautilus/nautilus-view-standard-main.h, libnautilus/nautilus-view-standard-main.c: (nautilus_view_standard_main_multi, nautilus_view_standard_main, nautilus_view_create_from_get_type): New convenience functions that encapsulate and librarify most of the cut and pasted main.c code that is in every nautilus view. (object_destroyed, make_object): Helper functions. * libnautilus/Makefile.am: Add nautilus-view-standard-main.[ch] to build. * libnautilus/nautilus-view-component.idl: Add license header comment. * libnautilus-extensions/nautilus-gtk-macros.h: Lined up the backslashes to make it easier to read and edit the multi-line macros. * components/sample/README: Explain that all files in this directory have "WHAT YOU NEED TO CHANGE" comments. * components/sample/main.c (main): Implement in terms of `nautilus_view_standard_main' and removed most of the rest of this file. Now all you have to change when writing your own view is an include and some defines at the top of the file. Added "WHAT YOU NEED TO CHANGE" comment. * components/sample/nautilus-sample-content-view.h, components/sample/nautilus-sample-content-view.c: Added "WHAT YOU NEED TO CHANGE" comments. (nautilus_sample_content_view_get_type, nautilus_sample_content_view_initialize, nautilus_sample_content_view_destroy, load_location, sample_load_location_callback, bonobo_sample_callback, sample_merge_bonobo_items_callback): Changed everything around so NautilusSampleContentView inherits from Nautilus view, not GtkLabel (the widget that happens to be in the main content area). This makes a lot more sense. Also fix bug 2410 but including alternative code to nautilus-only macros. * components/sample/nautilus-sample-content-view.oafinfo: Added "WHAT YOU NEED TO CHANGE" comment. * components/sample/Makefile.am: Added "WHAT YOU NEED TO CHANGE" comment.
Diffstat (limited to 'libnautilus')
-rw-r--r--libnautilus/Makefile.am2
-rw-r--r--libnautilus/nautilus-view-component.idl27
-rw-r--r--libnautilus/nautilus-view-standard-main.c175
-rw-r--r--libnautilus/nautilus-view-standard-main.h71
-rw-r--r--libnautilus/nautilus-view.c29
-rw-r--r--libnautilus/nautilus-view.h13
6 files changed, 312 insertions, 5 deletions
diff --git a/libnautilus/Makefile.am b/libnautilus/Makefile.am
index 6c0fa3a05..17617476c 100644
--- a/libnautilus/Makefile.am
+++ b/libnautilus/Makefile.am
@@ -43,6 +43,7 @@ libnautilusinclude_HEADERS= \
nautilus-distributed-undo.h \
nautilus-view-component.h \
nautilus-view.h \
+ nautilus-view-standard-main.h \
nautilus-undo.h \
nautilus-undo-private.h \
$(NULL)
@@ -56,6 +57,7 @@ libnautilus_la_SOURCES= \
nautilus-undo-transaction.h \
nautilus-undo.c \
nautilus-view.c \
+ nautilus-view-standard-main.c \
$(NULL)
$(nautilus_view_component_idl_sources): nautilus_view_component_idl_stamp
diff --git a/libnautilus/nautilus-view-component.idl b/libnautilus/nautilus-view-component.idl
index 77a9619f1..6ed271ae5 100644
--- a/libnautilus/nautilus-view-component.idl
+++ b/libnautilus/nautilus-view-component.idl
@@ -1,5 +1,32 @@
/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */
+/*
+ * libnautilus: A library for nautilus view implementations.
+ *
+ * Copyright (C) 1999, 2000 Red Hat, Inc.
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors: Elliot Lee <sopwith@redhat.com>
+ * Darin Adler <darin@eazel.com>
+ * Maciej Stachowiak <mjs@eazel.com>
+ *
+ */
+
+
#ifndef NAUTILUS_VIEW_COMPONENT_IDL
#define NAUTILUS_VIEW_COMPONENT_IDL
diff --git a/libnautilus/nautilus-view-standard-main.c b/libnautilus/nautilus-view-standard-main.c
new file mode 100644
index 000000000..5beffa70e
--- /dev/null
+++ b/libnautilus/nautilus-view-standard-main.c
@@ -0,0 +1,175 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * libnautilus: A library for nautilus view implementations.
+ *
+ * Copyright (C) 1999, 2000 Red Hat, Inc.
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors: Maciej Stachowiak <mjs@eazel.com>
+ *
+ */
+
+/* nautilus-view-standard-main.c: Standard main functions for Nautilus
+ views, to reduce boilerplate code. */
+
+#include <config.h>
+#include "nautilus-view-standard-main.h"
+
+#include <libgnomeui/gnome-init.h>
+#include <bonobo/bonobo-generic-factory.h>
+#include <bonobo/bonobo-main.h>
+#include <gtk/gtkmain.h>
+#include <gtk/gtksignal.h>
+#include <liboaf/liboaf.h>
+#include <stdlib.h>
+
+typedef struct {
+ int object_count;
+ GList *view_iids;
+ NautilusViewCreateFunction create_function;
+ void *user_data;
+} CallbackData;
+
+
+static void
+object_destroyed (GtkObject *object,
+ CallbackData *callback_data)
+{
+ g_assert (GTK_IS_OBJECT (object));
+
+ callback_data->object_count--;
+ if (callback_data->object_count <= 0) {
+ gtk_main_quit ();
+ }
+}
+
+static BonoboObject *
+make_object (BonoboGenericFactory *factory,
+ const char *iid,
+ gpointer data)
+{
+ CallbackData *callback_data;
+ NautilusView *view;
+
+ callback_data = (CallbackData *) data;
+
+ g_assert (BONOBO_IS_GENERIC_FACTORY (factory));
+ g_assert (iid != NULL);
+ g_assert (callback_data != NULL);
+
+ /* Check that this is one of the types of object we know how to
+ * create.
+ */
+
+ if (g_list_find_custom (callback_data->view_iids,
+ (gpointer) iid, (GCompareFunc) strcmp) == NULL) {
+ return NULL;
+ }
+
+ view = callback_data->create_function (iid, callback_data->user_data);
+
+ /* Connect a handler that will get us out of the main loop
+ * when there are no more objects outstanding.
+ */
+ callback_data->object_count++;
+ gtk_signal_connect (GTK_OBJECT (view), "destroy",
+ object_destroyed, callback_data);
+
+ return BONOBO_OBJECT (view);
+}
+
+
+int
+nautilus_view_standard_main_multi (const char *executable_name,
+ const char *version,
+ int argc,
+ char **argv,
+ const char *factory_iid,
+ GList *view_iids,
+ NautilusViewCreateFunction create_function,
+ void *user_data)
+{
+ CORBA_ORB orb;
+ BonoboGenericFactory *factory;
+ CallbackData callback_data;
+ char *registration_id;
+
+ /* Initialize libraries. */
+ gnome_init_with_popt_table (executable_name, version,
+ argc, argv,
+ oaf_popt_options, 0, NULL);
+ orb = oaf_init (argc, argv);
+ bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
+
+ /* Fill in the callback data */
+ callback_data.object_count = 0;
+ callback_data.view_iids = view_iids;
+ callback_data.create_function = create_function;
+ callback_data.user_data = user_data;
+
+ /* Create the factory. */
+ registration_id = oaf_make_registration_id (factory_iid, g_getenv ("DISPLAY"));
+ factory = bonobo_generic_factory_new_multi (registration_id,
+ make_object,
+ &callback_data);
+ g_free (registration_id);
+
+
+ /* Loop until we have no more objects. */
+ do {
+ bonobo_main ();
+ } while (callback_data.object_count > 0);
+
+ /* Let the factory go. */
+ bonobo_object_unref (BONOBO_OBJECT (factory));
+
+ return EXIT_SUCCESS;
+}
+
+
+
+int
+nautilus_view_standard_main (const char *executable_name,
+ const char *version,
+ int argc,
+ char **argv,
+ const char *factory_iid,
+ const char *view_iid,
+ NautilusViewCreateFunction create_function,
+ void *user_data)
+{
+ GList node;
+
+ node.data = (gpointer) view_iid;
+
+ return nautilus_view_standard_main_multi (executable_name, version,
+ argc, argv,
+ factory_iid, &node,
+ create_function, user_data);
+}
+
+typedef GtkType (* TypeFunc) (void);
+
+
+
+NautilusView *
+nautilus_view_create_from_get_type_function (const char *iid, void *user_data)
+{
+ return NAUTILUS_VIEW (gtk_object_new (((TypeFunc) (user_data)) (), NULL));
+}
+
diff --git a/libnautilus/nautilus-view-standard-main.h b/libnautilus/nautilus-view-standard-main.h
new file mode 100644
index 000000000..5aea84aae
--- /dev/null
+++ b/libnautilus/nautilus-view-standard-main.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */
+
+/*
+ * libnautilus: A library for nautilus view implementations.
+ *
+ * Copyright (C) 1999, 2000 Red Hat, Inc.
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Maciej Stachowiak <mjs@eazel.com>
+ *
+ */
+
+/* nautilus-view-standard-main.h - An implementation of most of a
+ * typical main.c file for Nautilus views. Just call the function from
+ * main and pass it the right arguments. This should make writing
+ * Nautilus views simpler.
+ */
+
+#ifndef NAUTILUS_VIEW_STANDARD_MAIN_H
+#define NAUTILUS_VIEW_STANDARD_MAIN_H
+
+#include <libnautilus/nautilus-view.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef NautilusView * (*NautilusViewCreateFunction) (const char *iid, void *user_data);
+
+int nautilus_view_standard_main (const char *executable_name,
+ const char *version,
+ int argc,
+ char **argv,
+ const char *factory_iid,
+ const char *view_iid,
+ NautilusViewCreateFunction create_function,
+ void *user_data);
+
+int nautilus_view_standard_main_multi (const char *executable_name,
+ const char *version,
+ int argc,
+ char **argv,
+ const char *factory_iid,
+ GList *view_iids, /* GList<const char *> */
+ NautilusViewCreateFunction create_function,
+ void *user_data);
+
+/* standard handy create function (pass the _get_type function for the
+ * class as the user_data)
+ */
+NautilusView * nautilus_view_create_from_get_type_function (const char *iid, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* NAUTILUS_VIEW_STANDARD_MAIN_H */
diff --git a/libnautilus/nautilus-view.c b/libnautilus/nautilus-view.c
index 1464a42e5..5be86a4f3 100644
--- a/libnautilus/nautilus-view.c
+++ b/libnautilus/nautilus-view.c
@@ -20,7 +20,8 @@
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
- * Author: Elliot Lee <sopwith@redhat.com>
+ * Authors: Elliot Lee <sopwith@redhat.com>
+ * Maciej Stachowiak <mjs@eazel.com>
*
*/
@@ -285,9 +286,27 @@ nautilus_view_new (GtkWidget *widget)
NautilusView *
nautilus_view_new_from_bonobo_control (BonoboControl *control)
{
- NautilusView *view;
-
- view = NAUTILUS_VIEW (gtk_object_new (NAUTILUS_TYPE_VIEW, NULL));
+ return nautilus_view_construct_from_bonobo_control
+ (NAUTILUS_VIEW (gtk_object_new (NAUTILUS_TYPE_VIEW, NULL)),
+ control);
+}
+
+NautilusView *
+nautilus_view_construct (NautilusView *view,
+ GtkWidget *widget)
+{
+ return nautilus_view_construct_from_bonobo_control
+ (view, bonobo_control_new (widget));
+}
+
+
+NautilusView *
+nautilus_view_construct_from_bonobo_control (NautilusView *view,
+ BonoboControl *control)
+{
+ g_return_val_if_fail (NAUTILUS_IS_VIEW (view), NULL);
+ g_return_val_if_fail (BONOBO_IS_CONTROL (control), NULL);
+
view->details->control = control;
bonobo_object_add_interface (BONOBO_OBJECT (view), BONOBO_OBJECT (control));
nautilus_undo_set_up_bonobo_control (control);
@@ -295,6 +314,8 @@ nautilus_view_new_from_bonobo_control (BonoboControl *control)
return view;
}
+
+
static void
nautilus_view_destroy (GtkObject *object)
{
diff --git a/libnautilus/nautilus-view.h b/libnautilus/nautilus-view.h
index b2ab4bb85..436ceebb7 100644
--- a/libnautilus/nautilus-view.h
+++ b/libnautilus/nautilus-view.h
@@ -20,7 +20,8 @@
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
- * Author: Elliot Lee <sopwith@redhat.com>
+ * Authors: Elliot Lee <sopwith@redhat.com>
+ * Maciej Stachowiak <mjs@eazel.com>
*
*/
@@ -64,6 +65,8 @@ typedef struct {
GtkType nautilus_view_get_type (void);
NautilusView * nautilus_view_new (GtkWidget *widget);
NautilusView * nautilus_view_new_from_bonobo_control (BonoboControl *bonobo_control);
+
+
BonoboControl * nautilus_view_get_bonobo_control (NautilusView *view);
/* Calls to the Nautilus shell via the view frame. See the IDL for detailed comments. */
@@ -99,6 +102,14 @@ BonoboUIComponent *nautilus_view_set_up_ui (NautilusV
const char *ui_xml_file_name,
const char *application_name);
+
+/* `protected' functions for use by subclasses only. */
+NautilusView * nautilus_view_construct (NautilusView *view,
+ GtkWidget *widget);
+NautilusView * nautilus_view_construct_from_bonobo_control (NautilusView *view,
+ BonoboControl *bonobo_control);
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */