lib: added warning checks for unsupported recursion fields in vevent.cc
[barry/progweb.git] / desktop / src / barrydesktop.cc
blob9bba98e1368d9f7a015eb689272cbe9674341fc3
1 ///
2 /// \file barrydesktop.cc
3 /// Program entry point for the desktop GUI
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 "barrydesktop.h"
23 #include "util.h"
24 #include "osbase.h"
25 #include "BaseFrame.h"
26 #include <memory>
27 #include <wx/splash.h>
28 #include <wx/mstream.h>
30 using namespace std;
32 UsbScanSplash::UsbScanSplash()
34 wxImage scanpng(GetImageFilename(_T("scanning.png")));
35 wxBitmap scanning(scanpng);
36 std::auto_ptr<wxSplashScreen> splash( new wxSplashScreen(
37 scanning, wxSPLASH_CENTRE_ON_SCREEN, 0,
38 NULL, -1, wxDefaultPosition, wxDefaultSize,
39 wxSIMPLE_BORDER) );
40 splash->Show(true);
41 wxGetApp().Yield();
42 wxGetApp().Yield();
45 UsbScanSplash::~UsbScanSplash()
49 //////////////////////////////////////////////////////////////////////////////
50 // BarryDesktopApp
52 BarryDesktopApp::BarryDesktopApp()
53 : m_global_config("BarryDesktop")
54 , m_set( new OpenSync::APISet )
58 void BarryDesktopApp::Probe()
60 // start fresh
61 m_results.clear();
63 try {
64 // This can throw Usb::Error exceptions
65 Barry::Probe probe;
66 m_results = probe.GetResults();
68 catch( Usb::Error &e ) {
69 wxString msg = _T("A serious error occurred while probing the USB subsystem for BlackBerry(R) devices: ");
70 msg += wxString(e.what(), wxConvUTF8);
71 wxMessageBox(msg, _T("USB Error"), wxOK | wxICON_ERROR);
75 wxBitmap BarryDesktopApp::GetScreenshot(const Barry::ProbeResult &device) const
77 // FIXME - will need to eventually move the controller object
78 // into the main app, I think, and maybe the modes too, so
79 // that multiple menu commands can work simultaneously
81 Barry::Controller con(device);
82 Barry::Mode::JavaLoader javaloader(con);
84 javaloader.Open();
85 javaloader.StartStream();
87 Barry::JLScreenInfo info;
88 Barry::Data image;
89 javaloader.GetScreenshot(info, image);
91 // Convert to BMP format
92 Barry::Data bitmap(-1, GetTotalBitmapSize(info));
93 Barry::ScreenshotToBitmap(info, image, bitmap);
95 // Load as wxImage
96 wxMemoryInputStream stream(bitmap.GetData(), bitmap.GetSize());
97 wxImage bmp(stream, wxBITMAP_TYPE_BMP);
98 bmp.Rescale(180, 100, wxIMAGE_QUALITY_HIGH);
99 return wxBitmap(bmp);
102 void BarryDesktopApp::SetDeviceName(Barry::Pin pin, const std::string &name)
104 if( !pin.Valid() )
105 return;
107 // load device config
108 Barry::ConfigFile cfg(pin);
110 // re-save device config
111 cfg.SetDeviceName(name);
112 cfg.Save();
114 // update our results if this device exists in our list
115 int index = Barry::Probe::Find(m_results, pin);
116 if( index != -1 ) {
117 m_results[index].m_cfgDeviceName = name;
121 std::string BarryDesktopApp::GetDeviceName(Barry::Pin pin) const
123 string name;
124 int index = Barry::Probe::Find(m_results, pin);
125 if( index != -1 )
126 name = m_results[index].m_cfgDeviceName;
127 return name;
130 void BarryDesktopApp::ShowMissingOpenSyncMessage()
132 wxMessageBox(_T("No OpenSync libraries were found. Sync will be unavailable until you install OpenSync version 0.22 or version 0.4x on your system, along with the needed plugins."), _T("OpenSync Not Found"), wxOK | wxICON_INFORMATION);
135 bool BarryDesktopApp::OnInit()
137 // Add a PNG handler for loading buttons and backgrounds
138 wxImage::AddHandler( new wxPNGHandler );
140 // Add handlers for loading Contact Photos
141 wxImage::AddHandler( new wxJPEGHandler );
142 wxImage::AddHandler( new wxTIFFHandler );
143 wxImage::AddHandler( new wxXPMHandler );
145 std::auto_ptr<UsbScanSplash> splash( new UsbScanSplash );
147 // Initialize Barry and USB
148 Barry::Init(m_global_config.VerboseLogging());
150 // Scan bus at the beginning so we know what devices we've got
151 Probe();
153 // Search for available OpenSync libraries
154 if( m_set->OpenAvailable() == 0 ) {
155 ShowMissingOpenSyncMessage();
158 // Create the main frame window where all the action happens
159 wxImage back(GetImageFilename(_T("background.png")));
160 if( !back.IsOk() ) {
161 Yield();
162 return false;
164 BaseFrame *frame = new BaseFrame(back);
166 // Clean up the splash screen, and init the main frame
167 splash.reset();
168 SetTopWindow(frame);
169 frame->Show(true);
171 return true;
174 int BarryDesktopApp::OnExit()
176 try {
177 m_global_config.Save();
179 catch( std::exception &e ) {
180 cerr << "Exception caught while saving config: "
181 << e.what() << endl;
184 return 0;
187 // This takes care of main() and wxGetApp() for us.
188 IMPLEMENT_APP(BarryDesktopApp)