propertydlg.cpp
来自「一款LINUX下的下载软件」· C++ 代码 · 共 1,024 行 · 第 1/2 页
CPP
1,024 行
all->AddSpacer( 10 );
all->Add( part2, 0, wxEXPAND );
all->AddSpacer( 10 );
all->Add( part3, 0, wxEXPAND );
all->AddSpacer( 10 );
all->Add( part4, 0, wxEXPAND );
all->AddSpacer( 10 );
all->Add( part6, 0, wxEXPAND );
all->AddSpacer( 10 );
all->Add( part5, 0, wxALIGN_RIGHT );
top->Add( all, 1, wxEXPAND | wxALL | wxFIXED_MINSIZE, 5 );
top->SetMinSize( 420, 300 );
TransferDataToWindow();
top->Fit( this );
SetSizer( top );
top->SetSizeHints( this );
m_bOpenUrlKeyEvent = true;
//select file if posible
//SelectFile(1);
}
void CPropertyDlg::OnPickPath( wxCommandEvent& event )
{
wxDirDialog dlg( this, _MGSTR( _S_NEW_CHOOSEPATH ), m_sSavePath, wxDD_NEW_DIR_BUTTON );
if ( dlg.ShowModal() == wxID_OK )
{
TransferDataFromWindow();
m_sSavePath = dlg.GetPath();
TransferDataToWindow();
}
}
void CPropertyDlg::OnThSpin( wxSpinEvent& event )
{
m_nThreadNum = m_ThSpin->GetValue();
}
void CPropertyDlg::OnReSpin( wxSpinEvent& event )
{
m_nRetry = m_ThRetry->GetValue();
}
void CPropertyDlg::OnWaSpin( wxSpinEvent& event )
{
m_nRetryWait = m_ThRetryWait->GetValue();
}
void CPropertyDlg::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 CPropertyDlg::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 );
return true;
fail:
m_FileSpin->SetValue( m_nFileSpin );
return false;
}
void CPropertyDlg::InitProxyList( std::string socks, std::string ftp, std::string http )
{
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 CPropertyDlg::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 CPropertyDlg::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 CPropertyDlg::AddMirrorUrl( wxString url )
{
if ( m_sMirrorUrl.GetCount() > 80 )
return ; //too many murl
m_sMirrorUrl.Add( url );
m_pMirrorBox->InsertItems( 1, &url, 0 );
}
int CPropertyDlg::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 CPropertyDlg::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();//unicode patch
#endif
fail:
#ifndef _UNICODE
if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ) ) )#else if ( par.SetUrl( m_sUrl.mb_str( wxConvLocal ).data() ) ) //unicode patch#endif
{
return par.GetFileName();
}
return std::string( "" );
}
std::string CPropertyDlg::GetSocksProxyName()
{
return m_SocksProxyList[ m_nSocksProxy ].name;
}
std::string CPropertyDlg::GetHttpProxyName()
{
return m_HttpProxyList[ m_nHttpProxy ].name;
}
std::string CPropertyDlg::GetFtpProxyName()
{
return m_FtpProxyList[ m_nFtpProxy ].name;
}
/*
void CPropertyDlg::OnUrlText( wxCommandEvent& event )
{//url text changed
if( !m_bOpenUrlKeyEvent) return; //too ugly but work!!
TransferDataFromWindow();
CUrlParser par;
if(!par.SetUrl(m_sUrl.mb_str(wxConvLocal)))
{
m_sRename.Clear();
TransferDataToWindow();
m_pTextCtrl->SetInsertionPointEnd();
}
else
{
m_sRename=wxString(par.GetFileName().c_str(),wxConvLocal);
TransferDataToWindow();
m_pTextCtrl->SetInsertionPointEnd();
}
}
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?