Bumped copyright dates to 2012
[barry/progweb.git] / desktop / src / BaseFrame.cc
blobad2a117a2f2aa91c403a555990d975be046be1fe
1 ///
2 /// \file BaseFrame.cc
3 /// Class for the fixed-size frame that holds the main app
4 ///
6 /*
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "BaseFrame.h"
23 #include "Mode_MainMenu.h"
24 #include "Mode_Sync.h"
25 #include "Mode_Browse.h"
26 #include "ClickImage.h"
27 #include "barrydesktop.h"
28 #include "windowids.h"
29 #include <wx/aboutdlg.h>
30 #include <iostream>
31 #include <sstream>
33 // include icons and logos
34 #include "../images/barry_logo_icon.xpm"
35 #include "../images/logo_NetDirect.xpm"
37 using namespace std;
39 BEGIN_EVENT_TABLE(BaseFrame, wxFrame)
40 EVT_SIZE (BaseFrame::OnSize)
41 EVT_PAINT (BaseFrame::OnPaint)
42 EVT_MOTION (BaseFrame::OnMouseMotion)
43 EVT_LEFT_DOWN (BaseFrame::OnLeftDown)
44 EVT_LEFT_UP (BaseFrame::OnLeftUp)
45 EVT_BUTTON (MainMenu_BackupAndRestore, BaseFrame::OnBackupRestore)
46 EVT_BUTTON (MainMenu_Sync, BaseFrame::OnSync)
47 EVT_BUTTON (MainMenu_Modem, BaseFrame::OnModem)
48 EVT_BUTTON (MainMenu_AppLoader, BaseFrame::OnAppLoader)
49 EVT_BUTTON (MainMenu_DeviceSwitch, BaseFrame::OnDeviceSwitch)
50 EVT_BUTTON (MainMenu_BrowseDatabases, BaseFrame::OnBrowseDatabases)
51 EVT_BUTTON (MainMenu_MediaManagement, BaseFrame::OnMediaManagement)
52 EVT_BUTTON (MainMenu_Misc, BaseFrame::OnMisc)
53 EVT_BUTTON (MainMenu_BackButton, BaseFrame::OnBackButton)
54 EVT_BUTTON (HotImage_BarryLogo, BaseFrame::OnBarryLogoClicked)
55 EVT_BUTTON (HotImage_NetDirectLogo, BaseFrame::OnNetDirectLogoClicked)
56 EVT_TEXT (Ctrl_DeviceCombo, BaseFrame::OnDeviceComboChange)
57 EVT_MENU (SysMenu_VerboseLogging, BaseFrame::OnVerboseLogging)
58 EVT_MENU (SysMenu_RenameDevice, BaseFrame::OnRenameDevice)
59 EVT_MENU (SysMenu_ResetDevice, BaseFrame::OnResetDevice)
60 EVT_MENU (SysMenu_RescanUsb, BaseFrame::OnRescanUsb)
61 EVT_MENU (SysMenu_About, BaseFrame::OnAbout)
62 EVT_MENU (SysMenu_Exit, BaseFrame::OnExit)
63 EVT_END_PROCESS (Process_BackupAndRestore, BaseFrame::OnTermBackupAndRestore)
64 END_EVENT_TABLE()
66 //////////////////////////////////////////////////////////////////////////////
67 // BaseFrame
69 BaseFrame::BaseFrame(const wxImage &background)
70 : wxFrame(NULL, wxID_ANY, _T("Barry Desktop Control Panel"),
71 wxPoint(50, 50),
72 wxSize(background.GetWidth(), background.GetHeight()),
73 wxMINIMIZE_BOX | wxCAPTION | wxCLOSE_BOX | wxSYSTEM_MENU |
74 wxCLIP_CHILDREN)
75 , TermCatcher(this, Process_BackupAndRestore)
76 , m_width(background.GetWidth())
77 , m_height(background.GetHeight())
78 , m_current_mode(0)
79 , m_backup_process(this)
81 // This is a workaround for different size behaviour
82 // in the GTK version of wxWidgets 2.9
83 SetClientSize(wxSize(background.GetWidth(), background.GetHeight()));
85 // load base bitmaps
86 m_background.reset( new wxBitmap(background) );
88 // the main menu mode always exists, but may not always be current
89 m_main_menu_mode.reset( new MainMenuMode(this) );
90 m_current_mode = m_main_menu_mode.get();
92 m_barry_logo.reset( new ClickableImage(this,
93 wxBitmap(barry_logo_icon_xpm), HotImage_BarryLogo,
94 4, 4, false) );
95 wxBitmap nd_logo(logo_NetDirect_xpm);
96 m_netdirect_logo.reset( new ClickableImage(this,
97 nd_logo, HotImage_NetDirectLogo,
98 m_width - 3 - nd_logo.GetWidth(),
99 (MAIN_HEADER_OFFSET - nd_logo.GetHeight()) / 2, true,
100 wxNullCursor));
102 // Create the Barry Logo popup system menu
103 m_sysmenu.reset( new wxMenu );
104 m_sysmenu->Append( new wxMenuItem(m_sysmenu.get(),
105 SysMenu_VerboseLogging, _T("&Verbose Logging"),
106 _T("Enable low level USB debug output"), wxITEM_CHECK, NULL) );
107 m_sysmenu->Append(SysMenu_RenameDevice, _T("Re&name Device..."));
108 m_sysmenu->Append(SysMenu_ResetDevice, _T("Re&set Device"));
109 m_sysmenu->Append(SysMenu_RescanUsb, _T("&Rescan USB"));
110 m_sysmenu->AppendSeparator();
111 m_sysmenu->Append(SysMenu_About, _T("&About..."));
112 m_sysmenu->AppendSeparator();
113 m_sysmenu->Append(wxID_EXIT, _T("E&xit"));
115 UpdateMenuState();
116 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
119 void BaseFrame::UpdateMenuState()
121 if( !m_sysmenu.get() )
122 return;
124 wxMenuItemList &list = m_sysmenu->GetMenuItems();
125 wxMenuItemList::iterator b = list.begin();
126 for( ; b != list.end(); ++b ) {
127 wxMenuItem *item = *b;
129 switch( item->GetId() )
131 case SysMenu_VerboseLogging:
132 item->Check(Barry::IsVerbose());
133 break;
138 void BaseFrame::CreateDeviceCombo(Barry::Pin pin)
140 const Barry::Probe::Results &results = wxGetApp().GetResults();
142 // default to:
143 // no device selected, if multiple available and no default given
144 // no devices available, if nothing there
145 // the first device, if only one exists
146 int selected = 0;
148 // create a list of selections
149 wxArrayString devices;
151 // if there's more than one device, let the user pick "none"
152 if( results.size() > 1 ) {
153 devices.Add(_T("No device selected"));
156 // add one entry for each device
157 for( Barry::Probe::Results::const_iterator i = results.begin();
158 i != results.end(); ++i ) {
159 std::ostringstream oss;
160 oss << i->m_pin.Str();
161 if( i->m_cfgDeviceName.size() ) {
162 oss << " (" << i->m_cfgDeviceName << ")";
165 // if this is the desired item, remember this selection
166 if( pin.Valid() && i->m_pin == pin ) {
167 selected = devices.GetCount();
170 devices.Add(wxString(oss.str().c_str(), wxConvUTF8));
173 // if nothing is there, be descriptive
174 if( devices.GetCount() == 0 ) {
175 devices.Add(_T("No devices available"));
178 // create the combobox
179 int x = m_width - 300;
180 int y = m_height - (MAIN_HEADER_OFFSET - 5);
181 m_device_combo.reset( new wxComboBox(this, Ctrl_DeviceCombo, _T(""),
182 wxPoint(x, y), wxSize(290, -1), devices, wxCB_READONLY) );
184 // select the desired entry
185 m_device_combo->SetValue(devices[selected]);
187 // update the screenshot
188 m_main_menu_mode->UpdateScreenshot(GetCurrentComboPin());
191 Barry::Pin BaseFrame::GetCurrentComboPin()
193 // fetch newly selected device
194 wxString value = m_device_combo->GetValue();
195 istringstream iss(string(value.utf8_str()).substr(0,8));
196 Barry::Pin pin;
197 iss >> pin;
198 return pin;
201 void BaseFrame::EnableBackButton(Mode *new_mode)
203 // create the button - this goes in the bottom FOOTER area
204 // so the height must be fixed to MAIN_HEADER_OFFSET
205 // minus a border of 5px top and bottom
206 wxPoint pos(10, m_height - (MAIN_HEADER_OFFSET - 5));
207 wxSize size(-1, MAIN_HEADER_OFFSET - 5 - 5);
209 m_back_button.reset( new wxButton(this, MainMenu_BackButton,
210 _T("Main Menu"), pos, size) );
212 // set the new mode
213 m_current_mode = new_mode;
215 // destroy the device switcher combo box
216 m_device_combo.reset();
218 // without the device combo, there is no concept of a
219 // "current device" so temporarily disable the USB options
220 m_sysmenu->Enable(SysMenu_RenameDevice, false);
221 m_sysmenu->Enable(SysMenu_ResetDevice, false);
222 m_sysmenu->Enable(SysMenu_RescanUsb, false);
224 // repaint!
225 Refresh(false);
228 void BaseFrame::DisableBackButton()
230 // destroy the back button
231 m_back_button.reset();
233 // delete all modes
234 m_sync_mode.reset();
235 m_browse_mode.reset();
237 // create the device switcher combo again
238 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
240 // enable the USB menu options
241 Barry::Pin pin = GetCurrentComboPin();
242 m_sysmenu->Enable(SysMenu_RenameDevice, pin.Valid());
243 m_sysmenu->Enable(SysMenu_ResetDevice, true);
244 m_sysmenu->Enable(SysMenu_RescanUsb, true);
246 // reset the current mode to main menu and repaint
247 m_current_mode = m_main_menu_mode.get();
248 Refresh(false);
251 void BaseFrame::OnSize(wxSizeEvent &event)
255 void BaseFrame::OnPaint(wxPaintEvent &event)
257 wxPaintDC dc(this);
258 dc.SetMapMode(wxMM_TEXT);
260 // paint the background image
261 dc.DrawBitmap(*m_background, 0, 0);
263 // paint the header: Barry logo
264 m_barry_logo->Draw(dc);
266 // paint the header: NetDirect logo
267 // m_netdirect_logo->Draw(dc);
269 // paint the header: text
270 auto_ptr<wxFont> font( wxFont::New(14,
271 wxFONTFAMILY_SWISS, wxFONTFLAG_ANTIALIASED,
272 _T("Luxi Sans")) );
273 dc.SetFont( *font );
274 dc.SetTextForeground( wxColour(0xd2, 0xaf, 0x0b) );
275 dc.SetTextBackground( wxColour(0, 0, 0, wxALPHA_TRANSPARENT) );
277 long width, height, descent;
278 wxString header = _T("Barry Desktop Control Panel");
279 if( m_current_mode )
280 header = m_current_mode->GetTitleText();
281 dc.GetTextExtent(header, &width, &height, &descent);
282 int x = (m_width - width) / 2;
283 int y = (MAIN_HEADER_OFFSET - height) / 2;
284 dc.DrawText(header, x, y);
286 // let the mode do its thing
287 if( m_current_mode )
288 m_current_mode->OnPaint(dc);
291 void BaseFrame::OnMouseMotion(wxMouseEvent &event)
293 wxClientDC dc(this);
294 m_barry_logo->HandleMotion(dc, event.m_x, event.m_y);
295 // m_netdirect_logo->HandleMotion(dc, event.m_x, event.m_y);
297 // the mode
298 if( m_current_mode )
299 m_current_mode->OnMouseMotion(dc, event.m_x, event.m_y);
302 void BaseFrame::OnLeftDown(wxMouseEvent &event)
304 wxClientDC dc(this);
305 m_barry_logo->HandleDown(dc, event.m_x, event.m_y);
306 // m_netdirect_logo->HandleDown(dc, event.m_x, event.m_y);
307 event.Skip();
309 // the mode
310 if( m_current_mode )
311 m_current_mode->OnLeftDown(dc, event.m_x, event.m_y);
314 void BaseFrame::OnLeftUp(wxMouseEvent &event)
316 wxClientDC dc(this);
317 m_barry_logo->HandleUp(dc, event.m_x, event.m_y);
318 // m_netdirect_logo->HandleUp(dc, event.m_x, event.m_y);
320 // the mode
321 if( m_current_mode )
322 m_current_mode->OnLeftUp(dc, event.m_x, event.m_y);
325 void BaseFrame::OnBackupRestore(wxCommandEvent &event)
327 if( m_backup_process.IsAppRunning() ) {
328 wxMessageBox(_T("The Backup program is already running!"),
329 _T("Backup and Restore"), wxOK | wxICON_INFORMATION);
330 return;
333 if( !m_backup_process.Run(this, "Backup and Restore", _T("barrybackup")) )
334 return;
337 void BaseFrame::OnSync(wxCommandEvent &event)
339 if( wxGetApp().GetOpenSync().GetAvailable() == 0 ) {
340 wxGetApp().ShowMissingOpenSyncMessage();
341 return;
344 try {
345 m_sync_mode.reset( new SyncMode(this) );
347 catch( std::exception &e ) {
348 wxString msg(_T(
349 "An error occurred that prevented the loading of Sync\n"
350 "mode. This is most likely because a critical piece\n"
351 "of OpenSync is missing. Check that all required\n"
352 "plugins are installed, and that tools like 'bidentify'\n"
353 "can find your BlackBerry(R) successfully.\n\n"
354 "Error: "));
355 msg += wxString(e.what(), wxConvUTF8);
356 wxMessageBox(msg, _T("Sync Mode"), wxOK | wxICON_ERROR);
357 return;
360 EnableBackButton(m_sync_mode.get());
363 //#include "EvoSources.h"
364 //#include "EvoCfgDlg.h"
365 //#include "EvoDefaultDlg.h"
366 //void DumpItems(const EvoSources::List &list)
368 // EvoSources::List::const_iterator i;
369 // for( i = list.begin(); i != list.end(); ++i ) {
370 // cout << i->m_GroupName << ", "
371 // << i->m_SourceName << ", "
372 // << i->m_SourcePath << endl;
373 // }
375 //#include "ConflictDlg.h"
376 void BaseFrame::OnModem(wxCommandEvent &event)
379 EvoDefaultDlg dlg(this);
380 dlg.ShowModal();
384 EvoSources es;
385 cout << "Addressbook:\n";
386 DumpItems(es.GetAddressBook());
387 cout << "Events:\n";
388 DumpItems(es.GetEvents());
389 cout << "Tasks:\n";
390 DumpItems(es.GetTasks());
391 cout << "Memos:\n";
392 DumpItems(es.GetMemos());
394 OpenSync::Config::Evolution ecfg;
396 EvoCfgDlg dlg(this, ecfg, es);
397 dlg.ShowModal();
398 dlg.SetPaths(ecfg);
399 cout << "Resulting paths:\n"
400 << ecfg.GetAddressPath() << endl
401 << ecfg.GetCalendarPath() << endl
402 << ecfg.GetTasksPath() << endl
403 << ecfg.GetMemosPath() << endl;
407 OpenSync::SyncChange change;
408 change.id = 1;
409 change.member_id = 1;
410 change.plugin_name = "barry-sync";
411 change.uid = "12341524235234";
412 change.printable_data =
413 "<contact>\n"
414 " <UnknownNode>\n"
415 " <NodeName>PRODID</NodeName>\n"
416 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
417 " </UnknownNode>\n"
418 " <FormattedName>\n"
419 " <Content>Adame Brandee</Content>\n"
420 " </FormattedName>\n"
421 " <Name>\n"
422 " <LastName>Brandee</LastName>\n"
423 " <FirstName>Adame</FirstName>\n"
424 " </Name>\n"
425 " <AddressLabel>\n"
426 " <Content>71 Long St.\n"
427 "Toronto ON Canada\n"
428 "N0N 0N0</Content>\n"
429 " <Type>home</Type>\n"
430 " </AddressLabel>\n"
431 " <Address>\n"
432 " <Street>71 Long St.</Street>\n"
433 " <City>Toronto</City>\n"
434 " <Region>ON</Region>\n"
435 " <PostalCode>N0N 0N0</PostalCode>\n"
436 " <Country>Canada</Country>\n"
437 " <Type>home</Type>\n"
438 " </Address>\n"
439 " <Telephone>\n"
440 " <Content>+1 (416) 555-7711</Content>\n"
441 " <Type>voice</Type>\n"
442 " <Type>home</Type>\n"
443 " </Telephone>\n"
444 " <Telephone>\n"
445 " <Content>+1 (416) 955-7117</Content>\n"
446 " <Type>msg</Type>\n"
447 " <Type>cell</Type>\n"
448 " </Telephone>\n"
449 " <EMail>\n"
450 " <Content>abrandee@sympatico.ca</Content>\n"
451 " <Type>internet</Type>\n"
452 " <Type>pref</Type>\n"
453 " </EMail>\n"
454 " <Categories>\n"
455 " <Category>Personal</Category>\n"
456 " </Categories>\n"
457 " <Note>\n"
458 " <Content>Interweb salesman... 24/7</Content>\n"
459 " </Note>\n"
460 "</contact>";
462 std::vector<OpenSync::SyncChange> changes;
463 changes.push_back(change);
465 change.id = 2;
466 change.member_id = 2;
467 change.plugin_name = "evo2-sync";
468 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
469 change.printable_data =
470 "<contact>\n"
471 " <Telephone>\n"
472 " <Content>+1 (416) 955-7117</Content>\n"
473 " <Type>CELL</Type>\n"
474 " <Slot>2</Slot>\n"
475 " </Telephone>\n"
476 " <Telephone>\n"
477 " <Content>+1 (416) 555-7711</Content>\n"
478 " <Type>HOME</Type>\n"
479 " <Type>VOICE</Type>\n"
480 " <Slot>1</Slot>\n"
481 " </Telephone>\n"
482 " <EMail>\n"
483 " <Content>abrandee@sympatico.ca</Content>\n"
484 " <Type>OTHER</Type>\n"
485 " <Slot>1</Slot>\n"
486 " </EMail>\n"
487 " <WantsHtml>\n"
488 " <Content>FALSE</Content>\n"
489 " </WantsHtml>\n"
490 " <Revision>\n"
491 " <Content>20100322T225303Z</Content>\n"
492 " </Revision>\n"
493 " <UnknownNode>\n"
494 " <NodeName>PRODID</NodeName>\n"
495 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
496 " </UnknownNode>\n"
497 " <FormattedName>\n"
498 " <Content>Adam Brandeee</Content>\n"
499 " </FormattedName>\n"
500 " <Name>\n"
501 " <LastName>Brandeee</LastName>\n"
502 " <FirstName>Adam</FirstName>\n"
503 " </Name>\n"
504 " <AddressLabel>\n"
505 " <Content>71 Long St.\n"
506 "Toronto, ON\n"
507 "N0N 0N1\n"
508 "Canada</Content>\n"
509 " <Type>home</Type>\n"
510 " </AddressLabel>\n"
511 " <Address>\n"
512 " <Street>71 Long St.</Street>\n"
513 " <City>Toronto</City>\n"
514 " <Region>ON</Region>\n"
515 " <PostalCode>N0N 0N1</PostalCode>\n"
516 " <Country>Canada</Country>\n"
517 " <Type>home</Type>\n"
518 " </Address>\n"
519 " <Categories>\n"
520 " <Category>Personal</Category>\n"
521 " </Categories>\n"
522 " <FileAs>\n"
523 " <Content>Brandeee, Adam</Content>\n"
524 " </FileAs>\n"
525 "</contact>";
527 changes.push_back(change);
530 ConflictDlg::AlwaysMemoryBlock always;
531 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
532 "SDAIN", changes, always);
533 dlg.ShowModal();
534 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
535 msg += _T(" ");
536 msg += always.m_always ? _T("always") : _T("not always");
537 wxMessageBox(msg);
542 void BaseFrame::OnAppLoader(wxCommandEvent &event)
545 OpenSync::SyncChange change;
546 change.id = 1;
547 change.member_id = 1;
548 change.plugin_name = "barry-sync";
549 change.uid = "12341524235234";
550 change.printable_data =
551 "<vcal>\n"
552 " <Event>\n"
553 " <Sequence>\n"
554 " <Content>0</Content>\n"
555 " </Sequence>\n"
556 " <Summary>\n"
557 " <Content>Subject</Content>\n"
558 " </Summary>\n"
559 " <Description>\n"
560 " <Content>Bring burnt offering</Content>\n"
561 " </Description>\n"
562 " <Location>\n"
563 " <Content>Tent</Content>\n"
564 " </Location>\n"
565 " <DateStarted>\n"
566 " <Content>20100506T040000Z</Content>\n"
567 " </DateStarted>\n"
568 " <DateEnd>\n"
569 " <Content>20100507T040000Z</Content>\n"
570 " </DateEnd>\n"
571 " <Alarm>\n"
572 " <AlarmAction>AUDIO</AlarmAction>\n"
573 " <AlarmTrigger>\n"
574 " <Content>20100506T034500Z</Content>\n"
575 " <Value>DATE-TIME</Value>\n"
576 " </AlarmTrigger>\n"
577 " </Alarm>\n"
578 " </Event>\n"
579 "</vcal>\n";
581 std::vector<OpenSync::SyncChange> changes;
582 changes.push_back(change);
584 change.id = 2;
585 change.member_id = 2;
586 change.plugin_name = "evo2-sync";
587 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
588 change.printable_data =
589 "<vcal>\n"
590 " <Method>\n"
591 " <Content>PUBLISH</Content>\n"
592 " </Method>\n"
593 " <Timezone>\n"
594 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
595 " <Location>America/Thunder_Bay</Location>\n"
596 " <Standard>\n"
597 " <TimezoneName>EST</TimezoneName>\n"
598 " <DateStarted>19701107T010000</DateStarted>\n"
599 " <RecurrenceRule>\n"
600 " <Rule>FREQ=YEARLY</Rule>\n"
601 " <Rule>INTERVAL=1</Rule>\n"
602 " <Rule>BYDAY=2SU</Rule>\n"
603 " <Rule>BYMONTH=11</Rule>\n"
604 " </RecurrenceRule>\n"
605 " <TZOffsetFrom>-0400</TZOffsetFrom>\n"
606 " <TZOffsetTo>-0500</TZOffsetTo>\n"
607 " </Standard>\n"
608 " <DaylightSavings>\n"
609 " <TimezoneName>EDT</TimezoneName>\n"
610 " <DateStarted>19700313T030000</DateStarted>\n"
611 " <RecurrenceRule>\n"
612 " <Rule>FREQ=YEARLY</Rule>\n"
613 " <Rule>INTERVAL=1</Rule>\n"
614 " <Rule>BYDAY=2SU</Rule>\n"
615 " <Rule>BYMONTH=3</Rule>\n"
616 " </RecurrenceRule>\n"
617 " <TZOffsetFrom>-0500</TZOffsetFrom>\n"
618 " <TZOffsetTo>-0400</TZOffsetTo>\n"
619 " </DaylightSavings>\n"
620 " </Timezone>\n"
621 " <Event>\n"
622 " <Sequence>\n"
623 " <Content>1</Content>\n"
624 " </Sequence>\n"
625 " <Summary>\n"
626 " <Content>Celebration day</Content>\n"
627 " </Summary>\n"
628 " <Location>\n"
629 " <Content>Tent of</Content>\n"
630 " </Location>\n"
631 " <DateStarted>\n"
632 " <Content>20100506T000000</Content>\n"
633 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
634 " </DateStarted>\n"
635 " <DateEnd>\n"
636 " <Content>20100507T000000</Content>\n"
637 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
638 " </DateEnd>\n"
639 " <DateCalendarCreated>\n"
640 " <Content>20100430T214736Z</Content>\n"
641 " </DateCalendarCreated>\n"
642 " <DateCreated>\n"
643 " <Content>20100430T214736</Content>\n"
644 " </DateCreated>\n"
645 " <LastModified>\n"
646 " <Content>20100430T214927</Content>\n"
647 " </LastModified>\n"
648 " <Description>\n"
649 " <Content>Bring burnt offering</Content>\n"
650 " </Description>\n"
651 " <Class>\n"
652 " <Content>PUBLIC</Content>\n"
653 " </Class>\n"
654 " <Transparency>\n"
655 " <Content>OPAQUE</Content>\n"
656 " </Transparency>\n"
657 " <Alarm>\n"
658 " <AlarmAction>AUDIO</AlarmAction>\n"
659 " <AlarmTrigger>\n"
660 " <Content>20100506T034500Z</Content>\n"
661 " <Value>DATE-TIME</Value>\n"
662 " </AlarmTrigger>\n"
663 " </Alarm>\n"
664 " </Event>\n"
665 "</vcal>\n";
668 changes.push_back(change);
671 ConflictDlg::AlwaysMemoryBlock always;
672 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
673 "SDAIN", changes, always);
674 dlg.ShowModal();
675 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
676 msg += _T(" ");
677 msg += always.m_always ? _T("always") : _T("not always");
678 wxMessageBox(msg);
683 void BaseFrame::OnDeviceSwitch(wxCommandEvent &event)
687 void BaseFrame::OnBrowseDatabases(wxCommandEvent &event)
689 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
690 if( i == -1 ) {
691 wxMessageBox(_T("There is no device selected in the device list. Please select a device to browse."),
692 _T("Database Browser Mode"), wxOK | wxICON_ERROR);
693 return;
696 try {
697 m_browse_mode.reset( new BrowseMode(this,
698 wxGetApp().GetResults()[i]) );
700 catch( std::exception &e ) {
701 wxString msg(_T(
702 "An error occurred that prevented the loading of Database\n"
703 "Browse mode. This could be due to a low level USB\n"
704 "issue. Please make sure your device is plugged in\n"
705 "and not in Desktop Mode. If it is, try replugging\n"
706 "the device, and rescanning the USB bus from the menu.\n"
707 "\n"
708 "Error: "));
709 msg += wxString(e.what(), wxConvUTF8);
710 wxMessageBox(msg, _T("Database Browser Mode"), wxOK | wxICON_ERROR);
711 return;
714 EnableBackButton(m_browse_mode.get());
717 void BaseFrame::OnMediaManagement(wxCommandEvent &event)
721 void BaseFrame::OnMisc(wxCommandEvent &event)
725 void BaseFrame::OnBackButton(wxCommandEvent &event)
727 DisableBackButton();
730 void BaseFrame::OnTermBackupAndRestore(wxProcessEvent &event)
732 barryverbose("OnTermBackupAndRestore(): done = "
733 << (!m_backup_process.IsAppRunning() ? "true" : "false")
734 << ", status = " << m_backup_process.GetAppStatus());
735 if( !m_backup_process.IsAppRunning() &&
736 m_backup_process.GetAppStatus() )
738 wxMessageBox(_T("Unable to run barrybackup, or it returned an error. Please make sure it is installed and in your PATH."),
739 _T("Backup and Restore"), wxOK | wxICON_ERROR);
743 void BaseFrame::OnBarryLogoClicked(wxCommandEvent &event)
745 PopupMenu(m_sysmenu.get(), 20, 20);
748 void BaseFrame::OnNetDirectLogoClicked(wxCommandEvent &event)
750 // fire up a browser to point to the Barry documentation
751 wxBusyCursor wait;
752 ::wxLaunchDefaultBrowser(_T("http://netdirect.ca/barry"));
755 void BaseFrame::OnDeviceComboChange(wxCommandEvent &event)
757 Barry::Pin pin = GetCurrentComboPin();
759 // any change?
760 if( pin == wxGetApp().GetGlobalConfig().GetLastDevice() )
761 return; // nope
763 // save
764 wxGetApp().GetGlobalConfig().SetLastDevice(pin);
766 // update sys menu
767 m_sysmenu->Enable(SysMenu_RenameDevice, false);
769 // update the main mode's screenshot
770 m_main_menu_mode->UpdateScreenshot(pin);
771 if( m_current_mode == m_main_menu_mode.get() )
772 Refresh(false);
774 // FIXME - if inside a sub menu mode, we need to destroy the mode
775 // class and start fresh
778 void BaseFrame::OnVerboseLogging(wxCommandEvent &event)
780 Barry::Verbose( !Barry::IsVerbose() );
781 wxGetApp().GetGlobalConfig().SetVerboseLogging( Barry::IsVerbose() );
782 UpdateMenuState();
785 void BaseFrame::OnRenameDevice(wxCommandEvent &event)
787 Barry::Pin pin = GetCurrentComboPin();
788 if( !pin.Valid() )
789 return;
791 // grab the current known name of the device
792 const Barry::Probe::Results &results = wxGetApp().GetResults();
793 int index = Barry::Probe::Find(results, pin);
794 if( index == -1 )
795 return;
797 wxString current_name(results[index].m_cfgDeviceName.c_str(), wxConvUTF8);
798 wxTextEntryDialog dlg(this,
799 _T("Please enter a name for the current device:"),
800 _T("Rename Device"),
801 current_name, wxTextEntryDialogStyle);
803 if( dlg.ShowModal() != wxID_OK )
804 return; // nothing to do
805 wxString name = dlg.GetValue();
806 if( name == current_name )
807 return; // nothing to do
809 wxGetApp().SetDeviceName(pin, string(name.utf8_str()));
811 // refill combo box
812 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
815 void BaseFrame::OnResetDevice(wxCommandEvent &event)
817 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
818 if( i != -1 ) {
819 Usb::Device dev(wxGetApp().GetResults()[i].m_dev);
820 dev.Reset();
821 wxBusyCursor wait;
822 wxSleep(4);
823 OnRescanUsb(event);
827 void BaseFrame::OnRescanUsb(wxCommandEvent &event)
829 if( m_current_mode == m_main_menu_mode.get() ) {
830 std::auto_ptr<UsbScanSplash> splash( new UsbScanSplash );
831 wxGetApp().Probe();
832 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
834 else {
835 // FIXME - tell the user we didn't do anything?
836 // or perhaps just disable rescan while in a mode
840 void BaseFrame::OnAbout(wxCommandEvent &event)
842 wxAboutDialogInfo info;
843 info.SetName(_T("Barry Desktop Control Panel"));
844 info.SetVersion(_T("0.18.0"));
845 info.SetDescription(_T("A Free Software graphical user interface for working with the BlackBerry® smartphone."));
846 info.SetCopyright(_T("Copyright © 2009-2012, Net Direct Inc."));
847 info.SetWebSite(_T("http://netdirect.ca/barry"));
848 info.SetLicense(_T(
849 " This program is free software; you can redistribute it and/or modify\n"
850 " it under the terms of the GNU General Public License as published by\n"
851 " the Free Software Foundation; either version 2 of the License, or\n"
852 " (at your option) any later version.\n"
853 "\n"
854 " This program is distributed in the hope that it will be useful,\n"
855 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
856 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
857 "\n"
858 " See the GNU General Public License in the COPYING file at the\n"
859 " root directory of this project for more details.\n"));
861 info.AddDeveloper(_T("Net Direct Inc."));
862 // info.AddDeveloper(_T("Chris Frey <cdfrey@foursquare.net>"));
863 // info.AddDeveloper(_T("See AUTHORS file for detailed"));
864 // info.AddDeveloper(_T("contribution information."));
866 info.AddArtist(_T("Chris Frey - GUI interface"));
867 info.AddArtist(_T("Martin Owens - Barry logo"));
868 info.AddArtist(_T("Tango Desktop Project - Public domain icons"));
870 wxAboutBox(info);
873 void BaseFrame::OnExit(wxCommandEvent &event)
875 Close(true);