From 9e90c1b2530f7a0678fe9e0c8d0588a6adac0a5d Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sun, 18 Jun 2023 11:34:04 +0200 Subject: [PATCH] feat: gnome project structure and accessory files --- .gitignore | 9 +++ build-aux/dist-vendor.sh | 9 +++ data/icons/meson.build | 10 +++ data/icons/org.gabmus.rex2.Devel.svg | 74 ++++++++++++++++++++++ data/meson.build | 77 +++++++++++++++++++++++ data/org.gabmus.rex2.desktop.in.in | 13 ++++ data/org.gabmus.rex2.metainfo.xml.in.in | 35 +++++++++++ data/resources.gresource.xml | 9 +++ data/style.css | 0 meson.build | 81 +++++++++++++++++++++++++ meson_options.txt | 10 +++ po/LINGUAS | 1 + po/POTFILES.in | 2 + po/make-pot.sh | 5 ++ po/meson.build | 15 +++++ po/rex2.pot | 34 +++++++++++ po/update_potfiles.sh | 15 +++++ src/constants.rs | 10 --- src/constants.rs.in | 14 +++++ src/meson.build | 45 ++++++++++++++ src/ui/about_dialog.rs | 3 +- 21 files changed, 460 insertions(+), 11 deletions(-) create mode 100644 build-aux/dist-vendor.sh create mode 100644 data/icons/meson.build create mode 100644 data/icons/org.gabmus.rex2.Devel.svg create mode 100644 data/meson.build create mode 100644 data/org.gabmus.rex2.desktop.in.in create mode 100644 data/org.gabmus.rex2.metainfo.xml.in.in create mode 100644 data/resources.gresource.xml create mode 100644 data/style.css create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 po/LINGUAS create mode 100644 po/POTFILES.in create mode 100755 po/make-pot.sh create mode 100644 po/meson.build create mode 100644 po/rex2.pot create mode 100755 po/update_potfiles.sh delete mode 100644 src/constants.rs create mode 100644 src/constants.rs.in create mode 100644 src/meson.build diff --git a/.gitignore b/.gitignore index ea8c4bf..e032bb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,10 @@ /target +build/ +_build/ +builddir/ +build-aux/app +build-aux/.flatpak-builder/ +src/constants.rs +.flatpak/ +vendor +*.mo diff --git a/build-aux/dist-vendor.sh b/build-aux/dist-vendor.sh new file mode 100644 index 0000000..809bccf --- /dev/null +++ b/build-aux/dist-vendor.sh @@ -0,0 +1,9 @@ +#!/bin/bash +export DIST="$1" +export SOURCE_ROOT="$2" + +cd "$SOURCE_ROOT" +mkdir "$DIST"/.cargo +cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config +# Move vendor into dist tarball directory +mv vendor "$DIST" diff --git a/data/icons/meson.build b/data/icons/meson.build new file mode 100644 index 0000000..2ab86e9 --- /dev/null +++ b/data/icons/meson.build @@ -0,0 +1,10 @@ +install_data( + '@0@.svg'.format(application_id), + install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps' +) + +install_data( + '@0@-symbolic.svg'.format(base_id), + install_dir: iconsdir / 'hicolor' / 'symbolic' / 'apps', + rename: '@0@-symbolic.svg'.format(application_id) +) diff --git a/data/icons/org.gabmus.rex2.Devel.svg b/data/icons/org.gabmus.rex2.Devel.svg new file mode 100644 index 0000000..f347401 --- /dev/null +++ b/data/icons/org.gabmus.rex2.Devel.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..20c131b --- /dev/null +++ b/data/meson.build @@ -0,0 +1,77 @@ +subdir('icons') +# Desktop file +desktop_file = i18n.merge_file( + type: 'desktop', + input: configure_file( + input: '@0@.desktop.in.in'.format(base_id), + output: '@BASENAME@', + configuration: global_conf + ), + output: '@0@.desktop'.format(application_id), + po_dir: podir, + install: true, + install_dir: datadir / 'applications' +) +# Validate Desktop file +if desktop_file_validate.found() + test( + 'validate-desktop', + desktop_file_validate, + args: [ + desktop_file.full_path() + ], + depends: desktop_file, + ) +endif + +# Appdata +appdata_file = i18n.merge_file( + input: configure_file( + input: '@0@.metainfo.xml.in.in'.format(base_id), + output: '@BASENAME@', + configuration: global_conf + ), + output: '@0@.metainfo.xml'.format(application_id), + po_dir: podir, + install: true, + install_dir: datadir / 'metainfo' +) +# Validate Appdata +if appstream_util.found() + test( + 'validate-appdata', appstream_util, + args: [ + 'validate', '--nonet', appdata_file.full_path() + ], + depends: appdata_file, + ) +endif + +#### Gschema currently disabled, using json config +# GSchema +# configure_file( +# input: '@0@.gschema.xml.in'.format(base_id), +# output: '@0@.gschema.xml'.format(application_id), +# configuration: global_conf, +# install: true, +# install_dir: datadir / 'glib-2.0' / 'schemas' +# ) + +# Validata GSchema +# if glib_compile_schemas.found() +# test( +# 'validate-gschema', glib_compile_schemas, +# args: [ +# '--strict', '--dry-run', meson.current_build_dir() +# ], +# ) +# endif + +resources = gnome.compile_resources( + 'resources', + 'resources.gresource.xml', + gresource_bundle: true, + source_dir: meson.current_build_dir(), + install: true, + install_dir: pkgdatadir, +) diff --git a/data/org.gabmus.rex2.desktop.in.in b/data/org.gabmus.rex2.desktop.in.in new file mode 100644 index 0000000..929af2e --- /dev/null +++ b/data/org.gabmus.rex2.desktop.in.in @@ -0,0 +1,13 @@ +[Desktop Entry] +# Translators: Do NOT translate or transliterate this text +Name=@PRETTY_NAME@ +Comment=GUI for Monado +Type=Application +Exec=@CMD_NAME@ +Terminal=false +Categories=GNOME;GTK;Game; +# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +Keywords=vr;virtual;reality;monado; +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=@APP_ID@ +StartupNotify=true diff --git a/data/org.gabmus.rex2.metainfo.xml.in.in b/data/org.gabmus.rex2.metainfo.xml.in.in new file mode 100644 index 0000000..8ef6f9c --- /dev/null +++ b/data/org.gabmus.rex2.metainfo.xml.in.in @@ -0,0 +1,35 @@ + + + @APP_ID@ + CC0 + AGPL-3.0 + @PRETTY_NAME@ + GUI for Monado + +

