/*------------------------------------------------------------------------------ -- This file is a part of the SocExplorer Software -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@lpp.polytechnique.fr ----------------------------------------------------------------------------*/ #include "ahbuartpluginui.h" #include "ui_ahbuartpluginui.h" ahbUartPluginUI::ahbUartPluginUI(QWidget *parent) : QWidget(parent), ui(new Ui::ahbUartPluginUI) { ui->setupUi(this); connect(ui->OpenPort,SIGNAL(clicked()),this,SLOT(connectPort())); connect(ui->PortspeedSlider,SIGNAL(valueChanged(int)),ui->baurateLCD,SLOT(display(int))); connect(ui->logFileChooseBp,SIGNAL(clicked()),this,SLOT(chooseLogFile())); connect(this,SIGNAL(setLogFileName(QString)),this->ui->logFileName,SLOT(setText(QString))); connect(ui->rescanPorts,SIGNAL(clicked()),this,SIGNAL(rescanPorts())); this->logFile = new QFile(); } void ahbUartPluginUI::connectPort() { emit this->connectPortsig(ui->PortName->text(),ui->PortspeedSlider->value()); } void ahbUartPluginUI::setConnected(bool connected) { if(connected == true) { ui->OpenPort->setText(tr("Close port")); } else ui->OpenPort->setText(tr("Open port")); } ahbUartPluginUI::~ahbUartPluginUI() { delete ui; } void ahbUartPluginUI::chooseLogFile() { if(this->logFile->isOpen()) this->logFile->close(); this->logFile->setFileName(QFileDialog::getSaveFileName(this,tr("Open Log file"),QDir::homePath(), tr("Log Files (*.txt *.log)"))); if(this->logFile->open(QIODevice::WriteOnly)) { this->logFileStrm = new QTextStream(this->logFile); emit this->setLogFileName(this->logFile->fileName()); } } void ahbUartPluginUI::setconfig(QString PortName, int baudrate) { this->ui->PortName->setText(PortName); this->ui->PortspeedSlider->setValue(baudrate); } void ahbUartPluginUI::logFileEnDisable(int state) { if(state==Qt::Checked) { this->logFileEn = true; } else if(state==Qt::Unchecked) { this->logFileEn = false; } } bool ahbUartPluginUI::islogfileenable() { return this->logFileEn; } void ahbUartPluginUI::appendToLogFile(const QString & text) { if(this->logFileEn && this->logFile->isOpen()) { *(this->logFileStrm) << text << endl; } } void ahbUartPluginUI::setCompleter(QCompleter *completer) { this->ui->PortName->setCompleter(completer); } void ahbUartPluginUI::closeEvent(QCloseEvent *event) { if(this->logFile->isOpen()) { this->logFileStrm->flush(); this->logFile->waitForBytesWritten(3000); this->logFile->close(); } event->accept(); }