- added raw data version of BuildField() to record-internal.h
[barry.git] / examples / addcontact.cc
blob026a88586b0fafd30d5595dd281659d49b7847d3
1 ///
2 /// \file addcontact.cc
3 /// Example code using the Barry library to add a contact
4 /// to a Blackberry device.
5 ///
7 /*
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>
24 #include <iostream>
26 using namespace std;
27 using namespace Barry;
30 void ReadLine(const char *prompt, std::string &data)
32 cout << prompt << ": ";
33 getline(cin, data);
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.WorkAddress.Address1);
50 ReadLine("Address Line 2", contact.WorkAddress.Address2);
51 ReadLine("Address Line 3", contact.WorkAddress.Address3);
52 ReadLine("City", contact.WorkAddress.City);
53 ReadLine("Province / State", contact.WorkAddress.Province);
54 ReadLine("Country", contact.WorkAddress.Country);
55 ReadLine("Postal / Zip Code", contact.WorkAddress.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();
71 // add it
72 con.AddRecordByType(recordId, contact);
73 cout << "Added successfully." << endl;
76 int main(int argc, char *argv[])
78 try {
80 Barry::Init();
82 Barry::Probe probe;
83 if( probe.GetCount() == 0 ) {
84 cout << "No Blackberry found!" << endl;
85 return 1;
89 Barry::Contact contact;
90 ReadInput(contact);
91 Upload(probe.Get(0), contact);
94 catch( std::exception &e ) {
95 std::cerr << "Exception caught: " << e.what() << endl;
96 return 1;
99 return 0;