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