2010-01-28 13:49:20 -08:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
2009-08-29 20:46:39 -07:00
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
# include "headers.h"
# ifdef _MSC_VER
# include <crtdbg.h>
# endif
2009-10-20 18:08:05 -07:00
2009-11-06 10:53:26 -08:00
DEFINE_EVENT_TYPE ( wxEVT_UITHREADCALL )
2009-08-29 20:46:39 -07:00
CMainFrame * pframeMain = NULL ;
2009-10-20 18:08:05 -07:00
CMyTaskBarIcon * ptaskbaricon = NULL ;
2009-11-12 17:23:08 -08:00
bool fClosedToTray = false ;
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
2010-02-23 14:01:39 -08:00
2009-08-29 20:46:39 -07:00
//////////////////////////////////////////////////////////////////////////////
//
// Util
//
void HandleCtrlA ( wxKeyEvent & event )
{
// Ctrl-a select all
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
wxTextCtrl * textCtrl = ( wxTextCtrl * ) event . GetEventObject ( ) ;
if ( event . GetModifiers ( ) = = wxMOD_CONTROL & & event . GetKeyCode ( ) = = ' A ' )
textCtrl - > SetSelection ( - 1 , - 1 ) ;
}
bool Is24HourTime ( )
{
//char pszHourFormat[256];
//pszHourFormat[0] = '\0';
//GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ITIME, pszHourFormat, 256);
//return (pszHourFormat[0] != '0');
return true ;
}
string DateStr ( int64 nTime )
{
2009-11-05 21:50:05 -08:00
// Can only be used safely here in the UI
2009-08-29 20:46:39 -07:00
return ( string ) wxDateTime ( ( time_t ) nTime ) . FormatDate ( ) ;
}
string DateTimeStr ( int64 nTime )
{
2009-11-05 21:50:05 -08:00
// Can only be used safely here in the UI
2009-08-29 20:46:39 -07:00
wxDateTime datetime ( ( time_t ) nTime ) ;
if ( Is24HourTime ( ) )
return ( string ) datetime . Format ( " %x %H:%M " ) ;
else
return ( string ) datetime . Format ( " %x " ) + itostr ( ( datetime . GetHour ( ) + 11 ) % 12 + 1 ) + ( string ) datetime . Format ( " :%M %p " ) ;
}
wxString GetItemText ( wxListCtrl * listCtrl , int nIndex , int nColumn )
{
// Helper to simplify access to listctrl
wxListItem item ;
item . m_itemId = nIndex ;
item . m_col = nColumn ;
item . m_mask = wxLIST_MASK_TEXT ;
if ( ! listCtrl - > GetItem ( item ) )
return " " ;
return item . GetText ( ) ;
}
int InsertLine ( wxListCtrl * listCtrl , const wxString & str0 , const wxString & str1 )
{
int nIndex = listCtrl - > InsertItem ( listCtrl - > GetItemCount ( ) , str0 ) ;
listCtrl - > SetItem ( nIndex , 1 , str1 ) ;
return nIndex ;
}
int InsertLine ( wxListCtrl * listCtrl , const wxString & str0 , const wxString & str1 , const wxString & str2 , const wxString & str3 , const wxString & str4 )
{
int nIndex = listCtrl - > InsertItem ( listCtrl - > GetItemCount ( ) , str0 ) ;
listCtrl - > SetItem ( nIndex , 1 , str1 ) ;
listCtrl - > SetItem ( nIndex , 2 , str2 ) ;
listCtrl - > SetItem ( nIndex , 3 , str3 ) ;
listCtrl - > SetItem ( nIndex , 4 , str4 ) ;
return nIndex ;
}
int InsertLine ( wxListCtrl * listCtrl , void * pdata , const wxString & str0 , const wxString & str1 , const wxString & str2 , const wxString & str3 , const wxString & str4 )
{
int nIndex = listCtrl - > InsertItem ( listCtrl - > GetItemCount ( ) , str0 ) ;
listCtrl - > SetItemPtrData ( nIndex , ( wxUIntPtr ) pdata ) ;
listCtrl - > SetItem ( nIndex , 1 , str1 ) ;
listCtrl - > SetItem ( nIndex , 2 , str2 ) ;
listCtrl - > SetItem ( nIndex , 3 , str3 ) ;
listCtrl - > SetItem ( nIndex , 4 , str4 ) ;
return nIndex ;
}
void SetSelection ( wxListCtrl * listCtrl , int nIndex )
{
int nSize = listCtrl - > GetItemCount ( ) ;
long nState = ( wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ) ;
for ( int i = 0 ; i < nSize ; i + + )
listCtrl - > SetItemState ( i , ( i = = nIndex ? nState : 0 ) , nState ) ;
}
int GetSelection ( wxListCtrl * listCtrl )
{
int nSize = listCtrl - > GetItemCount ( ) ;
for ( int i = 0 ; i < nSize ; i + + )
if ( listCtrl - > GetItemState ( i , wxLIST_STATE_FOCUSED ) )
return i ;
return - 1 ;
}
string HtmlEscape ( const char * psz , bool fMultiLine = false )
{
int len = 0 ;
for ( const char * p = psz ; * p ; p + + )
{
if ( * p = = ' < ' ) len + = 4 ;
else if ( * p = = ' > ' ) len + = 4 ;
else if ( * p = = ' & ' ) len + = 5 ;
else if ( * p = = ' " ' ) len + = 6 ;
else if ( * p = = ' ' & & p > psz & & p [ - 1 ] = = ' ' & & p [ 1 ] = = ' ' ) len + = 6 ;
else if ( * p = = ' \n ' & & fMultiLine ) len + = 5 ;
else
len + + ;
}
string str ;
str . reserve ( len ) ;
for ( const char * p = psz ; * p ; p + + )
{
if ( * p = = ' < ' ) str + = " < " ;
else if ( * p = = ' > ' ) str + = " > ; " ;
else if ( * p = = ' & ' ) str + = " & ; " ;
else if ( * p = = ' " ' ) str + = " " ; " ;
else if ( * p = = ' ' & & p > psz & & p [ - 1 ] = = ' ' & & p [ 1 ] = = ' ' ) str + = "   ; " ;
else if ( * p = = ' \n ' & & fMultiLine ) str + = " <br> \n " ;
else
str + = * p ;
}
return str ;
}
string HtmlEscape ( const string & str , bool fMultiLine = false )
{
return HtmlEscape ( str . c_str ( ) , fMultiLine ) ;
}
2009-11-06 21:05:03 -08:00
void CalledMessageBox ( const string & message , const string & caption , int style , wxWindow * parent , int x , int y , int * pnRet , bool * pfDone )
2009-11-06 10:53:26 -08:00
{
2009-11-06 21:05:03 -08:00
* pnRet = wxMessageBox ( message , caption , style , parent , x , y ) ;
* pfDone = true ;
2009-11-06 10:53:26 -08:00
}
int ThreadSafeMessageBox ( const string & message , const string & caption , int style , wxWindow * parent , int x , int y )
{
# ifdef __WXMSW__
2009-11-06 21:05:03 -08:00
return wxMessageBox ( message , caption , style , parent , x , y ) ;
2009-11-06 10:53:26 -08:00
# else
2010-02-23 14:01:39 -08:00
if ( wxThread : : IsMain ( ) | | fDaemon )
2009-11-06 21:05:03 -08:00
{
return wxMessageBox ( message , caption , style , parent , x , y ) ;
}
else
{
int nRet = 0 ;
bool fDone = false ;
UIThreadCall ( bind ( CalledMessageBox , message , caption , style , parent , x , y , & nRet , & fDone ) ) ;
while ( ! fDone )
Sleep ( 100 ) ;
return nRet ;
}
2009-11-06 10:53:26 -08:00
# endif
}
2010-02-20 13:59:59 -08:00
bool ThreadSafeAskFee ( int64 nFeeRequired , const string & strCaption , wxWindow * parent )
{
if ( nFeeRequired = = 0 | | fDaemon )
return true ;
string strMessage = strprintf (
_ ( " This transaction is over the size limit. You can still send it for a fee of %s, "
" which goes to the nodes that process your transaction and helps to support the network. "
" Do you want to pay the fee? " ) ,
FormatMoney ( nFeeRequired ) . c_str ( ) ) ;
return ( ThreadSafeMessageBox ( strMessage , strCaption , wxYES_NO , parent ) = = wxYES ) ;
}
2010-05-25 17:05:26 -07:00
void CalledSetStatusBar ( const string & strText , int nField )
{
if ( pframeMain & & pframeMain - > m_statusBar )
pframeMain - > m_statusBar - > SetStatusText ( strText , nField ) ;
}
2010-02-20 13:59:59 -08:00
void SetDefaultReceivingAddress ( const string & strAddress )
{
// Update main window address and database
if ( pframeMain = = NULL )
return ;
if ( strAddress ! = pframeMain - > m_textCtrlAddress - > GetValue ( ) )
{
uint160 hash160 ;
if ( ! AddressToHash160 ( strAddress , hash160 ) )
return ;
if ( ! mapPubKeys . count ( hash160 ) )
return ;
CWalletDB ( ) . WriteDefaultKey ( mapPubKeys [ hash160 ] ) ;
pframeMain - > m_textCtrlAddress - > SetValue ( strAddress ) ;
}
}
2009-11-06 10:53:26 -08:00
2009-08-29 20:46:39 -07:00
//////////////////////////////////////////////////////////////////////////////
//
// CMainFrame
//
CMainFrame : : CMainFrame ( wxWindow * parent ) : CMainFrameBase ( parent )
{
2009-11-06 10:53:26 -08:00
Connect ( wxEVT_UITHREADCALL , wxCommandEventHandler ( CMainFrame : : OnUIThreadCall ) , NULL , this ) ;
2009-08-29 20:46:39 -07:00
2010-02-21 13:42:01 -08:00
// Set initially selected page
wxNotebookEvent event ;
event . SetSelection ( 0 ) ;
OnNotebookPageChanged ( event ) ;
m_notebook - > ChangeSelection ( 0 ) ;
2009-08-29 20:46:39 -07:00
// Init
fRefreshListCtrl = false ;
fRefreshListCtrlRunning = false ;
fOnSetFocusAddress = false ;
2009-11-05 21:50:05 -08:00
fRefresh = false ;
2009-08-29 20:46:39 -07:00
m_choiceFilter - > SetSelection ( 0 ) ;
2009-12-11 08:49:21 -08:00
double dResize = 1.0 ;
2009-11-07 10:51:41 -08:00
# ifdef __WXMSW__
SetIcon ( wxICON ( bitcoin ) ) ;
# else
2010-06-21 10:11:26 -07:00
SetIcon ( bitcoin80_xpm ) ;
2010-06-20 18:33:44 -07:00
SetBackgroundColour ( m_toolBar - > GetBackgroundColour ( ) ) ;
2009-11-07 10:51:41 -08:00
wxFont fontTmp = m_staticText41 - > GetFont ( ) ;
2009-11-06 21:05:03 -08:00
fontTmp . SetFamily ( wxFONTFAMILY_TELETYPE ) ;
m_staticTextBalance - > SetFont ( fontTmp ) ;
m_staticTextBalance - > SetSize ( 140 , 17 ) ;
2009-12-11 08:49:21 -08:00
// resize to fit ubuntu's huge default font
2010-02-21 13:42:01 -08:00
dResize = 1.22 ;
2010-02-25 13:55:27 -08:00
SetSize ( dResize * GetSize ( ) . GetWidth ( ) , 1.15 * GetSize ( ) . GetHeight ( ) ) ;
2009-11-06 21:05:03 -08:00
# endif
2009-08-29 20:46:39 -07:00
m_staticTextBalance - > SetLabel ( FormatMoney ( GetBalance ( ) ) + " " ) ;
m_listCtrl - > SetFocus ( ) ;
2009-10-20 18:08:05 -07:00
ptaskbaricon = new CMyTaskBarIcon ( ) ;
2010-05-18 17:26:56 -07:00
# ifdef __WXMAC__
// Mac automatically moves wxID_EXIT, wxID_PREFERENCES and wxID_ABOUT
// to their standard places, leaving these menus empty.
GetMenuBar ( ) - > Remove ( 2 ) ; // remove Help menu
GetMenuBar ( ) - > Remove ( 0 ) ; // remove File menu
# endif
2009-08-29 20:46:39 -07:00
// Init column headers
int nDateWidth = DateTimeStr ( 1229413914 ) . size ( ) * 6 + 8 ;
2009-10-24 21:35:01 -07:00
if ( ! strstr ( DateTimeStr ( 1229413914 ) . c_str ( ) , " 2008 " ) )
nDateWidth + = 12 ;
2010-05-18 17:26:56 -07:00
# ifdef __WXMAC__
2010-05-25 17:05:26 -07:00
nDateWidth + = 5 ;
dResize - = 0.01 ;
2010-05-18 17:26:56 -07:00
# endif
2010-02-21 13:42:01 -08:00
wxListCtrl * pplistCtrl [ ] = { m_listCtrlAll , m_listCtrlSentReceived , m_listCtrlSent , m_listCtrlReceived } ;
foreach ( wxListCtrl * p , pplistCtrl )
{
p - > InsertColumn ( 0 , " " , wxLIST_FORMAT_LEFT , dResize * 0 ) ;
p - > InsertColumn ( 1 , " " , wxLIST_FORMAT_LEFT , dResize * 0 ) ;
p - > InsertColumn ( 2 , _ ( " Status " ) , wxLIST_FORMAT_LEFT , dResize * 112 ) ;
p - > InsertColumn ( 3 , _ ( " Date " ) , wxLIST_FORMAT_LEFT , dResize * nDateWidth ) ;
p - > InsertColumn ( 4 , _ ( " Description " ) , wxLIST_FORMAT_LEFT , dResize * 409 - nDateWidth ) ;
p - > InsertColumn ( 5 , _ ( " Debit " ) , wxLIST_FORMAT_RIGHT , dResize * 79 ) ;
p - > InsertColumn ( 6 , _ ( " Credit " ) , wxLIST_FORMAT_RIGHT , dResize * 79 ) ;
}
2009-08-29 20:46:39 -07:00
// Init status bar
2010-05-18 17:26:56 -07:00
int pnWidths [ 3 ] = { - 100 , 88 , 300 } ;
2009-12-11 08:49:21 -08:00
# ifndef __WXMSW__
pnWidths [ 1 ] = pnWidths [ 1 ] * 1.1 * dResize ;
pnWidths [ 2 ] = pnWidths [ 2 ] * 1.1 * dResize ;
# endif
2009-08-29 20:46:39 -07:00
m_statusBar - > SetFieldsCount ( 3 , pnWidths ) ;
// Fill your address text box
vector < unsigned char > vchPubKey ;
if ( CWalletDB ( " r " ) . ReadDefaultKey ( vchPubKey ) )
m_textCtrlAddress - > SetValue ( PubKeyToAddress ( vchPubKey ) ) ;
// Fill listctrl with wallet transactions
RefreshListCtrl ( ) ;
}
CMainFrame : : ~ CMainFrame ( )
{
pframeMain = NULL ;
2009-10-20 18:08:05 -07:00
delete ptaskbaricon ;
ptaskbaricon = NULL ;
2009-08-29 20:46:39 -07:00
}
2010-02-21 13:42:01 -08:00
void CMainFrame : : OnNotebookPageChanged ( wxNotebookEvent & event )
{
event . Skip ( ) ;
nPage = event . GetSelection ( ) ;
if ( nPage = = ALL )
{
m_listCtrl = m_listCtrlAll ;
fShowGenerated = true ;
fShowSent = true ;
fShowReceived = true ;
}
else if ( nPage = = SENTRECEIVED )
{
m_listCtrl = m_listCtrlSentReceived ;
fShowGenerated = false ;
fShowSent = true ;
fShowReceived = true ;
}
else if ( nPage = = SENT )
{
m_listCtrl = m_listCtrlSent ;
fShowGenerated = false ;
fShowSent = true ;
fShowReceived = false ;
}
else if ( nPage = = RECEIVED )
{
m_listCtrl = m_listCtrlReceived ;
fShowGenerated = false ;
fShowSent = false ;
fShowReceived = true ;
}
RefreshListCtrl ( ) ;
m_listCtrl - > SetFocus ( ) ;
}
2009-08-29 20:46:39 -07:00
void CMainFrame : : OnClose ( wxCloseEvent & event )
{
2009-11-12 17:23:08 -08:00
if ( fMinimizeOnClose & & event . CanVeto ( ) & & ! IsIconized ( ) )
2009-10-20 18:08:05 -07:00
{
// Divert close to minimize
event . Veto ( ) ;
2009-11-12 17:23:08 -08:00
fClosedToTray = true ;
2009-10-20 18:08:05 -07:00
Iconize ( true ) ;
}
else
{
Destroy ( ) ;
2009-11-12 17:23:08 -08:00
CreateThread ( Shutdown , NULL ) ;
2009-10-20 18:08:05 -07:00
}
2009-09-23 21:09:56 -07:00
}
void CMainFrame : : OnIconize ( wxIconizeEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-10-20 18:08:05 -07:00
// Hide the task bar button when minimized.
// Event is sent when the frame is minimized or restored.
2010-01-28 13:49:20 -08:00
// wxWidgets 2.8.9 doesn't have IsIconized() so there's no way
// to get rid of the deprecated warning. Just ignore it.
2009-11-12 17:23:08 -08:00
if ( ! event . Iconized ( ) )
fClosedToTray = false ;
2010-07-16 16:12:58 -07:00
# ifdef __WXGTK__
if ( mapArgs . count ( " -minimizetotray " ) ) {
# endif
2010-06-20 18:33:44 -07:00
// The tray icon sometimes disappears on ubuntu karmic
2010-06-21 20:45:37 -07:00
// Hiding the taskbar button doesn't work cleanly on ubuntu lucid
2010-07-14 17:18:45 -07:00
// Reports of CPU peg on 64-bit linux
2009-11-12 17:23:08 -08:00
if ( fMinimizeToTray & & event . Iconized ( ) )
fClosedToTray = true ;
Show ( ! fClosedToTray ) ;
ptaskbaricon - > Show ( fMinimizeToTray | | fClosedToTray ) ;
2010-07-16 16:12:58 -07:00
# ifdef __WXGTK__
}
# endif
2009-08-29 20:46:39 -07:00
}
void CMainFrame : : OnMouseEvents ( wxMouseEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
RandAddSeed ( ) ;
RAND_add ( & event . m_x , sizeof ( event . m_x ) , 0.25 ) ;
RAND_add ( & event . m_y , sizeof ( event . m_y ) , 0.25 ) ;
}
void CMainFrame : : OnListColBeginDrag ( wxListEvent & event )
{
2010-02-20 13:59:59 -08:00
// Hidden columns not resizeable
if ( event . GetColumn ( ) < = 1 & & ! fDebug )
2009-08-29 20:46:39 -07:00
event . Veto ( ) ;
2010-02-20 13:59:59 -08:00
else
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
}
2009-11-05 21:50:05 -08:00
int CMainFrame : : GetSortIndex ( const string & strSort )
{
# ifdef __WXMSW__
return 0 ;
# else
// The wx generic listctrl implementation used on GTK doesn't sort,
// so we have to do it ourselves. Remember, we sort in reverse order.
// In the wx generic implementation, they store the list of items
// in a vector, so indexed lookups are fast, but inserts are slower
// the closer they are to the top.
int low = 0 ;
int high = m_listCtrl - > GetItemCount ( ) ;
while ( low < high )
{
int mid = low + ( ( high - low ) / 2 ) ;
if ( strSort . compare ( m_listCtrl - > GetItemText ( mid ) . c_str ( ) ) > = 0 )
high = mid ;
else
low = mid + 1 ;
}
return low ;
# endif
}
2009-08-29 20:46:39 -07:00
void CMainFrame : : InsertLine ( bool fNew , int nIndex , uint256 hashKey , string strSort , const wxString & str2 , const wxString & str3 , const wxString & str4 , const wxString & str5 , const wxString & str6 )
{
2010-02-13 16:08:27 -08:00
strSort = " " + strSort ; // leading space to workaround wx2.9.0 ubuntu 9.10 bug
long nData = * ( long * ) & hashKey ; // where first char of hidden column is displayed
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
// Find item
if ( ! fNew & & nIndex = = - 1 )
{
2010-02-13 16:08:27 -08:00
string strHash = " " + hashKey . ToString ( ) ;
2009-10-20 18:08:05 -07:00
while ( ( nIndex = m_listCtrl - > FindItem ( nIndex , nData ) ) ! = - 1 )
2010-02-13 16:08:27 -08:00
if ( GetItemText ( m_listCtrl , nIndex , 1 ) = = strHash )
2009-10-20 18:08:05 -07:00
break ;
}
// fNew is for blind insert, only use if you're sure it's new
if ( fNew | | nIndex = = - 1 )
2009-08-29 20:46:39 -07:00
{
2010-02-13 16:08:27 -08:00
nIndex = m_listCtrl - > InsertItem ( GetSortIndex ( strSort ) , strSort ) ;
2009-08-29 20:46:39 -07:00
}
else
{
// If sort key changed, must delete and reinsert to make it relocate
2010-02-13 16:08:27 -08:00
if ( GetItemText ( m_listCtrl , nIndex , 0 ) ! = strSort )
2009-08-29 20:46:39 -07:00
{
m_listCtrl - > DeleteItem ( nIndex ) ;
2010-02-13 16:08:27 -08:00
nIndex = m_listCtrl - > InsertItem ( GetSortIndex ( strSort ) , strSort ) ;
2009-08-29 20:46:39 -07:00
}
}
2010-02-13 16:08:27 -08:00
m_listCtrl - > SetItem ( nIndex , 1 , " " + hashKey . ToString ( ) ) ;
2009-08-29 20:46:39 -07:00
m_listCtrl - > SetItem ( nIndex , 2 , str2 ) ;
m_listCtrl - > SetItem ( nIndex , 3 , str3 ) ;
m_listCtrl - > SetItem ( nIndex , 4 , str4 ) ;
m_listCtrl - > SetItem ( nIndex , 5 , str5 ) ;
m_listCtrl - > SetItem ( nIndex , 6 , str6 ) ;
m_listCtrl - > SetItemData ( nIndex , nData ) ;
}
2009-10-24 21:35:01 -07:00
bool CMainFrame : : DeleteLine ( uint256 hashKey )
{
long nData = * ( long * ) & hashKey ;
// Find item
int nIndex = - 1 ;
2010-02-13 16:08:27 -08:00
string strHash = " " + hashKey . ToString ( ) ;
2009-10-24 21:35:01 -07:00
while ( ( nIndex = m_listCtrl - > FindItem ( nIndex , nData ) ) ! = - 1 )
2010-02-13 16:08:27 -08:00
if ( GetItemText ( m_listCtrl , nIndex , 1 ) = = strHash )
2009-10-24 21:35:01 -07:00
break ;
if ( nIndex ! = - 1 )
m_listCtrl - > DeleteItem ( nIndex ) ;
return nIndex ! = - 1 ;
}
2009-08-29 20:46:39 -07:00
string FormatTxStatus ( const CWalletTx & wtx )
{
// Status
if ( ! wtx . IsFinal ( ) )
2009-10-24 21:35:01 -07:00
{
if ( wtx . nLockTime < 500000000 )
2010-02-17 09:22:01 -08:00
return strprintf ( _ ( " Open for %d blocks " ) , nBestHeight - wtx . nLockTime ) ;
2009-10-24 21:35:01 -07:00
else
2010-02-17 09:22:01 -08:00
return strprintf ( _ ( " Open until %s " ) , DateTimeStr ( wtx . nLockTime ) . c_str ( ) ) ;
2009-10-24 21:35:01 -07:00
}
2009-08-29 20:46:39 -07:00
else
2009-11-12 17:23:08 -08:00
{
int nDepth = wtx . GetDepthInMainChain ( ) ;
if ( GetAdjustedTime ( ) - wtx . nTimeReceived > 2 * 60 & & wtx . GetRequestCount ( ) = = 0 )
2010-02-17 09:22:01 -08:00
return strprintf ( _ ( " %d/offline? " ) , nDepth ) ;
2009-11-12 17:23:08 -08:00
else if ( nDepth < 6 )
2010-02-17 09:22:01 -08:00
return strprintf ( _ ( " %d/unconfirmed " ) , nDepth ) ;
2009-11-12 17:23:08 -08:00
else
2010-02-17 09:22:01 -08:00
return strprintf ( _ ( " %d confirmations " ) , nDepth ) ;
2009-11-12 17:23:08 -08:00
}
2009-08-29 20:46:39 -07:00
}
string SingleLine ( const string & strIn )
{
string strOut ;
bool fOneSpace = false ;
foreach ( int c , strIn )
{
if ( isspace ( c ) )
{
fOneSpace = true ;
}
else if ( c > ' ' )
{
if ( fOneSpace & & ! strOut . empty ( ) )
strOut + = ' ' ;
strOut + = c ;
fOneSpace = false ;
}
}
return strOut ;
}
2009-10-28 19:52:48 -07:00
bool CMainFrame : : InsertTransaction ( const CWalletTx & wtx , bool fNew , int nIndex )
2009-08-29 20:46:39 -07:00
{
int64 nTime = wtx . nTimeDisplayed = wtx . GetTxTime ( ) ;
2010-02-23 14:01:39 -08:00
int64 nCredit = wtx . GetCredit ( true ) ;
2009-08-29 20:46:39 -07:00
int64 nDebit = wtx . GetDebit ( ) ;
int64 nNet = nCredit - nDebit ;
uint256 hash = wtx . GetHash ( ) ;
string strStatus = FormatTxStatus ( wtx ) ;
map < string , string > mapValue = wtx . mapValue ;
2009-10-28 19:52:48 -07:00
wtx . nLinesDisplayed = 1 ;
2009-10-31 18:16:51 -07:00
nListViewUpdated + + ;
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
// Filter
if ( wtx . IsCoinBase ( ) )
{
// 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 )
2009-10-24 21:35:01 -07:00
{
2009-10-28 19:52:48 -07:00
wtx . nLinesDisplayed = 0 ;
return false ;
2009-10-24 21:35:01 -07:00
}
2009-10-28 19:52:48 -07:00
if ( ! fShowGenerated )
return false ;
2009-10-20 18:08:05 -07:00
}
2009-08-29 20:46:39 -07:00
// Find the block the tx is in
CBlockIndex * pindex = NULL ;
map < uint256 , CBlockIndex * > : : iterator mi = mapBlockIndex . find ( wtx . hashBlock ) ;
if ( mi ! = mapBlockIndex . end ( ) )
pindex = ( * mi ) . second ;
// Sort order, unrecorded transactions sort to the top
string strSort = strprintf ( " %010d-%01d-%010u " ,
( pindex ? pindex - > nHeight : INT_MAX ) ,
( wtx . IsCoinBase ( ) ? 1 : 0 ) ,
wtx . nTimeReceived ) ;
// Insert line
if ( nNet > 0 | | wtx . IsCoinBase ( ) )
{
//
// Credit
//
string strDescription ;
if ( wtx . IsCoinBase ( ) )
{
2010-02-20 13:59:59 -08:00
// Generated
2010-02-17 09:22:01 -08:00
strDescription = _ ( " Generated " ) ;
2009-08-29 20:46:39 -07:00
if ( nCredit = = 0 )
{
int64 nUnmatured = 0 ;
foreach ( const CTxOut & txout , wtx . vout )
nUnmatured + = txout . GetCredit ( ) ;
if ( wtx . IsInMainChain ( ) )
2009-11-12 17:23:08 -08:00
{
2010-02-17 09:22:01 -08:00
strDescription = strprintf ( _ ( " Generated (%s matures in %d more blocks) " ) , FormatMoney ( nUnmatured ) . c_str ( ) , wtx . GetBlocksToMaturity ( ) ) ;
2009-11-12 17:23:08 -08:00
// Check if the block was requested by anyone
if ( GetAdjustedTime ( ) - wtx . nTimeReceived > 2 * 60 & & wtx . GetRequestCount ( ) = = 0 )
2010-02-17 09:22:01 -08:00
strDescription = _ ( " Generated - Warning: This block was not received by any other nodes and will probably not be accepted! " ) ;
2009-11-12 17:23:08 -08:00
}
2009-08-29 20:46:39 -07:00
else
2009-11-12 17:23:08 -08:00
{
2010-02-17 09:22:01 -08:00
strDescription = _ ( " Generated (not accepted) " ) ;
2009-11-12 17:23:08 -08:00
}
2009-08-29 20:46:39 -07:00
}
}
else if ( ! mapValue [ " from " ] . empty ( ) | | ! mapValue [ " message " ] . empty ( ) )
{
2010-02-20 13:59:59 -08:00
// Received by IP connection
2010-02-21 13:42:01 -08:00
if ( ! fShowReceived )
return false ;
2009-08-29 20:46:39 -07:00
if ( ! mapValue [ " from " ] . empty ( ) )
2010-02-17 09:22:01 -08:00
strDescription + = _ ( " From: " ) + mapValue [ " from " ] ;
2009-08-29 20:46:39 -07:00
if ( ! mapValue [ " message " ] . empty ( ) )
{
if ( ! strDescription . empty ( ) )
strDescription + = " - " ;
strDescription + = mapValue [ " message " ] ;
}
}
else
{
2010-02-20 13:59:59 -08:00
// Received by Bitcoin Address
2010-02-21 13:42:01 -08:00
if ( ! fShowReceived )
return false ;
2009-08-29 20:46:39 -07:00
foreach ( const CTxOut & txout , wtx . vout )
{
if ( txout . IsMine ( ) )
{
vector < unsigned char > vchPubKey ;
if ( ExtractPubKey ( txout . scriptPubKey , true , vchPubKey ) )
{
2010-02-12 12:38:44 -08:00
CRITICAL_BLOCK ( cs_mapAddressBook )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
//strDescription += _("Received payment to ");
//strDescription += _("Received with address ");
strDescription + = _ ( " From: unknown, Received with: " ) ;
2010-02-12 12:38:44 -08:00
string strAddress = PubKeyToAddress ( vchPubKey ) ;
2010-02-20 13:59:59 -08:00
map < string , string > : : iterator mi = mapAddressBook . find ( strAddress ) ;
if ( mi ! = mapAddressBook . end ( ) & & ! ( * mi ) . second . empty ( ) )
2010-02-12 12:38:44 -08:00
{
2010-02-20 13:59:59 -08:00
string strLabel = ( * mi ) . second ;
strDescription + = strAddress . substr ( 0 , 12 ) + " ... " ;
strDescription + = " ( " + strLabel + " ) " ;
2010-02-12 12:38:44 -08:00
}
2010-02-20 13:59:59 -08:00
else
strDescription + = strAddress ;
2009-08-29 20:46:39 -07:00
}
}
break ;
}
}
}
InsertLine ( fNew , nIndex , hash , strSort ,
strStatus ,
nTime ? DateTimeStr ( nTime ) : " " ,
SingleLine ( strDescription ) ,
" " ,
FormatMoney ( nNet , true ) ) ;
}
else
{
bool fAllFromMe = true ;
foreach ( const CTxIn & txin , wtx . vin )
fAllFromMe = fAllFromMe & & txin . IsMine ( ) ;
bool fAllToMe = true ;
foreach ( const CTxOut & txout , wtx . vout )
fAllToMe = fAllToMe & & txout . IsMine ( ) ;
if ( fAllFromMe & & fAllToMe )
{
// Payment to self
int64 nValue = wtx . vout [ 0 ] . nValue ;
InsertLine ( fNew , nIndex , hash , strSort ,
strStatus ,
nTime ? DateTimeStr ( nTime ) : " " ,
2010-02-17 09:22:01 -08:00
_ ( " Payment to yourself " ) ,
2009-11-12 17:23:08 -08:00
" " ,
" " ) ;
/// issue: can't tell which is the payment and which is the change anymore
// FormatMoney(nNet - nValue, true),
// FormatMoney(nValue, true));
2009-08-29 20:46:39 -07:00
}
else if ( fAllFromMe )
{
//
// Debit
//
2010-02-21 13:42:01 -08:00
if ( ! fShowSent )
return false ;
2009-08-29 20:46:39 -07:00
int64 nTxFee = nDebit - wtx . GetValueOut ( ) ;
2009-10-28 19:52:48 -07:00
wtx . nLinesDisplayed = 0 ;
2009-08-29 20:46:39 -07:00
for ( int nOut = 0 ; nOut < wtx . vout . size ( ) ; nOut + + )
{
const CTxOut & txout = wtx . vout [ nOut ] ;
if ( txout . IsMine ( ) )
continue ;
string strAddress ;
if ( ! mapValue [ " to " ] . empty ( ) )
{
2010-02-20 13:59:59 -08:00
// Sent to IP
2009-08-29 20:46:39 -07:00
strAddress = mapValue [ " to " ] ;
}
else
{
2010-02-20 13:59:59 -08:00
// Sent to Bitcoin Address
2009-08-29 20:46:39 -07:00
uint160 hash160 ;
if ( ExtractHash160 ( txout . scriptPubKey , hash160 ) )
strAddress = Hash160ToAddress ( hash160 ) ;
}
2010-02-17 09:22:01 -08:00
string strDescription = _ ( " To: " ) ;
2010-02-12 12:38:44 -08:00
CRITICAL_BLOCK ( cs_mapAddressBook )
if ( mapAddressBook . count ( strAddress ) & & ! mapAddressBook [ strAddress ] . empty ( ) )
strDescription + = mapAddressBook [ strAddress ] + " " ;
2009-08-29 20:46:39 -07:00
strDescription + = strAddress ;
if ( ! mapValue [ " message " ] . empty ( ) )
{
if ( ! strDescription . empty ( ) )
strDescription + = " - " ;
strDescription + = mapValue [ " message " ] ;
}
int64 nValue = txout . nValue ;
2010-02-20 13:59:59 -08:00
if ( nTxFee > 0 )
{
2009-08-29 20:46:39 -07:00
nValue + = nTxFee ;
2010-02-20 13:59:59 -08:00
nTxFee = 0 ;
}
2009-08-29 20:46:39 -07:00
InsertLine ( fNew , nIndex , hash , strprintf ( " %s-%d " , strSort . c_str ( ) , nOut ) ,
strStatus ,
nTime ? DateTimeStr ( nTime ) : " " ,
SingleLine ( strDescription ) ,
FormatMoney ( - nValue , true ) ,
" " ) ;
2009-10-28 19:52:48 -07:00
wtx . nLinesDisplayed + + ;
2009-08-29 20:46:39 -07:00
}
}
else
{
//
// Mixed debit transaction, can't break down payees
//
bool fAllMine = true ;
foreach ( const CTxOut & txout , wtx . vout )
fAllMine = fAllMine & & txout . IsMine ( ) ;
foreach ( const CTxIn & txin , wtx . vin )
fAllMine = fAllMine & & txin . IsMine ( ) ;
InsertLine ( fNew , nIndex , hash , strSort ,
strStatus ,
nTime ? DateTimeStr ( nTime ) : " " ,
" " ,
FormatMoney ( nNet , true ) ,
" " ) ;
}
}
2009-10-28 19:52:48 -07:00
return true ;
2009-08-29 20:46:39 -07:00
}
void CMainFrame : : RefreshListCtrl ( )
{
fRefreshListCtrl = true ;
: : wxWakeUpIdle ( ) ;
}
void CMainFrame : : OnIdle ( wxIdleEvent & event )
{
if ( fRefreshListCtrl )
{
// Collect list of wallet transactions and sort newest first
bool fEntered = false ;
vector < pair < unsigned int , uint256 > > vSorted ;
TRY_CRITICAL_BLOCK ( cs_mapWallet )
{
printf ( " RefreshListCtrl starting \n " ) ;
fEntered = true ;
fRefreshListCtrl = false ;
vWalletUpdated . clear ( ) ;
// Do the newest transactions first
vSorted . reserve ( mapWallet . size ( ) ) ;
for ( map < uint256 , CWalletTx > : : iterator it = mapWallet . begin ( ) ; it ! = mapWallet . end ( ) ; + + it )
{
const CWalletTx & wtx = ( * it ) . second ;
unsigned int nTime = UINT_MAX - wtx . GetTxTime ( ) ;
vSorted . push_back ( make_pair ( nTime , ( * it ) . first ) ) ;
}
m_listCtrl - > DeleteAllItems ( ) ;
}
if ( ! fEntered )
return ;
sort ( vSorted . begin ( ) , vSorted . end ( ) ) ;
// Fill list control
for ( int i = 0 ; i < vSorted . size ( ) ; )
{
if ( fShutdown )
return ;
bool fEntered = false ;
TRY_CRITICAL_BLOCK ( cs_mapWallet )
{
fEntered = true ;
uint256 & hash = vSorted [ i + + ] . second ;
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( hash ) ;
if ( mi ! = mapWallet . end ( ) )
InsertTransaction ( ( * mi ) . second , true ) ;
}
if ( ! fEntered | | i = = 100 | | i % 500 = = 0 )
wxYield ( ) ;
}
printf ( " RefreshListCtrl done \n " ) ;
2009-10-28 19:52:48 -07:00
// Update transaction total display
MainFrameRepaint ( ) ;
2009-08-29 20:46:39 -07:00
}
else
{
// Check for time updates
static int64 nLastTime ;
if ( GetTime ( ) > nLastTime + 30 )
{
TRY_CRITICAL_BLOCK ( cs_mapWallet )
{
nLastTime = GetTime ( ) ;
for ( map < uint256 , CWalletTx > : : iterator it = mapWallet . begin ( ) ; it ! = mapWallet . end ( ) ; + + it )
{
CWalletTx & wtx = ( * it ) . second ;
if ( wtx . nTimeDisplayed & & wtx . nTimeDisplayed ! = wtx . GetTxTime ( ) )
InsertTransaction ( wtx , false ) ;
}
}
}
}
}
2009-10-31 18:16:51 -07:00
void CMainFrame : : RefreshStatusColumn ( )
{
static int nLastTop ;
static CBlockIndex * pindexLastBest ;
static unsigned int nLastRefreshed ;
int nTop = max ( ( int ) m_listCtrl - > GetTopItem ( ) , 0 ) ;
if ( nTop = = nLastTop & & pindexLastBest = = pindexBest )
return ;
TRY_CRITICAL_BLOCK ( cs_mapWallet )
{
int nStart = nTop ;
int nEnd = min ( nStart + 100 , m_listCtrl - > GetItemCount ( ) ) ;
if ( pindexLastBest = = pindexBest & & nLastRefreshed = = nListViewUpdated )
{
// If no updates, only need to do the part that moved onto the screen
if ( nStart > = nLastTop & & nStart < nLastTop + 100 )
nStart = nLastTop + 100 ;
if ( nEnd > = nLastTop & & nEnd < nLastTop + 100 )
nEnd = nLastTop ;
}
nLastTop = nTop ;
pindexLastBest = pindexBest ;
nLastRefreshed = nListViewUpdated ;
for ( int nIndex = nStart ; nIndex < min ( nEnd , m_listCtrl - > GetItemCount ( ) ) ; nIndex + + )
{
uint256 hash ( ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ) ;
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( hash ) ;
if ( mi = = mapWallet . end ( ) )
{
printf ( " CMainFrame::RefreshStatusColumn() : tx not found in mapWallet \n " ) ;
continue ;
}
CWalletTx & wtx = ( * mi ) . second ;
if ( wtx . IsCoinBase ( ) | | wtx . GetTxTime ( ) ! = wtx . nTimeDisplayed )
{
if ( ! InsertTransaction ( wtx , false , nIndex ) )
m_listCtrl - > DeleteItem ( nIndex - - ) ;
}
else
m_listCtrl - > SetItem ( nIndex , 2 , FormatTxStatus ( wtx ) ) ;
}
}
}
2009-08-29 20:46:39 -07:00
void CMainFrame : : OnPaint ( wxPaintEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-11-05 21:50:05 -08:00
if ( fRefresh )
{
fRefresh = false ;
Refresh ( ) ;
}
2009-08-29 20:46:39 -07:00
}
2009-10-31 18:16:51 -07:00
unsigned int nNeedRepaint = 0 ;
unsigned int nLastRepaint = 0 ;
int64 nLastRepaintTime = 0 ;
int64 nRepaintInterval = 500 ;
void ThreadDelayedRepaint ( void * parg )
2009-10-24 21:35:01 -07:00
{
2009-10-31 18:16:51 -07:00
while ( ! fShutdown )
{
if ( nLastRepaint ! = nNeedRepaint & & GetTimeMillis ( ) - nLastRepaintTime > = nRepaintInterval )
{
nLastRepaint = nNeedRepaint ;
if ( pframeMain )
{
printf ( " DelayedRepaint \n " ) ;
wxPaintEvent event ;
2009-11-05 21:50:05 -08:00
pframeMain - > fRefresh = true ;
2010-01-28 13:49:20 -08:00
pframeMain - > GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2009-10-31 18:16:51 -07:00
}
}
Sleep ( nRepaintInterval ) ;
}
}
void MainFrameRepaint ( )
{
// This is called by network code that shouldn't access pframeMain
// directly because it could still be running after the UI is closed.
if ( pframeMain )
{
// Don't repaint too often
static int64 nLastRepaintRequest ;
if ( GetTimeMillis ( ) - nLastRepaintRequest < 100 )
{
nNeedRepaint + + ;
return ;
}
nLastRepaintRequest = GetTimeMillis ( ) ;
printf ( " MainFrameRepaint \n " ) ;
wxPaintEvent event ;
2009-11-05 21:50:05 -08:00
pframeMain - > fRefresh = true ;
2010-01-28 13:49:20 -08:00
pframeMain - > GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2009-10-31 18:16:51 -07:00
}
2009-10-24 21:35:01 -07:00
}
2009-08-29 20:46:39 -07:00
void CMainFrame : : OnPaintListCtrl ( wxPaintEvent & event )
{
2010-02-20 13:59:59 -08:00
// Skip lets the listctrl do the paint, we're just hooking the message
event . Skip ( ) ;
2009-10-28 19:52:48 -07:00
if ( ptaskbaricon )
ptaskbaricon - > UpdateTooltip ( ) ;
2009-10-31 18:16:51 -07:00
//
// Slower stuff
//
static int nTransactionCount ;
bool fPaintedBalance = false ;
if ( GetTimeMillis ( ) - nLastRepaintTime > = nRepaintInterval )
2009-08-29 20:46:39 -07:00
{
2009-10-31 18:16:51 -07:00
nLastRepaint = nNeedRepaint ;
nLastRepaintTime = GetTimeMillis ( ) ;
// Update listctrl contents
if ( ! vWalletUpdated . empty ( ) )
2009-08-29 20:46:39 -07:00
{
2009-10-31 18:16:51 -07:00
TRY_CRITICAL_BLOCK ( cs_mapWallet )
2009-08-29 20:46:39 -07:00
{
2009-11-04 20:41:36 -08:00
string strTop ;
if ( m_listCtrl - > GetItemCount ( ) )
strTop = ( string ) m_listCtrl - > GetItemText ( 0 ) ;
2009-10-31 18:16:51 -07:00
foreach ( uint256 hash , vWalletUpdated )
{
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( hash ) ;
if ( mi ! = mapWallet . end ( ) )
2009-11-04 20:41:36 -08:00
InsertTransaction ( ( * mi ) . second , false ) ;
2009-10-31 18:16:51 -07:00
}
vWalletUpdated . clear ( ) ;
2009-11-04 20:41:36 -08:00
if ( m_listCtrl - > GetItemCount ( ) & & strTop ! = ( string ) m_listCtrl - > GetItemText ( 0 ) )
2009-11-05 21:50:05 -08:00
m_listCtrl - > ScrollList ( 0 , INT_MIN / 2 ) ;
2009-08-29 20:46:39 -07:00
}
}
2009-10-28 19:52:48 -07:00
2009-10-31 18:16:51 -07:00
// Balance total
TRY_CRITICAL_BLOCK ( cs_mapWallet )
2009-10-28 19:52:48 -07:00
{
2009-10-31 18:16:51 -07:00
fPaintedBalance = true ;
m_staticTextBalance - > SetLabel ( FormatMoney ( GetBalance ( ) ) + " " ) ;
// Count hidden and multi-line transactions
nTransactionCount = 0 ;
for ( map < uint256 , CWalletTx > : : iterator it = mapWallet . begin ( ) ; it ! = mapWallet . end ( ) ; + + it )
{
CWalletTx & wtx = ( * it ) . second ;
nTransactionCount + = wtx . nLinesDisplayed ;
}
2009-10-28 19:52:48 -07:00
}
}
2009-10-31 18:16:51 -07:00
if ( ! vWalletUpdated . empty ( ) | | ! fPaintedBalance )
nNeedRepaint + + ;
// Update status column of visible items only
RefreshStatusColumn ( ) ;
2009-10-28 19:52:48 -07:00
2009-08-29 20:46:39 -07:00
// Update status bar
string strGen = " " ;
if ( fGenerateBitcoins )
2010-02-17 09:22:01 -08:00
strGen = _ ( " Generating " ) ;
2009-08-29 20:46:39 -07:00
if ( fGenerateBitcoins & & vNodes . empty ( ) )
2010-02-17 09:22:01 -08:00
strGen = _ ( " (not connected) " ) ;
2009-08-29 20:46:39 -07:00
m_statusBar - > SetStatusText ( strGen , 1 ) ;
2010-02-17 09:22:01 -08:00
string strStatus = strprintf ( _ ( " %d connections %d blocks %d transactions " ) , vNodes . size ( ) , nBestHeight + 1 , nTransactionCount ) ;
2009-08-29 20:46:39 -07:00
m_statusBar - > SetStatusText ( strStatus , 2 ) ;
2009-11-12 17:23:08 -08:00
if ( fDebug & & GetTime ( ) - nThreadSocketHandlerHeartbeat > 60 )
m_statusBar - > SetStatusText ( " ERROR: ThreadSocketHandler has stopped " , 0 ) ;
2010-06-10 16:10:30 -07:00
// Update receiving address
string strDefaultAddress = PubKeyToAddress ( vchDefaultKey ) ;
if ( m_textCtrlAddress - > GetValue ( ) ! = strDefaultAddress )
m_textCtrlAddress - > SetValue ( strDefaultAddress ) ;
2009-08-29 20:46:39 -07:00
}
2009-10-31 18:16:51 -07:00
2009-11-06 21:05:03 -08:00
void UIThreadCall ( boost : : function0 < void > fn )
2009-08-29 20:46:39 -07:00
{
2009-11-06 10:53:26 -08:00
// Call this with a function object created with bind.
// bind needs all parameters to match the function's expected types
// and all default parameters specified. Some examples:
// UIThreadCall(bind(wxBell));
// UIThreadCall(bind(wxMessageBox, wxT("Message"), wxT("Title"), wxOK, (wxWindow*)NULL, -1, -1));
// UIThreadCall(bind(&CMainFrame::OnMenuHelpAbout, pframeMain, event));
2009-08-29 20:46:39 -07:00
if ( pframeMain )
2009-11-06 10:53:26 -08:00
{
wxCommandEvent event ( wxEVT_UITHREADCALL ) ;
2009-11-06 21:05:03 -08:00
event . SetClientData ( ( void * ) new boost : : function0 < void > ( fn ) ) ;
2009-08-29 20:46:39 -07:00
pframeMain - > GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2009-11-06 10:53:26 -08:00
}
2009-08-29 20:46:39 -07:00
}
2009-11-06 10:53:26 -08:00
void CMainFrame : : OnUIThreadCall ( wxCommandEvent & event )
2009-08-29 20:46:39 -07:00
{
2009-11-06 21:05:03 -08:00
boost : : function0 < void > * pfn = ( boost : : function0 < void > * ) event . GetClientData ( ) ;
2009-11-06 10:53:26 -08:00
( * pfn ) ( ) ;
delete pfn ;
2009-08-29 20:46:39 -07:00
}
void CMainFrame : : OnMenuFileExit ( wxCommandEvent & event )
{
2009-10-20 18:08:05 -07:00
// File->Exit
2009-08-29 20:46:39 -07:00
Close ( true ) ;
}
2009-09-23 21:09:56 -07:00
void CMainFrame : : OnMenuOptionsGenerate ( wxCommandEvent & event )
{
2009-10-20 18:08:05 -07:00
// Options->Generate Coins
2009-09-23 21:09:56 -07:00
GenerateBitcoins ( event . IsChecked ( ) ) ;
2009-10-20 18:08:05 -07:00
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
void CMainFrame : : OnUpdateUIOptionsGenerate ( wxUpdateUIEvent & event )
{
event . Check ( fGenerateBitcoins ) ;
2009-08-29 20:46:39 -07:00
}
void CMainFrame : : OnMenuOptionsChangeYourAddress ( wxCommandEvent & event )
{
2010-02-20 13:59:59 -08:00
// Options->Your Receiving Addresses
CAddressBookDialog dialog ( this , " " , CAddressBookDialog : : RECEIVING , false ) ;
if ( ! dialog . ShowModal ( ) )
return ;
2009-08-29 20:46:39 -07:00
}
void CMainFrame : : OnMenuOptionsOptions ( wxCommandEvent & event )
{
2009-10-20 18:08:05 -07:00
// Options->Options
2009-08-29 20:46:39 -07:00
COptionsDialog dialog ( this ) ;
dialog . ShowModal ( ) ;
}
void CMainFrame : : OnMenuHelpAbout ( wxCommandEvent & event )
{
2009-10-20 18:08:05 -07:00
// Help->About
2009-08-29 20:46:39 -07:00
CAboutDialog dialog ( this ) ;
dialog . ShowModal ( ) ;
}
void CMainFrame : : OnButtonSend ( wxCommandEvent & event )
{
// Toolbar: Send
CSendDialog dialog ( this ) ;
dialog . ShowModal ( ) ;
}
void CMainFrame : : OnButtonAddressBook ( wxCommandEvent & event )
{
// Toolbar: Address Book
2010-02-20 13:59:59 -08:00
CAddressBookDialog dialogAddr ( this , " " , CAddressBookDialog : : SENDING , false ) ;
2009-08-29 20:46:39 -07:00
if ( dialogAddr . ShowModal ( ) = = 2 )
{
// Send
2010-02-20 13:59:59 -08:00
CSendDialog dialogSend ( this , dialogAddr . GetSelectedAddress ( ) ) ;
2009-08-29 20:46:39 -07:00
dialogSend . ShowModal ( ) ;
}
}
void CMainFrame : : OnSetFocusAddress ( wxFocusEvent & event )
{
// Automatically select-all when entering window
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
fOnSetFocusAddress = true ;
}
void CMainFrame : : OnMouseEventsAddress ( wxMouseEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
if ( fOnSetFocusAddress )
m_textCtrlAddress - > SetSelection ( - 1 , - 1 ) ;
fOnSetFocusAddress = false ;
}
2010-02-20 13:59:59 -08:00
void CMainFrame : : OnButtonNew ( wxCommandEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Ask name
CGetTextFromUserDialog dialog ( this ,
_ ( " New Receiving Address " ) ,
_ ( " It's good policy to use a new address for each payment you receive. \n \n Label " ) ,
" " ) ;
2009-08-29 20:46:39 -07:00
if ( ! dialog . ShowModal ( ) )
return ;
2010-02-20 13:59:59 -08:00
string strName = dialog . GetValue ( ) ;
// Generate new key
string strAddress = PubKeyToAddress ( GenerateNewKey ( ) ) ;
// Save
SetAddressBookName ( strAddress , strName ) ;
SetDefaultReceivingAddress ( strAddress ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-14 20:03:07 -08:00
void CMainFrame : : OnButtonCopy ( wxCommandEvent & event )
{
// Copy address box to clipboard
if ( wxTheClipboard - > Open ( ) )
{
wxTheClipboard - > SetData ( new wxTextDataObject ( m_textCtrlAddress - > GetValue ( ) ) ) ;
wxTheClipboard - > Close ( ) ;
}
}
2010-02-03 14:58:40 -08:00
void CMainFrame : : OnListItemActivated ( wxListEvent & event )
2009-08-29 20:46:39 -07:00
{
uint256 hash ( ( string ) GetItemText ( m_listCtrl , event . GetIndex ( ) , 1 ) ) ;
CWalletTx wtx ;
CRITICAL_BLOCK ( cs_mapWallet )
{
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( hash ) ;
if ( mi = = mapWallet . end ( ) )
{
2010-02-03 14:58:40 -08:00
printf ( " CMainFrame::OnListItemActivated() : tx not found in mapWallet \n " ) ;
2009-08-29 20:46:39 -07:00
return ;
}
wtx = ( * mi ) . second ;
}
CTxDetailsDialog dialog ( this , wtx ) ;
dialog . ShowModal ( ) ;
//CTxDetailsDialog* pdialog = new CTxDetailsDialog(this, wtx);
//pdialog->Show();
}
//////////////////////////////////////////////////////////////////////////////
//
// CTxDetailsDialog
//
CTxDetailsDialog : : CTxDetailsDialog ( wxWindow * parent , CWalletTx wtx ) : CTxDetailsDialogBase ( parent )
{
2010-02-12 12:38:44 -08:00
CRITICAL_BLOCK ( cs_mapAddressBook )
{
string strHTML ;
strHTML . reserve ( 4000 ) ;
strHTML + = " <html><font face='verdana, arial, helvetica, sans-serif'> " ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
int64 nTime = wtx . GetTxTime ( ) ;
int64 nCredit = wtx . GetCredit ( ) ;
int64 nDebit = wtx . GetDebit ( ) ;
int64 nNet = nCredit - nDebit ;
2009-08-29 20:46:39 -07:00
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Status:</b> " ) + FormatTxStatus ( wtx ) ;
2010-02-12 12:38:44 -08:00
int nRequests = wtx . GetRequestCount ( ) ;
if ( nRequests ! = - 1 )
{
if ( nRequests = = 0 )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " , has not been successfully broadcast yet " ) ;
2010-02-12 12:38:44 -08:00
else if ( nRequests = = 1 )
2010-02-17 09:22:01 -08:00
strHTML + = strprintf ( _ ( " , broadcast through %d node " ) , nRequests ) ;
2010-02-12 12:38:44 -08:00
else
2010-02-17 09:22:01 -08:00
strHTML + = strprintf ( _ ( " , broadcast through %d nodes " ) , nRequests ) ;
2010-02-12 12:38:44 -08:00
}
strHTML + = " <br> " ;
2009-11-12 17:23:08 -08:00
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Date:</b> " ) + ( nTime ? DateTimeStr ( nTime ) : " " ) + " <br> " ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
//
// From
//
if ( wtx . IsCoinBase ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Source:</b> Generated<br> " ) ;
2010-02-12 12:38:44 -08:00
}
else if ( ! wtx . mapValue [ " from " ] . empty ( ) )
{
// Online transaction
if ( ! wtx . mapValue [ " from " ] . empty ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>From:</b> " ) + HtmlEscape ( wtx . mapValue [ " from " ] ) + " <br> " ;
2010-02-12 12:38:44 -08:00
}
else
{
// Offline transaction
if ( nNet > 0 )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
// Credit
foreach ( const CTxOut & txout , wtx . vout )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
if ( txout . IsMine ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
vector < unsigned char > vchPubKey ;
if ( ExtractPubKey ( txout . scriptPubKey , true , vchPubKey ) )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
string strAddress = PubKeyToAddress ( vchPubKey ) ;
if ( mapAddressBook . count ( strAddress ) )
{
2010-02-17 09:22:01 -08:00
strHTML + = string ( ) + _ ( " <b>From:</b> " ) + _ ( " unknown " ) + " <br> " ;
strHTML + = _ ( " <b>To:</b> " ) ;
2010-02-12 12:38:44 -08:00
strHTML + = HtmlEscape ( strAddress ) ;
if ( ! mapAddressBook [ strAddress ] . empty ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " (yours, label: " ) + mapAddressBook [ strAddress ] + " ) " ;
2010-02-12 12:38:44 -08:00
else
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " (yours) " ) ;
2010-02-12 12:38:44 -08:00
strHTML + = " <br> " ;
}
2009-08-29 20:46:39 -07:00
}
2010-02-12 12:38:44 -08:00
break ;
2009-08-29 20:46:39 -07:00
}
}
}
}
//
2010-02-12 12:38:44 -08:00
// To
2009-08-29 20:46:39 -07:00
//
2010-02-12 12:38:44 -08:00
string strAddress ;
if ( ! wtx . mapValue [ " to " ] . empty ( ) )
{
// Online transaction
strAddress = wtx . mapValue [ " to " ] ;
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>To:</b> " ) ;
2010-02-12 12:38:44 -08:00
if ( mapAddressBook . count ( strAddress ) & & ! mapAddressBook [ strAddress ] . empty ( ) )
strHTML + = mapAddressBook [ strAddress ] + " " ;
strHTML + = HtmlEscape ( strAddress ) + " <br> " ;
}
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
//
// Amount
//
if ( wtx . IsCoinBase ( ) & & nCredit = = 0 )
2009-08-29 20:46:39 -07:00
{
//
2010-02-12 12:38:44 -08:00
// Coinbase
2009-08-29 20:46:39 -07:00
//
2010-02-12 12:38:44 -08:00
int64 nUnmatured = 0 ;
2009-08-29 20:46:39 -07:00
foreach ( const CTxOut & txout , wtx . vout )
2010-02-12 12:38:44 -08:00
nUnmatured + = txout . GetCredit ( ) ;
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Credit:</b> " ) ;
2010-02-12 12:38:44 -08:00
if ( wtx . IsInMainChain ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = strprintf ( _ ( " (%s matures in %d more blocks) " ) , FormatMoney ( nUnmatured ) . c_str ( ) , wtx . GetBlocksToMaturity ( ) ) ;
2010-02-12 12:38:44 -08:00
else
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " (not accepted) " ) ;
strHTML + = " <br> " ;
2010-02-12 12:38:44 -08:00
}
else if ( nNet > 0 )
{
//
// Credit
//
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Credit:</b> " ) + FormatMoney ( nNet ) + " <br> " ;
2010-02-12 12:38:44 -08:00
}
else
{
bool fAllFromMe = true ;
foreach ( const CTxIn & txin , wtx . vin )
fAllFromMe = fAllFromMe & & txin . IsMine ( ) ;
bool fAllToMe = true ;
foreach ( const CTxOut & txout , wtx . vout )
fAllToMe = fAllToMe & & txout . IsMine ( ) ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
if ( fAllFromMe )
{
//
// Debit
//
foreach ( const CTxOut & txout , wtx . vout )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
if ( txout . IsMine ( ) )
continue ;
if ( wtx . mapValue [ " to " ] . empty ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
// Offline transaction
uint160 hash160 ;
if ( ExtractHash160 ( txout . scriptPubKey , hash160 ) )
{
string strAddress = Hash160ToAddress ( hash160 ) ;
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>To:</b> " ) ;
2010-02-12 12:38:44 -08:00
if ( mapAddressBook . count ( strAddress ) & & ! mapAddressBook [ strAddress ] . empty ( ) )
strHTML + = mapAddressBook [ strAddress ] + " " ;
strHTML + = strAddress ;
strHTML + = " <br> " ;
}
2009-08-29 20:46:39 -07:00
}
2010-02-12 12:38:44 -08:00
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Debit:</b> " ) + FormatMoney ( - txout . nValue ) + " <br> " ;
2009-08-29 20:46:39 -07:00
}
2010-02-12 12:38:44 -08:00
if ( fAllToMe )
{
// Payment to self
/// issue: can't tell which is the payment and which is the change anymore
//int64 nValue = wtx.vout[0].nValue;
2010-02-17 09:22:01 -08:00
//strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";
//strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";
2010-02-12 12:38:44 -08:00
}
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
int64 nTxFee = nDebit - wtx . GetValueOut ( ) ;
if ( nTxFee > 0 )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Transaction fee:</b> " ) + FormatMoney ( - nTxFee ) + " <br> " ;
2010-02-12 12:38:44 -08:00
}
else
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
//
// Mixed debit transaction
//
foreach ( const CTxIn & txin , wtx . vin )
if ( txin . IsMine ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Debit:</b> " ) + FormatMoney ( - txin . GetDebit ( ) ) + " <br> " ;
2010-02-12 12:38:44 -08:00
foreach ( const CTxOut & txout , wtx . vout )
if ( txout . IsMine ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Credit:</b> " ) + FormatMoney ( txout . GetCredit ( ) ) + " <br> " ;
2009-08-29 20:46:39 -07:00
}
}
2010-02-17 09:22:01 -08:00
strHTML + = _ ( " <b>Net amount:</b> " ) + FormatMoney ( nNet , true ) + " <br> " ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
//
// Message
//
if ( ! wtx . mapValue [ " message " ] . empty ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = string ( ) + " <br><b> " + _ ( " Message: " ) + " </b><br> " + HtmlEscape ( wtx . mapValue [ " message " ] , true ) + " <br> " ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
if ( wtx . IsCoinBase ( ) )
2010-02-17 09:22:01 -08:00
strHTML + = string ( ) + " <br> " + _ ( " Generated coins must wait 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, it will change to \" not accepted \" and not be spendable. This may occasionally happen if another node generates a block within a few seconds of yours. " ) + " <br> " ;
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
//
// Debug view
//
if ( fDebug )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
strHTML + = " <hr><br>debug print<br><br> " ;
2009-08-29 20:46:39 -07:00
foreach ( const CTxIn & txin , wtx . vin )
2010-02-12 12:38:44 -08:00
if ( txin . IsMine ( ) )
strHTML + = " <b>Debit:</b> " + FormatMoney ( - txin . GetDebit ( ) ) + " <br> " ;
foreach ( const CTxOut & txout , wtx . vout )
if ( txout . IsMine ( ) )
strHTML + = " <b>Credit:</b> " + FormatMoney ( txout . GetCredit ( ) ) + " <br> " ;
strHTML + = " <b>Inputs:</b><br> " ;
CRITICAL_BLOCK ( cs_mapWallet )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
foreach ( const CTxIn & txin , wtx . vin )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
COutPoint prevout = txin . prevout ;
map < uint256 , CWalletTx > : : iterator mi = mapWallet . find ( prevout . hash ) ;
if ( mi ! = mapWallet . end ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-12 12:38:44 -08:00
const CWalletTx & prev = ( * mi ) . second ;
if ( prevout . n < prev . vout . size ( ) )
{
strHTML + = HtmlEscape ( prev . ToString ( ) , true ) ;
strHTML + = " " + FormatTxStatus ( prev ) + " , " ;
strHTML = strHTML + " IsMine= " + ( prev . vout [ prevout . n ] . IsMine ( ) ? " true " : " false " ) + " <br> " ;
}
2009-08-29 20:46:39 -07:00
}
}
}
2010-02-12 12:38:44 -08:00
strHTML + = " <br><hr><br><b>Transaction:</b><br> " ;
strHTML + = HtmlEscape ( wtx . ToString ( ) , true ) ;
}
2009-08-29 20:46:39 -07:00
2010-02-12 12:38:44 -08:00
strHTML + = " </font></html> " ;
string ( strHTML . begin ( ) , strHTML . end ( ) ) . swap ( strHTML ) ;
m_htmlWin - > SetPage ( strHTML ) ;
m_buttonOK - > SetFocus ( ) ;
}
2009-08-29 20:46:39 -07:00
}
void CTxDetailsDialog : : OnButtonOK ( wxCommandEvent & event )
{
Close ( ) ;
//Destroy();
}
//////////////////////////////////////////////////////////////////////////////
//
// COptionsDialog
//
COptionsDialog : : COptionsDialog ( wxWindow * parent ) : COptionsDialogBase ( parent )
{
2009-10-20 18:08:05 -07:00
// Set up list box of page choices
2010-02-17 09:22:01 -08:00
m_listBox - > Append ( _ ( " Main " ) ) ;
//m_listBox->Append(_("Test 2"));
2009-10-20 18:08:05 -07:00
m_listBox - > SetSelection ( 0 ) ;
SelectPage ( 0 ) ;
2010-07-08 19:11:50 -07:00
# ifdef __WXGTK__
m_checkBoxStartOnSystemStartup - > SetLabel ( _ ( " &Start Bitcoin on window system startup " ) ) ;
2010-07-14 17:18:45 -07:00
if ( ! mapArgs . count ( " -minimizetotray " ) )
{
// Minimize to tray is just too buggy on Linux
fMinimizeToTray = false ;
m_checkBoxMinimizeToTray - > SetValue ( false ) ;
m_checkBoxMinimizeToTray - > Enable ( false ) ;
m_checkBoxMinimizeOnClose - > SetLabel ( _ ( " &Minimize on close " ) ) ;
}
2010-07-08 19:11:50 -07:00
# endif
# ifdef __WXMAC_OSX__
2009-12-11 08:49:21 -08:00
m_checkBoxStartOnSystemStartup - > Enable ( false ) ; // not implemented yet
2009-11-12 17:23:08 -08:00
# endif
2009-10-20 18:08:05 -07:00
// Init values
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTransactionFee ) ) ;
m_checkBoxLimitProcessors - > SetValue ( fLimitProcessors ) ;
m_spinCtrlLimitProcessors - > Enable ( fLimitProcessors ) ;
m_spinCtrlLimitProcessors - > SetValue ( nLimitProcessors ) ;
2009-11-04 20:41:36 -08:00
int nProcessors = wxThread : : GetCPUCount ( ) ;
2009-10-20 18:08:05 -07:00
if ( nProcessors < 1 )
nProcessors = 999 ;
m_spinCtrlLimitProcessors - > SetRange ( 1 , nProcessors ) ;
m_checkBoxStartOnSystemStartup - > SetValue ( fTmpStartOnSystemStartup = GetStartOnSystemStartup ( ) ) ;
m_checkBoxMinimizeToTray - > SetValue ( fMinimizeToTray ) ;
2009-11-12 17:23:08 -08:00
m_checkBoxMinimizeOnClose - > SetValue ( fMinimizeOnClose ) ;
2009-10-28 19:52:48 -07:00
m_checkBoxUseProxy - > SetValue ( fUseProxy ) ;
m_textCtrlProxyIP - > Enable ( fUseProxy ) ;
m_textCtrlProxyPort - > Enable ( fUseProxy ) ;
m_staticTextProxyIP - > Enable ( fUseProxy ) ;
m_staticTextProxyPort - > Enable ( fUseProxy ) ;
m_textCtrlProxyIP - > SetValue ( addrProxy . ToStringIP ( ) ) ;
m_textCtrlProxyPort - > SetValue ( addrProxy . ToStringPort ( ) ) ;
2009-08-29 20:46:39 -07:00
m_buttonOK - > SetFocus ( ) ;
2009-10-20 18:08:05 -07:00
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
void COptionsDialog : : SelectPage ( int nPage )
{
m_panelMain - > Show ( nPage = = 0 ) ;
m_panelTest2 - > Show ( nPage = = 1 ) ;
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
m_scrolledWindow - > Layout ( ) ;
m_scrolledWindow - > SetScrollbars ( 0 , 0 , 0 , 0 , 0 , 0 ) ;
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
void COptionsDialog : : OnListBox ( wxCommandEvent & event )
{
SelectPage ( event . GetSelection ( ) ) ;
2009-08-29 20:46:39 -07:00
}
2009-10-20 18:08:05 -07:00
void COptionsDialog : : OnKillFocusTransactionFee ( wxFocusEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-10-20 18:08:05 -07:00
int64 nTmp = nTransactionFee ;
ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTmp ) ;
m_textCtrlTransactionFee - > SetValue ( FormatMoney ( nTmp ) ) ;
2009-08-29 20:46:39 -07:00
}
2009-10-20 18:08:05 -07:00
void COptionsDialog : : OnCheckBoxLimitProcessors ( wxCommandEvent & event )
2009-08-29 20:46:39 -07:00
{
2009-10-20 18:08:05 -07:00
m_spinCtrlLimitProcessors - > Enable ( event . IsChecked ( ) ) ;
}
2009-09-23 21:09:56 -07:00
2009-10-28 19:52:48 -07:00
void COptionsDialog : : OnCheckBoxUseProxy ( wxCommandEvent & event )
{
m_textCtrlProxyIP - > Enable ( event . IsChecked ( ) ) ;
m_textCtrlProxyPort - > Enable ( event . IsChecked ( ) ) ;
m_staticTextProxyIP - > Enable ( event . IsChecked ( ) ) ;
m_staticTextProxyPort - > Enable ( event . IsChecked ( ) ) ;
}
CAddress COptionsDialog : : GetProxyAddr ( )
{
// Be careful about byte order, addr.ip and addr.port are big endian
CAddress addr ( m_textCtrlProxyIP - > GetValue ( ) + " : " + m_textCtrlProxyPort - > GetValue ( ) ) ;
if ( addr . ip = = INADDR_NONE )
addr . ip = addrProxy . ip ;
int nPort = atoi ( m_textCtrlProxyPort - > GetValue ( ) ) ;
addr . port = htons ( nPort ) ;
if ( nPort < = 0 | | nPort > USHRT_MAX )
addr . port = addrProxy . port ;
return addr ;
}
void COptionsDialog : : OnKillFocusProxy ( wxFocusEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-10-28 19:52:48 -07:00
m_textCtrlProxyIP - > SetValue ( GetProxyAddr ( ) . ToStringIP ( ) ) ;
m_textCtrlProxyPort - > SetValue ( GetProxyAddr ( ) . ToStringPort ( ) ) ;
}
2009-10-20 18:08:05 -07:00
void COptionsDialog : : OnButtonOK ( wxCommandEvent & event )
{
OnButtonApply ( event ) ;
2009-08-29 20:46:39 -07:00
Close ( ) ;
}
void COptionsDialog : : OnButtonCancel ( wxCommandEvent & event )
{
Close ( ) ;
}
2009-10-20 18:08:05 -07:00
void COptionsDialog : : OnButtonApply ( wxCommandEvent & event )
2009-09-23 21:09:56 -07:00
{
2009-10-20 18:08:05 -07:00
CWalletDB walletdb ;
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
int64 nPrevTransactionFee = nTransactionFee ;
if ( ParseMoney ( m_textCtrlTransactionFee - > GetValue ( ) , nTransactionFee ) & & nTransactionFee ! = nPrevTransactionFee )
walletdb . WriteSetting ( " nTransactionFee " , nTransactionFee ) ;
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
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 ) ;
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
if ( fTmpStartOnSystemStartup ! = m_checkBoxStartOnSystemStartup - > GetValue ( ) )
{
fTmpStartOnSystemStartup = m_checkBoxStartOnSystemStartup - > GetValue ( ) ;
SetStartOnSystemStartup ( fTmpStartOnSystemStartup ) ;
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
if ( fMinimizeToTray ! = m_checkBoxMinimizeToTray - > GetValue ( ) )
{
fMinimizeToTray = m_checkBoxMinimizeToTray - > GetValue ( ) ;
walletdb . WriteSetting ( " fMinimizeToTray " , fMinimizeToTray ) ;
2009-11-12 17:23:08 -08:00
ptaskbaricon - > Show ( fMinimizeToTray | | fClosedToTray ) ;
2009-10-20 18:08:05 -07:00
}
2009-11-12 17:23:08 -08:00
if ( fMinimizeOnClose ! = m_checkBoxMinimizeOnClose - > GetValue ( ) )
2009-10-20 18:08:05 -07:00
{
2009-11-12 17:23:08 -08:00
fMinimizeOnClose = m_checkBoxMinimizeOnClose - > GetValue ( ) ;
2009-10-20 18:08:05 -07:00
walletdb . WriteSetting ( " fMinimizeOnClose " , fMinimizeOnClose ) ;
}
2009-10-28 19:52:48 -07:00
2009-11-04 20:41:36 -08:00
fUseProxy = m_checkBoxUseProxy - > GetValue ( ) ;
walletdb . WriteSetting ( " fUseProxy " , fUseProxy ) ;
2009-10-28 19:52:48 -07:00
2009-11-04 20:41:36 -08:00
addrProxy = GetProxyAddr ( ) ;
walletdb . WriteSetting ( " addrProxy " , addrProxy ) ;
2009-09-23 21:09:56 -07:00
}
2009-08-29 20:46:39 -07:00
//////////////////////////////////////////////////////////////////////////////
//
// CAboutDialog
//
CAboutDialog : : CAboutDialog ( wxWindow * parent ) : CAboutDialogBase ( parent )
{
2010-07-03 23:15:06 -07:00
m_staticTextVersion - > SetLabel ( strprintf ( _ ( " version %d.%d.%d beta " ) , VERSION / 10000 , ( VERSION / 100 ) % 100 , VERSION % 100 ) ) ;
2009-08-29 20:46:39 -07:00
2010-02-17 09:22:01 -08:00
// Change (c) into UTF-8 or ANSI copyright symbol
2009-08-29 20:46:39 -07:00
wxString str = m_staticTextMain - > GetLabel ( ) ;
2010-02-17 09:22:01 -08:00
# if wxUSE_UNICODE
str . Replace ( " (c) " , wxString : : FromUTF8 ( " \xC2 \xA9 " ) ) ;
# else
str . Replace ( " (c) " , " \xA9 " ) ;
2010-01-28 13:49:20 -08:00
# endif
2010-02-17 09:22:01 -08:00
m_staticTextMain - > SetLabel ( str ) ;
2009-11-12 17:23:08 -08:00
# ifndef __WXMSW__
2010-02-03 14:58:40 -08:00
// Resize on Linux to make the window fit the text.
// The text was wrapped manually rather than using the Wrap setting because
// the wrap would be too small on Linux and it can't be changed at this point.
wxFont fontTmp = m_staticTextMain - > GetFont ( ) ;
if ( fontTmp . GetPointSize ( ) > 8 ) ;
fontTmp . SetPointSize ( 8 ) ;
m_staticTextMain - > SetFont ( fontTmp ) ;
2010-02-17 09:22:01 -08:00
SetSize ( GetSize ( ) . GetWidth ( ) + 44 , GetSize ( ) . GetHeight ( ) + 10 ) ;
2009-11-12 17:23:08 -08:00
# endif
2009-08-29 20:46:39 -07:00
}
void CAboutDialog : : OnButtonOK ( wxCommandEvent & event )
{
Close ( ) ;
}
//////////////////////////////////////////////////////////////////////////////
//
// CSendDialog
//
CSendDialog : : CSendDialog ( wxWindow * parent , const wxString & strAddress ) : CSendDialogBase ( parent )
{
// Init
m_textCtrlAddress - > SetValue ( strAddress ) ;
m_choiceTransferType - > SetSelection ( 0 ) ;
m_bitmapCheckMark - > Show ( false ) ;
2009-10-20 18:08:05 -07:00
fEnabledPrev = true ;
2009-11-06 21:05:03 -08:00
m_textCtrlAddress - > SetFocus ( ) ;
2009-08-29 20:46:39 -07:00
//// todo: should add a display of your balance for convenience
2009-11-06 21:05:03 -08:00
# ifndef __WXMSW__
wxFont fontTmp = m_staticTextInstructions - > GetFont ( ) ;
2009-11-07 10:51:41 -08:00
if ( fontTmp . GetPointSize ( ) > 9 ) ;
fontTmp . SetPointSize ( 9 ) ;
2009-11-06 21:05:03 -08:00
m_staticTextInstructions - > SetFont ( fontTmp ) ;
2010-01-28 13:49:20 -08:00
SetSize ( 725 , 380 ) ;
2009-11-06 21:05:03 -08:00
# endif
2009-08-29 20:46:39 -07:00
// Set Icon
wxIcon iconSend ;
2009-11-04 20:41:36 -08:00
iconSend . CopyFromBitmap ( wxBitmap ( send16noshadow_xpm ) ) ;
2009-08-29 20:46:39 -07:00
SetIcon ( iconSend ) ;
wxCommandEvent event ;
OnTextAddress ( event ) ;
// Fixup the tab order
m_buttonPaste - > MoveAfterInTabOrder ( m_buttonCancel ) ;
m_buttonAddress - > MoveAfterInTabOrder ( m_buttonPaste ) ;
this - > Layout ( ) ;
}
void CSendDialog : : OnTextAddress ( wxCommandEvent & event )
{
// Check mark
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
bool fBitcoinAddress = IsValidBitcoinAddress ( m_textCtrlAddress - > GetValue ( ) ) ;
m_bitmapCheckMark - > Show ( fBitcoinAddress ) ;
// Grey out message if bitcoin address
bool fEnable = ! fBitcoinAddress ;
m_staticTextFrom - > Enable ( fEnable ) ;
m_textCtrlFrom - > Enable ( fEnable ) ;
m_staticTextMessage - > Enable ( fEnable ) ;
m_textCtrlMessage - > Enable ( fEnable ) ;
m_textCtrlMessage - > SetBackgroundColour ( wxSystemSettings : : GetColour ( fEnable ? wxSYS_COLOUR_WINDOW : wxSYS_COLOUR_BTNFACE ) ) ;
2009-10-20 18:08:05 -07:00
if ( ! fEnable & & fEnabledPrev )
{
strFromSave = m_textCtrlFrom - > GetValue ( ) ;
strMessageSave = m_textCtrlMessage - > GetValue ( ) ;
2010-02-17 09:22:01 -08:00
m_textCtrlFrom - > SetValue ( _ ( " Will appear as \" From: Unknown \" " ) ) ;
m_textCtrlMessage - > SetValue ( _ ( " Can't include a message when sending to a Bitcoin address " ) ) ;
2009-10-20 18:08:05 -07:00
}
else if ( fEnable & & ! fEnabledPrev )
{
m_textCtrlFrom - > SetValue ( strFromSave ) ;
m_textCtrlMessage - > SetValue ( strMessageSave ) ;
}
fEnabledPrev = fEnable ;
2009-08-29 20:46:39 -07:00
}
void CSendDialog : : OnKillFocusAmount ( wxFocusEvent & event )
{
// Reformat the amount
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-08-29 20:46:39 -07:00
if ( m_textCtrlAmount - > GetValue ( ) . Trim ( ) . empty ( ) )
return ;
int64 nTmp ;
if ( ParseMoney ( m_textCtrlAmount - > GetValue ( ) , nTmp ) )
m_textCtrlAmount - > SetValue ( FormatMoney ( nTmp ) ) ;
}
void CSendDialog : : OnButtonAddressBook ( wxCommandEvent & event )
{
// Open address book
2010-02-20 13:59:59 -08:00
CAddressBookDialog dialog ( this , m_textCtrlAddress - > GetValue ( ) , CAddressBookDialog : : SENDING , true ) ;
2009-08-29 20:46:39 -07:00
if ( dialog . ShowModal ( ) )
2010-02-20 13:59:59 -08:00
m_textCtrlAddress - > SetValue ( dialog . GetSelectedAddress ( ) ) ;
2009-08-29 20:46:39 -07:00
}
void CSendDialog : : OnButtonPaste ( wxCommandEvent & event )
{
// Copy clipboard to address box
if ( wxTheClipboard - > Open ( ) )
{
if ( wxTheClipboard - > IsSupported ( wxDF_TEXT ) )
{
wxTextDataObject data ;
wxTheClipboard - > GetData ( data ) ;
m_textCtrlAddress - > SetValue ( data . GetText ( ) ) ;
}
wxTheClipboard - > Close ( ) ;
}
}
void CSendDialog : : OnButtonSend ( wxCommandEvent & event )
{
CWalletTx wtx ;
string strAddress = ( string ) m_textCtrlAddress - > GetValue ( ) ;
// Parse amount
int64 nValue = 0 ;
if ( ! ParseMoney ( m_textCtrlAmount - > GetValue ( ) , nValue ) | | nValue < = 0 )
{
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " Error in amount " ) , _ ( " Send Coins " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
if ( nValue > GetBalance ( ) )
{
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " Amount exceeds your balance " ) , _ ( " Send Coins " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
if ( nValue + nTransactionFee > GetBalance ( ) )
{
2010-02-17 09:22:01 -08:00
wxMessageBox ( string ( _ ( " Total exceeds your balance when the " ) ) + FormatMoney ( nTransactionFee ) + _ ( " transaction fee is included " ) , _ ( " Send Coins " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// Parse bitcoin address
uint160 hash160 ;
bool fBitcoinAddress = AddressToHash160 ( strAddress , hash160 ) ;
if ( fBitcoinAddress )
{
// Send to bitcoin address
CScript scriptPubKey ;
scriptPubKey < < OP_DUP < < OP_HASH160 < < hash160 < < OP_EQUALVERIFY < < OP_CHECKSIG ;
2010-02-20 13:59:59 -08:00
string strError = SendMoney ( scriptPubKey , nValue , wtx , true ) ;
if ( strError = = " " )
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " Payment sent " ) , _ ( " Sending... " ) ) ;
2010-02-20 13:59:59 -08:00
else if ( strError ! = " ABORTED " )
wxMessageBox ( strError + " " , _ ( " Sending... " ) ) ;
2009-08-29 20:46:39 -07:00
}
else
{
// Parse IP address
2009-10-31 18:16:51 -07:00
CAddress addr ( strAddress ) ;
if ( ! addr . IsValid ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " Invalid address " ) , _ ( " Send Coins " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// Message
wtx . mapValue [ " to " ] = strAddress ;
wtx . mapValue [ " from " ] = m_textCtrlFrom - > GetValue ( ) ;
wtx . mapValue [ " message " ] = m_textCtrlMessage - > GetValue ( ) ;
// Send to IP address
CSendingDialog * pdialog = new CSendingDialog ( this , addr , nValue , wtx ) ;
if ( ! pdialog - > ShowModal ( ) )
return ;
}
2010-02-12 12:38:44 -08:00
CRITICAL_BLOCK ( cs_mapAddressBook )
if ( ! mapAddressBook . count ( strAddress ) )
SetAddressBookName ( strAddress , " " ) ;
2009-08-29 20:46:39 -07:00
EndModal ( true ) ;
}
void CSendDialog : : OnButtonCancel ( wxCommandEvent & event )
{
// Cancel
EndModal ( false ) ;
}
//////////////////////////////////////////////////////////////////////////////
//
// CSendingDialog
//
CSendingDialog : : CSendingDialog ( wxWindow * parent , const CAddress & addrIn , int64 nPriceIn , const CWalletTx & wtxIn ) : CSendingDialogBase ( NULL ) // we have to give null so parent can't destroy us
{
addr = addrIn ;
nPrice = nPriceIn ;
wtx = wtxIn ;
start = wxDateTime : : UNow ( ) ;
2009-10-28 19:52:48 -07:00
memset ( pszStatus , 0 , sizeof ( pszStatus ) ) ;
2009-08-29 20:46:39 -07:00
fCanCancel = true ;
fAbort = false ;
fSuccess = false ;
fUIDone = false ;
fWorkDone = false ;
2009-12-11 08:49:21 -08:00
# ifndef __WXMSW__
2010-02-13 16:08:27 -08:00
SetSize ( 1.2 * GetSize ( ) . GetWidth ( ) , 1.08 * GetSize ( ) . GetHeight ( ) ) ;
2009-12-11 08:49:21 -08:00
# endif
2009-08-29 20:46:39 -07:00
2010-02-17 09:22:01 -08:00
SetTitle ( strprintf ( _ ( " Sending %s to %s " ) , FormatMoney ( nPrice ) . c_str ( ) , wtx . mapValue [ " to " ] . c_str ( ) ) ) ;
2009-08-29 20:46:39 -07:00
m_textCtrlStatus - > SetValue ( " " ) ;
2009-11-12 17:23:08 -08:00
CreateThread ( SendingDialogStartTransfer , this ) ;
2009-08-29 20:46:39 -07:00
}
CSendingDialog : : ~ CSendingDialog ( )
{
printf ( " ~CSendingDialog() \n " ) ;
}
void CSendingDialog : : Close ( )
{
// Last one out turn out the lights.
// fWorkDone signals that work side is done and UI thread should call destroy.
// fUIDone signals that UI window has closed and work thread should call destroy.
// This allows the window to disappear and end modality when cancelled
// without making the user wait for ConnectNode to return. The dialog object
// hangs around in the background until the work thread exits.
if ( IsModal ( ) )
EndModal ( fSuccess ) ;
else
Show ( false ) ;
if ( fWorkDone )
Destroy ( ) ;
else
fUIDone = true ;
}
void CSendingDialog : : OnClose ( wxCloseEvent & event )
{
if ( ! event . CanVeto ( ) | | fWorkDone | | fAbort | | ! fCanCancel )
{
Close ( ) ;
}
else
{
event . Veto ( ) ;
wxCommandEvent cmdevent ;
OnButtonCancel ( cmdevent ) ;
}
}
void CSendingDialog : : OnButtonOK ( wxCommandEvent & event )
{
if ( fWorkDone )
Close ( ) ;
}
void CSendingDialog : : OnButtonCancel ( wxCommandEvent & event )
{
if ( fCanCancel )
fAbort = true ;
}
void CSendingDialog : : OnPaint ( wxPaintEvent & event )
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
2009-10-28 19:52:48 -07:00
if ( strlen ( pszStatus ) > 130 )
m_textCtrlStatus - > SetValue ( string ( " \n " ) + pszStatus ) ;
2009-08-29 20:46:39 -07:00
else
2009-10-28 19:52:48 -07:00
m_textCtrlStatus - > SetValue ( string ( " \n \n " ) + pszStatus ) ;
2009-08-29 20:46:39 -07:00
m_staticTextSending - > SetFocus ( ) ;
if ( ! fCanCancel )
m_buttonCancel - > Enable ( false ) ;
if ( fWorkDone )
{
m_buttonOK - > Enable ( true ) ;
m_buttonOK - > SetFocus ( ) ;
m_buttonCancel - > Enable ( false ) ;
}
if ( fAbort & & fCanCancel & & IsShown ( ) )
{
2010-02-17 09:22:01 -08:00
strcpy ( pszStatus , _ ( " CANCELLED " ) ) ;
2009-08-29 20:46:39 -07:00
m_buttonOK - > Enable ( true ) ;
m_buttonOK - > SetFocus ( ) ;
m_buttonCancel - > Enable ( false ) ;
2010-02-17 09:22:01 -08:00
m_buttonCancel - > SetLabel ( _ ( " Cancelled " ) ) ;
2009-08-29 20:46:39 -07:00
Close ( ) ;
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " Transfer cancelled " ) , _ ( " Sending... " ) , wxOK , this ) ;
2009-08-29 20:46:39 -07:00
}
}
//
// Everything from here on is not in the UI thread and must only communicate
// with the rest of the dialog through variables and calling repaint.
//
void CSendingDialog : : Repaint ( )
{
Refresh ( ) ;
wxPaintEvent event ;
2010-01-28 13:49:20 -08:00
GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2009-08-29 20:46:39 -07:00
}
bool CSendingDialog : : Status ( )
{
if ( fUIDone )
{
Destroy ( ) ;
return false ;
}
if ( fAbort & & fCanCancel )
{
2009-10-28 19:52:48 -07:00
memset ( pszStatus , 0 , 10 ) ;
2010-02-17 09:22:01 -08:00
strcpy ( pszStatus , _ ( " CANCELLED " ) ) ;
2009-08-29 20:46:39 -07:00
Repaint ( ) ;
fWorkDone = true ;
return false ;
}
return true ;
}
bool CSendingDialog : : Status ( const string & str )
{
if ( ! Status ( ) )
return false ;
2009-10-28 19:52:48 -07:00
// This can be read by the UI thread at any time,
// so copy in a way that can be read cleanly at all times.
memset ( pszStatus , 0 , min ( str . size ( ) + 1 , sizeof ( pszStatus ) ) ) ;
strlcpy ( pszStatus , str . c_str ( ) , sizeof ( pszStatus ) ) ;
2009-08-29 20:46:39 -07:00
Repaint ( ) ;
return true ;
}
bool CSendingDialog : : Error ( const string & str )
{
fCanCancel = false ;
fWorkDone = true ;
2010-02-17 09:22:01 -08:00
Status ( string ( _ ( " Error: " ) ) + str ) ;
2009-08-29 20:46:39 -07:00
return false ;
}
void SendingDialogStartTransfer ( void * parg )
{
( ( CSendingDialog * ) parg ) - > StartTransfer ( ) ;
}
void CSendingDialog : : StartTransfer ( )
{
// Make sure we have enough money
if ( nPrice + nTransactionFee > GetBalance ( ) )
{
2010-02-25 13:55:27 -08:00
Error ( _ ( " Insufficient funds " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// We may have connected already for product details
2010-02-17 09:22:01 -08:00
if ( ! Status ( _ ( " Connecting... " ) ) )
2009-08-29 20:46:39 -07:00
return ;
2009-11-18 11:19:41 -08:00
CNode * pnode = ConnectNode ( addr , 15 * 60 ) ;
2009-08-29 20:46:39 -07:00
if ( ! pnode )
{
2010-02-17 09:22:01 -08:00
Error ( _ ( " Unable to connect " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// Send order to seller, with response going to OnReply2 via event handler
2010-02-17 09:22:01 -08:00
if ( ! Status ( _ ( " Requesting public key... " ) ) )
2009-08-29 20:46:39 -07:00
return ;
pnode - > PushRequest ( " checkorder " , wtx , SendingDialogOnReply2 , this ) ;
}
void SendingDialogOnReply2 ( void * parg , CDataStream & vRecv )
{
( ( CSendingDialog * ) parg ) - > OnReply2 ( vRecv ) ;
}
void CSendingDialog : : OnReply2 ( CDataStream & vRecv )
{
2010-02-17 09:22:01 -08:00
if ( ! Status ( _ ( " Received public key... " ) ) )
2009-08-29 20:46:39 -07:00
return ;
CScript scriptPubKey ;
int nRet ;
try
{
vRecv > > nRet ;
if ( nRet > 0 )
{
string strMessage ;
vRecv > > strMessage ;
2010-02-17 09:22:01 -08:00
Error ( _ ( " Transfer was not accepted " ) ) ;
2009-08-29 20:46:39 -07:00
//// todo: enlarge the window and enable a hidden white box to put seller's message
return ;
}
vRecv > > scriptPubKey ;
}
catch ( . . . )
{
//// what do we want to do about this?
2010-02-17 09:22:01 -08:00
Error ( _ ( " Invalid response received " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// Pause to give the user a chance to cancel
while ( wxDateTime : : UNow ( ) < start + wxTimeSpan ( 0 , 0 , 0 , 2 * 1000 ) )
{
Sleep ( 200 ) ;
if ( ! Status ( ) )
return ;
}
CRITICAL_BLOCK ( cs_main )
{
// Pay
2010-02-17 09:22:01 -08:00
if ( ! Status ( _ ( " Creating transaction... " ) ) )
2009-08-29 20:46:39 -07:00
return ;
if ( nPrice + nTransactionFee > GetBalance ( ) )
{
2010-02-25 13:55:27 -08:00
Error ( _ ( " Insufficient funds " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
2009-10-20 18:08:05 -07:00
CKey key ;
2009-08-29 20:46:39 -07:00
int64 nFeeRequired ;
2009-10-20 18:08:05 -07:00
if ( ! CreateTransaction ( scriptPubKey , nPrice , wtx , key , nFeeRequired ) )
2009-08-29 20:46:39 -07:00
{
if ( nPrice + nFeeRequired > GetBalance ( ) )
2010-02-17 09:22:01 -08:00
Error ( strprintf ( _ ( " This is an oversized transaction that requires a transaction fee of %s " ) , FormatMoney ( nFeeRequired ) . c_str ( ) ) ) ;
2009-08-29 20:46:39 -07:00
else
2010-02-17 09:22:01 -08:00
Error ( _ ( " Transaction creation failed " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
2010-02-20 13:59:59 -08:00
// Transaction fee
if ( ! ThreadSafeAskFee ( nFeeRequired , _ ( " Sending... " ) , this ) )
{
Error ( _ ( " Transaction aborted " ) ) ;
return ;
}
2009-11-18 11:19:41 -08:00
// Make sure we're still connected
CNode * pnode = ConnectNode ( addr , 2 * 60 * 60 ) ;
if ( ! pnode )
{
2010-02-17 09:22:01 -08:00
Error ( _ ( " Lost connection, transaction cancelled " ) ) ;
2009-11-18 11:19:41 -08:00
return ;
}
2009-08-29 20:46:39 -07:00
// Last chance to cancel
Sleep ( 50 ) ;
if ( ! Status ( ) )
return ;
fCanCancel = false ;
if ( fAbort )
{
fCanCancel = true ;
if ( ! Status ( ) )
return ;
fCanCancel = false ;
}
2010-02-17 09:22:01 -08:00
if ( ! Status ( _ ( " Sending payment... " ) ) )
2009-08-29 20:46:39 -07:00
return ;
// Commit
2010-02-20 13:59:59 -08:00
if ( ! CommitTransaction ( wtx , key ) )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
Error ( _ ( " The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here. " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
// Send payment tx to seller, with response going to OnReply3 via event handler
2010-06-10 16:10:30 -07:00
CWalletTx wtxSend = wtx ;
wtxSend . fFromMe = false ;
pnode - > PushRequest ( " submitorder " , wtxSend , SendingDialogOnReply3 , this ) ;
2009-08-29 20:46:39 -07:00
2010-02-17 09:22:01 -08:00
Status ( _ ( " Waiting for confirmation... " ) ) ;
2009-08-29 20:46:39 -07:00
MainFrameRepaint ( ) ;
}
}
void SendingDialogOnReply3 ( void * parg , CDataStream & vRecv )
{
( ( CSendingDialog * ) parg ) - > OnReply3 ( vRecv ) ;
}
void CSendingDialog : : OnReply3 ( CDataStream & vRecv )
{
int nRet ;
try
{
vRecv > > nRet ;
if ( nRet > 0 )
{
2010-02-17 09:22:01 -08:00
Error ( _ ( " The payment was sent, but the recipient was unable to verify it. \n "
" The transaction is recorded and will credit to the recipient, \n "
" but the comment information will be blank. " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
}
catch ( . . . )
{
//// what do we want to do about this?
2010-02-17 09:22:01 -08:00
Error ( _ ( " Payment was sent, but an invalid response was received " ) ) ;
2009-08-29 20:46:39 -07:00
return ;
}
fSuccess = true ;
fWorkDone = true ;
2010-02-17 09:22:01 -08:00
Status ( _ ( " Payment completed " ) ) ;
2009-08-29 20:46:39 -07:00
}
//////////////////////////////////////////////////////////////////////////////
//
2010-02-20 13:59:59 -08:00
// CAddressBookDialog
2009-08-29 20:46:39 -07:00
//
2010-02-20 13:59:59 -08:00
CAddressBookDialog : : CAddressBookDialog ( wxWindow * parent , const wxString & strInitSelected , int nPageIn , bool fDuringSendIn ) : CAddressBookDialogBase ( parent )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Set initially selected page
wxNotebookEvent event ;
event . SetSelection ( nPageIn ) ;
OnNotebookPageChanged ( event ) ;
m_notebook - > ChangeSelection ( nPageIn ) ;
fDuringSend = fDuringSendIn ;
if ( ! fDuringSend )
m_buttonCancel - > Show ( false ) ;
// Set Icon
wxIcon iconAddressBook ;
iconAddressBook . CopyFromBitmap ( wxBitmap ( addressbook16_xpm ) ) ;
SetIcon ( iconAddressBook ) ;
2009-08-29 20:46:39 -07:00
// Init column headers
2010-02-20 13:59:59 -08:00
m_listCtrlSending - > InsertColumn ( 0 , _ ( " Name " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrlSending - > InsertColumn ( 1 , _ ( " Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrlSending - > SetFocus ( ) ;
m_listCtrlReceiving - > InsertColumn ( 0 , _ ( " Label " ) , wxLIST_FORMAT_LEFT , 200 ) ;
m_listCtrlReceiving - > InsertColumn ( 1 , _ ( " Bitcoin Address " ) , wxLIST_FORMAT_LEFT , 350 ) ;
m_listCtrlReceiving - > SetFocus ( ) ;
2009-08-29 20:46:39 -07:00
// Fill listctrl with address book data
CRITICAL_BLOCK ( cs_mapKeys )
2010-02-12 12:38:44 -08:00
CRITICAL_BLOCK ( cs_mapAddressBook )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
string strDefaultReceiving = ( string ) pframeMain - > m_textCtrlAddress - > GetValue ( ) ;
2009-08-29 20:46:39 -07:00
foreach ( const PAIRTYPE ( string , string ) & item , mapAddressBook )
{
string strAddress = item . first ;
string strName = item . second ;
uint160 hash160 ;
bool fMine = ( AddressToHash160 ( strAddress , hash160 ) & & mapPubKeys . count ( hash160 ) ) ;
2010-02-20 13:59:59 -08:00
wxListCtrl * plistCtrl = fMine ? m_listCtrlReceiving : m_listCtrlSending ;
int nIndex = InsertLine ( plistCtrl , strName , strAddress ) ;
2010-05-18 17:26:56 -07:00
if ( strAddress = = ( fMine ? strDefaultReceiving : string ( strInitSelected ) ) )
2010-02-20 13:59:59 -08:00
plistCtrl - > SetItemState ( nIndex , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ) ;
2009-08-29 20:46:39 -07:00
}
}
}
2010-02-20 13:59:59 -08:00
wxString CAddressBookDialog : : GetSelectedAddress ( )
2009-08-29 20:46:39 -07:00
{
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
return " " ;
return GetItemText ( m_listCtrl , nIndex , 1 ) ;
}
2010-02-20 13:59:59 -08:00
wxString CAddressBookDialog : : GetSelectedSendingAddress ( )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
int nIndex = GetSelection ( m_listCtrlSending ) ;
if ( nIndex = = - 1 )
return " " ;
return GetItemText ( m_listCtrlSending , nIndex , 1 ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
wxString CAddressBookDialog : : GetSelectedReceivingAddress ( )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
int nIndex = GetSelection ( m_listCtrlReceiving ) ;
if ( nIndex = = - 1 )
return " " ;
return GetItemText ( m_listCtrlReceiving , nIndex , 1 ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnNotebookPageChanged ( wxNotebookEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
nPage = event . GetSelection ( ) ;
if ( nPage = = SENDING )
m_listCtrl = m_listCtrlSending ;
else if ( nPage = = RECEIVING )
m_listCtrl = m_listCtrlReceiving ;
m_buttonDelete - > Show ( nPage = = SENDING ) ;
m_buttonCopy - > Show ( nPage = = RECEIVING ) ;
this - > Layout ( ) ;
m_listCtrl - > SetFocus ( ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnListEndLabelEdit ( wxListEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Update address book with edited name
event . Skip ( ) ;
if ( event . IsEditCancelled ( ) )
2009-08-29 20:46:39 -07:00
return ;
2010-02-20 13:59:59 -08:00
string strAddress = ( string ) GetItemText ( m_listCtrl , event . GetIndex ( ) , 1 ) ;
SetAddressBookName ( strAddress , string ( event . GetText ( ) ) ) ;
2009-08-29 20:46:39 -07:00
pframeMain - > RefreshListCtrl ( ) ;
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnListItemSelected ( wxListEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
if ( nPage = = RECEIVING )
SetDefaultReceivingAddress ( ( string ) GetSelectedReceivingAddress ( ) ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnListItemActivated ( wxListEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
event . Skip ( ) ;
if ( fDuringSend )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Doubleclick returns selection
EndModal ( GetSelectedAddress ( ) ! = " " ? 2 : 0 ) ;
return ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
// Doubleclick edits item
wxCommandEvent event2 ;
OnButtonEdit ( event2 ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnButtonDelete ( wxCommandEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
if ( nPage ! = SENDING )
return ;
for ( int nIndex = m_listCtrl - > GetItemCount ( ) - 1 ; nIndex > = 0 ; nIndex - - )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
if ( m_listCtrl - > GetItemState ( nIndex , wxLIST_STATE_SELECTED ) )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
CWalletDB ( ) . EraseName ( strAddress ) ;
m_listCtrl - > DeleteItem ( nIndex ) ;
2009-08-29 20:46:39 -07:00
}
}
pframeMain - > RefreshListCtrl ( ) ;
}
2010-02-20 13:59:59 -08:00
void CAddressBookDialog : : OnButtonCopy ( wxCommandEvent & event )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Copy address box to clipboard
if ( wxTheClipboard - > Open ( ) )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
wxTheClipboard - > SetData ( new wxTextDataObject ( GetSelectedAddress ( ) ) ) ;
wxTheClipboard - > Close ( ) ;
2009-08-29 20:46:39 -07:00
}
}
bool CAddressBookDialog : : CheckIfMine ( const string & strAddress , const string & strTitle )
{
uint160 hash160 ;
bool fMine = ( AddressToHash160 ( strAddress , hash160 ) & & mapPubKeys . count ( hash160 ) ) ;
if ( fMine )
2010-02-17 09:22:01 -08:00
wxMessageBox ( _ ( " This is one of your own addresses for receiving payments and cannot be entered in the address book. " ) , strTitle ) ;
2009-08-29 20:46:39 -07:00
return fMine ;
}
void CAddressBookDialog : : OnButtonEdit ( wxCommandEvent & event )
{
int nIndex = GetSelection ( m_listCtrl ) ;
if ( nIndex = = - 1 )
return ;
string strName = ( string ) m_listCtrl - > GetItemText ( nIndex ) ;
string strAddress = ( string ) GetItemText ( m_listCtrl , nIndex , 1 ) ;
string strAddressOrg = strAddress ;
2010-02-20 13:59:59 -08:00
if ( nPage = = SENDING )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Ask name and address
do
{
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address " ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
if ( ! dialog . ShowModal ( ) )
return ;
strName = dialog . GetValue1 ( ) ;
strAddress = dialog . GetValue2 ( ) ;
}
while ( CheckIfMine ( strAddress , _ ( " Edit Address " ) ) ) ;
}
else if ( nPage = = RECEIVING )
{
// Ask name
CGetTextFromUserDialog dialog ( this , _ ( " Edit Address Label " ) , _ ( " Label " ) , strName ) ;
2009-08-29 20:46:39 -07:00
if ( ! dialog . ShowModal ( ) )
return ;
2010-02-20 13:59:59 -08:00
strName = dialog . GetValue ( ) ;
2009-08-29 20:46:39 -07:00
}
2010-02-20 13:59:59 -08:00
// Write back
2009-08-29 20:46:39 -07:00
if ( strAddress ! = strAddressOrg )
CWalletDB ( ) . EraseName ( strAddressOrg ) ;
SetAddressBookName ( strAddress , strName ) ;
m_listCtrl - > SetItem ( nIndex , 1 , strAddress ) ;
m_listCtrl - > SetItemText ( nIndex , strName ) ;
pframeMain - > RefreshListCtrl ( ) ;
}
void CAddressBookDialog : : OnButtonNew ( wxCommandEvent & event )
{
string strName ;
string strAddress ;
2010-02-20 13:59:59 -08:00
if ( nPage = = SENDING )
2009-08-29 20:46:39 -07:00
{
2010-02-20 13:59:59 -08:00
// Ask name and address
do
{
CGetTextFromUserDialog dialog ( this , _ ( " Add Address " ) , _ ( " Name " ) , strName , _ ( " Address " ) , strAddress ) ;
if ( ! dialog . ShowModal ( ) )
return ;
strName = dialog . GetValue1 ( ) ;
strAddress = dialog . GetValue2 ( ) ;
}
while ( CheckIfMine ( strAddress , _ ( " Add Address " ) ) ) ;
}
else if ( nPage = = RECEIVING )
{
// Ask name
CGetTextFromUserDialog dialog ( this ,
_ ( " New Receiving Address " ) ,
_ ( " It's good policy to use a new address for each payment you receive. \n \n Label " ) ,
" " ) ;
2009-08-29 20:46:39 -07:00
if ( ! dialog . ShowModal ( ) )
return ;
2010-02-20 13:59:59 -08:00
strName = dialog . GetValue ( ) ;
// Generate new key
strAddress = PubKeyToAddress ( GenerateNewKey ( ) ) ;
2009-08-29 20:46:39 -07:00
}
// Add to list and select it
SetAddressBookName ( strAddress , strName ) ;
int nIndex = InsertLine ( m_listCtrl , strName , strAddress ) ;
SetSelection ( m_listCtrl , nIndex ) ;
m_listCtrl - > SetFocus ( ) ;
2010-02-20 13:59:59 -08:00
if ( nPage = = SENDING )
pframeMain - > RefreshListCtrl ( ) ;
2009-08-29 20:46:39 -07:00
}
void CAddressBookDialog : : OnButtonOK ( wxCommandEvent & event )
{
// OK
2010-02-20 13:59:59 -08:00
EndModal ( GetSelectedAddress ( ) ! = " " ? 1 : 0 ) ;
2009-08-29 20:46:39 -07:00
}
void CAddressBookDialog : : OnButtonCancel ( wxCommandEvent & event )
{
// Cancel
EndModal ( 0 ) ;
}
void CAddressBookDialog : : OnClose ( wxCloseEvent & event )
{
// Close
EndModal ( 0 ) ;
}
2009-09-23 21:09:56 -07:00
//////////////////////////////////////////////////////////////////////////////
//
2009-10-20 18:08:05 -07:00
// CMyTaskBarIcon
2009-09-23 21:09:56 -07:00
//
2009-10-20 18:08:05 -07:00
enum
{
ID_TASKBAR_RESTORE = 10001 ,
2009-11-12 17:23:08 -08:00
ID_TASKBAR_OPTIONS ,
2009-10-20 18:08:05 -07:00
ID_TASKBAR_GENERATE ,
ID_TASKBAR_EXIT ,
2009-09-23 21:09:56 -07:00
} ;
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
BEGIN_EVENT_TABLE ( CMyTaskBarIcon , wxTaskBarIcon )
EVT_TASKBAR_LEFT_DCLICK ( CMyTaskBarIcon : : OnLeftButtonDClick )
EVT_MENU ( ID_TASKBAR_RESTORE , CMyTaskBarIcon : : OnMenuRestore )
2009-11-12 17:23:08 -08:00
EVT_MENU ( ID_TASKBAR_OPTIONS , CMyTaskBarIcon : : OnMenuOptions )
2009-10-20 18:08:05 -07:00
EVT_MENU ( ID_TASKBAR_GENERATE , CMyTaskBarIcon : : OnMenuGenerate )
EVT_UPDATE_UI ( ID_TASKBAR_GENERATE , CMyTaskBarIcon : : OnUpdateUIGenerate )
EVT_MENU ( ID_TASKBAR_EXIT , CMyTaskBarIcon : : OnMenuExit )
2009-09-23 21:09:56 -07:00
END_EVENT_TABLE ( )
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : Show ( bool fShow )
2009-09-23 21:09:56 -07:00
{
2009-10-28 19:52:48 -07:00
static char pszPrevTip [ 200 ] ;
2009-10-20 18:08:05 -07:00
if ( fShow )
{
2010-02-17 09:22:01 -08:00
string strTooltip = _ ( " Bitcoin " ) ;
2009-10-20 18:08:05 -07:00
if ( fGenerateBitcoins )
2010-02-17 09:22:01 -08:00
strTooltip = _ ( " Bitcoin - Generating " ) ;
2009-10-20 18:08:05 -07:00
if ( fGenerateBitcoins & & vNodes . empty ( ) )
2010-02-17 09:22:01 -08:00
strTooltip = _ ( " Bitcoin - (not connected) " ) ;
2009-10-28 19:52:48 -07:00
// Optimization, only update when changed, using char array to be reentrant
if ( strncmp ( pszPrevTip , strTooltip . c_str ( ) , sizeof ( pszPrevTip ) - 1 ) ! = 0 )
{
strlcpy ( pszPrevTip , strTooltip . c_str ( ) , sizeof ( pszPrevTip ) ) ;
2009-11-07 10:51:41 -08:00
# ifdef __WXMSW__
2010-06-21 20:45:37 -07:00
// somehow it'll choose the wrong size and scale it down if
2010-06-21 11:41:34 -07:00
// we use the main icon, so we hand it one with only 16x16
SetIcon ( wxICON ( favicon ) , strTooltip ) ;
2009-11-07 10:51:41 -08:00
# else
2010-06-21 10:11:26 -07:00
SetIcon ( bitcoin80_xpm , strTooltip ) ;
2009-11-07 10:51:41 -08:00
# endif
2009-10-28 19:52:48 -07:00
}
2009-10-20 18:08:05 -07:00
}
else
{
2009-10-28 19:52:48 -07:00
strlcpy ( pszPrevTip , " " , sizeof ( pszPrevTip ) ) ;
2009-10-20 18:08:05 -07:00
RemoveIcon ( ) ;
}
2009-09-23 21:09:56 -07:00
}
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : Hide ( )
2009-09-23 21:09:56 -07:00
{
2009-10-20 18:08:05 -07:00
Show ( false ) ;
2009-09-23 21:09:56 -07:00
}
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : OnLeftButtonDClick ( wxTaskBarIconEvent & event )
2009-09-23 21:09:56 -07:00
{
2009-10-20 18:08:05 -07:00
Restore ( ) ;
2009-09-23 21:09:56 -07:00
}
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : OnMenuRestore ( wxCommandEvent & event )
2009-09-23 21:09:56 -07:00
{
2009-10-20 18:08:05 -07:00
Restore ( ) ;
2009-09-23 21:09:56 -07:00
}
2009-11-12 17:23:08 -08:00
void CMyTaskBarIcon : : OnMenuOptions ( wxCommandEvent & event )
{
// Since it's modal, get the main window to do it
2010-05-18 17:26:56 -07:00
wxCommandEvent event2 ( wxEVT_COMMAND_MENU_SELECTED , wxID_PREFERENCES ) ;
2010-01-28 13:49:20 -08:00
pframeMain - > GetEventHandler ( ) - > AddPendingEvent ( event2 ) ;
2009-11-12 17:23:08 -08:00
}
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : Restore ( )
2009-09-23 21:09:56 -07:00
{
pframeMain - > Show ( ) ;
2009-11-12 17:23:08 -08:00
wxIconizeEvent event ( 0 , false ) ;
2010-01-28 13:49:20 -08:00
pframeMain - > GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2009-10-03 04:52:21 -07:00
pframeMain - > Iconize ( false ) ;
2009-09-23 21:09:56 -07:00
pframeMain - > Raise ( ) ;
}
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : OnMenuGenerate ( wxCommandEvent & event )
{
GenerateBitcoins ( event . IsChecked ( ) ) ;
}
void CMyTaskBarIcon : : OnUpdateUIGenerate ( wxUpdateUIEvent & event )
{
event . Check ( fGenerateBitcoins ) ;
2009-09-23 21:09:56 -07:00
}
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : OnMenuExit ( wxCommandEvent & event )
2009-09-23 21:09:56 -07:00
{
2009-10-20 18:08:05 -07:00
pframeMain - > Close ( true ) ;
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
void CMyTaskBarIcon : : UpdateTooltip ( )
{
if ( IsIconInstalled ( ) )
Show ( true ) ;
}
2009-09-23 21:09:56 -07:00
2009-10-20 18:08:05 -07:00
wxMenu * CMyTaskBarIcon : : CreatePopupMenu ( )
{
wxMenu * pmenu = new wxMenu ;
2010-02-17 09:22:01 -08:00
pmenu - > Append ( ID_TASKBAR_RESTORE , _ ( " &Open Bitcoin " ) ) ;
pmenu - > Append ( ID_TASKBAR_OPTIONS , _ ( " O&ptions... " ) ) ;
pmenu - > AppendCheckItem ( ID_TASKBAR_GENERATE , _ ( " &Generate Coins " ) ) - > Check ( fGenerateBitcoins ) ;
2009-10-20 18:08:05 -07:00
# ifndef __WXMAC_OSX__ // Mac has built-in quit menu
pmenu - > AppendSeparator ( ) ;
2010-02-17 09:22:01 -08:00
pmenu - > Append ( ID_TASKBAR_EXIT , _ ( " E&xit " ) ) ;
2009-10-20 18:08:05 -07:00
# endif
return pmenu ;
2009-09-23 21:09:56 -07:00
}
2009-08-29 20:46:39 -07:00
2009-10-20 18:08:05 -07:00
2009-10-28 19:52:48 -07:00
2009-10-20 18:08:05 -07:00
2009-08-29 20:46:39 -07:00
2010-02-25 13:55:27 -08:00
void CreateMainWindow ( )
2009-10-20 18:08:05 -07:00
{
2010-02-25 13:55:27 -08:00
pframeMain = new CMainFrame ( NULL ) ;
if ( mapArgs . count ( " -min " ) )
pframeMain - > Iconize ( true ) ;
2010-07-14 17:18:45 -07:00
# ifdef __WXGTK__
if ( ! mapArgs . count ( " -minimizetotray " ) )
fMinimizeToTray = false ;
# endif
2010-02-25 13:55:27 -08:00
pframeMain - > Show ( true ) ; // have to show first to get taskbar button to hide
if ( fMinimizeToTray & & pframeMain - > IsIconized ( ) )
fClosedToTray = true ;
pframeMain - > Show ( ! fClosedToTray ) ;
ptaskbaricon - > Show ( fMinimizeToTray | | fClosedToTray ) ;
CreateThread ( ThreadDelayedRepaint , NULL ) ;
2009-09-23 21:09:56 -07:00
}