2 /// \file barrydesktop.cc
3 /// Program entry point for the desktop GUI
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"
25 #include "BaseFrame.h"
27 #include <wx/splash.h>
28 #include <wx/mstream.h>
33 UsbScanSplash::UsbScanSplash()
35 wxImage
scanpng(GetImageFilename(_T("scanning.png")));
36 wxBitmap
scanning(scanpng
);
37 std::auto_ptr
<wxSplashScreen
> splash( new wxSplashScreen(
38 scanning
, wxSPLASH_CENTRE_ON_SCREEN
, 0,
39 NULL
, -1, wxDefaultPosition
, wxDefaultSize
,
46 UsbScanSplash::~UsbScanSplash()
50 //////////////////////////////////////////////////////////////////////////////
53 BarryDesktopApp::BarryDesktopApp()
54 : m_global_config("BarryDesktop")
55 , m_set( new OpenSync::APISet
)
59 void BarryDesktopApp::Probe()
65 // This can throw Usb::Error exceptions
67 m_results
= probe
.GetResults();
69 catch( Usb::Error
&e
) {
70 wxString msg
= _W("A serious error occurred while probing the USB subsystem for BlackBerry(R) devices: ");
71 msg
+= wxString(e
.what(), wxConvUTF8
);
72 wxMessageBox(msg
, _W("USB Error"), wxOK
| wxICON_ERROR
);
76 wxBitmap
BarryDesktopApp::GetScreenshot(const Barry::ProbeResult
&device
) const
78 // FIXME - will need to eventually move the controller object
79 // into the main app, I think, and maybe the modes too, so
80 // that multiple menu commands can work simultaneously
82 Barry::Controller
con(device
);
83 Barry::Mode::JavaLoader
javaloader(con
);
86 javaloader
.StartStream();
88 Barry::JLScreenInfo info
;
90 javaloader
.GetScreenshot(info
, image
);
92 // Convert to BMP format
93 Barry::Data
bitmap(-1, GetTotalBitmapSize(info
));
94 Barry::ScreenshotToBitmap(info
, image
, bitmap
);
97 wxMemoryInputStream
stream(bitmap
.GetData(), bitmap
.GetSize());
98 wxImage
bmp(stream
, wxBITMAP_TYPE_BMP
);
99 bmp
.Rescale(180, 100, wxIMAGE_QUALITY_HIGH
);
100 return wxBitmap(bmp
);
103 void BarryDesktopApp::SetDeviceName(Barry::Pin pin
, const std::string
&name
)
108 // load device config
109 Barry::ConfigFile
cfg(pin
);
111 // re-save device config
112 cfg
.SetDeviceName(name
);
115 // update our results if this device exists in our list
116 int index
= Barry::Probe::Find(m_results
, pin
);
118 m_results
[index
].m_cfgDeviceName
= name
;
122 std::string
BarryDesktopApp::GetDeviceName(Barry::Pin pin
) const
125 int index
= Barry::Probe::Find(m_results
, pin
);
127 name
= m_results
[index
].m_cfgDeviceName
;
131 void BarryDesktopApp::ShowMissingOpenSyncMessage()
133 wxMessageBox(_W("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."), _W("OpenSync Not Found"), wxOK
| wxICON_INFORMATION
);
136 bool BarryDesktopApp::OnInit()
138 // Add a PNG handler for loading buttons and backgrounds
139 wxImage::AddHandler( new wxPNGHandler
);
141 // Add handlers for loading Contact Photos
142 wxImage::AddHandler( new wxJPEGHandler
);
143 wxImage::AddHandler( new wxTIFFHandler
);
144 wxImage::AddHandler( new wxXPMHandler
);
146 std::auto_ptr
<UsbScanSplash
> splash( new UsbScanSplash
);
148 // Initialize Barry and USB
149 Barry::Init(m_global_config
.VerboseLogging());
151 // Scan bus at the beginning so we know what devices we've got
154 // Search for available OpenSync libraries
155 if( m_set
->OpenAvailable() == 0 ) {
156 ShowMissingOpenSyncMessage();
159 // Create the main frame window where all the action happens
160 wxImage
back(GetImageFilename(_T("background.png")));
165 BaseFrame
*frame
= new BaseFrame(back
);
167 // Clean up the splash screen, and init the main frame
175 int BarryDesktopApp::OnExit()
178 m_global_config
.Save();
180 catch( std::exception
&e
) {
181 cerr
<< "Exception caught while saving config: "
188 // This takes care of main() and wxGetApp() for us.
189 IMPLEMENT_APP(BarryDesktopApp
)