use libmtp_sys as ffi;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::ToPrimitive;
use std::{
ffi::CStr,
fmt::{self, Display},
};
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum Property {
StorageId = 0,
ObjectFormat,
ProtectionStatus,
ObjectSize,
AssociationType,
AssociationDesc,
ObjectFileName,
DateCreated,
DateModified,
Keywords,
ParentObject,
AllowedFolderContents,
Hidden,
SystemObject,
PersistantUniqueObjectIdentifier,
SyncId,
PropertyBag,
Name,
CreatedBy,
Artist,
DateAuthored,
Description,
UrlReference,
LanguageLocale,
CopyrightInformation,
Source,
OriginLocation,
DateAdded,
NonConsumable,
CorruptOrUnplayable,
ProducerSerialNumber,
RepresentativeSampleFormat,
RepresentativeSampleSize,
RepresentativeSampleHeight,
RepresentativeSampleWidth,
RepresentativeSampleDuration,
RepresentativeSampleData,
Width,
Height,
Duration,
Rating,
Track,
Genre,
Credits,
Lyrics,
SubscriptionContentId,
ProducedBy,
UseCount,
SkipCount,
LastAccessed,
ParentalRating,
MetaGenre,
Composer,
EffectiveRating,
Subtitle,
OriginalReleaseDate,
AlbumName,
AlbumArtist,
Mood,
DrmStatus,
SubDescription,
IsCropped,
IsColorCorrected,
ImageBitDepth,
Fnumber,
ExposureTime,
ExposureIndex,
DisplayName,
BodyText,
Subject,
Priority,
GivenName,
MiddleNames,
FamilyName,
Prefix,
Suffix,
PhoneticGivenName,
PhoneticFamilyName,
EmailPrimary,
EmailPersonal1,
EmailPersonal2,
EmailBusiness1,
EmailBusiness2,
EmailOthers,
PhoneNumberPrimary,
PhoneNumberPersonal,
PhoneNumberPersonal2,
PhoneNumberBusiness,
PhoneNumberBusiness2,
PhoneNumberMobile,
PhoneNumberMobile2,
FaxNumberPrimary,
FaxNumberPersonal,
FaxNumberBusiness,
PagerNumber,
PhoneNumberOthers,
PrimaryWebAddress,
PersonalWebAddress,
BusinessWebAddress,
InstantMessengerAddress,
InstantMessengerAddress2,
InstantMessengerAddress3,
PostalAddressPersonalFull,
PostalAddressPersonalFullLine1,
PostalAddressPersonalFullLine2,
PostalAddressPersonalFullCity,
PostalAddressPersonalFullRegion,
PostalAddressPersonalFullPostalCode,
PostalAddressPersonalFullCountry,
PostalAddressBusinessFull,
PostalAddressBusinessLine1,
PostalAddressBusinessLine2,
PostalAddressBusinessCity,
PostalAddressBusinessRegion,
PostalAddressBusinessPostalCode,
PostalAddressBusinessCountry,
PostalAddressOtherFull,
PostalAddressOtherLine1,
PostalAddressOtherLine2,
PostalAddressOtherCity,
PostalAddressOtherRegion,
PostalAddressOtherPostalCode,
PostalAddressOtherCountry,
OrganizationName,
PhoneticOrganizationName,
Role,
Birthdate,
MessageTo,
MessageCC,
MessageBCC,
MessageRead,
MessageReceivedTime,
MessageSender,
ActivityBeginTime,
ActivityEndTime,
ActivityLocation,
ActivityRequiredAttendees,
ActivityOptionalAttendees,
ActivityResources,
ActivityAccepted,
Owner,
Editor,
Webmaster,
UrlSource,
UrlDestination,
TimeBookmark,
ObjectBookmark,
ByteBookmark,
LastBuildDate,
TimeToLive,
MediaGuid,
TotalBitRate,
BitRateType,
SampleRate,
NumberOfChannels,
AudioBitDepth,
ScanDepth,
AudioWaveCodec,
AudioBitRate,
VideoFourCCCodec,
FramesPerThousandSeconds,
KeyFrameDistance,
BufferSize,
EncodingQuality,
EncodingProfile,
BuyFlag,
Unknown,
}
impl Display for Property {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ptype = self.to_u32().expect("Unexpected Property variant?");
unsafe {
let desc = ffi::LIBMTP_Get_Property_Description(ptype);
let cstr = CStr::from_ptr(desc);
write!(f, "{}", cstr.to_str().unwrap())
}
}
}