diff --git a/ui/Help.ui b/ui/Help.ui index a02fb66f..ae446cf6 100644 --- a/ui/Help.ui +++ b/ui/Help.ui @@ -3,7 +3,7 @@ Help - + 0 diff --git a/widgets/Help.cpp b/widgets/Help.cpp new file mode 100644 index 00000000..674a5098 --- /dev/null +++ b/widgets/Help.cpp @@ -0,0 +1,59 @@ +/* vi: set sw=4 ts=4: + * + * Copyright (C) 2001 - 2012 Christian Hohnstaedt. + * + * All rights reserved. + */ + +#include "Help.h" +#include "lib/func.h" + +#include +#include + +Help::Help() : QWidget(NULL) +{ + setupUi(this); + setWindowTitle(XCA_TITLE); + textbox->setSearchPaths(QStringList(getDocDir())); + + helpengine = new QHelpEngineCore(getDocDir() + "/xca.qhc"); +} + +Help::~Help() +{ + delete helpengine; +} + +void Help::display(const QUrl &url) +{ + qDebug() << "URL:" << url.toString() << "Fragment:" << url.fragment(); + textbox->setHtml(QString::fromUtf8( helpengine->fileData(url))); + textbox->scrollToAnchor(url.fragment()); + show(); +} + +void Help::content() +{ + display(QUrl("qthelp://org.sphinx.xca/doc/index.html")); +} + +void Help::contexthelp(const QString &context) +{ + QMap helpctx(helpengine->linksForIdentifier(context)); + + if (helpctx.count()) + display(helpctx.constBegin().value()); +} + +void Help::contexthelp() +{ + QObject *o = sender(); + if (!o) + return; + QString ctx = o->property("help_ctx").toString(); + if (ctx.isEmpty()) + return; + qDebug() << "help_ctx" << ctx; + contexthelp(QString("%1.%1").arg(ctx)); +} diff --git a/widgets/Help.h b/widgets/Help.h new file mode 100644 index 00000000..e8682c00 --- /dev/null +++ b/widgets/Help.h @@ -0,0 +1,34 @@ +/* vi: set sw=4 ts=4: + * + * Copyright (C) 2021 Christian Hohnstaedt. + * + * All rights reserved. + */ + +#ifndef __HELP_H +#define __HELP_H + +#include "ui_Help.h" + +#include + +class QHelpEngineCore; + +class Help: public QWidget, public Ui::Help +{ + Q_OBJECT + + QHelpEngineCore *helpengine; + void display(const QUrl &url); + + public: + Help(); + ~Help(); + + public slots: + void contexthelp(); + void contexthelp(const QString &context); + void content(); + +}; +#endif diff --git a/widgets/MW_help.cpp b/widgets/MW_help.cpp index d3446614..3e4d64ab 100644 --- a/widgets/MW_help.cpp +++ b/widgets/MW_help.cpp @@ -140,27 +140,3 @@ void MainWindow::about() about->exec(); delete about; } - -void MainWindow::help() -{ - QDialog *h = new QDialog(this); - QString path, uri; - Ui::Help ui; - ui.setupUi(h); - - path = QString("file://"); -#if defined(Q_OS_WIN32) - path += "/"; -#endif - path += getDocDir() + "/"; -#if defined(Q_OS_WIN32) - path = path.replace("\\","/"); -#endif - uri = path + "xca.html"; - - ui.textbox->setSource(QUrl(uri)); - ui.textbox->setSearchPaths(QStringList(path)); - h->setWindowTitle(XCA_TITLE); - h->show(); -} - diff --git a/widgets/MW_menu.cpp b/widgets/MW_menu.cpp index 2f72434d..70f1b267 100644 --- a/widgets/MW_menu.cpp +++ b/widgets/MW_menu.cpp @@ -22,6 +22,7 @@ #include "hashBox.h" #include "OidResolver.h" #include "OpenDb.h" +#include "Help.h" #include #include #include @@ -167,7 +168,7 @@ void MainWindow::init_menu() extra->addAction(tr("OID Resolver"), resolver, SLOT(show())); help = menuBar()->addMenu(tr("&Help") ); - help->addAction(tr("Content"), this, SLOT(help()), + help->addAction(tr("Content"), helpdlg, SLOT(content()), QKeySequence::HelpContents); a = new QAction(tr("About"), this); connect(a, SIGNAL(triggered()), this, SLOT(about())); diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index 10942a13..30acba97 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -89,6 +89,7 @@ MainWindow::MainWindow() : QMainWindow() } historyMenu = NULL; + helpdlg = new Help(); init_menu(); setItemEnabled(false); @@ -418,6 +419,7 @@ MainWindow::~MainWindow() EVP_cleanup(); OBJ_cleanup(); delete dbindex; + delete helpdlg; #ifdef MDEBUG fprintf(stderr, "Memdebug:\n"); CRYPTO_mem_leaks_fp(stderr); diff --git a/widgets/MainWindow.h b/widgets/MainWindow.h index fd0c4280..54524201 100644 --- a/widgets/MainWindow.h +++ b/widgets/MainWindow.h @@ -9,6 +9,7 @@ #define __MAINWINDOW_H #include "ui_MainWindow.h" +#include "Help.h" #include "lib/oid.h" #include "lib/Passwd.h" @@ -85,6 +86,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow public: int exitApp; QLabel *dbindex; + Help *helpdlg; MainWindow(); virtual ~MainWindow(); void loadSettings(); @@ -114,7 +116,6 @@ class MainWindow: public QMainWindow, public Ui::MainWindow void dump_database(); void default_database(); void about(); - void help(); void loadPem(); bool pastePem(QString text, bool silent=false); void pastePem(); diff --git a/widgets/Makefile b/widgets/Makefile index e95f5729..39ec57b0 100644 --- a/widgets/Makefile +++ b/widgets/Makefile @@ -9,7 +9,7 @@ MOC_NAMES=MainWindow KeyDetail clicklabel XcaTreeView NewX509 \ ImportMulti CrlDetail ExportDialog hashBox Options NewKey kvView \ NewCrl SearchPkcs11 RevocationList XcaProxyModel XcaHeaderView \ KeyTreeView TempTreeView ReqTreeView X509SuperTreeView CertTreeView \ - OidResolver OpenDb XcaWarning CrlTreeView XcaApplication + OidResolver OpenDb XcaWarning CrlTreeView XcaApplication Help NAMES=$(MOC_NAMES) NewX509_ext MW_menu MW_help OBJS=$(patsubst %,moc_%.o,$(MOC_NAMES)) $(patsubst %,%.o,$(NAMES)) diff --git a/xca.pro b/xca.pro index 982e4dd4..9c0fd3b3 100644 --- a/xca.pro +++ b/xca.pro @@ -118,6 +118,7 @@ HEADERS += lib/asn1int.h \ widgets/XcaProxyModel.h \ widgets/XcaApplication.h \ widgets/XcaWarning.h \ + widgets/Help.h \ widgets/OpenDb.h FORMS += ui/CaProperties.ui \ @@ -223,6 +224,7 @@ SOURCES += lib/asn1int.cpp \ widgets/XcaProxyModel.cpp \ widgets/XcaApplication.cpp \ widgets/XcaWarning.cpp \ + widgets/Help.cpp \ widgets/OpenDb.cpp TRANSLATIONS += lang/xca.ts \