| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * BKG NTRIP Client
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: bncTableDlg
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: Displays the source table, allows mountpoints selection
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 24-Dec-2005
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include "bnctabledlg.h"
|
|---|
| 19 | #include "bncgetthread.h"
|
|---|
| 20 |
|
|---|
| 21 | // Constructor
|
|---|
| 22 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 23 | bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
|
|---|
| 24 |
|
|---|
| 25 | setMinimumSize(600,400);
|
|---|
| 26 |
|
|---|
| 27 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|---|
| 28 |
|
|---|
| 29 | _casterHostLabel = new QLabel(tr("caster host"));
|
|---|
| 30 | _casterPortLabel = new QLabel(tr("caster port"));
|
|---|
| 31 | _casterUserLabel = new QLabel(tr("user"));
|
|---|
| 32 | _casterPasswordLabel = new QLabel(tr("password"));
|
|---|
| 33 | QSettings settings;
|
|---|
| 34 | _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
|
|---|
| 35 | int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
|
|---|
| 36 | _casterHostLineEdit->setMaximumWidth(18*ww);
|
|---|
| 37 | _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
|
|---|
| 38 | _casterPortLineEdit->setMaximumWidth(9*ww);
|
|---|
| 39 | _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
|
|---|
| 40 | _casterUserLineEdit->setMaximumWidth(9*ww);
|
|---|
| 41 | _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
|
|---|
| 42 | _casterPasswordLineEdit->setMaximumWidth(9*ww);
|
|---|
| 43 | _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
|
|---|
| 44 |
|
|---|
| 45 | QGridLayout* editLayout = new QGridLayout;
|
|---|
| 46 | editLayout->addWidget(_casterHostLabel, 0, 0);
|
|---|
| 47 | editLayout->addWidget(_casterHostLineEdit, 0, 1);
|
|---|
| 48 | editLayout->addWidget(_casterPortLabel, 0, 2);
|
|---|
| 49 | editLayout->addWidget(_casterPortLineEdit, 0, 3);
|
|---|
| 50 | editLayout->addWidget(_casterUserLabel, 1, 0);
|
|---|
| 51 | editLayout->addWidget(_casterUserLineEdit, 1, 1);
|
|---|
| 52 | editLayout->addWidget(_casterPasswordLabel, 1, 2);
|
|---|
| 53 | editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
|
|---|
| 54 |
|
|---|
| 55 | mainLayout->addLayout(editLayout);
|
|---|
| 56 |
|
|---|
| 57 | _table = new QTableWidget(this);
|
|---|
| 58 | mainLayout->addWidget(_table);
|
|---|
| 59 |
|
|---|
| 60 | _buttonGet = new QPushButton(tr("Get Table"), this);
|
|---|
| 61 | connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
|
|---|
| 62 |
|
|---|
| 63 | _buttonCancel = new QPushButton(tr("Cancel"), this);
|
|---|
| 64 | connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
|
|---|
| 65 |
|
|---|
| 66 | _buttonOK = new QPushButton(tr("OK"), this);
|
|---|
| 67 | connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
|
|---|
| 68 |
|
|---|
| 69 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
|---|
| 70 | buttonLayout->addStretch(1);
|
|---|
| 71 | buttonLayout->addWidget(_buttonGet);
|
|---|
| 72 | buttonLayout->addWidget(_buttonCancel);
|
|---|
| 73 | buttonLayout->addWidget(_buttonOK);
|
|---|
| 74 |
|
|---|
| 75 | mainLayout->addLayout(buttonLayout);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | // Destructor
|
|---|
| 79 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 80 | bncTableDlg::~bncTableDlg() {
|
|---|
| 81 | if (_table) {
|
|---|
| 82 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
|---|
| 83 | for (int ic = 0; ic < _table->columnCount(); ic++) {
|
|---|
| 84 | delete _table->item(ir,ic);
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | // Read Table from Caster
|
|---|
| 91 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 92 | void bncTableDlg::slotGetTable() {
|
|---|
| 93 |
|
|---|
| 94 | QUrl url;
|
|---|
| 95 | url.setHost(_casterHostLineEdit->text());
|
|---|
| 96 | url.setPort(_casterPortLineEdit->text().toInt());
|
|---|
| 97 |
|
|---|
| 98 | // Send the Request
|
|---|
| 99 | // ----------------
|
|---|
| 100 | QString msg;
|
|---|
| 101 | QTcpSocket* socket = bncGetThread::request(url, msg);
|
|---|
| 102 |
|
|---|
| 103 | if (!socket) {
|
|---|
| 104 | QMessageBox::warning(0, "BNC", msg);
|
|---|
| 105 | return;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | // Read Caster Response
|
|---|
| 109 | // --------------------
|
|---|
| 110 | QStringList allLines;
|
|---|
| 111 | bool first = true;
|
|---|
| 112 | while (true) {
|
|---|
| 113 | if (socket->canReadLine()) {
|
|---|
| 114 | QString line = socket->readLine();
|
|---|
| 115 | if (first) {
|
|---|
| 116 | first = false;
|
|---|
| 117 | if (line.indexOf("SOURCETABLE 200 OK") != 0) {
|
|---|
| 118 | QMessageBox::warning(0, "BNC", "Wrong Caster Response:\n" + line);
|
|---|
| 119 | break;
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | else {
|
|---|
| 123 | if (line.indexOf("ENDSOURCETABLE") == 0) {
|
|---|
| 124 | break;
|
|---|
| 125 | }
|
|---|
| 126 | if (line.indexOf("STR") == 0) {
|
|---|
| 127 | allLines.push_back(line);
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | else {
|
|---|
| 132 | const int timeOut = 10*1000;
|
|---|
| 133 | socket->waitForReadyRead(timeOut);
|
|---|
| 134 | if (socket->bytesAvailable() > 0) {
|
|---|
| 135 | continue;
|
|---|
| 136 | }
|
|---|
| 137 | else {
|
|---|
| 138 | QMessageBox::warning(0, "BNC", "Data Timeout");
|
|---|
| 139 | break;
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | delete socket;
|
|---|
| 144 |
|
|---|
| 145 | if (allLines.size() > 0) {
|
|---|
| 146 | _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|---|
| 147 | _table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|---|
| 148 |
|
|---|
| 149 | QStringList hlp = allLines[0].split(";");
|
|---|
| 150 | _table->setColumnCount(hlp.size()-1);
|
|---|
| 151 | _table->setRowCount(allLines.size());
|
|---|
| 152 |
|
|---|
| 153 | QListIterator<QString> it(allLines);
|
|---|
| 154 | int nRow = -1;
|
|---|
| 155 | while (it.hasNext()) {
|
|---|
| 156 | QStringList columns = it.next().split(";");
|
|---|
| 157 | ++nRow;
|
|---|
| 158 | for (int ic = 0; ic < columns.size()-1; ic++) {
|
|---|
| 159 | _table->setItem(nRow, ic, new QTableWidgetItem(columns[ic+1]));
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 | _table->sortItems(0);
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // Accept slot
|
|---|
| 167 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 168 | void bncTableDlg::accept() {
|
|---|
| 169 |
|
|---|
| 170 | QSettings settings;
|
|---|
| 171 | settings.setValue("casterHost", _casterHostLineEdit->text());
|
|---|
| 172 | settings.setValue("casterPort", _casterPortLineEdit->text());
|
|---|
| 173 | settings.setValue("casterUser", _casterUserLineEdit->text());
|
|---|
| 174 | settings.setValue("casterPassword", _casterPasswordLineEdit->text());
|
|---|
| 175 |
|
|---|
| 176 | QStringList* mountPoints = new QStringList;
|
|---|
| 177 |
|
|---|
| 178 | if (_table) {
|
|---|
| 179 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
|---|
| 180 | QTableWidgetItem* item = _table->item(ir,0);
|
|---|
| 181 | QString format = _table->item(ir,2)->text();
|
|---|
| 182 | format.replace(" ", "_");
|
|---|
| 183 | if (_table->isItemSelected(item)) {
|
|---|
| 184 | QUrl url;
|
|---|
| 185 | url.setUserName(_casterUserLineEdit->text());
|
|---|
| 186 | url.setPassword(_casterPasswordLineEdit->text());
|
|---|
| 187 | url.setHost(_casterHostLineEdit->text());
|
|---|
| 188 | url.setPort(_casterPortLineEdit->text().toInt());
|
|---|
| 189 | url.setPath(item->text());
|
|---|
| 190 |
|
|---|
| 191 | mountPoints->push_back(url.toString() + " " + format);
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 | emit newMountPoints(mountPoints);
|
|---|
| 196 |
|
|---|
| 197 | QDialog::accept();
|
|---|
| 198 | }
|
|---|