📄 gui.cpp
字号:
// ------------------------------------------------// File : gui.cpp// Date: 4-apr-2002// Author: giles// Desc: // Windows front end GUI, PeerCast core is not dependant on any of this. // Its very messy at the moment, but then again Windows UI always is.// I really don`t like programming win32 UI.. I want my borland back..//// (c) 2002 peercast.org// ------------------------------------------------// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// ------------------------------------------------#include <windows.h>#include "stdio.h"#include "string.h"#include "stdarg.h"#include "resource.h"#include "socket.h"#include "win32/wsys.h"#include "servent.h"#include "win32/wsocket.h"#include "inifile.h"#include "gui.h"#include "servmgr.h"#include "peercast.h"#include "simple.h"ThreadInfo guiThread;bool shownChannels=false;// --------------------------------------------------int logID,statusID,hitID,chanID;// --------------------------------------------------bool getButtonState(int id){ return SendDlgItemMessage(guiWnd, id,BM_GETCHECK, 0, 0) == BST_CHECKED;}// --------------------------------------------------void enableControl(int id, bool on){ EnableWindow(GetDlgItem(guiWnd,id),on);}// --------------------------------------------------void enableEdit(int id, bool on){ SendDlgItemMessage(guiWnd, id,WM_ENABLE, on, 0); SendDlgItemMessage(guiWnd, id,EM_SETREADONLY, !on, 0);}// --------------------------------------------------int getEditInt(int id){ char str[128]; SendDlgItemMessage(guiWnd, id,WM_GETTEXT, 128, (LONG)str); return atoi(str);}// --------------------------------------------------char * getEditStr(int id){ static char str[128]; SendDlgItemMessage(guiWnd, id,WM_GETTEXT, 128, (LONG)str); return str;}// --------------------------------------------------void setEditStr(int id, char *str){ SendDlgItemMessage(guiWnd, id,WM_SETTEXT, 0, (LONG)str);}// --------------------------------------------------void setEditInt(int id, int v){ char str[128]; sprintf(str,"%d",v); SendDlgItemMessage(guiWnd, id,WM_SETTEXT, 0, (LONG)str);}// --------------------------------------------------void *getListBoxSelData(int id){ int sel = SendDlgItemMessage(guiWnd, id,LB_GETCURSEL, 0, 0); if (sel >= 0) return (void *)SendDlgItemMessage(guiWnd, id,LB_GETITEMDATA, sel, 0); return NULL;}// --------------------------------------------------void setButtonState(int id, bool on){ SendDlgItemMessage(guiWnd, id,BM_SETCHECK, on, 0); SendMessage(guiWnd,WM_COMMAND,id,0);}// --------------------------------------------------void ADDLOG(const char *str,int id,bool sel,void *data, LogBuffer::TYPE type){ if (guiWnd) { int num = SendDlgItemMessage(guiWnd, id,LB_GETCOUNT, 0, 0); if (num > 100) { SendDlgItemMessage(guiWnd, id, LB_DELETESTRING, 0, 0); num--; } int idx = SendDlgItemMessage(guiWnd, id, LB_ADDSTRING, 0, (LONG)(LPSTR)str); SendDlgItemMessage(guiWnd, id, LB_SETITEMDATA, idx, (LONG)data); if (sel) SendDlgItemMessage(guiWnd, id, LB_SETCURSEL, num, 0); } if (type != LogBuffer::T_NONE) {#if _DEBUG OutputDebugString(str); OutputDebugString("\n");#endif }}// --------------------------------------------------void ADDLOG2(const char *fmt,va_list ap,int id,bool sel,void *data, LogBuffer::TYPE type){ char str[4096]; vsprintf(str,fmt,ap); ADDLOG(str,id,sel,data,type);}// --------------------------------------------------void ADDCHAN(void *d, const char *fmt,...){ va_list ap; va_start(ap, fmt); ADDLOG2(fmt,ap,chanID,false,d,LogBuffer::T_NONE); va_end(ap); }// --------------------------------------------------void ADDHIT(void *d, const char *fmt,...){ va_list ap; va_start(ap, fmt); ADDLOG2(fmt,ap,hitID,false,d,LogBuffer::T_NONE); va_end(ap); }// --------------------------------------------------void ADDCONN(void *d, const char *fmt,...){ va_list ap; va_start(ap, fmt); ADDLOG2(fmt,ap,statusID,false,d,LogBuffer::T_NONE); va_end(ap); }// --------------------------------------------------THREAD_PROC showConnections(ThreadInfo *thread){// thread->lock(); while (thread->active) { int sel,top,i; sel = SendDlgItemMessage(guiWnd, statusID,LB_GETCURSEL, 0, 0); top = SendDlgItemMessage(guiWnd, statusID,LB_GETTOPINDEX, 0, 0); SendDlgItemMessage(guiWnd, statusID, LB_RESETCONTENT, 0, 0); Servent *s = servMgr->servents; while (s) { if (s->type != Servent::T_NONE) { Host h = s->getHost(); { unsigned int ip = h.ip; unsigned short port = h.port; Host h(ip,port); char hostName[64]; h.toStr(hostName); unsigned int tnum = 0; char tdef = 's'; if (s->lastConnect) tnum = sys->getTime()-s->lastConnect; if ((s->type == Servent::T_RELAY) || (s->type == Servent::T_DIRECT)) { ADDCONN(s,"%s-%s-%d%c - %s - %d ", s->getTypeStr(),s->getStatusStr(),tnum,tdef, hostName, s->syncPos ); }else{ if (s->status == Servent::S_CONNECTED) { ADDCONN(s,"%s-%s-%d%c - %s - %d/%d", s->getTypeStr(),s->getStatusStr(),tnum,tdef, hostName, s->gnuStream.packetsIn,s->gnuStream.packetsOut); }else{ ADDCONN(s,"%s-%s-%d%c - %s", s->getTypeStr(),s->getStatusStr(),tnum,tdef, hostName ); } } } } s=s->next; } if (sel >= 0) SendDlgItemMessage(guiWnd, statusID,LB_SETCURSEL, sel, 0); if (top >= 0) SendDlgItemMessage(guiWnd, statusID,LB_SETTOPINDEX, top, 0); char cname[34]; { sel = SendDlgItemMessage(guiWnd, chanID,LB_GETCURSEL, 0, 0); top = SendDlgItemMessage(guiWnd, chanID,LB_GETTOPINDEX, 0, 0); SendDlgItemMessage(guiWnd, chanID, LB_RESETCONTENT, 0, 0);
Channel *c = chanMgr->channel; while (c) { if (c->isActive()) { strncpy(cname,c->getName(),16); cname[16] = 0; ADDCHAN(c,"%s - %d kb/s - %s",cname,c->getBitrate(),c->getStatusStr()); }
c=c->next; } if (sel >= 0) SendDlgItemMessage(guiWnd, chanID,LB_SETCURSEL, sel, 0); if (top >= 0) SendDlgItemMessage(guiWnd, chanID,LB_SETTOPINDEX, top, 0); } bool update = ((sys->getTime() - chanMgr->lastHit) < 3)||(!shownChannels); if (update) { shownChannels = true; { sel = SendDlgItemMessage(guiWnd, hitID,LB_GETCURSEL, 0, 0); top = SendDlgItemMessage(guiWnd, hitID,LB_GETTOPINDEX, 0, 0); SendDlgItemMessage(guiWnd, hitID, LB_RESETCONTENT, 0, 0);
ChanHitList *chl = chanMgr->hitlist; while (chl) { if (chl->isUsed())
{ if (chl->info.match(chanMgr->searchInfo)) { strncpy(cname,chl->info.name.cstr(),16); cname[16] = 0; ADDHIT(chl,"%s - %d kb/s - %d/%d",cname,chl->info.bitrate,chl->numListeners(),chl->numHits()); }
}
chl = chl->next; } } if (sel >= 0) SendDlgItemMessage(guiWnd, hitID,LB_SETCURSEL, sel, 0); if (top >= 0) SendDlgItemMessage(guiWnd, hitID,LB_SETTOPINDEX, top, 0); } { switch (servMgr->getFirewall()) { case ServMgr::FW_ON: SendDlgItemMessage(guiWnd, IDC_EDIT4,WM_SETTEXT, 0, (LONG)"Firewalled"); break; case ServMgr::FW_UNKNOWN: SendDlgItemMessage(guiWnd, IDC_EDIT4,WM_SETTEXT, 0, (LONG)"Unknown"); break; case ServMgr::FW_OFF: SendDlgItemMessage(guiWnd, IDC_EDIT4,WM_SETTEXT, 0, (LONG)"Normal"); break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -