diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-06 01:36:04 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-12-06 01:36:04 +0200 |
commit | cf9dda85c464ad6697b1b8960101d54dae986c98 (patch) | |
tree | 11d428da2b1fc4ad5055cee5c9ecd552b0dc75e4 /client | |
parent | 1a5d1e21d83fc5ef305c6138421ffb6f41cadcda (diff) | |
parent | 9974bde9106a1d7e05fbe12266d8bbfe00436a62 (diff) |
Merge branch 'master' of ssh://sss.chaoslab.ru//home/private_git/proxy_ui
Diffstat (limited to 'client')
-rw-r--r-- | client/Config.cpp | 11 | ||||
-rw-r--r-- | client/Config.h | 2 | ||||
-rw-r--r-- | client/Dialog.cpp | 26 | ||||
-rw-r--r-- | client/UpdatedConfig.cpp | 17 | ||||
-rw-r--r-- | client/config.cfg | 18 | ||||
-rw-r--r-- | client/main.cpp | 17 | ||||
-rw-r--r-- | client/style.qss | 2 |
7 files changed, 56 insertions, 37 deletions
diff --git a/client/Config.cpp b/client/Config.cpp index 40c24b2..38ff50f 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -73,20 +73,17 @@ void Config::FileEntry::Parse(string entry, ActionType _action) /* * ServerEntry nested class section */ -Config::ServerEntry::ServerEntry(string entry) -{ - ServerEntry(); - +Config::ServerEntry::ServerEntry(string& entry): host("127.0.0.1"), timeout(120), retryTimeout(60) +{ /* processing server entry e.g.: "8.8.8.8 600 60" */ size_t start = 0, end = 0; end = entry.find(' '); host = entry.substr(start, end); start = end+1; - end = entry.find(' '); + end = entry.find(' ', start); timeout = atoi(entry.substr(start, end).c_str()); start = end+1; - end = entry.find(' '); - retryTimeout = atoi(entry.substr(start, end).c_str()); + retryTimeout = atoi(entry.substr(start).c_str()); } diff --git a/client/Config.h b/client/Config.h index 466f93a..5254361 100644 --- a/client/Config.h +++ b/client/Config.h @@ -225,7 +225,7 @@ protected: * @brief initilize ServerEntry instance from config file entry<br/> * @param entry config file entry value, e.g.: '8.8.8.8:8080 600 60' */ - ServerEntry(string entry); + ServerEntry(string& entry); /** * @brief Hostname or address of server<br/> diff --git a/client/Dialog.cpp b/client/Dialog.cpp index a5d205c..4ce48be 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -25,7 +25,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) vector<string> countries = cfg->GetCountries(); for (unsigned i = 0; i < countries.size(); i++) { - QString country = QString::fromUtf8(countries[i].c_str()); + QString country = QString::fromLocal8Bit(countries[i].c_str()); countryBox->addItem(country); } countryBox->setCurrentIndex(-1); @@ -75,8 +75,12 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) QLabel *btnLabel = new QLabel(btnStr); btnLabel->setAttribute(Qt::WA_TransparentForMouseEvents); QHBoxLayout *btnLayout = new QHBoxLayout; + // insert spacers at the beginning and + // the end to center-align button content + btnLayout->addStretch(); btnLayout->addWidget(btnLabel); btnLayout->setSizeConstraint(QLayout::SetMinimumSize); + btnLayout->addStretch(); QPushButton *btn = new QPushButton(); btn->setObjectName("bottomBtn"); btn->setCheckable(true); @@ -115,7 +119,7 @@ void ProxyDialog::CountryActivated(int index) return; } - string country(countryBox->currentText().toUtf8().constData()); + string country(countryBox->currentText().toLocal8Bit().constData()); Logger::Info("Country %s was selected\n", country.c_str()); UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); @@ -127,7 +131,7 @@ void ProxyDialog::CountryActivated(int index) cityBox->clear(); for (unsigned i = 0; i < cities.size(); i++) { - QString city = QString::fromUtf8(cities[i].c_str()); + QString city = QString::fromLocal8Bit(cities[i].c_str()); cityBox->addItem(city); } cityBox->setCurrentIndex(-1); @@ -139,7 +143,7 @@ void ProxyDialog::CountryActivated(int index) stateBox->clear(); for (unsigned i = 0; i < states.size(); i++) { - QString state = QString::fromUtf8(states[i].c_str()); + QString state = QString::fromLocal8Bit(states[i].c_str()); stateBox->addItem(state); } stateBox->setCurrentIndex(-1); @@ -157,8 +161,8 @@ void ProxyDialog::StateActivated(int index) return; } - string country(countryBox->currentText().toUtf8().constData()); - string state(stateBox->currentText().toUtf8().constData()); + string country(countryBox->currentText().toLocal8Bit().constData()); + string state(stateBox->currentText().toLocal8Bit().constData()); Logger::Info("State %s was selected\n", state.c_str()); UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); @@ -166,7 +170,7 @@ void ProxyDialog::StateActivated(int index) cityBox->clear(); for (unsigned i = 0; i < cities.size(); i++) { - QString city = QString::fromUtf8(cities[i].c_str()); + QString city = QString::fromLocal8Bit(cities[i].c_str()); cityBox->addItem(city); } cityBox->setCurrentIndex(-1); @@ -184,11 +188,11 @@ void ProxyDialog::CityActivated(int index) vector<string> proxies; UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); - string country(countryBox->currentText().toUtf8().constData()); - string city(cityBox->currentText().toUtf8().constData()); + string country(countryBox->currentText().toLocal8Bit().constData()); + string city(cityBox->currentText().toLocal8Bit().constData()); if (stateBox->isVisible()) { - string state(stateBox->currentText().toUtf8().constData()); + string state(stateBox->currentText().toLocal8Bit().constData()); proxies = cfg->GetProxies(country, state, city); } else @@ -210,7 +214,7 @@ void ProxyDialog::CityActivated(int index) Logger::Trace("Adding new buttons\n"); for (unsigned i = 0; i < proxies.size(); i++) { - QString btnStr = QString::fromUtf8(proxies[i].c_str()); + QString btnStr = QString::fromLocal8Bit(proxies[i].c_str()); QPushButton *btn = new QPushButton(btnStr); btn->setCheckable(true); genericProxyGroup->addButton(btn); diff --git a/client/UpdatedConfig.cpp b/client/UpdatedConfig.cpp index 860042d..d5b4177 100644 --- a/client/UpdatedConfig.cpp +++ b/client/UpdatedConfig.cpp @@ -19,7 +19,8 @@ string UpdatedConfig::GetServerAddr() Logger::Error("No valid server records present!\n"); return string(""); } - return servers[activeSrvIndex].host; + string ret = servers[activeSrvIndex].host; + return ret; } UpdatedConfig::UpdatedConfig() @@ -35,7 +36,7 @@ UpdatedConfig::UpdatedConfig() return; } - client = new SslClient(QString::fromStdString(servers[0].host)); + client = new SslClient(QString::fromLocal8Bit(servers[0].host.c_str())); connect(client, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)), this, SLOT(gotServerReply(SslClient::RequestType&, QByteArray&))); connect(client, SIGNAL(ConnectionError()), @@ -68,6 +69,11 @@ void UpdatedConfig::update() { activeSrvIndex = 0; } + ServerEntry current = servers[activeSrvIndex]; + client->SetServerAddr(QString::fromLocal8Bit(current.host.c_str())); + configUpdateTimer->stop(); + configUpdateTimer->setInterval(current.retryTimeout * 1000); + configUpdateTimer->start(); } retryFailed = false; } @@ -154,9 +160,10 @@ void UpdatedConfig::gotServerReply(SslClient::RequestType &type, QByteArray &con Logger::Warn("Unknown reply type: %x\n", type); break; } - updateStatus |= (1 << type); end: + updateStatus |= (1 << type); + if (updateStatus != UPDATED_STATE_FULL) { Logger::Trace("Still need to update other config parts. Update status: %x\n", updateStatus); @@ -168,10 +175,10 @@ end: client->Disconnect(); configValid = true; - /* reset retry params and setup timer to fire on next planned update */ + // reset retry params and setup timer to fire on next planned update + // but leave activeSrvIndex as it is, so we will reconnect to the same working serv next time time = 0; updateStatus = 0; - activeSrvIndex = 0; retryFailed = false; configUpdateTimer->stop(); diff --git a/client/config.cfg b/client/config.cfg index 1f0ed0f..b6a77a9 100644 --- a/client/config.cfg +++ b/client/config.cfg @@ -1,9 +1,9 @@ -config_update_interval=300; -client_update_interval=60000; -server=127.0.0.1 600 60; -welcome_msg=Привет маме!; -config_downloaded_msg=Конфиг успешно загружен!; -top_panel_text=Верхняя панель; -bottom_panel_text=Нижняя панель; -speed_visibility=1; - +config_update_interval=300;
+client_update_interval=60000;
+server=127.0.0.1 10 10;
+server=192.168.1.100 600 60;
+welcome_msg=Welcome to the proxy configurator!;
+config_downloaded_msg=Config downloaded successfully;
+top_panel_text=Top Panel;
+bottom_panel_text=Bottom Panel;
+speed_visibility=1;
diff --git a/client/main.cpp b/client/main.cpp index 4b6d734..f7da59e 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,5 +1,5 @@ -#ifdef WINDOWS +#ifdef WIN32 #define UpdaterName "updater.exe" #define PathSlash "\\" #else @@ -22,9 +22,16 @@ int main(int argc, char *argv[]) Logger::Info("Starting client application\n"); string path = argv[0]; + QString dir; size_t p = path.find_last_of(PathSlash); - QString dir = QString::fromStdString(path.substr(0, p)); - Logger::Trace("Application path: %s\n", dir.toStdString().c_str()); + if (p == string::npos) + { + dir = QString::fromStdString("."); + } + else + { + dir = QString::fromStdString(path.substr(0, p)); + } // check if client should be update QFileInfo newClient(dir + PathSlash + "client.bin.latest"); @@ -46,6 +53,10 @@ int main(int argc, char *argv[]) // check if initial config exists (config.cfg) // without it application is useless QFileInfo configInfo(dir + PathSlash + "config.cfg"); + + fprintf(stderr, "%s\n", configInfo.fileName().toStdString().c_str()); + + if (! configInfo.exists()) { Logger::Fatal("Initial configuration file (config.cfg) do not exist!\n"); diff --git a/client/style.qss b/client/style.qss index 8ab52ce..290c9a5 100644 --- a/client/style.qss +++ b/client/style.qss @@ -32,7 +32,7 @@ QLabel { } QLabel#topLabel { -font-family: monospace; + font-family: monospace; font-weight: bold; font-style: italic; font-size: 16px; |