GUI for Monado

+
+ + @REPO_URL@ + @REPO_URL@/issues + + + + + + + ModernToolkit + HiDpiIcon + + Gabriele Musco + gabmus@disroot.org + @GETTEXT_PACKAGE@ + @APP_ID@.desktop +
diff --git a/data/resources.gresource.xml b/data/resources.gresource.xml new file mode 100644 index 0000000..9324408 --- /dev/null +++ b/data/resources.gresource.xml @@ -0,0 +1,9 @@ + + + + style.css + + icons/org.gabmus.rex2.svg + icons/org.gabmus.rex2-symbolic.svg + + diff --git a/data/style.css b/data/style.css new file mode 100644 index 0000000..e69de29 diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..89dc05f --- /dev/null +++ b/meson.build @@ -0,0 +1,81 @@ +project( + 'rex2', + 'rust', + version: '0.1.0', + meson_version: '>= 0.59', + license: 'AGPL-3.0', +) + +i18n = import('i18n') +gnome = import('gnome') + +base_id = 'org.gabmus.rex2' +pretty_name = 'Rex2' +upstream_repo = 'https://gitlab.com/gabmus/rex2' +author = 'The Rex2 Team' +description = 'GUI for Monado' # temporary + +dependency('glib-2.0', version: '>= 2.66') +dependency('gio-2.0', version: '>= 2.66') +dependency('gtk4', version: '>= 4.10.0') + +glib_compile_resources = find_program('glib-compile-resources', required: true) +# glib_compile_schemas = find_program('glib-compile-schemas', required: true) +desktop_file_validate = find_program('desktop-file-validate', required: false) +appstream_util = find_program('appstream-util', required: false) +cargo = find_program('cargo', required: true) + +version = meson.project_version() + +prefix = get_option('prefix') +bindir = prefix / get_option('bindir') +localedir = prefix / get_option('localedir') + +datadir = prefix / get_option('datadir') +pkgdatadir = datadir / meson.project_name() +iconsdir = datadir / 'icons' +podir = meson.project_source_root() / 'po' +gettext_package = meson.project_name() + +if get_option('profile') == 'development' + profile = 'Devel' + vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: false).stdout().strip() + if vcs_tag == '' + version_suffix = '-devel' + else + version_suffix = '-@0@'.format(vcs_tag) + endif + application_id = '@0@.@1@'.format(base_id, profile) +else + profile = '' + version_suffix = '' + application_id = base_id +endif + +meson.add_dist_script( + 'build-aux/dist-vendor.sh', + meson.project_build_root() / 'meson-dist' / meson.project_name() + '-' + version, + meson.project_source_root() +) + +global_conf = configuration_data() +global_conf.set('APP_ID', application_id) +global_conf.set('PKGDATADIR', pkgdatadir) +global_conf.set('PROFILE', profile) +global_conf.set('VERSION', version + version_suffix) +global_conf.set('GETTEXT_PACKAGE', gettext_package) +global_conf.set('LOCALEDIR', localedir) +global_conf.set('AUTHOR', author) +global_conf.set('PRETTY_NAME', pretty_name) +global_conf.set('CMD_NAME', meson.project_name()) +global_conf.set('REPO_URL', upstream_repo) + +subdir('data') +subdir('po') +subdir('src') + +gnome.post_install( + gtk_update_icon_cache: true, + glib_compile_schemas: false, + update_desktop_database: true, +) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..649ad5d --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,10 @@ +option( + 'profile', + type: 'combo', + choices: [ + 'default', + 'development' + ], + value: 'default', + description: 'The build profile. One of "default" or "development".' +) diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..378755f --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +# it diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..463ed46 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,2 @@ +data/org.gabmus.rex2.desktop.in.in +data/org.gabmus.rex2.metainfo.xml.in.in diff --git a/po/make-pot.sh b/po/make-pot.sh new file mode 100755 index 0000000..1c993c2 --- /dev/null +++ b/po/make-pot.sh @@ -0,0 +1,5 @@ +if [[ ! -d build ]]; then + meson setup build -Dprefix="$PWD/build/testdir" +fi + +ninja -C build rex2-pot diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..c74cae2 --- /dev/null +++ b/po/meson.build @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2022 Emmanuele Bassi +# SPDX-License-Identifier: GPL-3.0-or-later + +i18n.gettext( + gettext_package, + args: [ + '--keyword=i18n', + '--keyword=i18n_f', + '--keyword=i18n_k', + '--keyword=ni18n:1,2', + '--keyword=ni18n_f:1,2', + '--keyword=ni18n_k:1,2', + ], + preset: 'glib', +) diff --git a/po/rex2.pot b/po/rex2.pot new file mode 100644 index 0000000..602328a --- /dev/null +++ b/po/rex2.pot @@ -0,0 +1,34 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the rex2 package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: rex2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-06-18 11:17+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#. Translators: Do NOT translate or transliterate this text +#: data/org.gabmus.rex2.desktop.in.in:4 +msgid "@PRETTY_NAME@" +msgstr "" + +#: data/org.gabmus.rex2.desktop.in.in:5 +#: data/org.gabmus.rex2.metainfo.xml.in.in:7 +#: data/org.gabmus.rex2.metainfo.xml.in.in:9 +msgid "GUI for Monado" +msgstr "" + +#. Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +#: data/org.gabmus.rex2.desktop.in.in:11 +msgid "vr;virtual;reality;monado;" +msgstr "" diff --git a/po/update_potfiles.sh b/po/update_potfiles.sh new file mode 100755 index 0000000..81361e8 --- /dev/null +++ b/po/update_potfiles.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +APPID="org.gabmus.rex2" + +rm po/POTFILES.in po/POTFILES.in.in + +{ + grep -Fl "gettext(\"" src/**.rs + # grep -Fl "_(\"" data/resources/ui/**.blp + echo "data/${APPID}.desktop.in.in" + echo "data/${APPID}.metainfo.xml.in.in" +} >> po/POTFILES.in.in + +sort < po/POTFILES.in.in | uniq > po/POTFILES.in +rm po/POTFILES.in.in diff --git a/src/constants.rs b/src/constants.rs deleted file mode 100644 index cb4a792..0000000 --- a/src/constants.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub const APP_NAME: &str = "Rex2"; -pub const APP_ID: &str = "org.gabmus.rex2"; -pub const CMD_NAME: &str = "rex2"; -pub const VERSION: &str = "0.1"; -pub const REPO_URL: &str = "https://gitlab.com/gabmus/rex2"; -pub const SINGLE_DEVELOPER: &str = "The Rex2 Team"; - -pub fn get_developers() -> Vec { - vec!["Gabriele Musco ".to_string()] -} diff --git a/src/constants.rs.in b/src/constants.rs.in new file mode 100644 index 0000000..b21d03a --- /dev/null +++ b/src/constants.rs.in @@ -0,0 +1,14 @@ +pub const APP_NAME: &str = "@PRETTY_NAME@"; +pub const APP_ID: &str = "@APP_ID@"; +pub const PKG_DATA_DIR: &str = "@PKGDATADIR@"; +pub const CMD_NAME: &str = "@CMD_NAME@"; +pub const VERSION: &str = "@VERSION@"; +pub const REPO_URL: &str = "@UPSTREAM_REPO_URL@"; +pub const SINGLE_DEVELOPER: &str = "@AUTHOR@"; +pub const GETTEXT_PACKAGE: &str = "@GETTEXT_PACKAGE@"; +pub const LOCALE_DIR: &str = "@LOCALEDIR@"; +pub const BUILD_PROFILE: &str = "@PROFILE@"; + +pub fn get_developers() -> Vec { + vec!["Gabriele Musco ".to_string()] +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..8805504 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,45 @@ +config = configure_file( + input: 'constants.rs.in', + output: 'constants.rs', + configuration: global_conf +) +# Copy the config.rs output to the source directory. +run_command( + 'cp', + meson.project_build_root() / 'src' / 'constants.rs', + meson.project_source_root() / 'src' / 'constants.rs', + check: true +) + +cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ] +cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ] + +if get_option('profile') == 'default' + cargo_options += [ '--release' ] + rust_target = 'release' + message('Building in release mode') +else + rust_target = 'debug' + message('Building in debug mode') +endif + +cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ] + +cargo_build = custom_target( + 'cargo-build', + build_by_default: true, + build_always_stale: true, + output: meson.project_name(), + console: true, + install: true, + install_dir: bindir, + depends: resources, + command: [ + 'env', + cargo_env, + cargo, 'build', + cargo_options, + '&&', + 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@', + ] +) diff --git a/src/ui/about_dialog.rs b/src/ui/about_dialog.rs index a3a4983..1945279 100644 --- a/src/ui/about_dialog.rs +++ b/src/ui/about_dialog.rs @@ -1,4 +1,4 @@ -use crate::constants::{get_developers, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION}; +use crate::constants::{get_developers, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION, APP_ID}; use relm4::gtk::traits::GtkWindowExt; use relm4::prelude::*; use relm4::{ComponentParts, SimpleComponent}; @@ -15,6 +15,7 @@ impl SimpleComponent for AboutDialog { fn init_root() -> Self::Root { adw::AboutWindow::builder() .application_name(APP_NAME) + .application_icon(APP_ID) .license_type(gtk::License::Agpl30) .version(VERSION) .website(REPO_URL)