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-2009, 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.
26 #include <barry/barry.h>
30 using namespace Barry
;
33 void ReadLine(const char *prompt
, std::string
&data
)
35 cout
<< prompt
<< ": ";
39 bool ReadBool(const char *prompt
)
41 cout
<< prompt
<< "? (y/n) ";
44 return data
[0] == 'y' || data
[0] == 'Y';
47 time_t ReadTime(const char *prompt
)
50 char *unprocessed
= 0;
52 memset(&tm
, 0, sizeof(tm
));
56 cout
<< prompt
<< ": ";
58 unprocessed
= strptime(data
.c_str(), "%Y/%m/%d %H:%M", &tm
);
59 } while( !unprocessed
);
64 void ReadInput(Barry::Calendar
&cal
)
66 cal
.AllDayEvent
= ReadBool("All Day Event");
68 cout
<< "Note: enter dates in the following format: YYYY/MM/DD hh:mm\n";
69 cout
<< "Time is in 24 hour format\n\n";
70 cal
.StartTime
= ReadTime("Start Time");
71 cal
.EndTime
= ReadTime("End Time");
72 cal
.NotificationTime
= ReadTime("Notification Time");
74 ReadLine("Subject", cal
.Subject
);
75 ReadLine("Notes", cal
.Notes
);
76 ReadLine("Location", cal
.Location
);
78 cal
.Recurring
= false;
81 void Upload(const Barry::ProbeResult
&device
, const Barry::Calendar
&cal
)
83 // connect to address book
84 Controller
con(device
);
85 Mode::Desktop
desktop(con
);
87 unsigned int id
= desktop
.GetDBID("Calendar");
89 // find out what records are already there, and make new record ID
90 RecordStateTable table
;
91 desktop
.GetRecordStateTable(id
, table
);
92 uint32_t recordId
= table
.MakeNewRecordId();
95 desktop
.AddRecordByType(recordId
, cal
);
96 cout
<< "Added successfully: " << endl
<< cal
<< endl
;
99 int main(int argc
, char *argv
[])
106 if( probe
.GetCount() == 0 ) {
107 cout
<< "No Blackberry found!" << endl
;
114 cout
<< "Just before upload: " << cal
<< endl
;
115 Upload(probe
.Get(0), cal
);
118 catch( std::exception
&e
) {
119 std::cerr
<< "Exception caught: " << e
.what() << endl
;