diff options
author | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-21 04:06:39 +0200 |
---|---|---|
committer | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-12-21 04:06:39 +0200 |
commit | 2fd868ae27d74305310e5bcd2a81cd07a87659b3 (patch) | |
tree | 03141523c396af45835e070e858216633a05fc6b /client/Dialog.cpp | |
parent | 2f559d0e236c797e670f47cd70f52cde01092389 (diff) |
Generic proxy button work now. Proxy types support
Diffstat (limited to 'client/Dialog.cpp')
-rw-r--r-- | client/Dialog.cpp | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/client/Dialog.cpp b/client/Dialog.cpp index 279bfc8..6df4ceb 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -10,6 +10,7 @@ using namespace std; + ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) { UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); @@ -18,6 +19,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) if (!proxifier->IsValid()) { Logger::Fatal("No valid proxifier configuration file found!\n"); + return; } /* generic proxy panel */ @@ -94,7 +96,7 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) btn->setChecked(proxifier->IsOn(staticProxyLine[j].host, staticProxyLine[j].port)); btn->setProperty("proxyName", QString::fromLocal8Bit(staticProxyLine[j].name.c_str())); btn->setLayout(btnLayout); - connect(btn, SIGNAL(toggled(bool)), this, SLOT(StaticToggled(bool))); + connect(btn, SIGNAL(toggled(bool)), this, SLOT(StaticProxyToggled(bool))); staticProxyGroup->addButton(btn); bottomPanelLayout->addWidget(btn, i, j); } @@ -109,7 +111,42 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) setLayout(mainLayout); } -void ProxyDialog::StaticToggled(bool on) + +void ProxyDialog::ProxyToggled(bool on) +{ + QPushButton* btn = (QPushButton*) sender(); + QVariant propVal; + propVal = btn->property("proxyHost"); + QString proxyHost = propVal.toString(); + propVal = btn->property("proxyPort"); + short port = (short)propVal.toUInt(); + Logger::Debug("Proxy button toggled\n"); + Logger::Debug("State '%s', associated proxy: %s:%u\n", on ? "down" : "up", proxyHost.toStdString().c_str(), port); + + UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); + string host = proxyHost.toStdString(); + ProxyEntryGeneric* proxy = cfg->GetGenericProxy(host, port); + if (proxy == NULL) + { + Logger::Error("Generic proxy %s:%u was not found\n", host.c_str(), port); + return; + } + Proxifier *proxifier = Proxifier::GetInstance(); + if (!proxifier->IsValid()) + { + Logger::Fatal("No valid proxifier configuration file found!\n"); + } + if (on) + { + proxifier->TurnProxyOn(*proxy); + } + else + { + proxifier->TurnProxyOff(*proxy); + } +} + +void ProxyDialog::StaticProxyToggled(bool on) { QPushButton* btn = (QPushButton*) sender(); QVariant propVal = btn->property("proxyName"); @@ -217,7 +254,7 @@ void ProxyDialog::CityActivated(int index) return; } - vector<string> proxies; + vector<Proxy> proxies; UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); string country(countryBox->currentText().toLocal8Bit().constData()); string city(cityBox->currentText().toLocal8Bit().constData()); @@ -243,11 +280,22 @@ void ProxyDialog::CityActivated(int index) } Logger::Trace("Adding new buttons\n"); + Proxifier *proxifier = Proxifier::GetInstance(); + if (!proxifier->IsValid()) + { + Logger::Fatal("No valid proxifier configuration file found!\n"); + return; + } for (unsigned i = 0; i < proxies.size(); i++) { - QString btnStr = QString::fromLocal8Bit(proxies[i].c_str()); + QString btnStr = QString::fromLocal8Bit(proxies[i].host.c_str()); QPushButton *btn = new QPushButton(btnStr); btn->setCheckable(true); + btn->setChecked(proxifier->IsOn(proxies[i].host, proxies[i].port)); + btn->setProperty("proxyHost", QString::fromLocal8Bit(proxies[i].host.c_str())); + btn->setProperty("proxyPort", proxies[i].port); + + connect(btn, SIGNAL(toggled(bool)), this, SLOT(ProxyToggled(bool))); genericProxyGroup->addButton(btn); topPanelLayout->addWidget(btn, i / 3, i % 3 + 1); } |