2 /// \file addcontact.cc
3 /// Example code using the Barry library to add a contact
4 /// to a Blackberry device.
8 Copyright (C) 2006-2007, 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>
27 using namespace Barry
;
30 void ReadLine(const char *prompt
, std::string
&data
)
32 cout
<< prompt
<< ": ";
36 void ReadInput(Barry::Contact
&contact
)
38 ReadLine("First Name", contact
.FirstName
);
39 ReadLine("Last Name", contact
.LastName
);
40 ReadLine("Job Title", contact
.JobTitle
);
41 ReadLine("Email Address", contact
.Email
);
42 ReadLine("Main Phone Number", contact
.Phone
);
43 ReadLine("Home Phone Number", contact
.HomePhone
);
44 ReadLine("Work Phone Number", contact
.WorkPhone
);
45 ReadLine("Fax Number", contact
.Fax
);
46 ReadLine("Cell Number", contact
.MobilePhone
);
47 ReadLine("Pager Number", contact
.Pager
);
48 ReadLine("Company", contact
.Company
);
49 ReadLine("Address Line 1", contact
.Address1
);
50 ReadLine("Address Line 2", contact
.Address2
);
51 ReadLine("Address Line 3", contact
.Address3
);
52 ReadLine("City", contact
.City
);
53 ReadLine("Province / State", contact
.Province
);
54 ReadLine("Country", contact
.Country
);
55 ReadLine("Postal / Zip Code", contact
.PostalCode
);
56 ReadLine("Notes", contact
.Notes
);
59 void Upload(const Barry::ProbeResult
&device
, const Barry::Contact
&contact
)
61 // connect to address book
62 Controller
con(device
);
63 con
.OpenMode(Controller::Desktop
);
64 unsigned int id
= con
.GetDBID("Address Book");
66 // find out what records are already there, and make new record ID
67 RecordStateTable table
;
68 con
.GetRecordStateTable(id
, table
);
69 uint32_t recordId
= table
.MakeNewRecordId();
72 con
.AddRecordByType(recordId
, contact
);
73 cout
<< "Added successfully." << endl
;
76 int main(int argc
, char *argv
[])
83 if( probe
.GetCount() == 0 ) {
84 cout
<< "No Blackberry found!" << endl
;
89 Barry::Contact contact
;
91 Upload(probe
.Get(0), contact
);
94 catch( std::exception
&e
) {
95 std::cerr
<< "Exception caught: " << e
.what() << endl
;