Browse Source

refine VNote's log file in release mode

1. Add menu item "View Log" to view log file;
2. Add Captain mode shortcut "Ctrl+E ," to flush the log file;
Le Tan 8 years ago
parent
commit
85c09c296d
3 changed files with 35 additions and 1 deletions
  1. 4 1
      src/main.cpp
  2. 13 0
      src/vcaptain.cpp
  3. 18 0
      src/vmainwindow.cpp

+ 4 - 1
src/main.cpp

@@ -11,7 +11,10 @@
 #include "vconfigmanager.h"
 
 VConfigManager vconfig;
-static QFile g_logFile;
+
+#if defined(QT_NO_DEBUG)
+QFile g_logFile;
+#endif
 
 void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
 {

+ 13 - 0
src/vcaptain.cpp

@@ -13,6 +13,10 @@
 // 3s pending time after the leader keys.
 const int c_pendingTime = 3 * 1000;
 
+#if defined(QT_NO_DEBUG)
+extern QFile g_logFile;
+#endif
+
 VCaptain::VCaptain(VMainWindow *p_parent)
     : QWidget(p_parent), m_mainWindow(p_parent), m_mode(VCaptain::Normal),
       m_widgetBeforeCaptain(NULL), m_nextMajorKey('a'), m_ignoreFocusChange(false)
@@ -303,6 +307,15 @@ bool VCaptain::handleKeyPress(int p_key, Qt::KeyboardModifiers p_modifiers)
         break;
     }
 
+#if defined(QT_NO_DEBUG)
+    case Qt::Key_Comma:
+    {
+        // Flush g_logFile.
+        g_logFile.flush();
+        break;
+    }
+#endif
+
     default:
         // Not implemented yet. Just exit Captain mode.
         break;

+ 18 - 0
src/vmainwindow.cpp

@@ -25,6 +25,10 @@ extern VConfigManager vconfig;
 
 VNote *g_vnote;
 
+#if defined(QT_NO_DEBUG)
+extern QFile g_logFile;
+#endif
+
 VMainWindow::VMainWindow(QWidget *parent)
     : QMainWindow(parent), m_onePanel(false)
 {
@@ -288,6 +292,16 @@ void VMainWindow::initHelpMenu()
     QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
     helpMenu->setToolTipsVisible(true);
 
+#if defined(QT_NO_DEBUG)
+    QAction *logAct = new QAction(tr("View &Log"), this);
+    logAct->setToolTip(tr("View VNote's debug log (%1)").arg(vconfig.getLogFilePath()));
+    connect(logAct, &QAction::triggered,
+            this, [](){
+                QUrl url = QUrl::fromLocalFile(vconfig.getLogFilePath());
+                QDesktopServices::openUrl(url);
+            });
+#endif
+
     QAction *shortcutAct = new QAction(tr("&Shortcuts Help"), this);
     shortcutAct->setToolTip(tr("View information about shortcut keys"));
     connect(shortcutAct, &QAction::triggered,
@@ -303,6 +317,10 @@ void VMainWindow::initHelpMenu()
     connect(aboutQtAct, &QAction::triggered,
             qApp, &QApplication::aboutQt);
 
+#if defined(QT_NO_DEBUG)
+    helpMenu->addAction(logAct);
+#endif
+
     helpMenu->addAction(shortcutAct);
     helpMenu->addAction(aboutQtAct);
     helpMenu->addAction(aboutAct);