#include "fe_log.h" #if (FE_LOG_VERSION) #include #include #include #include #include #include #include #include #include #include #include #include #include QVector FELogHandler::buffer = QVector(); void FELogHandler::messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString ds = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz "); buffer.append(ds + msg); emit FELogHandler::instance()->appended(msg); //printDebug(__FUNCTION__ + msg); //OutputDebugString(reinterpret_cast(msg.utf16())); // QByteArray localMsg = msg.toLocal8Bit(); // switch (type) { // case QtDebugMsg: // fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); // break; // case QtInfoMsg: // fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); // break; // case QtWarningMsg: // fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); // break; // case QtCriticalMsg: // fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); // break; // case QtFatalMsg: // fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); // abort(); // } // fflush(stderr); } void FELogHandler::printDebug(QString msg) { OutputDebugString(reinterpret_cast(msg.utf16())); } void FELogDialog::onButton() { QPushButton* btn = qobject_cast(sender()); QString cmd = btn->text().toUpper(); if(cmd == "SAVE") { QString savePath = QFileDialog::getSaveFileName(0, "LOG SAVE FILE", NULL, "Log files (*.log)",0,QFileDialog::DontConfirmOverwrite); if(!savePath.isEmpty()) { QFile file(savePath); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << _text->toPlainText() << endl; } } } } QPushButton* FELogDialog::button(QWidget* parent,QLayout* layout,QString title) { QPushButton* btn = new QPushButton(parent); btn->setText(title); //btn->setStyleSheet("font-family: Arial;font-size: 9px;"); btn->setStyleSheet("QPushButton{font-family: Fixedsys;color : white;}" "QPushButton[enabled=\"false\"]{color : #AAAAAA;}"); btn->setFixedWidth(title.length() * 10); layout->addWidget(btn); connect(btn,SIGNAL(clicked()),SLOT(onButton())); return btn; } FELogDialog::FELogDialog(QWidget *parent,Qt::WindowFlags f) : QDialog(parent,f) { setWindowTitle("LOG."); //setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint); setWindowModality(Qt::NonModal); // 시작시 표시 및 처리되지 않도록 시작 #if !(TOGGLE_PLAYER) setAttribute(Qt::WA_DontShowOnScreen,true); setAttribute(Qt::WA_ShowWithoutActivating,true); #endif resize(640,480); _layout = new QVBoxLayout(this); _layout->setAlignment(Qt::AlignTop | Qt::AlignLeft); _layout->setMargin(0); _layout->setSpacing(0); _toolbar = new QWidget(this); _toolbar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); _toolbar->setFixedHeight(36); _layout->addWidget(_toolbar); _toolbar->setStyleSheet("background-color: #818181;"); //_toolbar->setObjectName("test_widget"); QHBoxLayout* toolLayout = new QHBoxLayout(_toolbar); toolLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); toolLayout->setSpacing(6); toolLayout->setMargin(2); QPushButton* btn; btn = button(_toolbar,toolLayout,"SAVE"); // _openButton = button(_toolbar,toolLayout,"OPEN"); // _reloadButton = button(_toolbar,toolLayout,"RELOAD"); // _stopButton = button(_toolbar,toolLayout,"STOP"); // _stopButton->setEnabled(false); // btn = button(_toolbar,toolLayout,"CLEAR"); // btn = button(_toolbar,toolLayout,"DIR"); _text = new QPlainTextEdit(this); _text->setReadOnly(true); _text->setStyleSheet("font-family: Fixedsys;color : #00FF00;background-color: #111111;border:1px;border-style:solid;border-color:#313131;"); _text->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); _layout->addWidget(_text); _addSystemInfo(); } FELogDialog* FELogDialog::instance(QWidget* parent) { static FELogDialog * _instance = NULL; if ( _instance == NULL ) { _instance = new FELogDialog(parent); } return _instance; } void FELogDialog::showEvent( QShowEvent* event ) { QDialog::showEvent(event); //qInfo() << __FUNCTION__; setUpdatesEnabled(false); _text->clear(); QVectorIterator iter(FELogHandler::buffer); while (iter.hasNext()) { _text->insertPlainText(iter.next() + "\n"); } connect(FELogHandler::instance(),SIGNAL(appended(QString)),SLOT(onAppended(QString)),Qt::UniqueConnection); //QMetaObject::invokeMethod(this, "afterWindowShown", Qt::ConnectionType::QueuedConnection); setUpdatesEnabled(true); } void FELogDialog::onAppended(QString msg) { QString ds = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz "); //FELogHandler::printDebug(__FUNCTION__ + msg); _text->insertPlainText(ds + msg + "\n"); _text->verticalScrollBar()->setValue(_text->verticalScrollBar()->maximum()); } void FELogDialog::onClose() { disconnect(FELogHandler::instance(),SIGNAL(appended(QString)),this,SLOT(onAppended(QString))); //qInfo() << __FUNCTION__; //_hideOnFullScreen = false; setHidden(true); close(); //RMApp::instance()->pMainWindow->setFocus(); } bool FELogDialog::isHiddenReal() { if(testAttribute(Qt::WA_DontShowOnScreen)) { setAttribute(Qt::WA_DontShowOnScreen,false); setAttribute(Qt::WA_ShowWithoutActivating,false); setHidden(true); return true; } return isHidden(); } void FELogDialog::_addSystemInfo() { FELogHandler::buffer.append("---------------------------------------------"); FELogHandler::buffer.append("SYSTEM INFO."); FELogHandler::buffer.append("OS:" + QSysInfo::prettyProductName() + " (" + QSysInfo::currentCpuArchitecture() + ")"); FELogHandler::buffer.append("KERNEL:" + QSysInfo::kernelType() + " VER " + QSysInfo::kernelVersion()); QSettings settings("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS", QSettings::NativeFormat); FELogHandler::buffer.append("Manufacturer:" + settings.value("SystemManufacturer", "0").toString()); FELogHandler::buffer.append("Product:" + settings.value("SystemProductName", "0").toString()); QProcess process_system; QString system_output; QString cpuname = "wmic cpu get name"; process_system.start(cpuname); process_system.waitForFinished(); system_output = process_system.readAllStandardOutput().toUpper(); while(system_output.contains(" ")) { system_output = system_output.replace(" "," "); } FELogHandler::buffer.append("CPU:" + system_output.replace("\n","").replace("\r","")); QString gpuname = "wmic PATH Win32_videocontroller get VideoProcessor "; process_system.start(gpuname); process_system.waitForFinished(); system_output = process_system.readAllStandardOutput(); while(system_output.contains(" ")) { system_output = system_output.replace(" "," "); } FELogHandler::buffer.append("GPU:" + system_output.replace("\n","").replace("\r","")); FELogHandler::buffer.append("---------------------------------------------"); } #endif // #if (FE_LOG_VERSION)