Back to index

lightning-sunbird  0.9+nobinonly
nsAbOSXUtils.mm
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Peter Van der Beken.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@propagandism.org>
00024  *
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsAbOSXUtils.h"
00041 #include "nsString.h"
00042 #include "nsAbOSXCard.h"
00043 
00044 #include <AddressBook/AddressBook.h>
00045 
00046 NSString*
00047 WrapString(const nsString &aString)
00048 {
00049     PRUnichar* chars = NS_CONST_CAST(PRUnichar*, aString.get());
00050 
00051     return [NSString stringWithCharacters:chars
00052                                    length:aString.Length()];
00053 }
00054 
00055 void
00056 AppendToString(const NSString *aString, nsString &aResult)
00057 {
00058     if (aString) {
00059         const char *chars = [aString UTF8String];
00060         if (chars) {
00061             AppendUTF8toUTF16(chars, aResult);
00062         }
00063     }
00064 }
00065 
00066 void
00067 AssignToString(const NSString *aString, nsString &aResult)
00068 {
00069     if (aString) {
00070         const char *chars = [aString UTF8String];
00071         if (chars) {
00072             CopyUTF8toUTF16(chars, aResult);
00073         }
00074     }
00075 }
00076 
00077 void
00078 AppendToCString(const NSString *aString, nsCString &aResult)
00079 {
00080     if (aString) {
00081         const char *chars = [aString UTF8String];
00082         if (chars) {
00083             aResult.Append(chars);
00084         }
00085     }
00086 }
00087 
00088 // Some properties can't be easily mapped back and forth.
00089 #define DONT_MAP(moz_name, osx_property, osx_label, osx_key)
00090 
00091 #define DEFINE_PROPERTY(moz_name, osx_property, osx_label, osx_key) \
00092     { osx_property, osx_label, osx_key, &nsAbOSXCard::m_##moz_name, #moz_name },
00093 
00094 const nsAbOSXPropertyMap nsAbOSXUtils::kPropertyMap[] = {
00095     DEFINE_PROPERTY(FirstName, kABFirstNameProperty, nil, nil)
00096     DEFINE_PROPERTY(LastName, kABLastNameProperty, nil, nil)
00097     DONT_MAP("DisplayName", nil, nil, nil)
00098     DEFINE_PROPERTY(PhoneticFirstName, kABFirstNamePhoneticProperty, nil, nil)
00099     DEFINE_PROPERTY(PhoneticLastName, kABLastNamePhoneticProperty, nil, nil)
00100     DEFINE_PROPERTY(NickName, kABNicknameProperty, nil, nil)
00101     DONT_MAP(PrimaryEmail, kABEmailProperty, nil, nil)
00102     DONT_MAP(SecondEmail, kABEmailProperty, nil, nil)
00103     DEFINE_PROPERTY(WorkPhone, kABPhoneProperty, kABPhoneWorkLabel, nil)
00104     DEFINE_PROPERTY(HomePhone, kABPhoneProperty, kABPhoneHomeLabel, nil)
00105     DEFINE_PROPERTY(FaxNumber, kABPhoneProperty, kABPhoneWorkFAXLabel, nil)
00106     DEFINE_PROPERTY(PagerNumber, kABPhoneProperty, kABPhonePagerLabel, nil)
00107     DEFINE_PROPERTY(CellularNumber, kABPhoneProperty, kABPhoneMobileLabel, nil)
00108     DEFINE_PROPERTY(HomeAddress, kABAddressProperty, kABAddressHomeLabel,
00109                     kABAddressStreetKey)
00110     DEFINE_PROPERTY(HomeCity, kABAddressProperty, kABAddressHomeLabel,
00111                     kABAddressCityKey)
00112     DEFINE_PROPERTY(HomeState, kABAddressProperty, kABAddressHomeLabel,
00113                     kABAddressStateKey)
00114     DEFINE_PROPERTY(HomeZipCode, kABAddressProperty, kABAddressHomeLabel,
00115                     kABAddressZIPKey)
00116     DEFINE_PROPERTY(HomeCountry, kABAddressProperty, kABAddressHomeLabel,
00117                     kABAddressCountryKey)
00118     DEFINE_PROPERTY(WorkAddress, kABAddressProperty, kABAddressWorkLabel,
00119                     kABAddressStreetKey)
00120     DEFINE_PROPERTY(WorkCity, kABAddressProperty, kABAddressWorkLabel,
00121                     kABAddressCityKey)
00122     DEFINE_PROPERTY(WorkState, kABAddressProperty, kABAddressWorkLabel,
00123                     kABAddressStateKey)
00124     DEFINE_PROPERTY(WorkZipCode, kABAddressProperty, kABAddressWorkLabel,
00125                     kABAddressZIPKey)
00126     DEFINE_PROPERTY(WorkCountry, kABAddressProperty, kABAddressWorkLabel,
00127                     kABAddressCountryKey)
00128     DEFINE_PROPERTY(JobTitle, kABJobTitleProperty, nil, nil)
00129     DEFINE_PROPERTY(Department, kABDepartmentProperty, nil, nil)
00130     DEFINE_PROPERTY(Company, kABOrganizationProperty, nil, nil)
00131     DONT_MAP(_AimScreenName, kABAIMInstantProperty, nil, nil)
00132     DEFINE_PROPERTY(WebPage1, kABHomePageProperty, nil, nil)
00133     DONT_MAP(WebPage2, kABHomePageProperty, nil, nil)
00134     DONT_MAP(BirthYear, "birthyear", nil, nil)
00135     DONT_MAP(BirthMonth, "birthmonth", nil, nil)
00136     DONT_MAP(BirthDay, "birthday", nil, nil)
00137     DONT_MAP(Custom1, "custom1", nil, nil)
00138     DONT_MAP(Custom2, "custom2", nil, nil)
00139     DONT_MAP(Custom3, "custom3", nil, nil)
00140     DONT_MAP(Custom4, "custom4", nil, nil)
00141     DEFINE_PROPERTY(Note, kABNoteProperty, nil, nil)
00142     DONT_MAP("PreferMailFormat", nil, nil, nil)
00143     DONT_MAP("LastModifiedDate", modifytimestamp, nil, nil)
00144 };
00145 
00146 const PRUint32 nsAbOSXUtils::kPropertyMapSize =
00147     NS_ARRAY_LENGTH(nsAbOSXUtils::kPropertyMap);