Browse Source

Show log messages

Kandrashin Denis 13 years ago
parent
commit
c6cc294f30
6 changed files with 92 additions and 22 deletions
  1. 30 3
      source/fb2app.cpp
  2. 20 0
      source/fb2app.h
  3. 2 1
      source/fb2edit.pro
  4. 34 18
      source/fb2main.cpp
  5. 4 0
      source/fb2main.h
  6. 2 0
      source/fb2read.cpp

+ 30 - 3
source/fb2app.cpp

@@ -1,20 +1,47 @@
 #include <QApplication>
 #include <QErrorMessage>
 
+#include "fb2app.h"
 #include "fb2main.h"
 
+void Fb2Application::handleMessage(QtMsgType type, const char *msg)
+{
+    /*
+    switch (type) {
+    case QtDebugMsg:
+        fprintf(stderr, "Debug: %s\n", msg);
+        break;
+    case QtWarningMsg:
+        fprintf(stderr, "Warning: %s\n", msg);
+        break;
+    case QtCriticalMsg:
+        fprintf(stderr, "Critical: %s\n", msg);
+        break;
+    case QtFatalMsg:
+        fprintf(stderr, "Fatal: %s\n", msg);
+        abort();
+    }
+    */
+    emit logMessage(msg);
+}
+
+static void fb2MessageHandler(QtMsgType type, const char *msg)
+{
+    ((Fb2Application*)qApp)->handleMessage(type, msg);
+}
+
 int main(int argc, char *argv[])
 {
     Q_INIT_RESOURCE(fb2edit);
 
-    QApplication app(argc, argv);
+    Fb2Application app(argc, argv);
     app.setApplicationName("fb2edit");
     app.setOrganizationName("LinTest");
 
-    QErrorMessage::qtHandler();
-
     MainWindow * mainWin = new MainWindow;
     mainWin->show();
 
+    qInstallMsgHandler(fb2MessageHandler);
+
     return app.exec();
 }

+ 20 - 0
source/fb2app.h

@@ -0,0 +1,20 @@
+#ifndef FB2APP_H
+#define FB2APP_H
+
+#include <QtGui>
+
+class Fb2Application : public QApplication
+{
+    Q_OBJECT
+
+public:
+    Fb2Application(int &argc, char **argv, int = QT_VERSION)
+        : QApplication(argc, argv, QT_VERSION) {}
+
+    void handleMessage(QtMsgType type, const char *msg);
+
+signals:
+    void logMessage(const QString &message);
+};
+
+#endif // FB2APP_H

+ 2 - 1
source/fb2edit.pro

@@ -1,7 +1,8 @@
 HEADERS = \
     fb2main.h \
     fb2read.h \
-    fb2doc.h
+    fb2doc.h \
+    fb2app.h
 
 SOURCES = \
     fb2app.cpp \

+ 34 - 18
source/fb2main.cpp

@@ -30,6 +30,40 @@ MainWindow::MainWindow(const QString &filename, Fb2MainDocument * document)
     setCurrentFile(filename, document);
 }
 
+void MainWindow::init()
+{
+    connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
+
+    setAttribute(Qt::WA_DeleteOnClose);
+
+    isUntitled = true;
+
+    createActions();
+    createStatusBar();
+
+    textEdit = NULL;
+    noteEdit = NULL;
+    qsciEdit = NULL;
+    messageEdit = NULL;
+
+    readSettings();
+
+    setUnifiedTitleAndToolBarOnMac(true);
+}
+
+void MainWindow::logMessage(const QString &message)
+{
+    if (!messageEdit) {
+        messageEdit = new QTextEdit(this);
+        QDockWidget * dock = new QDockWidget(tr("Message log"), this);
+        dock->setAttribute(Qt::WA_DeleteOnClose);
+        dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
+        dock->setWidget(messageEdit);
+        addDockWidget(Qt::BottomDockWidgetArea, dock);
+    }
+    messageEdit->append(message);
+}
+
 bool MainWindow::loadXML(const QString &filename)
 {
     if (!filename.isEmpty()) {
@@ -142,24 +176,6 @@ void MainWindow::documentWasModified()
     setWindowModified(true);
 }
 
-void MainWindow::init()
-{
-    setAttribute(Qt::WA_DeleteOnClose);
-
-    isUntitled = true;
-
-    createActions();
-    createStatusBar();
-
-    textEdit = NULL;
-    noteEdit = NULL;
-    qsciEdit = NULL;
-
-    readSettings();
-
-    setUnifiedTitleAndToolBarOnMac(true);
-}
-
 QIcon MainWindow::icon(const QString &name)
 {
     QString file = QString(":/images/%1.png").arg(name);

+ 4 - 0
source/fb2main.h

@@ -27,6 +27,9 @@ public:
 protected:
     void closeEvent(QCloseEvent *event);
 
+public slots:
+    void logMessage(const QString &message);
+
 private slots:
     void fileNew();
     void fileOpen();
@@ -69,6 +72,7 @@ private:
 
     QTextEdit *textEdit;
     QTextEdit *noteEdit;
+    QTextEdit *messageEdit;
     QsciScintilla *qsciEdit;
     QString curFile;
     bool isUntitled;

+ 2 - 0
source/fb2read.cpp

@@ -498,6 +498,8 @@ bool Fb2Handler::startElement(const QString & namespaceURI, const QString & loca
     const QString name = qName.toLower();
     if (m_handler) return m_handler->doStart(name, attributes);
 
+    qCritical() << name;
+
     if (name == "fictionbook") {
         m_handler = new RootHandler(m_document, name);
         return true;