- fixed the configure scripts and makefiles so that when building
[barry.git] / examples / addcontact.cc
blob7b0c2ce538db390386d08125c27f39cc4fe983b4
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);
58 string categories;
59 ReadLine("Categories", categories);
60 Contact::CategoryStr2List(categories, contact.Categories);
63 void Upload(const Barry::ProbeResult &device, const Barry::Contact &contact)
65 // connect to address book
66 Controller con(device);
67 con.OpenMode(Controller::Desktop);
68 unsigned int id = con.GetDBID("Address Book");
70 // find out what records are already there, and make new record ID
71 RecordStateTable table;
72 con.GetRecordStateTable(id, table);
73 uint32_t recordId = table.MakeNewRecordId();
75 // add it
76 con.AddRecordByType(recordId, contact);
77 cout << "Added successfully." << endl;
80 int main(int argc, char *argv[])
82 try {
84 Barry::Init();
86 Barry::Probe probe;
87 if( probe.GetCount() == 0 ) {
88 cout << "No Blackberry found!" << endl;
89 return 1;
93 Barry::Contact contact;
94 ReadInput(contact);
95 Upload(probe.Get(0), contact);
98 catch( std::exception &e ) {
99 std::cerr << "Exception caught: " << e.what() << endl;
100 return 1;
103 return 0;