/*************************************************************************** LogPanel.cxx - description ------------------- begin : Mon Jul 12 2004 copyright : (C) 2004 by jschumac email : jschumac@physik.uni-bonn.de ***************************************************************************/ /*************************************************************************** * * * 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include //Added by qt3to4: #include #include #include #include #include "LogPanel.h" LogPanel::LogPanel( QWidget* parent, const char* ) : QWidget( parent ) { setupUi(this); QObject::connect(SaveLogButton, SIGNAL(clicked()), this, SLOT(saveCurrentLog())); QObject::connect(clearButton, SIGNAL(clicked()), this, SLOT(clearCurrentLog())); QObject::connect(browseButton, SIGNAL(clicked()), this, SLOT(browseLogFolder())); QObject::connect(getlogButton, SIGNAL(clicked()), this, SLOT(getRodBuffers())); logsavePath->setText(QString::null); QString dt = QDateTime::currentDateTime().toString("hh:mm:ss_MM-dd-yyyy"); m_rodLogFile = "rodbuff_"+dt+".txt"; m_stcLogFile = "stclog_"+dt+".txt"; #ifdef WIN32 // replace colons by dashes, win doesn't like them in file names... m_rodLogFile.replace(":","-"); m_stcLogFile.replace(":","-"); #endif m_seenRodErrs = true; } LogPanel::~LogPanel(){ } void LogPanel::saveCurrentLog(){ QStringList filter; filter += "Text file (*.txt)"; filter += "Any file (*.*)"; Q3FileDialog fdia(QString::null,QString::null,this,"select data file",TRUE); fdia.setFilters(filter); fdia.setMode(Q3FileDialog::AnyFile); if(fdia.exec() == QDialog::Accepted) { std::ofstream out(fdia.selectedFile().latin1()); if (out.is_open()){ if(LogTabWidget->currentPage()==LogTabWidget->page(0)){ // STcontrol log out << "STcontrol log" << std::endl; out << STControlLogBrowser->text().latin1(); }else if(LogTabWidget->currentPage()==LogTabWidget->page(1)){ // ROD buffer log out << "ROD buffer log" << std::endl; out << RODBuffersLogBrowser->text().latin1(); } out.close(); } } } void LogPanel::clearCurrentLog(){ if(LogTabWidget->currentPage()==LogTabWidget->page(0)){ // STcontrol log STControlLogBrowser->clear(); }else if(LogTabWidget->currentPage()==LogTabWidget->page(1)){ // ROD buffer log RODBuffersLogBrowser->clear(); } } /** Append to the general Log */ void LogPanel::logToSTC( const QString& str_in ){ STControlLogBrowser->moveCursor( Q3TextEdit::MoveEnd, false ); STControlLogBrowser->insert( str_in ); if(!logsavePath->text().isEmpty()){ FILE *sctFile = fopen((logsavePath->text()+"/"+m_stcLogFile).latin1(),"a"); fprintf(sctFile,"%s",str_in.latin1()); fclose(sctFile); } } /** Append to the general Log, and open window since this is an error msg. */ void LogPanel::errorToSTC( const QString& str_in ){ // "normal" logging QString str = "ERROR:\n"; str += str_in; // STControlLogBrowser->moveCursor( QTextEdit::MoveEnd, false ); // STControlLogBrowser->insert( "ERROR:\n" ); // STControlLogBrowser->insert( str_in ); // if(!logsavePath->text().isEmpty()){ // FILE *sctFile = fopen((logsavePath->text()+"/"+m_stcLogFile).latin1(),"a"); // fprintf(sctFile,"%s",str_in.latin1()); // fclose(sctFile); // } logToSTC(str); // open waning box // default string should be class::routine : message -> split QString function="STcontrol", message=str_in; int pos = message.find(" : "); if(pos>=0){ function = message.left(pos); message = message.right(message.length()-pos-3); } QMessageBox::warning(this, function, message); } /** Append to the ROD buffers Log */ void LogPanel::logToROD( const QString& str_in ){ RODBuffersLogBrowser->moveCursor( Q3TextEdit::MoveEnd, false ); RODBuffersLogBrowser->insert( str_in ); if(!logsavePath->text().isEmpty()){ FILE *rodFile = fopen((logsavePath->text()+"/"+m_rodLogFile).latin1(),"a"); fprintf(rodFile,"%s",str_in.latin1()); fclose(rodFile); } } /** Append to the ROD buffers Log, and open window since this is an error msg. */ void LogPanel::errorToROD( const QString& str_in ){ // "normal" logging logToROD(str_in); // error window if(m_seenRodErrs){ QMessageBox::warning(this, "ROD buffer", "There is a message in one of the ROD error buffers.\n Please check log panel for details."); m_seenRodErrs = false; } } void LogPanel::getRodBuffers(){ logToROD( "user-triggered buffer readout\n"); emit wantRodBuffers(); } void LogPanel::browseLogFolder(const char *in_path){ QString path; if(in_path==0){ path = Q3FileDialog::getExistingDirectory ( logsavePath->text(), this, "brwsdir", "Browse to log-saving directory", true); }else{ path = in_path; if(path.right(1)!="/") path+="/"; } if(!path.isEmpty() && logsavePath->text()!=path){ logsavePath->setText(path); FILE *rodFile = fopen((logsavePath->text()+m_rodLogFile).latin1(),"w"); FILE *stcFile = fopen((logsavePath->text()+m_stcLogFile).latin1(),"w"); fprintf(stcFile,"%s",STControlLogBrowser->text().latin1()); fprintf(rodFile,"%s",RODBuffersLogBrowser->text().latin1()); fclose(rodFile); fclose(stcFile); } return; } void LogPanel::showEvent ( QShowEvent *e ) { QWidget::showEvent(e); m_seenRodErrs=true; }