diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -243,6 +243,17 @@ signals: + /** + * @brief Message emit from atcore these should be displayed to the user for debug. + * + * Possable Messages Are: + * - Waiting for firmware detect. + * - No Plugin found for (detected FW) + * - Failed to open device in Read / Write mode. + * @param msg: the message. + */ + void atcoreMessage(const QString &msg); + /** * @brief New number of extruders * @sa extruderCount(), setExtruderCount(int newCount) diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -82,18 +82,15 @@ d->tempTimer->setInterval(5000); d->tempTimer->setSingleShot(false); //Attempt to find our plugins + qCDebug(ATCORE_PLUGIN) << tr("Detecting Plugin path"); for (const auto &path : AtCoreDirectories::pluginDir) { - qCDebug(ATCORE_PLUGIN) << "Lookin for plugins in " << path; + qCDebug(ATCORE_PLUGIN) << tr("Try:") << path; if (QDir(path).exists()) { d->pluginsDir = QDir(path); - qCDebug(ATCORE_PLUGIN) << "Valid path for plugins found !"; break; } } - if (!d->pluginsDir.exists()) { - qCritical() << "No valid path for plugin !"; - } - qCDebug(ATCORE_PLUGIN) << d->pluginsDir; + qCDebug(ATCORE_PLUGIN) << tr("Plugin path: %1").arg(d->pluginsDir.absolutePath()); findFirmwarePlugins(); setState(AtCore::DISCONNECTED); } @@ -132,14 +129,14 @@ void AtCore::findFirmware(const QByteArray &message) { if (state() == AtCore::DISCONNECTED) { - qWarning() << "Cant find firwmware, serial not connected !"; + qWarning() << tr("Cant find firwmware, serial not connected !"); return; } if (state() == AtCore::CONNECTING) { //Most Firmwares will return "start" on connect, some return their firmware name. if (message.contains("start")) { - qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; + qCDebug(ATCORE_CORE) << tr("Waiting requestFirmware."); QTimer::singleShot(500, this, &AtCore::requestFirmware); return; } else if (message.contains("Grbl")) { @@ -150,15 +147,17 @@ return; } - qCDebug(ATCORE_CORE) << "Waiting for printer..."; + QString message = tr("Waiting for firmware detect."); + qCDebug(ATCORE_CORE) << message; + emit atcoreMessage(message); } - qCDebug(ATCORE_CORE) << "Find Firmware Called" << message; + qCDebug(ATCORE_CORE) << tr("Find Firmware %1").arg(QString::fromLatin1(message)); if (!message.contains("FIRMWARE_NAME:")) { - qCDebug(ATCORE_CORE) << "No firmware yet."; + qCDebug(ATCORE_CORE) << tr("No firmware yet."); return; } - qCDebug(ATCORE_CORE) << "Found firmware string, Looking for Firmware Name."; + qCDebug(ATCORE_CORE) << tr("Found firmware string, Looking for Firmware Name."); QString fwName = QString::fromLocal8Bit(message); fwName = fwName.split(QChar::fromLatin1(':')).at(1); @@ -174,7 +173,7 @@ if (fwName.contains(QChar::fromLatin1('_'))) { fwName.resize(fwName.indexOf(QChar::fromLatin1('_'))); } - qCDebug(ATCORE_CORE) << "Firmware Name:" << fwName; + qCDebug(ATCORE_CORE) << tr("Firmware Name: %1").arg(fwName); if (message.contains("EXTRUDER_COUNT:")) { //this code is broken if more then 9 extruders are detected. since only one char is returned @@ -185,19 +184,18 @@ void AtCore::loadFirmwarePlugin(const QString &fwName) { - qCDebug(ATCORE_PLUGIN) << "Looking for Plugin:" << fwName; + qCDebug(ATCORE_CORE) << tr("Loading plugin: %1").arg(fwName); if (d->plugins.contains(fwName)) { d->pluginLoader.setFileName(d->plugins[fwName]); if (!d->pluginLoader.load()) { //Plugin was not loaded, Provide some debug info. - qCDebug(ATCORE_PLUGIN) << "Plugin Loading: Failed."; - qCDebug(ATCORE_PLUGIN) << d->pluginLoader.errorString(); + qCDebug(ATCORE_CORE) << tr("Failed to load plugin."); + qCDebug(ATCORE_CORE) << d->pluginLoader.errorString(); setState(AtCore::CONNECTING); } else { //Plugin was loaded successfully. d->firmwarePlugin = qobject_cast(d->pluginLoader.instance()); firmwarePlugin()->init(this); - qCDebug(ATCORE_PLUGIN) << "Plugin Loading: Successful"; disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::newMessage); connect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); @@ -209,7 +207,9 @@ setState(IDLE); } } else { - qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; + QString message = tr("No plugin found for %1.").arg(fwName); + qCDebug(ATCORE_CORE) << message; + emit atcoreMessage(message); } } @@ -221,7 +221,9 @@ connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); return true; } else { - qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; + QString message = tr("Failed to open device in read/write mode."); + qCDebug(ATCORE_CORE) << message; + emit atcoreMessage(message); return false; } } @@ -244,7 +246,7 @@ QStringList ports; QList serialPortInfoList = QSerialPortInfo::availablePorts(); if (!serialPortInfoList.isEmpty()) { - foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) { + for (const QSerialPortInfo &serialPortInfo : serialPortInfoList) { #ifdef Q_OS_MAC //Mac OS has callout serial ports starting with cu these devices are read only. //It is necessary to filter them out to help prevent user error. @@ -327,7 +329,7 @@ void AtCore::print(const QString &fileName, bool sdPrint) { if (state() == AtCore::CONNECTING) { - qCDebug(ATCORE_CORE) << "Load a firmware plugin to print."; + qCDebug(ATCORE_CORE) << tr("Load a firmware plugin to print."); return; } //Start a print job. @@ -385,8 +387,8 @@ } //Attempt to unload the firmware plugin. QString name = firmwarePlugin()->name(); - QString msg = d->pluginLoader.unload() ? QStringLiteral("success") : QStringLiteral("FAIL"); - qCDebug(ATCORE_PLUGIN) << QStringLiteral("Firmware plugin %1 unload: %2").arg(name, msg); + QString msg = d->pluginLoader.unload() ? tr("closed.") : tr("Failed to close."); + qCDebug(ATCORE_CORE) << tr("Firmware plugin %1 %2").arg(name, msg); } serial()->close(); //Clear our copy of the sdcard filelist @@ -403,8 +405,9 @@ void AtCore::setState(AtCore::STATES state) { if (state != d->printerState) { - qCDebug(ATCORE_CORE) << "Atcore state changed from [" \ - << d->printerState << "] to [" << state << "]"; + qCDebug(ATCORE_CORE) << tr("Atcore state changed from [%1] to [%2]") + .arg(QVariant::fromValue(d->printerState).value()) + .arg(QVariant::fromValue(state).value()); d->printerState = state; if (state == AtCore::FINISHEDPRINT && d->sdCardPrinting) { //Clean up the sd card print @@ -458,10 +461,10 @@ void AtCore::requestFirmware() { if (serialInitialized()) { - qCDebug(ATCORE_CORE) << "Sending " << GCode::description(GCode::M115); + qCDebug(ATCORE_CORE) << tr("Sending %1").arg(GCode::description(GCode::M115)); serial()->pushCommand(GCode::toCommand(GCode::M115).toLocal8Bit()); } else { - qCDebug(ATCORE_CORE) << "There is no open device to send commands"; + qCDebug(ATCORE_CORE) << tr("There is no open device to send commands"); } } @@ -477,9 +480,8 @@ void AtCore::findFirmwarePlugins() { d->plugins.clear(); - qCDebug(ATCORE_PLUGIN) << "plugin dir:" << d->pluginsDir; QStringList files = d->pluginsDir.entryList(QDir::Files); - foreach (const QString &f, files) { + for (const QString &f : files) { QString file = f; #if defined(Q_OS_WIN) if (file.endsWith(QStringLiteral(".dll"))) @@ -490,20 +492,17 @@ #endif file = file.split(QChar::fromLatin1('.')).at(0); else { - qCDebug(ATCORE_PLUGIN) << "File" << file << "not plugin."; continue; } - qCDebug(ATCORE_CORE) << "Found plugin file" << f; if (file.startsWith(QStringLiteral("lib"))) { file = file.remove(QStringLiteral("lib")); } file = file.toLower().simplified(); - QString pluginString; - pluginString.append(d->pluginsDir.path()); + QString pluginString = d->pluginsDir.absolutePath(); pluginString.append(QChar::fromLatin1('/')); pluginString.append(f); d->plugins[file] = pluginString; - qCDebug(ATCORE_CORE) << tr("plugins[%1]=%2").arg(file, pluginString); + qCDebug(ATCORE_PLUGIN) << tr("Plugin:[%1]=%2").arg(file, pluginString); } } @@ -635,7 +634,7 @@ if (d->extruderCount != newCount && newCount >= 1) { d->extruderCount = newCount; emit extruderCountChanged(newCount); - qCDebug(ATCORE_CORE) << "Extruder Count:" << QString::number(extruderCount()); + qCDebug(ATCORE_CORE) << tr("Extruder Count: %1").arg(QString::number(extruderCount())); } } void AtCore::processQueue() @@ -647,7 +646,7 @@ } if (!serialInitialized()) { - qCDebug(ATCORE_PLUGIN) << "Can't process queue ! Serial not initialized."; + qCDebug(ATCORE_PLUGIN) << tr("Can't process queue ! Serial not initialized."); return; } @@ -748,7 +747,7 @@ pushCommand(GCode::toCommand(GCode::M30, fileName)); getSDFileList(); } else { - qCDebug(ATCORE_CORE) << "Delete failed file not found:" << fileName; + qCDebug(ATCORE_CORE) << tr("Delete failed file not found:%1").arg(fileName); } } diff --git a/src/core/printthread.cpp b/src/core/printthread.cpp --- a/src/core/printthread.cpp +++ b/src/core/printthread.cpp @@ -100,7 +100,7 @@ break; case AtCore::ERRORSTATE: - qCDebug(PRINT_THREAD) << "Error State"; + qCDebug(PRINT_THREAD) << tr("Error State"); break; case AtCore::STOP: { @@ -115,15 +115,15 @@ break; default: - qCDebug(PRINT_THREAD) << "Unknown State"; + qCDebug(PRINT_THREAD) << tr("Unknown State"); break; } } void PrintThread::endPrint() { emit(printProgressChanged(100)); - qCDebug(PRINT_THREAD) << "atEnd"; + qCDebug(PRINT_THREAD) << tr("atEnd"); disconnect(d->core->firmwarePlugin(), &IFirmware::readyForCommand, this, &PrintThread::processJob); disconnect(this, &PrintThread::nextCommand, d->core, &AtCore::pushCommand); disconnect(d->core, &AtCore::stateChanged, this, &PrintThread::setState); @@ -136,10 +136,10 @@ void PrintThread::nextLine() { d->cline = d->gcodestream->readLine(); - qCDebug(PRINT_THREAD) << "Nextline:" << d->cline; + qCDebug(PRINT_THREAD) << tr("Nextline: %1").arg(d->cline); d->stillSize -= d->cline.size() + 1; //remove read chars d->printProgress = float(d->totalSize - d->stillSize) * 100.0 / float(d->totalSize); - qCDebug(PRINT_THREAD) << "progress:" << QString::number(d->printProgress); + qCDebug(PRINT_THREAD) << tr("progress:%1").arg(QString::number(d->printProgress)); emit(printProgressChanged(d->printProgress)); if (d->cline.startsWith(QStringLiteral(";-"))) { @@ -171,11 +171,13 @@ newState == AtCore::STATES::STOP ) ) { - qCDebug(PRINT_THREAD) << "Serial not connected !"; + qCDebug(PRINT_THREAD) << tr("Serial not connected !"); return; } if (newState != d->state) { - qCDebug(PRINT_THREAD) << "State Changed from [" << d->state << "] to [" << newState << ']'; + qCDebug(PRINT_THREAD) << tr("State changed from [%1] to [%2]") + .arg(QVariant::fromValue(d->state).value()) + .arg(QVariant::fromValue(newState).value()); disconnect(d->core, &AtCore::stateChanged, this, &PrintThread::setState); d->state = newState; emit(stateChanged(d->state)); @@ -198,7 +200,7 @@ parser.addOptions(d->options); } - qCDebug(PRINT_THREAD) << "attempting to inject " << cmd; + qCDebug(PRINT_THREAD) << tr("attempting to inject:") << cmd; parser.process(cmd); if (parser.isSet(QStringLiteral("pause"))) { @@ -222,6 +224,6 @@ } else if (parser.isSet(QStringLiteral("command"))) { d->core->pushCommand(parser.positionalArguments().at(0)); } else { - qCDebug(PRINT_THREAD) << "Attempted to inject unknown command: " << parser.positionalArguments(); + qCDebug(PRINT_THREAD) << tr("Attempted to inject unknown command: ") << parser.positionalArguments(); } } diff --git a/src/core/seriallayer.cpp b/src/core/seriallayer.cpp --- a/src/core/seriallayer.cpp +++ b/src/core/seriallayer.cpp @@ -133,7 +133,7 @@ qCDebug(SERIAL_LAYER) << "Serial not connected !"; return; } - foreach (const auto &comm, d->_sByteCommands) { + for (const auto &comm : d->_sByteCommands) { write(comm); emit(pushedCommand(comm)); } diff --git a/src/plugins/aprinterplugin.cpp b/src/plugins/aprinterplugin.cpp --- a/src/plugins/aprinterplugin.cpp +++ b/src/plugins/aprinterplugin.cpp @@ -37,5 +37,5 @@ AprinterPlugin::AprinterPlugin() { - qCDebug(APRINTER_PLUGIN) << name() << " plugin loaded!"; + qCDebug(APRINTER_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } diff --git a/src/plugins/grblplugin.cpp b/src/plugins/grblplugin.cpp --- a/src/plugins/grblplugin.cpp +++ b/src/plugins/grblplugin.cpp @@ -36,7 +36,7 @@ GrblPlugin::GrblPlugin() { - qCDebug(GRBL_PLUGIN) << name() << " plugin loaded!"; + qCDebug(GRBL_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } void GrblPlugin::validateCommand(const QString &lastMessage) diff --git a/src/plugins/marlinplugin.cpp b/src/plugins/marlinplugin.cpp --- a/src/plugins/marlinplugin.cpp +++ b/src/plugins/marlinplugin.cpp @@ -37,7 +37,7 @@ MarlinPlugin::MarlinPlugin() { - qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; + qCDebug(MARLIN_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } void MarlinPlugin::validateCommand(const QString &lastMessage) diff --git a/src/plugins/repetierplugin.cpp b/src/plugins/repetierplugin.cpp --- a/src/plugins/repetierplugin.cpp +++ b/src/plugins/repetierplugin.cpp @@ -37,7 +37,7 @@ RepetierPlugin::RepetierPlugin() { - qCDebug(REPETIER_PLUGIN) << name() << " plugin loaded!"; + qCDebug(REPETIER_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } void RepetierPlugin::validateCommand(const QString &lastMessage) diff --git a/src/plugins/smoothieplugin.cpp b/src/plugins/smoothieplugin.cpp --- a/src/plugins/smoothieplugin.cpp +++ b/src/plugins/smoothieplugin.cpp @@ -37,5 +37,5 @@ SmoothiePlugin::SmoothiePlugin() { - qCDebug(SMOOTHIE_PLUGIN) << name() << " plugin loaded!"; + qCDebug(SMOOTHIE_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } diff --git a/src/plugins/sprinterplugin.cpp b/src/plugins/sprinterplugin.cpp --- a/src/plugins/sprinterplugin.cpp +++ b/src/plugins/sprinterplugin.cpp @@ -37,5 +37,5 @@ SprinterPlugin::SprinterPlugin() { - qCDebug(SPRINTER_PLUGIN) << name() << " plugin loaded!"; + qCDebug(SPRINTER_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } diff --git a/src/plugins/teacupplugin.cpp b/src/plugins/teacupplugin.cpp --- a/src/plugins/teacupplugin.cpp +++ b/src/plugins/teacupplugin.cpp @@ -37,7 +37,7 @@ TeacupPlugin::TeacupPlugin() { - qCDebug(TEACUP_PLUGIN) << name() << " plugin loaded!"; + qCDebug(TEACUP_PLUGIN) << tr("%1 plugin loaded.").arg(name()); } QByteArray TeacupPlugin::translate(const QString &command) diff --git a/src/widgets/about.cpp b/src/widgets/about.cpp --- a/src/widgets/about.cpp +++ b/src/widgets/about.cpp @@ -32,21 +32,21 @@ setWindowTitle(QStringLiteral("About Atcore")); setWindowIcon(QIcon::fromTheme(QStringLiteral("help-about"), style()->standardIcon(QStyle::SP_MessageBoxInformation))); - QLabel *lbl_version = new QLabel(QString::fromLatin1("Version: %1").arg(QCoreApplication::applicationVersion())); - QLabel *lbl_qt_version = new QLabel(QString::fromLatin1("Using Qt: %1").arg(QString::fromLatin1(qVersion()))); - QLabel *lbl_authors = new QLabel(QStringLiteral("Authors:\n" - " Chris Rizzitello \n" - " Patrick José Pereira \n" - " Lays Rodrigues \n" - " Tomaz Canabrava " - "")); + QLabel *lbl_version = new QLabel(tr("Version: %1").arg(QCoreApplication::applicationVersion())); + QLabel *lbl_qt_version = new QLabel(tr("Using Qt: %1").arg(QString::fromLatin1(qVersion()))); + QLabel *lbl_authors = new QLabel(tr("Authors:\n" + " Chris Rizzitello \n" + " Patrick José Pereira \n" + " Lays Rodrigues \n" + " Tomaz Canabrava " + "")); QLabel *lbl_icon = new QLabel(); lbl_icon->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); lbl_icon->setScaledContents(true); lbl_icon->setPixmap(QPixmap(QStringLiteral(":/icon/atcore"))); - QPushButton *btn_close = new QPushButton(QStringLiteral("&Close")); + QPushButton *btn_close = new QPushButton(tr("Close")); connect(btn_close, &QPushButton::clicked, this, &QDialog::close); QVBoxLayout *versionInfo = new QVBoxLayout; diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp --- a/src/widgets/axiscontrol.cpp +++ b/src/widgets/axiscontrol.cpp @@ -28,7 +28,7 @@ setRect(QRect(QPoint(size * -1, size * -1), QPoint(size, size))); setZValue(size * -1); setAcceptHoverEvents(true); - setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); + setToolTip(tr("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); } void PieButton::setPalette(QPalette palette) @@ -58,9 +58,9 @@ setAcceptHoverEvents(true); setZValue(size * -1); if (axis != QLatin1Char('E')) { - setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); + setToolTip(tr("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); } else { - setToolTip(QStringLiteral("Extrude %1 Units").arg(value)); + setToolTip(tr("Extrude %1 Units").arg(value)); } } diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -46,6 +46,7 @@ initStatusBar(); initWidgets(); + connect(core, &AtCore::atcoreMessage, logWidget, &LogWidget::appendLog); logWidget->appendLog(tr("Attempting to locate Serial Ports")); core->setSerialTimerInterval(1000); @@ -414,14 +415,9 @@ connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog); buttonConnect->setText(tr("Disconnect")); logWidget->appendLog(tr("Serial connected")); - if (comboPlugin->currentText().contains(tr("Autodetect"))) { - logWidget->appendLog(tr("No plugin loaded !")); - logWidget->appendLog(tr("Requesting Firmware...")); - } else { + if (!comboPlugin->currentText().contains(tr("Autodetect"))) { core->loadFirmwarePlugin(comboPlugin->currentText()); } - } else { - logWidget->appendLog(tr("Failed to open serial in r/w mode")); } } else { disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog);