2 /// \file barrydesktop.cc
3 /// Program entry point for the desktop GUI
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 "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
);
38 // draw i18n text on the splash screen
41 dc
.SelectObject(scanning
);
43 int pointsize
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
) .GetPointSize();
44 wxFont
font(pointsize
+ 2, wxFONTFAMILY_SWISS
,
45 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
47 DrawButtonLabelDC(dc
, scanning
, _W("Scanning USB..."),
48 font
, *wxBLACK
, 70, -1, -1, -1);
51 std::auto_ptr
<wxSplashScreen
> splash( new wxSplashScreen(
52 scanning
, wxSPLASH_CENTRE_ON_SCREEN
, 0,
53 NULL
, -1, wxDefaultPosition
, wxDefaultSize
,
56 for( int i
= 0; i
< 4; i
++ ) {
63 UsbScanSplash::~UsbScanSplash()
67 //////////////////////////////////////////////////////////////////////////////
70 BarryDesktopApp::BarryDesktopApp()
71 : m_global_config("BarryDesktop")
72 , m_set( new OpenSync::APISet
)
76 void BarryDesktopApp::Probe()
82 // This can throw Usb::Error exceptions
84 m_results
= probe
.GetResults();
86 catch( Usb::Error
&e
) {
87 wxString msg
= _W("A serious error occurred while probing the USB subsystem for BlackBerry(R) devices: ");
88 msg
+= wxString(e
.what(), wxConvUTF8
);
89 wxMessageBox(msg
, _W("USB Error"), wxOK
| wxICON_ERROR
);
93 wxBitmap
BarryDesktopApp::GetScreenshot(const Barry::ProbeResult
&device
) const
95 // FIXME - will need to eventually move the controller object
96 // into the main app, I think, and maybe the modes too, so
97 // that multiple menu commands can work simultaneously
99 Barry::Controller
con(device
);
100 Barry::Mode::JavaLoader
javaloader(con
);
103 javaloader
.StartStream();
105 Barry::JLScreenInfo info
;
107 javaloader
.GetScreenshot(info
, image
);
109 // Convert to BMP format
110 Barry::Data
bitmap(-1, GetTotalBitmapSize(info
));
111 Barry::ScreenshotToBitmap(info
, image
, bitmap
);
114 wxMemoryInputStream
stream(bitmap
.GetData(), bitmap
.GetSize());
115 wxImage
bmp(stream
, wxBITMAP_TYPE_BMP
);
116 bmp
.Rescale(180, 100, wxIMAGE_QUALITY_HIGH
);
117 return wxBitmap(bmp
);
120 void BarryDesktopApp::SetDeviceName(Barry::Pin pin
, const std::string
&name
)
125 // load device config
126 Barry::ConfigFile
cfg(pin
);
128 // re-save device config
129 cfg
.SetDeviceName(name
);
132 // update our results if this device exists in our list
133 int index
= Barry::Probe::Find(m_results
, pin
);
135 m_results
[index
].m_cfgDeviceName
= name
;
139 std::string
BarryDesktopApp::GetDeviceName(Barry::Pin pin
) const
142 int index
= Barry::Probe::Find(m_results
, pin
);
144 name
= m_results
[index
].m_cfgDeviceName
;
148 void BarryDesktopApp::ShowMissingOpenSyncMessage()
150 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
);
153 bool BarryDesktopApp::OnInit()
158 // Add a PNG handler for loading buttons and backgrounds
159 wxImage::AddHandler( new wxPNGHandler
);
161 // Add handlers for loading Contact Photos
162 wxImage::AddHandler( new wxJPEGHandler
);
163 wxImage::AddHandler( new wxTIFFHandler
);
164 wxImage::AddHandler( new wxXPMHandler
);
166 std::auto_ptr
<UsbScanSplash
> splash( new UsbScanSplash
);
168 // Initialize Barry and USB
169 Barry::Init(m_global_config
.VerboseLogging());
171 // Scan bus at the beginning so we know what devices we've got
174 // Search for available OpenSync libraries
175 if( m_set
->OpenAvailable() == 0 ) {
176 ShowMissingOpenSyncMessage();
179 // Create the main frame window where all the action happens
180 wxImage
back(GetImageFilename(_T("background.png")));
185 BaseFrame
*frame
= new BaseFrame(back
);
187 // Clean up the splash screen, and init the main frame
195 int BarryDesktopApp::OnExit()
198 m_global_config
.Save();
200 catch( std::exception
&e
) {
201 cerr
<< "Exception caught while saving config: "
208 // This takes care of main() and wxGetApp() for us.
209 IMPLEMENT_APP(BarryDesktopApp
)