=== modified file 'dcpp/AdcHub.cpp' --- dcpp/AdcHub.cpp 2010-05-10 17:23:07 +0000 +++ dcpp/AdcHub.cpp 2010-06-02 13:33:09 +0000 @@ -709,7 +709,7 @@ } } -void AdcHub::search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) { +void AdcHub::search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList) { if(state != STATE_NORMAL) return; @@ -730,6 +730,12 @@ if(aFileType == SearchManager::TYPE_DIRECTORY) { c.addParam("TY", "2"); } + if (!aExtList.empty()) { + StringTokenizer st(aExtList, ';'); + for(StringIter i = st.getTokens().begin(); i != st.getTokens().end(); ++i) { + c.addParam("EX", *i); + } + } } if(!aToken.empty()) === modified file 'dcpp/AdcHub.h' --- dcpp/AdcHub.h 2010-02-12 18:33:24 +0000 +++ dcpp/AdcHub.h 2010-05-22 10:55:43 +0000 @@ -38,7 +38,7 @@ virtual void hubMessage(const string& aMessage, bool thirdPerson = false); virtual void privateMessage(const OnlineUser& user, const string& aMessage, bool thirdPerson = false); virtual void sendUserCmd(const UserCommand& command, const StringMap& params); - virtual void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken); + virtual void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList); virtual void password(const string& pwd); virtual void info(bool alwaysSend); === modified file 'dcpp/Client.h' --- dcpp/Client.h 2010-02-11 21:44:13 +0000 +++ dcpp/Client.h 2010-05-22 11:11:41 +0000 @@ -43,7 +43,7 @@ virtual void hubMessage(const string& aMessage, bool thirdPerson = false) = 0; virtual void privateMessage(const OnlineUser& user, const string& aMessage, bool thirdPerson = false) = 0; virtual void sendUserCmd(const UserCommand& command, const StringMap& params) = 0; - virtual void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) = 0; + virtual void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList) = 0; virtual void password(const string& pwd) = 0; virtual void info(bool force) = 0; === modified file 'dcpp/ClientManager.cpp' --- dcpp/ClientManager.cpp 2010-02-11 21:44:13 +0000 +++ dcpp/ClientManager.cpp 2010-05-22 11:20:22 +0000 @@ -498,12 +498,12 @@ for(Client::Iter i = clients.begin(); i != clients.end(); ++i) { if((*i)->isConnected()) { - (*i)->search(aSizeMode, aSize, aFileType, aString, aToken); + (*i)->search(aSizeMode, aSize, aFileType, aString, aToken, Util::emptyString /*ExtList*/); } } } -void ClientManager::search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) { +void ClientManager::search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList) { Lock l(cs); for(StringIter it = who.begin(); it != who.end(); ++it) { @@ -511,7 +511,7 @@ for(Client::Iter j = clients.begin(); j != clients.end(); ++j) { Client* c = *j; if(c->isConnected() && c->getHubUrl() == client) { - c->search(aSizeMode, aSize, aFileType, aString, aToken); + c->search(aSizeMode, aSize, aFileType, aString, aToken, aExtList); } } } === modified file 'dcpp/ClientManager.h' --- dcpp/ClientManager.h 2010-02-11 21:44:13 +0000 +++ dcpp/ClientManager.h 2010-05-22 10:51:19 +0000 @@ -60,7 +60,7 @@ bool isConnected(const string& aUrl) const; void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken); - void search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken); + void search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList); void infoUpdated(); UserPtr getUser(const string& aNick, const string& aHubUrl) throw(); === modified file 'dcpp/NmdcHub.cpp' --- dcpp/NmdcHub.cpp 2010-02-25 18:56:41 +0000 +++ dcpp/NmdcHub.cpp 2010-05-22 10:55:09 +0000 @@ -832,7 +832,7 @@ } } -void NmdcHub::search(int aSizeType, int64_t aSize, int aFileType, const string& aString, const string&) { +void NmdcHub::search(int aSizeType, int64_t aSize, int aFileType, const string& aString, const string&, const string&) { checkstate(); char c1 = (aSizeType == SearchManager::SIZE_DONTCARE) ? 'F' : 'T'; char c2 = (aSizeType == SearchManager::SIZE_ATLEAST) ? 'F' : 'T'; === modified file 'dcpp/NmdcHub.h' --- dcpp/NmdcHub.h 2010-02-11 21:44:13 +0000 +++ dcpp/NmdcHub.h 2010-05-22 10:54:43 +0000 @@ -42,7 +42,7 @@ virtual void hubMessage(const string& aMessage, bool /*thirdPerson*/ = false); virtual void privateMessage(const OnlineUser& aUser, const string& aMessage, bool /*thirdPerson*/ = false); virtual void sendUserCmd(const UserCommand& command, const StringMap& params); - virtual void search(int aSizeType, int64_t aSize, int aFileType, const string& aString, const string& aToken); + virtual void search(int aSizeType, int64_t aSize, int aFileType, const string& aString, const string& aToken, const string& aExtList); virtual void password(const string& aPass) { send("$MyPass " + fromUtf8(aPass) + "|"); } virtual void info(bool force) { myInfo(force); } === modified file 'dcpp/SearchManager.cpp' --- dcpp/SearchManager.cpp 2010-02-11 21:44:13 +0000 +++ dcpp/SearchManager.cpp 2010-06-03 09:19:14 +0000 @@ -26,6 +26,8 @@ #include "ShareManager.h" #include "SearchResult.h" #include "LogManager.h" +#include "StringTokenizer.h" +#include "SimpleXML.h" namespace dcpp { @@ -34,7 +36,7 @@ stop(false), lastSearch(GET_TICK()) { - + SettingsManager::getInstance()->addListener(this); } SearchManager::~SearchManager() throw() { @@ -64,9 +66,9 @@ } } -void SearchManager::search(StringList& who, const string& aName, int64_t aSize /* = 0 */, TypeModes aTypeMode /* = TYPE_ANY */, SizeModes aSizeMode /* = SIZE_ATLEAST */, const string& aToken /* = Util::emptyString */) { +void SearchManager::search(StringList& who, const string& aName, int64_t aSize /* = 0 */, TypeModes aTypeMode /* = TYPE_ANY */, SizeModes aSizeMode /* = SIZE_ATLEAST */, const string& aToken /* = Util::emptyString */, const string& aExtList /* = Util::emptyString */) { if(okToSearch()) { - ClientManager::getInstance()->search(who, aSizeMode, aSize, aTypeMode, normalizeWhitespace(aName), aToken); + ClientManager::getInstance()->search(who, aSizeMode, aSize, aTypeMode, normalizeWhitespace(aName), aToken, aExtList); lastSearch = GET_TICK(); } } @@ -338,4 +340,149 @@ } } +void SearchManager::setDefaults() { + Lock l(cs); + + searchTypes.clear(); + searchTypes.push_back(make_pair(Util::toString(TYPE_AUDIO),"mp3;flac;ogg;mpc;ape;wma")); + searchTypes.push_back(make_pair(Util::toString(TYPE_COMPRESSED),"rar;7z;zip;tar;gz;bz2;z")); + searchTypes.push_back(make_pair(Util::toString(TYPE_DOCUMENT),"doc;xls;docx;xlsx;odf;pdf;xps;htm;html")); + searchTypes.push_back(make_pair(Util::toString(TYPE_EXECUTABLE),"exe;com;dll;bat;cmd")); + searchTypes.push_back(make_pair(Util::toString(TYPE_PICTURE),"jpg;jpeg;png;gif;tga")); + searchTypes.push_back(make_pair(Util::toString(TYPE_VIDEO),"mpg;avi;mkv;wmv;mov")); + + fire(SearchManagerListener::SearchTypesChanged(), true); +} + +void SearchManager::checkName(const string& name) { + if (name.size() < 2) { + throw SearchTypeException(_("Invalid search type name")); + } +} + +void SearchManager::checkExtensions(string& extensions) { + // Check extension list for invalid characters + StringTokenizer exts(extensions, ';'); + extensions = Util::emptyString; + for(StringList::iterator i = exts.getTokens().begin(); i != exts.getTokens().end();++i) { + if(!i->empty() && Util::checkExtension(*i)) { + if (i != exts.getTokens().begin()) extensions += ";"; + extensions += *i; + } + } + + if (extensions.empty()) { + throw SearchTypeException(_("Invalid extension list")); + } +} + +void SearchManager::addType(const string& name, string& extensions) { + checkName(name); + + Lock l(cs); + + for(StringPairList::iterator i = searchTypes.begin(); i != searchTypes.end();++i) { + if (name == i->first) { + throw SearchTypeException(_("Search type name already exists")); + } + } + + checkExtensions(extensions); + + searchTypes.push_back(make_pair(name, extensions)); + + fire(SearchManagerListener::SearchTypesChanged(), false); +} + +void SearchManager::delType(const string& name) { + checkName(name); + delType_(name); +} + +bool SearchManager::delType_(const string& name) { + Lock l(cs); + for(StringPairList::iterator i = searchTypes.begin(); i != searchTypes.end();++i) { + if (name == i->first) { + searchTypes.erase(i); + fire(SearchManagerListener::SearchTypesChanged(), true); + return true; + } + } + return false; +} + +void SearchManager::getExtensions(const string& name, string& extensions) { + Lock l(cs); + for(StringPairList::iterator i = searchTypes.begin(); i != searchTypes.end();++i) { + if (name == i->first) { + extensions = i->second; + return; + } + } +} + +void SearchManager::renameType(const string& oldName, const string& newName) { + checkName(oldName); + checkName(newName); + + string extensions; + getExtensions(oldName, extensions); + if (!extensions.empty()) { + if (delType_(oldName)) { + addType(newName, extensions); + } + } +} + +void SearchManager::modType(const string& name, string& extensions) { + checkExtensions(extensions); + + Lock l(cs); + for(StringPairList::iterator i = searchTypes.begin(); i != searchTypes.end();++i) { + if (name == i->first) { + i->second = extensions; + fire(SearchManagerListener::SearchTypesChanged(), false); + } + } +} + +void SearchManager::load(SimpleXML& aXml) { + Lock l(cs); + + searchTypes.clear(); + + aXml.resetCurrentChild(); + if(aXml.findChild("SearchTypes")) { + aXml.stepIn(); + while(aXml.findChild("SearchType")) { + string extensions = aXml.getChildData(); + if(extensions.empty()) { + continue; + } + string name = aXml.getChildAttrib("Id"); + if(name.empty()) { + continue; + } + searchTypes.push_back(make_pair(name, extensions)); + } + aXml.stepOut(); + } + + if (searchTypes.empty()) { + setDefaults(); + } +} + +void SearchManager::save(SimpleXML& aXml) { + Lock l(cs); + + aXml.addTag("SearchTypes"); + aXml.stepIn(); + for(StringPairList::iterator i = searchTypes.begin(); i != searchTypes.end();++i) { + aXml.addTag("SearchType", i->second); + aXml.addChildAttrib("Id", i->first); + } + aXml.stepOut(); +} + } // namespace dcpp === modified file 'dcpp/SearchManager.h' --- dcpp/SearchManager.h 2010-02-11 21:44:13 +0000 +++ dcpp/SearchManager.h 2010-06-07 16:38:14 +0000 @@ -30,13 +30,18 @@ #include "SearchManagerListener.h" #include "TimerManager.h" #include "AdcCommand.h" +#include "CriticalSection.h" +#include "Exception.h" namespace dcpp { +STANDARD_EXCEPTION(SearchTypeException); + +class SimpleXML; class SearchManager; class SocketException; -class SearchManager : public Speaker, public Singleton, public Thread +class SearchManager : public Speaker, public Singleton, public Thread, private SettingsManagerListener { public: enum SizeModes { @@ -62,9 +67,9 @@ search(aName, Util::toInt64(aSize), aTypeMode, aSizeMode, aToken); } - void search(StringList& who, const string& aName, int64_t aSize, TypeModes aTypeMode, SizeModes aSizeMode, const string& aToken); - void search(StringList& who, const string& aName, const string& aSize, TypeModes aTypeMode, SizeModes aSizeMode, const string& aToken) { - search(who, aName, Util::toInt64(aSize), aTypeMode, aSizeMode, aToken); + void search(StringList& who, const string& aName, int64_t aSize, TypeModes aTypeMode, SizeModes aSizeMode, const string& aToken, const string& aExtList); + void search(StringList& who, const string& aName, const string& aSize, TypeModes aTypeMode, SizeModes aSizeMode, const string& aToken, const string& aExtList) { + search(who, aName, Util::toInt64(aSize), aTypeMode, aSizeMode, aToken, aExtList); } void respond(const AdcCommand& cmd, const CID& cid, bool isUdpActive); @@ -90,6 +95,18 @@ return timeToSearch() <= 0; } + // Search types + void setDefaults(); + void addType(const string& name, string& extensions); + void delType(const string& name); + void renameType(const string& oldName, const string& newName); + void modType(const string& name, string& extensions); + + StringPairList getTypes() const { + Lock l(cs); + return searchTypes; + } + private: std::auto_ptr socket; @@ -105,6 +122,25 @@ virtual ~SearchManager() throw(); void onData(const uint8_t* buf, size_t aLen, const string& address); + + mutable CriticalSection cs; + + // Search types + StringPairList searchTypes; //name, extlist + bool delType_(const string& name); + void checkExtensions(string& extensions); + void checkName(const string& name); + void getExtensions(const string& name, string& extensions); + void load(SimpleXML& aXml); + void save(SimpleXML& aXml); + + // SettingsManagerListener + virtual void on(SettingsManagerListener::Save, SimpleXML& xml) throw() { + save(xml); + } + virtual void on(SettingsManagerListener::Load, SimpleXML& xml) throw() { + load(xml); + } }; } // namespace dcpp === modified file 'dcpp/SearchManagerListener.h' --- dcpp/SearchManagerListener.h 2010-02-11 21:44:13 +0000 +++ dcpp/SearchManagerListener.h 2010-05-26 16:39:25 +0000 @@ -29,7 +29,10 @@ template struct X { enum { TYPE = I }; }; typedef X<0> SR; + typedef X<1> SearchTypesChanged; + virtual void on(SR, const SearchResultPtr&) throw() = 0; + virtual void on(SearchTypesChanged, bool reordered) throw() { } }; } // namespace dcpp === modified file 'dcpp/Util.cpp' --- dcpp/Util.cpp 2010-05-04 16:37:43 +0000 +++ dcpp/Util.cpp 2010-06-02 16:16:13 +0000 @@ -366,6 +366,18 @@ return tmp; } +bool Util::checkExtension(string tmp) { + for(int i = 0; i < tmp.length(); i++) { + if (tmp[i] < 0 || tmp[i] == 32 || tmp[i] == ':') { + return false; + } + } + if(tmp.find_first_of(badChars, 0) != string::npos) { + return false; + } + return true; +} + string Util::cleanPathChars(string aNick) { string::size_type i = 0; === modified file 'dcpp/Util.h' --- dcpp/Util.h 2010-03-20 16:51:58 +0000 +++ dcpp/Util.h 2010-05-20 17:33:03 +0000 @@ -201,6 +201,7 @@ static void decodeUrl(const string& aUrl, string& aServer, uint16_t& aPort, string& aFile); static string validateFileName(string aFile); + static bool checkExtension(string tmp); static string cleanPathChars(string aNick); static string addBrackets(const string& s); === modified file 'win32/SearchFrame.cpp' --- win32/SearchFrame.cpp 2010-05-08 16:17:17 +0000 +++ win32/SearchFrame.cpp 2010-06-07 16:57:08 +0000 @@ -188,16 +188,7 @@ fileType = group->addChild(WinUtil::Seeds::comboBoxStatic); addWidget(fileType); - - fileType->addValue(T_("Any")); - fileType->addValue(T_("Audio")); - fileType->addValue(T_("Compressed")); - fileType->addValue(T_("Document")); - fileType->addValue(T_("Executable")); - fileType->addValue(T_("Picture")); - fileType->addValue(T_("Video")); - fileType->addValue(T_("Directory")); - fileType->addValue(T_("TTH")); + fillFileType(false); gs.caption = T_("Search options"); cur = options->addChild(gs)->addChild(Grid::Seed(3, 1)); @@ -294,6 +285,30 @@ SearchFrame::~SearchFrame() { } +void SearchFrame::fillFileType(bool reordered) { + int toSelect = reordered ? 0 : fileType->getSelected(); + + fileType->clear(); + fileType->addValue(T_("Any")); + fileType->addValue(T_("Audio")); + fileType->addValue(T_("Compressed")); + fileType->addValue(T_("Document")); + fileType->addValue(T_("Executable")); + fileType->addValue(T_("Picture")); + fileType->addValue(T_("Video")); + fileType->addValue(T_("Directory")); + fileType->addValue(T_("TTH")); + + const StringPairList searchTypes = SearchManager::getInstance()->getTypes(); + for(StringPairList::const_iterator i = searchTypes.begin(), iend = searchTypes.end(); i != iend; ++i) { + if (i->first.size() > 1) { + fileType->addValue(Text::toT(i->first)); + } + } + + fileType->setSelected(toSelect); +} + void SearchFrame::layout() { dwt::Rectangle r(getClientSize()); @@ -848,6 +863,7 @@ void SearchFrame::runSearch() { StringList clients; + string extList; // Change Default Settings If Changed if (onlyFree != BOOLSETTING(SEARCH_ONLY_FREE_SLOTS)) @@ -930,6 +946,14 @@ int ftype = fileType->getSelected(); + // Get ADC searchtype extensions if any selected + if (ftype > SearchManager::TYPE_ANY && ftype < SearchManager::TYPE_DIRECTORY) { + getExtList(Util::toString(ftype), extList); // Predefined searchtype + } else if (ftype > SearchManager::TYPE_TTH) { + getExtList(Text::fromT(fileType->getValue(ftype)), extList); // Custom searchtype + ftype = SearchManager::TYPE_ANY; // Any type for NMDC + } + status->setText(STATUS_STATUS, str(TF_("Searching for %1%...") % s)); status->setText(STATUS_COUNT, Util::emptyStringT); status->setText(STATUS_FILTERED, Util::emptyStringT); @@ -940,7 +964,7 @@ if(SearchManager::getInstance()->okToSearch()) { SearchManager::getInstance()->search(clients, Text::fromT(s), llsize, - (SearchManager::TypeModes)ftype, searchMode, token); + (SearchManager::TypeModes)ftype, searchMode, token, extList); if(BOOLSETTING(CLEAR_SEARCH)) // Only clear if the search was sent searchBox->setText(Util::emptyStringT); } else { @@ -957,6 +981,16 @@ } } +void SearchFrame::getExtList(const string& typeName, string& extList) { + const StringPairList searchTypes = SearchManager::getInstance()->getTypes(); + for(StringPairList::const_iterator i = searchTypes.begin(), iend = searchTypes.end(); i != iend; ++i) { + if (i->first == typeName) { + extList = i->second; + return; + } + } +} + void SearchFrame::updateStatusFiltered() { status->setText(STATUS_FILTERED, str(TF_("%1% filtered") % droppedResults)); } @@ -1055,3 +1089,10 @@ void SearchFrame::on(ClientDisconnected, Client* c) throw() { callAsync(std::tr1::bind(&SearchFrame::onHubRemoved, this, new HubInfo(c))); } + +void SearchFrame::on(SearchManagerListener::SearchTypesChanged, bool reordered) throw() { + fillFileType(reordered); + if (reordered) { + SettingsManager::getInstance()->set(SettingsManager::LAST_SEARCH_TYPE, fileType->getSelected()); + } +} === modified file 'win32/SearchFrame.h' --- win32/SearchFrame.h 2010-05-08 16:17:17 +0000 +++ win32/SearchFrame.h 2010-06-02 16:18:43 +0000 @@ -230,10 +230,13 @@ void initSecond(); bool eachSecond(); + void fillFileType(bool reordered); + void treat(const SearchInfo::Download& dl); void runUserCommand(const UserCommand& uc); void runSearch(); + void getExtList(const string& typeName, string& extList); void updateStatusFiltered(); MenuPtr makeMenu(); @@ -245,6 +248,7 @@ // SearchManagerListener virtual void on(SearchManagerListener::SR, const SearchResultPtr& aResult) throw(); void addResult(SearchInfo* si); + virtual void on(SearchManagerListener::SearchTypesChanged, bool reordered) throw(); // ClientManagerListener virtual void on(ClientConnected, Client* c) throw(); === added file 'win32/SearchTypePage.cpp' --- win32/SearchTypePage.cpp 1970-01-01 00:00:00 +0000 +++ win32/SearchTypePage.cpp 2010-06-03 09:52:49 +0000 @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "stdafx.h" + +#include "resource.h" + +#include "SearchTypePage.h" + +#include +#include +#include +#include "ParamDlg.h" +#include "WinUtil.h" + +static const ColumnInfo columns[] = { + { N_("Search type name"), 100, false }, + { N_("Extensions"), 100, false } +}; + +SearchTypePage::SearchTypePage(dwt::Widget* parent) : +PropPage(parent), +grid(0), +types(0), +rename(0), +remove(0), +modify(0) + +{ + //setHelpId(IDH_SEARCHTYPEPAGE); + + predefinedTypes.push_back(T_("Audio")); + predefinedTypes.push_back(T_("Compressed")); + predefinedTypes.push_back(T_("Document")); + predefinedTypes.push_back(T_("Executable")); + predefinedTypes.push_back(T_("Picture")); + predefinedTypes.push_back(T_("Video")); + + grid = addChild(Grid::Seed(2, 1)); + grid->column(0).mode = GridInfo::FILL; + grid->row(0).mode = GridInfo::FILL; + grid->row(0).align = GridInfo::STRETCH; + + { + GroupBoxPtr group = grid->addChild(GroupBox::Seed(T_("Available search types"))); + //group->setHelpId(IDH_SETTINGS_SEARCHTYPES_LIST); + + GridPtr cur = group->addChild(Grid::Seed(4, 1)); + cur->column(0).mode = GridInfo::FILL; + cur->row(0).mode = GridInfo::FILL; + cur->row(0).align = GridInfo::STRETCH; + cur->setSpacing(6); + + Table::Seed seed = WinUtil::Seeds::Dialog::table; + types = cur->addChild(seed); + types->setSingleRowSelection(); + + { + GridPtr row = cur->addChild(Grid::Seed(1, 5)); + row->column(0).mode = GridInfo::FILL; + row->column(1).mode = GridInfo::FILL; + row->column(2).mode = GridInfo::FILL; + row->column(3).mode = GridInfo::FILL; + row->column(4).mode = GridInfo::FILL; + + row->addChild(Button::Seed(T_("&Add")))->onClicked(std::tr1::bind(&SearchTypePage::handleAddClicked, this)); + + modify = row->addChild(Button::Seed(T_("M&odify"))); + modify->onClicked(std::tr1::bind(&SearchTypePage::handleModClicked, this)); + + rename = row->addChild(Button::Seed(T_("Re&name"))); + rename->onClicked(std::tr1::bind(&SearchTypePage::handleRenameClicked, this)); + + remove = row->addChild(Button::Seed(T_("&Remove"))); + remove->onClicked(std::tr1::bind(&SearchTypePage::handleRemoveClicked, this)); + + row->addChild(Button::Seed(T_("&Defaults")))->onClicked(std::tr1::bind(&SearchTypePage::handleDefaultsClicked, this)); + } + + cur->addChild(Label::Seed(T_("Note; Configured search types have effect on ADC hubs only!"))); + + } + + WinUtil::makeColumns(types, columns, 2); + + fillList(); + + handleItemChanged(); + + types->onDblClicked(std::tr1::bind(&SearchTypePage::handleDoubleClick, this)); + types->onRaw(std::tr1::bind(&SearchTypePage::handleItemChanged, this), dwt::Message(WM_NOTIFY, LVN_ITEMCHANGED)); +} + +SearchTypePage::~SearchTypePage() { +} + +void SearchTypePage::layout(const dwt::Rectangle& rc) { + PropPage::layout(rc); + + dwt::Point clientSize = getClientSize(); + grid->layout(dwt::Rectangle(7, 4, clientSize.x - 14, clientSize.y - 21)); + + types->setColumnWidth(1, types->getWindowSize().x - 120); +} + +void SearchTypePage::handleDoubleClick() { + if(types->hasSelected()) { + handleModClicked(); + } else { + handleAddClicked(); + } +} + +LRESULT SearchTypePage::handleItemChanged() { + bool enable = types->hasSelected(); + bool changeable = enable && typeNames[types->getSelected()].size() > 1; + rename->setEnabled(changeable); + remove->setEnabled(changeable); + modify->setEnabled(enable); + return 0; +} + +void SearchTypePage::handleAddClicked() { + try { + ParamDlg dlg(this, T_("New search type"), T_("Name of the new search type")); + dlg.addTextBox(T_("List of file extensions, separate with semicolon (;)"), lastExts); + if(dlg.run() == IDOK) { + const TStringList& values = dlg.getValues(); + const string name = Text::fromT(values[0]); + lastExts = values[1]; + string extensions = Text::fromT(lastExts); + SearchManager::getInstance()->addType(name, extensions); + addRow(name, extensions); + typeNames.push_back(name); + } + } catch(const SearchTypeException& e) { + showError(e.getError()); + } +} + +void SearchTypePage::handleModClicked() { + int cur = types->getSelected(); + try { + ParamDlg dlg(this, T_("Modify search type extensions"), T_("List of file extensions, separate with semicolon (;)"), types->getText(cur, 1)); + if(dlg.run() == IDOK) { + string extensions = Text::fromT(dlg.getValue()); + SearchManager::getInstance()->modType(typeNames[cur], extensions); + types->setText(cur,1, Text::toT(extensions)); + } + } catch(const SearchTypeException& e) { + showError(e.getError()); + } +} + +void SearchTypePage::handleDefaultsClicked() { + if(dwt::MessageBox(this).show(T_("This will delete all defined search types and restore the default ones. Do you want to continue?"), _T(APPNAME) _T(" ") _T(VERSIONSTRING), dwt::MessageBox::BOX_YESNO, dwt::MessageBox::BOX_ICONEXCLAMATION) == IDYES ) { + SearchManager::getInstance()->setDefaults(); + types->clear(); + fillList(); + } +} + +void SearchTypePage::handleRenameClicked() { + int cur = types->getSelected(); + try { + ParamDlg dlg(this, T_("Modify search type name"), T_("Enter new name"), types->getText(cur, 0)); + if(dlg.run() == IDOK) { + const string newName = Text::fromT(dlg.getValue()); + SearchManager::getInstance()->renameType(typeNames[cur], newName); + types->setText(cur,0, Text::toT(newName)); + } + } catch(const SearchTypeException& e) { + showError(e.getError()); + } +} + +void SearchTypePage::handleRemoveClicked() { + int cur = types->getSelected(); + try { + if(dwt::MessageBox(this).show(T_("Do you really want to delete this search type?"), _T(APPNAME) _T(" ") _T(VERSIONSTRING), dwt::MessageBox::BOX_YESNO, dwt::MessageBox::BOX_ICONEXCLAMATION) == IDYES ) { + SearchManager::getInstance()->delType(typeNames[cur]); + types->erase(cur); + typeNames.erase(typeNames.begin() + cur); + } + } catch(const SearchTypeException& e) { + showError(e.getError()); + } +} + +void SearchTypePage::addRow(const string& name, const string& extensions) { + TStringList row; + + tstring nameT=Text::toT(name); + for(size_t i = 0; i != predefinedTypes.size(); ++i) { + if (nameT == Text::toT(Util::toString(i + 1))) { + nameT = predefinedTypes[i]; + break; + } + } + + row.push_back(nameT); + row.push_back(Text::toT(extensions)); + types->insert(row); + + typeNames.push_back(name); +} + +void SearchTypePage::fillList() { + typeNames.clear(); + const StringPairList searchtypes = SearchManager::getInstance()->getTypes(); + for(StringPairList::const_iterator i = searchtypes.begin(), iend = searchtypes.end(); i != iend; ++i) + addRow(i->first, i->second); +} + +void SearchTypePage::showError(const string& e) { + dwt::MessageBox(this).show(Text::toT(e), _T(APPNAME) _T(" ") _T(VERSIONSTRING), + dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONSTOP); +} === added file 'win32/SearchTypePage.h' --- win32/SearchTypePage.h 1970-01-01 00:00:00 +0000 +++ win32/SearchTypePage.h 2010-06-02 16:19:18 +0000 @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef DCPLUSPLUS_WIN32_SEARCHTYPE_PAGE_H +#define DCPLUSPLUS_WIN32_SEARCHTYPE_PAGE_H + +#include "PropPage.h" + +class SearchTypePage : public PropPage +{ +public: + SearchTypePage(dwt::Widget* parent); + virtual ~SearchTypePage(); + + virtual void layout(const dwt::Rectangle& rect); + +private: + TStringList predefinedTypes; + StringList typeNames; + tstring lastExts; + + GridPtr grid; + TablePtr types; + + ButtonPtr rename; + ButtonPtr remove; + ButtonPtr modify; + + void handleDoubleClick(); + LRESULT handleItemChanged(); + void handleAddClicked(); + void handleModClicked(); + void handleRenameClicked(); + void handleRemoveClicked(); + void handleDefaultsClicked(); + + void addRow(const string& virtualPath, const string& realPath); + void addDirectory(const tstring& aPath); + void fillList(); + void showError(const string& e); +}; + +#endif // !defined(DCPLUSPLUS_WIN32_SEARCHTYPE_PAGE_H) === modified file 'win32/SettingsDialog.cpp' --- win32/SettingsDialog.cpp 2010-02-11 21:44:13 +0000 +++ win32/SettingsDialog.cpp 2010-05-22 14:13:28 +0000 @@ -40,6 +40,7 @@ #include "UCPage.h" #include "CertificatesPage.h" #include "BandwidthLimitPage.h" +#include "SearchTypePage.h" SettingsDialog::SettingsDialog(dwt::Widget* parent) : dwt::ModalDialog(parent), @@ -124,6 +125,7 @@ addPage(T_("User Commands"), cur, new UCPage(cur), item); addPage(T_("Security Certificates"), cur, new CertificatesPage(cur), item); addPage(T_("Bandwidth Limiting"), cur, new BandwidthLimitPage(cur), item); + addPage(T_("Search Types"), cur, new SearchTypePage(cur), item); } }