Changeset View
Changeset View
Standalone View
Standalone View
testclient/mainwindow.cpp
Show All 16 Lines | 1 | /* AtCore Test Client | |||
---|---|---|---|---|---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | 18 | GNU General Public License for more details. | ||
19 | 19 | | |||
20 | You should have received a copy of the GNU General Public License | 20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | */ | 22 | */ | ||
23 | #include <QSerialPortInfo> | 23 | #include <QSerialPortInfo> | ||
24 | #include <QMessageBox> | 24 | #include <QMessageBox> | ||
25 | #include <QFileDialog> | | |||
26 | #include <QTextStream> | 25 | #include <QTextStream> | ||
27 | #include <QTimer> | 26 | #include <QTimer> | ||
28 | #include <QLoggingCategory> | 27 | #include <QLoggingCategory> | ||
29 | 28 | | |||
30 | #include "mainwindow.h" | 29 | #include "mainwindow.h" | ||
31 | #include "seriallayer.h" | 30 | #include "seriallayer.h" | ||
32 | #include "gcodecommands.h" | 31 | #include "gcodecommands.h" | ||
33 | #include "about.h" | 32 | #include "about.h" | ||
Show All 15 Lines | 41 | { | |||
49 | 48 | | |||
50 | connect(core, &AtCore::atcoreMessage, logWidget, &LogWidget::appendLog); | 49 | connect(core, &AtCore::atcoreMessage, logWidget, &LogWidget::appendLog); | ||
51 | logWidget->appendLog(tr("Attempting to locate Serial Ports")); | 50 | logWidget->appendLog(tr("Attempting to locate Serial Ports")); | ||
52 | core->setSerialTimerInterval(1000); | 51 | core->setSerialTimerInterval(1000); | ||
53 | 52 | | |||
54 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | 53 | connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); | ||
55 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | 54 | connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); | ||
56 | connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); | 55 | connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); | ||
56 | connect(sdWidget, &SdWidget::writeSdFile, this, &MainWindow::writeToSd); | ||||
57 | | ||||
57 | comboPort->setFocus(Qt::OtherFocusReason); | 58 | comboPort->setFocus(Qt::OtherFocusReason); | ||
58 | } | 59 | } | ||
59 | 60 | | |||
60 | void MainWindow::initMenu() | 61 | void MainWindow::initMenu() | ||
61 | { | 62 | { | ||
62 | QMenu *menuFile = new QMenu(tr("File")); | 63 | QMenu *menuFile = new QMenu(tr("File")); | ||
63 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); | 64 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); | ||
64 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | 65 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | ||
▲ Show 20 Lines • Show All 553 Lines • ▼ Show 20 Line(s) | |||||
618 | } | 619 | } | ||
619 | 620 | | |||
620 | void MainWindow::setConnectionWidgetsEnabled(bool enabled) | 621 | void MainWindow::setConnectionWidgetsEnabled(bool enabled) | ||
621 | { | 622 | { | ||
622 | comboBAUD->setEnabled(enabled); | 623 | comboBAUD->setEnabled(enabled); | ||
623 | comboPlugin->setEnabled(enabled); | 624 | comboPlugin->setEnabled(enabled); | ||
624 | comboPort->setEnabled(enabled); | 625 | comboPort->setEnabled(enabled); | ||
625 | } | 626 | } | ||
627 | | ||||
628 | void MainWindow::writeToSd(const QString &fileName) | ||||
629 | { | ||||
630 | std::unique_ptr<QProgressDialog> dialog(new QProgressDialog(tr("Writing file to SD Card..."), tr("Cancel"), 0, 100, this)); | ||||
631 | | ||||
632 | connect(core, &AtCore::sdWriteChanged, this, [&dialog](bool writing) { | ||||
patrickelectric: check if file exist | |||||
633 | if (writing) { | ||||
634 | dialog->open(); | ||||
635 | } else { | ||||
636 | dialog->close(); | ||||
637 | } | ||||
638 | }); | ||||
639 | | ||||
640 | connect(core, &AtCore::sdWriteProgressChanged, dialog.get(), &QProgressDialog::setValue); | ||||
641 | | ||||
642 | connect(dialog.get(), &QProgressDialog::canceled, this, [this] { | ||||
643 | core->setState(AtCore::STOP); | ||||
tcanabrava: wait, what? | |||||
644 | }); | ||||
645 | | ||||
646 | if (!core->toSd(fileName)) { | ||||
647 | QMessageBox::warning(this, tr("Write to Sd"), tr("Writing FAILED")); | ||||
648 | dialog->close(); | ||||
649 | core->setState(AtCore::IDLE); | ||||
650 | } | ||||
651 | } | ||||
patrickelectric: unnecessary |
check if file exist