Commit 92be3115 authored by Ramiro Estrugo's avatar Ramiro Estrugo
Browse files

Add support for gettext. Add a post initialize callback so that callers

	* libnautilus/nautilus-view-standard-main.h:
	* libnautilus/nautilus-view-standard-main.c:
	(nautilus_view_standard_main_multi), (nautilus_view_standard_main):
	Add support for gettext.  Add a post initialize callback so that
	callers can initialize any component specific stuff before the
	main even loop begins (nautilus preferences for example)
	Update for standard main changes.
	Add documentation for these functions.  Also add criticals to make
	the code a little bit more robust.

	* components/help/hyperbola-main.c: (main):
	* components/history/nautilus-history-view.c: (main):
	* components/music/main.c: (main):
	* components/notes/nautilus-notes.c: (main):
	* components/sample/main.c: (main):
	* components/text/main.c: (main):
	* components/tree/main.c: (main):
	Update for standard main changes.  Make these a little simpler by
	putting gettext support in standard main itself.  Also, make sure
	that components that use preferences initialize them.

	* src/nautilus-main.c: (main):
	Dont do the preferences initialization if we are about to kill the
	nautilus shell.
parent 33f543ec
2001-04-12 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus/nautilus-view-standard-main.h:
* libnautilus/nautilus-view-standard-main.c:
(nautilus_view_standard_main_multi), (nautilus_view_standard_main):
Add support for gettext. Add a post initialize callback so that
callers can initialize any component specific stuff before the
main even loop begins (nautilus preferences for example)
Update for standard main changes.
Add documentation for these functions. Also add criticals to make
the code a little bit more robust.
* components/help/hyperbola-main.c: (main):
* components/history/nautilus-history-view.c: (main):
* components/music/main.c: (main):
* components/notes/nautilus-notes.c: (main):
* components/sample/main.c: (main):
* components/text/main.c: (main):
* components/tree/main.c: (main):
Update for standard main changes. Make these a little simpler by
putting gettext support in standard main itself. Also, make sure
that components that use preferences initialize them.
* src/nautilus-main.c: (main):
Dont do the preferences initialization if we are about to kill the
nautilus shell.
2001-04-12 Seth Nickell <snickell@stanford.edu>
 
