[telegnome] Basic port to GtkApplication



commit bf2f5c592d1eea9b99c016ea13a77780ffe6d89f
Author: Colin Watson <cjwatson debian org>
Date:   Wed Feb 3 04:10:54 2016 +0000

    Basic port to GtkApplication
    
    * src/app.c: New file.
    * src/app.h: Likewise.
    * src/gui.c (tg_gui_new): Drop unimplemented startpage parameter.
    Construct a GtkApplicationWindow for the current GtkApplication.
    (tg_gui_cb_quit): Be more robust against being called more than
    once.  Call g_application_quit rather than gtk_main_quit.
    * src/gui.h (tg_gui_new): Update prototype.
    * src/main.c (main): Initialise localisation using GETTEXT_PACKAGE
    rather than PACKAGE (currently synonymous but a better semantic
    fit).  Call bind_textdomain_codeset to ensure that GLib always gets
    UTF-8 strings.  Replace settings and GUI setup with tg_app_new and
    g_application_run; TgApp handles all this now.
    * src/Makefile.am (telegnome_SOURCES): Add app.c and app.h.

 NEWS            |    1 +
 src/Makefile.am |    2 +
 src/app.c       |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/app.h       |   42 ++++++++++++++++++++++++++++++++
 src/gui.c       |   10 ++++----
 src/gui.h       |    2 +-
 src/main.c      |   36 ++++-----------------------
 7 files changed, 128 insertions(+), 37 deletions(-)
---
diff --git a/NEWS b/NEWS
index 0afac3a..00fc65a 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Changes in TeleGNOME 0.2.1
  * Port to new (as of GTK+ 2.4) GtkToolbar API.
  * Port from GdkDrawable to Cairo.
  * Port to GTK+ 3.
+ * Basic port to GtkApplication.
 
 Changes in TeleGNOME 0.2.0
 ==========================
diff --git a/src/Makefile.am b/src/Makefile.am
index a3ffc4b..b3eaef5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,8 @@ bin_PROGRAMS = telegnome
 telegnome_SOURCES = \
        main.h \
        main.c \
+       app.h \
+       app.c \
        http.h \
        http.c \
        gui.h \
diff --git a/src/app.c b/src/app.c
new file mode 100644
index 0000000..3d4ac20
--- /dev/null
+++ b/src/app.c
@@ -0,0 +1,72 @@
+/* app.c
+ * Part of TeleGNOME, a GNOME app to view Teletext.
+ * This file defines the main TeleGNOME application.
+ */
+
+/*
+** Copyright (C) 2016 Colin Watson <cjwatson debian org>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+*/
+
+#include <string.h>
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include "app.h"
+#include "gui.h"
+#include "legacy-config.h"
+
+struct _TgApp {
+    GtkApplication parent;
+};
+
+G_DEFINE_TYPE (TgApp, tg_app, GTK_TYPE_APPLICATION)
+
+static void
+tg_app_init (TgApp *app)
+{
+}
+
+static void
+tg_app_activate (GApplication *app)
+{
+    GSettings *settings;
+    TgGui *gui;
+
+    settings = g_settings_new (g_application_get_application_id (app));
+    legacy_convert (settings);
+
+    gui = tg_gui_new (GTK_APPLICATION (app), settings);
+    gtk_window_present (GTK_WINDOW (tg_gui_get_window (gui)));
+}
+
+static void
+tg_app_class_init (TgAppClass *klass)
+{
+    G_APPLICATION_CLASS (klass)->activate = tg_app_activate;
+}
+
+TgApp *
+tg_app_new (void)
+{
+    return g_object_new (TG_TYPE_APP,
+                        "application-id", "org.gnome.telegnome",
+                        "flags", G_APPLICATION_NON_UNIQUE,
+                        NULL);
+}
diff --git a/src/app.h b/src/app.h
new file mode 100644
index 0000000..96800ea
--- /dev/null
+++ b/src/app.h
@@ -0,0 +1,42 @@
+/* app.h
+ * Part of TeleGNOME, a GNOME app to view Teletext.
+ * This file declares the main TeleGNOME application.
+ */
+
+/*
+** Copyright (C) 2016 Colin Watson <cjwatson debian org>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+*/
+
+#ifndef _APP_H_
+#define _APP_H_
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TG_TYPE_APP                (tg_app_get_type ())
+G_DECLARE_FINAL_TYPE (TgApp, tg_app, TG, APP, GtkApplication)
+
+GType tg_app_get_type (void);
+
+TgApp *tg_app_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/gui.c b/src/gui.c
index 606dd16..6e74274 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -654,10 +654,10 @@ tg_gui_class_init (TgGuiClass *klass)
 }
 
 /*******************************
- * return the app gui, with startpage or NULL
+ * return the app gui
  */
 TgGui *
