⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adlsearchframe.cpp

📁 p2p技术C源代码.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	// Edit existing
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;
	ADLSearch search = collection[i];

	// Invoke dialog with selected search
	ADLSProperties dlg(&search);
	if(dlg.DoModal((HWND)*this) == IDOK)
	{
		// Update search collection
		collection[i] = search;

		// Update list control
		UpdateSearch(i);	  
	}

	return 0;
}

// Remove searches
LRESULT ADLSearchFrame::onRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 
{
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;

	// Loop over all selected items
	int i;
	while((i = ctrlList.GetNextItem(-1, LVNI_SELECTED)) >= 0)
	{
		collection.erase(collection.begin() + i);
		ctrlList.DeleteItem(i);
	}
	return 0;
}

// Help
LRESULT ADLSearchFrame::onHelp(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 
{
	char title[] =
		"ADLSearch brief description";

	char message[] = 
		"ADLSearch is a tool for fast searching of directory listings downloaded from users. \n"
		"Create a new ADLSearch entering 'avi' as search string for example. When you \n"
		"download a directory listing from a user, all avi-files will be placed in a special folder \n"
		"called <<<ADLSearch>>> for easy finding. It is almost the same as using the standard \n"
		"'Find' multiple times in a directory listing. \n"
		"\n"
		"Special options: \n"
		"- 'Active' check box selects if the search is used or not. \n"
		"- 'Source Type' can be the following options; 'Filename' matches search against filename, \n"
		"   'Directory' matches against current subdirectory and places the whole structure in the \n"
		"   special folder, 'Full Path' matches against whole directory + filename. \n"
		"- 'Destination Directory' selects the special output folder for a search. Multiple folders \n"
		"   with different names can exist simultaneously. \n"
		"- 'Min/Max Size' sets file size limits. This is not used for 'Directory' type searches. \n"
		"- 'Move Up'/'Move Down' can be used to organize the list of searches. \n"
		"\n"
		"There is a new option in the context menu (right-click) for directory listings. It is called \n"
		"'Go to directory' and can be used to jump to the original location of the file or directory. \n"
		"\n"
		"Extra features:\n"
		"\n"
		"1) If you use %y.%m.%d in a search string it will be replaced by todays date. Switch \n"
		"place on y/m/d, or leave any of them out to alter the substitution. If you use %[nick] \n"
		"it will be replaced by the nick of the user you download the directory listing from. \n"
		"\n"
		"2) If you name a destination directory 'discard', it will not be shown in the total result. \n"
		"Useful with the extra feature 3) below to remove uninteresting results. \n"
		" \n"
		"3) There is a switch called 'Break on first ADLSearch match' in Settings->Advanced'.  \n"
		"If enabled, ADLSearch will stop after the first match for a specific file/directory. \n"
		"The order in the ADLSearch windows is therefore important. Example: Add a search \n"
		"item at the top of the list with string='xxx' and destination='discard'. It will catch \n"
		"many pornographic files and they will not be included in any following search results. \n"
		;

	MessageBox(message, title, MB_OK);
	return 0;
}

// Move selected entries up one step
LRESULT ADLSearchFrame::onMoveUp(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 
{
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;

	// Get selection
	vector<int> sel;
	int i = -1;
	while((i = ctrlList.GetNextItem(i, LVNI_SELECTED)) >= 0)
	{
		sel.push_back(i);
	}
	if(sel.size() < 1)
	{
		return 0;
	}

	// Find out where to insert
	int i0 = sel[0];
	if(i0 > 0)
	{
		i0 = i0 - 1;
	}

	// Backup selected searches
	ADLSearchManager::SearchCollection backup;
	for(i = 0; i < (int)sel.size(); ++i)
	{
		backup.push_back(collection[sel[i]]);
	}

	// Erase selected searches
	for(i = sel.size() - 1; i >= 0; --i)
	{
		collection.erase(collection.begin() + sel[i]);
	}

	// Insert (grouped together)
	for(i = 0; i < (int)sel.size(); ++i)
	{
		collection.insert(collection.begin() + i0 + i, backup[i]);
	}

	// Update UI
	LoadAll();

	// Restore selection
	for(i = 0; i < (int)sel.size(); ++i)
	{
		ctrlList.SetItemState(i0 + i, LVNI_SELECTED, LVNI_SELECTED);
	}

	return 0;
}

// Move selected entries down one step
LRESULT ADLSearchFrame::onMoveDown(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 
{
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;

	// Get selection
	vector<int> sel;
	int i = -1;
	while((i = ctrlList.GetNextItem(i, LVNI_SELECTED)) >= 0)
	{
		sel.push_back(i);
	}
	if(sel.size() < 1)
	{
		return 0;
	}

	// Find out where to insert
	int i0 = sel[sel.size() - 1] + 2;
	if(i0 > (int)collection.size())
	{
		i0 = collection.size();
	}

	// Backup selected searches
	ADLSearchManager::SearchCollection backup;
	for(i = 0; i < (int)sel.size(); ++i)
	{
		backup.push_back(collection[sel[i]]);
	}

	// Erase selected searches
	for(i = sel.size() - 1; i >= 0; --i)
	{
		collection.erase(collection.begin() + sel[i]);
		if(i < i0)
		{
			i0--;
		}
	}

	// Insert (grouped together)
	for(i = 0; i < (int)sel.size(); ++i)
	{
		collection.insert(collection.begin() + i0 + i, backup[i]);
	}

	// Update UI
	LoadAll();

	// Restore selection
	for(i = 0; i < (int)sel.size(); ++i)
	{
		ctrlList.SetItemState(i0 + i, LVNI_SELECTED, LVNI_SELECTED);
	}

	return 0;
}

// Clicked 'Active' check box
LRESULT ADLSearchFrame::onItemChanged(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) 
{
	NMITEMACTIVATE* item = (NMITEMACTIVATE*)pnmh;

	if((item->uChanged & LVIF_STATE) == 0)
		return 0;
	if((item->uOldState & INDEXTOSTATEIMAGEMASK(0xf)) == 0)
		return 0;
	if((item->uNewState & INDEXTOSTATEIMAGEMASK(0xf)) == 0)
		return 0;

	if(item->iItem >= 0)
	{
		// Set new active status check box
		ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;
		ADLSearch& search = collection[item->iItem];
		search.isActive = (ctrlList.GetCheckState(item->iItem) != 0);
	}
	return 0;
}

// Double-click on list control
LRESULT ADLSearchFrame::onDoubleClickList(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled) 
{
	NMITEMACTIVATE* item = (NMITEMACTIVATE*)pnmh;

	// Hit-test
	LVHITTESTINFO info;
	info.pt = item->ptAction;
    int iItem = ctrlList.SubItemHitTest(&info);
	if(iItem >= 0)
	{
		// Treat as onEdit command
		onEdit(0, 0, 0, bHandled);
	}

	return 0;
}

// Load all searches from manager
void ADLSearchFrame::LoadAll()
{
	// Clear current contents
	ctrlList.DeleteAllItems();

	// Load all searches
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;
	for(unsigned long l = 0; l < collection.size(); l++)
	{
		UpdateSearch(l, FALSE);
	}
}

// Update a specific search item
void ADLSearchFrame::UpdateSearch(int index, BOOL doDelete)
{
	ADLSearchManager::SearchCollection& collection = ADLSearchManager::getInstance()->collection;

	// Check args
	if(index >= (int)collection.size())
	{
		return;
	}
	ADLSearch& search = collection[index];

	// Delete from list control
	if(doDelete)
	{
		ctrlList.DeleteItem(index);
	}

	// Generate values
	StringList line;
	char buf[32];
	string fs;
	line.push_back(search.searchString);
	line.push_back(search.SourceTypeToString(search.sourceType));
	line.push_back(search.destDir);

	fs = "";
	if(search.minFileSize >= 0)
	{
		fs = _i64toa(search.minFileSize, buf, 10);
		fs += " ";
		fs += search.SizeTypeToStringInternational(search.typeFileSize);
	}
	line.push_back(fs);

	fs = "";
	if(search.maxFileSize >= 0)
	{
		fs = _i64toa(search.maxFileSize, buf, 10);
		fs += " ";
		fs += search.SizeTypeToStringInternational(search.typeFileSize);
	}
	line.push_back(fs);

	// Insert in list control
	ctrlList.insert(index, line);

	// Update 'Active' check box
	ctrlList.SetCheckState(index, search.isActive);
}

/**
 * @file
 * $Id: ADLSearchFrame.cpp,v 1.6 2003/07/15 14:53:11 arnetheduck Exp $
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -