Esempio n. 1
0
void cPreferences::load() throw(cSevException)
{
    QSettings obPrefFile( m_qsFileName, QSettings::IniFormat );
    if( obPrefFile.status() != QSettings::NoError )
    {
        throw cSevException( cSeverity::WARNING, QString( "Failed to open preferences file: %1" ).arg( m_qsFileName ).toStdString() );
    }

    unsigned int uiGUILevel = obPrefFile.value( "LogLevels/GUILogLevel", cSeverity::ERROR ).toUInt();
    if( (uiGUILevel >= cSeverity::MAX) ||
        (uiGUILevel <= cSeverity::MIN) )
    {
        uiGUILevel = cSeverity::NONE;
        throw cSevException( cSeverity::WARNING, QString( "Invalid GUILogLevel in preferences file: %1" ).arg( m_qsFileName ).toStdString() );
    }
    setGUILogLevel( (cSeverity::teSeverity)uiGUILevel );

    unsigned int uiFileLevel = obPrefFile.value( "LogLevels/FileLogLevel", cSeverity::ERROR ).toUInt();
    if( (uiFileLevel >= cSeverity::MAX) ||
        (uiFileLevel <= cSeverity::MIN) )
    {
        uiFileLevel = cSeverity::NONE;
        throw cSevException( cSeverity::WARNING, QString( "Invalid FileLogLevel in preferences file: %1" ).arg( m_qsFileName ).toStdString() );
    }
    setFileLogLevel( (cSeverity::teSeverity)uiFileLevel );

    m_qsDBHost    = obPrefFile.value( "DataBase/Host", "" ).toString();
    m_qsDBSchema  = obPrefFile.value( "DataBase/Schema", "" ).toString();
    m_qsDBUser    = obPrefFile.value( "DataBase/User", "" ).toString();
    m_qsDBPwd     = obPrefFile.value( "DataBase/Password", "" ).toString();

    setWorkDayEnd( obPrefFile.value( "WorkDay/EndTime", "00:00:00" ).toString() );
    setWorkDayLength( obPrefFile.value( "WorkDay/Length", "08:30:00" ).toString() );
}
Esempio n. 2
0
QString cLogDataSource::decodeFile( const QString &p_qsFileName ) throw( cSevException )
{
    cTracer  obTracer( &g_obLogger, "cLogDataSource::decodeFile", p_qsFileName.toStdString() );

    QString qsTempFileName = copyFile( p_qsFileName );
    QString qsDecodedFileName = qsTempFileName + ".decoded";

    QFile   obCodedFile( qsTempFileName );
    if( !obCodedFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        throw cSevException( cSeverity::ERROR, QString( "%1: %2" ).arg( qsTempFileName ).arg( obCodedFile.errorString() ).toStdString() );
    }

    QFile   obDecodedFile( qsDecodedFileName );
    if( !obDecodedFile.open( QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text ) )
    {
        obCodedFile.close();
        throw cSevException( cSeverity::ERROR, QString( "%1: %2" ).arg( qsDecodedFileName ).arg( obDecodedFile.errorString() ).toStdString() );
    }

    QTextStream srCodedStream( &obCodedFile );
    QTextStream srDecodedStream( &obDecodedFile );
    bool boFirstLine = true;
    for( QString qsCodedLine = srCodedStream.readLine();
         !qsCodedLine.isNull();
         qsCodedLine = srCodedStream.readLine() )
    {
        QStringList slCodedTags = qsCodedLine.split( ',' );
        bool boFirstTag = true;
        for( int i = 0; i < slCodedTags.size(); i++ )
        {
            if( boFirstTag ) boFirstTag = false;
            else srDecodedStream << ",";

            //only need to decode the 5. 9. 10. and 11. tags
            if( boFirstLine || ( i != 5 && i != 9 && i != 10 && i != 11 ) )
            {
                srDecodedStream << slCodedTags.at( i );
            }
            else
            {
                srDecodedStream << decodeString( slCodedTags.at( i ) );
            }
        }
        srDecodedStream << "\n";
        srDecodedStream.flush();

        if( boFirstLine ) boFirstLine = false;
    }

    obCodedFile.close();
    QFile::remove( qsTempFileName );

    obDecodedFile.close();

    obTracer << qsTempFileName.toStdString();

    return qsDecodedFileName;
}
Esempio n. 3
0
void cActionDefList::validateActionDef( const QString &p_qsActionDefFile, const QString &p_qsSchemaFile ) throw( cSevException )
{
    cTracer  obTracer( &g_obLogger, "cActionList::validateActionDef", p_qsActionDefFile.toStdString() );

    QFile obActionsFile( p_qsActionDefFile );

    try
    {
        if( !obActionsFile.open( QIODevice::ReadOnly ) )
        {
            throw cSevException( cSeverity::ERROR, QString( "Cannot open Actions file: %1" ).arg( p_qsActionDefFile ).toStdString() );
        }

        QXmlSchema obSchema;
        obSchema.load( p_qsSchemaFile );

        if( !obSchema.isValid() )
        {
            throw cSevException( cSeverity::ERROR, QString( "Schema %1 is not valid" ).arg( p_qsSchemaFile ).toStdString() );
        }

        QXmlSchemaValidator obValidator( obSchema );
        if( !obValidator.validate( &obActionsFile, QUrl::fromLocalFile( p_qsActionDefFile ) ) )
        {
            throw cSevException( cSeverity::ERROR,
                                 QString( "Action definition file %1 is not valid according to Schema %2" ).arg( p_qsActionDefFile ).arg( p_qsSchemaFile ).toStdString() );
        }

        QString      qsErrorMsg  = "";
        int          inErrorLine = 0;
        obActionsFile.seek( 0 );
        if( !m_poActionsDoc->setContent( &obActionsFile, &qsErrorMsg, &inErrorLine ) )
        {
            throw cSevException( cSeverity::ERROR,
                                 QString( "Parsing Actions file: %1 - Error in line %2: %3" ).arg( p_qsActionDefFile ).arg( inErrorLine ).arg( qsErrorMsg ).toStdString() );
        }

        obActionsFile.close();
    }
    catch( cSevException &e )
    {
        obActionsFile.close();

        throw e;
    }
}
Esempio n. 4
0
void cQTMySQLConnection::executeQuery( const string &p_stQuery,
                                       const bool p_boLog )
                         throw( cSevException )
{
    if( !isOpen() )
        throw cSevException( cSeverity::ERROR,
                "Error executing query: Database is not open" );

    if( p_boLog )
    {
        g_obLogger << cSeverity::DEBUG;
        g_obLogger << p_stQuery << cQTLogger::EOM;
    }

    QSqlQuery  obQuery;
    if( !obQuery.exec( QString::fromStdString( p_stQuery ) ) )
    {
        throw cSevException( cSeverity::ERROR,
                "Error executing query: " + obQuery.lastError().text().toStdString() );
    }
}
Esempio n. 5
0
QSqlQuery* cQTMySQLConnection::executeQTQuery( const QString &p_qsQuery )
                               throw( cSevException )
{
    g_obLogger << cSeverity::DEBUG;
    g_obLogger << p_qsQuery.toStdString() << cQTLogger::EOM;

    if( !isOpen() )
        throw cSevException( cSeverity::ERROR,
                "Error executing query: Database is not open" );

    QSqlQuery*  poQuery = new QSqlQuery;
    if( !poQuery->exec( p_qsQuery ) )
    {
        QString  qsError = poQuery->lastError().text();
        delete poQuery;

        throw cSevException( cSeverity::ERROR,
                "Error executing query: " + qsError.toStdString() );
    }

    return poQuery;
}
Esempio n. 6
0
void cQTMySQLConnection::open( void ) throw( cSevException )
{
    close();

    if( m_poDB->open() )
    {
        m_boOpen = true;
    }
    else
    {
        throw cSevException( cSeverity::ERROR,
                "Error opening database: " + m_poDB->lastError().text().toStdString() );
    }
}
Esempio n. 7
0
void cPreferences::save() const throw(cSevException)
{
    QSettings  obPrefFile( m_qsFileName, QSettings::IniFormat );
    if( obPrefFile.status() != QSettings::NoError )
    {
        throw cSevException( cSeverity::WARNING, QString( "Failed to write to preferences file: %1" ).arg( m_qsFileName ).toStdString() );
    }

    obPrefFile.setValue( "LogLevels/GUILogLevel", m_poGUIWriter->minSeverity() );
    obPrefFile.setValue( "LogLevels/FileLogLevel", m_poFileWriter->minSeverity() );

    obPrefFile.setValue( "WorkDay/EndTime", m_qsWorkDayEnd );
    obPrefFile.setValue( "WorkDay/Length", m_qsWorkDayLength );
}
Esempio n. 8
0
QString cLogDataSource::gunzipFile( const QString &p_qsFileName )
        throw( cSevException )
{
    cTracer  obTracer( &g_obLogger, "cLogDataSource::gunzipFile", p_qsFileName.toStdString() );

    QString qsTempFileName = copyFile( p_qsFileName );
    QString qsCommand = "gzip -d -q -f " + qsTempFileName;
    if( system( qsCommand.toAscii() ) != 0 ) throw cSevException( cSeverity::ERROR, "Error in gunzip command" );

    qsTempFileName.chop( 3 );  // Remove the ".gz" from file-name

    obTracer << qsTempFileName.toStdString();

    return qsTempFileName;
}
Esempio n. 9
0
QString cLogDataSource::unzipFile( const QString &p_qsFileName )
        throw( cSevException )
{
    cTracer  obTracer( &g_obLogger, "cLogDataSource::unzipFile", p_qsFileName.toStdString() );

    QString qsTempFileName = copyFile( p_qsFileName );
    QString qsCommand = QString( "unzip -o -d %1 %2" ).arg( g_poPrefs->tempDir() ).arg( qsTempFileName );
    if( system( qsCommand.toAscii() ) != 0 ) throw cSevException( cSeverity::ERROR, "Error in unzip command" );

    QFile::remove( qsTempFileName ); // Remove the .zip file since unzip leaves it there

    qsTempFileName.chop( 4 );  // Remove the ".zip" from file-name
    qsTempFileName.append( ".log" );

    obTracer << qsTempFileName.toStdString();

    return qsTempFileName;
}
Esempio n. 10
0
QString cLogDataSource::copyFile( const QString &p_qsFileName )
        throw( cSevException )
{
    cTracer  obTracer( &g_obLogger, "cLogDataSource::copyFile", p_qsFileName.toStdString() );

    QString qsTempFileName = g_poPrefs->tempDir();
    if( (qsTempFileName.at( qsTempFileName.length() - 1 ) != '/') &&
        (qsTempFileName.at( qsTempFileName.length() - 1 ) != '\\') )
    {
        qsTempFileName.append( QDir::separator() );
    }
    qsTempFileName.append( p_qsFileName.section( QRegExp( "[/\\\\]" ), -1, -1 ) );

    QFile::remove( qsTempFileName );
    if( !QFile::copy( p_qsFileName, qsTempFileName ) )
    {
        throw cSevException( cSeverity::ERROR, "Cannot copy file " + p_qsFileName.toStdString() + " to " + qsTempFileName.toStdString() );
    }

    obTracer << qsTempFileName.toStdString();

    return qsTempFileName;
}