desktop: disable netdirect logo until we get a better looking one
[barry/progweb.git] / desktop / src / BaseFrame.cc
blob06a8804be7d8ea91b7f908c22aefa13bbf9883bb
1 ///
2 /// \file BaseFrame.cc
3 /// Class for the fixed-size frame that holds the main app
4 ///
6 /*
7 Copyright (C) 2009-2011, 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 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 "ConflictDlg.h"
364 void BaseFrame::OnModem(wxCommandEvent &event)
367 OpenSync::SyncChange change;
368 change.id = 1;
369 change.member_id = 1;
370 change.plugin_name = "barry-sync";
371 change.uid = "12341524235234";
372 change.printable_data =
373 "<contact>\n"
374 " <UnknownNode>\n"
375 " <NodeName>PRODID</NodeName>\n"
376 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
377 " </UnknownNode>\n"
378 " <FormattedName>\n"
379 " <Content>Adame Brandee</Content>\n"
380 " </FormattedName>\n"
381 " <Name>\n"
382 " <LastName>Brandee</LastName>\n"
383 " <FirstName>Adame</FirstName>\n"
384 " </Name>\n"
385 " <AddressLabel>\n"
386 " <Content>71 Long St.\n"
387 "Toronto ON Canada\n"
388 "N0N 0N0</Content>\n"
389 " <Type>home</Type>\n"
390 " </AddressLabel>\n"
391 " <Address>\n"
392 " <Street>71 Long St.</Street>\n"
393 " <City>Toronto</City>\n"
394 " <Region>ON</Region>\n"
395 " <PostalCode>N0N 0N0</PostalCode>\n"
396 " <Country>Canada</Country>\n"
397 " <Type>home</Type>\n"
398 " </Address>\n"
399 " <Telephone>\n"
400 " <Content>+1 (416) 555-7711</Content>\n"
401 " <Type>voice</Type>\n"
402 " <Type>home</Type>\n"
403 " </Telephone>\n"
404 " <Telephone>\n"
405 " <Content>+1 (416) 955-7117</Content>\n"
406 " <Type>msg</Type>\n"
407 " <Type>cell</Type>\n"
408 " </Telephone>\n"
409 " <EMail>\n"
410 " <Content>abrandee@sympatico.ca</Content>\n"
411 " <Type>internet</Type>\n"
412 " <Type>pref</Type>\n"
413 " </EMail>\n"
414 " <Categories>\n"
415 " <Category>Personal</Category>\n"
416 " </Categories>\n"
417 " <Note>\n"
418 " <Content>Interweb salesman... 24/7</Content>\n"
419 " </Note>\n"
420 "</contact>";
422 std::vector<OpenSync::SyncChange> changes;
423 changes.push_back(change);
425 change.id = 2;
426 change.member_id = 2;
427 change.plugin_name = "evo2-sync";
428 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
429 change.printable_data =
430 "<contact>\n"
431 " <Telephone>\n"
432 " <Content>+1 (416) 955-7117</Content>\n"
433 " <Type>CELL</Type>\n"
434 " <Slot>2</Slot>\n"
435 " </Telephone>\n"
436 " <Telephone>\n"
437 " <Content>+1 (416) 555-7711</Content>\n"
438 " <Type>HOME</Type>\n"
439 " <Type>VOICE</Type>\n"
440 " <Slot>1</Slot>\n"
441 " </Telephone>\n"
442 " <EMail>\n"
443 " <Content>abrandee@sympatico.ca</Content>\n"
444 " <Type>OTHER</Type>\n"
445 " <Slot>1</Slot>\n"
446 " </EMail>\n"
447 " <WantsHtml>\n"
448 " <Content>FALSE</Content>\n"
449 " </WantsHtml>\n"
450 " <Revision>\n"
451 " <Content>20100322T225303Z</Content>\n"
452 " </Revision>\n"
453 " <UnknownNode>\n"
454 " <NodeName>PRODID</NodeName>\n"
455 " <Content>-//OpenSync//NONSGML Barry Contact Record//EN</Content>\n"
456 " </UnknownNode>\n"
457 " <FormattedName>\n"
458 " <Content>Adam Brandeee</Content>\n"
459 " </FormattedName>\n"
460 " <Name>\n"
461 " <LastName>Brandeee</LastName>\n"
462 " <FirstName>Adam</FirstName>\n"
463 " </Name>\n"
464 " <AddressLabel>\n"
465 " <Content>71 Long St.\n"
466 "Toronto, ON\n"
467 "N0N 0N1\n"
468 "Canada</Content>\n"
469 " <Type>home</Type>\n"
470 " </AddressLabel>\n"
471 " <Address>\n"
472 " <Street>71 Long St.</Street>\n"
473 " <City>Toronto</City>\n"
474 " <Region>ON</Region>\n"
475 " <PostalCode>N0N 0N1</PostalCode>\n"
476 " <Country>Canada</Country>\n"
477 " <Type>home</Type>\n"
478 " </Address>\n"
479 " <Categories>\n"
480 " <Category>Personal</Category>\n"
481 " </Categories>\n"
482 " <FileAs>\n"
483 " <Content>Brandeee, Adam</Content>\n"
484 " </FileAs>\n"
485 "</contact>";
487 changes.push_back(change);
490 ConflictDlg::AlwaysMemoryBlock always;
491 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
492 "SDAIN", changes, always);
493 dlg.ShowModal();
494 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
495 msg += _T(" ");
496 msg += always.m_always ? _T("always") : _T("not always");
497 wxMessageBox(msg);
502 void BaseFrame::OnAppLoader(wxCommandEvent &event)
505 OpenSync::SyncChange change;
506 change.id = 1;
507 change.member_id = 1;
508 change.plugin_name = "barry-sync";
509 change.uid = "12341524235234";
510 change.printable_data =
511 "<vcal>\n"
512 " <Event>\n"
513 " <Sequence>\n"
514 " <Content>0</Content>\n"
515 " </Sequence>\n"
516 " <Summary>\n"
517 " <Content>Subject</Content>\n"
518 " </Summary>\n"
519 " <Description>\n"
520 " <Content>Bring burnt offering</Content>\n"
521 " </Description>\n"
522 " <Location>\n"
523 " <Content>Tent</Content>\n"
524 " </Location>\n"
525 " <DateStarted>\n"
526 " <Content>20100506T040000Z</Content>\n"
527 " </DateStarted>\n"
528 " <DateEnd>\n"
529 " <Content>20100507T040000Z</Content>\n"
530 " </DateEnd>\n"
531 " <Alarm>\n"
532 " <AlarmAction>AUDIO</AlarmAction>\n"
533 " <AlarmTrigger>\n"
534 " <Content>20100506T034500Z</Content>\n"
535 " <Value>DATE-TIME</Value>\n"
536 " </AlarmTrigger>\n"
537 " </Alarm>\n"
538 " </Event>\n"
539 "</vcal>\n";
541 std::vector<OpenSync::SyncChange> changes;
542 changes.push_back(change);
544 change.id = 2;
545 change.member_id = 2;
546 change.plugin_name = "evo2-sync";
547 change.uid = "asdfioausdf_1235234as_asdf12341524235234";
548 change.printable_data =
549 "<vcal>\n"
550 " <Method>\n"
551 " <Content>PUBLISH</Content>\n"
552 " </Method>\n"
553 " <Timezone>\n"
554 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
555 " <Location>America/Thunder_Bay</Location>\n"
556 " <Standard>\n"
557 " <TimezoneName>EST</TimezoneName>\n"
558 " <DateStarted>19701107T010000</DateStarted>\n"
559 " <RecurrenceRule>\n"
560 " <Rule>FREQ=YEARLY</Rule>\n"
561 " <Rule>INTERVAL=1</Rule>\n"
562 " <Rule>BYDAY=2SU</Rule>\n"
563 " <Rule>BYMONTH=11</Rule>\n"
564 " </RecurrenceRule>\n"
565 " <TZOffsetFrom>-0400</TZOffsetFrom>\n"
566 " <TZOffsetTo>-0500</TZOffsetTo>\n"
567 " </Standard>\n"
568 " <DaylightSavings>\n"
569 " <TimezoneName>EDT</TimezoneName>\n"
570 " <DateStarted>19700313T030000</DateStarted>\n"
571 " <RecurrenceRule>\n"
572 " <Rule>FREQ=YEARLY</Rule>\n"
573 " <Rule>INTERVAL=1</Rule>\n"
574 " <Rule>BYDAY=2SU</Rule>\n"
575 " <Rule>BYMONTH=3</Rule>\n"
576 " </RecurrenceRule>\n"
577 " <TZOffsetFrom>-0500</TZOffsetFrom>\n"
578 " <TZOffsetTo>-0400</TZOffsetTo>\n"
579 " </DaylightSavings>\n"
580 " </Timezone>\n"
581 " <Event>\n"
582 " <Sequence>\n"
583 " <Content>1</Content>\n"
584 " </Sequence>\n"
585 " <Summary>\n"
586 " <Content>Celebration day</Content>\n"
587 " </Summary>\n"
588 " <Location>\n"
589 " <Content>Tent of</Content>\n"
590 " </Location>\n"
591 " <DateStarted>\n"
592 " <Content>20100506T000000</Content>\n"
593 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
594 " </DateStarted>\n"
595 " <DateEnd>\n"
596 " <Content>20100507T000000</Content>\n"
597 " <TimezoneID>/softwarestudio.org/Tzfile/America/Thunder_Bay</TimezoneID>\n"
598 " </DateEnd>\n"
599 " <DateCalendarCreated>\n"
600 " <Content>20100430T214736Z</Content>\n"
601 " </DateCalendarCreated>\n"
602 " <DateCreated>\n"
603 " <Content>20100430T214736</Content>\n"
604 " </DateCreated>\n"
605 " <LastModified>\n"
606 " <Content>20100430T214927</Content>\n"
607 " </LastModified>\n"
608 " <Description>\n"
609 " <Content>Bring burnt offering</Content>\n"
610 " </Description>\n"
611 " <Class>\n"
612 " <Content>PUBLIC</Content>\n"
613 " </Class>\n"
614 " <Transparency>\n"
615 " <Content>OPAQUE</Content>\n"
616 " </Transparency>\n"
617 " <Alarm>\n"
618 " <AlarmAction>AUDIO</AlarmAction>\n"
619 " <AlarmTrigger>\n"
620 " <Content>20100506T034500Z</Content>\n"
621 " <Value>DATE-TIME</Value>\n"
622 " </AlarmTrigger>\n"
623 " </Alarm>\n"
624 " </Event>\n"
625 "</vcal>\n";
628 changes.push_back(change);
631 ConflictDlg::AlwaysMemoryBlock always;
632 ConflictDlg dlg(this, *wxGetApp().GetOpenSync().os22(),
633 "SDAIN", changes, always);
634 dlg.ShowModal();
635 wxString msg(dlg.GetCommand().c_str(), wxConvUTF8);
636 msg += _T(" ");
637 msg += always.m_always ? _T("always") : _T("not always");
638 wxMessageBox(msg);
643 void BaseFrame::OnDeviceSwitch(wxCommandEvent &event)
647 void BaseFrame::OnBrowseDatabases(wxCommandEvent &event)
649 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
650 if( i == -1 ) {
651 wxMessageBox(_T("There is no device selected in the device list. Please select a device to browse."),
652 _T("Database Browser Mode"), wxOK | wxICON_ERROR);
653 return;
656 try {
657 m_browse_mode.reset( new BrowseMode(this,
658 wxGetApp().GetResults()[i]) );
660 catch( std::exception &e ) {
661 wxString msg(_T(
662 "An error occurred that prevented the loading of Database\n"
663 "Browse mode. This could be due to a low level USB\n"
664 "issue. Please make sure your device is plugged in\n"
665 "and not in Desktop Mode. If it is, try replugging\n"
666 "the device, and rescanning the USB bus from the menu.\n"
667 "\n"
668 "Error: "));
669 msg += wxString(e.what(), wxConvUTF8);
670 wxMessageBox(msg, _T("Database Browser Mode"), wxOK | wxICON_ERROR);
671 return;
674 EnableBackButton(m_browse_mode.get());
677 void BaseFrame::OnMediaManagement(wxCommandEvent &event)
681 void BaseFrame::OnMisc(wxCommandEvent &event)
685 void BaseFrame::OnBackButton(wxCommandEvent &event)
687 DisableBackButton();
690 void BaseFrame::OnTermBackupAndRestore(wxProcessEvent &event)
692 barryverbose("OnTermBackupAndRestore(): done = "
693 << (!m_backup_process.IsAppRunning() ? "true" : "false")
694 << ", status = " << m_backup_process.GetAppStatus());
695 if( !m_backup_process.IsAppRunning() &&
696 m_backup_process.GetAppStatus() )
698 wxMessageBox(_T("Unable to run barrybackup, or it returned an error. Please make sure it is installed and in your PATH."),
699 _T("Backup and Restore"), wxOK | wxICON_ERROR);
703 void BaseFrame::OnBarryLogoClicked(wxCommandEvent &event)
705 PopupMenu(m_sysmenu.get(), 20, 20);
708 void BaseFrame::OnNetDirectLogoClicked(wxCommandEvent &event)
710 // fire up a browser to point to the Barry documentation
711 wxBusyCursor wait;
712 ::wxLaunchDefaultBrowser(_T("http://netdirect.ca/barry"));
715 void BaseFrame::OnDeviceComboChange(wxCommandEvent &event)
717 Barry::Pin pin = GetCurrentComboPin();
719 // any change?
720 if( pin == wxGetApp().GetGlobalConfig().GetLastDevice() )
721 return; // nope
723 // save
724 wxGetApp().GetGlobalConfig().SetLastDevice(pin);
726 // update sys menu
727 m_sysmenu->Enable(SysMenu_RenameDevice, false);
729 // update the main mode's screenshot
730 m_main_menu_mode->UpdateScreenshot(pin);
731 if( m_current_mode == m_main_menu_mode.get() )
732 Refresh(false);
734 // FIXME - if inside a sub menu mode, we need to destroy the mode
735 // class and start fresh
738 void BaseFrame::OnVerboseLogging(wxCommandEvent &event)
740 Barry::Verbose( !Barry::IsVerbose() );
741 wxGetApp().GetGlobalConfig().SetVerboseLogging( Barry::IsVerbose() );
742 UpdateMenuState();
745 void BaseFrame::OnRenameDevice(wxCommandEvent &event)
747 Barry::Pin pin = GetCurrentComboPin();
748 if( !pin.Valid() )
749 return;
751 // grab the current known name of the device
752 const Barry::Probe::Results &results = wxGetApp().GetResults();
753 int index = Barry::Probe::Find(results, pin);
754 if( index == -1 )
755 return;
757 wxString current_name(results[index].m_cfgDeviceName.c_str(), wxConvUTF8);
758 wxTextEntryDialog dlg(this,
759 _T("Please enter a name for the current device:"),
760 _T("Rename Device"),
761 current_name, wxTextEntryDialogStyle);
763 if( dlg.ShowModal() != wxID_OK )
764 return; // nothing to do
765 wxString name = dlg.GetValue();
766 if( name == current_name )
767 return; // nothing to do
769 wxGetApp().SetDeviceName(pin, string(name.utf8_str()));
771 // refill combo box
772 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
775 void BaseFrame::OnResetDevice(wxCommandEvent &event)
777 int i = Barry::Probe::Find(wxGetApp().GetResults(), GetCurrentComboPin());
778 if( i != -1 ) {
779 Usb::Device dev(wxGetApp().GetResults()[i].m_dev);
780 dev.Reset();
781 wxBusyCursor wait;
782 wxSleep(4);
783 OnRescanUsb(event);
787 void BaseFrame::OnRescanUsb(wxCommandEvent &event)
789 if( m_current_mode == m_main_menu_mode.get() ) {
790 std::auto_ptr<UsbScanSplash> splash( new UsbScanSplash );
791 wxGetApp().Probe();
792 CreateDeviceCombo(wxGetApp().GetGlobalConfig().GetLastDevice());
794 else {
795 // FIXME - tell the user we didn't do anything?
796 // or perhaps just disable rescan while in a mode
800 void BaseFrame::OnAbout(wxCommandEvent &event)
802 wxAboutDialogInfo info;
803 info.SetName(_T("Barry Desktop Control Panel"));
804 info.SetVersion(_T("0.17"));
805 info.SetDescription(_T("A Free Software graphical user interface for working with the BlackBerry(TM) handheld."));
806 info.SetCopyright(_T("Copyright (C) 2009-2011, Net Direct Inc."));
807 info.SetWebSite(_T("http://netdirect.ca/barry"));
808 info.SetLicense(_T(
809 " This program is free software; you can redistribute it and/or modify\n"
810 " it under the terms of the GNU General Public License as published by\n"
811 " the Free Software Foundation; either version 2 of the License, or\n"
812 " (at your option) any later version.\n"
813 "\n"
814 " This program is distributed in the hope that it will be useful,\n"
815 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
816 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
817 "\n"
818 " See the GNU General Public License in the COPYING file at the\n"
819 " root directory of this project for more details.\n"));
821 info.AddDeveloper(_T("Net Direct Inc."));
822 // info.AddDeveloper(_T("Chris Frey <cdfrey@foursquare.net>"));
823 // info.AddDeveloper(_T("See AUTHORS file for detailed"));
824 // info.AddDeveloper(_T("contribution information."));
826 info.AddArtist(_T("Chris Frey - GUI interface"));
827 info.AddArtist(_T("Martin Owens - Barry logo"));
828 info.AddArtist(_T("Tango Desktop Project - Public domain icons"));
830 wxAboutBox(info);
833 void BaseFrame::OnExit(wxCommandEvent &event)
835 Close(true);