comparison MainWindow.cpp @ 8:21ce6187d32e

Minor changes done by automatic style checker
author Ideenmodellierer
date Mon, 12 Jan 2026 13:51:17 +0000
parents 115cfa4a3239
children e47e0f59101d
comparison
equal deleted inserted replaced
7:0969ef86c42d 8:21ce6187d32e
37 #include "MainWindow.h" 37 #include "MainWindow.h"
38 38
39 #include "Utils/LogAppender.h" 39 #include "Utils/LogAppender.h"
40 #include "Utils/ProgressEvent.h" 40 #include "Utils/ProgressEvent.h"
41 41
42 #include "SettingsDialog.h"
43 #include "editlogdialog.h"
42 #include "ui_MainWindow.h" 44 #include "ui_MainWindow.h"
43 #include "SettingsDialog.h" 45
44 #include "editLogDialog.h"
45
46 #include <QString>
47 #include <QDateTime> 46 #include <QDateTime>
48 #include <QFileDialog> 47 #include <QFileDialog>
49 #include <QInputDialog> 48 #include <QInputDialog>
50 #include <QMenu> 49 #include <QMenu>
51 #include <QMenuBar> 50 #include <QMenuBar>
52 #include <QMessageBox> 51 #include <QMessageBox>
53 #include <QPlainTextEdit> 52 #include <QPlainTextEdit>
54 #include <QProgressBar> 53 #include <QProgressBar>
55 #include <QSettings> 54 #include <QSettings>
55 #include <QString>
56 #include <QTextCursor> 56 #include <QTextCursor>
57 #include "OSTCFrogOperations.h" 57 #include "OSTC2Operations.h"
58 #include "OSTC2cOperations.h" 58 #include "OSTC2cOperations.h"
59 #include "OSTC2Operations.h"
60 #include "OSTCSportOperations.h"
61 #include "OSTC3Operations.h" 59 #include "OSTC3Operations.h"
62 #include "OSTC3pOperations.h" 60 #include "OSTC3pOperations.h"
63 #include "OSTC4Operations.h" 61 #include "OSTC4Operations.h"
62 #include "OSTCFrogOperations.h"
63 #include "OSTCSportOperations.h"
64 #include "OSTC_CR_Operations.h" 64 #include "OSTC_CR_Operations.h"
65 65
66 extern QSettings* settings; 66 extern QSettings *settings;
67 67
68 ////////////////////////////////////////////////////////////////////////////// 68 //////////////////////////////////////////////////////////////////////////////
69 69
70 class EXPORT LogWindow 70 class EXPORT LogWindow : public LogAppender
71 : public LogAppender 71 {
72 { 72 MainWindow *_window;
73 MainWindow* _window;
74 73
75 //---- The <<printing>> function ----------------------------------------- 74 //---- The <<printing>> function -----------------------------------------
76 void operator()(const Log &log) override { 75 void operator()(const Log &log) override
76 {
77 QString message = log.message; 77 QString message = log.message;
78 78
79 message.replace("< ", "&lt; ") 79 message.replace("< ", "&lt; ").replace(" >", " &gt;");
80 .replace(" >", " &gt;"); 80 if (!message.isEmpty())
81 if( ! message.isEmpty() )
82 _window->statusMessage(message); 81 _window->statusMessage(message);
83 } 82 }
84 83
85 //---- Reimplementing mandatory methds ----------------------------------- 84 //---- Reimplementing mandatory methds -----------------------------------
86 const char *type() const override { 85 const char *type() const override { return "File"; }
87 return "File"; 86 Log::Level defaultMinLevel() const override { return Log::LEVEL_INFO; }
88 } 87 const char *defaultFormat() const override { return "%m"; }
89 Log::Level defaultMinLevel() const override {
90 return Log::LEVEL_INFO;
91 }
92 const char* defaultFormat() const override {
93 return "%m";
94 }
95 88
96 public: 89 public:
97 LogWindow(MainWindow* window) 90 LogWindow(MainWindow *window)
98 : LogAppender(0, NULL), 91 : LogAppender(0, NULL)
99 _window(window) 92 , _window(window)
100 {} 93 {}
101 }; 94 };
102 95
103 ////////////////////////////////////////////////////////////////////////////// 96 //////////////////////////////////////////////////////////////////////////////
104 97
105 MainWindow::MainWindow() 98 MainWindow::MainWindow()
106 : QMainWindow(NULL), 99 : QMainWindow(NULL)
107 _ui(new Ui::MainWindow), 100 , _ui(new Ui::MainWindow)
108 _op(0) 101 , _op(0)
109 { 102 {
110 // Connect the Log system to this window: 103 // Connect the Log system to this window:
111 new LogWindow(this); 104 new LogWindow(this);
112 // Connect the progress system to this window: 105 // Connect the progress system to this window:
113 ProgressManager::getInstance()->setMainWindow(this); 106 ProgressManager::getInstance()->setMainWindow(this);
117 110
118 _ui->editLog->setVisible(false); 111 _ui->editLog->setVisible(false);
119 112
120 // Auto-select last model: 113 // Auto-select last model:
121 QString model = settings->value("Interface/computerType").toString(); 114 QString model = settings->value("Interface/computerType").toString();
115 _ui->computerType->setCurrentIndex(0);
116
117 if (model == "ostc2c")
122 _ui->computerType->setCurrentIndex(0); 118 _ui->computerType->setCurrentIndex(0);
123 119 else if (model == "hwOS (Bluetooth)")
124 if( model == "ostc2c" )
125 _ui->computerType->setCurrentIndex(0);
126 else if( model == "hwOS (Bluetooth)" )
127 _ui->computerType->setCurrentIndex(1); 120 _ui->computerType->setCurrentIndex(1);
128 else if( model == "hwOS (USB)" ) 121 else if (model == "hwOS (USB)")
129 _ui->computerType->setCurrentIndex(2); 122 _ui->computerType->setCurrentIndex(2);
130 else if( model == "ostc4" ) 123 else if (model == "ostc4")
131 _ui->computerType->setCurrentIndex(3); 124 _ui->computerType->setCurrentIndex(3);
132 125
133 changeTypeSlot(); 126 changeTypeSlot();
134 127
135 #ifdef Q_OS_MAC 128 #ifdef Q_OS_MAC
136 { 129 {
137 QMenuBar *menuBar = new QMenuBar(this); 130 QMenuBar *menuBar = new QMenuBar(this);
138 QMenu* help = menuBar->addMenu(tr("&Help")); 131 QMenu *help = menuBar->addMenu(tr("&Help"));
139 help->addAction(tr("Preferences..."), this, SLOT(settingsSlot())); 132 help->addAction(tr("Preferences..."), this, SLOT(settingsSlot()));
140 } 133 }
141 #endif 134 #endif
142 135
143 setWindowTitle(QString("OSTC Companion v%1.%2 %3") 136 setWindowTitle(QString("OSTC Companion v%1.%2 %3")
144 .arg(MAJOR_VERSION) 137 .arg(MAJOR_VERSION)
145 .arg(MINOR_VERSION) // kein sprintf nötig, arg konvertiert automatisch 138 .arg(MINOR_VERSION) // kein sprintf nötig, arg konvertiert automatisch
146 .arg(BETA_VERSION 139 .arg(BETA_VERSION ? QString(" beta %1").arg(PATCH_VERSION)
147 ? QString(" beta %1").arg(PATCH_VERSION) 140 : QString::number(PATCH_VERSION)));
148 : QString::number(PATCH_VERSION)) 141 }
149 );
150 }
151
152 142
153 ////////////////////////////////////////////////////////////////////////////// 143 //////////////////////////////////////////////////////////////////////////////
154 144
155 MainWindow::~MainWindow() 145 MainWindow::~MainWindow()
156 { 146 {
158 delete _op; 148 delete _op;
159 } 149 }
160 150
161 ////////////////////////////////////////////////////////////////////////////// 151 //////////////////////////////////////////////////////////////////////////////
162 152
163 bool MainWindow::event(QEvent* e) 153 bool MainWindow::event(QEvent *e)
164 { 154 {
165 if( ProgressEvent* p = dynamic_cast<ProgressEvent*>(e) ) 155 if (ProgressEvent *p = dynamic_cast<ProgressEvent *>(e)) {
166 { 156 QProgressBar *w = _ui->progressBar;
167 QProgressBar* w = _ui->progressBar; 157
168 158 if (p->current > p->maximum && p->maximum > 0) {
169 if( p->current > p->maximum && p->maximum > 0) 159 w->setMaximum(p->maximum); // Remove throttling mode, if any.
170 {
171 w->setMaximum(p->maximum); // Remove throttling mode, if any.
172 w->reset(); 160 w->reset();
173 } 161 } else {
174 else 162 if (!w->isEnabled())
175 {
176 if( ! w->isEnabled() )
177 w->setEnabled(true); 163 w->setEnabled(true);
178 if( w->maximum() != p->maximum ) 164 if (w->maximum() != p->maximum)
179 w->setMaximum(p->maximum); // Start throttling if max==0 165 w->setMaximum(p->maximum); // Start throttling if max==0
180 w->setValue(p->current); 166 w->setValue(p->current);
181 } 167 }
182 return true; 168 return true;
183 } 169 }
184 170
192 QString name; 178 QString name;
193 179
194 //---- Setup a new driver ------------------------------------------------ 180 //---- Setup a new driver ------------------------------------------------
195 delete _op; 181 delete _op;
196 _op = 0; 182 _op = 0;
197 switch( _ui->computerType->currentIndex() ) { 183 switch (_ui->computerType->currentIndex()) {
198 case 0: name = "ostc2c"; 184 case 0:
199 _op = new OSTC2cOperations; 185 name = "ostc2c";
186 _op = new OSTC2cOperations;
200 break; 187 break;
201 case 1: name = "hwOS (USB)"; 188 case 1:
202 _op = new OSTC3Operations; 189 name = "hwOS (USB)";
190 _op = new OSTC3Operations;
203 break; 191 break;
204 case 2: name = "hwOS (Bluetooth)"; 192 case 2:
205 _op = new OSTC3pOperations; 193 name = "hwOS (Bluetooth)";
194 _op = new OSTC3pOperations;
206 break; 195 break;
207 case 3: name = "ostc4"; 196 case 3:
197 name = "ostc4";
208 _op = new OSTC4Operations; 198 _op = new OSTC4Operations;
209 break; 199 break;
210 200
211 default: 201 default:
212 qWarning("Internal error: unknown computer type"); 202 qWarning("Internal error: unknown computer type");
216 206
217 settings->setValue("Interface/computerType", name); 207 settings->setValue("Interface/computerType", name);
218 settings->sync(); 208 settings->sync();
219 209
220 // backword compatibility >= translate name if necessary 210 // backword compatibility >= translate name if necessary
221 if ( name =="hwOS (Bluetooth)") name = "ostc3p"; 211 if (name == "hwOS (Bluetooth)")
222 if( name =="hwOS (USB)") name = "ostc3"; 212 name = "ostc3p";
223 if( name =="ostc 4/5") name = "ostc4"; 213 if (name == "hwOS (USB)")
224 214 name = "ostc3";
225 _ui->computerImage->setPixmap( QPixmap(":/Images/" + name + "_160x120.png")); 215 if (name == "ostc 4/5")
216 name = "ostc4";
217
218 _ui->computerImage->setPixmap(QPixmap(":/Images/" + name + "_160x120.png"));
226 219
227 updateStatus(); 220 updateStatus();
228 } 221 }
229 222
230 ////////////////////////////////////////////////////////////////////////////// 223 //////////////////////////////////////////////////////////////////////////////
231 224
232 void MainWindow::settingsSlot() 225 void MainWindow::settingsSlot()
233 { 226 {
234 Settings* s = new Settings(this, _op); 227 Settings *s = new Settings(this, _op);
235 s->exec(); 228 s->exec();
236 delete s; 229 delete s;
237 } 230 }
238 231
239 ////////////////////////////////////////////////////////////////////////////// 232 //////////////////////////////////////////////////////////////////////////////
240 233
241 void MainWindow::connectSlot() 234 void MainWindow::connectSlot()
242 { 235 {
243 Q_ASSERT( _op ); 236 Q_ASSERT(_op);
244 237
245 try { 238 try {
246 LOG_INFO("Connecting..."); 239 LOG_INFO("Connecting...");
247 240
248 //---- Already connected ? ---------------------------------------------- 241 //---- Already connected ? ----------------------------------------------
249 if( ! _op->description().isEmpty() ) 242 if (!_op->description().isEmpty())
250 _op->disconnect(); 243 _op->disconnect();
251 244
252 //---- (Re)connect ------------------------------------------------------ 245 //---- (Re)connect ------------------------------------------------------
253 if( _op->connect() ) { 246 if (_op->connect()) {
254 247 if (Settings::autoSetDateTime)
255 if( Settings::autoSetDateTime )
256 dateSlot(); 248 dateSlot();
257 249
258 LOG_INFO("Connected: " + _op->description() ); 250 LOG_INFO("Connected: " + _op->description());
259 } 251 }
260 updateStatus(); 252 updateStatus();
261 } 253 } catch (const std::exception &e) {
262 catch(const std::exception& e) { 254 LOG_INFO(
263 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 255 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
264 .arg(tr("Error"))
265 .arg(e.what()) );
266 } 256 }
267 } 257 }
268 258
269 ////////////////////////////////////////////////////////////////////////////// 259 //////////////////////////////////////////////////////////////////////////////
270 260
271 void MainWindow::closeSlot() 261 void MainWindow::closeSlot()
272 { 262 {
273 Q_ASSERT( _op ); 263 Q_ASSERT(_op);
274 264
275 try { 265 try {
276 LOG_INFO("Disconnecting..."); 266 LOG_INFO("Disconnecting...");
277 if( _op->disconnect() ) 267 if (_op->disconnect())
278 LOG_INFO("Disconnected."); 268 LOG_INFO("Disconnected.");
279 updateStatus(); 269 updateStatus();
280 } 270 } catch (const std::exception &e) {
281 catch(const std::exception& e) { 271 LOG_INFO(
282 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 272 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
283 .arg(tr("Error"))
284 .arg(e.what()) );
285 } 273 }
286 } 274 }
287 275
288 ////////////////////////////////////////////////////////////////////////////// 276 //////////////////////////////////////////////////////////////////////////////
289 277
290 void MainWindow::updateStatus() 278 void MainWindow::updateStatus()
291 { 279 {
292 bool ok = _op; 280 bool ok = _op;
293 _ui->connectButton->setEnabled( ok ); 281 _ui->connectButton->setEnabled(ok);
294 282
295 // ON when supported but NOT connected, OFF once connected. 283 // ON when supported but NOT connected, OFF once connected.
296 _ui->upgradeButton->setEnabled( ok 284 _ui->upgradeButton->setEnabled(
297 && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE)) 285 ok
298 && !_op->serial().isOpen()); 286 && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE))
287 && !_op->serial().isOpen());
299 288
300 // Only allow buttons when connected: 289 // Only allow buttons when connected:
301 ok &= _op->serial().isOpen(); 290 ok &= _op->serial().isOpen();
302 _ui->dateButton ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE)); 291 _ui->dateButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE));
303 _ui->nameButton ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME)); 292 _ui->nameButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME));
304 _ui->iconButton ->setEnabled(ok);// && _op->supported().testFlag(HardwareOperations::ICON)); 293 _ui->iconButton->setEnabled(ok); // && _op->supported().testFlag(HardwareOperations::ICON));
305 _ui->signalButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::SIGNAL_CHECK)); 294 _ui->signalButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::SIGNAL_CHECK));
306 _ui->closeButton ->setEnabled( ok ); 295 _ui->closeButton->setEnabled(ok);
307 } 296 }
308 297
309 ////////////////////////////////////////////////////////////////////////////// 298 //////////////////////////////////////////////////////////////////////////////
310 299
311 void MainWindow::dateSlot() 300 void MainWindow::dateSlot()
312 { 301 {
313 Q_ASSERT( _op ); 302 Q_ASSERT(_op);
314 303
315 try { 304 try {
316 QDateTime date = QDateTime::currentDateTime(); 305 QDateTime date = QDateTime::currentDateTime();
317 306
318 LOG_INFO(tr("Settings date & time...")); 307 LOG_INFO(tr("Settings date & time..."));
319 _op->setDate( date ); 308 _op->setDate(date);
320 LOG_INFO( QString("Date set to %1") 309 LOG_INFO(QString("Date set to %1").arg(date.toString("yyyy/MM/dd hh:mm:ss")));
321 .arg(date.toString("yyyy/MM/dd hh:mm:ss")) ); 310 } catch (const std::exception &e) {
322 } 311 LOG_INFO(
323 catch(const std::exception& e) { 312 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
324 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 313 }
325 .arg(tr("Error")) 314 }
326 .arg(e.what()) );
327 }
328 }
329
330 315
331 ////////////////////////////////////////////////////////////////////////////// 316 //////////////////////////////////////////////////////////////////////////////
332 317
333 void MainWindow::nameSlot() 318 void MainWindow::nameSlot()
334 { 319 {
335 Q_ASSERT( _op ); 320 Q_ASSERT(_op);
336 try { 321 try {
337 LOG_INFO(tr("Settings name...")); 322 LOG_INFO(tr("Settings name..."));
338 323
339 //---- Get old name, and reformat to multi-lines --------------------- 324 //---- Get old name, and reformat to multi-lines ---------------------
340 QString oldName = _op->description().section(", ", 2); 325 QString oldName = _op->description().section(", ", 2);
341 QString oldText; 326 QString oldText;
342 QSize size = _op->nameSize(); 327 QSize size = _op->nameSize();
343 328
344 for(int l=0; l<size.height(); ++l) { 329 for (int l = 0; l < size.height(); ++l) {
345 QString line = oldName.left( size.width() ).leftJustified(size.width()); 330 QString line = oldName.left(size.width()).leftJustified(size.width());
346 if( line.contains("\n") ) { 331 if (line.contains("\n")) {
347 line = line.section("\n", 0, 0); 332 line = line.section("\n", 0, 0);
348 oldName = oldName.mid(line.length()); 333 oldName = oldName.mid(line.length());
349 } 334 } else {
350 else {
351 oldName = oldName.mid(line.length()); 335 oldName = oldName.mid(line.length());
352 if( oldName[0] == '\n' ) 336 if (oldName[0] == '\n')
353 oldName = oldName.mid(1); 337 oldName = oldName.mid(1);
354 } 338 }
355 oldText += line + "|\n"; 339 oldText += line + "|\n";
356 } 340 }
357 341
358 //---- Ask user ------------------------------------------------------ 342 //---- Ask user ------------------------------------------------------
359 343
360 QInputDialog* d = new QInputDialog(this); 344 QInputDialog *d = new QInputDialog(this);
361 d->setWindowTitle("Set Computer Name..."); 345 d->setWindowTitle("Set Computer Name...");
362 d->setInputMode(QInputDialog::TextInput); 346 d->setInputMode(QInputDialog::TextInput);
363 d->setOptions(QInputDialog::UsePlainTextEditForTextInput); 347 d->setOptions(QInputDialog::UsePlainTextEditForTextInput);
364 d->setTextValue(oldText); 348 d->setTextValue(oldText);
365 349
366 QPlainTextEdit* edit = d->findChild<QPlainTextEdit*>(); 350 QPlainTextEdit *edit = d->findChild<QPlainTextEdit *>();
367 assert(edit); 351 assert(edit);
368 edit->setStyleSheet( 352 edit->setStyleSheet("background-color: black;"
369 "background-color: black;" 353 "color: green;"
370 "color: green;" 354 "font: 14pt 'Courier New';");
371 "font: 14pt 'Courier New';" 355
372 ); 356 if (d->exec() != QDialog::Accepted)
373
374 if( d->exec() != QDialog::Accepted )
375 return; 357 return;
376 358
377 QString newText = d->textValue(); 359 QString newText = d->textValue();
378 delete d; 360 delete d;
379 361
380 //---- Reformat to single padded string ------------------------------ 362 //---- Reformat to single padded string ------------------------------
381 QStringList lines = newText.split("\n"); 363 QStringList lines = newText.split("\n");
382 QString name; 364 QString name;
383 for(int l=0; l<size.height(); ++l) { 365 for (int l = 0; l < size.height(); ++l) {
384 if( l < lines.count() ) 366 if (l < lines.count())
385 name += lines[l].leftJustified(size.width(), ' ', true); 367 name += lines[l].leftJustified(size.width(), ' ', true);
386 else 368 else
387 name += QString(size.width(), ' '); 369 name += QString(size.width(), ' ');
388 } 370 }
389 371
390 //---- Send result --------------------------------------------------- 372 //---- Send result ---------------------------------------------------
391 _op->setName( name ); 373 _op->setName(name);
392 _op->getIdentity(); 374 _op->getIdentity();
393 LOG_INFO( QString("Name set to '%1'") 375 LOG_INFO(
394 .arg(_op->description().section(',', 2)).replace("\n", "|") ); 376 QString("Name set to '%1'").arg(_op->description().section(',', 2)).replace("\n", "|"));
395 } 377 } catch (const std::exception &e) {
396 catch(const std::exception& e) { 378 LOG_INFO(
397 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 379 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
398 .arg(tr("Error"))
399 .arg(e.what()) );
400 } 380 }
401 } 381 }
402 382
403 ////////////////////////////////////////////////////////////////////////////// 383 //////////////////////////////////////////////////////////////////////////////
404 384
405 void MainWindow::iconSlot() 385 void MainWindow::iconSlot()
406 { 386 {
407 Q_ASSERT( _op ); 387 Q_ASSERT(_op);
408 try { 388 try {
409 LOG_INFO(tr("Settings icons...")); 389 LOG_INFO(tr("Settings icons..."));
410 390
411 QString fileName = QFileDialog::getOpenFileName(this, 391 QString fileName = QFileDialog::getOpenFileName(this,
412 "Icon File...", 392 "Icon File...",
413 QString(), 393 QString(),
414 "Images (*.bmp);;" 394 "Images (*.bmp);;"
415 "BMP Image (*.bmp);;" 395 "BMP Image (*.bmp);;"
416 "Anything (*.*)"); 396 "Anything (*.*)");
417 if( ! fileName.isEmpty() ) 397 if (!fileName.isEmpty())
418 _op->setIcons(fileName); 398 _op->setIcons(fileName);
419 } 399 } catch (const std::exception &e) {
420 catch(const std::exception& e) { 400 LOG_INFO(
421 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 401 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
422 .arg(tr("Error"))
423 .arg(e.what()) );
424 } 402 }
425 } 403 }
426 404
427 ////////////////////////////////////////////////////////////////////////////// 405 //////////////////////////////////////////////////////////////////////////////
428 406
429 void MainWindow::upgradeSlot() 407 void MainWindow::upgradeSlot()
430 { 408 {
431 Q_ASSERT( _op ); 409 Q_ASSERT(_op);
432 410
433 try { 411 try {
434 LOG_INFO(tr("Upgrading firmware...")); 412 LOG_INFO(tr("Upgrading firmware..."));
435 413
436 QString hexFile = QFileDialog::getOpenFileName(0, 414 QString hexFile = QFileDialog::getOpenFileName(0,
437 "Hex File...", 415 "Hex File...",
438 Settings::currentPath, 416 Settings::currentPath,
439 _op->firmwareTemplate()); 417 _op->firmwareTemplate());
440 if( hexFile.isEmpty() ) 418 if (hexFile.isEmpty())
441 return; 419 return;
442 420
443 Settings::currentPath = QFileInfo(hexFile).absoluteDir().path(); 421 Settings::currentPath = QFileInfo(hexFile).absoluteDir().path();
444 Settings::save(); 422 Settings::save();
445 423
446 if( _op ) 424 if (_op)
447 _op->upgradeFW(hexFile); 425 _op->upgradeFW(hexFile);
448 } 426 } catch (const std::exception &e) {
449 catch(const std::exception& e) { 427 LOG_INFO(
450 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 428 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
451 .arg(tr("Error")) 429 }
452 .arg(e.what()) ); 430 }
453 } 431
454 } 432 //////////////////////////////////////////////////////////////////////////////
455 433
456 ////////////////////////////////////////////////////////////////////////////// 434 void MainWindow::statusMessage(const QString &msg)
457 435 {
458 void MainWindow::statusMessage(const QString& msg) 436 { // Move cursor to end of document.
459 {
460 { // Move cursor to end of document.
461 QTextCursor c = _ui->console->textCursor(); 437 QTextCursor c = _ui->console->textCursor();
462 c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); 438 c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
463 _ui->console->setTextCursor(c); 439 _ui->console->setTextCursor(c);
464 } 440 }
465 _ui->console->appendHtml(msg); 441 _ui->console->appendHtml(msg);
474 } 450 }
475 451
476 ////////////////////////////////////////////////////////////////////////////// 452 //////////////////////////////////////////////////////////////////////////////
477 void MainWindow::on_signalButton_clicked() 453 void MainWindow::on_signalButton_clicked()
478 { 454 {
479 Q_ASSERT( _op ); 455 Q_ASSERT(_op);
480 456
481 try { 457 try {
482 LOG_INFO(tr("Request Bluetooth signal strength...")); 458 LOG_INFO(tr("Request Bluetooth signal strength..."));
483 _op->getSignal(); 459 _op->getSignal();
484 } 460 } catch (const std::exception &e) {
485 catch(const std::exception& e) { 461 LOG_INFO(
486 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") 462 QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what()));
487 .arg(tr("Error")) 463 }
488 .arg(e.what()) ); 464 }
489 }
490 }
491
492 465
493 void MainWindow::on_editLog_clicked() 466 void MainWindow::on_editLog_clicked()
494 { 467 {
495 EditLogDialog* eL = new EditLogDialog(this, _op); 468 EditLogDialog *eL = new EditLogDialog(this, _op);
496 eL->exec(); 469 eL->exec();
497 delete eL; 470 delete eL;
498 } 471 }