diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/Config.cpp | 29 | ||||
-rw-r--r-- | client/Config.h | 23 | ||||
-rw-r--r-- | client/Dialog.cpp | 80 | ||||
-rw-r--r-- | client/Dialog.h | 1 | ||||
-rw-r--r-- | client/config/proxy_list.cfg | 31 |
5 files changed, 100 insertions, 64 deletions
diff --git a/client/Config.cpp b/client/Config.cpp index 16c82ac..614d95f 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -49,7 +49,7 @@ vector<string> Config::GetCountries() return countries; } -vector<string> Config::GetStates(std::string &country) +vector<string> Config::GetStates(string &country) { vector<string> states; for (unsigned i = 0; i < genericProxy.size(); i++) @@ -69,14 +69,13 @@ vector<string> Config::GetStates(std::string &country) return states; } -vector<string> Config::GetCities(std::string &country) +vector<string> Config::GetCities(string &country) { - Logger::Trace("Getting cities in countre: %s", country.c_str()); string defState = "-"; return GetCities(country, defState); } -vector<string> Config::GetCities(std::string &country, std::string &state) +vector<string> Config::GetCities(string &country, string &state) { vector<string> cities; for (unsigned i = 0; i < genericProxy.size(); i++) @@ -93,6 +92,28 @@ vector<string> Config::GetCities(std::string &country, std::string &state) return cities; } +vector<string> Config::GetProxies(string &country, string &city) +{ + string defState = "-"; + return GetProxies(country, defState, city); +} + +vector<string> Config::GetProxies(string &country, string &state, string &city) +{ + vector<string> proxies; + for (unsigned i = 0; i < genericProxy.size(); i++) + { + if ((genericProxy[i].state == state) && + (genericProxy[i].country == country) && + (genericProxy[i].city == city)) + { + proxies.push_back(genericProxy[i].host); + } + } + sort(proxies.begin(), proxies.end()); + return proxies; +} + int Config::ReadGenericProxy() { Logger::Info("Parsing generic proxy list\n"); diff --git a/client/Config.h b/client/Config.h index ad30ebf..9d9e9eb 100644 --- a/client/Config.h +++ b/client/Config.h @@ -55,18 +55,35 @@ public: * @brief Get list of cities in particular country without states<br/> * (generic proxy records only) * @param country name of country to get list of states for - * @return Alphabetically sorted vector<string> with unique city names<br/> + * @return Alphabetically sorted vector<string> with unique city names */ std::vector<std::string> GetCities(std::string &country); /** * @brief Get list of cities in particular country and state<br/> * (generic proxy records only) - * @param country name of country to get list of states for - * @param state name state to get list of proxies for<br/> + * @param country name of country to get list of cities for + * @param state name of state to get list of cities for * @return Alphabetically sorted vector<string> with unique city names */ std::vector<std::string> GetCities(std::string &country, std::string &state); + + /* + * @brief Get list of proxy server addresses in particular country and city (without states)<br/> + * (generic proxy records only) + * @param country name of country to get list of proxies for + * @param city name of city to get list of proxies for + */ + std::vector<std::string> GetProxies(std::string &country, std::string &city); + + /* + * @brief Get list of proxy server addresses in particular country, state and city<br/> + * (generic proxy records only) + * @param country name of country to get list of proxies for + * @param state name of state to get list of proxies for + * @param city name of city to get list of proxies for + */ + std::vector<std::string> GetProxies(std::string &country, std::string &state, std::string &city); protected: Config(); private: diff --git a/client/Dialog.cpp b/client/Dialog.cpp index 7fe64c8..03b9db7 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -30,7 +30,8 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) vector<string> countries = cfg->GetCountries(); for (unsigned i = 0; i < countries.size(); i++) { - countryBox->addItem(countries[i].c_str()); + QString country = QString::fromUtf8(countries[i].c_str()); + countryBox->addItem(country); } countryBox->setCurrentIndex(-1); @@ -51,7 +52,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) bottomLabel = new QLabel(tr("Bottom Panel")); /* setup layouting */ - comboBoxLayout = new QVBoxLayout; + QVBoxLayout *comboBoxLayout = new QVBoxLayout; comboBoxLayout->addWidget(countryBox); comboBoxLayout->addWidget(stateBox); comboBoxLayout->addWidget(cityBox); @@ -80,7 +81,6 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) void ProxyDialog::CountryActivated(int index) { Logger::Trace("Country activated. Activated index=%d\n", index); - stateBox->setVisible(false); cityBox->setVisible(false); if (index == -1) @@ -88,24 +88,20 @@ void ProxyDialog::CountryActivated(int index) return; } - Config *cfg = Config::CurrentConfig(); - vector<string> countries = cfg->GetCountries(); - if (index > countries.size()) - { - Logger::Error("Invalid country index: %d\n", index); - return; - } - Logger::Info("Country %s was selected\n", countries[index].c_str()); + string country(countryBox->currentText().toUtf8().constData()); + Logger::Info("Country %s was selected\n", country.c_str()); - vector<string> states = cfg->GetStates(countries[index]); + Config *cfg = Config::CurrentConfig(); + vector<string> states = cfg->GetStates(country); if (states.empty()) { - Logger::Info("There are no states in %s\n", countries[index].c_str()); - vector<string> cities = cfg->GetCities(countries[index]); + Logger::Info("There are no states in %s\n",country.c_str()); + vector<string> cities = cfg->GetCities(country); cityBox->clear(); for (unsigned i = 0; i < cities.size(); i++) - { - cityBox->addItem(cities[i].c_str()); + { + QString city = QString::fromUtf8(cities[i].c_str()); + cityBox->addItem(city); } cityBox->setCurrentIndex(-1); cityBox->adjustSize(); @@ -116,7 +112,8 @@ void ProxyDialog::CountryActivated(int index) stateBox->clear(); for (unsigned i = 0; i < states.size(); i++) { - stateBox->addItem(states[i].c_str()); + QString state = QString::fromUtf8(states[i].c_str()); + stateBox->addItem(state); } stateBox->setCurrentIndex(-1); stateBox->adjustSize(); @@ -127,40 +124,23 @@ void ProxyDialog::CountryActivated(int index) void ProxyDialog::StateActivated(int index) { Logger::Trace("State activated. Activated index=%d\n", index); - cityBox->setVisible(false); if (index == -1) { return; } - int countryIndex = countryBox->currentIndex(); - if (countryIndex == -1) - { - Logger::Error("Invalid country index selected: %d\n", countryIndex); - return; - } + string country(countryBox->currentText().toUtf8().constData()); + string state(stateBox->currentText().toUtf8().constData()); + Logger::Info("State %s was selected\n", state.c_str()); Config *cfg = Config::CurrentConfig(); - vector<string> countries = cfg->GetCountries(); - if (countryIndex > countries.size()) - { - Logger::Error("Invalid country index selected: %d\n", countryIndex); - return; - } - - vector<string> states = cfg->GetStates(countries[countryIndex]); - if (index > states.size()) - { - Logger::Error("Invalid state index: %d\n", index); - return; - } - - vector<string> cities = cfg->GetCities(countries[countryIndex], states[index]); + vector<string> cities = cfg->GetCities(country, state); cityBox->clear(); for (unsigned i = 0; i < cities.size(); i++) { - cityBox->addItem(cities[i].c_str()); + QString city = QString::fromUtf8(cities[i].c_str()); + cityBox->addItem(city); } cityBox->setCurrentIndex(-1); cityBox->adjustSize(); @@ -170,4 +150,24 @@ void ProxyDialog::StateActivated(int index) void ProxyDialog::CityActivated(int index) { Logger::Trace("City activated. Activated index=%d\n", index); + if (index == -1) + { + return; + } + + vector<string> proxies; + Config *cfg = Config::CurrentConfig(); + string country(countryBox->currentText().toUtf8().constData()); + string city(cityBox->currentText().toUtf8().constData()); + if (stateBox->isVisible()) + { + string state(stateBox->currentText().toUtf8().constData()); + proxies = cfg->GetProxies(country, state, city); + } + else + { + proxies = cfg->GetProxies(country, city); + } + + } diff --git a/client/Dialog.h b/client/Dialog.h index 64b42ec..1b66b55 100644 --- a/client/Dialog.h +++ b/client/Dialog.h @@ -29,7 +29,6 @@ private: QComboBox *countryBox; QComboBox *stateBox; QComboBox *cityBox; - QVBoxLayout *comboBoxLayout; }; #endif
\ No newline at end of file diff --git a/client/config/proxy_list.cfg b/client/config/proxy_list.cfg index 0a14616..c4ec480 100644 --- a/client/config/proxy_list.cfg +++ b/client/config/proxy_list.cfg @@ -1,17 +1,17 @@ -user:password@server.com:123 "Ukraine" "Kharkovskaya obl." "Kharkov"; -server.com:123 "Ukraine" "Kharkovskaya obl." "Izum"; -user:password@server.com:123 "Ukraine" "Kharkovskaya obl." "Balakleya"; -user:password@server.com:123 "Ukraine" "Kievskaya obl." "Kiev"; -user:password@server.com:123 "Ukraine" "Sumskaya obl." "Sumi"; -user:password@server.com:123 "Ukraine" "Sumskaya obl." "Konotop"; -user:password@server.com:123 "Ukraine" "Sumskaya obl." "Seredina-Buda"; -user:password@server.com:123 "Ukraine" "AR Krym" "Alushta"; -user:password@server.com:123 "Ukraine" "AR Krym" "Simferorpol"; -user:password@server.com:123 "Ukraine" "AR Krym" "Sevastopol"; -user:password@server.com:123 "Ukraine" "AR Krym" "Evpatoria"; -server.com:123 "Ukraine" "AR Krym" "Kerch"; -user:password@server.com:123 "Ukraine" "AR Krym" "Yalta"; -user:password@server.com:123 "Ukraine" "AR Krym" "Sudak"; +user:password@server.com:123 "Украина" "Харьковская обл." "Харьков"; +server.com:123 "Украина" "Харьковская обл." "Изюм"; +user:password@server.com:123 "Украина" "Харьковская обл." "Балаклея"; +user:password@server.com:123 "Украина" "Киевская обл." "Киев"; +user:password@server.com:123 "Украина" "Сумская обл." "Сумы"; +user:password@server.com:123 "Украина" "Сумская обл." "Конотоп"; +user:password@server.com:123 "Украина" "Сумская обл." "Середина-Буда"; +user:password@server.com:123 "Украина" "АР Крым" "Алушта"; +user:password@server.com:123 "Украина" "АР Крым" "Симферополь"; +user:password@server.com:123 "Украина" "АР Крым" "Севастополь"; +user:password@server.com:123 "Украина" "АР Крым" "Евпатория"; +server.com:123 "Украина" "АР Крым" "Керч"; +user:password@server.com:123 "Украина" "АР Крым" "Ялта"; +user:password@server.com:123 "Украина" "АР Крым" "Судак"; server.net:213 "Russia" "-" "Moscow"; server.net:213 "Russia" "-" "St. Petersburg"; server.net:213 "Russia" "-" "Perm"; @@ -19,6 +19,5 @@ server.net:213 "Russia" "-" "Vlasivostok"; server.net:213 "Russia" "-" "Belgorod"; server.net:213 "Russia" "-" "Bryansk"; server.net:213 "Russia" "-" "Sochi"; -server.net:213 "USA" "California" "San francisco"; +server.net:213 "USA" "California" "San Francisco"; sdf:wer@sfds.info:666 "China" "-" "Shanghai"; - |