mgnewtaskdlg.cpp
来自「一款LINUX下的下载软件」· C++ 代码 · 共 1,039 行 · 第 1/2 页
CPP
1,039 行
top->Add( all, 1, wxEXPAND | wxALL | wxFIXED_MINSIZE, 5 );
TransferDataToWindow();
//top->SetMinSize(420,300);
top->Fit( this );
SetSizer( top );
top->SetSizeHints( this );
m_bOpenUrlKeyEvent = true;
if ( m_sUrl.IsNull() )
{
m_pTextCtrl->SetFocus();
}
else
{
m_ThSpin->SetFocus();
}
}
void CNewTaskDlg::OnPickPath( wxCommandEvent& event )
{
m_sSavePath=m_SavePathCtrl->GetValue();
wxDirDialog dlg( this, _MGSTR( _S_NEW_CHOOSEPATH ), m_sSavePath, wxDD_NEW_DIR_BUTTON );
if ( dlg.ShowModal() == wxID_OK )
{
//TransferDataFromWindow();
m_sSavePath = dlg.GetPath();
m_SavePathCtrl->SetValue(m_sSavePath);
//MessageBox(NULL,m_sSavePath,"cap",MB_OK);
//TransferDataToWindow();//??don't work in windows?
}
}
void CNewTaskDlg::OnThSpin( wxSpinEvent& event )
{
m_nThreadNum = m_ThSpin->GetValue();
}
void CNewTaskDlg::OnReSpin( wxSpinEvent& event )
{
m_nRetry = m_ThRetry->GetValue();
}
void CNewTaskDlg::OnWaSpin( wxSpinEvent& event )
{
m_nRetryWait = m_ThRetryWait->GetValue();
}
void CNewTaskDlg::OnFileSpin( wxSpinEvent& event )
{
int tempvalue = m_FileSpin->GetValue();
//m_nFileSpin = m_FileSpin->GetValue();
//check if this value is valid for main url.
//if not a valid , set old value to spin.
TransferDataFromWindow(); //get url to m_sUrl
if ( SelectFile( tempvalue ) )
{
m_nFileSpin = tempvalue;
}
else
{
m_FileSpin->SetValue( m_nFileSpin );
}
}
bool CNewTaskDlg::SelectFile( int step )
{
int len = m_sUrl.Length();
int pos = len;
bool found = false;
if ( step <= 0 )
return false;
for ( int i = 0; i < step; i++ )
{
found = false;
for ( int j = pos - 1; j > 1; j-- )
{
if ( wxChar( '/' ) == m_sUrl[ j ] )
{
found = true;
if ( wxChar( '/' ) != m_sUrl[ j - 1 ] )
{
//valid /
pos = j;
break;
}
else
{
//not valid /
goto fail;
}
}
}
if ( found )
continue;
else
goto fail;
//from end to search '/'
}
//select it
//pos point to /
//select from pos+1 to end;
m_pTextCtrl->SetSelection( pos, len );
//m_pTextCtrl->SetInsertionPointEnd();
return true;
fail:
m_FileSpin->SetValue( m_nFileSpin );
return false;
}
void CNewTaskDlg::InitProxyList()
{
m_SocksProxyList.clear();
m_FtpProxyList.clear();
m_HttpProxyList.clear();
_PL temp;
temp.name = "";
temp.showname = _MGSTR( _S_NEW_NONE );
m_SocksProxyList.push_back( temp );
m_FtpProxyList.push_back( temp );
m_HttpProxyList.push_back( temp );
wxString tstr;
//get proxy from parent
int count = m_pParent->GetProxyCount();
for ( int i = 0;i < count;i++ )
{
_ProxyAttr pa = m_pParent->GetProxy( i );
switch ( pa.nType )
{
case 0:
{
temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT("%s[%s:%d][auto]"), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("][auto]");#endif
temp.showname = tstr;
m_SocksProxyList.push_back( temp );
}
break;
case 1:
{ temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT( "%s[%s:%d][v4]" ), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("][v4]");#endif
temp.showname = tstr;
m_SocksProxyList.push_back( temp ); }
break;
case 2:
{ temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT( "%s[%s:%d][v4a]" ), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );
#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("][v4a]");#endif
temp.showname = tstr;
m_SocksProxyList.push_back( temp ); }
break;
case 3:
{ temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT( "%s[%s:%d][v5]" ), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("][v5]");#endif
temp.showname = tstr;
m_SocksProxyList.push_back( temp );
}
break;
case 4:
{
temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT( "%s[%s:%d]" ), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("]");#endif
temp.showname = tstr;
m_FtpProxyList.push_back( temp );
}
break;
case 5:
{
temp.name = pa.sName;#ifndef _UNICODE
tstr.Printf( wxT( "%s[%s:%d]" ), pa.sName.c_str(), pa.sServer.c_str(), pa.nPort );#else //use Printf in UNICODE will error wxString port; port.Printf(wxT("%d"), pa.nPort); tstr = wxString ( pa.sName.c_str(), wxConvLocal ) + wxT("[") + wxString( pa.sServer.c_str(), wxConvLocal ) + wxT(":") + port + wxT("]");#endif
temp.showname = tstr;
m_HttpProxyList.push_back( temp );
}
break;
default:
break;
}
}
if ( m_SocksProxyList.size() == 1 )
{
m_SocksProxyList[ 0 ].showname = _MGSTR( _S_NEW_NOSOCKSPROXY );
}
if ( m_FtpProxyList.size() == 1 )
{
m_FtpProxyList[ 0 ].showname = _MGSTR( _S_NEW_NOFTPPROXY );
}
if ( m_HttpProxyList.size() == 1 )
{
m_HttpProxyList[ 0 ].showname = _MGSTR( _S_NEW_NOHTTPPROXY );
}
}
void CNewTaskDlg::GetProxyName( std::string& socks, std::string& ftp, std::string& http )
{
socks = ( m_SocksProxyList[ m_nSocksProxy ].name );
ftp = ( m_FtpProxyList[ m_nFtpProxy ].name );
http = ( m_HttpProxyList[ m_nHttpProxy ].name );
}
//如果user和pass不为空,要改写url返回
std::string CNewTaskDlg::GetUrl()
{
if ( !m_sUser.IsEmpty() && !m_sPass.IsEmpty() )
{ //用户和密码两个都不空
//但是如果都等于缺省值就不重新构造地址
if (
m_sUser.mb_str( wxConvLocal ) != "anonymous" ||
// m_sPass.mb_str( wxConvLocal ) != gDefFtpPass m_sPass.mb_str(wxConvLocal) != wxString::FromAscii(gDefFtpPass.c_str()).mb_str() //unicode patch
)
{
CUrlParser parser;
std::string rebuild;
std::string origin = std::string( m_sUrl.mb_str( wxConvLocal ) );
if ( parser.RebuildUrl( origin,
std::string( m_sUser.mb_str( wxConvLocal ) ),
std::string( m_sPass.mb_str( wxConvLocal ) ),
rebuild ) )
{
return rebuild;
}
}
}
#ifndef _UNICODE
return m_sUrl.mb_str( wxConvLocal );#else return m_sUrl.mb_str( wxConvLocal ).data();#endif
}
void CNewTaskDlg::AddMirrorUrl( wxString url )
{
if ( m_sMirrorUrl.GetCount() > 100 )
return ; //too many murl
m_sMirrorUrl.Add( url );
m_pMirrorBox->InsertItems( 1, &url, 0 );
}
int CNewTaskDlg::GetMirrorUrl( int num, std::string mu[] )
{
int n = m_sMirrorUrl.GetCount();
int i;
for ( i = 0; i < n; i++ )
{#ifndef _UNICODE
std::string murl = m_sMirrorUrl[ i ].mb_str( wxConvLocal );#else std::string murl = m_sMirrorUrl[ i ].mb_str( wxConvLocal ).data();#endif
Trim( murl );
if ( murl.empty() )
continue;
// else if(murl[murl.length()-1]=='/') {
//put the selected file name at the end of url.
// murl+=GetSelectFileName();
// }
mu[ i ] = murl;
if ( i >= num )
break;
}
return i;
}
std::string CNewTaskDlg::GetSelectFileName()
{
int len = m_sUrl.Length();
int pos = len;
bool found = false;
int step = m_nFileSpin;
CUrlParser par;
wxString ret;
if ( step <= 0 )
return std::string( "" );
for ( int i = 0; i < step; i++ )
{
found = false;
for ( int j = pos - 1; j > 1; j-- )
{
if ( wxChar( '/' ) == m_sUrl[ j ] )
{
found = true;
if ( wxChar( '/' ) != m_sUrl[ j - 1 ] )
{
//valid /
pos = j;
break;
}
else
{
//not valid /
goto fail;
}
}
}
if ( found )
continue;
else
goto fail;
//from end to search '/'
}
//select it
//pos point to /
//select from pos+1 to end;
ret = m_sUrl.SubString( pos + 1, len );
#ifndef _UNICODE
return ret.mb_str( wxConvLocal );#else return ret.mb_str( wxConvLocal ).data();#endif
fail:
#ifndef _UNICODE
if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) )#else if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) )#endif
{
return par.GetFileName();
}
return std::string( "" );
}
void CNewTaskDlg::OnUrlText( wxCommandEvent& event )
{ //url text changed
#ifdef WIN32
if ( !m_bOpenUrlKeyEvent )
return ; //too ugly but work!!
TransferDataFromWindow();
CUrlParser par;
if ( !par.SetUrl( m_sUrl.c_str() ) ) {
m_sRename.Clear();
//m_pTextCtrl->SetInsertionPointEnd();
m_RenameCtrl->SetValue(m_sRename);
}
else
{
m_sRename = wxString( par.GetFileName().c_str(), wxConvLocal );
//m_pTextCtrl->SetInsertionPointEnd();
m_RenameCtrl->SetValue(m_sRename);
}
#else
if ( !m_bOpenUrlKeyEvent )
return ; //too ugly but work!!
TransferDataFromWindow();
CUrlParser par;
#ifndef _UNICODE
if ( !par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) )#else if ( !par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) )#endif
{
m_sRename.Clear();
//TransferDataToWindow(); //this in win32 will cause a new Text Event,and then circle and circle!
//m_pTextCtrl->SetInsertionPointEnd();
m_RenameCtrl->SetValue(m_sRename);
}
else
{
m_sRename = wxString( par.GetFileName().c_str(), wxConvLocal );
//TransferDataToWindow();
//m_pTextCtrl->SetInsertionPointEnd();
m_RenameCtrl->SetValue(m_sRename);
}
#endif
}
void CNewTaskDlg::OnRenameText( wxCommandEvent& event )
{
event.Skip();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?