Fairport
v1.0.38
|
00001 00002 00003 00004 00005 00006 00007 00008 #ifndef FAIRPORT_PST_CONTACT_H 00009 #define FAIRPORT_PST_CONTACT_H 00010 00011 #include <string> 00012 #include <memory> 00013 00014 #include "fairport/ndb/database_iface.h" 00015 #include "fairport/ndb/node.h" 00016 00017 #include "fairport/ltp/propbag.h" 00018 #include "fairport/ltp/table.h" 00019 #include "fairport/ltp/nameid.h" 00020 00021 #include "fairport/pst/pstutil.h" 00022 #include "fairport/pst/message.h" 00023 00024 namespace fairport 00025 { 00026 00029 00036 class contact : public detail::itembase 00037 { 00038 public: 00041 explicit contact(const node& n) 00042 : detail::itembase(n) { } 00043 00044 // property access 00048 std::wstring get_full_name() const 00049 { return get_property_bag().read_prop<std::wstring>(0x3001); } 00050 00054 std::wstring get_company() const 00055 { return get_property_bag().read_prop<std::wstring>(0x3a16); } 00058 bool has_company() const 00059 { return get_property_bag().prop_exists(0x3a16); } 00060 00064 std::wstring get_job_title() const 00065 { return get_property_bag().read_prop<std::wstring>(0x3a17); } 00068 bool has_job_title() const 00069 { return get_property_bag().prop_exists(0x3a17); } 00070 00074 std::wstring get_email_address() const 00075 { return get_property_bag().read_prop<std::wstring>(get_name_id_map().lookup(ps_contact, 0x8083)); } 00078 bool has_email_address() const 00079 { return get_property_bag().prop_exists(get_name_id_map().lookup(ps_contact, 0x8083)); } 00080 00084 std::wstring get_email_address2() const 00085 { return get_property_bag().read_prop<std::wstring>(get_name_id_map().lookup(ps_contact, 0x8093)); } 00088 bool has_email_address2() const 00089 { return get_property_bag().prop_exists(get_name_id_map().lookup(ps_contact, 0x8093)); } 00090 00094 std::wstring get_email_address3() const 00095 { return get_property_bag().read_prop<std::wstring>(get_name_id_map().lookup(ps_contact, 0x80a3)); } 00098 bool has_email_address3() const 00099 { return get_property_bag().prop_exists(get_name_id_map().lookup(ps_contact, 0x80a3)); } 00100 00104 std::wstring get_business_phone() const 00105 { return get_property_bag().read_prop<std::wstring>(0x3a08); } 00108 bool has_business_phone() const 00109 { return get_property_bag().prop_exists(0x3a08); } 00110 00114 std::wstring get_home_phone() const 00115 { return get_property_bag().read_prop<std::wstring>(0x3a09); } 00118 bool has_home_phone() const 00119 { return get_property_bag().prop_exists(0x3a09); } 00120 00124 std::wstring get_primary_phone() const 00125 { return get_property_bag().read_prop<std::wstring>(0x3a1a); } 00128 bool has_primary_phone() const 00129 { return get_property_bag().prop_exists(0x3a1a); } 00130 00134 std::wstring get_mobile_phone() const 00135 { return get_property_bag().read_prop<std::wstring>(0x3a1c); } 00138 bool has_mobile_phone() const 00139 { return get_property_bag().prop_exists(0x3a1c); } 00140 00144 std::wstring get_home_address() const 00145 { return get_property_bag().read_prop<std::wstring>(get_name_id_map().lookup(ps_contact, 0x801a)); } 00148 bool has_home_address() const 00149 { return get_property_bag().prop_exists(get_name_id_map().lookup(ps_contact, 0x801a)); } 00150 00154 std::wstring get_business_address() const 00155 { return get_property_bag().read_prop<std::wstring>(get_name_id_map().lookup(ps_contact, 0x801b)); } 00158 bool has_business_address() const 00159 { return get_property_bag().prop_exists(get_name_id_map().lookup(ps_contact, 0x801b)); } 00160 00164 attachment& get_contact_photo_attachment() 00165 { return const_cast<attachment&>(const_cast<const contact*>(this)->get_contact_photo_attachment()); } 00167 const attachment& get_contact_photo_attachment() const; 00171 std::vector<byte> get_contact_photo_bytes() const 00172 { return get_contact_photo_attachment().get_bytes(); } 00176 hnid_stream_device open_contact_photo_stream() 00177 { return get_contact_photo_attachment().open_byte_stream(); } 00181 bool has_contact_photo() const 00182 { return get_property_bag().read_prop<bool>(get_name_id_map().lookup(ps_contact, 0x8015)); } 00183 00184 private: 00185 const name_id_map& get_name_id_map() const; 00186 00187 mutable std::tr1::shared_ptr<name_id_map> m_map; 00188 mutable std::tr1::shared_ptr<attachment> m_photo; 00189 }; 00190 00191 typedef detail::item_transform_row<contact> contact_transform_row; 00192 00193 } // end namespace fairport 00194 00195 inline const fairport::name_id_map& fairport::contact::get_name_id_map() const 00196 { 00197 if(!m_map) 00198 m_map.reset(new name_id_map(get_property_bag().get_node().get_db())); 00199 00200 return *m_map; 00201 } 00202 00203 inline const fairport::attachment& fairport::contact::get_contact_photo_attachment() const 00204 { 00205 if(!m_photo) 00206 { 00207 table t(get_property_bag().get_node().lookup(nid_attachment_table)); 00208 00209 for(const_table_row_iter i = t.begin(); i != t.end(); ++i) 00210 { 00211 attachment a(property_bag(get_property_bag().get_node().lookup(i->get_row_id()))); 00212 if(a.get_property_bag().read_prop<bool>(0x7fff)) 00213 { 00214 m_photo.reset(new attachment(a)); 00215 break; 00216 } 00217 } 00218 00219 if(!m_photo) 00220 throw key_not_found<prop_id>(0x7fff); 00221 } 00222 00223 return *m_photo; 00224 } 00225 00226 #endif