[35] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
[93] | 3 | * BKG NTRIP Client
|
---|
[35] | 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 | ////////////////////////////////////////////////////////////////////////////
|
---|
[90] | 23 | bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
|
---|
[35] | 24 |
|
---|
| 25 | setMinimumSize(600,400);
|
---|
[237] | 26 | setWindowTitle(tr("Add Mountpoints"));
|
---|
[35] | 27 |
|
---|
| 28 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
| 29 |
|
---|
| 30 | QSettings settings;
|
---|
[88] | 31 | _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
|
---|
| 32 | int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
|
---|
| 33 | _casterHostLineEdit->setMaximumWidth(18*ww);
|
---|
| 34 | _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
|
---|
| 35 | _casterPortLineEdit->setMaximumWidth(9*ww);
|
---|
| 36 | _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
|
---|
| 37 | _casterUserLineEdit->setMaximumWidth(9*ww);
|
---|
| 38 | _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
|
---|
| 39 | _casterPasswordLineEdit->setMaximumWidth(9*ww);
|
---|
| 40 | _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
|
---|
[35] | 41 |
|
---|
[88] | 42 | QGridLayout* editLayout = new QGridLayout;
|
---|
[105] | 43 | editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
|
---|
| 44 | editLayout->addWidget(_casterHostLineEdit, 0, 1);
|
---|
| 45 | editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
|
---|
| 46 | editLayout->addWidget(_casterPortLineEdit, 0, 3);
|
---|
| 47 | editLayout->addWidget(new QLabel(tr("User")), 1, 0);
|
---|
| 48 | editLayout->addWidget(_casterUserLineEdit, 1, 1);
|
---|
| 49 | editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
|
---|
| 50 | editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
|
---|
[88] | 51 |
|
---|
[35] | 52 | mainLayout->addLayout(editLayout);
|
---|
| 53 |
|
---|
| 54 | _table = new QTableWidget(this);
|
---|
[195] | 55 | connect(_table, SIGNAL(itemSelectionChanged()),
|
---|
| 56 | this, SLOT(slotSelectionChanged()));
|
---|
[35] | 57 | mainLayout->addWidget(_table);
|
---|
| 58 |
|
---|
[201] | 59 | // _buttonSkl = new QPushButton(tr("Create skeleton headers"), this);
|
---|
| 60 | // _buttonSkl->setEnabled(false);
|
---|
| 61 | // connect(_buttonSkl, SIGNAL(clicked()), this, SLOT(slotSkl()));
|
---|
[195] | 62 |
|
---|
| 63 | _buttonGet = new QPushButton(tr("Get table"), this);
|
---|
[35] | 64 | connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
|
---|
| 65 |
|
---|
| 66 | _buttonCancel = new QPushButton(tr("Cancel"), this);
|
---|
| 67 | connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
|
---|
| 68 |
|
---|
| 69 | _buttonOK = new QPushButton(tr("OK"), this);
|
---|
| 70 | connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
|
---|
| 71 |
|
---|
| 72 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
[201] | 73 | // buttonLayout->addWidget(_buttonSkl);
|
---|
[35] | 74 | buttonLayout->addStretch(1);
|
---|
| 75 | buttonLayout->addWidget(_buttonGet);
|
---|
| 76 | buttonLayout->addWidget(_buttonCancel);
|
---|
| 77 | buttonLayout->addWidget(_buttonOK);
|
---|
| 78 |
|
---|
| 79 | mainLayout->addLayout(buttonLayout);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | // Destructor
|
---|
| 83 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 84 | bncTableDlg::~bncTableDlg() {
|
---|
| 85 | if (_table) {
|
---|
| 86 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
---|
| 87 | for (int ic = 0; ic < _table->columnCount(); ic++) {
|
---|
| 88 | delete _table->item(ir,ic);
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[191] | 94 | // Read Table the caster (static)
|
---|
[35] | 95 | ////////////////////////////////////////////////////////////////////////////
|
---|
[191] | 96 | t_irc bncTableDlg::getFullTable(const QString& casterHost,
|
---|
| 97 | int casterPort, QStringList& allLines) {
|
---|
[35] | 98 |
|
---|
[191] | 99 | allLines.clear();
|
---|
| 100 |
|
---|
[88] | 101 | QUrl url;
|
---|
[191] | 102 | url.setHost(casterHost);
|
---|
| 103 | url.setPort(casterPort);
|
---|
[35] | 104 |
|
---|
| 105 | // Send the Request
|
---|
| 106 | // ----------------
|
---|
[136] | 107 | const int timeOut = 10*1000;
|
---|
[82] | 108 | QString msg;
|
---|
[136] | 109 | QTcpSocket* socket = bncGetThread::request(url, timeOut, msg);
|
---|
[88] | 110 |
|
---|
[35] | 111 | if (!socket) {
|
---|
[191] | 112 | return failure;
|
---|
[35] | 113 | }
|
---|
| 114 |
|
---|
| 115 | // Read Caster Response
|
---|
| 116 | // --------------------
|
---|
| 117 | bool first = true;
|
---|
| 118 | while (true) {
|
---|
| 119 | if (socket->canReadLine()) {
|
---|
| 120 | QString line = socket->readLine();
|
---|
[191] | 121 | allLines.push_back(line);
|
---|
[35] | 122 | if (first) {
|
---|
| 123 | first = false;
|
---|
| 124 | if (line.indexOf("SOURCETABLE 200 OK") != 0) {
|
---|
| 125 | break;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | else {
|
---|
| 129 | if (line.indexOf("ENDSOURCETABLE") == 0) {
|
---|
| 130 | break;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | else {
|
---|
| 135 | socket->waitForReadyRead(timeOut);
|
---|
| 136 | if (socket->bytesAvailable() > 0) {
|
---|
| 137 | continue;
|
---|
| 138 | }
|
---|
| 139 | else {
|
---|
| 140 | break;
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | delete socket;
|
---|
| 145 |
|
---|
[191] | 146 | return success;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | // Read Table from Caster
|
---|
| 150 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 151 | void bncTableDlg::slotGetTable() {
|
---|
| 152 |
|
---|
[196] | 153 | _allLines.clear();
|
---|
[191] | 154 |
|
---|
| 155 | if ( getFullTable(_casterHostLineEdit->text(),
|
---|
| 156 | _casterPortLineEdit->text().toInt(),
|
---|
[196] | 157 | _allLines) != success ) {
|
---|
[191] | 158 | QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
|
---|
| 159 | return;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | QStringList lines;
|
---|
[196] | 163 | QStringListIterator it(_allLines);
|
---|
[191] | 164 | while (it.hasNext()) {
|
---|
| 165 | QString line = it.next();
|
---|
| 166 | if (line.indexOf("STR") == 0) {
|
---|
| 167 | lines.push_back(line);
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[103] | 171 | static const QStringList labels = QString("mountpoint,identifier,format,"
|
---|
| 172 | "format-details,carrier,nav-system,network,country,latitude,longitude,"
|
---|
| 173 | "nmea,solution,generator,compression,authentication,fee,bitrate,"
|
---|
| 174 | "misc").split(",");
|
---|
| 175 |
|
---|
[191] | 176 | if (lines.size() > 0) {
|
---|
[35] | 177 | _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
| 178 | _table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
| 179 |
|
---|
[191] | 180 | QStringList hlp = lines[0].split(";");
|
---|
[35] | 181 | _table->setColumnCount(hlp.size()-1);
|
---|
[191] | 182 | _table->setRowCount(lines.size());
|
---|
[35] | 183 |
|
---|
[191] | 184 | QListIterator<QString> it(lines);
|
---|
[35] | 185 | int nRow = -1;
|
---|
| 186 | while (it.hasNext()) {
|
---|
| 187 | QStringList columns = it.next().split(";");
|
---|
| 188 | ++nRow;
|
---|
| 189 | for (int ic = 0; ic < columns.size()-1; ic++) {
|
---|
[107] | 190 | QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
|
---|
[115] | 191 | it->setFlags(it->flags() & ~Qt::ItemIsEditable);
|
---|
[107] | 192 | _table->setItem(nRow, ic, it);
|
---|
[35] | 193 | }
|
---|
| 194 | }
|
---|
[83] | 195 | _table->sortItems(0);
|
---|
[103] | 196 | _table->setHorizontalHeaderLabels(labels);
|
---|
[104] | 197 | _table->setSortingEnabled(true);
|
---|
[35] | 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | // Accept slot
|
---|
| 202 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 203 | void bncTableDlg::accept() {
|
---|
| 204 |
|
---|
| 205 | QSettings settings;
|
---|
| 206 | settings.setValue("casterHost", _casterHostLineEdit->text());
|
---|
| 207 | settings.setValue("casterPort", _casterPortLineEdit->text());
|
---|
[88] | 208 | settings.setValue("casterUser", _casterUserLineEdit->text());
|
---|
| 209 | settings.setValue("casterPassword", _casterPasswordLineEdit->text());
|
---|
[35] | 210 |
|
---|
| 211 | QStringList* mountPoints = new QStringList;
|
---|
| 212 |
|
---|
| 213 | if (_table) {
|
---|
| 214 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
---|
[59] | 215 | QTableWidgetItem* item = _table->item(ir,0);
|
---|
| 216 | QString format = _table->item(ir,2)->text();
|
---|
| 217 | format.replace(" ", "_");
|
---|
[35] | 218 | if (_table->isItemSelected(item)) {
|
---|
| 219 | QUrl url;
|
---|
[88] | 220 | url.setUserName(_casterUserLineEdit->text());
|
---|
| 221 | url.setPassword(_casterPasswordLineEdit->text());
|
---|
[35] | 222 | url.setHost(_casterHostLineEdit->text());
|
---|
| 223 | url.setPort(_casterPortLineEdit->text().toInt());
|
---|
| 224 | url.setPath(item->text());
|
---|
[59] | 225 |
|
---|
| 226 | mountPoints->push_back(url.toString() + " " + format);
|
---|
[35] | 227 | }
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
| 230 | emit newMountPoints(mountPoints);
|
---|
| 231 |
|
---|
| 232 | QDialog::accept();
|
---|
| 233 | }
|
---|
[195] | 234 |
|
---|
| 235 | // User changed the selection of mountPoints
|
---|
| 236 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 237 | void bncTableDlg::slotSelectionChanged() {
|
---|
| 238 | if (_table->selectedItems().isEmpty()) {
|
---|
[201] | 239 | // _buttonSkl->setEnabled(false);
|
---|
[195] | 240 | }
|
---|
| 241 | else {
|
---|
[201] | 242 | // _buttonSkl->setEnabled(true);
|
---|
[195] | 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[196] | 246 | // Create RINEX skeleton header
|
---|
[195] | 247 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 248 | void bncTableDlg::slotSkl() {
|
---|
| 249 |
|
---|
[196] | 250 | int nRows = _table->rowCount();
|
---|
| 251 | for (int iRow = 0; iRow < nRows; iRow++) {
|
---|
| 252 | if (_table->isItemSelected(_table->item(iRow,1))) {
|
---|
| 253 | QString staID = _table->item(iRow,0)->text();
|
---|
| 254 | QString net = _table->item(iRow,6)->text();
|
---|
[195] | 255 |
|
---|
[196] | 256 | QString ftpDir;
|
---|
| 257 | QStringListIterator it(_allLines);
|
---|
| 258 | while (it.hasNext()) {
|
---|
| 259 | QString line = it.next();
|
---|
| 260 | if (line.indexOf("NET") == 0) {
|
---|
| 261 | QStringList tags = line.split(';');
|
---|
| 262 | if (tags.at(1) == net) {
|
---|
| 263 | ftpDir = tags.at(6);
|
---|
| 264 | break;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[197] | 269 | if (!ftpDir.isEmpty()) {
|
---|
| 270 | QUrl url(ftpDir);
|
---|
| 271 | QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
|
---|
| 272 | "\nnot yet implemented");
|
---|
| 273 | }
|
---|
[196] | 274 | }
|
---|
| 275 | }
|
---|
[197] | 276 | }
|
---|
[196] | 277 |
|
---|