diff options
Diffstat (limited to 'client/Dialog.cpp')
-rw-r--r-- | client/Dialog.cpp | 78 |
1 files changed, 51 insertions, 27 deletions
diff --git a/client/Dialog.cpp b/client/Dialog.cpp index 03b9db7..63a3c63 100644 --- a/client/Dialog.cpp +++ b/client/Dialog.cpp @@ -1,6 +1,7 @@ #include <QtGui> #include <iostream> +#include <typeinfo> #include "client.h" #include "Config.h" #include "Dialog.h" @@ -19,14 +20,14 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) Logger::Fatal("No valid configuration found! Can't proceed."); return ; } - - topLabel = new QLabel(tr("Top Panel")); + + /* generic proxy panel */ + topLabel = new QLabel("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++) { @@ -42,39 +43,43 @@ ProxyDialog::ProxyDialog(QWidget *parent): QDialog(parent) 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"); + topPanelLayout = new QGridLayout; + topPanelLayout->setSpacing(5); + topPanelLayout->addWidget(countryBox, 0, 0); + topPanelLayout->addWidget(stateBox, 1, 0); + topPanelLayout->addWidget(cityBox, 2, 0); + genericProxyGroup = new QButtonGroup; + /* static proxy panel */ bottomLabel = new QLabel(tr("Bottom Panel")); + QGridLayout *bottomPanelLayout = new QGridLayout; + unsigned nlines = cfg->GetStaticProxyGuiLines(); + for (unsigned i = 0; i < nlines; i++) + { + vector<ProxyEntryStatic> staticProxyLine = cfg->GetStaticProxyGuiLine(i+1); + for (unsigned j = 0; j < staticProxyLine.size(); j++) + { + //char speed[8]; + //sprintf(speed, "%d", staticProxyLine[j].speed); + //QLabel *speedLabel = new QLabel(speed); + QString btnStr = QString::fromUtf8(staticProxyLine[j]. name.c_str()); + //QLabel *btnLabel = new QLabel(btnStr); + //QHBoxLayout *btnLayout = new QHBoxLayout; + //btnLayout->addWidget(speedLabel); + //btnLayout->addWidget(btnLabel); + QPushButton *btn = new QPushButton(btnStr); + //btn->setLayout(btnLayout); + btn->setCheckable(true); + bottomPanelLayout->addWidget(btn, i, j); + } + } /* setup layouting */ - QVBoxLayout *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); } @@ -169,5 +174,24 @@ void ProxyDialog::CityActivated(int index) proxies = cfg->GetProxies(country, city); } + /* delete existing buttons */ + if (topPanelLayout->count() != 0) + { + Logger::Trace("Going to delete existing buttons\n"); + QLayoutItem *child; + while ((child = topPanelLayout->takeAt(3)) != 0) + { + delete child->widget(); + } + } + Logger::Trace("Adding new buttons\n"); + for (unsigned i = 0; i < proxies.size(); i++) + { + QString btnStr = QString::fromUtf8(proxies[i].c_str()); + QPushButton *btn = new QPushButton(btnStr); + btn->setCheckable(true); + genericProxyGroup->addButton(btn); + topPanelLayout->addWidget(btn, i / 3, i % 3 + 1); + } } |