[PATCH 2 of 2] (issue89) Add ui to open help in browser

Wald Commits scm-commit at wald.intevation.org
Fri Aug 22 19:56:09 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1408730164 -7200
# Node ID 7c89c5dc2200408f29c4ce1e5e9d5846577ccab2
# Parent  574cd1fae1dceb412a39b7b80c2a019893e7e0a4
(issue89) Add ui to open help in browser

diff -r 574cd1fae1dc -r 7c89c5dc2200 ui/mainwindow.cpp
--- a/ui/mainwindow.cpp	Fri Aug 22 19:55:08 2014 +0200
+++ b/ui/mainwindow.cpp	Fri Aug 22 19:56:04 2014 +0200
@@ -29,6 +29,7 @@
 #include <QButtonGroup>
 #include <QToolButton>
 #include <QStandardPaths>
+#include <QDesktopServices>
 
 #include "certificatelist.h"
 #include "downloader.h"
@@ -81,6 +82,14 @@
 # endif
 #endif
 
+/* Help installation path the path relative to the installation directory where
+ * the help is placed.*/
+#ifdef WIN32
+#define HELP_PATH "/doc/index.html"
+#else
+#define HELP_PATH "/../share/doc/trustbridge/index.html"
+#endif
+
 MainWindow::MainWindow(bool trayMode):
     mTrayMode(trayMode)
 {
@@ -514,6 +523,14 @@
     infoCenterLayout->insertSpacing(2, 10);
     infoCenterLayout->insertSpacing(4, 10);
     infoCenterLayout->insertSpacing(6, 10);
+
+    QHBoxLayout *helpButtonLayout = new QHBoxLayout();
+    QPushButton *helpButton = new QPushButton(tr("Show Help"));
+    connect(helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
+    helpButtonLayout->addWidget(helpButton);
+    helpButtonLayout->addStretch();
+    infoCenterLayout->addLayout(helpButtonLayout);
+
     infoCenterLayout->insertStretch(8, 10);
 
     infoPanelLayout->addLayout(infoHeaderLayout);
@@ -1375,3 +1392,23 @@
         emit changesChanged(QString("%1").arg(cnt));
     }
 }
+
+void MainWindow::showHelp()
+{
+    char *inst_dir = get_install_dir();
+    if (!inst_dir) {
+        qDebug() << "Failed to find install dir";
+        return;
+    }
+    QString helpPath = QString::fromUtf8(inst_dir);
+    helpPath += HELP_PATH;
+    QFileInfo fiHelp(helpPath);
+    qDebug() << "Opening help: " << fiHelp.absoluteFilePath();
+    if (!fiHelp.exists()) {
+        QMessageBox::warning(this, tr("Error!"), tr ("Failed to find the manual"));
+        return;
+    }
+    QDesktopServices::openUrl(QUrl(fiHelp.absoluteFilePath()));
+    free (inst_dir);
+    return;
+}
diff -r 574cd1fae1dc -r 7c89c5dc2200 ui/mainwindow.h
--- a/ui/mainwindow.h	Fri Aug 22 19:55:08 2014 +0200
+++ b/ui/mainwindow.h	Fri Aug 22 19:56:04 2014 +0200
@@ -146,6 +146,10 @@
      */
     void updateCheckSuccess();
 
+    /** @brief open the manual in an external browser window
+     */
+    void showHelp();
+
 protected:
     virtual void closeEvent(QCloseEvent *event);
 


More information about the Trustbridge-commits mailing list