-
-
Notifications
You must be signed in to change notification settings - Fork 127
Implement gio::File::set_attribute #1713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Take a look at the license at the top of the repository in the LICENSE file. | ||
sdroege marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use glib::{ | ||
object::ObjectType, | ||
translate::{IntoGlib, ToGlibPtr}, | ||
}; | ||
|
||
use crate::FileAttributeType; | ||
|
||
use std::ffi::CStr; | ||
|
||
#[derive(Debug)] | ||
pub struct FileAttributeValue<'a>(FileAttributeValueInner<'a>); | ||
|
||
impl From<&str> for FileAttributeValue<'_> { | ||
fn from(value: &str) -> Self { | ||
Self(FileAttributeValueInner::String( | ||
ToGlibPtr::<*mut libc::c_char>::to_glib_none(value).1, | ||
)) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a CStr> for FileAttributeValue<'a> { | ||
fn from(value: &'a CStr) -> Self { | ||
Self(FileAttributeValueInner::ByteString(value)) | ||
} | ||
} | ||
|
||
impl From<bool> for FileAttributeValue<'_> { | ||
fn from(value: bool) -> Self { | ||
Self(FileAttributeValueInner::Boolean(value.into_glib())) | ||
} | ||
} | ||
|
||
impl From<u32> for FileAttributeValue<'_> { | ||
fn from(value: u32) -> Self { | ||
Self(FileAttributeValueInner::Uint32(value)) | ||
} | ||
} | ||
|
||
impl From<i32> for FileAttributeValue<'_> { | ||
fn from(value: i32) -> Self { | ||
Self(FileAttributeValueInner::Int32(value)) | ||
} | ||
} | ||
|
||
impl From<u64> for FileAttributeValue<'_> { | ||
fn from(value: u64) -> Self { | ||
Self(FileAttributeValueInner::Uint64(value)) | ||
} | ||
} | ||
|
||
impl From<i64> for FileAttributeValue<'_> { | ||
fn from(value: i64) -> Self { | ||
Self(FileAttributeValueInner::Int64(value)) | ||
} | ||
} | ||
|
||
impl<'a, T: AsRef<glib::Object>> From<&'a T> for FileAttributeValue<'a> { | ||
fn from(value: &'a T) -> Self { | ||
Self(FileAttributeValueInner::Object(value.as_ref())) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a [&str]> for FileAttributeValue<'a> { | ||
fn from(value: &'a [&str]) -> Self { | ||
Self(FileAttributeValueInner::Stringv(value.into())) | ||
} | ||
} | ||
|
||
impl FileAttributeValue<'_> { | ||
pub(crate) fn type_(&self) -> FileAttributeType { | ||
self.0.type_() | ||
} | ||
|
||
pub(crate) fn as_ptr(&self) -> glib::ffi::gpointer { | ||
self.0.as_ptr() | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum FileAttributeValueInner<'a> { | ||
#[allow(dead_code)] // TODO remove this allow attribute when Pointer will be used by this crate | ||
Pointer(FileAttributeType, glib::ffi::gpointer), | ||
String(<&'a str as ToGlibPtr<'a, *mut libc::c_char>>::Storage), | ||
ByteString(&'a CStr), | ||
Boolean(glib::ffi::gboolean), | ||
Uint32(u32), | ||
Int32(i32), | ||
Uint64(u64), | ||
Int64(i64), | ||
Object(&'a glib::Object), | ||
Stringv(glib::StrV), | ||
} | ||
|
||
impl FileAttributeValueInner<'_> { | ||
pub(crate) fn type_(&self) -> FileAttributeType { | ||
match self { | ||
Self::Pointer(type_, _) => *type_, | ||
Self::String(_) => FileAttributeType::String, | ||
Self::ByteString(_) => FileAttributeType::ByteString, | ||
Self::Boolean(_) => FileAttributeType::Boolean, | ||
Self::Uint32(_) => FileAttributeType::Uint32, | ||
Self::Int32(_) => FileAttributeType::Int32, | ||
Self::Uint64(_) => FileAttributeType::Uint64, | ||
Self::Int64(_) => FileAttributeType::Int64, | ||
Self::Object(_) => FileAttributeType::Object, | ||
Self::Stringv(_) => FileAttributeType::Stringv, | ||
} | ||
} | ||
|
||
pub(crate) fn as_ptr(&self) -> glib::ffi::gpointer { | ||
match self { | ||
Self::Pointer(_, s) => *s, | ||
Self::String(s) => s.as_ptr() as _, | ||
Self::ByteString(s) => s.as_ptr() as _, | ||
Self::Boolean(s) => s as *const i32 as _, | ||
Self::Uint32(s) => s as *const u32 as _, | ||
Self::Int32(s) => s as *const i32 as _, | ||
Self::Uint64(s) => s as *const u64 as _, | ||
Self::Int64(s) => s as *const i64 as _, | ||
Self::Object(s) => s.as_ptr() as _, | ||
Self::Stringv(s) => s.as_ptr() as _, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.