libmtp-rs 0.7.7

High-level interface for the libmtp C library.
Documentation
//! Contains all the properties that `libmtp` claims to support and can handle. Note that some
//! devices and certain filetypes may not support some of these properties (but theorically every
//! object should support all properties).

use libmtp_sys as ffi;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::ToPrimitive;
use std::ffi::CStr;
use std::fmt::{self, Display};

/// Enumeration that holds the supported properties, this enum implements `Display` with the
/// description of the property.
#[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())
        }
    }
}