DumontEXE 0.0.1
QxtLogger.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include "qxtlogger.h"
00026 
00027 #include <QApplication>
00028 #include <QFile>
00029 #include <QFlags>
00030 #include <QIODevice>
00031 #include <QTextStream>
00032 #include <QTextCodec>
00033 #include <QTextEdit>
00034 #include <QMessageBox>
00035 #include <QSettings>
00036 #include <QTextEdit>
00037 
00038 QxtLoggerManager * QxtLoggerManager::s_self  = NULL;
00039 
00040 QxtLoggerManager::QxtLoggerManager( QObject * parent )
00041 :
00042   QObject(parent)
00043 {
00044   init();
00045 }
00046 
00047 QxtLoggerManager::~QxtLoggerManager()
00048 {
00049   qInstallMsgHandler(0);
00050 
00051   s_self = NULL;
00052 }
00053 
00054 void QxtLoggerManager::init(void)
00055 {
00056   Q_ASSERT_X( !s_self, "QxtLoggerManager", "There should be only one QxtLogManager object" );
00057 
00058   s_self = this;
00059 
00060   qInstallMsgHandler( messageTrap );
00061 
00062 }
00063 
00064 void QxtLoggerManager::messageTrap( QtMsgType type, const char *msg )
00065 {
00066   Q_ASSERT_X( qxtLoggerManager, "QxtLoggerManager", "No Static Logger Manager" );
00067 
00068   switch( type )
00069   {
00070     case QtDebugMsg:    qxtLoggerManager-> getRootLogger()-> debug    ( msg ); break;
00071     case QtWarningMsg:  qxtLoggerManager-> getRootLogger()-> warning  ( msg ); break;
00072     case QtCriticalMsg: qxtLoggerManager-> getRootLogger()-> critical ( msg ); break;
00073     case QtFatalMsg:    qxtLoggerManager-> getRootLogger()-> fatal    ( msg ); break;
00074   }
00075 }
00076 
00077 
00078 QxtLoggerManager * QxtLoggerManager::instance(void)
00079 {
00080   if( !s_self ) new QxtLoggerManager();
00081 
00082   return( s_self );
00083 }
00084 
00085 QxtLogger * QxtLoggerManager::getRootLogger(void)
00086 {
00087   /*
00088   ** If a root log doesn't exist, then create one.
00089   **
00090   */
00091   if( !m_rootLogger )
00092        m_rootLogger = getLogger( "root" );
00093 
00094   return( m_rootLogger );
00095 
00096 }
00097 
00098 QxtLogger * QxtLoggerManager::getLogger( const QString & name )
00099 {
00100   return( new QxtLogger(name) );
00101 }
00102 
00103 
00104 
00105 
00106 
00107 QxtLogger::QxtLogger( const QString & name, QxtLogger * parent )
00108 :
00109   QObject(parent)
00110 {
00111   setObjectName(name);
00112 
00113   qxtLoggerManager-> instance();
00114 
00115 //  qDebug( "QxtLogger(%s)", name.toAscii().data() );
00116 
00117 }
00118 
00119 QxtLogger::~QxtLogger()
00120 {
00121 //  qDebug( "~QxtLogger(%s)", objectName().toAscii().data() );
00122 }
00123 
00124 QxtLogger * QxtLogger::parent(void)
00125 {
00126   return( (QxtLogger*) parent() );
00127 }
00128 
00129 void QxtLogger::trace( const QString & msg )
00130 {
00131   log( QxtLogger::Trace, msg );
00132 }
00133 
00134 void QxtLogger::debug( const QString & msg )
00135 {
00136   log( QxtLogger::Debug, msg );
00137 }
00138 
00139 void QxtLogger::warning( const QString & msg )
00140 {
00141   log( QxtLogger::Warning, msg );
00142 }
00143 
00144 void QxtLogger::info( const QString & msg )
00145 {
00146   log( QxtLogger::Info, msg );
00147 }
00148 
00149 void QxtLogger::critical( const QString & msg )
00150 {
00151   log( QxtLogger::Critical, msg );
00152 }
00153 
00154 void QxtLogger::fatal( const QString & msg )
00155 {
00156   log( QxtLogger::Fatal, msg );
00157 }
00158 
00159 void QxtLogger::log( const Level l, const QString & msg )
00160 {
00161   if( !m_text )
00162   {
00163     m_text = new QTextEdit();
00164     m_text-> setFont( QFont("Courier New",8) );
00165     m_text-> resize( 600, 600 );
00166     m_text-> move( 1, 1 );
00167   }
00168 
00169   m_text-> moveCursor( QTextCursor::End );
00170   m_text-> insertPlainText( msg + "\r\n" );
00171   m_text-> show();
00172   qApp-> processEvents();
00173 
00174 //  QMessageBox::information( NULL, "QxtLogger", msg );
00175 
00176 
00177 }
00178 
00179 
00180 void QxtLogger::clear()
00181 {
00182   if( m_text )
00183   {
00184     m_text-> clear();
00185   }
00186 }
00187 
00188 
00189 #include <QGridLayout>
00190 
00191 QxtLoggerWindow::QxtLoggerWindow
00192 (
00193   const QString & name,
00194   QWidget * parent,
00195   int x,
00196   int y,
00197   int w,
00198   int h
00199 )
00200 : QTextEdit( parent )
00201 {
00202   QFont font;
00203   font.setFamily( QString::fromUtf8("Courier New") );
00204   setFont(font);
00205 
00206 //  if( (x != -1) && (y != -1) && (w != -1) && (h != -1) )
00207 //  {
00208 //    move( x, y );
00209 //    resize( w, h );
00210 //    savePosition();
00211 //  }
00212 //  else
00213 //  {
00214 //    QSettings settings;
00215 //    QPoint pos = settings.value("QxtLoggerWindow/" + objectName() + "/pos", QPoint(10, 10)).toPoint();
00216 //    QSize size = settings.value("QxtLoggerWindow/" + objectName() + "/size", QSize(600, 600)).toSize();
00217 //    resize(size);
00218 //    move(pos);
00219 //  }
00220 }
00221 
00222 
00223 QxtLoggerWindow::~QxtLoggerWindow()
00224 {
00225 //  savePosition();
00226 }
00227 
00228 void QxtLoggerWindow::print( const QString & line )
00229 {
00230   moveCursor( QTextCursor::End );
00231   insertPlainText( line + "\r\n" );
00232 }
00233 
00234 void QxtLoggerWindow::oprint( const QString & line )
00235 {
00236   undo();
00237   print( line );
00238 }
00239 
00240 bool QxtLoggerWindow::save( const QString & filename )
00241 {
00242   QFile file(filename);
00243   if( !file.open( QFlags<QIODevice::OpenModeFlag>(QFile::WriteOnly | QFile::Truncate) ) )
00244     return(false);
00245 
00246   QTextStream ts(&file);
00247   ts.setCodec(QTextCodec::codecForName("UTF-8"));
00248   ts << document()-> toPlainText();
00249 
00250   return( true );
00251 
00252 }
00253 
00254 void QxtLoggerWindow::savePosition()
00255 {
00256 //  QSettings settings;
00257 //  settings.setValue("QxtLoggerWindow/" + objectName() + "/pos", pos());
00258 //  settings.setValue("QxtLoggerWindow/" + objectName() + "/size", size());
00259 }
 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