Bumped copyright dates for 2013
[barry.git] / desktop / src / BaseFrame.cc
blob69dc85d3e8d49a2253f0cc95c0f2cc46a414424e
1 ///
2 /// \file BaseFrame.cc
3 /// Class for the fixed-size frame that holds the main app
4 ///
6 /*
7 Copyright (C) 2009-2013, 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 "MigrateDlg.h"
27 #include "ModemDlg.h"
28 #include "ClickImage.h"
29 #include "barrydesktop.h"
30 #include "windowids.h"
31 #include "config.h"
32 #include <wx/aboutdlg.h>
33 #include <iostream>
34 #include <sstream>
36 // include icons and logos
37 #include "../images/barry_logo_icon.xpm"
38 #include "../images/logo_NetDirect.xpm"
40 using namespace std;
42 BEGIN_EVENT_TABLE(BaseFrame, wxFrame)
43 EVT_SIZE (BaseFrame::OnSize)
44 EVT_PAINT (BaseFrame::OnPaint)
45 EVT_MOTION (BaseFrame::OnMouseMotion)
46 EVT_LEFT_DOWN (BaseFrame::OnLeftDown)
47 EVT_LEFT_UP (BaseFrame::OnLeftUp)
48 EVT_BUTTON (MainMenu_BackupAndRestore, BaseFrame::OnBackupRestore)
49 EVT_BUTTON (MainMenu_Sync, BaseFrame::OnSync)
50 EVT_BUTTON (MainMenu_Modem, BaseFrame::OnModem)
51 EVT_BUTTON (MainMenu_AppLoader, BaseFrame::OnAppLoader)
52 EVT_BUTTON (MainMenu_MigrateDevice, BaseFrame::OnMigrateDevice)
53 EVT_BUTTON (MainMenu_BrowseDatabases, BaseFrame::OnBrowseDatabases)
54 EVT_BUTTON (MainMenu_MediaManagement, BaseFrame::OnMediaManagement)
55 EVT_BUTTON (MainMenu_Misc, BaseFrame::OnMisc)
56 EVT_BUTTON (MainMenu_BackButton, BaseFrame::OnBackButton)
57 EVT_BUTTON (HotImage_BarryLogo, BaseFrame::OnBarryLogoClicked)
58 EVT_BUTTON (HotImage_NetDirectLogo, BaseFrame::OnNetDirectLogoClicked)
59 EVT_TEXT (Ctrl_DeviceCombo, BaseFrame::OnDeviceComboChange)
60 EVT_MENU (SysMenu_VerboseLogging, BaseFrame::OnVerboseLogging)
61 EVT_MENU (SysMenu_RenameDevice, BaseFrame::OnRenameDevice)
62 EVT_MENU (SysMenu_ResetDevice, BaseFrame::OnResetDevice)
63 EVT_MENU (SysMenu_RescanUsb, BaseFrame::OnRescanUsb)
64 EVT_MENU (SysMenu_About, BaseFrame::OnAbout)
65 EVT_MENU (SysMenu_Exit, BaseFrame::OnExit)
66 EVT_END_PROCESS (Process_BackupAndRestore, BaseFrame::OnTermBackupAndRestore)
67 END_EVENT_TABLE()
69 //////////////////////////////////////////////////////////////////////////////
70 // BaseFrame
72 BaseFrame::BaseFrame(const wxImage &background)
73 : wxFrame(NULL, wxID_ANY, _W("Barry Desktop Control Panel"),
74 wxPoint(50, 50),
75 wxSize(background.GetWidth(), background.GetHeight()),
76 wxMINIMIZE_BOX | wxCAPTION | wxCLOSE_BOX | wxSYSTEM_MENU |
77 wxCLIP_CHILDREN)
78 , TermCatcher(this, Process_BackupAndRestore)
79 , m_width(background.GetWidth())
80 , m_height(background.GetHeight())
81 , m_current_mode(0)
82 , m_backup_process(this)
83 , m_rescan_pending(false)
85 // This is a workaround for different size behaviour
86 // in the GTK version of wxWidgets 2.9
87 SetClientSize(wxSize(background.GetWidth(), background.GetHeight()));
89 // load base bitmaps
90 m_background.reset( new wxBitmap(background) );
92 // the main menu mode always exists, but may not always be current
93 m_main_menu_mode.reset( new MainMenuMode(this) );
94 m_current_mode = m_main_menu_mode.get();
96 m_barry_logo.reset( new ClickableImage(this,
97 wxBitmap(barry_logo_icon_xpm), HotImage_BarryLogo,
98 4, 4, false) );
99 wxBitmap nd_logo(logo_NetDirect_xpm);
100 m_netdirect_logo.reset( new ClickableImage(this,
101 nd_logo, HotImage_NetDirectLogo,
102 m_width - 3 - nd_logo.GetWidth(),
103 (MAIN_HEADER_OFFSET - nd_logo.GetHeight()) / 2, true,
104 wxNullCursor));
106 // Create the Barry Logo popup system menu
107 m_sysmenu.reset( new wxMenu );
108 m_sysmenu->Append( new wxMenuItem(m_sysmenu.get(),
109 SysMenu_VerboseLogging, _W("&Verbose Logging"),
110 _W("Enable low level USB debug output"), wxITEM_CHECK, NULL) );
111 m_sysmenu->Append(SysMenu_RenameDevice, _W("Re&name Device..."));
112 m_sysmenu->Append(SysMenu_ResetDevice, _W("Re&set Device"));
113 m_sysmenu->Append(SysMenu_RescanUsb, _W("&Rescan USB"));
114 m_sysmenu->AppendSeparator();
115 m_sysmenu->Append(SysMenu_About, _W("&About..."));
116 m_sysmenu->AppendSeparator();
117 m_sysmenu->Append(wxID_EXIT, _W("E&xit"));
119 UpdateMenuState();
120 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
123 void BaseFrame::UpdateMenuState()
125 if( !m_sysmenu.get() )
126 return;
128 wxMenuItemList &list = m_sysmenu->GetMenuItems();
129 wxMenuItemList::iterator b = list.begin();
130 for( ; b != list.end(); ++b ) {
131 wxMenuItem *item = *b;
133 switch( item->GetId() )
135 case SysMenu_VerboseLogging:
136 item->Check(Barry::IsVerbose());
137 break;
142 void BaseFrame::CreateDeviceCombo(Barry::Pin pin)
144 const Barry::Probe::Results &results = wxGetApp().GetResults();
146 // default to:
147 // no device selected, if multiple available and no default given
148 // no devices available, if nothing there
149 // the first device, if only one exists
150 int selected = 0;
152 // create a list of selections
153 wxArrayString devices;
155 // if there's more than one device, let the user pick "none"
156 if( results.size() > 1 ) {
157 devices.Add(_W("No device selected"));
160 // add one entry for each device
161 for( Barry::Probe::Results::const_iterator i = results.begin();
162 i != results.end(); ++i )
164 // if this is the desired item, remember this selection
165 if( pin.Valid() && i->m_pin == pin ) {
166 selected = devices.GetCount();
169 devices.Add(wxString(i->GetDisplayName().c_str(), wxConvUTF8));
172 // if nothing is there, be descriptive
173 if( devices.GetCount() == 0 ) {
174 devices.Add(_W("No devices available"));
177 // create the combobox
178 int x = m_width - 300;
179 int y = m_height - (MAIN_HEADER_OFFSET - 5);
180 m_device_combo.reset( new wxComboBox(this, Ctrl_DeviceCombo, _T(""),
181 wxPoint(x, y), wxSize(290, -1), devices, wxCB_READONLY) );
183 // select the desired entry
184 m_device_combo->SetValue(devices[selected]);
186 // update the screenshot
187 m_main_menu_mode->UpdateScreenshot(GetCurrentComboPin());
190 Barry::Pin BaseFrame::GetCurrentComboPin()
192 // fetch newly selected device
193 wxString value = m_device_combo->GetValue();
194 istringstream iss(string(value.utf8_str()).substr(0,8));
195 Barry::Pin pin;
196 iss >> pin;
197 return pin;
200 void BaseFrame::EnableBackButton(Mode *new_mode)
202 // create the button - this goes in the bottom FOOTER area
203 // so the height must be fixed to MAIN_HEADER_OFFSET
204 // minus a border of 5px top and bottom
205 wxPoint pos(10, m_height - (MAIN_HEADER_OFFSET - 5));
206 wxSize size(-1, MAIN_HEADER_OFFSET - 5 - 5);
208 m_back_button.reset( new wxButton(this, MainMenu_BackButton,
209 _W("Main Menu"), pos, size) );
211 // set the new mode
212 m_current_mode = new_mode;
214 // destroy the device switcher combo box
215 m_device_combo.reset();
217 // without the device combo, there is no concept of a
218 // "current device" so temporarily disable the USB options
219 m_sysmenu->Enable(SysMenu_RenameDevice, false);
220 m_sysmenu->Enable(SysMenu_ResetDevice, false);
221 m_sysmenu->Enable(SysMenu_RescanUsb, false);
223 // repaint!
224 Refresh(false);
227 void BaseFrame::DisableBackButton()
229 // destroy the back button
230 m_back_button.reset();
232 // delete all modes
233 m_sync_mode.reset();
234 m_browse_mode.reset();
236 // create the device switcher combo again
237 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
239 // enable the USB menu options
240 Barry::Pin pin = GetCurrentComboPin();
241 m_sysmenu->Enable(SysMenu_RenameDevice, pin.Valid());
242 m_sysmenu->Enable(SysMenu_ResetDevice, true);
243 m_sysmenu->Enable(SysMenu_RescanUsb, true);
245 // reset the current mode to main menu and repaint
246 m_current_mode = m_main_menu_mode.get();
247 Refresh(false);
249 // if a USB rescan is pending, do it now
250 if( m_rescan_pending ) {
251 wxCommandEvent event;
252 OnRescanUsb(event);
256 void BaseFrame::OnSize(wxSizeEvent &event)
260 void BaseFrame::OnPaint(wxPaintEvent &event)
262 wxPaintDC dc(this);
263 dc.SetMapMode(wxMM_TEXT);
265 // paint the background image
266 dc.DrawBitmap(*m_background, 0, 0);
268 // paint the header: Barry logo
269 m_barry_logo->Draw(dc);
271 // paint the header: NetDirect logo
272 // m_netdirect_logo->Draw(dc);
274 // paint the header: text
275 auto_ptr<wxFont> font( wxFont::New(14,
276 wxFONTFAMILY_SWISS, wxFONTFLAG_ANTIALIASED,
277 _T("Luxi Sans")) );
278 dc.SetFont( *font );
279 dc.SetTextForeground( wxColour(0xd2, 0xaf, 0x0b) );
280 dc.SetTextBackground( wxColour(0, 0, 0, wxALPHA_TRANSPARENT) );
282 long width, height, descent;
283 wxString header = _W("Barry Desktop Control Panel");
284 if( m_current_mode )
285 header = m_current_mode->GetTitleText();
286 dc.GetTextExtent(header, &width, &height, &descent);
287 int x = (m_width - width) / 2;
288 int y = (MAIN_HEADER_OFFSET - height) / 2;
289 dc.DrawText(header, x, y);
291 // let the mode do its thing
292 if( m_current_mode )
293 m_current_mode->OnPaint(dc);
296 void BaseFrame::OnMouseMotion(wxMouseEvent &event)
298 wxClientDC dc(this);
299 m_barry_logo->HandleMotion(dc, event.m_x, event.m_y);
300 // m_netdirect_logo->HandleMotion(dc, event.m_x, event.m_y);
302 // the mode
303 if( m_current_mode )
304 m_current_mode->OnMouseMotion(dc, event.m_x, event.m_y);
307 void BaseFrame::OnLeftDown(wxMouseEvent &event)
309 wxClientDC dc(this);
310 m_barry_logo->HandleDown(dc, event.m_x, event.m_y);
311 // m_netdirect_logo->HandleDown(dc, event.m_x, event.m_y);
312 event.Skip();
314 // the mode
315 if( m_current_mode )
316 m_current_mode->OnLeftDown(dc, event.m_x, event.m_y);
319 void BaseFrame::OnLeftUp(wxMouseEvent &event)
321 wxClientDC dc(this);
322 m_barry_logo->HandleUp(dc, event.m_x, event.m_y);
323 // m_netdirect_logo->HandleUp(dc, event.m_x, event.m_y);
325 // the mode
326 if( m_current_mode )
327 m_current_mode->OnLeftUp(dc, event.m_x, event.m_y);
330 void BaseFrame::OnBackupRestore(wxCommandEvent &event)
332 if( m_backup_process.IsAppRunning() ) {
333 wxMessageBox(_W("The Backup program is already running!"),
334 _W("Backup and Restore"), wxOK | wxICON_INFORMATION,
335 this);
336 return;
339 if( !m_backup_process.Run(this, _C("Backup and Restore"), _T("barrybackup")) )
340 return;
343 void BaseFrame::OnSync(wxCommandEvent &event)
345 if( wxGetApp().GetOpenSync().GetAvailable() == 0 ) {
346 wxGetApp().ShowMissingOpenSyncMessage();
347 return;
350 try {
351 m_sync_mode.reset( new SyncMode(this) );
353 catch( std::exception &e ) {
354 wxString msg(_W(
355 "An error occurred that prevented the loading of Sync\n"
356 "mode. This is most likely because a critical piece\n"
357 "of OpenSync is missing. Check that all required\n"
358 "plugins are installed, and that tools like 'bidentify'\n"
359 "can find your BlackBerry(R) successfully.\n\n"
360 "Error: "));
361 msg += wxString(e.what(), wxConvUTF8);
362 wxMessageBox(msg, _W("Sync Mode"), wxOK | wxICON_ERROR, this);
363 return;
366 EnableBackButton(m_sync_mode.get());
369 void BaseFrame::OnModem(wxCommandEvent &event)
371 Barry::Pin pin = GetCurrentComboPin();
372 if( pin.Valid() ) {
373 ModemDlg::DoModem(this, pin);
375 else {
376 wxMessageBox(_W("Please select a device first."),
377 _W("No Device"), wxOK | wxICON_ERROR, this);
381 OpenSync::SyncChange change;
382 change.id = 1;
383 change.member_id = 1;
384 change.plugin_name = "barry-sync";
385 change.uid = "12341524235234";
386 change.printable_data =
387 "<contact>\n"
388 " <UnknownNode>\n"
389 " <NodeName>PRODID</NodeName>\n"
390 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
391 " </UnknownNode>\n"
392 " <FormattedName>\n"
393 " <Content>Adame Brandee</Content>\n"
394 " </FormattedName>\n"
395 " <Name>\n"
396 " <LastName>Brandee</LastName>\n"
397 " <FirstName>Adame</FirstName>\n"
398 " </Name>\n"
399 " <AddressLabel>\n"
400 " <Content>71 Long St.\n"
401 "Toronto ON Canada\n"
402 "N0N 0N0</Content>\n"
403 " <Type>home</Type>\n"
404 " </AddressLabel>\n"
405 " <Address>\n"
406 " <Street>71 Long St.</Street>\n"
407 " <City>Toronto</City>\n"
408 " <Region>ON</Region>\n"
409 " <PostalCode>N0N 0N0</PostalCode>\n"
410 " <Country>Canada</Country>\n"
411 " <Type>home</Type>\n"
412 " </Address>\n"
413 " <Telephone>\n"
414 " <Content>+1 (416) 555-7711</Content>\n"
415 " <Type>voice</Type>\n"
416 " <Type>home</Type>\n"
417 " </Telephone>\n"
418 " <Telephone>\n"
419 " <Content>+1 (416) 955-7117</Content>\n"
420 " <Type>msg</Type>\n"
421 " <Type>cell</Type>\n"
422 " </Telephone>\n"
423 " <EMail>\n"
424 " <Content>abrandee@sympatico.ca</Content>\n"
425 " <Type>internet</Type>\n"
426 " <Type>pref</Type>\n"
427 " </EMail>\n"
428 " <Categories>\n"
429 " <Category>Personal</Category>\n"
430 " </Categories>\n"
431 " <Note>\n"
432 " <Content>Interweb salesman... 24/7</Content>\n"
433 " </Note>\n"
434 "</contact>";
436 std::vector<OpenSync::SyncChange> changes;
437 changes.push_back(change);
439 change.id = 2;
440 change.member_id = 2;
441 change.plugin_name = "evo2-sync";
442 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
443 change.printable_data =
444 "<contact>\n"
445 " <Telephone>\n"
446 " <Content>+1 (416) 955-7117</Content>\n"
447 " <Type>CELL</Type>\n"
448 " <Slot>2</Slot>\n"
449 " </Telephone>\n"
450 " <Telephone>\n"
451 " <Content>+1 (416) 555-7711</Content>\n"
452 " <Type>HOME</Type>\n"
453 " <Type>VOICE</Type>\n"
454 " <Slot>1</Slot>\n"
455 " </Telephone>\n"
456 " <EMail>\n"
457 " <Content>abrandee@sympatico.ca</Content>\n"
458 " <Type>OTHER</Type>\n"
459 " <Slot>1</Slot>\n"
460 " </EMail>\n"
461 " <WantsHtml>\n"
462 " <Content>FALSE</Content>\n"
463 " </WantsHtml>\n"
464 " <Revision>\n"
465 " <Content>20100322T225303Z</Content>\n"
466 " </Revision>\n"
467 " <UnknownNode>\n"
468 " <NodeName>PRODID</NodeName>\n"
469 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
470 " </UnknownNode>\n"
471 " <FormattedName>\n"
472 " <Content>Adam Brandeee</Content>\n"
473 " </FormattedName>\n"
474 " <Name>\n"
475 " <LastName>Brandeee</LastName>\n"
476 " <FirstName>Adam</FirstName>\n"
477 " </Name>\n"
478 " <AddressLabel>\n"
479 " <Content>71 Long St.\n"
480 "Toronto, ON\n"
481 "N0N 0N1\n"
482 "Canada</Content>\n"
483 " <Type>home</Type>\n"
484 " </AddressLabel>\n"
485 " <Address>\n"
486 " <Street>71 Long St.</Street>\n"
487 " <City>Toronto</City>\n"
488 " <Region>ON</Region>\n"
489 " <PostalCode>N0N 0N1</PostalCode>\n"
490 " <Country>Canada</Country>\n"
491 " <Type>home</Type>\n"
492 " </Address>\n"
493 " <Categories>\n"
494 " <Category>Personal</Category>\n"
495 " </Categories>\n"
496 " <FileAs>\n"
497 " <Content>Brandeee, Adam</Content>\n"
498 " </FileAs>\n"
499 "</contact>";
501 changes.push_back(change);
504 ConflictDlg::AlwaysMemoryBlock always;
505 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
506 "SDAIN", changes, always);
507 dlg.ShowModal();
508 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
509 msg += _T(" ");
510 msg += always.m_always ? _T("always") : _T("not always");
511 wxMessageBox(msg);
516 void BaseFrame::OnAppLoader(wxCommandEvent &event)
519 OpenSync::SyncChange change;
520 change.id = 1;
521 change.member_id = 1;
522 change.plugin_name = "barry-sync";
523 change.uid = "12341524235234";
524 change.printable_data =
525 "<vcal>\n"
526 " <Event>\n"
527 " <Sequence>\n"
528 " <Content>0</Content>\n"
529 " </Sequence>\n"
530 " <Summary>\n"
531 " <Content>Subject</Content>\n"
532 " </Summary>\n"
533 " <Description>\n"
534 " <Content>Bring burnt offering</Content>\n"
535 " </Description>\n"
536 " <Location>\n"
537 " <Content>Tent</Content>\n"
538 " </Location>\n"
539 " <DateStarted>\n"
540 " <Content>20100506T040000Z</Content>\n"
541 " </DateStarted>\n"
542 " <DateEnd>\n"
543 " <Content>20100507T040000Z</Content>\n"
544 " </DateEnd>\n"
545 " <Alarm>\n"
546 " <AlarmAction>AUDIO</AlarmAction>\n"
547 " <AlarmTrigger>\n"
548 " <Content>20100506T034500Z</Content>\n"
549 " <Value>DATE-TIME</Value>\n"
550 " </AlarmTrigger>\n"
551 " </Alarm>\n"
552 " </Event>\n"
553 "</vcal>\n";
555 std::vector<OpenSync::SyncChange> changes;
556 changes.push_back(change);
558 change.id = 2;
559 change.member_id = 2;
560 change.plugin_name = "evo2-sync";
561 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
562 change.printable_data =
563 "<vcal>\n"
564 " <Method>\n"
565 " <Content>PUBLISH</Content>\n"
566 " </Method>\n"
567 " <Timezone>\n"
568 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
569 " <Location>America/Thunder_Bay</Location>\n"
570 " <Standard>\n"
571 " <TimezoneName>EST</TimezoneName>\n"
572 " <DateStarted>19701107T010000</DateStarted>\n"
573 " <RecurrenceRule>\n"
574 " <Rule>FREQ=YEARLY</Rule>\n"
575 " <Rule>INTERVAL=1</Rule>\n"
576 " <Rule>BYDAY=2SU</Rule>\n"
577 " <Rule>BYMONTH=11</Rule>\n"
578 " </RecurrenceRule>\n"
579 " <TZOffsetFrom>-0400</TZOffsetFrom>\n"
580 " <TZOffsetTo>-0500</TZOffsetTo>\n"
581 " </Standard>\n"
582 " <DaylightSavings>\n"
583 " <TimezoneName>EDT</TimezoneName>\n"
584 " <DateStarted>19700313T030000</DateStarted>\n"
585 " <RecurrenceRule>\n"
586 " <Rule>FREQ=YEARLY</Rule>\n"
587 " <Rule>INTERVAL=1</Rule>\n"
588 " <Rule>BYDAY=2SU</Rule>\n"
589 " <Rule>BYMONTH=3</Rule>\n"
590 " </RecurrenceRule>\n"
591 " <TZOffsetFrom>-0500</TZOffsetFrom>\n"
592 " <TZOffsetTo>-0400</TZOffsetTo>\n"
593 " </DaylightSavings>\n"
594 " </Timezone>\n"
595 " <Event>\n"
596 " <Sequence>\n"
597 " <Content>1</Content>\n"
598 " </Sequence>\n"
599 " <Summary>\n"
600 " <Content>Celebration day</Content>\n"
601 " </Summary>\n"
602 " <Location>\n"
603 " <Content>Tent of</Content>\n"
604 " </Location>\n"
605 " <DateStarted>\n"
606 " <Content>20100506T000000</Content>\n"
607 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
608 " </DateStarted>\n"
609 " <DateEnd>\n"
610 " <Content>20100507T000000</Content>\n"
611 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
612 " </DateEnd>\n"
613 " <DateCalendarCreated>\n"
614 " <Content>20100430T214736Z</Content>\n"
615 " </DateCalendarCreated>\n"
616 " <DateCreated>\n"
617 " <Content>20100430T214736</Content>\n"
618 " </DateCreated>\n"
619 " <LastModified>\n"
620 " <Content>20100430T214927</Content>\n"
621 " </LastModified>\n"
622 " <Description>\n"
623 " <Content>Bring burnt offering</Content>\n"
624 " </Description>\n"
625 " <Class>\n"
626 " <Content>PUBLIC</Content>\n"
627 " </Class>\n"
628 " <Transparency>\n"
629 " <Content>OPAQUE</Content>\n"
630 " </Transparency>\n"
631 " <Alarm>\n"
632 " <AlarmAction>AUDIO</AlarmAction>\n"
633 " <AlarmTrigger>\n"
634 " <Content>20100506T034500Z</Content>\n"
635 " <Value>DATE-TIME</Value>\n"
636 " </AlarmTrigger>\n"
637 " </Alarm>\n"
638 " </Event>\n"
639 "</vcal>\n";
642 changes.push_back(change);
645 ConflictDlg::AlwaysMemoryBlock always;
646 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
647 "SDAIN", changes, always);
648 dlg.ShowModal();
649 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
650 msg += _T(" ");
651 msg += always.m_always ? _T("always") : _T("not always");
652 wxMessageBox(msg);
657 void BaseFrame::OnMigrateDevice(wxCommandEvent &event)
659 try {
661 int i = Barry::Probe::Find(wxGetApp().GetResults(),
662 GetCurrentComboPin());
664 MigrateDlg dlg(this, wxGetApp().GetResults(), i);
665 dlg.ShowModal();
668 catch( std::exception &e ) {
669 wxString msg(_W(
670 "An error occurred during device migration.\n"
671 "This could be due to a low level USB issue\n"
672 "Please make sure your device is plugged in\n"
673 "and not in Desktop Mode. If it is, try replugging\n"
674 "the device, and rescanning the USB bus from the menu.\n"
675 "\n"
676 "Error: "));
677 msg += wxString(e.what(), wxConvUTF8);
678 wxMessageBox(msg, _W("Migrate Device"), wxOK | wxICON_ERROR, this);
679 return;
683 void BaseFrame::OnBrowseDatabases(wxCommandEvent &event)
685 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
686 if( i == -1 ) {
687 wxMessageBox(_W("There is no device selected in the device list. Please select a device to browse."),
688 _W("Database Browser Mode"), wxOK | wxICON_ERROR, this);
689 return;
692 try {
693 m_browse_mode.reset( new BrowseMode(this,
694 wxGetApp().GetResults()[i]) );
696 catch( std::exception &e ) {
697 wxString msg(_W(
698 "An error occurred that prevented the loading of Database\n"
699 "Browse mode. This could be due to a low level USB\n"
700 "issue. Please make sure your device is plugged in\n"
701 "and not in Desktop Mode. If it is, try replugging\n"
702 "the device, and rescanning the USB bus from the menu.\n"
703 "\n"
704 "Error: "));
705 msg += wxString(e.what(), wxConvUTF8);
706 wxMessageBox(msg, _W("Database Browser Mode"), wxOK | wxICON_ERROR, this);
707 return;
710 EnableBackButton(m_browse_mode.get());
713 void BaseFrame::OnMediaManagement(wxCommandEvent &event)
717 void BaseFrame::OnMisc(wxCommandEvent &event)
721 void BaseFrame::OnBackButton(wxCommandEvent &event)
723 DisableBackButton();
726 void BaseFrame::OnTermBackupAndRestore(wxProcessEvent &event)
728 barryverbose("OnTermBackupAndRestore(): done = "
729 << (!m_backup_process.IsAppRunning() ? "true" : "false")
730 << ", status = " << m_backup_process.GetRawAppStatus()
731 << ", exit code = " << m_backup_process.GetChildExitCode());
732 // only give a warning if the application could not be run...
733 // if there's an error code, and it's been running for longer
734 // than a second or two, then it's a real error code, or a
735 // segfault or something similar.
736 if( !m_backup_process.IsAppRunning() &&
737 m_backup_process.GetChildExitCode() &&
738 (time(NULL) - m_backup_process.GetStartTime()) < 2 )
740 wxMessageBox(_W("Unable to run barrybackup, or it returned an error. Please make sure it is installed and in your PATH."),
741 _W("Backup and Restore"), wxOK | wxICON_ERROR, this);
743 else
745 // looks like a successful run... the device name may
746 // have been changed by the BarryBackup GUI, so reprobe
747 // to refresh the names and device list
748 wxCommandEvent event;
749 OnRescanUsb(event);
753 void BaseFrame::OnBarryLogoClicked(wxCommandEvent &event)
755 PopupMenu(m_sysmenu.get(), 20, 20);
758 void BaseFrame::OnNetDirectLogoClicked(wxCommandEvent &event)
760 // fire up a browser to point to the Barry documentation
761 wxBusyCursor wait;
762 ::wxLaunchDefaultBrowser(_T("http://netdirect.ca/barry"));
765 void BaseFrame::OnDeviceComboChange(wxCommandEvent &event)
767 Barry::Pin pin = GetCurrentComboPin();
769 // any change?
770 if( pin == wxGetApp().GetGlobalConfig().GetLastDevice() )
771 return; // nope
773 // save
774 wxGetApp().GetGlobalConfig().SetLastDevice(pin);
776 // update sys menu
777 m_sysmenu->Enable(SysMenu_RenameDevice, pin.Valid());
779 // update the main mode's screenshot
780 m_main_menu_mode->UpdateScreenshot(pin);
781 if( m_current_mode == m_main_menu_mode.get() )
782 Refresh(false);
784 // FIXME - if inside a sub menu mode, we need to destroy the mode
785 // class and start fresh
788 void BaseFrame::OnVerboseLogging(wxCommandEvent &event)
790 Barry::Verbose( !Barry::IsVerbose() );
791 wxGetApp().GetGlobalConfig().SetVerboseLogging( Barry::IsVerbose() );
792 UpdateMenuState();
795 void BaseFrame::OnRenameDevice(wxCommandEvent &event)
797 Barry::Pin pin = GetCurrentComboPin();
798 if( !pin.Valid() )
799 return;
801 // grab the current known name of the device
802 const Barry::Probe::Results &results = wxGetApp().GetResults();
803 int index = Barry::Probe::Find(results, pin);
804 if( index == -1 )
805 return;
807 wxString current_name(results[index].m_cfgDeviceName.c_str(), wxConvUTF8);
808 wxTextEntryDialog dlg(this,
809 _W("Please enter a name for the current device:"),
810 _W("Rename Device"),
811 current_name, wxTextEntryDialogStyle);
813 if( dlg.ShowModal() != wxID_OK )
814 return; // nothing to do
815 wxString name = dlg.GetValue();
816 if( name == current_name )
817 return; // nothing to do
819 wxGetApp().SetDeviceName(pin, string(name.utf8_str()));
821 // refill combo box
822 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
825 void BaseFrame::OnResetDevice(wxCommandEvent &event)
827 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
828 if( i != -1 ) {
829 Usb::Device dev(wxGetApp().GetResults()[i].m_dev);
830 dev.Reset();
831 wxBusyCursor wait;
832 wxSleep(4);
833 OnRescanUsb(event);
837 void BaseFrame::OnRescanUsb(wxCommandEvent &event)
839 if( m_current_mode == m_main_menu_mode.get() ) {
840 std::auto_ptr<UsbScanSplash> splash( new UsbScanSplash );
841 wxGetApp().Probe();
842 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
843 m_rescan_pending = false;
845 else {
846 // flag that we need to rescan the next time we return
847 // to the main screen
848 m_rescan_pending = true;
852 void BaseFrame::OnAbout(wxCommandEvent &event)
854 wxAboutDialogInfo info;
855 info.SetName(_W("Barry Desktop Control Panel"));
856 info.SetVersion(_T(BARRY_DESKTOP_VER_STRING));
857 info.SetDescription(_W("A Free Software graphical user interface for working with the BlackBerry® smartphone."));
858 info.SetCopyright(_T("Copyright © 2009-2013, Net Direct Inc."));
859 info.SetWebSite(_T("http://netdirect.ca/barry"));
860 info.SetLicense(_T(
861 " This program is free software; you can redistribute it and/or modify\n"
862 " it under the terms of the GNU General Public License as published by\n"
863 " the Free Software Foundation; either version 2 of the License, or\n"
864 " (at your option) any later version.\n"
865 "\n"
866 " This program is distributed in the hope that it will be useful,\n"
867 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
868 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
869 "\n"
870 " See the GNU General Public License in the COPYING file at the\n"
871 " root directory of this project for more details.\n"));
873 info.AddDeveloper(_T("Net Direct Inc."));
874 // info.AddDeveloper(_T("Chris Frey <cdfrey@foursquare.net>"));
875 // info.AddDeveloper(_T("See AUTHORS file for detailed"));
876 // info.AddDeveloper(_T("contribution information."));
878 info.AddArtist(_W("Chris Frey - GUI interface"));
879 info.AddArtist(_W("Martin Owens - Barry logo"));
880 info.AddArtist(_W("Tango Desktop Project - Public domain icons"));
882 wxAboutBox(info);
885 void BaseFrame::OnExit(wxCommandEvent &event)
887 Close(true);