DumontEXE 0.0.1
QxtLog.cpp
00001 
00002 #include "qxtlog.h"
00003 
00004 #include <QFile>
00005 #include <QTextStream>
00006 #include <QTextCodec>
00007 
00008 QPointer<QxtLog>       QxtLog::s_instance;
00009 QPointer<QxtLogWindow> QxtLog::s_window;
00010 
00011 QxtLog::QxtLog( int argc, char **argv, QObject * parent )
00012 :
00013   QObject(parent)
00014 {
00015   s_instance = this;
00016 
00017 //  qInstallMsgHandler( messageTrap );
00018 }
00019 
00020 QxtLog::~QxtLog()
00021 {
00022   s_instance = NULL;
00023 
00024   qInstallMsgHandler(NULL);
00025 }
00026 
00027 void QxtLog::save( const QString & fileName )
00028 {
00029   window()-> save( fileName );
00030 }
00031 
00032 void QxtLog::debug( const QString & msg )
00033 {
00034   qDebug( msg.toAscii().data() );
00035 }
00036 
00037 void QxtLog::warning( const QString & msg )
00038 {
00039   qWarning( msg.toAscii().data() );
00040 }
00041 
00042 void QxtLog::critical( const QString & msg )
00043 {
00044   qCritical( msg.toAscii().data() );
00045 }
00046 
00047 void QxtLog::fatal( const QString & msg )
00048 {
00049   qFatal( msg.toAscii().data() );
00050 }
00051 
00052 QxtLogWindow * QxtLog::window(void)
00053 {
00054 
00055   if( !s_window ) 
00056        s_window = new QxtLogWindow();
00057 
00058   return( s_window );
00059 }
00060 
00061 void QxtLog::messageTrap( QtMsgType type, const char *msg )
00062 {
00063   const char * title = "";
00064   switch( type )
00065   {
00066     case QtDebugMsg:    title = "qDebug";    break;
00067     case QtWarningMsg:  title = "qWarning";  break;
00068     case QtCriticalMsg: title = "qCritical"; break;
00069     case QtFatalMsg:    title = "qFatal";    break;
00070     default:            title = "unknown";
00071   }
00072 
00073   if( instance() )
00074   {
00075     if( instance()-> window() )
00076     {
00077       instance()-> window()-> textField()-> append( QString(title) + ": " + QString(msg) );
00078     }
00079   }
00080 
00081   if( qApp )
00082       qApp-> processEvents();
00083 
00084 }
00085 
00086 
00087 
00088 
00089 
00090 
00091 QxtLogWindow::QxtLogWindow( QWidget * parent )
00092 :
00093   QMainWindow(parent)
00094 {
00095   setupUi(this);
00096   QWidget::setFont( QFont("Courier New", 10) );
00097 }
00098 
00099 QxtLogWindow::~QxtLogWindow()
00100 {
00101 }
00102 
00103 void QxtLogWindow::on_actLogSave_triggered(void)
00104 {
00105   save( qApp-> applicationDirPath() + "/dumont.log" );
00106 }
00107 
00108 void QxtLogWindow::save( const QString & i_fileName )
00109 {
00110   QFile file(i_fileName);
00111   if( !file.open(QFile::WriteOnly) )
00112     return;
00113 
00114   QTextStream ts(&file);
00115   ts.setCodec(QTextCodec::codecForName("UTF-8"));
00116   ts << textEdit-> document()-> toPlainText();
00117 
00118 }
00119 
00120 void QxtLogWindow::show(void)
00121 {
00122   QWidget::show();
00123   QWidget::setFocus();
00124 }
00125 
00126 QTextEdit * QxtLogWindow::textField(void)
00127 {
00128   return( textEdit );
00129 }
00130 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com