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>
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
,
45 UsbScanSplash::~UsbScanSplash()
49 //////////////////////////////////////////////////////////////////////////////
52 BarryDesktopApp::BarryDesktopApp()
53 : m_global_config("BarryDesktop")
54 , m_set( new OpenSync::APISet
)
58 void BarryDesktopApp::Probe()
64 // This can throw Usb::Error exceptions
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
);
85 javaloader
.StartStream();
87 Barry::JLScreenInfo info
;
89 javaloader
.GetScreenshot(info
, image
);
91 // Convert to BMP format
92 Barry::Data
bitmap(-1, GetTotalBitmapSize(info
));
93 Barry::ScreenshotToBitmap(info
, image
, bitmap
);
96 wxMemoryInputStream
stream(bitmap
.GetData(), bitmap
.GetSize());
97 wxImage
bmp(stream
, wxBITMAP_TYPE_BMP
);
98 bmp
.Rescale(180, 100, wxIMAGE_QUALITY_HIGH
);
102 void BarryDesktopApp::SetDeviceName(Barry::Pin pin
, const std::string
&name
)
107 // load device config
108 Barry::ConfigFile
cfg(pin
);
110 // re-save device config
111 cfg
.SetDeviceName(name
);
114 // update our results if this device exists in our list
115 int index
= Barry::Probe::Find(m_results
, pin
);
117 m_results
[index
].m_cfgDeviceName
= name
;
121 std::string
BarryDesktopApp::GetDeviceName(Barry::Pin pin
) const
124 int index
= Barry::Probe::Find(m_results
, pin
);
126 name
= m_results
[index
].m_cfgDeviceName
;
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
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")));
164 BaseFrame
*frame
= new BaseFrame(back
);
166 // Clean up the splash screen, and init the main frame
174 int BarryDesktopApp::OnExit()
177 m_global_config
.Save();
179 catch( std::exception
&e
) {
180 cerr
<< "Exception caught while saving config: "
187 // This takes care of main() and wxGetApp() for us.
188 IMPLEMENT_APP(BarryDesktopApp
)