[gedit/wip/gtkapp: 11/26] Initial port to GtkApplication



commit ccd7941965064cc683c57beb10a624729ee170f1
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat May 5 21:46:01 2012 +0200

    Initial port to GtkApplication

 gedit/gedit-app-osx.c |    2 +-
 gedit/gedit-app.c     |  145 +++++++++++++++++++++++-----------------
 gedit/gedit-app.h     |   31 ++-------
 gedit/gedit-window.c  |    6 +-
 gedit/gedit-window.h  |   28 ++------
 gedit/gedit.c         |  175 ++++++++++--------------------------------------
 6 files changed, 137 insertions(+), 250 deletions(-)
---
diff --git a/gedit/gedit-app-osx.c b/gedit/gedit-app-osx.c
index 2b07fe8..27bdd2e 100644
--- a/gedit/gedit-app-osx.c
+++ b/gedit/gedit-app-osx.c
@@ -369,7 +369,7 @@ static void
 on_osx_will_terminate (GtkOSXApplication *osxapp,
                        GeditAppOSX       *app)
 {
-	_gedit_app_quit (GEDIT_APP (app));
+	g_application_quit (G_APPLICATION (app));
 }
 
 static gboolean
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index b2f8d3b..322aa80 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -74,7 +74,6 @@ enum
 
 struct _GeditAppPrivate
 {
-	GList	          *windows;
 	GeditWindow       *active_window;
 
 	GeditLockdownMask  lockdown;
@@ -90,17 +89,7 @@ struct _GeditAppPrivate
 
 static GeditApp *app_instance = NULL;
 
-G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, G_TYPE_OBJECT)
-
-static void
-gedit_app_finalize (GObject *object)
-{
-	GeditApp *app = GEDIT_APP (object); 
-
-	g_list_free (app->priv->windows);
-
-	G_OBJECT_CLASS (gedit_app_parent_class)->finalize (object);
-}
+G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, GTK_TYPE_APPLICATION)
 
 static void
 gedit_app_dispose (GObject *object)
@@ -247,6 +236,36 @@ gedit_app_set_window_title_impl (GeditApp    *app,
 	gtk_window_set_title (GTK_WINDOW (window), title);
 }
 
+static void
+gedit_app_startup (GApplication *application)
+{
+	const gchar *dir;
+	gchar *icon_dir;
+
+	G_APPLICATION_CLASS (gedit_app_parent_class)->startup (application);
+
+	gedit_debug_message (DEBUG_APP, "Set icon");
+
+	dir = gedit_dirs_get_gedit_data_dir ();
+	icon_dir = g_build_filename (dir, "icons", NULL);
+
+	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_dir);
+	g_free (icon_dir);
+}
+
+static void
+gedit_app_activate (GApplication *application)
+{
+	GeditWindow *window;
+
+	gedit_debug_message (DEBUG_APP, "Create main window");
+	window = gedit_app_create_window (GEDIT_APP (application), NULL);
+	gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window));
+
+	gedit_debug_message (DEBUG_APP, "Show window");
+	gtk_widget_show (GTK_WIDGET (window));
+}
+
 static gboolean
 ensure_user_config_dir (void)
 {
@@ -370,7 +389,7 @@ save_print_settings (GeditApp *app)
 }
 
 static void
-gedit_app_quit_impl (GeditApp *app)
+gedit_app_shutdown (GApplication *app)
 {
 	gedit_debug_message (DEBUG_APP, "Quitting\n");
 
@@ -378,10 +397,10 @@ gedit_app_quit_impl (GeditApp *app)
 	ensure_user_config_dir ();
 
 	save_accels ();
-	save_page_setup (app);
-	save_print_settings (app);
+	save_page_setup (GEDIT_APP (app));
+	save_print_settings (GEDIT_APP (app));
 
-	gtk_main_quit ();
+	G_APPLICATION_CLASS (gedit_app_parent_class)->shutdown (app);
 }
 
 static void
@@ -449,22 +468,18 @@ window_delete_event (GeditWindow *window,
 	return TRUE;
 }
 
-void
-_gedit_app_quit (GeditApp *app)
-{
-	GEDIT_APP_GET_CLASS (app)->quit (app);
-}
-
 static void
-window_destroy (GeditWindow *window, 
+window_destroy (GeditWindow *window,
 		GeditApp    *app)
 {
-	app->priv->windows = g_list_remove (app->priv->windows,
-					    window);
+	GList *windows;
+
+	gtk_application_remove_window (GTK_APPLICATION (app), GTK_WINDOW (window));
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
 
 	if (window == app->priv->active_window)
 	{
-		set_active_window (app, app->priv->windows != NULL ? app->priv->windows->data : NULL);
+		set_active_window (app, windows != NULL ? windows->data : NULL);
 	}
 
 /* CHECK: I don't think we have to disconnect this function, since windows
@@ -477,14 +492,14 @@ window_destroy (GeditWindow *window,
 					      G_CALLBACK (window_destroy),
 					      app);
 */
-	if (app->priv->windows == NULL)
+	if (windows == NULL)
 	{
 		if (!GEDIT_APP_GET_CLASS (app)->last_window_destroyed (app, window))
 		{
 			return;
 		}
 
-		_gedit_app_quit (app);
+		g_application_quit (G_APPLICATION (app));
 	}
 }
 
@@ -492,7 +507,8 @@ static GeditWindow *
 gedit_app_create_window_impl (GeditApp *app)
 {
 	GeditWindow *window;
-	gboolean isfirst;
+	GList *windows;
+	gboolean is_first;
 	
 	/*
 	 * We need to be careful here, there is a race condition:
@@ -501,29 +517,29 @@ gedit_app_create_window_impl (GeditApp *app)
 	 * is never NULL when at least a window exists.
 	 */
 
-	isfirst = (app->priv->windows == NULL);
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
+	is_first = (windows == NULL);
 	
-	window = g_object_new (GEDIT_TYPE_WINDOW, NULL);
+	window = g_object_new (GEDIT_TYPE_WINDOW, "application", app, NULL);
 
-	if (isfirst)
+	if (is_first)
 	{
 		set_active_window (app, window);
 	}
 
-	app->priv->windows = g_list_prepend (app->priv->windows,
-					     window);
+	gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (window));
 
 	gedit_debug_message (DEBUG_APP, "Window created");
 
-	g_signal_connect (window, 
+	g_signal_connect (window,
 			  "focus_in_event",
-			  G_CALLBACK (window_focus_in_event), 
+			  G_CALLBACK (window_focus_in_event),
 			  app);
 	g_signal_connect (window,
 			  "delete_event",
 			  G_CALLBACK (window_delete_event),
-			  app);			  
-	g_signal_connect (window, 
+			  app);
+	g_signal_connect (window,
 			  "destroy",
 			  G_CALLBACK (window_destroy),
 			  app);
@@ -540,18 +556,21 @@ static void
 gedit_app_class_init (GeditAppClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GApplicationClass *app_class = G_APPLICATION_CLASS (klass);
 
-	object_class->finalize = gedit_app_finalize;
 	object_class->dispose = gedit_app_dispose;
 	object_class->get_property = gedit_app_get_property;
 	object_class->constructor = gedit_app_constructor;
 	object_class->constructed = gedit_app_constructed;
 
+	app_class->startup = gedit_app_startup;
+	app_class->activate = gedit_app_activate;
+	app_class->shutdown = gedit_app_shutdown;
+
 	klass->last_window_destroyed = gedit_app_last_window_destroyed_impl;
 	klass->show_help = gedit_app_show_help_impl;
 	klass->help_link_id = gedit_app_help_link_id_impl;
 	klass->set_window_title = gedit_app_set_window_title_impl;
-	klass->quit = gedit_app_quit_impl;
 	klass->create_window = gedit_app_create_window_impl;
 	klass->ready = gedit_app_ready_impl;
 
@@ -691,6 +710,7 @@ gedit_app_init (GeditApp *app)
 	                            app);
 }
 
+/* FIXME: lets kill this method */
 /**
  * gedit_app_get_default:
  *
@@ -719,7 +739,10 @@ gedit_app_get_default (void)
 #endif
 #endif
 
-	return GEDIT_APP (g_object_new (type, NULL));
+	return GEDIT_APP (g_object_new (type,
+	                                "application-id", "org.gnome.Gedit",
+	                                // FIXME: should be HANDLES_COMMAND_LINE
+	                                NULL));
 }
 
 /* Generates a unique string for a window role */
@@ -840,6 +863,7 @@ _gedit_app_restore_window (GeditApp    *app,
 	return window;
 }
 
+/* FIXME: lets kill this method */
 /**
  * gedit_app_get_windows:
  * @app: the #GeditApp
@@ -854,7 +878,7 @@ gedit_app_get_windows (GeditApp *app)
 {
 	g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
 
-	return app->priv->windows;
+	return gtk_application_get_windows (GTK_APPLICATION (app));
 }
 
 /**
@@ -959,8 +983,7 @@ _gedit_app_get_window_in_viewport (GeditApp  *app,
 				   gint       viewport_y)
 {
 	GeditWindow *window;
-
-	GList *l;
+	GList *windows, *l;
 
 	g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
 
@@ -973,7 +996,8 @@ _gedit_app_get_window_in_viewport (GeditApp  *app,
 		return window;
 
 	/* otherwise try to see if there is a window on this workspace */
-	for (l = app->priv->windows; l != NULL; l = l->next)
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
+	for (l = windows; l != NULL; l = l->next)
 	{
 		window = l->data;
 
@@ -997,18 +1021,15 @@ GList *
 gedit_app_get_documents	(GeditApp *app)
 {
 	GList *res = NULL;
-	GList *windows;
+	GList *windows, *l;
 
 	g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
 
-	windows = app->priv->windows;
-
-	while (windows != NULL)
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
+	for (l = windows; l != NULL; l = g_list_next (l))
 	{
 		res = g_list_concat (res,
-				     gedit_window_get_documents (GEDIT_WINDOW (windows->data)));
-
-		windows = g_list_next (windows);
+				     gedit_window_get_documents (GEDIT_WINDOW (l->data)));
 	}
 
 	return res;
@@ -1027,18 +1048,15 @@ GList *
 gedit_app_get_views (GeditApp *app)
 {
 	GList *res = NULL;
-	GList *windows;
+	GList *windows, *l;
 
 	g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
 
-	windows = app->priv->windows;
-
-	while (windows != NULL)
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
+	for (l = windows; l != NULL; l = g_list_next (l))
 	{
 		res = g_list_concat (res,
-				     gedit_window_get_views (GEDIT_WINDOW (windows->data)));
-
-		windows = g_list_next (windows);
+				     gedit_window_get_views (GEDIT_WINDOW (l->data)));
 	}
 
 	return res;
@@ -1102,11 +1120,14 @@ gedit_app_process_window_event (GeditApp    *app,
 static void
 app_lockdown_changed (GeditApp *app)
 {
-	GList *l;
+	GList *windows, *l;
 
-	for (l = app->priv->windows; l != NULL; l = l->next)
+	windows = gtk_application_get_windows (GTK_APPLICATION (app));
+	for (l = windows; l != NULL; l = g_list_next (l))
+	{
 		_gedit_window_set_lockdown (GEDIT_WINDOW (l->data),
-					    app->priv->lockdown);
+		                            app->priv->lockdown);
+	}
 
 	g_object_notify (G_OBJECT (app), "lockdown");
 }
diff --git a/gedit/gedit-app.h b/gedit/gedit-app.h
index 9b9b8c7..68e57ef 100644
--- a/gedit/gedit-app.h
+++ b/gedit/gedit-app.h
@@ -37,9 +37,6 @@
 
 G_BEGIN_DECLS
 
-/*
- * Type checking and casting macros
- */
 #define GEDIT_TYPE_APP              (gedit_app_get_type())
 #define GEDIT_APP(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_APP, GeditApp))
 #define GEDIT_APP_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_APP, GeditAppClass))
@@ -47,30 +44,21 @@ G_BEGIN_DECLS
 #define GEDIT_IS_APP_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_APP))
 #define GEDIT_APP_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_APP, GeditAppClass))
 
-/* Private structure type */
+typedef struct _GeditApp        GeditApp;
+typedef struct _GeditAppClass   GeditAppClass;
 typedef struct _GeditAppPrivate GeditAppPrivate;
 
-/*
- * Main object structure
- */
-typedef struct _GeditApp GeditApp;
-
 struct _GeditApp
 {
-	GObject parent;
+	GtkApplication parent;
 
 	/*< private > */
 	GeditAppPrivate *priv;
 };
 
-/*
- * Class definition
- */
-typedef struct _GeditAppClass GeditAppClass;
-
 struct _GeditAppClass
 {
-	GObjectClass parent_class;
+	GtkApplicationClass parent_class;
 
 	gboolean (*last_window_destroyed)	(GeditApp    *app,
 	                                         GeditWindow *window);
@@ -88,8 +76,6 @@ struct _GeditAppClass
 	                                         GeditWindow *window,
 	                                         const gchar *title);
 
-	void (*quit)                            (GeditApp    *app);
-
 	GeditWindow *(*create_window)		(GeditApp    *app);
 
 	gboolean (*process_window_event)	(GeditApp    *app,
@@ -113,9 +99,7 @@ typedef enum
 /* We need to define this here to avoid problems with bindings and gsettings */
 #define GEDIT_LOCKDOWN_ALL 0xF
 
-/*
- * Public methods
- */
+/* Public methods */
 GType 		 gedit_app_get_type 			(void) G_GNUC_CONST;
 
 GeditApp 	*gedit_app_get_default			(void);
@@ -147,9 +131,7 @@ gboolean	gedit_app_process_window_event		(GeditApp    *app,
 							 GeditWindow *window,
 							 GdkEvent    *event);
 
-/*
- * Non exported functions
- */
+/* Non exported functions */
 GeditWindow	*_gedit_app_restore_window		(GeditApp    *app,
 							 const gchar *role);
 GeditWindow	*_gedit_app_get_window_in_viewport	(GeditApp     *app,
@@ -178,7 +160,6 @@ void			 _gedit_app_set_default_print_settings	(GeditApp         *app,
 								 GtkPrintSettings *settings);
 
 GObject			*_gedit_app_get_settings		(GeditApp  *app);
-void                     _gedit_app_quit                        (GeditApp  *app);
 void                     _gedit_app_ready                       (GeditApp  *app);
 
 G_END_DECLS
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 39fe0f1..a710cf2 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -3193,7 +3193,7 @@ fullscreen_controls_build (GeditWindow *window)
 	priv->fullscreen_controls = gtk_window_new (GTK_WINDOW_POPUP);
 
 	gtk_window_set_transient_for (GTK_WINDOW (priv->fullscreen_controls),
-				      &window->window);
+				      GTK_WINDOW (&window->window));
 	
 	/* popup toolbar */
 	toolbar = gtk_ui_manager_get_widget (priv->manager, "/FullscreenToolBar");
@@ -4863,7 +4863,7 @@ _gedit_window_fullscreen (GeditWindow *window)
 		return;
 
 	/* Go to fullscreen mode and hide bars */
-	gtk_window_fullscreen (&window->window);
+	gtk_window_fullscreen (GTK_WINDOW (&window->window));
 
 	gedit_multi_notebook_foreach_notebook (window->priv->multi_notebook,
 					       (GtkCallback)hide_notebook_tabs,
@@ -4907,7 +4907,7 @@ _gedit_window_unfullscreen (GeditWindow *window)
 		return;
 
 	/* Unfullscreen and show bars */
-	gtk_window_unfullscreen (&window->window);
+	gtk_window_unfullscreen (GTK_WINDOW (&window->window));
 
 	gedit_multi_notebook_foreach_notebook (window->priv->multi_notebook,
 					       (GtkCallback)show_notebook_tabs,
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index 860be5c..16ad51f 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -49,10 +49,7 @@ typedef enum
 	GEDIT_WINDOW_STATE_ERROR		= 1 << 4,
 	GEDIT_WINDOW_STATE_SAVING_SESSION	= 1 << 5
 } GeditWindowState;
-	
-/*
- * Type checking and casting macros
- */
+
 #define GEDIT_TYPE_WINDOW              (gedit_window_get_type())
 #define GEDIT_WINDOW(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_WINDOW, GeditWindow))
 #define GEDIT_WINDOW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_WINDOW, GeditWindowClass))
@@ -60,30 +57,21 @@ typedef enum
 #define GEDIT_IS_WINDOW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_WINDOW))
 #define GEDIT_WINDOW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_WINDOW, GeditWindowClass))
 
-/* Private structure type */
+typedef struct _GeditWindow        GeditWindow;
+typedef struct _GeditWindowClass   GeditWindowClass;
 typedef struct _GeditWindowPrivate GeditWindowPrivate;
 
-/*
- * Main object structure
- */
-typedef struct _GeditWindow GeditWindow;
-
 struct _GeditWindow
 {
-	GtkWindow window;
+	GtkApplicationWindow window;
 
 	/*< private > */
 	GeditWindowPrivate *priv;
 };
 
-/*
- * Class definition
- */
-typedef struct _GeditWindowClass GeditWindowClass;
-
 struct _GeditWindowClass
 {
-	GtkWindowClass parent_class;
+	GtkApplicationWindowClass parent_class;
 
 	/* Signals */
 	void	 (* tab_added)      	(GeditWindow *window,
@@ -93,13 +81,11 @@ struct _GeditWindowClass
 	void	 (* tabs_reordered) 	(GeditWindow *window);
 	void	 (* active_tab_changed)	(GeditWindow *window,
 				     	 GeditTab    *tab);
-	void	 (* active_tab_state_changed)	
+	void	 (* active_tab_state_changed)
 					(GeditWindow *window);
 };
 
-/*
- * Public methods
- */
+/* Public methods */
 GType 		 gedit_window_get_type 			(void) G_GNUC_CONST;
 
 GeditTab	*gedit_window_create_tab		(GeditWindow         *window,
diff --git a/gedit/gedit.c b/gedit/gedit.c
index 6658799..448f3cc 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -37,151 +37,25 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include "gedit-command-line.h"
-#include "gedit-dbus.h"
-
 #include "gedit-app.h"
-#include "gedit-encodings.h"
 
-#include "gedit-commands.h"
 #include "gedit-debug.h"
 #include "gedit-dirs.h"
-#include "gedit-encodings.h"
 #include "gedit-plugins-engine.h"
 #include "gedit-session.h"
-#include "gedit-utils.h"
-#include "gedit-window.h"
 
 #ifndef ENABLE_GVFS_METADATA
 #include "gedit-metadata-manager.h"
 #define METADATA_FILE "gedit-metadata.xml"
 #endif
 
-static void
-gedit_main_window (void)
-{
-	GSList *file_list;
-	GeditWindow *window;
-	GeditCommandLine *command_line;
-	GeditApp *app;
-	gboolean doc_created = FALSE;
-	const gchar *geometry;
-
-	app = gedit_app_get_default ();
-
-	gedit_debug_message (DEBUG_APP, "Create main window");
-	window = gedit_app_create_window (app, NULL);
-
-	command_line = gedit_command_line_get_default ();
-	file_list = gedit_command_line_get_file_list (command_line);
-
-	if (file_list != NULL)
-	{
-		GSList *loaded;
-		const GeditEncoding *encoding;
-		gint line_position;
-		gint column_position;
-
-		encoding = gedit_command_line_get_encoding (command_line);
-		line_position = gedit_command_line_get_line_position (command_line);
-		column_position = gedit_command_line_get_column_position (command_line);
-
-		gedit_debug_message (DEBUG_APP, "Load files");
-		loaded = _gedit_cmd_load_files_from_prompt (window,
-		                                            file_list,
-		                                            encoding,
-		                                            line_position,
-		                                            column_position);
-
-		doc_created = loaded != NULL;
-		g_slist_free (loaded);
-	}
-
-	if (!doc_created || gedit_command_line_get_new_document (command_line))
-	{
-		gedit_debug_message (DEBUG_APP, "Create tab");
-		gedit_window_create_tab (window, TRUE);
-	}
-
-	geometry = gedit_command_line_get_geometry (command_line);
-
-	gedit_debug_message (DEBUG_APP, "Show window");
-	gtk_widget_show (GTK_WIDGET (window));
-
-	if (geometry)
-	{
-		gtk_window_parse_geometry (GTK_WINDOW (window),
-		                           geometry);
-	}
-}
-
-static void
-gedit_main (gboolean service)
-{
-	GeditPluginsEngine *engine;
-	GeditApp *app;
-	const gchar *dir;
-	gchar *icon_dir;
-
-	gedit_debug_message (DEBUG_APP, "Set icon");
-
-	dir = gedit_dirs_get_gedit_data_dir ();
-	icon_dir = g_build_filename (dir, "icons", NULL);
-
-	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), icon_dir);
-	g_free (icon_dir);
-
-	/* Init plugins engine */
-	gedit_debug_message (DEBUG_APP, "Init plugins");
-	engine = gedit_plugins_engine_get_default ();
-
-	app = gedit_app_get_default ();
-
-	/* Initialize session management */
-	gedit_debug_message (DEBUG_APP, "Init session manager");
-	gedit_session_init ();
-
-	if (!service)
-	{
-		gboolean restored = FALSE;
-
-		if (gedit_session_is_restored ())
-		{
-			restored = gedit_session_load ();
-		}
-
-		if (!restored)
-		{
-			gedit_main_window ();
-		}
-	}
-
-	_gedit_app_ready (app);
-
-	gedit_debug_message (DEBUG_APP, "Start gtk-main");
-	gtk_main ();
-
-	/* Make sure settings are saved */
-	g_settings_sync ();
-
-	/* Cleanup */
-	g_object_unref (engine);
-	g_object_unref (app);
-
-	gedit_dirs_shutdown ();
-
-#ifndef ENABLE_GVFS_METADATA
-	gedit_metadata_manager_shutdown ();
-#endif
-}
-
 int
 main (int argc, char *argv[])
 {
+	GeditApp *app;
+	GeditPluginsEngine *engine;
 	const gchar *dir;
-	GeditCommandLine *command_line;
-	gboolean ret;
-	gboolean service = FALSE;
+	gint status;
 
 #ifndef ENABLE_GVFS_METADATA
 	const gchar *cache_dir;
@@ -214,22 +88,47 @@ main (int argc, char *argv[])
 	g_free (metadata_filename);
 #endif
 
-	/* Parse command line arguments */
-	command_line = gedit_command_line_get_default ();
-
-	ret = gedit_command_line_parse (command_line, &argc, &argv);
+	/* FIXME: This is needed if not we get a crash building with introspection */
+#ifdef ENABLE_INTROSPECTION
+	GOptionContext *context;
+	GError *error = NULL;
 
-	if (!ret)
+	context = g_option_context_new (_("- Edit text files"));
+	g_option_context_add_group (context, g_irepository_get_option_group ());
+	if (!g_option_context_parse (context, &argc, &argv, &error))
 	{
-		g_object_unref (command_line);
+		g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+		        error->message, argv[0]);
+
+		g_error_free (error);
 		return 1;
 	}
+	g_option_context_free (context);
+#endif
+
+	/* Init plugins en thegine */
+	gedit_debug_message (DEBUG_APP, "Init plugins");
+	engine = gedit_plugins_engine_get_default ();
 
-	gedit_main (service);
+	/* Initialize session management */
+	gedit_debug_message (DEBUG_APP, "Init session manager");
+	gedit_session_init ();
+
+	gedit_debug_message (DEBUG_APP, "Run application");
+	app = gedit_app_get_default ();
+	status = g_application_run (G_APPLICATION (app), argc, argv);
 
-	g_object_unref (command_line);
+	/* Cleanup */
+	g_object_unref (app);
+	g_object_unref (engine);
+
+	gedit_dirs_shutdown ();
+
+#ifndef ENABLE_GVFS_METADATA
+	gedit_metadata_manager_shutdown ();
+#endif
 
-	return 0;
+	return status;
 }
 
 /* ex:set ts=8 noet: */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]