# HG changeset patch
# Node ID 951199175e79
# Parent  53d3a46592f2
diff --git a/demo/data/demo.ui b/demo/data/demo.ui
--- a/demo/data/demo.ui
+++ b/demo/data/demo.ui
@@ -25,10 +25,9 @@ along with this library; if not, see <ht
   <!-- interface-name Talkatu -->
   <!-- interface-description GTK widgets for chat applications -->
   <!-- interface-copyright Gary Kramlich <grim@reaperworld.com> -->
-  <template class="TalkatuDemoWindow" parent="GtkWindow">
+  <template class="TalkatuDemoWindow" parent="GtkApplicationWindow">
     <property name="can-focus">False</property>
     <property name="border-width">12</property>
-    <signal name="delete-event" handler="talkatu_demo_window_closed_cb" swapped="no"/>
     <child>
       <object class="GtkPaned">
         <property name="visible">True</property>
diff --git a/demo/talkatudemo.c b/demo/talkatudemo.c
--- a/demo/talkatudemo.c
+++ b/demo/talkatudemo.c
@@ -28,76 +28,75 @@
 
 #include "talkatudemowindow.h"
 
-static gboolean exit_early = FALSE;
-
-static gboolean
-talkatu_demo_version_cb(const gchar *n, const gchar *v, gpointer d, GError **e) {
-	printf("talkatu-demo %s\n", TALKATU_VERSION);
-
-	exit_early = TRUE;
-
-	return TRUE;
-}
-
 static GOptionEntry entries[] = {
 	{
-		"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
-		talkatu_demo_version_cb, N_("Display the version and exit"),
+		"version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
+		NULL, N_("Display the version and exit"),
 		NULL,
 	}, {
 		NULL, 0, 0, 0, NULL, NULL, NULL,
 	}
 };
 
+static gint
+talkatu_demo_handle_local_options(G_GNUC_UNUSED GApplication *application,
+                                  GVariantDict *options,
+                                  G_GNUC_UNUSED gpointer data)
+{
+	if (g_variant_dict_contains(options, "version")) {
+		printf("talkatu-demo %s\n", TALKATU_VERSION);
+
+		return 0;
+	}
+
+	return -1;
+}
+
+static void
+talkatu_demo_startup(G_GNUC_UNUSED GApplication *app,
+                     G_GNUC_UNUSED gpointer data)
+{
+	talkatu_init();
+}
+
+static void
+talkatu_demo_shutdown(G_GNUC_UNUSED GApplication *app, 
+                      G_GNUC_UNUSED gpointer data) 
+{
+	talkatu_uninit();
+}
+
+static void
+talkatu_demo_activate(GApplication *app, G_GNUC_UNUSED gpointer data) {
+	GtkWidget *win = NULL;
+
+	win = talkatu_demo_window_new();
+	gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(win));
+	gtk_widget_show(win);
+}
+
 gint
 main(gint argc, gchar **argv) {
-	GtkWidget *win = NULL;
-	GError *error = NULL;
-	GOptionContext *ctx = NULL;
-	GOptionGroup *group = NULL;
+	GtkApplication *app = NULL;
+	gint status;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
-	ctx = g_option_context_new(NULL);
-	g_option_context_set_summary(ctx, _("Talkatu Demo"));
-	g_option_context_set_translation_domain(ctx, GETTEXT_PACKAGE);
-	g_option_context_add_main_entries(ctx, entries, NULL);
-
-	group = gtk_get_option_group(FALSE);
-	g_option_context_add_group(ctx, group);
-
-	g_option_context_parse(ctx, &argc, &argv, &error);
-	g_option_context_free(ctx);
-
-	if(error) {
-		fprintf(stderr, "%s\n", error->message);
-
-		g_error_free(error);
-
-		talkatu_uninit();
+	app = gtk_application_new("org.imfreedom.keep.talkatu.TalkatuDemo",
+	                          G_APPLICATION_FLAGS_NONE);
+	g_application_add_main_option_entries(G_APPLICATION(app), entries);
 
-		return EXIT_FAILURE;
-	}
-
-	if(exit_early) {
-		talkatu_uninit();
-
-		return EXIT_SUCCESS;
-	}
-
-	gtk_init(&argc, &argv);
+	g_signal_connect(app, "handle-local-options",
+	                 G_CALLBACK(talkatu_demo_handle_local_options), NULL);
+	g_signal_connect(app, "activate", G_CALLBACK(talkatu_demo_activate), NULL);
+	g_signal_connect(app, "startup", G_CALLBACK(talkatu_demo_startup), NULL);
+	g_signal_connect(app, "shutdown", G_CALLBACK(talkatu_demo_shutdown), NULL);
 
-	talkatu_init();
-
-	win = talkatu_demo_window_new();
-	gtk_widget_show(win);
-
-	gtk_main();
-
-	talkatu_uninit();
-
-	return 0;
+	status = g_application_run(G_APPLICATION(app), argc, argv);
+	g_object_unref(app);
+  
+	return status;
 }
diff --git a/demo/talkatudemowindow.h b/demo/talkatudemowindow.h
--- a/demo/talkatudemowindow.h
+++ b/demo/talkatudemowindow.h
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
 
 #define TALKATU_DEMO_TYPE_WINDOW (talkatu_demo_window_get_type())
 
-G_DECLARE_FINAL_TYPE(TalkatuDemoWindow, talkatu_demo_window, TALKATU_DEMO, WINDOW, GtkWindow)
+G_DECLARE_FINAL_TYPE(TalkatuDemoWindow, talkatu_demo_window, TALKATU_DEMO, WINDOW, GtkApplicationWindow)
 
 GtkWidget *talkatu_demo_window_new(void);
 
diff --git a/demo/talkatudemowindow.c b/demo/talkatudemowindow.c
--- a/demo/talkatudemowindow.c
+++ b/demo/talkatudemowindow.c
@@ -22,7 +22,7 @@
 #include "talkatudemowindow.h"
 
 struct _TalkatuDemoWindow {
-	GtkWindow parent;
+	GtkApplicationWindow parent;
 
 	GtkWidget *history;
 	GtkWidget *editor;
@@ -47,7 +47,7 @@ struct _TalkatuDemoWindow {
 	GtkWidget *author_item;
 };
 
-G_DEFINE_TYPE(TalkatuDemoWindow, talkatu_demo_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE(TalkatuDemoWindow, talkatu_demo_window, GTK_TYPE_APPLICATION_WINDOW);
 
 static void
 talkatu_demo_window_insert_html_cb(GtkButton *toggle, gpointer data) {
@@ -213,13 +213,6 @@ talkatu_demo_window_view_send_message_cb
 	talkatu_message_clear_attachments(TALKATU_MESSAGE(input));
 }
 
-static gboolean
-talkatu_demo_window_closed_cb(GtkWidget *w, GdkEvent *e, gpointer d) {
-	gtk_main_quit();
-
-	return FALSE;
-}
-
 static void
 talkatu_demo_window_author_toggled_cb(GtkToolButton *button, gpointer data) {
 	GtkPopover *popover = GTK_POPOVER(data);
@@ -348,7 +341,6 @@ talkatu_demo_window_class_init(TalkatuDe
 	gtk_widget_class_bind_template_child(widget_class, TalkatuDemoWindow, toggle_send_button);
 	gtk_widget_class_bind_template_child(widget_class, TalkatuDemoWindow, toggle_edited);
 
-	gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_window_closed_cb);
 	gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_window_buffer_changed_cb);
 	gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_window_buffer_modified_cb);
 	gtk_widget_class_bind_template_callback(widget_class, talkatu_demo_window_view_open_url_cb);