-tg_gui_new (GSettings *settings, gchar *startpage)
+tg_gui_new (GtkApplication *app, GSettings *settings)
 {
     GtkWidget *toolbar;
     GtkUIManager *ui_manager;
@@ -673,7 +673,7 @@ tg_gui_new (GSettings *settings, gchar *startpage)
     gui = g_object_new (TG_TYPE_GUI, NULL);
 
     /* the app */
-    gui->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    gui->window = gtk_application_window_new (app);
     gtk_window_set_title (GTK_WINDOW (gui->window),
                          _("TeleGNOME: Teletext for GNOME"));
     gtk_window_set_resizable (GTK_WINDOW (gui->window), FALSE);
@@ -878,10 +878,10 @@ tg_gui_cb_quit (GtkWidget* widget, gpointer data)
        g_slist_free_full(gui->channels, g_object_unref);
        gui->channels = NULL;
     }
-    tg_view_free(currentview);
+    g_clear_pointer(&currentview, tg_view_free);
 
     /* get outta here ;) */
-    gtk_main_quit();
+    g_application_quit(g_application_get_default());
 }
 
 void
diff --git a/src/gui.h b/src/gui.h
index 426ad74..37f81d3 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -59,7 +59,7 @@ G_DECLARE_FINAL_TYPE (TgGui, tg_gui, TG, GUI, GObject)
 
 GType tg_gui_get_type (void);
 
-TgGui *tg_gui_new (GSettings *settings, gchar *startpage);
+TgGui *tg_gui_new (GtkApplication *app, GSettings *settings);
 
 GtkWidget *tg_gui_get_window (TgGui *gui);
 
diff --git a/src/main.c b/src/main.c
index 9e2ccf3..1891c13 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,44 +28,18 @@
 #include <config.h>
 #endif /* HAVE_CONFIG_H */
 
-#include <stdio.h>
-#include <string.h>
-
 #include <libintl.h>
 
 #include <gio/gio.h>
-#include <gtk/gtk.h>
-
-#include "main.h"
-#include "http.h"
-#include "gui.h"
-#include "prefs.h"
-#include "legacy-config.h"
 
+#include "app.h"
 
 int 
 main (int argc, char **argv)
 {
-       TgGui *gui;
-       GSettings *settings;
-
-       bindtextdomain(PACKAGE,GNOMELOCALEDIR);
-       textdomain(PACKAGE);
-
-       gtk_init (&argc, &argv);
-
-       settings = g_settings_new ("org.gnome.telegnome");
-       legacy_convert (settings);
-
-       /* build gui, handle cmd line args */
-       if ((argc >1) && (strlen(argv[1])<6)) {
-               gui = tg_gui_new (settings, argv[1]);
-       } else {
-               gui = tg_gui_new (settings, "100");
-       } 
-
-       gtk_widget_show_all (tg_gui_get_window (gui));
-       gtk_main();
+    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
 
-       return 0;
+    return g_application_run (G_APPLICATION (tg_app_new ()), argc, argv);
 }


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