tools: fix signed comparison warnings in bfuse
[barry.git] / examples / addmemo.cc
blob61380765c99890a2259957cdef62f39a7b642577
1 ///
2 /// \file addmemo.cc
3 /// Example code using the Barry library to add a memo
4 /// to a Blackberry device.
5 ///
7 /*
8 Copyright (C) 2009-2010, 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>
25 #include <fstream>
26 #include <iomanip>
28 using namespace std;
29 using namespace Barry;
32 void ReadLine(const char *prompt, std::string &data)
34 cout << prompt << ": ";
35 getline(cin, data);
38 void ReadInput(Barry::Memo &memo)
40 ReadLine("Title", memo.Title);
42 string body;
43 do {
44 ReadLine("Body line (blank to end)", body);
45 if( body.size() ) {
46 if( memo.Body.size() )
47 memo.Body += "\n";
48 memo.Body += body;
50 } while( body.size() );
52 string categories;
53 ReadLine("Categories", categories);
54 memo.Categories.CategoryStr2List(categories);
57 void Upload(const Barry::ProbeResult &device, const Barry::Memo &memo)
59 // connect to address book
60 Controller con(device);
61 Mode::Desktop desktop(con);
62 desktop.Open();
63 unsigned int id = desktop.GetDBID(Barry::Memo::GetDBName());
65 // find out what records are already there, and make new record ID
66 RecordStateTable table;
67 desktop.GetRecordStateTable(id, table);
68 uint32_t recordId = table.MakeNewRecordId();
70 // add it
71 desktop.AddRecordByType(recordId, memo);
72 cout << "Added successfully." << endl;
75 int main(int argc, char *argv[])
77 try {
79 Barry::Init();
81 Barry::Probe probe;
82 if( probe.GetCount() == 0 ) {
83 cout << "No Blackberry found!" << endl;
84 return 1;
86 else {
87 cout << "Using PIN: "
88 << probe.Get(0).m_pin.Str() << endl;
92 Barry::Memo memo;
93 ReadInput(memo);
94 Upload(probe.Get(0), memo);
97 catch( std::exception &e ) {
98 std::cerr << "Exception caught: " << e.what() << endl;
99 return 1;
102 return 0;