📄 emuledlg.cpp
字号:
case IDC_PREFERENCES:
ShowPreferences();
break;
}
}
}
void CemuleDlg::AddSpeedSelectorSys(CMenu* addToMenu)
{
CString text;
// creating UploadPopup Menu
ASSERT( m_menuUploadCtrl.m_hMenu == NULL );
if (m_menuUploadCtrl.CreateMenu())
{
//m_menuUploadCtrl.AddMenuTitle(GetResString(IDS_PW_TIT_UP));
text.Format(_T("20%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.2),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U20, text);
text.Format(_T("40%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.4),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U40, text);
text.Format(_T("60%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.6),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U60, text);
text.Format(_T("80%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.8),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U80, text);
text.Format(_T("100%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U100, text);
m_menuUploadCtrl.AppendMenu(MF_SEPARATOR);
if (GetRecMaxUpload()>0) {
text.Format(GetResString(IDS_PW_MINREC)+GetResString(IDS_KBYTESEC),GetRecMaxUpload());
m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_UP10, text );
}
//m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_UPC, GetResString(IDS_PW_UNLIMITED));
text.Format(_T("%s:"), GetResString(IDS_PW_UPL));
addToMenu->AppendMenu(MF_STRING|MF_POPUP, (UINT_PTR)m_menuUploadCtrl.m_hMenu, text);
}
// creating DownloadPopup Menu
ASSERT( m_menuDownloadCtrl.m_hMenu == NULL );
if (m_menuDownloadCtrl.CreateMenu())
{
//m_menuDownloadCtrl.AddMenuTitle(GetResString(IDS_PW_TIT_DOWN));
text.Format(_T("20%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.2),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D20, text);
text.Format(_T("40%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.4),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D40, text);
text.Format(_T("60%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.6),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D60, text);
text.Format(_T("80%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.8),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D80, text);
text.Format(_T("100%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D100, text);
//m_menuDownloadCtrl.AppendMenu(MF_SEPARATOR);
//m_menuDownloadCtrl.AppendMenu(MF_STRING, MP_QS_DC, GetResString(IDS_PW_UNLIMITED));
// Show DownloadPopup Menu
text.Format(_T("%s:"), GetResString(IDS_PW_DOWNL));
addToMenu->AppendMenu(MF_STRING|MF_POPUP, (UINT_PTR)m_menuDownloadCtrl.m_hMenu, text);
}
addToMenu->AppendMenu(MF_SEPARATOR);
addToMenu->AppendMenu(MF_STRING, MP_CONNECT, GetResString(IDS_MAIN_BTN_CONNECT));
addToMenu->AppendMenu(MF_STRING, MP_DISCONNECT, GetResString(IDS_MAIN_BTN_DISCONNECT));
}
void CemuleDlg::StartConnection(){
if (!Kademlia::CKademlia::isRunning() && !theApp.serverconnect->IsConnecting()){
AddLogLine(true, GetResString(IDS_CONNECTING));
if( thePrefs.GetNetworkED2K() ){
if ( serverwnd->serverlistctrl.GetSelectedCount()>1 )
{
serverwnd->serverlistctrl.PostMessage(WM_COMMAND,MP_CONNECTTO,0L);
}
else
{
theApp.serverconnect->ConnectToAnyServer();
}
}
if( thePrefs.GetNetworkKademlia() )
{
Kademlia::CKademlia::start();
}
ShowConnectionState();
}
}
void CemuleDlg::CloseConnection()
{
if (theApp.serverconnect->IsConnected()){
theApp.serverconnect->Disconnect();
}
if (theApp.serverconnect->IsConnecting()){
theApp.serverconnect->StopConnectionTry();
}
Kademlia::CKademlia::stop();
theApp.OnlineSig(); // Added By Bouc7
ShowConnectionState();
}
void CemuleDlg::RestoreWindow()
{
if (IsPreferencesDlgOpen()) {
MessageBeep((UINT)-1);
preferenceswnd->SetForegroundWindow();
preferenceswnd->BringWindowToTop();
return;
}
if (TrayIsVisible())
TrayHide();
DestroyMiniMule();
if (m_wpFirstRestore.length)
{
SetWindowPlacement(&m_wpFirstRestore);
memset(&m_wpFirstRestore, 0, sizeof m_wpFirstRestore);
SetForegroundWindow();
BringWindowToTop();
}
else
CTrayDialog::RestoreWindow();
}
void CemuleDlg::UpdateTrayIcon(int iPercent)
{
// compute an id of the icon to be generated
UINT uSysTrayIconCookie = (iPercent > 0) ? (16 - ((iPercent*15/100) + 1)) : 0;
if (theApp.IsConnected()) {
if (!theApp.IsFirewalled())
uSysTrayIconCookie += 50;
}
else
uSysTrayIconCookie += 100;
// dont update if the same icon as displayed would be generated
if (m_uLastSysTrayIconCookie == uSysTrayIconCookie)
return;
m_uLastSysTrayIconCookie = uSysTrayIconCookie;
// prepare it up
if (theApp.IsConnected()) {
if (theApp.IsFirewalled())
m_TrayIcon.Init(m_icoSysTrayLowID, 100, 1, 1, 16, 16, thePrefs.GetStatsColor(11));
else
m_TrayIcon.Init(m_icoSysTrayConnected, 100, 1, 1, 16, 16, thePrefs.GetStatsColor(11));
}
else
m_TrayIcon.Init(m_icoSysTrayDisconnected, 100, 1, 1, 16, 16, thePrefs.GetStatsColor(11));
// load our limit and color info
static const int aiLimits[1] = { 100 }; // set the limits of where the bar color changes (low-high)
COLORREF aColors[1] = { thePrefs.GetStatsColor(11) }; // set the corresponding color for each level
m_TrayIcon.SetColorLevels(aiLimits, aColors, ARRSIZE(aiLimits));
// generate the icon (do *not* destroy that icon using DestroyIcon(), that's done in 'TrayUpdate')
int aiVals[1] = { iPercent };
m_icoSysTrayCurrent = m_TrayIcon.Create(aiVals);
ASSERT( m_icoSysTrayCurrent != NULL );
if (m_icoSysTrayCurrent)
TraySetIcon(m_icoSysTrayCurrent, true);
TrayUpdate();
}
int CemuleDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
return CTrayDialog::OnCreate(lpCreateStruct);
}
void CemuleDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
if (IsRunning())
ShowTransferRate(true);
CTrayDialog::OnShowWindow(bShow, nStatus);
}
void CemuleDlg::ShowNotifier(CString Text, int MsgType, LPCTSTR pszLink, bool bForceSoundOFF)
{
if (!notifierenabled)
return;
Text.Trim();
if (Text.IsEmpty())
{
return; //VeryCD版
}
LPCTSTR pszSoundEvent = NULL;
int iSoundPrio = 0;
bool ShowIt = false;
switch (MsgType)
{
case TBN_CHAT:
if (thePrefs.GetUseChatNotifier())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_Chat");
iSoundPrio = 1;
}
break;
case TBN_SERVERMSG: //VeryCD版
if (thePrefs.GetUseServerNotifier()) {
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_Chat");
iSoundPrio = 1;
}
break;
case TBN_DLOAD:
if (thePrefs.GetUseDownloadNotifier())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_DownloadFinished");
iSoundPrio = 1;
}
break;
case TBN_DLOADADDED:
if (thePrefs.GetUseNewDownloadNotifier())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_DownloadAdded");
iSoundPrio = 1;
}
break;
case TBN_LOG:
if (thePrefs.GetUseLogNotifier())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_LogEntryAdded");
}
break;
case TBN_IMPORTANTEVENT:
if (thePrefs.GetNotifierPopOnImportantError())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_Urgent");
iSoundPrio = 1;
}
break;
case TBN_NEWVERSION:
if (thePrefs.GetNotifierPopOnNewVersion())
{
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
pszSoundEvent = _T("eMule_NewVersion");
iSoundPrio = 1;
}
break;
case TBN_NULL:
m_wndTaskbarNotifier->Show(Text, MsgType, pszLink);
ShowIt = true;
break;
}
if (ShowIt && !bForceSoundOFF)
{
if (thePrefs.GetUseSoundInNotifier())
{
PlaySound(thePrefs.GetNotifierWavSoundPath(), NULL, SND_FILENAME | SND_NOSTOP | SND_NOWAIT | SND_ASYNC);
}
else if (pszSoundEvent)
{
// use 'SND_NOSTOP' only for low priority events, otherwise the 'Log message' event may overrule a more important
// event which is fired nearly at the same time.
PlaySound(pszSoundEvent, NULL, SND_APPLICATION | SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | ((iSoundPrio > 0) ? 0 : SND_NOSTOP));
}
}
}
void CemuleDlg::LoadNotifier(CString configuration)
{
notifierenabled = m_wndTaskbarNotifier->LoadConfiguration(configuration);
}
LRESULT CemuleDlg::OnTaskbarNotifierClicked(WPARAM wParam,LPARAM lParam)
{
if (lParam)
{
LPTSTR pszLink = (LPTSTR)lParam;
ShellOpenFile(pszLink, NULL);
free(pszLink);
pszLink = NULL;
}
switch (m_wndTaskbarNotifier->GetMessageType())
{
case TBN_CHAT:
RestoreWindow();
SetActiveDialog(chatwnd);
break;
case TBN_DLOAD:
// if we had a link and opened the downloaded file, dont restore the app window
if (lParam==0)
{
RestoreWindow();
SetActiveDialog(transferwnd);
}
break;
case TBN_DLOADADDED:
RestoreWindow();
SetActiveDialog(transferwnd);
break;
case TBN_IMPORTANTEVENT:
RestoreWindow();
SetActiveDialog(serverwnd);
break;
case TBN_LOG:
RestoreWindow();
SetActiveDialog(serverwnd);
break;
case TBN_NEWVERSION:
{
CString theUrl;
theUrl.Format(_T("/en/version_check.php?version=%i&language=%i"),theApp.m_uCurVersionCheck,thePrefs.GetLanguageID());
theUrl = thePrefs.GetVersionCheckBaseURL()+theUrl;
ShellExecute(NULL, NULL, theUrl, NULL, thePrefs.GetAppDir(), SW_SHOWDEFAULT);
break;
}
}
return 0;
}
void CemuleDlg::OnSysColorChange()
{
CTrayDialog::OnSysColorChange();
SetAllIcons();
}
void CemuleDlg::SetAllIcons()
{
// connection state
for (int i = 0; i < ARRSIZE(connicons); i++){
if (connicons[i]) VERIFY( ::DestroyIcon(connicons[i]) );
}
connicons[0] = theApp.LoadIcon(_T("ConnectedNotNot"), 16, 16);
connicons[1] = theApp.LoadIcon(_T("ConnectedNotLow"), 16, 16);
connicons[2] = theApp.LoadIcon(_T("ConnectedNotHigh"), 16, 16);
connicons[3] = theApp.LoadIcon(_T("ConnectedLowNot"), 16, 16);
connicons[4] = theApp.LoadIcon(_T("ConnectedLowLow"), 16, 16);
connicons[5] = theApp.LoadIcon(_T("ConnectedLowHigh"), 16, 16);
connicons[6] = theApp.LoadIcon(_T("ConnectedHighNot"), 16, 16);
connicons[7] = theApp.LoadIcon(_T("ConnectedHighLow"), 16, 16);
connicons[8] = theApp.LoadIcon(_T("ConnectedHighHigh"), 16, 16);
ShowConnectionStateIcon();
// transfer state
if (transicons[0]) VERIFY( ::DestroyIcon(transicons[0]) );
if (transicons[1]) VERIFY( ::DestroyIcon(transicons[1]) );
if (transicons[2]) VERIFY( ::DestroyIcon(transicons[2]) );
if (transicons[3]) VERIFY( ::DestroyIcon(transicons[3]) );
transicons[0] = theApp.LoadIcon(_T("UP0DOWN0"), 16, 16);
transicons[1] = theApp.LoadIcon(_T("UP0DOWN1"), 16, 16);
transicons[2] = theApp.LoadIcon(_T("UP1DOWN0"), 16, 16);
transicons[3] = theApp.LoadIcon(_T("UP1DOWN1"), 16, 16);
ShowTransferStateIcon();
// users state
if (usericon) VERIFY( ::DestroyIcon(usericon) );
usericon = theApp.LoadIcon(_T("StatsClients"), 16, 16);
ShowUserStateIcon();
// traybar icons
if (m_icoSysTrayConnected) VERIFY( ::DestroyIcon(m_icoSysTrayConnected) );
if (m_icoSysTrayDisconnected) VERIFY( ::DestroyIcon(m_icoSysTrayDisconnected) );
if (m_icoSysTrayLowID) VERIFY( ::DestroyIcon(m_icoSysTrayLowID) );
m_icoSysTrayConnected = theApp.LoadIcon(_T("TrayConnected"), 16, 16);
m_icoSysTrayDisconnected = theApp.LoadIcon(_T("TrayNotConnected"), 16, 16);
m_icoSysTrayLowID = theApp.LoadIcon(_T("TrayLowID"), 16, 16);
ShowTransferRate(true);
if (imicons[0]) VERIFY( ::DestroyIcon(imicons[0]) );
if (imicons[1]) VERIFY( ::DestroyIcon(imicons[1]) );
if (imicons[2]) VERIFY( ::DestroyIcon(imicons[2]) );
imicons[0] = NULL;
imicons[1] = theApp.LoadIcon(_T("Message"), 16, 16);
imicons[2] = theApp.LoadIcon(_T("MessagePending"), 16, 16);
ShowMessageState(m_iMsgIcon);
}
void CemuleDlg::Localize()
{
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu)
{
VERIFY( pSysMenu->ModifyMenu(MP_ABOUTBOX, MF_BYCOMMAND | MF_STRING, MP_ABOUTBOX, GetResString(IDS_ABOUTBOX)) );
VERIFY( pSysMenu->ModifyMenu(MP_VERSIONCHECK, MF_BYCOMMAND | MF_STRING, MP_VERSIONCHECK, GetResString(IDS_VERSIONCHECK)) );
switch (thePrefs.GetWindowsVersion()){
case _WINVER_98_:
case _WINVER_95_:
case _WINVER_ME_:
// NOTE: I think the reason why the old version of the following code crashed under Win9X was because
// of the menus were destroyed right after they were added to the system menu. New code should work
// under Win9X too but I can't test it.
break;
default:{
// localize the 'speed control' sub menus by deleting the current menus and creating a new ones.
// remove any already available 'speed control' menus from system menu
UINT uOptMenuPos = pSysMenu->GetMenuItemCount() - 1;
CMenu* pAccelMenu = pSysMenu->GetSubMenu(uOptMenuPos);
if (pAccelMenu)
{
ASSERT( pAccelMenu->m_hMenu == m_SysMenuOptions.m_hMenu );
VERIFY( pSysMenu->RemoveMenu(uOptMenuPos, MF_BYPOSITION) );
pAccelMenu = NULL;
}
// destroy all 'speed control' me
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -