📄 searchdlg.cpp
字号:
if (!theApp.serverconnect->IsConnected())
MessageBox(GetResString(IDS_ERR_NOTCONNECTED),GetResString(IDS_NOTCONNECTED),64);
else{
m_nSearchID++;
CString typeText;
CString searchString;
GetDlgItem(IDC_TypeSearch)->GetWindowText(typeText);
GetDlgItem(IDC_SEARCHNAME)->GetWindowText(searchString);
theApp.searchlist->NewSearch(&searchlistctrl,typeText,m_nSearchID);
this->GetDlgItem(IDC_STARTS)->EnableWindow(false);
this->GetDlgItem(IDC_CANCELS)->EnableWindow(true);
canceld = false;
long typeNemonic= 0x00030001;
long extensionNemonic= 0x00040001;
long avaibilityNemonic=0x15000101;
long minNemonic= 0x02000101;
long maxNemonic= 0x02000102;
byte stringParameter=1;
byte typeParameter=2;
byte numericParameter=3;
int andParameter=0x0000;
int orParameter=0x0100;
CMemFile* data = new CMemFile(100);
uint16 nSize;
char* formatC;
unsigned long avaibility;
CString sizeMin,sizeMax,extension,avaibilitystr,type;
GetDlgItem(IDC_EDITSEARCHMIN)->GetWindowText(sizeMin);
GetDlgItem(IDC_EDITSEARCHMAX)->GetWindowText(sizeMax);
unsigned long max=atol(sizeMax.GetString())*1048576;
unsigned long min=atol(sizeMin.GetString())*1048576;
if (max==0 || max<min) max=2147483646;//max file size
GetDlgItem(IDC_EDITSEARCHEXTENSION)->GetWindowText(extension);
if (extension.GetLength()>0 && extension.GetAt(0)!='.' ) extension="."+extension;
type="";
if (GetResString(IDS_SEARCH_AUDIO)==typeText) type.Format("Audio");
if (GetResString(IDS_SEARCH_VIDEO)==typeText) type.Format("Video");
if (GetResString(IDS_SEARCH_PRG)==typeText) type.Format("Pro");
if (GetResString(IDS_SEARCH_PICS)==typeText) type.Format("Image");
GetDlgItem(IDC_EDITSEARCHAVAIBILITY)->GetWindowText(avaibilitystr);
avaibility=atol(avaibilitystr.GetString());
if ( searchString.GetLength()==0 && extension.GetLength()==0)
{
delete data;
return;
}
int parametercount=0; //must be written parametercount-1 parmeter headers
if ( searchString.GetLength()>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
if (type.GetLength()>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
if (min>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
if (max>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
if (avaibility>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
if (extension.GetLength()>0)
{
parametercount++;
if (parametercount>1)
data->Write(&andParameter,2);
}
//body
if (searchString.GetLength()>0) //search a string
{
data->Write(&stringParameter,1); //write the parameter type
nSize = GetDlgItem(IDC_SEARCHNAME)->GetWindowTextLength();
data->Write(&nSize,2); // write parameter length
char* searchstr = new char[nSize+1];
GetDlgItem(IDC_SEARCHNAME)->GetWindowText(searchstr,nSize+1);
data->Write(searchstr,nSize); //write the searched string
delete[] searchstr;
}
if (type.GetLength()>0)
{
data->Write(&typeParameter,1); //write the parameter type
nSize=type.GetLength();
data->Write(&nSize,2); //write the length
formatC=type.GetBuffer();
data->Write(formatC,nSize); //write parameter
data->Write(&typeNemonic,3); //nemonic for this kind of parameter (only 3 bytes!!)
}
if (min>0)
{
data->Write(&numericParameter,1); //write the parameter type
data->Write(&min,4); //write the parameter
data->Write(&minNemonic,4); //nemonic for this kind of parameter
}
if (max>0)
{
data->Write(&numericParameter,1); //write the parameter type
data->Write(&max,4); //write the parameter
data->Write(&maxNemonic,4); //nemonic for this kind of parameter
}
if (avaibility>0)
{
data->Write(&numericParameter,1); //write the parameter type
data->Write(&avaibility,4); //write the parameter
data->Write(&avaibilityNemonic,4); //nemonic for this kind of parameter
}
if (extension.GetLength()>0)
{
data->Write(&stringParameter,1); //write the parameter type
nSize=extension.GetLength();
data->Write(&nSize,2); //write the length
formatC=extension.GetBuffer();
data->Write(formatC,nSize); //write parameter
data->Write(&extensionNemonic,3); //nemonic for this kind of parameter (only 3 bytes!!)
}
Packet* packet = new Packet(data);
packet->opcode = OP_SEARCHREQUEST;
delete data;
theApp.uploadqueue->AddUpDataOverheadServer(packet->size);
theApp.serverconnect->SendPacket(packet,false);
if (methodBox.GetCurSel()==1){
if( theApp.glob_prefs->Score() ){
theApp.serverlist->ResetSearchServerPos();
}
searchpacket = packet;
searchpacket->opcode = OP_GLOBSEARCHREQ;
servercount = 0;
searchprogress.SetRange32(0,theApp.serverlist->GetServerCount()-1);
globsearch = true;
}
else{
globsearch = false;
delete packet;
}
CreateNewTab(searchString,m_nSearchID);
}
}
void CSearchDlg::CreateNewTab(CString searchString,uint32 nSearchID){
int iTabItems = searchselect.GetItemCount();
for (int i = 0; i < iTabItems; i++){
TCITEM tci;
tci.mask = TCIF_PARAM;
if (searchselect.GetItem(i, &tci) && tci.lParam == nSearchID)
return;
}
// add new tab
TCITEM newitem;
if (searchString.GetLength() == 0)
searchString = "-";
newitem.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE;
newitem.lParam = (LPARAM)nSearchID;
newitem.pszText = searchString.GetBuffer();
newitem.cchTextMax = (int)searchString.GetLength()+10;
newitem.iImage = 0;
uint16 itemnr = searchselect.InsertItem(searchselect.GetItemCount(),&newitem);
if (!searchselect.IsWindowVisible())
searchselect.ShowWindow(SW_SHOW);
searchselect.SetCurSel(itemnr);
searchlistctrl.ShowResults(nSearchID);
}
void CSearchDlg::DeleteSearch(uint32 nSearchID){
TCITEM item;
item.mask = TCIF_PARAM;
int i;
for (i = 0; i != searchselect.GetItemCount();i++){
searchselect.GetItem(i,&item);
if (item.lParam == nSearchID)
break;
}
if (item.lParam != nSearchID)
return;
if ((!canceld) && (nSearchID == m_nSearchID))
OnBnClickedCancels(); //Sony - cancel active search before closing active tab
theApp.searchlist->RemoveResults(nSearchID);
searchselect.DeleteItem(i);
if (searchselect.GetItemCount()){
searchselect.SetCurSel(0);
item.mask = TCIF_PARAM;
searchselect.GetItem(0,&item);
searchlistctrl.ShowResults(item.lParam);
}
else{
searchlistctrl.DeleteAllItems();
searchselect.ShowWindow(SW_HIDE);
searchlistctrl.NoTabs();
}
}
void CSearchDlg::DeleteAllSearchs(){
theApp.searchlist->Clear();
searchlistctrl.DeleteAllItems();
searchselect.ShowWindow(SW_HIDE);
searchselect.DeleteAllItems();
}
void CSearchDlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
TCITEM item;
item.mask = TCIF_PARAM;
int cur_sel = searchselect.GetCurSel();
if (cur_sel == (-1))
return;
searchselect.GetItem(cur_sel,&item);
searchlistctrl.ShowResults(item.lParam);
*pResult = 0;
}
LRESULT CSearchDlg::OnCloseTab(WPARAM wparam, LPARAM lparam) {
TCITEM item;
item.mask = TCIF_PARAM;
int i = (int)wparam;
searchselect.GetItem(i,&item);
int nSearchID = item.lParam;
if ((!canceld) && (nSearchID == m_nSearchID))
OnBnClickedCancels(); //Sony - cancel active search before closing active tab
DeleteSearch(nSearchID);
//theApp.searchlist->RemoveResults(nSearchID);
return true;
}
void CSearchDlg::OnEnChangeSearchname()
{
this->GetDlgItem(IDC_STARTS)->EnableWindow(true);
}
void CSearchDlg::OnBnClickedSearchReset()
{
GetDlgItem(IDC_EDITSEARCHAVAIBILITY)->SetWindowText("");
GetDlgItem(IDC_EDITSEARCHEXTENSION)->SetWindowText("");
GetDlgItem(IDC_EDITSEARCHMIN)->SetWindowText("");
GetDlgItem(IDC_EDITSEARCHMAX)->SetWindowText("");
GetDlgItem(IDC_SEARCHNAME)->SetWindowText("");
Stypebox.SetCurSel(Stypebox.FindString(-1,GetResString(IDS_SEARCH_ANY)));
methodBox.SetCurSel(0);
OnEnChangeSearchname();
}
void CSearchDlg::UpdateCatTabs() {
int oldsel=m_cattabs.GetCurSel();
m_cattabs.DeleteAllItems();
for (int ix=0;ix<theApp.glob_prefs->GetCatCount();ix++)
m_cattabs.InsertItem(ix,(ix==0)?GetResString(IDS_ALL):theApp.glob_prefs->GetCategory(ix)->title);
if (oldsel<m_cattabs.GetItemCount()) oldsel=0;
m_cattabs.SetCurSel(oldsel);
int flag;
flag=(m_cattabs.GetItemCount()>1) ? SW_SHOW:SW_HIDE;
this->GetDlgItem(IDC_CATTAB2)->ShowWindow(flag);
this->GetDlgItem(IDC_STATIC_DLTOof)->ShowWindow(flag);
}
void CSearchDlg::SearchClipBoard() {
if (m_guardCBPrompt) return;
CString clpbrd=theApp.CopyTextFromClipboard();
if (clpbrd=="") return;
if (clpbrd.Compare(m_lastclpbrd)==0) return;
if (clpbrd.Left(13).CompareNoCase("ed2k://|file|")==0) {
m_guardCBPrompt=true;
int res=MessageBox(GetResString(IDS_ADDDOWNLOADSFROMCB)+clpbrd,GetResString(IDS_ADDDOWNLOADSFROMCBTITLE),MB_YESNO);
if (res==IDYES) {
AddEd2kLinksToDownload(clpbrd);
}
}
m_lastclpbrd=clpbrd;
m_guardCBPrompt=false;
}
void CSearchDlg::AddEd2kLinksToDownload(CString strlink){
CString resToken;
int curPos=0;
resToken= strlink.Tokenize("\t\n\r",curPos);
while (resToken != "")
{
if (resToken.Right(1)!="/") resToken+="/";
try {
CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(resToken.Trim());
_ASSERT( pLink !=0 );
if ( pLink->GetKind() == CED2KLink::kFile) {
theApp.downloadqueue->AddFileLinkToDownload(pLink->GetFileLink(),m_cattabs.GetCurSel());
} else {
delete pLink; // [i_a] memleak
throw CString("bad link");
}
delete pLink;
} catch(CString error){
OUTPUT_DEBUG_TRACE();
char buffer[200];
sprintf(buffer,GetResString(IDS_ERR_INVALIDLINK),error.GetBuffer());
theApp.emuledlg->AddLogLine(true, GetResString(IDS_ERR_LINKERROR), buffer);
}
resToken= strlink.Tokenize("\t\n\r",curPos);
}
}
void CSearchDlg::OnEnKillfocusElink()
{
CString content;
GetDlgItem(IDC_ELINK)->GetWindowText(content);
if (content.GetLength()==0 || content.Find('\n')==-1) return;
content.Replace("\n","\r\n");
content.Replace("\r\r","\r");
GetDlgItem(IDC_ELINK)->SetWindowText(content);
}
CString CSearchDlg::ToQueryString(CString str){
CString sTmp = URLEncode(str);
sTmp.Replace("%20","+");
return sTmp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -