107 lines
3.5 KiB
C++
Executable File
107 lines
3.5 KiB
C++
Executable File
|
|
|
|
|
|
#include "nglmainwindow.h"
|
|
|
|
#include <ngltranslator/ngltranslator.h>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QtCore/QLibraryInfo>
|
|
#include <QtCore/QTextStream>
|
|
#include <QGuiApplication>
|
|
#include <QMenu>
|
|
#include <QMenuBar>
|
|
|
|
NGLMainWindow::NGLMainWindow(QWidget *parent)
|
|
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger())
|
|
, QMainWindow(parent)
|
|
, m_helpProcess(nullptr)
|
|
, m_versionView(nullptr)
|
|
, m_menuBar(new QMenuBar(this))
|
|
{
|
|
m_menu[QLatin1String("File")] = m_menuBar->addMenu(tr("File"));
|
|
m_fileActionBefore = m_menu[QLatin1String("File")]->addSeparator();
|
|
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), QKeySequence(tr("Ctrl+q")), this, &NGLMainWindow::onExit);
|
|
|
|
m_menu[QLatin1String("Help")] = m_menuBar->addMenu(tr("Help"));
|
|
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), QKeySequence(tr("F1")), this, &NGLMainWindow::onHelpIndex);
|
|
m_menu[QLatin1String("Help")]->addSeparator();
|
|
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-about.png")),
|
|
tr("About"), this, &NGLMainWindow::onHelpAbout);
|
|
|
|
setWindowIcon(QIcon(QLatin1String(":icons/16x16/rde_16x16.png")));
|
|
setMenuBar(m_menuBar);
|
|
}
|
|
|
|
void NGLMainWindow::onExit()
|
|
{
|
|
|
|
close();
|
|
}
|
|
|
|
void NGLMainWindow::onHelpIndex()
|
|
{
|
|
onInvokeHelp(QLatin1String("Index"));
|
|
}
|
|
|
|
void NGLMainWindow::onInvokeHelp(const QString &helpContext)
|
|
{
|
|
|
|
DEBUG_LOG(m_logger) << "onInvokeHelp " << helpContext ;
|
|
|
|
if (!m_helpProcess)
|
|
{
|
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
QString lang = QString::fromLatin1(NGL::translationLocale()) + QLatin1String(".UTF-8");
|
|
env.insert(QLatin1String("LANG"), lang);
|
|
m_helpProcess = new QProcess(this);
|
|
m_helpProcess->setProcessEnvironment(env);
|
|
QStringList args;
|
|
QString fn = QString::fromLatin1(NGL::translationLocale()) + QLatin1String(".qhc");
|
|
args << QLatin1String("-collectionFile")
|
|
<< QCoreApplication::applicationDirPath() + QLatin1String("/../help/scms/") + fn
|
|
<< QLatin1String("-enableRemoteControl");
|
|
DEBUG_LOG(m_logger) << "Attempting to invoke help at URL: " << args.join(QLatin1String(" ")) ;
|
|
m_helpProcess->start(QLibraryInfo::path(QLibraryInfo::BinariesPath) + QLatin1String("/assistant"), args);
|
|
if (!m_helpProcess->waitForStarted())
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not start help browser (error: "
|
|
<< m_helpProcess->error()
|
|
<< " )" ;
|
|
delete m_helpProcess;
|
|
m_helpProcess = nullptr;
|
|
return;
|
|
}
|
|
connect(m_helpProcess, QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished),
|
|
this, &NGLMainWindow::onHelpFinished);
|
|
}
|
|
QTextStream str(m_helpProcess);
|
|
|
|
str << QLatin1String("activateIdentifier ") + helpContext << QLatin1Char('\0') << QLatin1Char('\n');
|
|
str.flush();
|
|
}
|
|
|
|
void NGLMainWindow::onHelpFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
{
|
|
if (exitStatus != QProcess::NormalExit)
|
|
{
|
|
WARNING_LOG(m_logger) << "help browser exited with status "
|
|
<< exitStatus << " code "
|
|
<< exitCode << "!" ;
|
|
}
|
|
delete m_helpProcess;
|
|
m_helpProcess = nullptr;
|
|
}
|
|
|
|
void NGLMainWindow::onHelpAbout()
|
|
{
|
|
if (m_versionView)
|
|
m_versionView->show();
|
|
}
|
|
|
|
void NGLMainWindow::onVersionViewDeleted()
|
|
{
|
|
m_versionView = nullptr;
|
|
setVersionView();
|
|
}
|