mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Initial commit
This commit is contained in:
parent
9969fb065e
commit
9969ebcfd7
25 changed files with 2250 additions and 0 deletions
112
src/application.rs
Normal file
112
src/application.rs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* application.rs
|
||||
*
|
||||
* Copyright 2023 Unknown
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use gtk::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
use crate::config::VERSION;
|
||||
use crate::MusicusWindow;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MusicusApplication {}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MusicusApplication {
|
||||
const NAME: &'static str = "MusicusApplication";
|
||||
type Type = super::MusicusApplication;
|
||||
type ParentType = adw::Application;
|
||||
}
|
||||
|
||||
impl ObjectImpl for MusicusApplication {
|
||||
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 MusicusApplication {
|
||||
// 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 = if let Some(window) = application.active_window() {
|
||||
window
|
||||
} else {
|
||||
let window = MusicusWindow::new(&*application);
|
||||
window.upcast()
|
||||
};
|
||||
|
||||
// Ask the window manager/compositor to present the window
|
||||
window.present();
|
||||
}
|
||||
}
|
||||
|
||||
impl GtkApplicationImpl for MusicusApplication {}
|
||||
impl AdwApplicationImpl for MusicusApplication {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MusicusApplication(ObjectSubclass<imp::MusicusApplication>)
|
||||
@extends gio::Application, gtk::Application, adw::Application,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl MusicusApplication {
|
||||
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::AboutWindow::builder()
|
||||
.transient_for(&window)
|
||||
.application_name("musicus")
|
||||
.application_icon("de.johrpan.musicus")
|
||||
.developer_name("Unknown")
|
||||
.version(VERSION)
|
||||
.developers(vec!["Unknown"])
|
||||
.copyright("© 2023 Unknown")
|
||||
.build();
|
||||
|
||||
about.present();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue