#include #include #include "client.h" #include "Config.h" #include "Dialog.h" #include "Proxy.h" using namespace std; ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) { //WIPE it out!!! COnfig shoud be reread by timer event! Config *cfg = Config::CurrentConfig(); cfg->AcquireConfig(); if (! cfg->IsConfigValid()) { Logger::Fatal("No valid configuration found! Can't proceed."); return ; } topLabel = new QLabel(tr("Top Panel")); countryBox = new QComboBox; stateBox = new QComboBox; stateBox->setVisible(false); cityBox = new QComboBox; cityBox->setVisible(false); vector countries = cfg->GetCountries(); for (unsigned i = 0; i < countries.size(); i++) { countryBox->addItem(countries[i].c_str()); } countryBox->setCurrentIndex(-1); 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"); QPushButton *topProxy2 = new QPushButton("proxy 2"); QPushButton *bottomProxy1 = new QPushButton("proxy 3"); QPushButton *bottomProxy2 = new QPushButton("proxy 4"); bottomLabel = new QLabel(tr("Bottom Panel")); /* setup layouting */ comboBoxLayout = new QVBoxLayout; comboBoxLayout->addWidget(countryBox); comboBoxLayout->addWidget(stateBox); comboBoxLayout->addWidget(cityBox); QVBoxLayout *proxyButtonLayout = new QVBoxLayout; proxyButtonLayout->addWidget(topProxy1); proxyButtonLayout->addWidget(topProxy2); QHBoxLayout *topPanelLayout = new QHBoxLayout; topPanelLayout->addLayout(comboBoxLayout); topPanelLayout->addLayout(proxyButtonLayout); QHBoxLayout *bottomPanelLayout = new QHBoxLayout; bottomPanelLayout->addWidget(bottomProxy1); bottomPanelLayout->addWidget(bottomProxy2); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(topLabel); mainLayout->addLayout(topPanelLayout); mainLayout->addWidget(bottomLabel); mainLayout->addLayout(bottomPanelLayout); setLayout(mainLayout); } 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 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 states = cfg->GetStates(countries[index]); if (states.empty()) { Logger::Info("There are no states in %s\n", countries[index].c_str()); vector 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 countries = cfg->GetCountries(); if (countryIndex > countries.size()) { Logger::Error("Invalid country index selected: %d\n", countryIndex); return; } vector states = cfg->GetStates(countries[countryIndex]); if (index > states.size()) { Logger::Error("Invalid state index: %d\n", index); return; } vector 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); }