{
Q_OBJECT
public:
virtual ~ShowLog() {}
private:
Ui::ShowLogClass ui;
MainWin* m_pMainWin;
private slots:
void on_okBtn_clicked( void ) { accept(); }
void on_clearBtn_clicked( void );
};
{
m_pMainWin = static_cast<MainWin*>( pParent );
QDir::setCurrent( QDir::currentPath() );
QFile logFile
( LOG_FILENAME
);
if ( !logFile.exists() || !logFile.open( nOpenMode ) )
reject();
ui.setupUi( this );
QPalette palette
= ui.
centralWidget->palette
();
palette.setColor( ui.centralWidget->backgroundRole(), COLOR_ManageBkg );
ui.centralWidget->setPalette( palette );
// Layout the Show Logfile dialog
sLabels << "Source" << "Type" << "Time" << "Message";
m_logTable->setHorizontalHeaderLabels( sLabels );
m_logTable->verticalHeader()->hide();
m_logTable->setColumnWidth( COL0_Src, 78 );
m_logTable->setColumnWidth( COL1_Type, 70 );
m_logTable->setColumnWidth( COL2_Time, 130 );
m_logTable->setColumnWidth( COL3_Msg, 510 );
m_logTable->setMinimumWidth( 775 );
// Enable sorting after the table is populated, otherwise sorting
// may interfere with the insertion order
m_logTable->setSortingEnabled( false );
QSize bs
= ui.
okBtn->sizeHint
().
expandedTo( ui.
clearBtn->sizeHint
() );
ui.okBtn->setFixedSize( bs );
ui.clearBtn->setFixedSize( bs );
ui.okBtn->setDefault( true );
// Set the "What's This?" text for controls
m_logTable->setWhatsThis( WT_LOG_TABLE );
ui.okBtn->setWhatsThis( WT_OK_BTN );
ui.clearBtn->setWhatsThis( WT_CLEARLOG_BTN );
vbox->addSpacing( 10 );
vbox->addWidget( m_logTable, Qt::AlignHCenter );
vbox->addStretch( 0 );
vbox->addSpacing( 15 );
// Add a stretch to either side of the box to keep the
// button centered whenever stretching horizontally
hbox->addStretch();
hbox->addSpacing( 100 );
hbox->addWidget( ui.clearBtn );
hbox->addSpacing( 60 );
hbox->addWidget( ui.okBtn );
hbox->addSpacing( 100 );
hbox->addStretch();
vbox->addLayout( hbox );
vbox->addSpacing( 7 );
resize( sizeHint() );
// Create a splash-like dialog
qint64 nProgDlgMax = logFile.size();
"Cancel", 0, nProgDlgMax, this, Qt::FramelessWindowHint );
progDlg.setModal( true );
progDlg.setWindowOpacity( 0.92 ); // make the dialog semi-transparent
palette = progDlg.palette();
progDlg.setPalette( palette );
progDlg.setFixedSize( 350, 110 );
QFont font
= progDlg.
font();
font.setBold( true );
progDlg.setFont( font ); // Set the splash font to bold
progDlg.
setForegroundRole( QPalette::WindowText );
// Center the splash screen in the main application window
progDlg.move( m_pMainWin->pos().x() +
(m_pMainWin->frameGeometry().width() / 2) -
(progDlg.frameGeometry().width() / 2),
m_pMainWin->pos().y() +
(m_pMainWin->frameGeometry().height() / 2) -
(progDlg.frameGeometry().height() / 2) );
// Initialize the text stream
QString sLine, sSrc, sType, sTime, sMsg;
Qt::ItemFlags flags;
int start, end, nRow = 0;
int nProgDlgValue = 0;
const int nTextAlignment = Qt::AlignCenter;
const int nMsgTextAlign = Qt::AlignLeft | Qt::AlignVCenter;
const Qt::ItemFlags itemFlags = Qt::ItemIsEditable | Qt::ItemIsSelectable;
// Skip the header
while ( (sLine = logStream.readLine())[0] == '*' )
nProgDlgValue += sLine.length();
// Load the text
while ( !logStream.atEnd() || !sLine.isEmpty() )
{
if ( sLine.isEmpty() ) // skip any empty lines
{
sLine = logStream.readLine();
continue;
}
sSrc.clear();
sType.clear();
sTime.clear();
sMsg.clear();
start = 0;
// Parse the Source
end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
for ( int i = 0; i < 3; i++ )
sSrc[i] = sLine[start + i];
if ( sSrc == "LIB" )
sSrc = "Library";
else if ( sSrc == "APP" )
sSrc = "GCE";
else if ( sSrc == "DBG" )
sSrc = "Debug";
else if ( sSrc == "SYS" )
sSrc = "System";
else if ( sSrc == "SEC" )
sSrc = "Security";
else
sSrc = "Unknown";
start = end + 1;
// Parse the Type
end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
for ( int i = 0; i < 3; i++ )
sType[i] = sLine[start + i];
if ( sType == "INF" )
sType = "Information";
else if ( sType == "ERR" )
sType = "Error";
else if ( sType == "WRN" )
sType = "Warning";
else
sType = "Unknown";
start = end + 1;
// Parse the Time
end = sLine.indexOf( CDL_COOKIE, start, Qt::CaseSensitive );
for ( int i = 0; i < 19; i++ )
sTime[i] = sLine[start + i];
sTime[sTime.indexOf( ' ', 0 )] = '/'; // for year/month
sTime[sTime.indexOf( ' ', 0 )] = '/'; // for month/day
start = end + 4;
// Get the message
sMsg = sLine.right( sLine.count() - start );
// Fill a table row
m_logTable->insertRow( nRow );
// Add message source
m_logTable->item( nRow, COL0_Src )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL0_Src )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL0_Src )->setFlags( flags );
// Add message type
m_logTable->item( nRow, COL1_Type )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL1_Type )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL1_Type )->setFlags( flags );
// Add message time
m_logTable->item( nRow, COL2_Time )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL2_Time )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL2_Time )->setFlags( flags );
// Add message
m_logTable->item( nRow, COL3_Msg )->setTextAlignment( nMsgTextAlign );
// Set as read-only
flags = m_logTable->item( nRow, COL3_Msg )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL3_Msg )->setFlags( flags );
nRow++;
sLine = logStream.readLine();
// Increment progress bar
progDlg.setValue( nProgDlgValue += sLine.length() );
m_pMainWin->m_pApp->processEvents();
if ( progDlg.wasCanceled() )
break;
}
// Close the QFile
if ( logFile.isOpen() )
logFile.close();
// Enable sorting
m_logTable->setSortingEnabled( true );
}
class ShowLog : public QDialog
{
Q_OBJECT
public:
ShowLog( QWidget* pParent = 0 );
virtual ~ShowLog() {}
private:
Ui::ShowLogClass ui;
QTableWidget* m_logTable;
MainWin* m_pMainWin;
private slots:
void on_okBtn_clicked( void ) { accept(); }
void on_clearBtn_clicked( void );
};
ShowLog::ShowLog( QWidget *pParent ) : QDialog( pParent )
{
m_pMainWin = static_cast<MainWin*>( pParent );
QDir::setCurrent( QDir::currentPath() );
QFile logFile( LOG_FILENAME );
QIODevice::OpenMode nOpenMode = QIODevice::ReadOnly | QIODevice::Text;
if ( !logFile.exists() || !logFile.open( nOpenMode ) )
reject();
ui.setupUi( this );
QPalette palette = ui.centralWidget->palette();
palette.setColor( ui.centralWidget->backgroundRole(), COLOR_ManageBkg );
ui.centralWidget->setPalette( palette );
m_logTable = new QTableWidget( 0, 4, this );
// Layout the Show Logfile dialog
QStringList sLabels;
sLabels << "Source" << "Type" << "Time" << "Message";
m_logTable->setHorizontalHeaderLabels( sLabels );
m_logTable->verticalHeader()->hide();
m_logTable->setColumnWidth( COL0_Src, 78 );
m_logTable->setColumnWidth( COL1_Type, 70 );
m_logTable->setColumnWidth( COL2_Time, 130 );
m_logTable->setColumnWidth( COL3_Msg, 510 );
m_logTable->setMinimumWidth( 775 );
// Enable sorting after the table is populated, otherwise sorting
// may interfere with the insertion order
m_logTable->setSortingEnabled( false );
QSize bs = ui.okBtn->sizeHint().expandedTo( ui.clearBtn->sizeHint() );
ui.okBtn->setFixedSize( bs );
ui.clearBtn->setFixedSize( bs );
ui.okBtn->setDefault( true );
// Set the "What's This?" text for controls
m_logTable->setWhatsThis( WT_LOG_TABLE );
ui.okBtn->setWhatsThis( WT_OK_BTN );
ui.clearBtn->setWhatsThis( WT_CLEARLOG_BTN );
QVBoxLayout *vbox = new QVBoxLayout( this );
vbox->addSpacing( 10 );
vbox->addWidget( m_logTable, Qt::AlignHCenter );
vbox->addStretch( 0 );
vbox->addSpacing( 15 );
// Add a stretch to either side of the box to keep the
// button centered whenever stretching horizontally
QHBoxLayout* hbox = new QHBoxLayout();
hbox->addStretch();
hbox->addSpacing( 100 );
hbox->addWidget( ui.clearBtn );
hbox->addSpacing( 60 );
hbox->addWidget( ui.okBtn );
hbox->addSpacing( 100 );
hbox->addStretch();
vbox->addLayout( hbox );
vbox->addSpacing( 7 );
resize( sizeHint() );
// Create a splash-like dialog
qint64 nProgDlgMax = logFile.size();
QProgressDialog progDlg( QString( "Reading %1 . . ." ).arg( LOG_FILENAME ),
"Cancel", 0, nProgDlgMax, this, Qt::FramelessWindowHint );
progDlg.setModal( true );
progDlg.setWindowOpacity( 0.92 ); // make the dialog semi-transparent
palette = progDlg.palette();
palette.setColor( QPalette::WindowText, QColor( 64, 64, 64 ) );
progDlg.setPalette( palette );
progDlg.setFixedSize( 350, 110 );
QFont font = progDlg.font();
font.setBold( true );
progDlg.setFont( font ); // Set the splash font to bold
progDlg.setForegroundRole( QPalette::WindowText );
// Center the splash screen in the main application window
progDlg.move( m_pMainWin->pos().x() +
(m_pMainWin->frameGeometry().width() / 2) -
(progDlg.frameGeometry().width() / 2),
m_pMainWin->pos().y() +
(m_pMainWin->frameGeometry().height() / 2) -
(progDlg.frameGeometry().height() / 2) );
// Initialize the text stream
QTextStream logStream( &logFile );
QString sLine, sSrc, sType, sTime, sMsg;
Qt::ItemFlags flags;
int start, end, nRow = 0;
int nProgDlgValue = 0;
const int nTextAlignment = Qt::AlignCenter;
const int nMsgTextAlign = Qt::AlignLeft | Qt::AlignVCenter;
const Qt::ItemFlags itemFlags = Qt::ItemIsEditable | Qt::ItemIsSelectable;
// Skip the header
while ( (sLine = logStream.readLine())[0] == '*' )
nProgDlgValue += sLine.length();
// Load the text
while ( !logStream.atEnd() || !sLine.isEmpty() )
{
if ( sLine.isEmpty() ) // skip any empty lines
{
sLine = logStream.readLine();
continue;
}
sSrc.clear();
sType.clear();
sTime.clear();
sMsg.clear();
start = 0;
// Parse the Source
end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
for ( int i = 0; i < 3; i++ )
sSrc[i] = sLine[start + i];
if ( sSrc == "LIB" )
sSrc = "Library";
else if ( sSrc == "APP" )
sSrc = "GCE";
else if ( sSrc == "DBG" )
sSrc = "Debug";
else if ( sSrc == "SYS" )
sSrc = "System";
else if ( sSrc == "SEC" )
sSrc = "Security";
else
sSrc = "Unknown";
start = end + 1;
// Parse the Type
end = sLine.indexOf( ' ', start, Qt::CaseSensitive );
for ( int i = 0; i < 3; i++ )
sType[i] = sLine[start + i];
if ( sType == "INF" )
sType = "Information";
else if ( sType == "ERR" )
sType = "Error";
else if ( sType == "WRN" )
sType = "Warning";
else
sType = "Unknown";
start = end + 1;
// Parse the Time
end = sLine.indexOf( CDL_COOKIE, start, Qt::CaseSensitive );
for ( int i = 0; i < 19; i++ )
sTime[i] = sLine[start + i];
sTime[sTime.indexOf( ' ', 0 )] = '/'; // for year/month
sTime[sTime.indexOf( ' ', 0 )] = '/'; // for month/day
start = end + 4;
// Get the message
sMsg = sLine.right( sLine.count() - start );
// Fill a table row
m_logTable->insertRow( nRow );
// Add message source
m_logTable->setItem( nRow, COL0_Src, new QTableWidgetItem( sSrc ) );
m_logTable->item( nRow, COL0_Src )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL0_Src )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL0_Src )->setFlags( flags );
// Add message type
m_logTable->setItem( nRow, COL1_Type, new QTableWidgetItem( sType ) );
m_logTable->item( nRow, COL1_Type )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL1_Type )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL1_Type )->setFlags( flags );
// Add message time
m_logTable->setItem( nRow, COL2_Time, new QTableWidgetItem( sTime ) );
m_logTable->item( nRow, COL2_Time )->setTextAlignment( nTextAlignment );
// Set as read-only
flags = m_logTable->item( nRow, COL2_Time )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL2_Time )->setFlags( flags );
// Add message
m_logTable->setItem( nRow, COL3_Msg, new QTableWidgetItem( sMsg ) );
m_logTable->item( nRow, COL3_Msg )->setTextAlignment( nMsgTextAlign );
// Set as read-only
flags = m_logTable->item( nRow, COL3_Msg )->flags();
flags ^= itemFlags;
m_logTable->item( nRow, COL3_Msg )->setFlags( flags );
nRow++;
sLine = logStream.readLine();
// Increment progress bar
progDlg.setValue( nProgDlgValue += sLine.length() );
m_pMainWin->m_pApp->processEvents();
if ( progDlg.wasCanceled() )
break;
}
// Close the QFile
if ( logFile.isOpen() )
logFile.close();
// Enable sorting
m_logTable->setSortingEnabled( true );
}
To copy to clipboard, switch view to plain text mode
Bookmarks