Preferences: Load UI templates from resources

This commit is contained in:
Romain Vigier
2022-04-04 22:23:48 +02:00
parent 9dbfbafe85
commit e977326be4
13 changed files with 58 additions and 23 deletions
+1 -1
View File
@@ -4,4 +4,4 @@
FROM debian:stable-slim FROM debian:stable-slim
RUN apt update \ RUN apt update \
&& apt install --no-install-recommends -y gettext libglib2.0-bin meson zip gzip brotli && apt install --no-install-recommends -y gettext libglib2.0-bin libglib2.0-dev-bin meson zip gzip brotli
+8 -1
View File
@@ -1,6 +1,14 @@
# SPDX-FileCopyrightText: 2022 Romain Vigier <contact AT romainvigier.fr> # SPDX-FileCopyrightText: 2022 Romain Vigier <contact AT romainvigier.fr>
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
gnome.compile_resources(
DNS,
DNS + '.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: INSTALL_DIR / 'resources',
)
glib_compile_schemas_exe = find_program('glib-compile-schemas') glib_compile_schemas_exe = find_program('glib-compile-schemas')
custom_target( custom_target(
'gschemas', 'gschemas',
@@ -16,4 +24,3 @@ custom_target(
) )
install_subdir('icons', install_dir: INSTALL_DIR) install_subdir('icons', install_dir: INSTALL_DIR)
install_subdir('ui', install_dir: INSTALL_DIR / 'preferences')
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2022 Romain Vigier <contact AT romainvigier.fr>
SPDX-License-Identifier: GPL-3.0-or-later
-->
<gresources>
<gresource prefix="/org/gnome/shell/extensions/nightthemeswitcher">
<file compressed="true" preprocess="xml-stripblanks">ui/BackgroundButton.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/BackgroundsPage.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/ClearableEntry.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/CommandsPage.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/ContributePage.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/SchedulePage.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/ShortcutButton.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/ThemesPage.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/TimeChooser.ui</file>
</gresource>
</gresources>
+1 -1
View File
@@ -10,7 +10,7 @@ const _ = extensionUtils.gettext;
var BackgroundButton = GObject.registerClass({ var BackgroundButton = GObject.registerClass({
GTypeName: 'BackgroundButton', GTypeName: 'BackgroundButton',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'BackgroundButton.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/BackgroundButton.ui',
InternalChildren: ['filechooser'], InternalChildren: ['filechooser'],
Properties: { Properties: {
uri: GObject.ParamSpec.string( uri: GObject.ParamSpec.string(
+1 -1
View File
@@ -9,7 +9,7 @@ const Me = extensionUtils.getCurrentExtension();
var BackgroundsPage = GObject.registerClass({ var BackgroundsPage = GObject.registerClass({
GTypeName: 'BackgroundsPage', GTypeName: 'BackgroundsPage',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'BackgroundsPage.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/BackgroundsPage.ui',
InternalChildren: [ InternalChildren: [
'day_button', 'day_button',
'night_button', 'night_button',
+1 -1
View File
@@ -9,7 +9,7 @@ const Me = extensionUtils.getCurrentExtension();
var ClearableEntry = GObject.registerClass({ var ClearableEntry = GObject.registerClass({
GTypeName: 'ClearableEntry', GTypeName: 'ClearableEntry',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'ClearableEntry.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/ClearableEntry.ui',
}, class ClearableEntry extends Gtk.Entry { }, class ClearableEntry extends Gtk.Entry {
onIconReleased(entry, position) { onIconReleased(entry, position) {
if (position === Gtk.EntryIconPosition.SECONDARY) if (position === Gtk.EntryIconPosition.SECONDARY)
+1 -1
View File
@@ -11,7 +11,7 @@ const utils = Me.imports.utils;
var CommandsPage = GObject.registerClass({ var CommandsPage = GObject.registerClass({
GTypeName: 'CommandsPage', GTypeName: 'CommandsPage',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'CommandsPage.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/CommandsPage.ui',
InternalChildren: [ InternalChildren: [
'enabled_switch', 'enabled_switch',
'sunrise_entry', 'sunrise_entry',
+1 -1
View File
@@ -9,5 +9,5 @@ const Me = extensionUtils.getCurrentExtension();
var ContributePage = GObject.registerClass({ var ContributePage = GObject.registerClass({
GTypeName: 'ContributePage', GTypeName: 'ContributePage',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'ContributePage.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/ContributePage.ui',
}, class ContributePage extends Adw.PreferencesPage {}); }, class ContributePage extends Adw.PreferencesPage {});
+1 -1
View File
@@ -14,7 +14,7 @@ const { DropDownChoice } = Me.imports.preferences.DropDownChoice;
var SchedulePage = GObject.registerClass({ var SchedulePage = GObject.registerClass({
GTypeName: 'SchedulePage', GTypeName: 'SchedulePage',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'SchedulePage.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/SchedulePage.ui',
InternalChildren: [ InternalChildren: [
'transition_switch', 'transition_switch',
'manual_time_source_switch', 'manual_time_source_switch',
+1 -1
View File
@@ -11,7 +11,7 @@ const utils = Me.imports.utils;
var ShortcutButton = GObject.registerClass({ var ShortcutButton = GObject.registerClass({
GTypeName: 'ShortcutButton', GTypeName: 'ShortcutButton',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'ShortcutButton.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/ShortcutButton.ui',
InternalChildren: ['choose_button', 'change_button', 'clear_button', 'dialog'], InternalChildren: ['choose_button', 'change_button', 'clear_button', 'dialog'],
Properties: { Properties: {
keybinding: GObject.ParamSpec.string( keybinding: GObject.ParamSpec.string(
+1 -1
View File
@@ -14,7 +14,7 @@ const { DropDownChoice } = Me.imports.preferences.DropDownChoice;
var ThemesPage = GObject.registerClass({ var ThemesPage = GObject.registerClass({
GTypeName: 'ThemesPage', GTypeName: 'ThemesPage',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'ThemesPage.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/ThemesPage.ui',
InternalChildren: [ InternalChildren: [
'gtk_enabled_switch', 'gtk_enabled_switch',
'gtk_day_variant_combo_row', 'gtk_day_variant_combo_row',
+1 -1
View File
@@ -9,7 +9,7 @@ const Me = extensionUtils.getCurrentExtension();
var TimeChooser = GObject.registerClass({ var TimeChooser = GObject.registerClass({
GTypeName: 'TimeChooser', GTypeName: 'TimeChooser',
Template: `file://${GLib.build_filenamev([Me.path, 'preferences', 'ui', 'TimeChooser.ui'])}`, Template: 'resource:///org/gnome/shell/extensions/nightthemeswitcher/ui/TimeChooser.ui',
InternalChildren: ['hours', 'minutes'], InternalChildren: ['hours', 'minutes'],
Properties: { Properties: {
time: GObject.ParamSpec.double( time: GObject.ParamSpec.double(
+22 -12
View File
@@ -3,23 +3,12 @@
'use strict'; 'use strict';
const { Adw, Gdk, GLib, Gtk } = imports.gi; const { Adw, Gdk, Gio, GLib, GObject, Gtk } = imports.gi;
const { extensionUtils } = imports.misc; const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension(); const Me = extensionUtils.getCurrentExtension();
const _ = extensionUtils.gettext; const _ = extensionUtils.gettext;
const { BackgroundsPage } = Me.imports.preferences.BackgroundsPage;
const { CommandsPage } = Me.imports.preferences.CommandsPage;
const { ContributePage } = Me.imports.preferences.ContributePage;
const { SchedulePage } = Me.imports.preferences.SchedulePage;
const { ThemesPage } = Me.imports.preferences.ThemesPage;
const { BackgroundButton } = Me.imports.preferences.BackgroundButton;
const { ClearableEntry } = Me.imports.preferences.ClearableEntry;
const { ShortcutButton } = Me.imports.preferences.ShortcutButton;
const { TimeChooser } = Me.imports.preferences.TimeChooser;
/** /**
* Initialize the preferences. * Initialize the preferences.
@@ -27,6 +16,20 @@ const { TimeChooser } = Me.imports.preferences.TimeChooser;
function init() { function init() {
extensionUtils.initTranslations(); extensionUtils.initTranslations();
const resource = Gio.Resource.load(GLib.build_filenamev([Me.path, 'resources', 'org.gnome.shell.extensions.nightthemeswitcher.gresource']));
Gio.resources_register(resource);
GObject.type_ensure(Me.imports.preferences.BackgroundsPage.BackgroundsPage);
GObject.type_ensure(Me.imports.preferences.CommandsPage.CommandsPage);
GObject.type_ensure(Me.imports.preferences.ContributePage.ContributePage);
GObject.type_ensure(Me.imports.preferences.SchedulePage.SchedulePage);
GObject.type_ensure(Me.imports.preferences.ThemesPage.ThemesPage);
GObject.type_ensure(Me.imports.preferences.BackgroundButton.BackgroundButton);
GObject.type_ensure(Me.imports.preferences.ClearableEntry.ClearableEntry);
GObject.type_ensure(Me.imports.preferences.ShortcutButton.ShortcutButton);
GObject.type_ensure(Me.imports.preferences.TimeChooser.TimeChooser);
const iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()); const iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default());
iconTheme.add_search_path(GLib.build_filenamev([Me.path, 'icons'])); iconTheme.add_search_path(GLib.build_filenamev([Me.path, 'icons']));
} }
@@ -37,6 +40,12 @@ function init() {
* @param {Adw.PreferencesWindow} window The PreferencesWindow to fill. * @param {Adw.PreferencesWindow} window The PreferencesWindow to fill.
*/ */
function fillPreferencesWindow(window) { function fillPreferencesWindow(window) {
const { BackgroundsPage } = Me.imports.preferences.BackgroundsPage;
const { CommandsPage } = Me.imports.preferences.CommandsPage;
const { ContributePage } = Me.imports.preferences.ContributePage;
const { SchedulePage } = Me.imports.preferences.SchedulePage;
const { ThemesPage } = Me.imports.preferences.ThemesPage;
[ [
new SchedulePage(), new SchedulePage(),
new BackgroundsPage(), new BackgroundsPage(),
@@ -44,6 +53,7 @@ function fillPreferencesWindow(window) {
new ThemesPage(), new ThemesPage(),
new ContributePage(), new ContributePage(),
].forEach(page => window.add(page)); ].forEach(page => window.add(page));
window.search_enabled = true; window.search_enabled = true;
window.set_default_size(720, 490); window.set_default_size(720, 490);
} }