diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index 8d9e553..128b4cd 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -9,7 +9,6 @@ chrono = "0.4.6" crossbeam-channel = "0.3.8" gdk = "0.11.0" gdk-pixbuf = "0.7.0" -glib = "0.8.0" gst = { version = "0.14.0", package = "gstreamer" } gst-player = { version = "0.14.0", package = "gstreamer-player" } humansize = "1.1.0" @@ -28,13 +27,18 @@ serde_json = "1.0.39" # html2text = "0.1.8" html2text = { git = "https://github.com/jugglerchris/rust-html2text" } + +[dependencies.glib] +features = ["subclassing"] +version = "0.8.0" + [dependencies.gettext-rs] git = "https://github.com/danigm/gettext-rs" branch = "no-gettext" features = ["gettext-system"] [dependencies.gtk] -features = ["v3_24"] +features = ["v3_24", "subclassing"] version = "0.7.0" [dependencies.gio] diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index 219686b..5f5f413 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -20,8 +20,13 @@ #![allow(new_without_default)] -use gio::{self, prelude::*, ActionMapExt, SettingsExt}; -use glib::{self, Variant}; +use glib; +use glib::subclass; +use glib::subclass::prelude::*; +use glib::translate::*; +use glib::{glib_object_impl, glib_object_subclass, glib_object_wrapper, glib_wrapper, Variant}; + +use gio::{self, prelude::*, ActionMapExt, ApplicationFlags, SettingsExt}; use gtk; use gtk::prelude::*; @@ -43,11 +48,56 @@ use crate::widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu}; use std::cell::RefCell; use std::env; use std::rc::Rc; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use crate::config::{APP_ID, LOCALEDIR}; use crate::i18n::i18n; +#[derive(Debug)] +struct AppState { + some_window: gtk::Window, + some_label: gtk::Label, +} + +pub struct HmdApplicationPrivate { + state: Mutex>, +} + +impl ObjectSubclass for HmdApplicationPrivate { + const NAME: &'static str = "HmdApplication"; + type ParentType = gtk::Application; + type Instance = subclass::simple::InstanceStruct; + type Class = subclass::simple::ClassStruct; + + glib_object_subclass!(); + + fn new() -> Self { + Self { + state: Mutex::new(None), + } + } +} + +impl ObjectImpl for HmdApplicationPrivate { + glib_object_impl!(); +} + +impl gio::subclass::prelude::ApplicationImpl for HmdApplicationPrivate { + fn activate(&self, app: &gio::Application) { + println!("activated!"); + } +} + +impl gtk::subclass::application::GtkApplicationImpl for HmdApplicationPrivate {} + +glib_wrapper! { + pub struct HmdApplication(Object, subclass::simple::ClassStruct, HmdApplicationClass>) @extends gio::Application, gtk::Application; + + match fn { + get_type => || HmdApplicationPrivate::get_type().to_glib(), + } +} + /// Creates an action named `name` in the action map `T with the handler `F` fn action(thing: &T, name: &str, action: F) where @@ -87,7 +137,7 @@ pub(crate) enum Action { #[derive(Debug, Clone)] pub(crate) struct App { - instance: gtk::Application, + instance: HmdApplication, window: gtk::ApplicationWindow, overlay: gtk::Overlay, settings: gio::Settings, @@ -100,7 +150,7 @@ pub(crate) struct App { } impl App { - pub(crate) fn new(application: >k::Application) -> Rc { + pub(crate) fn new(application: &HmdApplication) -> Rc { let settings = gio::Settings::new("org.gnome.Podcasts"); let (sender, receiver) = unbounded(); @@ -401,8 +451,17 @@ impl App { bindtextdomain("gnome-podcasts", LOCALEDIR); textdomain("gnome-podcasts"); - let application = gtk::Application::new(Some(APP_ID), gio::ApplicationFlags::empty()) - .expect("Application initialization failed..."); + let application = glib::Object::new( + HmdApplication::static_type(), + &[ + ("application-id", &Some(APP_ID)), + ("flags", &ApplicationFlags::empty()), + ], + ) + .expect("Application initialization failed...") + .downcast::() + .expect("Congrats, you have won a prize for triggering an impossible outcome"); + application.set_resource_base_path(Some("/org/gnome/Podcasts")); let weak_app = application.downgrade();