#include "resource/ui_strings.h"
#include "displaybase.h"
+#include "util/new_debug_ch.h"
+// XXX: all modules in ui/* are controlled by channel name "qt5_ui"
+DECLARE_DEBUG_CHANNEL(qt5_ui);
+
extern "C" {
#include "emul_state.h"
#include "emulator_options.h"
}
//using namespace std;
-void qMessageOutput(QtMsgType, const QMessageLogContext &, const QString &);
-void loadMainFormFromXML(QString, UiInformation *);
-void loadConFormFromXML(QFile *, UiInformation *);
-
bool qt5IsOnscreen;
QApplication *qt5App = NULL;
}
#endif
+static void loadMainFormFromXML(QString xmlPath, UiInformation *uiInfo/* out */)
+{
+ QFile file(xmlPath);
+
+ if (file.exists() == false ||
+ file.open(QIODevice::ReadOnly | QIODevice::Text) == false) {
+ qFatal("Failed to load the emulator skin. %s%s", MSG_CHECK_PATH,
+ qPrintable(xmlPath));
+ return;
+ }
+
+ qDebug("main form is loaded from %s", qPrintable(file.fileName()));
+
+ /* read xml */
+ QXmlStreamReader xml(&file);
+
+ /* parse xml */
+ QFileInfo fileInfo(xmlPath);
+ XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo);
+ QString version = parser.parseEmulatorUI(xml);
+ qDebug() << "* main layout version:" << version;
+
+ const bool hasError = xml.hasError();
+ xml.clear();
+ file.close();
+
+ if (hasError == true) {
+ qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH,
+ qPrintable(xmlPath));
+ return;
+ }
+}
+
+static void loadConFormFromXML(QFile *file, UiInformation *uiInfo/* out */)
+{
+ if (file->exists() == false ||
+ file->open(QIODevice::ReadOnly | QIODevice::Text) == false) {
+ qWarning() << "Failed to load the controller skin:" <<
+ file->fileName();
+ return;
+ }
+
+ qDebug("controller form is loaded from %s", qPrintable(file->fileName()));
+
+ /* read xml */
+ QXmlStreamReader xml(file);
+
+ /* parse xml */
+ QFileInfo fileInfo(*file);
+ XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo);
+ QString version = parser.parseControllerUI(xml);
+ qDebug() << "* con layout version:" << version;
+
+ const bool hasError = xml.hasError();
+ xml.clear();
+ file->close();
+
+ if (hasError == true) {
+ qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH,
+ qPrintable(fileInfo.absoluteFilePath()));
+ return;
+ }
+}
+
+static void qMessageOutput(QtMsgType type, const QMessageLogContext &context,
+ const QString &msg)
+{
+ char typeChar = '\0';
+
+ switch (type) {
+ case QtDebugMsg:
+ if (!IS_TRACE_ON) {
+ // if TRACE if off, we have nothing to do.
+ return;
+ }
+ typeChar = 'T';
+ break;
+ case QtInfoMsg:
+ typeChar = 'I';
+ break;
+ case QtWarningMsg:
+ typeChar = 'W';
+ break;
+ case QtCriticalMsg:
+ case QtFatalMsg:
+ typeChar = 'S';
+ default:
+ qFatal("invalid message type");
+ break;
+ }
+
+ QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
+ QString path = QFileInfo(context.file).completeBaseName();
+ path.truncate(10);
+
+ // XXX: it is hard to use DEBUGCH for c++ modules, so we are printing
+ // logs now.
+ QTextStream out(stdout);
+ out.setFieldAlignment(QTextStream::AlignRight);
+ out << qSetFieldWidth(12) << timestamp;
+ out << qSetFieldWidth(1) << "|";
+ out << qSetFieldWidth(5) << qemu_get_thread_id();
+ out << qSetFieldWidth(1) << "|";
+ out << qSetFieldWidth(1) << typeChar;
+ out << qSetFieldWidth(1) << "|";
+ out << qSetFieldWidth(10) << path;
+ out << qSetFieldWidth(1) << "|";
+ out << qSetFieldWidth(4) << context.line;
+ out << qSetFieldWidth(1) << "|";
+ out << qSetFieldWidth(0) << msg;
+ out << qSetFieldWidth(0) << endl;
+
+ if (type == QtCriticalMsg || type == QtFatalMsg) {
+ QMessageBox::critical(0, EMULATOR_TITLE,
+ QString(MSG_INTERNAL_ERR) + msg +
+ MSG_EMULATOR_EXIT);
+
+ abort();
+ }
+}
+
const char *qt5_get_version(void)
{
return qVersion();
{
QCoreApplication::setApplicationName(EMULATOR_TITLE);
- qDebug() << "* Qt version (compile time):" << QT_VERSION_STR;
- qDebug() << "* Qt version (runtime):" << qVersion();
- qDebug() << "* working path:" << QDir::currentPath();
- qDebug() << "* binary path:" << QCoreApplication::applicationDirPath();
+ qInfo() << "* Qt version (compile time):" << QT_VERSION_STR;
+ qInfo() << "* Qt version (runtime):" << qVersion();
+ qInfo() << "* working path:" << QDir::currentPath();
+ qInfo() << "* binary path:" << QCoreApplication::applicationDirPath();
uiInfo = new UiInformation();
mainwindow->processCaptured(captured, pixels, width, height);
}
}
-
-void qMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
-{
- QByteArray localMsg = msg.toLocal8Bit();
- QByteArray dateMsg = QDateTime::currentDateTime().toString("hh:mm:ss.zzz").toLocal8Bit();
-
- QString path = context.file;
- QByteArray fname = NULL;
- int posFname = path.lastIndexOf('/') + 1;
- int posDot = path.lastIndexOf('.');
-
- if (( posFname != 0 ) && ( posDot != -1)) {
- int fnameLen = path.length() - posFname;
- path = path.right(fnameLen);
- fnameLen = posDot - posFname;
- path.truncate(fnameLen);
- }
- fname = path.toLocal8Bit();
-
- switch (type) {
- case QtDebugMsg:
- fprintf(stdout, "%s|%5d|I|%10.10s|%4u|%s\n", dateMsg.constData(),
- qemu_get_thread_id(), fname.trimmed().constData(), context.line,
- localMsg.trimmed().constData());
- break;
- case QtWarningMsg:
- fprintf(stdout, "%s|%5d|W|%10.10s|%4u|%s\n", dateMsg.constData(),
- qemu_get_thread_id(), fname.trimmed().constData(), context.line,
- localMsg.trimmed().constData());
- break;
- case QtCriticalMsg:
- fprintf(stderr, "%s|%5d|S|%10.10s|%4u|%s\n", dateMsg.constData(),
- qemu_get_thread_id(), fname.trimmed().constData(), context.line,
- localMsg.trimmed().constData());
- break;
- case QtFatalMsg:
- fprintf(stderr, "%s|%5d|S|%10.10s|%4u|%s\n", dateMsg.constData(),
- qemu_get_thread_id(), fname.trimmed().constData(), context.line,
- localMsg.trimmed().constData());
- {
- QString err;
- QMessageBox::critical(0, EMULATOR_TITLE,
- QString(MSG_INTERNAL_ERR) +
- err.sprintf("%s", (localMsg.trimmed()).constData()) +
- MSG_EMULATOR_EXIT);
- }
-
- abort();
- default:
- qFatal("invalid message type");
- break;
- }
-}
-
-void loadMainFormFromXML(QString xmlPath, UiInformation *uiInfo/* out */)
-{
- QFile file(xmlPath);
-
- if (file.exists() == false ||
- file.open(QIODevice::ReadOnly | QIODevice::Text) == false) {
- qFatal("Failed to load the emulator skin. %s%s", MSG_CHECK_PATH,
- qPrintable(xmlPath));
- return;
- }
-
- qDebug("main form is loaded from %s", qPrintable(file.fileName()));
-
- /* read xml */
- QXmlStreamReader xml(&file);
-
- /* parse xml */
- QFileInfo fileInfo(xmlPath);
- XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo);
- QString version = parser.parseEmulatorUI(xml);
- qDebug() << "* main layout version:" << version;
-
- const bool hasError = xml.hasError();
- xml.clear();
- file.close();
-
- if (hasError == true) {
- qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH,
- qPrintable(xmlPath));
- return;
- }
-}
-
-void loadConFormFromXML(QFile *file, UiInformation *uiInfo/* out */)
-{
- if (file->exists() == false ||
- file->open(QIODevice::ReadOnly | QIODevice::Text) == false) {
- qWarning() << "Failed to load the controller skin:" <<
- file->fileName();
- return;
- }
-
- qDebug("controller form is loaded from %s", qPrintable(file->fileName()));
-
- /* read xml */
- QXmlStreamReader xml(file);
-
- /* parse xml */
- QFileInfo fileInfo(*file);
- XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo);
- QString version = parser.parseControllerUI(xml);
- qDebug() << "* con layout version:" << version;
-
- const bool hasError = xml.hasError();
- xml.clear();
- file->close();
-
- if (hasError == true) {
- qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH,
- qPrintable(fileInfo.absoluteFilePath()));
- return;
- }
-}