changeset 2466:c5898fd4a4f5 draft

Merge pull request #1247 from Diapolo/Win_open_debug_logfile Windows: open debug.log file via Bitcoin-Qt
author Wladimir J. van der Laan <laanwj@gmail.com>
date Fri, 11 May 2012 02:22:17 -0700 (2012-05-11)
parents 619245c5666e (current diff) 9f78e190908a (diff)
children a7c09c66dd97 80849ad5a725 a9b012461972
files
diffstat 5 files changed, 81 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/qt/forms/rpcconsole.ui
+++ b/src/qt/forms/rpcconsole.ui
@@ -204,6 +204,42 @@
         </widget>
        </item>
        <item row="11" column="0">
+        <spacer name="verticalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item row="12" column="0">
+        <widget class="QLabel" name="labelDebugLogfile">
+         <property name="font">
+          <font>
+           <weight>75</weight>
+           <bold>true</bold>
+          </font>
+         </property>
+         <property name="text">
+          <string>Debug logfile</string>
+         </property>
+        </widget>
+       </item>
+       <item row="13" column="0">
+        <widget class="QPushButton" name="openDebugLogfileButton">
+         <property name="toolTip">
+          <string>Open the Bitcoin debug logfile from the current data directory. This can take a few seconds for large logfiles.</string>
+         </property>
+         <property name="text">
+          <string>&amp;Open</string>
+         </property>
+        </widget>
+       </item>
+       <item row="14" column="0">
         <spacer name="verticalSpacer">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -17,6 +17,24 @@
 #include <QDesktopServices>
 #include <QThread>
 
+#include <boost/filesystem.hpp>
+
+#ifdef WIN32
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0501
+#ifdef _WIN32_IE
+#undef _WIN32_IE
+#endif
+#define _WIN32_IE 0x0501
+#define WIN32_LEAN_AND_MEAN 1
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include "shlwapi.h"
+#endif
+
 namespace GUIUtil {
 
 QString dateTimeStr(const QDateTime &date)
@@ -214,6 +232,17 @@
            && checkPoint(QPoint(w->width()/2, w->height()/2), w));
 }
 
+void openDebugLogfile()
+{
+    boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
+
+#ifdef WIN32
+    if (boost::filesystem::exists(pathDebug))
+        /* Open debug.log with the associated application */
+        ShellExecuteA((HWND)0, (LPCSTR)"open", (LPCSTR)pathDebug.string().c_str(), NULL, NULL, SW_SHOWNORMAL);
+#endif
+}
+
 ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject *parent):
     size_threshold(size_threshold), QObject(parent)
 {
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -70,6 +70,9 @@
     // Determine whether a widget is hidden behind other windows
     bool isObscured(QWidget *w);
 
+    // Open debug.log
+    void openDebugLogfile();
+
     /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
       representation if needed. This assures that Qt can word-wrap long tooltip messages.
       Tooltips longer than the provided size threshold (in characters) are wrapped.
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -90,6 +90,12 @@
     ui->messagesWidget->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
     ui->messagesWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
 
+#ifndef WIN32
+    // Show Debug logfile label and Open button only for Windows
+    ui->labelDebugLogfile->setVisible(false);
+    ui->openDebugLogfileButton->setVisible(false);
+#endif
+
     // Install event filter for up and down arrow
     ui->lineEdit->installEventFilter(this);
 
@@ -101,6 +107,7 @@
     ui->messagesWidget->addAction(copyMessageAction);
 
     connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
+    connect(ui->openDebugLogfileButton, SIGNAL(clicked()), this, SLOT(on_openDebugLogfileButton_clicked()));
 
     startExecutor();
 
@@ -310,3 +317,8 @@
         ui->lineEdit->setFocus();
     }
 }
+
+void RPCConsole::on_openDebugLogfileButton_clicked()
+{
+    GUIUtil::openDebugLogfile();
+}
--- a/src/qt/rpcconsole.h
+++ b/src/qt/rpcconsole.h
@@ -32,8 +32,8 @@
 
 private slots:
     void on_lineEdit_returnPressed();
-
     void on_tabWidget_currentChanged(int index);
+    void on_openDebugLogfileButton_clicked();
 
 public slots:
     void clear();