[easytag/wip/application-window: 12/26] Port from GApplication to GtkApplication
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/application-window: 12/26] Port from GApplication to GtkApplication
- Date: Tue, 15 Apr 2014 19:52:16 +0000 (UTC)
commit b8e9808c256b60b22f202c97007e04b6682771c9
Author: David King <amigadave amigadave com>
Date: Tue Apr 15 20:39:45 2014 +0100
Port from GApplication to GtkApplication
src/application.c | 53 +++--------------------------------------------------
src/application.h | 8 ++------
src/easytag.c | 19 ++++++++++---------
3 files changed, 15 insertions(+), 65 deletions(-)
---
diff --git a/src/application.c b/src/application.c
index 8135363..239e526 100644
--- a/src/application.c
+++ b/src/application.c
@@ -1,5 +1,5 @@
/* EasyTAG - tag editor for audio files
- * Copyright (C) 2013 David King <amigadave amigadave com>
+ * Copyright (C) 2014 David King <amigadave amigadave com>
*
* 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
@@ -24,12 +24,7 @@
#include <glib/gi18n.h>
#include <stdlib.h>
-G_DEFINE_TYPE (EtApplication, et_application, G_TYPE_APPLICATION)
-
-struct _EtApplicationPrivate
-{
- GtkWindow *main_window;
-};
+G_DEFINE_TYPE (EtApplication, et_application, GTK_TYPE_APPLICATION)
static const GOptionEntry entries[] =
{
@@ -137,9 +132,6 @@ et_application_startup (GApplication *application)
{
Charset_Insert_Locales_Init ();
- /* TODO: Remove gtk_init() when porting to GtkApplication. */
- gtk_init (NULL, NULL);
-
G_APPLICATION_CLASS (et_application_parent_class)->startup (application);
}
@@ -152,11 +144,6 @@ et_application_finalize (GObject *object)
static void
et_application_init (EtApplication *application)
{
- application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
- ET_TYPE_APPLICATION,
- EtApplicationPrivate);
-
- application->priv->main_window = NULL;
}
static void
@@ -165,8 +152,6 @@ et_application_class_init (EtApplicationClass *klass)
G_OBJECT_CLASS (klass)->finalize = et_application_finalize;
G_APPLICATION_CLASS (klass)->local_command_line = et_local_command_line;
G_APPLICATION_CLASS (klass)->startup = et_application_startup;
-
- g_type_class_add_private (klass, sizeof (EtApplicationPrivate));
}
/*
@@ -179,39 +164,7 @@ et_application_class_init (EtApplicationClass *klass)
EtApplication *
et_application_new ()
{
- return g_object_new (et_application_get_type (), "application-id",
+ return g_object_new (ET_TYPE_APPLICATION, "application-id",
"org.gnome.EasyTAG", "flags",
G_APPLICATION_HANDLES_OPEN, NULL);
}
-
-/*
- * et_application_get_window:
- * @application: the application
- *
- * Get the current application window.
- *
- * Returns: the current application window, or %NULL if no window is set
- */
-GtkWindow *
-et_application_get_window (EtApplication *application)
-{
- g_return_val_if_fail (ET_APPLICATION (application), NULL);
-
- return application->priv->main_window;
-}
-
-/*
- * et_application_set_window:
- * @application: the application
- * @window: the window to set
- *
- * Set the application window, if none has been set already.
- */
-void
-et_application_set_window (EtApplication *application, GtkWindow *window)
-{
- g_return_if_fail (ET_APPLICATION (application) || GTK_WINDOW (window)
- || application->priv->main_window != NULL);
-
- application->priv->main_window = window;
-}
diff --git a/src/application.h b/src/application.h
index c3a1858..fdb774c 100644
--- a/src/application.h
+++ b/src/application.h
@@ -29,25 +29,21 @@ G_BEGIN_DECLS
typedef struct _EtApplication EtApplication;
typedef struct _EtApplicationClass EtApplicationClass;
-typedef struct _EtApplicationPrivate EtApplicationPrivate;
struct _EtApplication
{
/*< private >*/
- GApplication parent_instance;
- EtApplicationPrivate *priv;
+ GtkApplication parent_instance;
};
struct _EtApplicationClass
{
/*< private >*/
- GApplicationClass parent_class;
+ GtkApplicationClass parent_class;
};
GType et_application_get_type (void);
EtApplication *et_application_new (void);
-GtkWindow *et_application_get_window (EtApplication *application);
-void et_application_set_window (EtApplication *application, GtkWindow *window);
G_END_DECLS
diff --git a/src/easytag.c b/src/easytag.c
index 71f6310..14d24c2 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -231,8 +231,8 @@ common_init (GApplication *application)
/* The main window */
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- et_application_set_window (ET_APPLICATION (application),
- GTK_WINDOW (MainWindow));
+ gtk_application_add_window (GTK_APPLICATION (application),
+ GTK_WINDOW (MainWindow));
gtk_window_set_title (GTK_WINDOW (MainWindow), PACKAGE_NAME);
// This part is needed to set correctly the position of handle panes
gtk_window_set_default_size(GTK_WINDOW(MainWindow),MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT);
@@ -397,7 +397,7 @@ static void
on_application_open (GApplication *application, GFile **files, gint n_files,
gchar *hint, gpointer user_data)
{
- GtkWindow *main_window;
+ GList *windows;
gboolean activated;
GFile *arg;
GFile *parent;
@@ -407,8 +407,8 @@ on_application_open (GApplication *application, GFile **files, gint n_files,
gchar *path;
gchar *path_utf8;
- main_window = et_application_get_window (ET_APPLICATION (application));
- activated = main_window ? TRUE : FALSE;
+ windows = gtk_application_get_windows (GTK_APPLICATION (application));
+ activated = windows ? TRUE : FALSE;
/* Only take the first file; ignore the rest. */
arg = files[0];
@@ -511,12 +511,13 @@ on_application_open (GApplication *application, GFile **files, gint n_files,
static void
on_application_activate (GApplication *application, gpointer user_data)
{
- GtkWindow *main_window;
+ GList *windows;
- main_window = et_application_get_window (ET_APPLICATION (application));
- if (main_window != NULL)
+ windows = gtk_application_get_windows (GTK_APPLICATION (application));
+
+ if (windows != NULL)
{
- gtk_window_present (main_window);
+ gtk_window_present (windows->data);
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]