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 | } | ||
58 | 58 | | |||
59 | void MainWindow::initMenu() | 59 | void MainWindow::initMenu() | ||
60 | { | 60 | { | ||
61 | QMenu *menuFile = new QMenu(tr("File")); | 61 | QMenu *menuFile = new QMenu(tr("File")); | ||
62 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); | 62 | QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); | ||
63 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | 63 | connect(actionQuit, &QAction::triggered, this, &MainWindow::close); | ||
64 | menuFile->addAction(actionQuit); | 64 | menuFile->addAction(actionQuit); | ||
▲ Show 20 Lines • Show All 511 Lines • ▼ Show 20 Line(s) | 569 | { | |||
576 | if (!disabled) { | 576 | if (!disabled) { | ||
577 | temperatureWidget->updateExtruderCount(core->extruderCount()); | 577 | temperatureWidget->updateExtruderCount(core->extruderCount()); | ||
578 | printWidget->updateFanCount(fanCount); | 578 | printWidget->updateFanCount(fanCount); | ||
579 | } else { | 579 | } else { | ||
580 | printWidget->setPrintText(tr("Print File")); | 580 | printWidget->setPrintText(tr("Print File")); | ||
581 | statusWidget->showPrintArea(false); | 581 | statusWidget->showPrintArea(false); | ||
582 | } | 582 | } | ||
583 | } | 583 | } | ||
584 | | ||||
585 | void MainWindow::writeToSd(const QString &fileName) | ||||
586 | { | ||||
587 | std::unique_ptr<QProgressDialog> dialog(new QProgressDialog(tr("Writing file to SD Card..."), tr("Cancel"), 0, 100, this)); | ||||
588 | | ||||
589 | connect(core, &AtCore::sdWriteChanged, this, [&dialog](bool writing) { | ||||
590 | if (writing) { | ||||
591 | dialog->open(); | ||||
592 | } else { | ||||
593 | dialog->close(); | ||||
594 | } | ||||
595 | }); | ||||
596 | | ||||
patrickelectric: check if file exist | |||||
597 | connect(core, &AtCore::sdWriteProgressChanged, dialog.get(), &QProgressDialog::setValue); | ||||
598 | | ||||
599 | connect(dialog.get(), &QProgressDialog::canceled, this, [this] { | ||||
600 | core->setState(AtCore::STOP); | ||||
601 | }); | ||||
602 | | ||||
603 | if (!core->toSd(fileName)) { | ||||
604 | QMessageBox::warning(this, tr("Write to Sd"), tr("Writing FAILED")); | ||||
605 | dialog->close(); | ||||
606 | core->setState(AtCore::IDLE); | ||||
607 | } | ||||
tcanabrava: wait, what? | |||||
608 | } | ||||
patrickelectric: unnecessary |
check if file exist