i18n work in progress... desperately needs some housecleaning.
[barry.git] / examples / addcontact.cc
blob2eadd2b78a4a7e10c42e741cea17dbe93b757a30
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-2008, 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 Mode::Desktop desktop(con);
68 desktop.Open();
69 unsigned int id = desktop.GetDBID("Address Book");
71 // find out what records are already there, and make new record ID
72 RecordStateTable table;
73 desktop.GetRecordStateTable(id, table);
74 uint32_t recordId = table.MakeNewRecordId();
76 // add it
77 desktop.AddRecordByType(recordId, contact);
78 cout << "Added successfully." << endl;
81 int main(int argc, char *argv[])
83 try {
85 Barry::Init();
87 Barry::Probe probe;
88 if( probe.GetCount() == 0 ) {
89 cout << "No Blackberry found!" << endl;
90 return 1;
94 Barry::Contact contact;
95 ReadInput(contact);
96 Upload(probe.Get(0), contact);
99 catch( std::exception &e ) {
100 std::cerr << "Exception caught: " << e.what() << endl;
101 return 1;
104 return 0;