• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmobiletools

errorhandler.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    Copyright (C) 2007 by Matthias Lechner <matthias@lmme.de>
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the
00016    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "errorhandler.h"
00021 #include "errorlog.h"
00022 
00023 #include <KMessageBox>
00024 #include <KPassivePopup>
00025 #include <KGlobal>
00026 #include <QMutex>
00027 
00028 namespace KMobileTools {
00029 
00030 class ErrorHandlerInstance {
00031 public:
00032     ErrorHandler m_uniqueInstance;
00033 };
00034 
00035 class ErrorHandlerPrivate {
00036 public:
00037     QMutex m_mutex;
00038     QStack<const BaseError*> m_errorStack;
00039 
00040     ~ErrorHandlerPrivate() {
00041         qDeleteAll( m_errorStack.begin(), m_errorStack.end() );
00042     }
00043 };
00044 
00045 K_GLOBAL_STATIC(ErrorHandlerInstance, errorHandlerInstance)
00046 
00047 ErrorHandler::ErrorHandler()
00048 : QObject( 0 ), d( new ErrorHandlerPrivate )
00049 {
00050 }
00051 
00052 
00053 ErrorHandler::~ErrorHandler()
00054 {
00055 }
00056 
00057 ErrorHandler* ErrorHandler::instance() {
00058     // instance is automatically created
00059     return &errorHandlerInstance->m_uniqueInstance;
00060 }
00061 
00062 void ErrorHandler::addError( const BaseError* error ) {
00064     d->m_mutex.lock();
00065 
00066     // don't add the same error twice in a row
00067     if( !d->m_errorStack.isEmpty() ) {
00068         if( *(d->m_errorStack.top()) != *error )
00069             d->m_errorStack.push( error );
00070     } else
00071         d->m_errorStack.push( error );
00072 
00073     displayError( error );
00074     writeToLog( error );
00075 
00076     d->m_mutex.unlock();
00077 }
00078 
00079 int ErrorHandler::errorCount() const {
00080     return d->m_errorStack.count();
00081 }
00082 
00083 QStack<const BaseError*> ErrorHandler::errorStack() {
00084     return d->m_errorStack;
00085 }
00086 
00087 void ErrorHandler::displayError( const BaseError* error ) {
00088     if( receivers( SIGNAL(errorOccurred(QString,BaseError::Priority)) ) > 0 )
00089         emit errorOccurred( error->description(), error->priority() );
00090     else
00091         KMessageBox::error( 0, error->description() );
00092 }
00093 
00094 void ErrorHandler::writeToLog( const BaseError* error ) {
00095     ErrorLog* errorLog = ErrorLog::instance();
00096 
00097     errorLog->write( QString( "===============================" ) );
00098     errorLog->write( QString( "Occurred on %1").arg( error->dateTime().toString( Qt::ISODate ) ) );
00099     errorLog->write( QString( "Location:    %1:%2" ).arg( error->fileName() )
00100                                                     .arg( QString::number( error->lineNumber() ) ) );
00101     errorLog->write( QString( "Method:      %1()" ).arg( error->methodName() ) );
00102     errorLog->write( QString( "Priority:    %1" ).arg( error->priority() ) );
00103     errorLog->write( QString( "Description: %1" ).arg( error->description() ) );
00104 }
00105 
00106 }
00107 
00108 #include "errorhandler.moc"

kmobiletools

Skip menu "kmobiletools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal