Initialize project
This commit is contained in:
112
src/application.rs
Normal file
112
src/application.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
/* application.rs
|
||||
*
|
||||
* Copyright (C) 2024 Elias Schriefer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use gettextrs::gettext;
|
||||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
use crate::config::{VERSION, PKGNAME};
|
||||
use crate::MensaAdwWindow;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MensaAdwApplication {}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MensaAdwApplication {
|
||||
const NAME: &'static str = "MensaAdwApplication";
|
||||
type Type = super::MensaAdwApplication;
|
||||
type ParentType = adw::Application;
|
||||
}
|
||||
|
||||
impl ObjectImpl for MensaAdwApplication {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
let obj = self.obj();
|
||||
obj.setup_gactions();
|
||||
obj.set_accels_for_action("app.quit", &["<primary>q"]);
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationImpl for MensaAdwApplication {
|
||||
// We connect to the activate callback to create a window when the application
|
||||
// has been launched. Additionally, this callback notifies us when the user
|
||||
// tries to launch a "second instance" of the application. When they try
|
||||
// to do that, we'll just present any existing window.
|
||||
fn activate(&self) {
|
||||
let application = self.obj();
|
||||
// Get the current window or create one if necessary
|
||||
let window = application.active_window().unwrap_or_else(|| {
|
||||
let window = MensaAdwWindow::new(&*application);
|
||||
window.upcast()
|
||||
});
|
||||
|
||||
// Ask the window manager/compositor to present the window
|
||||
window.present();
|
||||
}
|
||||
}
|
||||
|
||||
impl GtkApplicationImpl for MensaAdwApplication {}
|
||||
impl AdwApplicationImpl for MensaAdwApplication {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MensaAdwApplication(ObjectSubclass<imp::MensaAdwApplication>)
|
||||
@extends gio::Application, gtk::Application, adw::Application,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl MensaAdwApplication {
|
||||
pub fn new(application_id: &str, flags: &gio::ApplicationFlags) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("application-id", application_id)
|
||||
.property("flags", flags)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn setup_gactions(&self) {
|
||||
let quit_action = gio::ActionEntry::builder("quit")
|
||||
.activate(move |app: &Self, _, _| app.quit())
|
||||
.build();
|
||||
let about_action = gio::ActionEntry::builder("about")
|
||||
.activate(move |app: &Self, _, _| app.show_about())
|
||||
.build();
|
||||
self.add_action_entries([quit_action, about_action]);
|
||||
}
|
||||
|
||||
fn show_about(&self) {
|
||||
let window = self.active_window().unwrap();
|
||||
let about = adw::AboutDialog::builder()
|
||||
.application_name("mensa-adw")
|
||||
.application_icon(PKGNAME)
|
||||
.developer_name("Elias Schriefer")
|
||||
.version(VERSION)
|
||||
.developers(vec!["Elias Schriefer"])
|
||||
// Translators: Replace "translator-credits" with your name/username, and optionally an email or URL.
|
||||
.translator_credits(&gettext("translator-credits"))
|
||||
.copyright("© 2024 Elias Schriefer")
|
||||
.build();
|
||||
|
||||
about.present(Some(&window));
|
||||
}
|
||||
}
|
||||
26
src/config.rs
Normal file
26
src/config.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
/* config.rs
|
||||
*
|
||||
* Copyright (C) 2024 Elias Schriefer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
pub static VERSION: &str = "0.1.0";
|
||||
pub static GETTEXT_PACKAGE: &str = "mensa-adw";
|
||||
pub static LOCALEDIR: &str = "/app/share/locale";
|
||||
pub static PKGDATADIR: &str = "/app/share/mensa-adw";
|
||||
pub static PKGNAME: &str = "org.ddnss.sfs.git.eliasschriefer.Mensa";
|
||||
|
||||
26
src/config.rs.in
Normal file
26
src/config.rs.in
Normal file
@@ -0,0 +1,26 @@
|
||||
/* config.rs
|
||||
*
|
||||
* Copyright (C) 2024 Elias Schriefer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
pub static VERSION: &str = @VERSION@;
|
||||
pub static GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
|
||||
pub static LOCALEDIR: &str = @LOCALEDIR@;
|
||||
pub static PKGDATADIR: &str = @PKGDATADIR@;
|
||||
pub static PKGNAME: &str = @PKGNAME@;
|
||||
|
||||
24
src/gtk/help-overlay.blp
Normal file
24
src/gtk/help-overlay.blp
Normal file
@@ -0,0 +1,24 @@
|
||||
using Gtk 4.0;
|
||||
|
||||
ShortcutsWindow help_overlay {
|
||||
modal: true;
|
||||
|
||||
ShortcutsSection {
|
||||
section-name: 'shortcuts';
|
||||
max-height: 10;
|
||||
|
||||
ShortcutsGroup {
|
||||
title: C_('shortcut window', 'General');
|
||||
|
||||
ShortcutsShortcut {
|
||||
title: C_('shortcut window', 'Show Shortcuts');
|
||||
action-name: 'win.show-help-overlay';
|
||||
}
|
||||
|
||||
ShortcutsShortcut {
|
||||
title: C_('shortcut window', 'Quit');
|
||||
action-name: 'app.quit';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
src/main.rs
Normal file
55
src/main.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
/* main.rs
|
||||
*
|
||||
* Copyright (C) 2024 Elias Schriefer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
mod application;
|
||||
mod config;
|
||||
mod window;
|
||||
|
||||
use self::application::MensaAdwApplication;
|
||||
use self::window::MensaAdwWindow;
|
||||
|
||||
use config::{GETTEXT_PACKAGE, LOCALEDIR, PKGDATADIR, PKGNAME};
|
||||
use gettextrs::{bind_textdomain_codeset, bindtextdomain, textdomain};
|
||||
use gtk::{gio, glib};
|
||||
use gtk::prelude::*;
|
||||
|
||||
fn main() -> glib::ExitCode {
|
||||
// Set up gettext translations
|
||||
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8")
|
||||
.expect("Unable to set the text domain encoding");
|
||||
textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");
|
||||
|
||||
// Load resources
|
||||
let resources = gio::Resource::load(PKGDATADIR.to_owned() + "/mensa-adw.gresource")
|
||||
.expect("Could not load resources");
|
||||
gio::resources_register(&resources);
|
||||
|
||||
// Create a new GtkApplication. The application manages our main loop,
|
||||
// application windows, integration with the window manager/compositor, and
|
||||
// desktop features such as file opening and single-instance applications.
|
||||
let app = MensaAdwApplication::new(PKGNAME, &gio::ApplicationFlags::empty());
|
||||
|
||||
// Run the application. This function will block until the application
|
||||
// exits. Upon return, we have our exit code to return to the shell. (This
|
||||
// is the code you see when you do `echo $?` after running a command in a
|
||||
// terminal.
|
||||
app.run()
|
||||
}
|
||||
8
src/mensa-adw.gresource.xml
Normal file
8
src/mensa-adw.gresource.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/ddnss/sfs/git/eliasschriefer/Mensa">
|
||||
<file preprocess="xml-stripblanks">window.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
67
src/meson.build
Normal file
67
src/meson.build
Normal file
@@ -0,0 +1,67 @@
|
||||
pkgdatadir = get_option('prefix') / get_option('datadir') / meson.project_name()
|
||||
gnome = import('gnome')
|
||||
|
||||
blueprints = custom_target('blueprints',
|
||||
input: files(
|
||||
'gtk/help-overlay.blp',
|
||||
'window.blp',
|
||||
),
|
||||
output: '.',
|
||||
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
|
||||
)
|
||||
|
||||
gnome.compile_resources('mensa-adw',
|
||||
'mensa-adw.gresource.xml',
|
||||
gresource_bundle: true,
|
||||
install: true,
|
||||
install_dir: pkgdatadir,
|
||||
dependencies: blueprints,
|
||||
)
|
||||
|
||||
conf = configuration_data()
|
||||
conf.set_quoted('VERSION', meson.project_version())
|
||||
conf.set_quoted('GETTEXT_PACKAGE', 'mensa-adw')
|
||||
conf.set_quoted('LOCALEDIR', get_option('prefix') / get_option('localedir'))
|
||||
conf.set_quoted('PKGDATADIR', pkgdatadir)
|
||||
conf.set_quoted('PKGNAME', 'org.ddnss.sfs.git.eliasschriefer.Mensa')
|
||||
|
||||
configure_file(
|
||||
input: 'config.rs.in',
|
||||
output: 'config.rs',
|
||||
configuration: conf
|
||||
)
|
||||
|
||||
# Copy the config.rs output to the source directory.
|
||||
run_command(
|
||||
'cp',
|
||||
meson.project_build_root() / 'src' / 'config.rs',
|
||||
meson.project_source_root() / 'src' / 'config.rs',
|
||||
check: true
|
||||
)
|
||||
|
||||
cargo_bin = find_program('cargo')
|
||||
cargo_opt = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
|
||||
cargo_opt += [ '--target-dir', meson.project_build_root() / 'src' ]
|
||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||
|
||||
if get_option('buildtype') == 'release'
|
||||
cargo_opt += [ '--release' ]
|
||||
rust_target = 'release'
|
||||
else
|
||||
rust_target = 'debug'
|
||||
endif
|
||||
|
||||
cargo_build = custom_target(
|
||||
'cargo-build',
|
||||
build_by_default: true,
|
||||
build_always_stale: true,
|
||||
output: meson.project_name(),
|
||||
console: true,
|
||||
install: true,
|
||||
install_dir: get_option('bindir'),
|
||||
command: [
|
||||
'env', cargo_env,
|
||||
cargo_bin, 'build',
|
||||
cargo_opt, '&&', 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
|
||||
]
|
||||
)
|
||||
48
src/window.blp
Normal file
48
src/window.blp
Normal file
@@ -0,0 +1,48 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $MensaAdwWindow: Adw.ApplicationWindow {
|
||||
title: _('Mensa-adw');
|
||||
default-width: 800;
|
||||
default-height: 600;
|
||||
|
||||
content: Adw.ToolbarView {
|
||||
[top]
|
||||
Adw.HeaderBar {
|
||||
[end]
|
||||
MenuButton {
|
||||
primary: true;
|
||||
icon-name: 'open-menu-symbolic';
|
||||
tooltip-text: _('Main Menu');
|
||||
menu-model: primary_menu;
|
||||
}
|
||||
}
|
||||
|
||||
content: Label label {
|
||||
label: _('Hello, World!');
|
||||
|
||||
styles [
|
||||
"title-1",
|
||||
]
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
menu primary_menu {
|
||||
section {
|
||||
item {
|
||||
label: _('_Preferences');
|
||||
action: 'app.preferences';
|
||||
}
|
||||
|
||||
item {
|
||||
label: _('_Keyboard Shortcuts');
|
||||
action: 'win.show-help-overlay';
|
||||
}
|
||||
|
||||
item {
|
||||
label: _('_About Mensa-adw');
|
||||
action: 'app.about';
|
||||
}
|
||||
}
|
||||
}
|
||||
70
src/window.rs
Normal file
70
src/window.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
/* window.rs
|
||||
*
|
||||
* Copyright (C) 2024 Elias Schriefer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use gtk::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[template(resource = "/org/ddnss/sfs/git/eliasschriefer/Mensa/window.ui")]
|
||||
pub struct MensaAdwWindow {
|
||||
// Template widgets
|
||||
#[template_child]
|
||||
pub label: TemplateChild<gtk::Label>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MensaAdwWindow {
|
||||
const NAME: &'static str = "MensaAdwWindow";
|
||||
type Type = super::MensaAdwWindow;
|
||||
type ParentType = adw::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for MensaAdwWindow {}
|
||||
impl WidgetImpl for MensaAdwWindow {}
|
||||
impl WindowImpl for MensaAdwWindow {}
|
||||
impl ApplicationWindowImpl for MensaAdwWindow {}
|
||||
impl AdwApplicationWindowImpl for MensaAdwWindow {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MensaAdwWindow(ObjectSubclass<imp::MensaAdwWindow>)
|
||||
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl MensaAdwWindow {
|
||||
pub fn new<P: IsA<gtk::Application>>(application: &P) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("application", application)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user