* libnautilus-extensions/Makefile.am:
......
......@@ -25,6 +25,7 @@
#include <bonobo.h>
#include <gnome.h>
#include <liboaf/liboaf.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include "hyperbola-nav.h"
......@@ -104,6 +105,8 @@ main (int argc, char *argv[])
NULL);
g_free (registration_id);
nautilus_global_preferences_initialize ();
do {
bonobo_main ();
} while (object_count > 0);
......
......@@ -28,15 +28,17 @@
#include <config.h>
#include <bonobo/bonobo-ui-util.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <gtk/gtkclist.h>
#include <gtk/gtkscrolledwindow.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libnautilus-extensions/nautilus-bookmark.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus/nautilus-view-standard-main.h>
#define FACTORY_IID "OAFIID:nautilus_history_view_factory:912d6634-d18f-40b6-bb83-bdfe16f1d15e"
#define VIEW_IID "OAFIID:nautilus_history_view:a7a85bdd-2ecf-4bc1-be7c-ed328a29aacb"
#define NAUTILUS_TYPE_HISTORY_VIEW (nautilus_history_view_get_type ())
#define NAUTILUS_HISTORY_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_HISTORY_VIEW, NautilusHistoryView))
#define NAUTILUS_HISTORY_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_HISTORY_VIEW, NautilusHistoryViewClass))
......@@ -331,16 +333,15 @@ nautilus_history_view_destroy (GtkObject *object)
int
main (int argc, char *argv[])
{
/* Initialize gettext support */
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
return nautilus_view_standard_main ("nautilus_history-view", VERSION,
argc, argv,
"OAFIID:nautilus_history_view_factory:912d6634-d18f-40b6-bb83-bdfe16f1d15e",
"OAFIID:nautilus_history_view:a7a85bdd-2ecf-4bc1-be7c-ed328a29aacb",
return nautilus_view_standard_main ("nautilus_history-view",
VERSION,
PACKAGE,
GNOMELOCALEDIR,
argc,
argv,
FACTORY_IID,
VIEW_IID,
nautilus_view_create_from_get_type_function,
nautilus_global_preferences_initialize,
nautilus_history_view_get_type);
}
......@@ -26,27 +26,26 @@
*/
#include <config.h>
#include <gnome.h>
#include "nautilus-music-view.h"
#include <libnautilus/nautilus-view-standard-main.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#define FACTORY_IID "OAFIID:nautilus_music_view_factory:1be0c129-87cd-4daa-9d3a-94397de9bce2"
#define VIEW_IID "OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391"
#define EXECUTABLE_NAME "nautilus-music-view"
#define GET_TYPE_FUNCTION nautilus_music_view_get_type
int
main (int argc, char *argv[])
{
/* Initialize gettext support */
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
return nautilus_view_standard_main (EXECUTABLE_NAME, VERSION,
argc, argv,
FACTORY_IID, VIEW_IID,
return nautilus_view_standard_main ("nautilus-music-view",
VERSION,
PACKAGE,
GNOMELOCALEDIR,
argc,
argv,
FACTORY_IID,
VIEW_IID,
nautilus_view_create_from_get_type_function,
GET_TYPE_FUNCTION);
nautilus_global_preferences_initialize,
nautilus_music_view_get_type);
}
......@@ -34,11 +34,10 @@
#include <gtk/gtkmain.h>
#include <gtk/gtktext.h>
#include <gtk/gtkvbox.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libnautilus-extensions/nautilus-file-attributes.h>
#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-font-factory.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus/nautilus-clipboard.h>
#include <libnautilus/nautilus-view-standard-main.h>
......@@ -429,16 +428,15 @@ main(int argc, char *argv[])
(G_LOG_DOMAIN, g_log_domain_glib, "Gdk", "Gtk", "GnomeVFS", "GnomeUI", "Bonobo", NULL);
}
/* Initialize gettext support */
#ifdef ENABLE_NLS /* sadly we need this ifdef because otherwise the following get empty statement warnings */
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
return nautilus_view_standard_main ("nautilus-notes", VERSION,
argc, argv,
return nautilus_view_standard_main ("nautilus-notes",
VERSION,
PACKAGE,
GNOMELOCALEDIR,
argc,
argv,
"OAFIID:nautilus_notes_view_factory:4b39e388-3ca2-4d68-9f3d-c137ee62d5b0",
"OAFIID:nautilus_notes_view:7f04c3cb-df79-4b9a-a577-38b19ccd4185",
make_notes_view,
nautilus_global_preferences_initialize,
NULL);
}
......@@ -31,6 +31,7 @@
*/
#include <config.h>
#include "nautilus-sample-content-view.h"
#include <libnautilus/nautilus-view-standard-main.h>
......@@ -46,13 +47,18 @@
/* CHANGE: Change to the get_type function for your view class */
#define GET_TYPE_FUNCTION nautilus_sample_content_view_get_type
int
main (int argc, char *argv[])
{
return nautilus_view_standard_main (EXECUTABLE_NAME, VERSION,
argc, argv,
FACTORY_IID, VIEW_IID,
return nautilus_view_standard_main (EXECUTABLE_NAME,
VERSION,
NULL, /* Could be PACKAGE */
NULL, /* Could be GNOMELOCALEDIR */
argc,
argv,
FACTORY_IID,
VIEW_IID,
nautilus_view_create_from_get_type_function,
NULL,
GET_TYPE_FUNCTION);
}
......@@ -26,27 +26,26 @@
*/
#include <config.h>
#include <gnome.h>
#include "nautilus-text-view.h"
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus/nautilus-view-standard-main.h>
#define FACTORY_IID "OAFIID:nautilus_text_view_factory:124ae209-d356-418f-8757-54e071cb3a21"
#define VIEW_IID "OAFIID:nautilus_text_view:fa466311-17c1-435c-8231-c9fc434b6437"
#define EXECUTABLE_NAME "nautilus-text-view"
#define GET_TYPE_FUNCTION nautilus_text_view_get_type
int
main (int argc, char *argv[])
{
/* Initialize gettext support */
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
return nautilus_view_standard_main (EXECUTABLE_NAME, VERSION,
argc, argv,
FACTORY_IID, VIEW_IID,
return nautilus_view_standard_main ("nautilus-text-view",
VERSION,
PACKAGE,
GNOMELOCALEDIR,
argc,
argv,
FACTORY_IID,
VIEW_IID,
nautilus_view_create_from_get_type_function,
GET_TYPE_FUNCTION);
nautilus_global_preferences_initialize,
nautilus_text_view_get_type);
}
......@@ -25,21 +25,21 @@
#include "nautilus-tree-view-iids.h"
#include "nautilus-tree-view.h"
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus/nautilus-view-standard-main.h>
int
main (int argc, char *argv[])
{
/* Initialize gettext support */
#ifdef ENABLE_NLS /* sadly we need this ifdef because otherwise the following get empty statement warnings */
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
return nautilus_view_standard_main ("nautilus-tree-view", VERSION,
argc, argv,
return nautilus_view_standard_main ("nautilus-tree-view",
VERSION,
PACKAGE,
GNOMELOCALEDIR,
argc,
argv,
TREE_VIEW_FACTORY_IID,
TREE_VIEW_IID,
nautilus_view_create_from_get_type_function,
nautilus_global_preferences_initialize,
nautilus_tree_view_get_type);
}
......@@ -30,11 +30,13 @@
#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 <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-init.h>
#include <libgnomevfs/gnome-vfs-init.h>
#include <liboaf/liboaf.h>
#include <stdlib.h>
......@@ -94,22 +96,75 @@ make_object (BonoboGenericFactory *factory,
return BONOBO_OBJECT (view);
}
/**
* nautilus_view_standard_main_multi
*
* A version of nautilus_view_standard_main that accepts multiple view
* IIDs.
*
* @executable_name: The name of the executable binary.
* @version: Component version. Usually VERSION.
* @gettext_package_name: Package name for gettext support. Usually PACKAGE.
* Can be NULL, in which case the component will not
* have gettext support and translations might not
* work
* @gettext_locale_directory: Locale directory for gettext support. Usually
* GNOMELOCALEDIR. Must not be NULL if
* @gettext_package_name is not NULL.
* @argc: Command line argument count.
* @argv: Command line argument vector.
* @factory_iid: The components's factory IID.
* @view_iids: A GList of NautilusView IIDs.
* @create_function: Function called to create the NautilusView instance.
* @post_initialize_callback: An optional callback which is invoked after
* all modules have been initialized (gtk, bonobo,
* gnome-vfs, etc.) but before the execution of
* the main event loop.
* @user_data: User data for @create_function.
**/
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)
nautilus_view_standard_main_multi (const char *executable_name,
const char *version,
const char *gettext_package_name,
const char *gettext_locale_directory,
int argc,
char **argv,
const char *factory_iid,
GList *view_iids,
NautilusViewCreateFunction create_function,
GVoidFunc post_initialize_callback,
void *user_data)
{
CORBA_ORB orb;
BonoboGenericFactory *factory;
CallbackData callback_data;
char *registration_id;
g_return_val_if_fail (executable_name != NULL, EXIT_FAILURE);
g_return_val_if_fail (version != NULL, EXIT_FAILURE);
g_return_val_if_fail (argc > 0, EXIT_FAILURE);
g_return_val_if_fail (argv != NULL, EXIT_FAILURE);
g_return_val_if_fail (argv[0] != NULL, EXIT_FAILURE);
g_return_val_if_fail (factory_iid != NULL, EXIT_FAILURE);
g_return_val_if_fail (g_list_length (view_iids) > 0, EXIT_FAILURE);
g_return_val_if_fail (create_function != NULL, EXIT_FAILURE);
if (gettext_package_name != NULL) {
g_return_val_if_fail (gettext_locale_directory != NULL, EXIT_FAILURE);
}
if (gettext_locale_directory != NULL) {
g_return_val_if_fail (gettext_package_name != NULL, EXIT_FAILURE);
}
/* Initialize gettext support if needed */
#ifdef ENABLE_NLS
if (gettext_package_name != NULL
&& gettext_locale_directory != NULL) {
bindtextdomain (gettext_package_name, gettext_locale_directory);
textdomain (gettext_package_name);
}
#endif
/* Disable session manager connection */
gnome_client_disable_master_connection ();
......@@ -117,8 +172,7 @@ nautilus_view_standard_main_multi (const char *executable_name,
orb = oaf_init (argc, argv);
/* Initialize libraries. */
gnome_init (executable_name, version,
argc, argv);
gnome_init (executable_name, version, argc, argv);
gdk_rgb_init ();
g_thread_init (NULL);
gnome_vfs_init ();
......@@ -137,6 +191,9 @@ nautilus_view_standard_main_multi (const char *executable_name,
&callback_data);
g_free (registration_id);
if (post_initialize_callback != NULL) {
(* post_initialize_callback) ();
}
/* Loop until we have no more objects. */
do {
......@@ -151,32 +208,83 @@ nautilus_view_standard_main_multi (const char *executable_name,
return EXIT_SUCCESS;
}
/**
* nautilus_view_standard_main
*
* 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.
*
* @executable_name: The name of the executable binary.
* @version: Component version. Usually VERSION.
* @gettext_package_name: Package name for gettext support. Usually PACKAGE.
* Can be NULL, in which case the component will not
* have gettext support and translations might not
* work
* @gettext_locale_directory: Locale directory for gettext support. Usually
* GNOMELOCALEDIR. Must not be NULL if
* @gettext_package_name is not NULL.
* @argc: Command line argument count.
* @argv: Command line argument vector.
* @factory_iid: The components's factory IID.
* @view_iid: The component's NautilusView IID.
* @create_function: Function called to create the NautilusView instance.
* @post_initialize_callback: An optional callback which is invoked after
* all modules have been initialized (gtk, bonobo,
* gnome-vfs, etc.) but before the execution of
* the main event loop.
* @user_data: User data for @create_function.
**/
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)
nautilus_view_standard_main (const char *executable_name,
const char *version,
const char *gettext_package_name,
const char *gettext_locale_directory,
int argc,
char **argv,
const char *factory_iid,
const char *view_iid,
NautilusViewCreateFunction create_function,
GVoidFunc post_initialize_callback,
void *user_data)
{
GList node;
GList node;
g_return_val_if_fail (executable_name != NULL, EXIT_FAILURE);
g_return_val_if_fail (version != NULL, EXIT_FAILURE);
g_return_val_if_fail (argc > 0, EXIT_FAILURE);
g_return_val_if_fail (argv != NULL, EXIT_FAILURE);
g_return_val_if_fail (argv[0] != NULL, EXIT_FAILURE);
g_return_val_if_fail (factory_iid != NULL, EXIT_FAILURE);
g_return_val_if_fail (view_iid != NULL, EXIT_FAILURE);
g_return_val_if_fail (create_function != NULL, EXIT_FAILURE);
if (gettext_package_name != NULL) {
g_return_val_if_fail (gettext_locale_directory != NULL, EXIT_FAILURE);
}
if (gettext_locale_directory != NULL) {
g_return_val_if_fail (gettext_package_name != NULL, EXIT_FAILURE);
}
node.data = (gpointer) view_iid;
return nautilus_view_standard_main_multi (executable_name, version,
argc, argv,
factory_iid, &node,
create_function, user_data);
node.next = NULL;
node.prev = NULL;
return nautilus_view_standard_main_multi (executable_name,
version,
gettext_package_name,
gettext_locale_directory,
argc,
argv,
factory_iid,
&node,
create_function,
post_initialize_callback,
user_data);
}
typedef GtkType (* TypeFunc) (void);
NautilusView *
nautilus_view_create_from_get_type_function (const char *iid, void *user_data)
{
......
......@@ -41,20 +41,26 @@ typedef NautilusView * (*NautilusViewCreateFunction) (const char *iid, void *use
int nautilus_view_standard_main (const char *executable_name,
const char *version,
const char *gettext_package_name,
const char *gettext_locale_directory,
int argc,
char **argv,
const char *factory_iid,
const char *view_iid,
NautilusViewCreateFunction create_function,
GVoidFunc post_initialize_callback,
void *user_data);
int nautilus_view_standard_main_multi (const char *executable_name,
const char *version,
const char *gettext_package_name,
const char *gettext_locale_directory,
int argc,
char **argv,
const char *factory_iid,
GList *view_iids, /* GList<const char *> */
NautilusViewCreateFunction create_function,
GVoidFunc post_initialize_callback,
void *user_data);
/* standard handy create function (pass the _get_type function for the
......
......@@ -240,11 +240,15 @@ main (int argc, char *argv[])
/* Initialize preferences. This is needed so that proper
* defaults are available before any preference peeking
* happens.
* happens. Do this only if we are not goinh to kill the
* nautilus shell.
*/
nautilus_global_preferences_initialize ();
start_desktop = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP);
if (!kill_shell) {
nautilus_global_preferences_initialize ();
start_desktop = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP);
} else {
start_desktop = FALSE;
}
/* Do either the self-check or the real work. */
if (perform_self_check) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment