gio: subclass: Add handle_local_options to Application
@@ -9,10 +9,12 @@ use glib::translate::*;
use glib::subclass::prelude::*;
+use glib::VariantDict;
+
use Application;
use ApplicationClass;
-use libc::{c_char, c_void};
+use libc::{c_char, c_int, c_void};
use std::convert;
use std::ffi::OsString;
use std::fmt;
@@ -123,6 +125,10 @@ pub trait ApplicationImpl: ApplicationImplExt + 'static {
fn startup(&self, application: &Application) {
self.parent_startup(application)
}
+
+ fn handle_local_options(&self, application: &Application, options: &VariantDict) -> i32 {
+ self.parent_handle_local_options(application, options)
+ }
}
pub trait ApplicationImplExt {
@@ -144,6 +150,7 @@ pub trait ApplicationImplExt {
fn parent_run_mainloop(&self, application: &Application);
fn parent_shutdown(&self, application: &Application);
fn parent_startup(&self, application: &Application);
+ fn parent_handle_local_options(&self, application: &Application, options: &VariantDict) -> i32;
}
impl<T: ApplicationImpl + ObjectImpl> ApplicationImplExt for T {
@@ -281,6 +288,19 @@ impl<T: ApplicationImpl + ObjectImpl> ApplicationImplExt for T {
f(application.to_glib_none().0)
}
}
+
+ fn parent_handle_local_options(&self, application: &Application, options: &VariantDict) -> i32 {
+ unsafe {
+ let data = self.get_type_data();
+ let parent_class = data.as_ref().get_parent_class() as *mut gio_sys::GApplicationClass;
+ if let Some(f) = (*parent_class).handle_local_options {
+ f(application.to_glib_none().0, options.to_glib_none().0)
+ } else {
+ // Continue default handling
+ -1
+ }
+ }
+ }
}
unsafe impl<T: ObjectSubclass + ApplicationImpl> IsSubclassable<T> for ApplicationClass {
@@ -298,6 +318,7 @@ unsafe impl<T: ObjectSubclass + ApplicationImpl> IsSubclassable<T> for Applicati
klass.run_mainloop = Some(application_run_mainloop::<T>);
klass.shutdown = Some(application_shutdown::<T>);
klass.startup = Some(application_startup::<T>);
+ klass.handle_local_options = Some(application_handle_local_options::<T>);
}
}
}
@@ -434,6 +455,20 @@ where
imp.startup(&wrap)
}
+unsafe extern "C" fn application_handle_local_options<T: ObjectSubclass>(
+ ptr: *mut gio_sys::GApplication,
+ options: *mut glib_sys::GVariantDict,
+) -> c_int
+where
+ T: ApplicationImpl,
+{
+ let instance = &*(ptr as *mut T::Instance);
+ let imp = instance.get_impl();
+ let wrap: Borrowed<Application> = from_glib_borrow(ptr);
+
+ imp.handle_local_options(&wrap, &from_glib_borrow(options))
+}
+
#[cfg(test)]
mod tests {
use super::*;
