1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include <stdio.h>
#include "errorLog.h"
#include "guiclient.h"
#include <QObject>
#include <QVariant>
#include <QMessageBox>
#include <QStringList>
#include <QDateTime>
#include <QSqlError>
#include "xtsettings.h"
static QStringList _errorList;
static errorLogListener * listener = 0;
void errorLogListener::initialize()
{
listener = new errorLogListener();
}
void errorLogListener::destroy()
{
if(listener)
delete listener;
listener = 0;
}
errorLog::errorLog(QWidget* parent, const char * name, Qt::WindowFlags flags)
: XWidget(parent, name, flags)
{
setupUi(this);
for(int i = 0; i < _errorList.size(); i++)
_errorLog->append(_errorList.at(i));
_debug->setChecked(xtsettingsValue("catchQDebug").toBool());
_warning->setChecked(xtsettingsValue("catchQWarning").toBool());
_critical->setChecked(xtsettingsValue("catchQCritical").toBool());
_fatal->setChecked(xtsettingsValue("catchQFatal").toBool());
connect(_clear, SIGNAL(clicked()), _errorLog, SLOT(clear()));
connect(_clear, SIGNAL(clicked()), listener, SLOT(clear()));
connect(_clear, SIGNAL(clicked()), omfgThis, SLOT(sClearErrorMessages()));
connect(listener, SIGNAL(updated(const QString &)), this, SLOT(updateErrors(const QString &)));
connect(_debug, SIGNAL(toggled(bool)), this, SLOT(toggleDebug(bool)));
connect(_warning, SIGNAL(toggled(bool)), this, SLOT(toggleWarning(bool)));
connect(_critical,SIGNAL(toggled(bool)), this, SLOT(toggleCritical(bool)));
connect(_fatal, SIGNAL(toggled(bool)), this, SLOT(toggleFatal(bool)));
}
errorLog::~errorLog()
{
// no need to delete child widgets, Qt does it all for us
}
void errorLog::languageChange()
{
retranslateUi(this);
}
void errorLog::updateErrors(const QString & msg)
{
_errorLog->append(msg);
}
void errorLog::toggleDebug(bool y)
{
xtsettingsSetValue("catchQDebug", y);
}
void errorLog::toggleWarning(bool y)
{
xtsettingsSetValue("catchQWarning", y);
}
void errorLog::toggleCritical(bool y)
{
xtsettingsSetValue("catchQCritical", y);
}
void errorLog::toggleFatal(bool y)
{
xtsettingsSetValue("catchQFatal", y);
}
errorLogListener::errorLogListener(QObject * parent)
: QObject(parent)
{
XSqlQuery::addErrorListener(this);
}
errorLogListener::~errorLogListener()
{
XSqlQuery::removeErrorListener(this);
}
void errorLogListener::error(const QString & sql, const QSqlError & error)
{
QString msg;
msg = QDateTime::currentDateTime().toString();
msg += " " + error.text();
msg += "\n" + sql;
_errorList.append(msg);
if(_errorList.size() > 20)
_errorList.removeFirst();
emit updated(msg);
if(omfgThis)
omfgThis->sNewErrorMessage();
}
void errorLogListener::clear()
{
bool blocked = blockSignals(true);
_errorList.clear();
(void)blockSignals(blocked);
}
#if QT_VERSION >= 0x050000
void xTupleMessageOutput(QtMsgType type, const QMessageLogContext&, const QString &pMsg)
#else
void xTupleMessageOutput(QtMsgType type, const char *pMsg)
#endif
{
QString msg;
msg = QDateTime::currentDateTime().toString();
bool notify = false;
bool iserror= (type == QtCriticalMsg) || (type == QtFatalMsg);
switch (type) {
case QtDebugMsg:
notify = xtsettingsValue("catchQDebug").toBool();
msg += " Debug: ";
break;
case QtWarningMsg:
notify = xtsettingsValue("catchQWarning").toBool();
msg += " Warning: ";
break;
case QtCriticalMsg:
notify = xtsettingsValue("catchQCritical").toBool();
msg += " Critical: ";
break;
case QtFatalMsg:
notify = xtsettingsValue("catchQFatal").toBool();
msg += " Fatal: ";
//abort();
break;
}
msg += pMsg;
_errorList.append(msg);
if(_errorList.size() > 20)
_errorList.removeFirst();
if(listener && notify)
listener->updated(msg);
if(omfgThis && notify && iserror)
omfgThis->sNewErrorMessage();
printf("%s\n", qPrintable(msg));
}
|