Skip to content

Commit

Permalink
Merge pull request #899 from pbor/settings-strv
Browse files Browse the repository at this point in the history
settings: implement strv setter and getter manually
  • Loading branch information
sdroege authored Jan 17, 2023
2 parents 776120e + 658073d commit e616855
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 53 deletions.
16 changes: 16 additions & 0 deletions gio/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,14 @@ status = "generate"
name = "set_modification_time"
# use SystemTime
manual = true
[[object.function]]
name = "get_attribute_stringv"
# use strv
manual = true
[[object.function]]
name = "set_attribute_stringv"
# use strv
manual = true

[[object]]
name = "Gio.FilterOutputStream"
Expand Down Expand Up @@ -1114,6 +1122,14 @@ status = "generate"
[object.function.return]
bool_return_is_error = "Can't set readonly key"
[[object.function]]
name = "get_strv"
# Use strv
manual = true
[[object.function]]
name = "set_strv"
# Use strv
manual = true
[[object.function]]
name = "bind"
manual = true
[[object.function]]
Expand Down
22 changes: 0 additions & 22 deletions gio/src/auto/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,6 @@ impl FileInfo {
}
}

#[doc(alias = "g_file_info_get_attribute_stringv")]
#[doc(alias = "get_attribute_stringv")]
pub fn attribute_stringv(&self, attribute: &str) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::g_file_info_get_attribute_stringv(
self.to_glib_none().0,
attribute.to_glib_none().0,
))
}
}

#[doc(alias = "g_file_info_get_attribute_type")]
#[doc(alias = "get_attribute_type")]
pub fn attribute_type(&self, attribute: &str) -> FileAttributeType {
Expand Down Expand Up @@ -425,17 +414,6 @@ impl FileInfo {
}
}

#[doc(alias = "g_file_info_set_attribute_stringv")]
pub fn set_attribute_stringv(&self, attribute: &str, attr_value: &[&str]) {
unsafe {
ffi::g_file_info_set_attribute_stringv(
self.to_glib_none().0,
attribute.to_glib_none().0,
attr_value.to_glib_none().0,
);
}
}

#[doc(alias = "g_file_info_set_attribute_uint32")]
pub fn set_attribute_uint32(&self, attribute: &str, attr_value: u32) {
unsafe {
Expand Down
29 changes: 0 additions & 29 deletions gio/src/auto/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ pub trait SettingsExt: 'static {
#[doc(alias = "get_string")]
fn string(&self, key: &str) -> glib::GString;

#[doc(alias = "g_settings_get_strv")]
#[doc(alias = "get_strv")]
fn strv(&self, key: &str) -> Vec<glib::GString>;

#[doc(alias = "g_settings_get_uint")]
#[doc(alias = "get_uint")]
fn uint(&self, key: &str) -> u32;
Expand Down Expand Up @@ -218,9 +214,6 @@ pub trait SettingsExt: 'static {
#[doc(alias = "g_settings_set_string")]
fn set_string(&self, key: &str, value: &str) -> Result<(), glib::error::BoolError>;

#[doc(alias = "g_settings_set_strv")]
fn set_strv(&self, key: &str, value: &[&str]) -> Result<(), glib::error::BoolError>;

#[doc(alias = "g_settings_set_uint")]
fn set_uint(&self, key: &str, value: u32) -> Result<(), glib::error::BoolError>;

Expand Down Expand Up @@ -385,15 +378,6 @@ impl<O: IsA<Settings>> SettingsExt for O {
}
}

fn strv(&self, key: &str) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::g_settings_get_strv(
self.as_ref().to_glib_none().0,
key.to_glib_none().0,
))
}
}

fn uint(&self, key: &str) -> u32 {
unsafe { ffi::g_settings_get_uint(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
}
Expand Down Expand Up @@ -544,19 +528,6 @@ impl<O: IsA<Settings>> SettingsExt for O {
}
}

fn set_strv(&self, key: &str, value: &[&str]) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::g_settings_set_strv(
self.as_ref().to_glib_none().0,
key.to_glib_none().0,
value.to_glib_none().0
),
"Can't set readonly key"
)
}
}

fn set_uint(&self, key: &str, value: u32) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
Expand Down
26 changes: 25 additions & 1 deletion gio/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::{Duration, SystemTime},
};

use glib::translate::*;
use glib::{translate::*, IntoStrV, StrV};

use crate::FileInfo;

Expand Down Expand Up @@ -47,4 +47,28 @@ impl FileInfo {
);
}
}

#[doc(alias = "g_file_info_get_attribute_stringv")]
#[doc(alias = "get_attribute_stringv")]
pub fn attribute_stringv(&self, attribute: &str) -> StrV {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::g_file_info_get_attribute_stringv(
self.to_glib_none().0,
attribute.to_glib_none().0,
))
}
}

#[doc(alias = "g_file_info_set_attribute_stringv")]
pub fn set_attribute_stringv(&self, attribute: &str, attr_value: impl IntoStrV) {
unsafe {
attr_value.run_with_strv(|attr_value| {
ffi::g_file_info_set_attribute_stringv(
self.to_glib_none().0,
attribute.to_glib_none().0,
attr_value.as_ptr() as *mut _,
);
});
}
}
}
33 changes: 32 additions & 1 deletion gio/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, translate::*, variant::FromVariant, BoolError, Variant};
use glib::{prelude::*, translate::*, variant::FromVariant, BoolError, IntoStrV, StrV, Variant};

use crate::{prelude::*, Settings, SettingsBindFlags};

Expand Down Expand Up @@ -170,6 +170,13 @@ pub trait SettingsExtManual {

fn set(&self, key: &str, value: impl Into<Variant>) -> Result<(), BoolError>;

#[doc(alias = "g_settings_get_strv")]
#[doc(alias = "get_strv")]
fn strv(&self, key: &str) -> StrV;

#[doc(alias = "g_settings_set_strv")]
fn set_strv(&self, key: &str, value: impl IntoStrV) -> Result<(), glib::error::BoolError>;

#[doc(alias = "g_settings_bind")]
#[doc(alias = "g_settings_bind_with_mapping")]
fn bind<'a, P: IsA<glib::Object>>(
Expand All @@ -196,6 +203,30 @@ impl<O: IsA<Settings>> SettingsExtManual for O {
self.set_value(key, &value.into())
}

fn strv(&self, key: &str) -> StrV {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::g_settings_get_strv(
self.as_ref().to_glib_none().0,
key.to_glib_none().0,
))
}
}

fn set_strv(&self, key: &str, value: impl IntoStrV) -> Result<(), glib::error::BoolError> {
unsafe {
value.run_with_strv(|value| {
glib::result_from_gboolean!(
ffi::g_settings_set_strv(
self.as_ref().to_glib_none().0,
key.to_glib_none().0,
value.as_ptr() as *mut _,
),
"Can't set readonly key"
)
})
}
}

fn bind<'a, P: IsA<glib::Object>>(
&'a self,
key: &'a str,
Expand Down

0 comments on commit e616855

Please sign in to comment.