@ -7,6 +7,13 @@
# include <crtdbg.h>
# include <crtdbg.h>
# endif
# endif
void ThreadRequestProductDetails ( void * parg ) ;
void ThreadRandSendTest ( void * parg ) ;
bool GetStartOnSystemStartup ( ) ;
void SetStartOnSystemStartup ( bool fAutoStart ) ;
DEFINE_EVENT_TYPE ( wxEVT_CROSSTHREADCALL )
DEFINE_EVENT_TYPE ( wxEVT_CROSSTHREADCALL )
DEFINE_EVENT_TYPE ( wxEVT_REPLY1 )
DEFINE_EVENT_TYPE ( wxEVT_REPLY1 )
DEFINE_EVENT_TYPE ( wxEVT_REPLY2 )
DEFINE_EVENT_TYPE ( wxEVT_REPLY2 )
@ -16,22 +23,21 @@ DEFINE_EVENT_TYPE(wxEVT_TABLEUPDATED)
DEFINE_EVENT_TYPE ( wxEVT_TABLEDELETED )
DEFINE_EVENT_TYPE ( wxEVT_TABLEDELETED )
CMainFrame * pframeMain = NULL ;
CMainFrame * pframeMain = NULL ;
CMyTaskBarIcon * ptaskbaricon = NULL ;
map < string , string > mapAddressBook ;
map < string , string > mapAddressBook ;
CBitcoinTBIcon * taskBarIcon = NULL ; // Tray icon
map < string , string > mapArgs ;
void ThreadRequestProductDetails ( void * parg ) ;
void ThreadRandSendTest ( void * parg ) ;
bool fRandSendTest = false ;
bool fRandSendTest = false ;
void RandSend ( ) ;
void RandSend ( ) ;
extern int g_isPainting ;
extern int g_isPainting ;
// UI settings and their default values
// Settings
int minimizeToTray = 1 ;
int fShowGenerated = true ;
int closeToTray = 1 ;
int fMinimizeToTray = true ;
int startOnSysBoot = 1 ;
int fMinimizeOnClose = true ;
int askBeforeClosing = 1 ;
int alwaysShowTrayIcon = 1 ;
@ -282,7 +288,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
m_staticTextBalance - > SetLabel ( FormatMoney ( GetBalance ( ) ) + " " ) ;
m_staticTextBalance - > SetLabel ( FormatMoney ( GetBalance ( ) ) + " " ) ;
m_listCtrl - > SetFocus ( ) ;
m_listCtrl - > SetFocus ( ) ;
SetIcon ( wxICON ( bitcoin ) ) ;
SetIcon ( wxICON ( bitcoin ) ) ;
m_menuOptions - > Check ( wxID_OPTIONSGENERATEBITCOINS , fGenerateBitcoins ) ;
ptaskbaricon = new CMyTaskBarIcon ( ) ;
// Init toolbar with transparency masked bitmaps
// Init toolbar with transparency masked bitmaps
m_toolBar - > ClearTools ( ) ;
m_toolBar - > ClearTools ( ) ;
@ -327,7 +333,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
//m_listCtrlOrdersReceived->InsertColumn(4, "", wxLIST_FORMAT_LEFT, 100);
//m_listCtrlOrdersReceived->InsertColumn(4, "", wxLIST_FORMAT_LEFT, 100);
// Init status bar
// Init status bar
int pnWidths [ 3 ] = { - 100 , 81 , 286 } ;
int pnWidths [ 3 ] = { - 100 , 88 , 290 } ;
m_statusBar - > SetFieldsCount ( 3 , pnWidths ) ;
m_statusBar - > SetFieldsCount ( 3 , pnWidths ) ;
// Fill your address text box
// Fill your address text box
@ -342,6 +348,8 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
CMainFrame : : ~ CMainFrame ( )
CMainFrame : : ~ CMainFrame ( )
{
{
pframeMain = NULL ;
pframeMain = NULL ;
delete ptaskbaricon ;
ptaskbaricon = NULL ;
}
}
void Shutdown ( void * parg )
void Shutdown ( void * parg )
@ -362,28 +370,24 @@ void Shutdown(void* parg)
void CMainFrame : : OnClose ( wxCloseEvent & event )
void CMainFrame : : OnClose ( wxCloseEvent & event )
{
{
if ( closeToTray & & event . CanVeto ( ) ) {
if ( fMinimizeToTray & & fMinimizeOnClose & & event . CanVeto ( ) & & ! IsIconized ( ) )
event . Veto ( ) ;
{
SendToTray ( ) ;
// Divert close to minimize
}
event . Veto ( ) ;
else if ( ! event . CanVeto ( ) | | ! askBeforeClosing | | wxMessageBox ( " Quit program? " , " Confirm " , wxYES_NO , this ) = = wxYES ) {
Iconize ( true ) ;
delete taskBarIcon ;
}
Destroy ( ) ;
else
_beginthread ( Shutdown , 0 , NULL ) ;
{
}
Destroy ( ) ;
_beginthread ( Shutdown , 0 , NULL ) ;
}
}
}
void CMainFrame : : OnIconize ( wxIconizeEvent & event )
void CMainFrame : : OnIconize ( wxIconizeEvent & event )
{
{
if ( minimizeToTray ) {
// Hide the task bar button when minimized.
SendToTray ( ) ;
// Event is sent when the frame is minimized or restored.
}
Show ( ! fMinimizeToTray | | ! event . Iconized ( ) ) ;
}
void CMainFrame : : SendToTray ( )
{
Hide ( ) ;
taskBarIcon - > Show ( ) ;
}
}
void CMainFrame : : OnMouseEvents ( wxMouseEvent & event )
void CMainFrame : : OnMouseEvents ( wxMouseEvent & event )
@ -405,25 +409,21 @@ void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSo
string str0 = strSort ;
string str0 = strSort ;
long nData = * ( long * ) & hashKey ;
long nData = * ( long * ) & hashKey ;
if ( fNew )
// Find item
if ( ! fNew & & nIndex = = - 1 )
{
while ( ( nIndex = m_listCtrl - > FindItem ( nIndex , nData ) ) ! = - 1 )
if ( GetItemText ( m_listCtrl , nIndex , 1 ) = = hashKey . ToString ( ) )
break ;
}
// fNew is for blind insert, only use if you're sure it's new
if ( fNew | | nIndex = = - 1 )
{
{
nIndex = m_listCtrl - > InsertItem ( 0 , str0 ) ;
nIndex = m_listCtrl - > InsertItem ( 0 , str0 ) ;
}
}
else
else
{
{
if ( nIndex = = - 1 )
{
// Find item
while ( ( nIndex = m_listCtrl - > FindItem ( nIndex , nData ) ) ! = - 1 )
if ( GetItemText ( m_listCtrl , nIndex , 1 ) = = hashKey . ToString ( ) )
break ;
if ( nIndex = = - 1 )
{
printf ( " CMainFrame::InsertLine : Couldn't find item to be updated \n " ) ;
return ;
}
}
// If sort key changed, must delete and reinsert to make it relocate
// If sort key changed, must delete and reinsert to make it relocate
if ( GetItemText ( m_listCtrl , nIndex , 0 ) ! = str0 )
if ( GetItemText ( m_listCtrl , nIndex , 0 ) ! = str0 )
{
{
@ -484,6 +484,28 @@ void CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
string strStatus = FormatTxStatus ( wtx ) ;
string strStatus = FormatTxStatus ( wtx ) ;
map < string , string > mapValue = wtx . mapValue ;
map < string , string > mapValue = wtx . mapValue ;
// Filter
if ( wtx . IsCoinBase ( ) )
{
// View->Show Generated
if ( ! fShowGenerated )
return ;
// Don't show generated coin until confirmed by at least one block after it
// so we don't get the user's hopes up until it looks like it's probably accepted.
//
// It is not an error when generated blocks are not accepted. By design,
// some percentage of blocks, like 10% or more, will end up not accepted.
// This is the normal mechanism by which the network copes with latency.
//
// We display regular transactions right away before any confirmation
// because they can always get into some block eventually. Generated coins
// are special because if their block is not accepted, they are not valid.
//
if ( wtx . GetDepthInMainChain ( ) < 2 )
return ;
}
// Find the block the tx is in
// Find the block the tx is in
CBlockIndex * pindex = NULL ;
CBlockIndex * pindex = NULL ;
map < uint256 , CBlockIndex * > : : iterator mi = mapBlockIndex . find ( wtx . hashBlock ) ;
map < uint256 , CBlockIndex * > : : iterator mi = mapBlockIndex . find ( wtx . hashBlock ) ;
@ -785,16 +807,11 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
{
{
TRY_CRITICAL_BLOCK ( cs_mapWallet )
TRY_CRITICAL_BLOCK ( cs_mapWallet )
{
{
pair < uint256 , bool > item ;
foreach ( uint256 hash , vWalletUpdated )
foreach ( item , vWalletUpdated )
{
{
bool fNew = item . second ;
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( hash ) ;
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( item . first ) ;
if ( mi ! = mapWallet . end ( ) )
if ( mi ! = mapWallet . end ( ) )
{
InsertTransaction ( ( * mi ) . second , false ) ;
printf ( " vWalletUpdated: %s %s \n " , ( * mi ) . second . GetHash ( ) . ToString ( ) . substr ( 0 , 6 ) . c_str ( ) , fNew ? " new " : " " ) ;
InsertTransaction ( ( * mi ) . second , fNew ) ;
}
}
}
m_listCtrl - > ScrollList ( 0 , INT_MAX ) ;
m_listCtrl - > ScrollList ( 0 , INT_MAX ) ;
vWalletUpdated . clear ( ) ;
vWalletUpdated . clear ( ) ;
@ -807,7 +824,7 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
// Update status bar
// Update status bar
string strGen = " " ;
string strGen = " " ;
if ( fGenerateBitcoins )
if ( fGenerateBitcoins )
strGen = " Generating " ;
strGen = " Generating " ;
if ( fGenerateBitcoins & & vNodes . empty ( ) )
if ( fGenerateBitcoins & & vNodes . empty ( ) )
strGen = " (not connected) " ;
strGen = " (not connected) " ;
m_statusBar - > SetStatusText ( strGen , 1 ) ;
m_statusBar - > SetStatusText ( strGen , 1 ) ;
@ -856,39 +873,54 @@ void CMainFrame::OnCrossThreadCall(wxCommandEvent& event)
void CMainFrame : : OnMenuFileExit ( wxCommandEvent & event )
void CMainFrame : : OnMenuFileExit ( wxCommandEvent & event )
{
{
// File->Exit
Close ( true ) ;
Close ( true ) ;
}
}
void CMainFrame : : OnMenuViewShowGenerated ( wxCommandEvent & event )
{
// View->Show Generated
fShowGenerated = event . IsChecked ( ) ;
CWalletDB ( ) . WriteSetting ( " fShowGenerated " , fShowGenerated ) ;
RefreshListCtrl ( ) ;
}
void CMainFrame : : OnUpdateUIViewShowGenerated ( wxUpdateUIEvent & event )
{
event . Check ( fShowGenerated ) ;
}
void CMainFrame : : OnMenuOptionsGenerate ( wxCommandEvent & event )
void CMainFrame : : OnMenuOptionsGenerate ( wxCommandEvent & event )
{
{
// Options->Generate Coins
GenerateBitcoins ( event . IsChecked ( ) ) ;
GenerateBitcoins ( event . IsChecked ( ) ) ;
}
Refresh ( ) ;
void CMainFrame : : OnUpdateUIOptionsGenerate ( wxUpdateUIEvent & event )
wxPaintEvent eventPaint ;
{
AddPendingEvent ( eventPaint ) ;
event . Check ( fGenerateBitcoins ) ;
}
}
void CMainFrame : : OnMenuOptionsChangeYourAddress ( wxCommandEvent & event )
void CMainFrame : : OnMenuOptionsChangeYourAddress ( wxCommandEvent & event )
{
{
// Options->Change Your Address
OnButtonChange ( event ) ;
OnButtonChange ( event ) ;
}
}
void CMainFrame : : OnMenuOptionsOptions ( wxCommandEvent & event )
void CMainFrame : : OnMenuOptionsOptions ( wxCommandEvent & event )
{
{
// Options->Options
COptionsDialog dialog ( this ) ;
COptionsDialog dialog ( this ) ;
dialog . ShowModal ( ) ;
dialog . ShowModal ( ) ;
}
}
void CMainFrame : : OnMenuHelpAbout ( wxCommandEvent & event )
void CMainFrame : : OnMenuHelpAbout ( wxCommandEvent & event )
{
{
// Help->About
CAboutDialog dialog ( this ) ;
CAboutDialog dialog ( this ) ;
dialog . ShowModal ( ) ;
dialog . ShowModal ( ) ;
}
}
void CMainFrame : : OnUpdateMenuGenerate ( wxUpdateUIEvent & event ) {
event . Check ( fGenerateBitcoins ) ;
}
void CMainFrame : : OnButtonSend ( wxCommandEvent & event )
void CMainFrame : : OnButtonSend ( wxCommandEvent & event )
{
{
/// debug test
/// debug test
@ -1252,58 +1284,74 @@ void CTxDetailsDialog::OnButtonOK(wxCommandEvent& event)
COptionsDialog : : COptionsDialog ( wxWindow * parent ) : COptionsDialogBase ( parent )
COptionsDialog : : COptionsDialog ( wxWindow * parent ) : COptionsDialogBase ( parent )
{
{
// Set up list box of page choices
m_listBox - > Append ( " Main " ) ;
//m_listBox->Append("Test 2");
m_listBox - > SetSelection ( 0 ) ;
SelectPage ( 0 ) ;
// Init values
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTransactionFee ) ) ;
m_checkBoxLimitProcessors - > SetValue ( fLimitProcessors ) ;
m_spinCtrlLimitProcessors - > Enable ( fLimitProcessors ) ;
m_spinCtrlLimitProcessors - > SetValue ( nLimitProcessors ) ;
int nProcessors = atoi ( getenv ( " NUMBER_OF_PROCESSORS " ) ) ;
if ( nProcessors < 1 )
nProcessors = 999 ;
m_spinCtrlLimitProcessors - > SetRange ( 1 , nProcessors ) ;
m_checkBoxStartOnSystemStartup - > SetValue ( fTmpStartOnSystemStartup = GetStartOnSystemStartup ( ) ) ;
m_checkBoxMinimizeToTray - > SetValue ( fMinimizeToTray ) ;
m_checkBoxMinimizeOnClose - > Enable ( fMinimizeToTray ) ;
m_checkBoxMinimizeOnClose - > SetValue ( fMinimizeToTray & & fMinimizeOnClose ) ;
fTmpMinimizeOnClose = fMinimizeOnClose ;
m_buttonOK - > SetFocus ( ) ;
m_buttonOK - > SetFocus ( ) ;
m_treeCtrl - > AddRoot ( wxT ( " Settings " ) ) ;
}
m_treeCtrl - > AppendItem ( m_treeCtrl - > GetRootItem ( ) , wxT ( " Bitcoin " ) ) ;
m_treeCtrl - > AppendItem ( m_treeCtrl - > GetRootItem ( ) , wxT ( " UI " ) ) ;
panelUI = new COptionsPanelUI ( this ) ;
void COptionsDialog : : SelectPage ( int nPage )
panelBitcoin = new COptionsPanelBitcoin ( this ) ;
{
currentPanel = panelBitcoin ;
m_panelMain - > Show ( nPage = = 0 ) ;
m_panelTest2 - > Show ( nPage = = 1 ) ;
panelSizer - > Add ( panelUI ) ;
m_scrolledWindow - > Layout ( ) ;
panelSizer - > Hide ( panelUI ) ;
m_scrolledWindow - > SetScrollbars ( 0 , 0 , 0 , 0 , 0 , 0 ) ;
panelSizer - > Add ( panelBitcoin ) ;
}
panelSizer - > Layout ( ) ;
void COptionsDialog : : OnListBox ( wxCommandEvent & event )
{
SelectPage ( event . GetSelection ( ) ) ;
}
}
void COptionsDialog : : MenuSelChanged ( wxTreeEvent & event )
void COptionsDialog : : OnKillFocusTransactionFee ( wxFocus Event& event )
{
{
panelSizer - > Hide ( currentPanel ) ;
int64 nTmp = nTransactionFee ;
wxString text = m_treeCtrl - > GetItemText ( event . GetItem ( ) ) ;
ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTmp ) ;
if ( text = = " Bitcoin " ) {
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTmp ) ) ;
panelSizer - > Show ( panelBitcoin ) ;
currentPanel = panelBitcoin ;
}
else {
panelSizer - > Show ( panelUI ) ;
currentPanel = panelUI ;
}
panelSizer - > Layout ( ) ;
}
}
void COptionsDialog : : OnButtonOK ( wxCommandEvent & event )
void COptionsDialog : : OnCheckBoxLimitProcessors ( wxCommandEvent & event )
{
{
// nTransactionFee
m_spinCtrlLimitProcessors - > Enable ( event . IsChecked ( ) ) ;
int64 nPrevTransactionFee = nTransactionFee ;
}
if ( ParseMoney ( panelBitcoin - > m_textCtrlTransactionFee - > GetValue ( ) , nTransactionFee ) & & nTransactionFee ! = nPrevTransactionFee )
CWalletDB ( ) . WriteSetting ( " transactionFee " , nTransactionFee ) ;
minimizeToTray = panelUI - > m_checkMinToTray - > IsChecked ( ) ;
void COptionsDialog : : OnCheckBoxMinimizeToTray ( wxCommandEvent & event )
closeToTray = panelUI - > m_checkCloseToTray - > IsChecked ( ) ;
{
startOnSysBoot = panelUI - > m_checkStartOnSysBoot - > IsChecked ( ) ;
m_checkBoxMinimizeOnClose - > Enable ( event . IsChecked ( ) ) ;
askBeforeClosing = panelUI - > m_checkAskBeforeClosing - > IsChecked ( ) ;
alwaysShowTrayIcon = panelUI - > m_checkAlwaysShowTray - > IsChecked ( ) ;
CWalletDB ( ) . WriteSetting ( " minimizeToTray " , minimizeToTray ) ;
// Save the value in fTmpMinimizeOnClose so we can
CWalletDB ( ) . WriteSetting ( " closeToTray " , closeToTray ) ;
// show the checkbox unchecked when its parent is unchecked
CWalletDB ( ) . WriteSetting ( " startOnSysBoot " , startOnSysBoot ) ;
if ( event . IsChecked ( ) )
CWalletDB ( ) . WriteSetting ( " askBeforeClosing " , askBeforeClosing ) ;
m_checkBoxMinimizeOnClose - > SetValue ( fTmpMinimizeOnClose ) ;
CWalletDB ( ) . WriteSetting ( " alwaysShowTrayIcon " , alwaysShowTrayIcon ) ;
else
{
fTmpMinimizeOnClose = m_checkBoxMinimizeOnClose - > GetValue ( ) ;
m_checkBoxMinimizeOnClose - > SetValue ( false ) ;
}
ApplyUISettings ( ) ;
}
void COptionsDialog : : OnButtonOK ( wxCommandEvent & event )
{
OnButtonApply ( event ) ;
Close ( ) ;
Close ( ) ;
}
}
@ -1312,44 +1360,53 @@ void COptionsDialog::OnButtonCancel(wxCommandEvent& event)
Close ( ) ;
Close ( ) ;
}
}
void COptionsDialog : : OnButtonApply ( wxCommandEvent & event )
//////////////////////////////////////////////////////////////////////////////
//
// COptionsPanelBitcoin
//
COptionsPanelBitcoin : : COptionsPanelBitcoin ( wxWindow * parent ) : COptionsPanelBitcoinBase ( parent )
{
{
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTransactionFee ) ) ;
CWalletDB walletdb ;
}
void COptionsPanelBitcoin : : OnKillFocusTransactionFee ( wxFocusEvent & event )
int64 nPrevTransactionFee = nTransactionFee ;
{
if ( ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTransactionFee ) & & nTransactionFee ! = nPrevTransactionFee )
int64 nTmp = nTransactionFee ;
walletdb . WriteSetting ( " nTransactionFee " , nTransactionFee ) ;
ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTmp ) ;
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTmp ) ) ;
}
int nPrevMaxProc = ( fLimitProcessors ? nLimitProcessors : INT_MAX ) ;
if ( fLimitProcessors ! = m_checkBoxLimitProcessors - > GetValue ( ) )
{
fLimitProcessors = m_checkBoxLimitProcessors - > GetValue ( ) ;
walletdb . WriteSetting ( " fLimitProcessors " , fLimitProcessors ) ;
}
if ( nLimitProcessors ! = m_spinCtrlLimitProcessors - > GetValue ( ) )
{
nLimitProcessors = m_spinCtrlLimitProcessors - > GetValue ( ) ;
walletdb . WriteSetting ( " nLimitProcessors " , nLimitProcessors ) ;
}
if ( fGenerateBitcoins & & ( fLimitProcessors ? nLimitProcessors : INT_MAX ) > nPrevMaxProc )
GenerateBitcoins ( fGenerateBitcoins ) ;
//////////////////////////////////////////////////////////////////////////////
if ( fTmpStartOnSystemStartup ! = m_checkBoxStartOnSystemStartup - > GetValue ( ) )
//
{
// COptionsPanelUI
fTmpStartOnSystemStartup = m_checkBoxStartOnSystemStartup - > GetValue ( ) ;
//
SetStartOnSystemStartup ( fTmpStartOnSystemStartup ) ;
}
COptionsPanelUI : : COptionsPanelUI ( wxWindow * parent ) : COptionsPanelUIBase ( parent )
if ( fMinimizeToTray ! = m_checkBoxMinimizeToTray - > GetValue ( ) )
{
{
m_checkMinToTray - > SetValue ( minimizeToTray ) ;
fMinimizeToTray = m_checkBoxMinimizeToTray - > GetValue ( ) ;
m_checkCloseToTray - > SetValue ( closeToTray ) ;
walletdb . WriteSetting ( " fMinimizeToTray " , fMinimizeToTray ) ;
m_checkStartOnSysBoot - > SetValue ( startOnSysBoot ) ;
ptaskbaricon - > Show ( fMinimizeToTray ) ;
m_checkAskBeforeClosing - > SetValue ( askBeforeClosing ) ;
}
m_checkAlwaysShowTray - > SetValue ( alwaysShowTrayIcon ) ;
if ( fMinimizeOnClose ! = ( fMinimizeToTray ? m_checkBoxMinimizeOnClose - > GetValue ( ) : fTmpMinimizeOnClose ) )
{
fMinimizeOnClose = ( fMinimizeToTray ? m_checkBoxMinimizeOnClose - > GetValue ( ) : fTmpMinimizeOnClose ) ;
walletdb . WriteSetting ( " fMinimizeOnClose " , fMinimizeOnClose ) ;
}
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// CAboutDialog
// CAboutDialog
@ -1387,6 +1444,7 @@ CSendDialog::CSendDialog(wxWindow* parent, const wxString& strAddress) : CSendDi
m_textCtrlAddress - > SetValue ( strAddress ) ;
m_textCtrlAddress - > SetValue ( strAddress ) ;
m_choiceTransferType - > SetSelection ( 0 ) ;
m_choiceTransferType - > SetSelection ( 0 ) ;
m_bitmapCheckMark - > Show ( false ) ;
m_bitmapCheckMark - > Show ( false ) ;
fEnabledPrev = true ;
//// todo: should add a display of your balance for convenience
//// todo: should add a display of your balance for convenience
// Set Icon
// Set Icon
@ -1418,6 +1476,19 @@ void CSendDialog::OnTextAddress(wxCommandEvent& event)
m_staticTextMessage - > Enable ( fEnable ) ;
m_staticTextMessage - > Enable ( fEnable ) ;
m_textCtrlMessage - > Enable ( fEnable ) ;
m_textCtrlMessage - > Enable ( fEnable ) ;
m_textCtrlMessage - > SetBackgroundColour ( wxSystemSettings : : GetColour ( fEnable ? wxSYS_COLOUR_WINDOW : wxSYS_COLOUR_BTNFACE ) ) ;
m_textCtrlMessage - > SetBackgroundColour ( wxSystemSettings : : GetColour ( fEnable ? wxSYS_COLOUR_WINDOW : wxSYS_COLOUR_BTNFACE ) ) ;
if ( ! fEnable & & fEnabledPrev )
{
strFromSave = m_textCtrlFrom - > GetValue ( ) ;
strMessageSave = m_textCtrlMessage - > GetValue ( ) ;
m_textCtrlFrom - > SetValue ( " Will appear as \" From: Unknown \" " ) ;
m_textCtrlMessage - > SetValue ( " Can't include a message when sending to a Bitcoin address " ) ;
}
else if ( fEnable & & ! fEnabledPrev )
{
m_textCtrlFrom - > SetValue ( strFromSave ) ;
m_textCtrlMessage - > SetValue ( strMessageSave ) ;
}
fEnabledPrev = fEnable ;
}
}
void CSendDialog : : OnKillFocusAmount ( wxFocusEvent & event )
void CSendDialog : : OnKillFocusAmount ( wxFocusEvent & event )
@ -1773,8 +1844,9 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
Error ( " You don't have enough money " ) ;
Error ( " You don't have enough money " ) ;
return ;
return ;
}
}
CKey key ;
int64 nFeeRequired ;
int64 nFeeRequired ;
if ( ! CreateTransaction ( scriptPubKey , nPrice , wtx , nFeeRequired ) )
if ( ! CreateTransaction ( scriptPubKey , nPrice , wtx , key , nFeeRequired ) )
{
{
if ( nPrice + nFeeRequired > GetBalance ( ) )
if ( nPrice + nFeeRequired > GetBalance ( ) )
Error ( strprintf ( " This is an oversized transaction that requires a transaction fee of %s " , FormatMoney ( nFeeRequired ) . c_str ( ) ) ) ;
Error ( strprintf ( " This is an oversized transaction that requires a transaction fee of %s " , FormatMoney ( nFeeRequired ) . c_str ( ) ) ) ;
@ -1799,7 +1871,7 @@ void CSendingDialog::OnReply2(CDataStream& vRecv)
return ;
return ;
// Commit
// Commit
if ( ! CommitTransactionSpent ( wtx ) )
if ( ! CommitTransactionSpent ( wtx , key ) )
{
{
Error ( " Error finalizing payment " ) ;
Error ( " Error finalizing payment " ) ;
return ;
return ;
@ -2950,84 +3022,112 @@ void CEditReviewDialog::GetReview(CReview& review)
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// BitcoinTB Icon
// CMyTaskBar Icon
//
//
enum {
enum
PU_RESTORE = 10001 ,
{
PU_GENERATE ,
ID_TASKBAR_RESTORE = 10001 ,
PU_EXIT ,
ID_TASKBAR_GENERATE ,
ID_TASKBAR_EXIT ,
} ;
} ;
BEGIN_EVENT_TABLE ( CBitcoinTBIcon , wxTaskBarIcon )
BEGIN_EVENT_TABLE ( CMyTaskBarIcon , wxTaskBarIcon )
EVT_TASKBAR_LEFT_DCLICK ( CBitcoinTBIcon : : OnLeftButtonDClick )
EVT_TASKBAR_LEFT_DCLICK ( CMyTaskBarIcon : : OnLeftButtonDClick )
EVT_MENU ( PU_RESTORE , CBitcoinTBIcon : : OnMenuRestore )
EVT_MENU ( ID_TASKBAR_RESTORE , CMyTaskBarIcon : : OnMenuRestore )
EVT_MENU ( PU_GENERATE , CBitcoinTBIcon : : OnMenuGenerate )
EVT_MENU ( ID_TASKBAR_GENERATE , CMyTaskBarIcon : : OnMenuGenerate )
EVT_MENU ( PU_EXIT , CBitcoinTBIcon : : OnMenuExit )
EVT_UPDATE_UI ( ID_TASKBAR_GENERATE , CMyTaskBarIcon : : OnUpdateUIGenerate )
EVT_MENU ( ID_TASKBAR_EXIT , CMyTaskBarIcon : : OnMenuExit )
END_EVENT_TABLE ( )
END_EVENT_TABLE ( )
void CBitcoinTB Icon : : Show ( )
void CMyTaskBar Icon : : Show ( bool fShow )
{
{
string tooltip = " Bitcoin " ;
if ( fShow )
tooltip + = fGenerateBitcoins ? " - Generating " : " " ;
{
SetIcon ( wxICON ( bitcoin ) , tooltip ) ;
string strTooltip = " Bitcoin " ;
if ( fGenerateBitcoins )
strTooltip = " Bitcoin - Generating " ;
if ( fGenerateBitcoins & & vNodes . empty ( ) )
strTooltip = " Bitcoin - (not connected) " ;
SetIcon ( wxICON ( bitcoin ) , strTooltip ) ;
}
else
{
RemoveIcon ( ) ;
}
}
}
void CBitcoinTBIcon : : Hide ( )
void CMyTaskBar Icon : : Hide ( )
{
{
RemoveIcon ( ) ;
Show ( false ) ;
}
}
void CBitcoinTBIcon : : OnLeftButtonDClick ( wxTaskBarIconEvent & )
void CMyTaskBar Icon : : OnLeftButtonDClick ( wxTaskBarIconEvent & event )
{
{
Restore ( ) ;
Restore ( ) ;
}
}
void CBitcoinTBIcon : : OnMenuExit ( wxCommandEvent & )
void CMyTaskBarIcon : : OnMenuRestore ( wxCommandEvent & event )
{
{
pframeMain - > Close ( true ) ;
Restore ( ) ;
}
}
void CBitcoinTBIcon : : OnMenuGenerate ( wxCommandEvent & event )
void CMyTaskBarIcon : : Restore ( )
{
{
GenerateBitcoins ( event . IsChecked ( ) ) ;
pframeMain - > Refresh ( ) ;
}
void CBitcoinTBIcon : : OnMenuRestore ( wxCommandEvent & ) {
Restore ( ) ;
}
void CBitcoinTBIcon : : Restore ( ) {
pframeMain - > Show ( ) ;
pframeMain - > Show ( ) ;
pframeMain - > Iconize ( false ) ;
pframeMain - > Iconize ( false ) ;
pframeMain - > Raise ( ) ;
pframeMain - > Raise ( ) ;
if ( ! alwaysShowTrayIcon )
Hide ( ) ;
}
}
void CBitcoinTBIcon : : UpdateTooltip ( ) {
void CMyTaskBarIcon : : OnMenuGenerate ( wxCommandEvent & event )
if ( IsIconInstalled ( ) )
{
Show ( ) ;
GenerateBitcoins ( event . IsChecked ( ) ) ;
}
void CMyTaskBarIcon : : OnUpdateUIGenerate ( wxUpdateUIEvent & event )
{
event . Check ( fGenerateBitcoins ) ;
}
}
wxMenu * CBitcoinTBIcon : : CreatePopupMenu ( )
void CMyTaskBarIcon : : OnMenuExit ( wxCommandEvent & event )
{
{
wxMenu * menu = new wxMenu ;
pframeMain - > Close ( true ) ;
menu - > Append ( PU_RESTORE , _T ( " Open Bitcoin " ) ) ;
}
wxMenuItem * generateCheck = menu - > AppendCheckItem ( PU_GENERATE , _T ( " Generate Coins " ) ) ;
menu - > InsertSeparator ( 2 ) ;
menu - > Append ( PU_EXIT , _T ( " Exit " ) ) ;
generateCheck - > Check ( fGenerateBitcoins ) ;
void CMyTaskBarIcon : : UpdateTooltip ( )
{
if ( IsIconInstalled ( ) )
Show ( true ) ;
}
return menu ;
wxMenu * CMyTaskBarIcon : : CreatePopupMenu ( )
{
wxMenu * pmenu = new wxMenu ;
pmenu - > Append ( ID_TASKBAR_RESTORE , " &Open Bitcoin " ) ;
pmenu - > AppendCheckItem ( ID_TASKBAR_GENERATE , " &Generate Coins " ) - > Check ( fGenerateBitcoins ) ;
# ifndef __WXMAC_OSX__ // Mac has built-in quit menu
pmenu - > AppendSeparator ( ) ;
pmenu - > Append ( ID_TASKBAR_EXIT , " E&xit " ) ;
# endif
return pmenu ;
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
//
// CMyApp
// CMyApp
@ -3150,7 +3250,7 @@ bool CMyApp::OnInit2()
// Parameters
// Parameters
//
//
wxImage : : AddHandler ( new wxPNGHandler ) ;
wxImage : : AddHandler ( new wxPNGHandler ) ;
map < string , string > map Args = ParseParameters ( argc , argv ) ;
mapArgs = ParseParameters ( argc , argv ) ;
if ( mapArgs . count ( " /datadir " ) )
if ( mapArgs . count ( " /datadir " ) )
strSetDataDir = mapArgs [ " /datadir " ] ;
strSetDataDir = mapArgs [ " /datadir " ] ;
@ -3179,6 +3279,7 @@ bool CMyApp::OnInit2()
//
//
// Load data files
// Load data files
//
//
bool fFirstRun ;
string strErrors ;
string strErrors ;
int64 nStart , nEnd ;
int64 nStart , nEnd ;
@ -3198,7 +3299,7 @@ bool CMyApp::OnInit2()
printf ( " Loading wallet... \n " ) ;
printf ( " Loading wallet... \n " ) ;
QueryPerformanceCounter ( ( LARGE_INTEGER * ) & nStart ) ;
QueryPerformanceCounter ( ( LARGE_INTEGER * ) & nStart ) ;
if ( ! LoadWallet ( ) )
if ( ! LoadWallet ( fFirstRun ) )
strErrors + = " Error loading wallet.dat \n " ;
strErrors + = " Error loading wallet.dat \n " ;
QueryPerformanceCounter ( ( LARGE_INTEGER * ) & nEnd ) ;
QueryPerformanceCounter ( ( LARGE_INTEGER * ) & nEnd ) ;
printf ( " wallet %20I64d \n " , nEnd - nStart ) ;
printf ( " wallet %20I64d \n " , nEnd - nStart ) ;
@ -3244,62 +3345,60 @@ bool CMyApp::OnInit2()
//
//
// Create the main frame window
// Create the main frame window
//
//
pframeMain = new CMainFrame ( NULL ) ;
if ( mapArgs . count ( " /min " ) )
pframeMain - > Iconize ( true ) ;
pframeMain - > Show ( true ) ; // have to show first to get taskbar button to hide
pframeMain - > Show ( ! fMinimizeToTray | | ! pframeMain - > IsIconized ( ) ) ;
ptaskbaricon - > Show ( fMinimizeToTray ) ;
if ( ! CheckDiskSpace ( ) )
{
{
pframeMain = new CMainFrame ( NULL ) ;
OnExit ( ) ;
pframeMain - > Show ( ) ;
return false ;
}
if ( ! CheckDiskSpace ( ) )
if ( ! StartNode ( strErrors ) )
{
wxMessageBox ( strErrors , " Bitcoin " ) ;
OnExit ( ) ;
return false ;
}
if ( ! StartNode ( strErrors ) )
GenerateBitcoins ( fGenerateBitcoins ) ;
wxMessageBox ( strErrors , " Bitcoin " ) ;
if ( fGenerateBitcoins )
if ( fFirstRun )
if ( _beginthread ( ThreadBitcoinMiner , 0 , NULL ) = = - 1 )
SetStartOnSystemStartup ( true ) ;
printf ( " Error: _beginthread(ThreadBitcoinMiner) failed \n " ) ;
//
// Tests
//
if ( argc > = 2 & & stricmp ( argv [ 1 ] , " /send " ) = = 0 )
{
int64 nValue = 1 ;
if ( argc > = 3 )
ParseMoney ( argv [ 2 ] , nValue ) ;
string strAddress ;
if ( argc > = 4 )
strAddress = argv [ 3 ] ;
CAddress addr ( strAddress . c_str ( ) ) ;
CWalletTx wtx ;
wtx . mapValue [ " to " ] = strAddress ;
wtx . mapValue [ " from " ] = addrLocalHost . ToString ( ) ;
wtx . mapValue [ " message " ] = " command line send " ;
// Send to IP address
CSendingDialog * pdialog = new CSendingDialog ( pframeMain , addr , nValue , wtx ) ;
if ( ! pdialog - > ShowModal ( ) )
return false ;
}
if ( mapArgs . count ( " /randsendtest " ) )
//
{
// Tests
if ( ! mapArgs [ " /randsendtest " ] . empty ( ) )
//
_beginthread ( ThreadRandSendTest , 0 , new string ( mapArgs [ " /randsendtest " ] ) ) ;
if ( argc > = 2 & & stricmp ( argv [ 1 ] , " /send " ) = = 0 )
else
{
fRandSendTest = true ;
int64 nValue = 1 ;
fDebug = true ;
if ( argc > = 3 )
}
ParseMoney ( argv [ 2 ] , nValue ) ;
string strAddress ;
if ( argc > = 4 )
strAddress = argv [ 3 ] ;
CAddress addr ( strAddress . c_str ( ) ) ;
CWalletTx wtx ;
wtx . mapValue [ " to " ] = strAddress ;
wtx . mapValue [ " from " ] = addrLocalHost . ToString ( ) ;
wtx . mapValue [ " message " ] = " command line send " ;
// Send to IP address
CSendingDialog * pdialog = new CSendingDialog ( pframeMain , addr , nValue , wtx ) ;
if ( ! pdialog - > ShowModal ( ) )
return false ;
}
}
taskBarIcon = new CBitcoinTBIcon ( ) ;
if ( mapArgs . count ( " /randsendtest " ) )
ApplyUISettings ( ) ;
{
if ( mapArgs . count ( " /min " ) & & minimizeToTray ) {
if ( ! mapArgs [ " /randsendtest " ] . empty ( ) )
pframeMain - > Iconize ( true ) ;
_beginthread ( ThreadRandSendTest , 0 , new string ( mapArgs [ " /randsendtest " ] ) ) ;
else
fRandSendTest = true ;
fDebug = true ;
}
}
return true ;
return true ;
@ -3320,14 +3419,14 @@ bool CMyApp::OnExceptionInMainLoop()
catch ( std : : exception & e )
catch ( std : : exception & e )
{
{
PrintException ( & e , " CMyApp::OnExceptionInMainLoop() " ) ;
PrintException ( & e , " CMyApp::OnExceptionInMainLoop() " ) ;
wxLogWarning ( _T ( " Exception %s %s " ) , typeid ( e ) . name ( ) , e . what ( ) ) ;
wxLogWarning ( " Exception %s %s " , typeid ( e ) . name ( ) , e . what ( ) ) ;
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
throw ;
throw ;
}
}
catch ( . . . )
catch ( . . . )
{
{
PrintException ( NULL , " CMyApp::OnExceptionInMainLoop() " ) ;
PrintException ( NULL , " CMyApp::OnExceptionInMainLoop() " ) ;
wxLogWarning ( _T ( " Unknown exception " ) ) ;
wxLogWarning ( " Unknown exception " ) ;
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
throw ;
throw ;
}
}
@ -3345,14 +3444,14 @@ void CMyApp::OnUnhandledException()
catch ( std : : exception & e )
catch ( std : : exception & e )
{
{
PrintException ( & e , " CMyApp::OnUnhandledException() " ) ;
PrintException ( & e , " CMyApp::OnUnhandledException() " ) ;
wxLogWarning ( _T ( " Exception %s %s " ) , typeid ( e ) . name ( ) , e . what ( ) ) ;
wxLogWarning ( " Exception %s %s " , typeid ( e ) . name ( ) , e . what ( ) ) ;
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
throw ;
throw ;
}
}
catch ( . . . )
catch ( . . . )
{
{
PrintException ( NULL , " CMyApp::OnUnhandledException() " ) ;
PrintException ( NULL , " CMyApp::OnUnhandledException() " ) ;
wxLogWarning ( _T ( " Unknown exception " ) ) ;
wxLogWarning ( " Unknown exception " ) ;
Sleep ( 1000 ) ;
Sleep ( 1000 ) ;
throw ;
throw ;
}
}
@ -3367,6 +3466,8 @@ void CMyApp::OnFatalException()
void MainFrameRepaint ( )
void MainFrameRepaint ( )
{
{
// This is called by network code that shouldn't access pframeMain and ptaskbaricon
// directly because it could still be running after the UI is closed.
if ( pframeMain )
if ( pframeMain )
{
{
printf ( " MainFrameRepaint() \n " ) ;
printf ( " MainFrameRepaint() \n " ) ;
@ -3374,68 +3475,84 @@ void MainFrameRepaint()
pframeMain - > Refresh ( ) ;
pframeMain - > Refresh ( ) ;
pframeMain - > AddPendingEvent ( event ) ;
pframeMain - > AddPendingEvent ( event ) ;
}
}
if ( ptaskbaricon )
ptaskbaricon - > UpdateTooltip ( ) ;
}
}
string StartupShortcutPath ( )
{
// Get the startup folder shortcut path
char pszLinkPath [ MAX_PATH + 100 ] ;
pszLinkPath [ 0 ] = ' \0 ' ;
SHGetSpecialFolderPath ( 0 , pszLinkPath , CSIDL_STARTUP , 0 ) ;
strcat ( pszLinkPath , " \\ Bitcoin.lnk " ) ;
return pszLinkPath ;
}
bool GetStartOnSystemStartup ( )
{
return FileExists ( StartupShortcutPath ( ) . c_str ( ) ) ;
}
void ApplyUISettings ( ) {
void SetStartOnSystemStartup ( bool fAutoStart )
// Show the tray icon?
{
if ( alwaysShowTrayIcon )
// If the shortcut exists already, remove it for updating
taskBarIcon - > Show ( ) ;
remove ( StartupShortcutPath ( ) . c_str ( ) ) ;
else
taskBarIcon - > Hide ( ) ;
// Autostart on system startup?
if ( fAutoStart )
// Open the startup registry key
{
HKEY hKey ;
CoInitialize ( NULL ) ;
LONG lnRes = RegOpenKeyEx (
HKEY_CURRENT_USER ,
" SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Run " ,
0 ,
KEY_ALL_ACCESS ,
& hKey
) ;
if ( ERROR_SUCCESS = = lnRes )
// Get a pointer to the IShellLink interface.
{
HRESULT hres = NULL ;
if ( startOnSysBoot ) {
IShellLink * psl = NULL ;
// Get the current executable path
hres = CoCreateInstance ( CLSID_ShellLink , NULL ,
char exePath [ MAX_PATH ] ;
CLSCTX_INPROC_SERVER , IID_IShellLink ,
GetModuleFileName ( NULL , exePath , _MAX_PATH + 1 ) ;
reinterpret_cast < void * * > ( & psl ) ) ;
char runCmd [ MAX_PATH + 5 ] ;
strcat ( runCmd , exePath ) ;
strcat ( runCmd , " /min " ) ;
RegSetValueEx ( hKey ,
if ( SUCCEEDED ( hres ) )
" Bitcoin " ,
{
0 ,
// Get the current executable path
REG_SZ ,
char pszExePath [ MAX_PATH ] ;
( BYTE * ) runCmd ,
GetModuleFileName ( NULL , pszExePath , sizeof ( pszExePath ) ) ;
sizeof ( runCmd )
_strlwr ( pszExePath ) ;
) ;
}
// Set the path to the shortcut target
else {
psl - > SetPath ( pszExePath ) ;
RegDeleteValue ( hKey , " Bitcoin " ) ;
PathRemoveFileSpec ( pszExePath ) ;
}
psl - > SetWorkingDirectory ( pszExePath ) ;
}
psl - > SetShowCmd ( SW_SHOWMINNOACTIVE ) ;
RegCloseKey ( hKey ) ;
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
IPersistFile * ppf = NULL ;
hres = psl - > QueryInterface ( IID_IPersistFile ,
reinterpret_cast < void * * > ( & ppf ) ) ;
if ( SUCCEEDED ( hres ) )
{
WCHAR pwsz [ MAX_PATH ] ;
// Ensure that the string is ANSI.
MultiByteToWideChar ( CP_ACP , 0 , StartupShortcutPath ( ) . c_str ( ) , - 1 , pwsz , MAX_PATH ) ;
// Save the link by calling IPersistFile::Save.
hres = ppf - > Save ( pwsz , TRUE ) ;
ppf - > Release ( ) ;
}
psl - > Release ( ) ;
}
CoUninitialize ( ) ;
}
}
}
void GenerateBitcoins ( bool flag )
{
fGenerateBitcoins = flag ;
nTransactionsUpdated + + ;
CWalletDB ( ) . WriteSetting ( " fGenerateBitcoins " , fGenerateBitcoins ) ;
if ( fGenerateBitcoins )
if ( _beginthread ( ThreadBitcoinMiner , 0 , NULL ) = = - 1 )
printf ( " Error: _beginthread(ThreadBitcoinMiner) failed \n " ) ;
taskBarIcon - > UpdateTooltip ( ) ;
}