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 519 Lines • ▼ Show 20 Line(s) | 577 | { | |||
584 | if (!disabled) { | 584 | if (!disabled) { | ||
585 | temperatureWidget->updateExtruderCount(core->extruderCount()); | 585 | temperatureWidget->updateExtruderCount(core->extruderCount()); | ||
586 | printWidget->updateFanCount(fanCount); | 586 | printWidget->updateFanCount(fanCount); | ||
587 | } else { | 587 | } else { | ||
588 | printWidget->setPrintText(tr("Print File")); | 588 | printWidget->setPrintText(tr("Print File")); | ||
589 | statusWidget->showPrintArea(false); | 589 | statusWidget->showPrintArea(false); | ||
590 | } | 590 | } | ||
591 | } | 591 | } | ||
592 | | ||||
593 | void MainWindow::writeToSd(const QString &fileName) | ||||
594 | { | ||||
595 | std::unique_ptr<QProgressDialog> dialog(new QProgressDialog(tr("Writing file to SD Card..."), tr("Cancel"), 0, 100, this)); | ||||
596 | | ||||
597 | connect(core, &AtCore::sdWriteChanged, this, [&dialog](bool writing) { | ||||
598 | if (writing) { | ||||
599 | dialog->open(); | ||||
600 | } else { | ||||
601 | dialog->close(); | ||||
602 | } | ||||
603 | }); | ||||
604 | | ||||
patrickelectric: check if file exist | |||||
605 | connect(core, &AtCore::sdWriteProgressChanged, dialog.get(), &QProgressDialog::setValue); | ||||
606 | | ||||
607 | connect(dialog.get(), &QProgressDialog::canceled, this, [this] { | ||||
608 | core->setState(AtCore::STOP); | ||||
609 | }); | ||||
610 | | ||||
611 | if (!core->toSd(fileName)) { | ||||
612 | QMessageBox::warning(this, tr("Write to Sd"), tr("Writing FAILED")); | ||||
613 | dialog->close(); | ||||
614 | core->setState(AtCore::IDLE); | ||||
615 | } | ||||
tcanabrava: wait, what? | |||||
616 | } | ||||
patrickelectric: unnecessary |
check if file exist