2 /// \file addcontact.cc
3 /// Example code using the Barry library to add a contact
4 /// to a Blackberry device.
8 Copyright (C) 2006-2009, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <barry/barry.h>
28 using namespace Barry
;
31 void ReadLine(const char *prompt
, std::string
&data
)
33 cout
<< prompt
<< ": ";
37 void ReadDate(const char *prompt
, Barry::Date
&date
)
42 ReadLine(prompt
, datestr
);
43 if( date
.FromYYYYMMDD(datestr
) )
46 cout
<< "Unable to parse date, try again" << endl
;
50 void ReadInput(Barry::Contact
&contact
)
52 ReadLine("First Name", contact
.FirstName
);
53 ReadLine("Last Name", contact
.LastName
);
54 ReadLine("Job Title", contact
.JobTitle
);
58 ReadLine("Email Address (blank to end)", email
);
60 contact
.EmailAddresses
.push_back(email
);
61 } while( email
.size() );
63 ReadLine("Main Phone Number", contact
.Phone
);
64 ReadLine("Home Phone Number", contact
.HomePhone
);
65 ReadLine("Work Phone Number", contact
.WorkPhone
);
66 ReadLine("Fax Number", contact
.Fax
);
67 ReadLine("Cell Number", contact
.MobilePhone
);
68 ReadLine("Pager Number", contact
.Pager
);
69 ReadLine("Company", contact
.Company
);
70 ReadLine("Address Line 1", contact
.WorkAddress
.Address1
);
71 ReadLine("Address Line 2", contact
.WorkAddress
.Address2
);
72 ReadLine("Address Line 3", contact
.WorkAddress
.Address3
);
73 ReadLine("City", contact
.WorkAddress
.City
);
74 ReadLine("Province / State", contact
.WorkAddress
.Province
);
75 ReadLine("Country", contact
.WorkAddress
.Country
);
76 ReadLine("Postal / Zip Code", contact
.WorkAddress
.PostalCode
);
77 ReadLine("Notes", contact
.Notes
);
79 ReadDate("Birthday (YYYYMMDD format)", contact
.Birthday
);
80 ReadDate("Anniversary (YYYYMMDD format)", contact
.Anniversary
);
83 ReadLine("Categories", categories
);
84 Contact::CategoryStr2List(categories
, contact
.Categories
);
87 void Upload(const Barry::ProbeResult
&device
, const Barry::Contact
&contact
)
89 // connect to address book
90 Controller
con(device
);
91 Mode::Desktop
desktop(con
);
93 unsigned int id
= desktop
.GetDBID("Address Book");
95 // find out what records are already there, and make new record ID
96 RecordStateTable table
;
97 desktop
.GetRecordStateTable(id
, table
);
98 uint32_t recordId
= table
.MakeNewRecordId();
101 desktop
.AddRecordByType(recordId
, contact
);
102 cout
<< "Added successfully." << endl
;
105 int main(int argc
, char *argv
[])
112 if( probe
.GetCount() == 0 ) {
113 cout
<< "No Blackberry found!" << endl
;
117 cout
<< "Using PIN: " << std::hex
118 << probe
.Get(0).m_pin
<< endl
;
122 Barry::Contact contact
;
124 Upload(probe
.Get(0), contact
);
127 catch( std::exception
&e
) {
128 std::cerr
<< "Exception caught: " << e
.what() << endl
;