2 /// \file addcontact.cc
3 /// Example code using the Barry library to add a contact
4 /// to a Blackberry device.
8 Copyright (C) 2006-2011, 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>
29 using namespace Barry
;
32 void ReadLine(const char *prompt
, std::string
&data
)
34 cout
<< prompt
<< ": ";
38 void ReadDate(const char *prompt
, Barry::Date
&date
)
43 ReadLine(prompt
, datestr
);
44 if( !datestr
.size() ) {
50 if( date
.FromYYYYMMDD(datestr
) )
53 cout
<< "Unable to parse date, try again" << endl
;
57 void ReadInput(Barry::Contact
&contact
)
59 ReadLine("First Name", contact
.FirstName
);
60 ReadLine("Last Name", contact
.LastName
);
61 ReadLine("Job Title", contact
.JobTitle
);
65 ReadLine("Email Address (blank to end)", email
);
67 contact
.EmailAddresses
.push_back(email
);
68 } while( email
.size() );
70 ReadLine("Main Phone Number", contact
.Phone
);
71 ReadLine("Home Phone Number", contact
.HomePhone
);
72 ReadLine("Work Phone Number", contact
.WorkPhone
);
73 ReadLine("Fax Number", contact
.Fax
);
74 ReadLine("Cell Number", contact
.MobilePhone
);
75 ReadLine("Pager Number", contact
.Pager
);
76 ReadLine("Company", contact
.Company
);
77 ReadLine("Address Line 1", contact
.WorkAddress
.Address1
);
78 ReadLine("Address Line 2", contact
.WorkAddress
.Address2
);
79 ReadLine("Address Line 3", contact
.WorkAddress
.Address3
);
80 ReadLine("City", contact
.WorkAddress
.City
);
81 ReadLine("Province / State", contact
.WorkAddress
.Province
);
82 ReadLine("Country", contact
.WorkAddress
.Country
);
83 ReadLine("Postal / Zip Code", contact
.WorkAddress
.PostalCode
);
84 ReadLine("Notes", contact
.Notes
);
86 ReadDate("Birthday (YYYYMMDD format)", contact
.Birthday
);
87 ReadDate("Anniversary (YYYYMMDD format)", contact
.Anniversary
);
90 ReadLine("Categories", categories
);
91 contact
.Categories
.CategoryStr2List(categories
);
94 ReadLine("Photo path", image_path
);
95 if( image_path
.size() ) {
96 ifstream
in(image_path
.c_str());
99 contact
.Image
.clear();
100 while( in
.read(block
, sizeof(block
)) ) {
101 contact
.Image
.append(block
, in
.gcount());
105 cout
<< "Can't open: " << image_path
<< endl
;
109 void Upload(const Barry::ProbeResult
&device
, const Barry::Contact
&contact
)
111 // connect to address book
112 Controller
con(device
);
113 Mode::Desktop
desktop(con
);
115 unsigned int id
= desktop
.GetDBID("Address Book");
117 // find out what records are already there, and make new record ID
118 RecordStateTable table
;
119 desktop
.GetRecordStateTable(id
, table
);
120 uint32_t recordId
= table
.MakeNewRecordId();
123 desktop
.AddRecordByType(recordId
, contact
);
124 cout
<< "Added successfully." << endl
;
127 int main(int argc
, char *argv
[])
134 if( probe
.GetCount() == 0 ) {
135 cout
<< "No Blackberry found!" << endl
;
139 cout
<< "Using PIN: "
140 << probe
.Get(0).m_pin
.Str() << endl
;
144 Barry::Contact contact
;
146 Upload(probe
.Get(0), contact
);
149 catch( std::exception
&e
) {
150 std::cerr
<< "Exception caught: " << e
.what() << endl
;