/***************************************************************************
                                 kstdebug.h
                             -------------------
    begin                : Mar 07 2004
    copyright            : (C) 2004 The University of Toronto
    email                :
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KSTDEBUG_H
#define KSTDEBUG_H

#include <qdatetime.h>
#include <qobject.h>
#include <qmutex.h>

#include <kstaticdeleter.h>

class KstDebug : public QObject {
  Q_OBJECT
  friend class KStaticDeleter<KstDebug>;
  public:
    enum LogLevel { Notice = 0, Warning, Error, Debug, None = 9999 };
    struct LogMessage {
      QDateTime	date;
      QString 	msg;
      LogLevel 	level;
    };
    static KstDebug* self();

    void clear();
    void log(const QString& msg, LogLevel level = Notice);
    void setLimit(bool applyLimit, int limit);   
    QString text();
    void sendEmail();
    
    const QValueList<LogMessage>& messages() const { return _messages; }
    QStringList dataSourcePlugins() const;
    QString label(LogLevel level) const;

  signals: 
    void logAdded();

  private:
    KstDebug();
    ~KstDebug();
    
    static KstDebug *_self;
    QValueList<LogMessage> _messages;
    bool  _applyLimit;
    int 	_limit;
    QMutex _lock;
};


#endif

// vim: ts=2 sw=2 et
