Exemple #1
0
/// \brief Construct the object
HelpDialog::HelpDialog() :
	ui(new Ui::HelpDialog)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	ui->setupUi(this);
	reloadTextValue();
	#ifdef ULTRACOPIER_DEBUG
	connect(debug_engine_instance,SIGNAL(newDebugInformation()),this,SLOT(addDebugText()));
	connect(ui->pushButtonSaveBugReport,SIGNAL(clicked()),debug_engine_instance,SLOT(saveBugReport()));
	#else // ULTRACOPIER_DEBUG
	ui->lineEditInsertDebug->hide();
	ui->debugView->hide();
	ui->pushButtonSaveBugReport->hide();
	ui->pushButtonCrash->hide();
	this->setMaximumSize(QSize(500,128));
	/*timeToSetText.setInterval(250);
	timeToSetText.setSingleShot(true);
	connect(&timeToSetText,SIGNAL(timeout()),this,SLOT(showDebugText()));*/
	ui->pushButtonClose->hide();
	#endif // ULTRACOPIER_DEBUG
	//connect the about Qt
	connect(ui->pushButtonAboutQt,SIGNAL(toggled(bool)),qApp,SLOT(aboutQt()));
}
/// \brief For add message info, this function is thread safe
void DebugEngine::addDebugInformation(const DebugLevel_custom &level,const QString& function,const QString& text,QString file,const int& ligne,const QString& location)
{
    //Remove the compiler extra patch generated
    file=file.remove(QRegularExpression("\\.\\.?[/\\\\]([^/]+[/\\\\])?"));
    QString addDebugInformation_lignestring=QString::number(ligne);
    QString addDebugInformation_fileString=file;
    if(ligne!=-1)
        addDebugInformation_fileString+=":"+addDebugInformation_lignestring;
    //Load the time from start
    QString addDebugInformation_time = QString::number(startTime.elapsed());
    QString addDebugInformation_htmlFormat;
    switch(level)
    {
        case DebugLevel_custom_Information:
            addDebugInformation_htmlFormat="<tr class=\"Information\"><td class=\"time\">"+addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
        break;
        case DebugLevel_custom_Critical:
            addDebugInformation_htmlFormat="<tr class=\"Critical\"><td class=\"time\">"+addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
        break;
        case DebugLevel_custom_Warning:
            addDebugInformation_htmlFormat="<tr class=\"Warning\"><td class=\"time\">"+addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
        break;
        case DebugLevel_custom_Notice:
            addDebugInformation_htmlFormat="<tr class=\"Notice\"><td class=\"time\">"+addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
        break;
        case DebugLevel_custom_UserNote:
            addDebugInformation_htmlFormat="<tr class=\"Note\"><td class=\"time\">"+addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
        break;
    }
    //To prevent access of string in multi-thread
    {
        //Show the text in console
        QString addDebugInformation_textFormat;
        addDebugInformation_textFormat = "("+addDebugInformation_time.rightJustified(8,' ')+") ";
        if(file!="" && ligne!=-1)
            addDebugInformation_textFormat += file+":"+addDebugInformation_lignestring+":";
        addDebugInformation_textFormat += function+"(), (location: "+location+"): "+text;
        puts(qPrintable(addDebugInformation_textFormat));
        QMutexLocker lock_mutex(&mutex);
        if(currentBackend==File)
        {
            if(logFile.size()>64*1024*1024) // greater than 64MB
                puts("File log greater than 64MB, stop to record it!");
            else
                logFile.write(addDebugInformation_htmlFormat.toUtf8());
        }
        else
        {
            if(debugHtmlContent.size()<64*1024*1024)
                debugHtmlContent+=addDebugInformation_htmlFormat;
            else
                puts("String greater than 64MB, stop to record it!");
        }
        ItemOfDebug newItem;
        newItem.time=addDebugInformation_time;
        newItem.level=level;
        newItem.function=function;
        if(addDebugInformation_lignestring!="-1")
            newItem.file=file+":"+addDebugInformation_lignestring;
        else
            newItem.file=file;
        newItem.location=location;
        newItem.text=text;
        listItemOfDebug << newItem;
    }
    //Send the new line
    if(addDebugInformationCallNumber<ULTRACOPIER_DEBUG_MAX_GUI_LINE)
    {
        addDebugInformationCallNumber++;
        emit newDebugInformation();
    }
}