📄 mainfrm.cpp
字号:
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_FINISHED;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_VIEW_WAITING_USERS;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_FINISHED_UL;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].fsStyle = TBSTYLE_SEP;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = ID_FILE_SEARCH;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_FILE_ADL_SEARCH;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_SEARCH_SPY;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].fsStyle = TBSTYLE_SEP;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_OPEN_FILE_LIST;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].fsStyle = TBSTYLE_SEP;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = ID_FILE_SETTINGS;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
n++;
tb[n].fsStyle = TBSTYLE_SEP;
n++;
tb[n].iBitmap = bitmap++;
tb[n].idCommand = IDC_NOTEPAD;
tb[n].fsState = TBSTATE_ENABLED;
tb[n].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
ctrlToolbar.SetButtonStructSize();
ctrlToolbar.AddButtons(numButtons, tb);
ctrlToolbar.AutoSize();
return ctrlToolbar.m_hWnd;
}
LRESULT MainFrame::onSpeaker(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) {
if(wParam == DOWNLOAD_LISTING) {
auto_ptr<DirectoryListInfo> i(reinterpret_cast<DirectoryListInfo*>(lParam));
DirectoryListingFrame::openWindow(i->file, i->user, i->speed);
} else if(wParam == BROWSE_LISTING) {
auto_ptr<DirectoryBrowseInfo> i(reinterpret_cast<DirectoryBrowseInfo*>(lParam));
DirectoryListingFrame::openWindow(i->user, i->text, 0);
} else if(wParam == VIEW_FILE_AND_DELETE) {
auto_ptr<tstring> file(reinterpret_cast<tstring*>(lParam));
TextFrame::openWindow(*file);
File::deleteFile(Text::fromT(*file));
} else if(wParam == STATS) {
auto_ptr<TStringList> pstr(reinterpret_cast<TStringList*>(lParam));
const TStringList& str = *pstr;
if(ctrlStatus.IsWindow()) {
HDC dc = ::GetDC(ctrlStatus.m_hWnd);
bool u = false;
ctrlStatus.SetText(1, str[0].c_str());
for(int i = 1; i < 7; i++) {
int w = WinUtil::getTextWidth(str[i], dc);
if(statusSizes[i] < w) {
statusSizes[i] = w;
u = true;
}
ctrlStatus.SetText(i+1, str[i].c_str());
}
::ReleaseDC(ctrlStatus.m_hWnd, dc);
if(u)
UpdateLayout(TRUE);
}
} else if(wParam == AUTO_CONNECT) {
autoConnect(FavoriteManager::getInstance()->getFavoriteHubs());
} else if(wParam == PARSE_COMMAND_LINE) {
parseCommandLine(GetCommandLine());
} else if(wParam == STATUS_MESSAGE) {
auto_ptr<pair<time_t, tstring> > msg((pair<time_t, tstring>*)lParam);
if(ctrlStatus.IsWindow()) {
tstring line = Text::toT("[" + Util::getShortTimeString(msg->first) + "] ") + msg->second;
ctrlStatus.SetText(0, line.c_str());
while(lastLinesList.size() + 1 > MAX_CLIENT_LINES)
lastLinesList.erase(lastLinesList.begin());
if (line.find(_T('\r')) == tstring::npos) {
lastLinesList.push_back(line);
} else {
lastLinesList.push_back(line.substr(0, line.find(_T('\r'))));
}
}
}
return 0;
}
void MainFrame::parseCommandLine(const tstring& cmdLine)
{
string::size_type i = 0;
string::size_type j;
if( (j = cmdLine.find(_T("dchub://"), i)) != string::npos) {
WinUtil::parseDchubUrl(cmdLine.substr(j));
}
if( (j = cmdLine.find(_T("adc://"), i)) != string::npos) {
WinUtil::parseADChubUrl(cmdLine.substr(j));
}
if( (j = cmdLine.find(_T("magnet:?"), i)) != string::npos) {
WinUtil::parseMagnetUri(cmdLine.substr(j));
}
}
LRESULT MainFrame::onCopyData(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) {
tstring cmdLine = (LPCTSTR) (((COPYDATASTRUCT *)lParam)->lpData);
parseCommandLine(Text::toT(Util::getAppName() + " ") + cmdLine);
return true;
}
LRESULT MainFrame::onHashProgress(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
HashProgressDlg(false).DoModal(m_hWnd);
return 0;
}
LRESULT MainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
AboutDlg dlg;
dlg.DoModal(m_hWnd);
return 0;
}
LRESULT MainFrame::onOpenWindows(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
switch(wID) {
case ID_FILE_SEARCH: SearchFrame::openWindow(); break;
case ID_FILE_CONNECT: PublicHubsFrame::openWindow(); break;
case IDC_FAVORITES: FavoriteHubsFrame::openWindow(); break;
case IDC_FAVUSERS: UsersFrame::openWindow(); break;
case IDC_NOTEPAD: NotepadFrame::openWindow(); break;
case IDC_QUEUE: QueueFrame::openWindow(); break;
case IDC_SEARCH_SPY: SpyFrame::openWindow(); break;
case IDC_FILE_ADL_SEARCH: ADLSearchFrame::openWindow(); break;
case IDC_NET_STATS: StatsFrame::openWindow(); break;
case IDC_FINISHED: FinishedFrame::openWindow(); break;
case IDC_FINISHED_UL: FinishedULFrame::openWindow(); break;
case IDC_VIEW_WAITING_USERS: WaitingUsersFrame::openWindow(); break;
case IDC_SYSTEM_LOG: SystemFrame::openWindow(); break;
default: dcassert(0); break;
}
return 0;
}
LRESULT MainFrame::OnFileSettings(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PropertiesDlg dlg(m_hWnd, SettingsManager::getInstance());
short lastPort = (short)SETTING(TCP_PORT);
short lastUDP = (short)SETTING(UDP_PORT);
int lastConn = SETTING(INCOMING_CONNECTIONS);
if(dlg.DoModal(m_hWnd) == IDOK)
{
SettingsManager::getInstance()->save();
if(missedAutoConnect && !SETTING(NICK).empty()) {
PostMessage(WM_SPEAKER, AUTO_CONNECT);
}
if(SETTING(INCOMING_CONNECTIONS) != lastConn || SETTING(TCP_PORT) != lastPort || SETTING(UDP_PORT) != lastUDP) {
startSocket();
}
ClientManager::getInstance()->infoUpdated();
if(BOOLSETTING(URL_HANDLER)) {
WinUtil::registerDchubHandler();
WinUtil::registerADChubHandler();
WinUtil::urlDcADCRegistered = true;
} else if(WinUtil::urlDcADCRegistered) {
WinUtil::unRegisterDchubHandler();
WinUtil::unRegisterADChubHandler();
WinUtil::urlDcADCRegistered = false;
}
if(BOOLSETTING(MAGNET_REGISTER)) {
WinUtil::registerMagnetHandler();
WinUtil::urlMagnetRegistered = true;
} else if(WinUtil::urlMagnetRegistered) {
WinUtil::unRegisterMagnetHandler();
WinUtil::urlMagnetRegistered = false;
}
}
return 0;
}
void MainFrame::on(HttpConnectionListener::Complete, HttpConnection* /*aConn*/, const string&) throw() {
try {
SimpleXML xml;
xml.fromXML(versionInfo);
xml.stepIn();
string url = Text::fromT(links.homepage);
if(xml.findChild("URL")) {
url = xml.getChildData();
}
xml.resetCurrentChild();
if(xml.findChild("Version")) {
if(Util::toDouble(xml.getChildData()) > VERSIONFLOAT) {
xml.resetCurrentChild();
xml.resetCurrentChild();
if(xml.findChild("Title")) {
const string& title = xml.getChildData();
xml.resetCurrentChild();
if(xml.findChild("Message")) {
if(url.empty()) {
const string& msg = xml.getChildData();
MessageBox(Text::toT(msg).c_str(), Text::toT(title).c_str(), MB_OK);
} else {
string msg = xml.getChildData() + "\r\n" + STRING(OPEN_DOWNLOAD_PAGE);
if(MessageBox(Text::toT(msg).c_str(), Text::toT(title).c_str(), MB_YESNO) == IDYES) {
WinUtil::openLink(Text::toT(url));
}
}
}
}
}
xml.resetCurrentChild();
if(xml.findChild("Links")) {
xml.stepIn();
if(xml.findChild("Homepage")) {
links.homepage = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Downloads")) {
links.downloads = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("GeoIP database update")) {
links.geoipfile = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Translations")) {
links.translations = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Faq")) {
links.faq = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Bugs")) {
links.bugs = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Features")) {
links.features = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Help")) {
links.help = Text::toT(xml.getChildData());
}
xml.resetCurrentChild();
if(xml.findChild("Forum")) {
links.discuss = Text::toT(xml.getChildData());
}
xml.stepOut();
}
}
xml.stepOut();
} catch (const Exception&) {
// ...
}
}
LRESULT MainFrame::onHelp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
HtmlHelp(m_hWnd, WinUtil::getHelpFile().c_str(), HH_DISPLAY_TOC, NULL);
bHandled = TRUE;
return 0;
}
LRESULT MainFrame::onMenuHelp(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled) {
UINT action = (wID == IDC_HELP_CONTENTS) ? HH_DISPLAY_TOC : HH_HELP_CONTEXT;
HtmlHelp(m_hWnd, WinUtil::getHelpFile().c_str(), action, wID);
bHandled = TRUE;
return 0;
}
LRESULT MainFrame::onGetToolTip(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/) {
LPNMTTDISPINFO pDispInfo = (LPNMTTDISPINFO)pnmh;
pDispInfo->szText[0] = 0;
if((idCtrl != 0) && !(pDispInfo->uFlags & TTF_IDISHWND))
{
int stringId = -1;
switch(idCtrl) {
case ID_FILE_CONNECT: stringId = ResourceManager::MENU_PUBLIC_HUBS; break;
case ID_FILE_RECONNECT: stringId = ResourceManager::MENU_RECONNECT; break;
case IDC_FOLLOW: stringId = ResourceManager::MENU_FOLLOW_REDIRECT; break;
case IDC_FAVORITES: stringId = ResourceManager::MENU_FAVORITE_HUBS; break;
case IDC_FAVUSERS: stringId = ResourceManager::MENU_FAVORITE_USERS; break;
case IDC_QUEUE: stringId = ResourceManager::MENU_DOWNLOAD_QUEUE; break;
case IDC_FINISHED: stringId = ResourceManager::FINISHED_DOWNLOADS; break;
case IDC_FINISHED_UL: stringId = ResourceManager::FINISHED_UPLOADS; break;
case ID_FILE_SEARCH: stringId = ResourceManager::MENU_SEARCH; break;
case IDC_FILE_ADL_SEARCH: stringId = ResourceManager::MENU_ADL_SEARCH; break;
case IDC_VIEW_WAITING_USERS: stringId = ResourceManager::WAITING_USERS; break;
case IDC_SEARCH_SPY: stringId = ResourceManager::MENU_SEARCH_SPY; break;
case IDC_OPEN_FILE_LIST: stringId = ResourceManager::MENU_OPEN_FILE_LIST; break;
case ID_FILE_SETTINGS: stringId = ResourceManager::MENU_SETTINGS; break;
case IDC_NET_STATS: stringId = ResourceManager::MENU_NETWORK_STATISTICS; break;
case IDC_NOTEPAD: stringId = ResourceManager::MENU_NOTEPAD; break;
}
if(stringId != -1) {
_tcsncpy(pDispInfo->lpszText, CTSTRING_I((ResourceManager::Strings)stringId), 79);
pDispInfo->uFlags |= TTF_DI_SETITEM;
}
} else { // if we're really in the status bar, this should be detected intelligently
lastLines.clear();
for(TStringIter i = lastLinesList.begin(); i != lastLinesList.end(); ++i) {
lastLines += *i;
lastLines += _T("\r\n");
}
if(lastLines.size() > 2) {
lastLines.erase(lastLines.size() - 2);
}
pDispInfo->lpszText = const_cast<TCHAR*>(lastLines.c_str());
}
return 0;
}
void MainFrame::autoConnect(const FavoriteHubEntry::List& fl) {
missedAutoConnect = false;
for(FavoriteHubEntry::List::const_iterator i = fl.begin(); i != fl.end(); ++i) {
FavoriteHubEntry* entry = *i;
if(entry->getConnect()) {
if(!entry->getNick().empty() || !SETTING(NICK).empty())
HubFrame::openWindow(Text::toT(entry->getServer()));
else
missedAutoConnect = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -