diff options
-rw-r--r-- | client/Config.cpp | 9 | ||||
-rw-r--r-- | client/Dialog.cpp | 131 | ||||
-rw-r--r-- | client/Dialog.h | 9 | ||||
-rw-r--r-- | client/client.pro | 2 |
4 files changed, 125 insertions, 26 deletions
diff --git a/client/Config.cpp b/client/Config.cpp index 62318df..16c82ac 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -38,7 +38,7 @@ bool Config::IsConfigValid() vector<string> Config::GetCountries() { - vector<string> countries(genericProxy.size()); + vector<string> countries; for (unsigned i = 0; i < genericProxy.size(); i++) { countries.push_back(genericProxy[i].country); @@ -51,7 +51,7 @@ vector<string> Config::GetCountries() vector<string> Config::GetStates(std::string &country) { - vector<string> states(genericProxy.size()); + vector<string> states; for (unsigned i = 0; i < genericProxy.size(); i++) { if ((genericProxy[i].state != "-") && @@ -71,13 +71,14 @@ vector<string> Config::GetStates(std::string &country) vector<string> Config::GetCities(std::string &country) { + Logger::Trace("Getting cities in countre: %s", country.c_str()); string defState = "-"; - GetCities(country, defState); + return GetCities(country, defState); } vector<string> Config::GetCities(std::string &country, std::string &state) { - vector<string> cities(genericProxy.size()); + vector<string> cities; for (unsigned i = 0; i < genericProxy.size(); i++) { if ((genericProxy[i].state == state) && diff --git a/client/Dialog.cpp b/client/Dialog.cpp index 3b477e1..7fe64c8 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -19,31 +19,27 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) Logger::Fatal("No valid configuration found! Can't proceed."); return ; } - vector<string> countries = cfg->GetCountries(); - string country = "Ukraine"; - vector<string> states = cfg->GetStates(country); - string state = "AR Krym"; - vector<string> cities = cfg->GetCities(country, state); - - + topLabel = new QLabel(tr("Top Panel")); countryBox = new QComboBox; + stateBox = new QComboBox; + stateBox->setVisible(false); + cityBox = new QComboBox; + cityBox->setVisible(false); + + vector<string> countries = cfg->GetCountries(); for (unsigned i = 0; i < countries.size(); i++) { countryBox->addItem(countries[i].c_str()); } + countryBox->setCurrentIndex(-1); - stateBox = new QComboBox; - for (unsigned i = 0; i < states.size(); i++) - { - stateBox->addItem(states[i].c_str()); - } - - cityBox = new QComboBox; - for (unsigned i = 0; i < cities.size(); i++) - { - cityBox->addItem(cities[i].c_str()); - } + connect(countryBox, SIGNAL(activated(int)), + this, SLOT(CountryActivated(int))); + connect(stateBox, SIGNAL(activated(int)), + this, SLOT(StateActivated(int))); + connect(cityBox, SIGNAL(activated(int)), + this, SLOT(CityActivated(int))); /* proxy buttons */ QPushButton *topProxy1 = new QPushButton("proxy 1"); @@ -55,7 +51,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) bottomLabel = new QLabel(tr("Bottom Panel")); /* setup layouting */ - QVBoxLayout *comboBoxLayout = new QVBoxLayout; + comboBoxLayout = new QVBoxLayout; comboBoxLayout->addWidget(countryBox); comboBoxLayout->addWidget(stateBox); comboBoxLayout->addWidget(cityBox); @@ -79,4 +75,99 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) mainLayout->addLayout(bottomPanelLayout); setLayout(mainLayout); -}
\ No newline at end of file +} + +void ProxyDialog::CountryActivated(int index) +{ + Logger::Trace("Country activated. Activated index=%d\n", index); + + stateBox->setVisible(false); + cityBox->setVisible(false); + if (index == -1) + { + 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()); + + vector<string> states = cfg->GetStates(countries[index]); + if (states.empty()) + { + Logger::Info("There are no states in %s\n", countries[index].c_str()); + vector<string> cities = cfg->GetCities(countries[index]); + cityBox->clear(); + for (unsigned i = 0; i < cities.size(); i++) + { + cityBox->addItem(cities[i].c_str()); + } + cityBox->setCurrentIndex(-1); + cityBox->adjustSize(); + cityBox->setVisible(true); + } + else + { + stateBox->clear(); + for (unsigned i = 0; i < states.size(); i++) + { + stateBox->addItem(states[i].c_str()); + } + stateBox->setCurrentIndex(-1); + stateBox->adjustSize(); + stateBox->setVisible(true); + } +} + +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; + } + + 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]); + cityBox->clear(); + for (unsigned i = 0; i < cities.size(); i++) + { + cityBox->addItem(cities[i].c_str()); + } + cityBox->setCurrentIndex(-1); + cityBox->adjustSize(); + cityBox->setVisible(true); +} + +void ProxyDialog::CityActivated(int index) +{ + Logger::Trace("City activated. Activated index=%d\n", index); +} diff --git a/client/Dialog.h b/client/Dialog.h index d8cd7a9..64b42ec 100644 --- a/client/Dialog.h +++ b/client/Dialog.h @@ -5,8 +5,9 @@ #include <QDialog> #include <vector> -class QLabel; class QComboBox; +class QLabel; +class QVBoxLayout; class ProxyEntryGeneric; class ProxyEntryStatic; @@ -16,6 +17,11 @@ class ProxyDialog: public QDialog public: ProxyDialog(QWidget *parent = 0); + +private slots: + void CountryActivated(int index); + void StateActivated(int index); + void CityActivated(int index); private: QLabel *topLabel; @@ -23,6 +29,7 @@ private: QComboBox *countryBox; QComboBox *stateBox; QComboBox *cityBox; + QVBoxLayout *comboBoxLayout; }; #endif
\ No newline at end of file diff --git a/client/client.pro b/client/client.pro index d81d28d..4a6bcdc 100644 --- a/client/client.pro +++ b/client/client.pro @@ -2,7 +2,7 @@ # Automatically generated by qmake (2.01a) Wed Oct 19 03:05:59 2011 ###################################################################### -QMAKE_CXXFLAGS= -DDEBUG -g +QMAKE_CXXFLAGS= -DDEBUG -g -ggdb TEMPLATE = app TARGET = |