Move Help window into separate class

Start it on application start and keep it around
for context sensitive help.
This commit is contained in:
Christian Hohnstaedt 2021-04-08 12:58:37 +02:00
parent 7ace0db0d5
commit 4f706fb3de
9 changed files with 103 additions and 28 deletions

View File

@ -3,7 +3,7 @@
<comment></comment>
<exportmacro></exportmacro>
<class>Help</class>
<widget class="QDialog" name="Help" >
<widget class="QWidget" name="Help" >
<property name="geometry" >
<rect>
<x>0</x>

59
widgets/Help.cpp Normal file
View File

@ -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 <QDebug>
#include <QHelpEngine>
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<QString, QUrl> 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));
}

34
widgets/Help.h Normal file
View File

@ -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 <QDialog>
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

View File

@ -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();
}

View File

@ -22,6 +22,7 @@
#include "hashBox.h"
#include "OidResolver.h"
#include "OpenDb.h"
#include "Help.h"
#include <QApplication>
#include <QClipboard>
#include <QMenuBar>
@ -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()));

View File

@ -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);

View File

@ -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();

View File

@ -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))

View File

@ -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 \