1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License") {}
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "vcard_name_data.h"
16
17 #include "telephony_errors.h"
18
19 namespace OHOS {
20 namespace Telephony {
21
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)22 int32_t VCardNameData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
23 {
24 valuesBucket.Put(ContactData::TYPE_ID, TypeId::NAME);
25 if (!given_.empty()) {
26 valuesBucket.Put(ContactData::GIVEN_NAME, given_);
27 }
28 if (!family_.empty()) {
29 valuesBucket.Put(ContactData::FAMILY_NAME, family_);
30 }
31 if (!middle_.empty()) {
32 valuesBucket.Put(ContactData::MIDDLE_NAME, middle_);
33 }
34 if (!prefix_.empty()) {
35 valuesBucket.Put(ContactData::NAME_PREFIX, prefix_);
36 }
37 if (!suffix_.empty()) {
38 valuesBucket.Put(ContactData::NAME_SUFFIX, suffix_);
39 }
40 bool isPhoneticNameSpecified = false;
41 if (!phoneticGiven_.empty()) {
42 valuesBucket.Put(ContactData::GIVEN_NAME_PHONETIC, phoneticGiven_);
43 isPhoneticNameSpecified = true;
44 }
45 if (!phoneticFamily_.empty()) {
46 valuesBucket.Put(ContactData::FAMILY_NAME_PHONETIC, phoneticFamily_);
47 isPhoneticNameSpecified = true;
48 }
49 if (!phoneticMiddle_.empty()) {
50 valuesBucket.Put(ContactData::MIDDLE_NAME_PHONETIC, phoneticMiddle_);
51 isPhoneticNameSpecified = true;
52 }
53 if (!isPhoneticNameSpecified) {
54 valuesBucket.Put(ContactData::GIVEN_NAME_PHONETIC, sort_);
55 }
56 valuesBucket.Put(ContactData::FULL_NAME, displayName_);
57 return TELEPHONY_SUCCESS;
58 }
59
SetFamily(const std::string & family)60 void VCardNameData::SetFamily(const std::string &family)
61 {
62 family_ = family;
63 }
64
SetGiven(const std::string & given)65 void VCardNameData::SetGiven(const std::string &given)
66 {
67 given_ = given;
68 }
69
SetMiddle(const std::string & middle)70 void VCardNameData::SetMiddle(const std::string &middle)
71 {
72 middle_ = middle;
73 }
74
SetPrefix(const std::string & prefix)75 void VCardNameData::SetPrefix(const std::string &prefix)
76 {
77 prefix_ = prefix;
78 }
79
SetSuffix(const std::string & suffix)80 void VCardNameData::SetSuffix(const std::string &suffix)
81 {
82 suffix_ = suffix;
83 }
84
SetFormatted(const std::string & formatted)85 void VCardNameData::SetFormatted(const std::string &formatted)
86 {
87 formatted_ = formatted;
88 }
89
SetPhoneticFamily(const std::string & phoneticFamily)90 void VCardNameData::SetPhoneticFamily(const std::string &phoneticFamily)
91 {
92 phoneticFamily_ = phoneticFamily;
93 }
94
SetPhoneticGiven(const std::string & phoneticGiven)95 void VCardNameData::SetPhoneticGiven(const std::string &phoneticGiven)
96 {
97 phoneticGiven_ = phoneticGiven;
98 }
99
SetPhoneticMiddle(const std::string & phoneticMiddle)100 void VCardNameData::SetPhoneticMiddle(const std::string &phoneticMiddle)
101 {
102 phoneticMiddle_ = phoneticMiddle;
103 }
104
SetPhoneticName(const std::string & phoneticName)105 void VCardNameData::SetPhoneticName(const std::string &phoneticName)
106 {
107 phoneticName_ = phoneticName;
108 }
109
setSort(const std::string & sort)110 void VCardNameData::setSort(const std::string &sort)
111 {
112 sort_ = sort;
113 }
114
setDispalyName(const std::string & displayName)115 void VCardNameData::setDispalyName(const std::string &displayName)
116 {
117 displayName_ = displayName;
118 }
119
GetPrefix()120 std::string VCardNameData::GetPrefix()
121 {
122 return prefix_;
123 }
124
GetFamily()125 std::string VCardNameData::GetFamily()
126 {
127 return family_;
128 }
129
GetGiven()130 std::string VCardNameData::GetGiven()
131 {
132 return given_;
133 }
134
GetMiddle()135 std::string VCardNameData::GetMiddle()
136 {
137 return middle_;
138 }
139
GetSuffix()140 std::string VCardNameData::GetSuffix()
141 {
142 return suffix_;
143 }
144
GetFormatted()145 std::string VCardNameData::GetFormatted()
146 {
147 return formatted_;
148 }
149
GetPhoneticFamily()150 std::string VCardNameData::GetPhoneticFamily()
151 {
152 return phoneticFamily_;
153 }
154
GetPhoneticGiven()155 std::string VCardNameData::GetPhoneticGiven()
156 {
157 return phoneticGiven_;
158 }
159
GetPhoneticMiddle()160 std::string VCardNameData::GetPhoneticMiddle()
161 {
162 return phoneticMiddle_;
163 }
164
GetPhoneticName()165 std::string VCardNameData::GetPhoneticName()
166 {
167 return phoneticName_;
168 }
169
GetSort()170 std::string VCardNameData::GetSort()
171 {
172 return sort_;
173 }
174
GetDisplayName()175 std::string VCardNameData::GetDisplayName()
176 {
177 return displayName_;
178 }
179
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)180 int32_t VCardNameData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
181 {
182 if (resultSet == nullptr) {
183 return TELEPHONY_ERROR;
184 }
185 int32_t index;
186 resultSet->GetColumnIndex(ContactData::GIVEN_NAME, index);
187 resultSet->GetString(index, given_);
188 resultSet->GetColumnIndex(ContactData::FAMILY_NAME, index);
189 resultSet->GetString(index, family_);
190 resultSet->GetColumnIndex(ContactData::MIDDLE_NAME, index);
191 resultSet->GetString(index, middle_);
192 resultSet->GetColumnIndex(ContactData::NAME_PREFIX, index);
193 resultSet->GetString(index, prefix_);
194 resultSet->GetColumnIndex(ContactData::NAME_SUFFIX, index);
195 resultSet->GetString(index, suffix_);
196 resultSet->GetColumnIndex(ContactData::GIVEN_NAME_PHONETIC, index);
197 resultSet->GetString(index, phoneticGiven_);
198 resultSet->GetColumnIndex(ContactData::FAMILY_NAME_PHONETIC, index);
199 resultSet->GetString(index, phoneticFamily_);
200 resultSet->GetColumnIndex(ContactData::MIDDLE_NAME_PHONETIC, index);
201 resultSet->GetString(index, phoneticMiddle_);
202 resultSet->GetColumnIndex(ContactData::FULL_NAME, index);
203 resultSet->GetString(index, displayName_);
204 return TELEPHONY_SUCCESS;
205 }
206
207 } // namespace Telephony
208 } // namespace OHOS
209