use objc::{msg_send, sel, sel_impl};
use crate::{
foundation::{NSArray, NSData, NSDateComponents, NSString},
object,
objective_c_runtime::macros::interface_impl,
};
use super::{
CNContactRelation, CNInstantMessageAddress, CNLabeledValue, CNPhoneNumber, CNSocialProfile,
ICNContact, ICNPostalAddress,
};
object! {
unsafe pub struct CNMutableContact;
}
impl ICNContact for CNMutableContact {}
#[interface_impl(CNContact)]
impl CNMutableContact {
#[property]
pub fn set_name_prefix(&mut self, name_prefix: NSString) {
unsafe { msg_send![self.m_self(), setNamePrefix: name_prefix] }
}
#[property]
pub fn set_given_name(&mut self, given_name: NSString) {
unsafe { msg_send![self.m_self(), setGivenName: given_name] }
}
#[property]
pub fn set_middle_name(&mut self, middle_name: NSString) {
unsafe { msg_send![self.m_self(), setMiddleName: middle_name] }
}
#[property]
pub fn set_family_name(&mut self, family_name: NSString) {
unsafe { msg_send![self.m_self(), setFamilyName: family_name] }
}
#[property]
pub fn set_previous_family_name(&mut self, previous_family_name: NSString) {
unsafe { msg_send![self.m_self(), setPreviousFamilyName: previous_family_name] }
}
#[property]
pub fn set_name_suffix(&mut self, name_suffix: NSString) {
unsafe { msg_send![self.m_self(), setNameSuffix: name_suffix] }
}
#[property]
pub fn set_nickname(&mut self, nickname: NSString) {
unsafe { msg_send![self.m_self(), setNickname: nickname] }
}
#[property]
pub fn set_phonetic_given_name(&mut self, phonetic_given_name: NSString) {
unsafe { msg_send![self.m_self(), setPhoneticGivenName: phonetic_given_name] }
}
#[property]
pub fn set_phonetic_middle_name(&mut self, phonetic_middle_name: NSString) {
unsafe { msg_send![self.m_self(), setPhoneticMiddleName: phonetic_middle_name] }
}
#[property]
pub fn set_phonetic_family_name(&mut self, phonetic_family_name: NSString) {
unsafe { msg_send![self.m_self(), setPhoneticFamilyName: phonetic_family_name] }
}
#[property]
pub fn set_job_title(&mut self, job_title: NSString) {
unsafe { msg_send![self.m_self(), setJobTitle: job_title] }
}
#[property]
pub fn set_department_name(&mut self, department_name: NSString) {
unsafe { msg_send![self.m_self(), setDepartmentName: department_name] }
}
#[property]
pub fn set_organization_name(&mut self, organization_name: NSString) {
unsafe { msg_send![self.m_self(), setOrganizationName: organization_name] }
}
#[property]
pub fn set_phonetic_organization_name(&mut self, phonetic_organization_name: NSString) {
unsafe {
msg_send![
self.m_self(),
setPhoneticOrganizationName: phonetic_organization_name
]
}
}
#[property]
pub fn set_postal_addresses<PostalAddress>(
&mut self,
postal_addresses: NSArray<CNLabeledValue<PostalAddress>>,
) where
PostalAddress: ICNPostalAddress,
{
unsafe { msg_send![self.m_self(), setPostalAddresses: postal_addresses] }
}
#[property]
pub fn set_email_addresses(&mut self, email_addresses: NSArray<CNLabeledValue<NSString>>) {
unsafe { msg_send![self.m_self(), setEmailAddresses: email_addresses] }
}
#[property]
pub fn set_url_addresses(&mut self, url_addresses: NSArray<CNLabeledValue<NSString>>) {
unsafe { msg_send![self.m_self(), setUrlAddresses: url_addresses] }
}
#[property]
pub fn set_phone_numbers(&mut self, phone_numbers: NSArray<CNLabeledValue<CNPhoneNumber>>) {
unsafe { msg_send![self.m_self(), setPhoneNumbers: phone_numbers] }
}
#[property]
pub fn set_social_profiles(
&mut self,
social_profiles: NSArray<CNLabeledValue<CNSocialProfile>>,
) {
unsafe { msg_send![self.m_self(), setSocialProfiles: social_profiles] }
}
#[property]
pub fn set_dates(&mut self, dates: NSArray<CNLabeledValue<NSDateComponents>>) {
unsafe { msg_send![self.m_self(), setBirthdayDates: dates] }
}
#[property]
pub fn set_non_gregorian_birthday(&mut self, non_gregorian_birthday: NSDateComponents) {
unsafe {
msg_send![
self.m_self(),
setNonGregorianBirthday: non_gregorian_birthday
]
}
}
#[property]
pub fn set_birthday(&mut self, birthday: NSDateComponents) {
unsafe { msg_send![self.m_self(), setBirthday: birthday] }
}
#[property]
pub fn set_note(&mut self, note: NSString) {
unsafe { msg_send![self.m_self(), setNote: note] }
}
#[property]
pub fn set_image_data(&mut self, image_data: NSData) {
unsafe { msg_send![self.m_self(), setImageData: image_data] }
}
#[property]
pub fn set_contact_relations(
&mut self,
contact_relations: NSArray<CNLabeledValue<CNContactRelation>>,
) {
unsafe { msg_send![self.m_self(), setContactRelations: contact_relations] }
}
#[property]
pub fn set_instant_messenger_addresses(
&mut self,
instant_messenger_addresses: NSArray<CNLabeledValue<CNInstantMessageAddress>>,
) {
unsafe {
msg_send![
self.m_self(),
setInstantMessageAddresses: instant_messenger_addresses
]
}
}
}
#[cfg(test)]
mod test {
use crate::{
contacts::{CNContactType, CNMutableContact, ICNContact},
objective_c_runtime::traits::PNSObject,
};
#[test]
fn test_mutable_contact() {
let contact = CNMutableContact::m_new();
assert!(contact.p_birthday().is_none());
assert!(contact.p_contact_relations().count() == 0);
assert!(contact.p_contact_type() == CNContactType::Person);
assert!(contact.p_dates().count() == 0);
assert!(contact.p_department_name() == "");
assert!(contact.p_email_addresses().count() == 0);
assert!(contact.p_family_name() == "");
assert!(contact.p_given_name() == "");
assert!(contact.p_identifier() != "");
assert!(contact.p_image_data().is_none());
assert!(!contact.p_image_data_available());
assert!(contact.p_instant_messaging_addresses().count() == 0);
assert!(contact.p_job_title() == "");
assert!(contact.p_middle_name() == "");
assert!(contact.p_name_prefix() == "");
assert!(contact.p_name_suffix() == "");
assert!(contact.p_nickname() == "");
assert!(contact.p_non_gregorian_birthday().is_none());
assert!(contact.p_note() == "");
assert!(contact.p_organization_name() == "");
assert!(contact.p_phone_numbers().count() == 0);
assert!(contact.p_phonetic_given_name() == "");
assert!(contact.p_phonetic_middle_name() == "");
assert!(contact.p_phonetic_family_name() == "");
assert!(contact.p_postal_addresses().count() == 0);
assert!(contact.p_previous_family_name() == "");
assert!(contact.p_social_profiles().count() == 0);
assert!(contact.p_thumbnail_image_data().is_none());
assert!(contact.p_url_addresses().count() == 0);
}
}