📄 searchresultswnd.cpp
字号:
if (pParams->ulMinSize > 0)
query.AppendFormat(_T("&min_size=%u"),pParams->ulMinSize);
if (pParams->ulMaxSize > 0)
query.AppendFormat(_T("&max_size=%u"),pParams->ulMaxSize);
break;
case SearchTypeVeryCD:
query = "http://www.verycd.com/forum/index.php?act=down&q=";
query += ToQueryString(pParams->strExpression);
break;
default:
return _T("");
}
return query;
}
void CSearchResultsWnd::DownloadSelected()
{
DownloadSelected(thePrefs.AddNewFilesPaused());
}
void CSearchResultsWnd::DownloadSelected(bool paused)
{
CWaitCursor curWait;
POSITION pos = searchlistctrl.GetFirstSelectedItemPosition();
while (pos != NULL)
{
int index = searchlistctrl.GetNextSelectedItem(pos);
if (index > -1)
{
// get selected listview item (may be a child item from an expanded search result)
CSearchFile* cur_file = (CSearchFile*)searchlistctrl.GetItemData(index);
// use filename of selected listview item
theApp.downloadqueue->AddSearchToDownload(cur_file, paused, m_cattabs.GetCurSel());
// get parent
if (cur_file->GetListParent() != NULL)
cur_file = cur_file->GetListParent();
// update parent and all childs
searchlistctrl.UpdateSources(cur_file);
}
}
}
void CSearchResultsWnd::OnSysColorChange()
{
CResizableFormView::OnSysColorChange();
SetAllIcons();
}
void CSearchResultsWnd::SetAllIcons()
{
if (icon_search)
VERIFY( DestroyIcon(icon_search) );
icon_search = theApp.LoadIcon(_T("SearchResults"), 16, 16);
((CStatic*)GetDlgItem(IDC_SEARCHLST_ICO))->SetIcon(icon_search);
CImageList iml;
iml.Create(16,16,theApp.m_iDfltImageListColorFlags|ILC_MASK,0,1);
iml.SetBkColor(CLR_NONE);
iml.Add(CTempIconLoader(_T("SearchMethod_ServerActive"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_GlobalActive"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_KademliaActive"), 16, 16));
iml.Add(CTempIconLoader(_T("StatsClients"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_SERVER"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_GLOBAL"), 16, 16));
iml.Add(CTempIconLoader(_T("SearchMethod_KADEMLIA"), 16, 16));
searchselect.SetImageList(&iml);
m_imlSearchResults.DeleteImageList();
m_imlSearchResults.Attach(iml.Detach());
searchselect.SetPadding(CSize(10, 3));
}
void CSearchResultsWnd::Localize()
{
searchlistctrl.Localize();
UpdateCatTabs();
GetDlgItem(IDC_CLEARALL)->SetWindowText(GetResString(IDS_REMOVEALLSEARCH));
GetDlgItem(IDC_RESULTS_LBL)->SetWindowText(GetResString(IDS_SW_RESULT));
GetDlgItem(IDC_SDOWNLOAD)->SetWindowText(GetResString(IDS_SW_DOWNLOAD));
GetDlgItem(IDC_OPEN_PARAMS_WND)->SetWindowText(GetResString(IDS_SEARCHPARAMS)+_T("..."));
}
void CSearchResultsWnd::OnBnClickedClearall()
{
CancelSearch();
DeleteAllSearchs();
CWnd* pWndFocus = GetFocus();
m_pwndParams->m_ctlMore.EnableWindow(FALSE);
if (pWndFocus && pWndFocus->m_hWnd == m_pwndParams->m_ctlMore.m_hWnd)
m_pwndParams->m_ctlStart.SetFocus();
}
static CSearchExpr _SearchExpr;
CStringArray _astrParserErrors;
#ifdef _DEBUG
static char _chLastChar = 0;
static CStringA _strSearchTree;
bool DumpSearchTree(int& iExpr, const CSearchExpr& rSearchExpr)
{
if (iExpr >= rSearchExpr.m_aExpr.GetCount())
return false;
CStringA strTok = rSearchExpr.m_aExpr[iExpr++];
if (strTok == SEARCHOPTOK_AND || strTok == SEARCHOPTOK_OR || strTok == SEARCHOPTOK_NOT)
{
if (_chLastChar != '(' && _chLastChar != '\0')
_strSearchTree.AppendFormat(" ");
_strSearchTree.AppendFormat("(%s ", strTok.Mid(1));
_chLastChar = '(';
DumpSearchTree(iExpr, rSearchExpr);
DumpSearchTree(iExpr, rSearchExpr);
_strSearchTree.AppendFormat(")");
_chLastChar = ')';
}
else
{
if (_chLastChar != '(' && _chLastChar != '\0')
_strSearchTree.AppendFormat(" ");
_strSearchTree.AppendFormat("\"%s\"", strTok);
_chLastChar = '\1';
}
return true;
}
bool DumpSearchTree(const CSearchExpr& rSearchExpr)
{
_chLastChar = '\0';
int iExpr = 0;
return DumpSearchTree(iExpr, rSearchExpr);
}
#endif//!_DEBUG
static CStringA _strCurKadKeywordA;
void ParsedSearchExpression(const CSearchExpr* pexpr)
{
int iOpAnd = 0;
int iOpOr = 0;
int iOpNot = 0;
CStringA strDbg;
for (int i = 0; i < pexpr->m_aExpr.GetCount(); i++)
{
CStringA str(pexpr->m_aExpr[i]);
if (str == SEARCHOPTOK_AND)
{
iOpAnd++;
strDbg.AppendFormat("%s ", str.Mid(1));
}
else if (str == SEARCHOPTOK_OR)
{
iOpOr++;
strDbg.AppendFormat("%s ", str.Mid(1));
}
else if (str == SEARCHOPTOK_NOT)
{
iOpNot++;
strDbg.AppendFormat("%s ", str.Mid(1));
}
else
{
strDbg.AppendFormat("\"%s\" ", str);
}
}
if (thePrefs.GetDebugServerSearchesLevel() > 0)
Debug(_T("Search Expr: %hs\n"), strDbg);
// this limit (+ the additional operators which will be added later) has to match the limit in 'CreateSearchExpressionTree'
// +1 Type (Audio, Video)
// +1 MinSize
// +1 MaxSize
// +1 Avail
// +1 Extension
// +1 Complete sources
// +1 Codec
// +1 Bitrate
// +1 Length
// +1 Title
// +1 Album
// +1 Artist
// ---------------
// 12
if (iOpAnd + iOpOr + iOpNot > 10)
yyerror(GetResString(IDS_SEARCH_TOOCOMPLEX));
_SearchExpr.m_aExpr.RemoveAll();
// optimize search expression, if no OR nor NOT specified
if (iOpAnd > 0 && iOpOr == 0 && iOpNot == 0)
{
CStringA strAndTerms;
for (int i = 0; i < pexpr->m_aExpr.GetCount(); i++)
{
if (pexpr->m_aExpr[i] != SEARCHOPTOK_AND)
{
// Minor optimization: Because we added the Kad keyword to the boolean search expression,
// we remove it here (and only here) again because we know that the entire search expression
// does only contain (implicit) ANDed strings.
if (pexpr->m_aExpr[i] != _strCurKadKeywordA)
{
if (!strAndTerms.IsEmpty())
strAndTerms += ' ';
strAndTerms += pexpr->m_aExpr[i];
}
}
}
ASSERT( _SearchExpr.m_aExpr.GetCount() == 0);
_SearchExpr.m_aExpr.Add(strAndTerms);
}
else
{
if (pexpr->m_aExpr.GetCount() != 1 || pexpr->m_aExpr[0] != _strCurKadKeywordA)
_SearchExpr.m_aExpr.Append(pexpr->m_aExpr);
}
#ifdef _DEBUG
if (thePrefs.GetDebugServerSearchesLevel() > 0){
_strSearchTree.Empty();
DumpSearchTree(_SearchExpr);
Debug(_T("Search Tree: %hs\n"), _strSearchTree);
}
#endif
}
CString DbgGetMetaTagName(UINT uMetaTagID)
{
extern CString GetMetaTagName(UINT uTagID);
return GetMetaTagName(uMetaTagID);
}
CString DbgGetMetaTagName(LPCSTR pszMetaTagID)
{
extern CString GetMetaTagName(UINT uTagID);
if (strlen(pszMetaTagID) == 1)
return GetMetaTagName(((BYTE*)pszMetaTagID)[0]);
CString strName;
strName.Format(_T("\"%s\""), pszMetaTagID);
return strName;
}
CString DbgGetOperatorName(bool bEd2k, UINT uOperator)
{
static const LPCTSTR _aszEd2kOps[] =
{
_T("="),
_T(">"),
_T("<"),
_T(">="),
_T("<="),
_T("<>"),
};
static const LPCTSTR _aszKadOps[] =
{
_T("="),
_T(">="),
_T("<="),
_T(">"),
_T("<"),
_T("<>"),
};
if (bEd2k)
{
if (uOperator >= ARRSIZE(_aszEd2kOps)){
ASSERT(0);
return _T("*UnkOp*");
}
return _aszEd2kOps[uOperator];
}
else
{
if (uOperator >= ARRSIZE(_aszKadOps)){
ASSERT(0);
return _T("*UnkOp*");
}
return _aszKadOps[uOperator];
}
}
class CSearchExprTarget
{
public:
CSearchExprTarget(CSafeMemFile* pData, EUtf8Str eStrEncode)
{
m_data = pData;
m_eStrEncode = eStrEncode;
}
const CString& GetDebugString() const
{
return m_strDbg;
}
void WriteBooleanAND()
{
m_data->WriteUInt8(0); // boolean operator parameter type
m_data->WriteUInt8(0x00); // "AND"
m_strDbg.AppendFormat(_T("AND "));
}
void WriteBooleanOR()
{
m_data->WriteUInt8(0); // boolean operator parameter type
m_data->WriteUInt8(0x01); // "OR"
m_strDbg.AppendFormat(_T("OR "));
}
void WriteBooleanNOT()
{
m_data->WriteUInt8(0); // boolean operator parameter type
m_data->WriteUInt8(0x02); // "NOT"
m_strDbg.AppendFormat(_T("NOT "));
}
void WriteMetaDataSearchParam(const CString& rstrValue)
{
m_data->WriteUInt8(1); // string parameter type
m_data->WriteString(rstrValue, m_eStrEncode); // string value
m_strDbg.AppendFormat(_T("\"%s\" "), rstrValue);
}
void WriteMetaDataSearchParam(UINT uMetaTagID, const CString& rstrValue)
{
m_data->WriteUInt8(2); // string parameter type
m_data->WriteString(rstrValue, m_eStrEncode); // string value
m_data->WriteUInt16(sizeof uint8); // meta tag ID length
m_data->WriteUInt8(uMetaTagID); // meta tag ID name
m_strDbg.AppendFormat(_T("%s=\"%s\" "), DbgGetMetaTagName(uMetaTagID), rstrValue);
}
void WriteMetaDataSearchParamA(UINT uMetaTagID, const CStringA& rstrValueA)
{
m_data->WriteUInt8(2); // string parameter type
m_data->WriteString(rstrValueA); // string value
m_data->WriteUInt16(sizeof uint8); // meta tag ID length
m_data->WriteUInt8(uMetaTagID); // meta tag ID name
m_strDbg.AppendFormat(_T("%s=\"%hs\" "), DbgGetMetaTagName(uMetaTagID), rstrValueA);
}
void WriteMetaDataSearchParam(LPCSTR pszMetaTagID, const CString& rstrValue)
{
m_data->WriteUInt8(2); // string parameter type
m_data->WriteString(rstrValue, m_eStrEncode); // string value
m_data->WriteString(pszMetaTagID); // meta tag ID
m_strDbg.AppendFormat(_T("%s=\"%s\" "), DbgGetMetaTagName(pszMetaTagID), rstrValue);
}
void WriteMetaDataSearchParam(UINT uMetaTagID, UINT uOperator, UINT uValue, bool bEd2k)
{
m_data->WriteUInt8(3); // numeric parameter type
m_data->WriteUInt32(uValue); // numeric value
m_data->WriteUInt8(uOperator); // comparison operator
m_data->WriteUInt16(sizeof uint8); // meta tag ID length
m_data->WriteUInt8(uMetaTagID); // meta tag ID name
m_strDbg.AppendFormat(_T("%s%s%u "), DbgGetMetaTagName(uMetaTagID), DbgGetOperatorName(bEd2k, uOperator), uValue);
}
void WriteMetaDataSearchParam(LPCSTR pszMetaTagID, UINT uOperator, UINT uValue, bool bEd2k)
{
m_data->WriteUInt8(3); // numeric parameter type
m_data->WriteUInt32(uValue); // numeric value
m_data->WriteUInt8(uOperator); // comparison operator
m_data->WriteString(pszMetaTagID); // meta tag ID
m_strDbg.AppendFormat(_T("%s%s%u "), DbgGetMetaTagName(pszMetaTagID), DbgGetOperatorName(bEd2k, uOperator), uValue);
}
void WriteOldMinMetaDataSearchParam(UINT uMetaTagID, UINT uValue, bool bEd2k)
{
UINT uOperator;
if (bEd2k){
uOperator = ED2K_SEARCH_OP_GREATER;
uValue -= 1;
}
else
uOperator = KAD_SEARCH_OP_GREATER_EQUAL;
WriteMetaDataSearchParam(uMetaTagID, uOperator, uValue, bEd2k);
}
void WriteOldMinMetaDataSearchParam(LPCSTR pszMetaTagID, UINT uValue, bool bEd2k)
{
UINT uOperator;
if (bEd2k){
uOperator = ED2K_SEARCH_OP_GREATER;
uValue -= 1;
}
else
uOperator = KAD_SEARCH_OP_GREATER_EQUAL;
WriteMetaDataSearchParam(pszMetaTagID, uOperator, uValue, bEd2k);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -