translated src/application.vala
This commit is contained in:
parent
5bfaeade17
commit
4193fb72c2
4 changed files with 79 additions and 24 deletions
|
@ -1,36 +1,49 @@
|
|||
use gtk::{glib, gio};
|
||||
mod imp {
|
||||
use crate::ui;
|
||||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::glib;
|
||||
|
||||
pub mod ffi {
|
||||
#[repr(C)]
|
||||
pub struct AudreyApplication {
|
||||
pub parent_instance: adw::ffi::AdwApplication,
|
||||
#[derive(Default)]
|
||||
pub struct Application;
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for Application {
|
||||
const NAME: &'static str = "AudreyApplication";
|
||||
type Type = super::Application;
|
||||
type ParentType = adw::Application;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct AudreyApplicationClass {
|
||||
pub parent_class: adw::ffi::AdwApplicationClass,
|
||||
impl ObjectImpl for Application {}
|
||||
|
||||
impl ApplicationImpl for Application {
|
||||
fn activate(&self) {
|
||||
self.parent_activate();
|
||||
match self.obj().active_window() {
|
||||
None => ui::Window::new(self.obj().as_ref()).present(),
|
||||
Some(win) => win.present(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GtkApplicationImpl for Application {}
|
||||
|
||||
impl AdwApplicationImpl for Application {}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn audrey_application_get_type() -> glib::ffi::GType;
|
||||
fn audrey_application_new() -> *mut ffi::AudreyApplication;
|
||||
}
|
||||
use gtk::{gio, glib};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Application(Object<ffi::AudreyApplication, ffi::AudreyApplicationClass>)
|
||||
pub struct Application(ObjectSubclass<imp::Application>)
|
||||
@extends adw::Application, gtk::Application, gio::Application,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
|
||||
match fn {
|
||||
type_ => || audrey_application_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
impl Application {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
glib::translate::from_glib_full(audrey_application_new())
|
||||
}
|
||||
glib::Object::builder()
|
||||
.property("application-id", "eu.callcc.audrey")
|
||||
.property("flags", gio::ApplicationFlags::default())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
mod application;
|
||||
use application::{Application};
|
||||
pub use application::Application;
|
||||
|
||||
pub mod ui;
|
||||
|
||||
use gtk::prelude::*;
|
||||
use gtk::{glib, gio};
|
||||
use gtk::{gio, glib};
|
||||
|
||||
extern crate libsecret;
|
||||
|
||||
|
@ -11,8 +13,7 @@ extern crate libsecret;
|
|||
#[link(name = "json-glib-1.0")]
|
||||
#[link(name = "mpv")]
|
||||
#[link(name = "soup-3.0")]
|
||||
extern "C" {
|
||||
}
|
||||
extern "C" {}
|
||||
|
||||
fn main() -> glib::ExitCode {
|
||||
gio::resources_register_include!("audrey.gresource").expect("could not register resources");
|
||||
|
|
2
src/ui.rs
Normal file
2
src/ui.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
mod window;
|
||||
pub use window::Window;
|
39
src/ui/window.rs
Normal file
39
src/ui/window.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
mod ffi {
|
||||
use gtk::glib;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct UiWindow {
|
||||
parent_instance: adw::ffi::AdwApplicationWindow,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct UiWindowClass {
|
||||
parent_class: adw::ffi::AdwApplicationWindowClass,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn ui_window_get_type() -> glib::ffi::GType;
|
||||
pub fn ui_window_new(app: *mut gtk::ffi::GtkApplication) -> *mut UiWindow;
|
||||
}
|
||||
}
|
||||
|
||||
use adw::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Window(Object<ffi::UiWindow, ffi::UiWindowClass>)
|
||||
@extends adw::ApplicationWindow, gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
|
||||
match fn {
|
||||
type_ => || ffi::ui_window_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(app: &impl IsA<gtk::Application>) -> Self {
|
||||
use glib::translate::*;
|
||||
|
||||
unsafe { from_glib_none(ffi::ui_window_new(app.as_ref().to_glib_none().0)) }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue