[gedit/wip/gtkapp] Initial port to GtkApplication



commit 0380f784a01ea8d76dd7904060d6f07495e81e58
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     |  101 +++++++++++++++++++++++--------------------------
 gedit/gedit-app.h     |   31 +++------------
 gedit/gedit-window.h  |   28 +++----------
 gedit/gedit.c         |    6 ++-
 5 files changed, 65 insertions(+), 103 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 51a2bc0..376b604 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,15 +89,11 @@ struct _GeditAppPrivate
 
 static GeditApp *app_instance = NULL;
 
-G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, GTK_TYPE_APPLICATION)
 
 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);
 }
 
@@ -370,7 +365,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 +373,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 +444,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 +468,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 +483,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 +493,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,6 +532,7 @@ 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;
@@ -547,11 +540,12 @@ gedit_app_class_init (GeditAppClass *klass)
 	object_class->constructor = gedit_app_constructor;
 	object_class->constructed = gedit_app_constructed;
 
+	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 +685,7 @@ gedit_app_init (GeditApp *app)
 	                            app);
 }
 
+/* FIXME: lets kill this method */
 /**
  * gedit_app_get_default:
  *
@@ -840,6 +835,7 @@ _gedit_app_restore_window (GeditApp    *app,
 	return window;
 }
 
+/* FIXME: lets kill this method */
 /**
  * gedit_app_get_windows:
  * @app: the #GeditApp
@@ -854,7 +850,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 +955,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 +968,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 +993,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 +1020,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 +1092,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.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 408a6b6..54813f2 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -38,7 +38,6 @@
 #include <glib/gi18n.h>
 
 #include "gedit-command-line.h"
-#include "gedit-dbus.h"
 
 #include "gedit-app.h"
 #include "gedit-encodings.h"
@@ -122,6 +121,7 @@ gedit_main (gboolean service)
 	GeditApp *app;
 	const gchar *dir;
 	gchar *icon_dir;
+	gint status;
 
 	gedit_debug_message (DEBUG_APP, "Set icon");
 
@@ -159,7 +159,9 @@ gedit_main (gboolean service)
 	_gedit_app_ready (app);
 
 	gedit_debug_message (DEBUG_APP, "Start gtk-main");
-	gtk_main ();
+	// FIXME: the status has to be returned and we must parse the
+	// commandline stuff with g application itself
+	status = g_application_run (G_APPLICATION (app), 0, NULL);
 
 	/* Make sure settings are saved */
 	g_settings_sync ();



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