From b0f72c432f160c161305d98a626a10b911957a0f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 19 Dec 2019 13:41:17 +0000 Subject: [PATCH] malcontent-control: Add initial main window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s currently empty, but it’s a start. Signed-off-by: Philip Withnall --- malcontent-control/application.c | 30 +++++++++++++++++++ malcontent-control/main.ui | 12 ++++++++ .../malcontent-control.gresource.xml | 7 +++++ malcontent-control/meson.build | 26 +++++++++++++++- po/POTFILES.in | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 malcontent-control/main.ui create mode 100644 malcontent-control/malcontent-control.gresource.xml diff --git a/malcontent-control/application.c b/malcontent-control/application.c index 94981ca..b5f6499 100644 --- a/malcontent-control/application.c +++ b/malcontent-control/application.c @@ -69,12 +69,42 @@ mct_application_constructed (GObject *object) G_OBJECT_CLASS (mct_application_parent_class)->constructed (object); } +static void +mct_application_activate (GApplication *application) +{ + GList *windows; /* (element-type GtkWindow) */ + GtkWindow *window = NULL; + + windows = gtk_application_get_windows (GTK_APPLICATION (application)); + if (windows != NULL) + window = windows->data; + + if (window == NULL) + { + g_autoptr(GtkBuilder) builder = NULL; + + builder = gtk_builder_new_from_resource ("/org/freedesktop/MalcontentControl/ui/main.ui"); + + gtk_builder_set_translation_domain (builder, "malcontent"); + + /* Set up the main window. */ + window = GTK_WINDOW (gtk_builder_get_object (builder, "main_window")); + gtk_window_set_application (window, GTK_APPLICATION (application)); + gtk_widget_show (GTK_WIDGET (window)); + } + + /* Bring the window to the front. */ + gtk_window_present (window); +} + static void mct_application_class_init (MctApplicationClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GApplicationClass *application_class = G_APPLICATION_CLASS (klass); object_class->constructed = mct_application_constructed; + application_class->activate = mct_application_activate; } /** diff --git a/malcontent-control/main.ui b/malcontent-control/main.ui new file mode 100644 index 0000000..ebc3ad5 --- /dev/null +++ b/malcontent-control/main.ui @@ -0,0 +1,12 @@ + + + + + + + + vertical + + + + diff --git a/malcontent-control/malcontent-control.gresource.xml b/malcontent-control/malcontent-control.gresource.xml new file mode 100644 index 0000000..c0ec8fd --- /dev/null +++ b/malcontent-control/malcontent-control.gresource.xml @@ -0,0 +1,7 @@ + + + + + main.ui + + diff --git a/malcontent-control/meson.build b/malcontent-control/meson.build index 63e9b91..7834dc3 100644 --- a/malcontent-control/meson.build +++ b/malcontent-control/meson.build @@ -1,11 +1,21 @@ application_id = 'org.freedesktop.MalcontentControl' +if not cc.has_function('atexit') + error('atexit() needed for generated GResource files') +endif + +resources = gnome.compile_resources( + 'resources', + 'malcontent-control.gresource.xml', + source_dir: meson.source_root(), +) + malcontent_control = executable('malcontent-control', [ 'application.c', 'application.h', 'main.c', - ], + ] + resources, dependencies: [ dependency('gio-2.0', version: '>= 2.44'), dependency('glib-2.0', version: '>= 2.54.2'), @@ -57,6 +67,20 @@ if appstream_util.found() ) endif +xmllint = find_program('xmllint', required: false) +if xmllint.found() + gtk_prefix = dependency('gtk+-3.0').get_pkgconfig_variable('prefix') + test( + 'validate-ui', xmllint, + args: [ + '--nonet', '--noblanks', '--noout', + '--relaxng', join_paths(gtk_prefix, 'share', 'gtk-3.0', 'gtkbuilder.rng'), + files('main.ui'), + ], + suite: ['malcontent-control'], + ) +endif + # FIXME: Add icons and tests #subdir('icons') #subdir('tests') diff --git a/po/POTFILES.in b/po/POTFILES.in index 9f4b4eb..10ec5ad 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -3,6 +3,7 @@ accounts-service/com.endlessm.ParentalControls.policy.in libmalcontent/manager.c malcontent-control/application.c +malcontent-control/main.ui malcontent-control/org.freedesktop.MalcontentControl.appdata.xml.in malcontent-control/org.freedesktop.MalcontentControl.desktop.in pam/pam_malcontent.c