forked from AuroraMiddleware/gtk
gtk-demo: Streamline application
Avoid the odd #ifdef STANDALONE construction; we can show multiple source files nowadays.
This commit is contained in:
parent
fc90bd5e30
commit
c0a61c2da3
@ -4,7 +4,7 @@ include $(top_srcdir)/Makefile.decl
|
||||
## These should be in the order you want them to appear in the
|
||||
## demo app, which means alphabetized by demo title, not filename
|
||||
demos_base = \
|
||||
application.c \
|
||||
application_demo.c \
|
||||
assistant.c \
|
||||
builder.c \
|
||||
button_box.c \
|
||||
@ -143,7 +143,7 @@ gtk3_demo_LDADD = $(LDADDS)
|
||||
gtk3_demo_LDFLAGS = -export-dynamic
|
||||
|
||||
gtk3_demo_application_SOURCES = \
|
||||
application-standalone.c \
|
||||
application.c \
|
||||
demo_resources.c
|
||||
|
||||
gtk3_demo_application_LDADD = $(LDADDS)
|
||||
|
@ -1,3 +0,0 @@
|
||||
#define STANDALONE
|
||||
|
||||
#include "application.c"
|
@ -1,18 +1,8 @@
|
||||
/* Application Class
|
||||
*
|
||||
* Demonstrates a simple application.
|
||||
*
|
||||
* This examples uses GtkApplication, GtkApplicationWindow, GtkBuilder
|
||||
* as well as GMenu and GResource. Due to the way GtkApplication is structured,
|
||||
* it is run as a separate process.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef STANDALONE
|
||||
|
||||
typedef GtkApplication DemoApplication;
|
||||
typedef GtkApplicationClass DemoApplicationClass;
|
||||
|
||||
@ -356,7 +346,7 @@ startup (GApplication *app)
|
||||
G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_resource (builder, "/application/menus.ui", NULL);
|
||||
gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
|
||||
|
||||
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
|
||||
menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
|
||||
@ -528,7 +518,7 @@ demo_application_window_class_init (DemoApplicationWindowClass *class)
|
||||
widget_class->window_state_event = demo_application_window_state_event;
|
||||
widget_class->destroy = demo_application_window_destroy;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/application/application.ui");
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/application_demo/application.ui");
|
||||
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, message);
|
||||
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, infobar);
|
||||
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, status);
|
||||
@ -552,90 +542,3 @@ main (int argc, char *argv[])
|
||||
|
||||
return g_application_run (G_APPLICATION (app), 0, NULL);
|
||||
}
|
||||
|
||||
#else /* !STANDALONE */
|
||||
|
||||
static gboolean name_seen;
|
||||
static GtkWidget *placeholder;
|
||||
|
||||
static void
|
||||
on_name_appeared (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
const gchar *name_owner,
|
||||
gpointer user_data)
|
||||
{
|
||||
name_seen = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_vanished (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (!name_seen)
|
||||
return;
|
||||
|
||||
if (placeholder)
|
||||
{
|
||||
gtk_widget_destroy (placeholder);
|
||||
g_object_unref (placeholder);
|
||||
placeholder = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define APP_EXTENSION ".exe"
|
||||
#else
|
||||
#define APP_EXTENSION
|
||||
#endif
|
||||
|
||||
GtkWidget *
|
||||
do_application (GtkWidget *toplevel)
|
||||
{
|
||||
static guint watch = 0;
|
||||
|
||||
if (watch == 0)
|
||||
watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
||||
"org.gtk.Demo2",
|
||||
0,
|
||||
on_name_appeared,
|
||||
on_name_vanished,
|
||||
NULL, NULL);
|
||||
|
||||
if (placeholder == NULL)
|
||||
{
|
||||
const gchar *command;
|
||||
GError *error = NULL;
|
||||
|
||||
if (g_file_test ("./gtk3-demo-application" APP_EXTENSION, G_FILE_TEST_IS_EXECUTABLE))
|
||||
command = "./gtk3-demo-application" APP_EXTENSION;
|
||||
else
|
||||
command = "gtk3-demo-application";
|
||||
|
||||
if (!g_spawn_command_line_async (command, &error))
|
||||
{
|
||||
g_warning ("%s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
placeholder = gtk_label_new ("");
|
||||
g_object_ref_sink (placeholder);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
|
||||
"org.gtk.Demo2",
|
||||
"/org/gtk/Demo2",
|
||||
"org.gtk.Actions",
|
||||
"Activate",
|
||||
g_variant_new ("(sava{sv})", "quit", NULL, NULL),
|
||||
NULL,
|
||||
0,
|
||||
G_MAXINT,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
95
demos/gtk-demo/application_demo.c
Normal file
95
demos/gtk-demo/application_demo.c
Normal file
@ -0,0 +1,95 @@
|
||||
/* Application Class
|
||||
*
|
||||
* Demonstrates a simple application.
|
||||
*
|
||||
* This examples uses GtkApplication, GtkApplicationWindow, GtkBuilder
|
||||
* as well as GMenu and GResource. Due to the way GtkApplication is structured,
|
||||
* it is run as a separate process.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static gboolean name_seen;
|
||||
static GtkWidget *placeholder;
|
||||
|
||||
static void
|
||||
on_name_appeared (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
const gchar *name_owner,
|
||||
gpointer user_data)
|
||||
{
|
||||
name_seen = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_vanished (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (!name_seen)
|
||||
return;
|
||||
|
||||
if (placeholder)
|
||||
{
|
||||
gtk_widget_destroy (placeholder);
|
||||
g_object_unref (placeholder);
|
||||
placeholder = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define APP_EXTENSION ".exe"
|
||||
#else
|
||||
#define APP_EXTENSION
|
||||
#endif
|
||||
|
||||
GtkWidget *
|
||||
do_application_demo (GtkWidget *toplevel)
|
||||
{
|
||||
static guint watch = 0;
|
||||
|
||||
if (watch == 0)
|
||||
watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
||||
"org.gtk.Demo2",
|
||||
0,
|
||||
on_name_appeared,
|
||||
on_name_vanished,
|
||||
NULL, NULL);
|
||||
|
||||
if (placeholder == NULL)
|
||||
{
|
||||
const gchar *command;
|
||||
GError *error = NULL;
|
||||
|
||||
if (g_file_test ("./gtk3-demo-application" APP_EXTENSION, G_FILE_TEST_IS_EXECUTABLE))
|
||||
command = "./gtk3-demo-application" APP_EXTENSION;
|
||||
else
|
||||
command = "gtk3-demo-application";
|
||||
|
||||
if (!g_spawn_command_line_async (command, &error))
|
||||
{
|
||||
g_warning ("%s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
placeholder = gtk_label_new ("");
|
||||
g_object_ref_sink (placeholder);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
|
||||
"org.gtk.Demo2",
|
||||
"/org/gtk/Demo2",
|
||||
"org.gtk.Actions",
|
||||
"Activate",
|
||||
g_variant_new ("(sava{sv})", "quit", NULL, NULL),
|
||||
NULL,
|
||||
0,
|
||||
G_MAXINT,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
<gresource prefix="/ui">
|
||||
<file preprocess="xml-stripblanks">main.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/application">
|
||||
<gresource prefix="/application_demo">
|
||||
<file>application.c</file>
|
||||
<file>application.ui</file>
|
||||
<file>menus.ui</file>
|
||||
</gresource>
|
||||
@ -117,7 +118,7 @@
|
||||
<file>gnu-keys.png</file>
|
||||
</gresource>
|
||||
<gresource prefix="/sources">
|
||||
<file>application.c</file>
|
||||
<file>application_demo.c</file>
|
||||
<file>assistant.c</file>
|
||||
<file>builder.c</file>
|
||||
<file>button_box.c</file>
|
||||
|
Loading…
Reference in New Issue
Block a user