2 /// \file addcalendar.cc
3 /// Example code using the Barry library to add a calendar
4 /// entry to a Blackberry device.
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.
25 #include <barry/barry.h>
29 using namespace Barry
;
32 void ReadLine(const char *prompt
, std::string
&data
)
34 cout
<< prompt
<< ": ";
38 bool ReadBool(const char *prompt
)
40 cout
<< prompt
<< "? (y/n) ";
43 return data
[0] == 'y' || data
[0] == 'Y';
46 time_t ReadTime(const char *prompt
)
49 char *unprocessed
= 0;
51 memset(&tm
, 0, sizeof(tm
));
55 cout
<< prompt
<< ": ";
57 unprocessed
= strptime(data
.c_str(), "%Y/%m/%d %H:%M", &tm
);
58 } while( !unprocessed
);
63 void ReadInput(Barry::Calendar
&cal
)
65 cal
.AllDayEvent
= ReadBool("All Day Event");
67 cout
<< "Note: enter dates in the following format: YYYY/MM/DD hh:mm\n";
68 cout
<< "Time is in 24 hour format\n\n";
69 cal
.StartTime
= ReadTime("Start Time");
70 cal
.EndTime
= ReadTime("End Time");
71 cal
.NotificationTime
= ReadTime("Notification Time");
73 ReadLine("Subject", cal
.Subject
);
74 ReadLine("Notes", cal
.Notes
);
75 ReadLine("Location", cal
.Location
);
77 cal
.Recurring
= false;
80 void Upload(const Barry::ProbeResult
&device
, const Barry::Calendar
&cal
)
82 // connect to address book
83 Controller
con(device
);
84 Mode::Desktop
desktop(con
);
86 unsigned int id
= desktop
.GetDBID("Calendar");
88 // find out what records are already there, and make new record ID
89 RecordStateTable table
;
90 desktop
.GetRecordStateTable(id
, table
);
91 uint32_t recordId
= table
.MakeNewRecordId();
94 desktop
.AddRecordByType(recordId
, cal
);
95 cout
<< "Added successfully: " << endl
<< cal
<< endl
;
98 int main(int argc
, char *argv
[])
105 if( probe
.GetCount() == 0 ) {
106 cout
<< "No Blackberry found!" << endl
;
113 cout
<< "Just before upload: " << cal
<< endl
;
114 Upload(probe
.Get(0), cal
);
117 catch( std::exception
&e
) {
118 std::cerr
<< "Exception caught: " << e
.what() << endl
;