Revert HelpPages.cpp

This commit is contained in:
Andy Vandijck 2024-02-24 15:35:39 +01:00
parent 864f8897b5
commit 407426421f
1 changed files with 178 additions and 178 deletions

View File

@ -108,25 +108,25 @@ void consoleWin_t::OpenHelpWindow(std::string subpage)
#if defined(_UNICODE) || defined(UNICODE)
helpWin = HtmlHelp(HWND(winId()), wHelpFileName.data(), HH_DISPLAY_TOPIC, (DWORD)NULL);
#else
helpWin = HtmlHelp(HWND(winId()), helpFileName.c_str(), HH_DISPLAY_TOPIC, (DWORD)NULL);
helpWin = HtmlHelp(HWND(winId()), helpFileName.c_str(), HH_DISPLAY_TOPIC, (DWORD)NULL);
#endif
if ( helpWin == NULL )
{
printf("Error: Failed to open help file '%s'\n", helpFileName.c_str() );
}
if ( helpWin == NULL )
{
printf("Error: Failed to open help file '%s'\n", helpFileName.c_str() );
}
#else
if ( (long)helpWin > 0 )
{
printf("There is already a CHM Viewer open somewhere...\n");
return;
}
//helpWin = forkHelpFileViewer( helpFileViewer.c_str(), helpFileName.c_str() );
if ( (long)helpWin > 0 )
{
printf("There is already a CHM Viewer open somewhere...\n");
return;
}
//helpWin = forkHelpFileViewer( helpFileViewer.c_str(), helpFileName.c_str() );
#ifdef _USE_QHELP
HelpDialog *win = new HelpDialog( helpFileName.c_str(), this);
#ifdef _USE_QHELP
HelpDialog *win = new HelpDialog( helpFileName.c_str(), this);
win->show();
#endif
win->show();
#endif
#endif
}
@ -134,112 +134,112 @@ void consoleWin_t::OpenHelpWindow(std::string subpage)
//void consoleWin_t::helpPageMaint(void)
//{
//#ifdef WIN32
// // Does any help page cleanup need to be done in windows?
// // Does any help page cleanup need to be done in windows?
//#else
// if ( helpWin > 0 )
// { // Calling waitpid is important to ensure that CHM viewer process is cleaned up
// // in the event that it exits. Otherwise zombie processes will be left.
// int pid, wstat=0;
// if ( helpWin > 0 )
// { // Calling waitpid is important to ensure that CHM viewer process is cleaned up
// // in the event that it exits. Otherwise zombie processes will be left.
// int pid, wstat=0;
//
// pid = waitpid( -1, &wstat, WNOHANG );
// pid = waitpid( -1, &wstat, WNOHANG );
//
// if ( pid == helpWin )
// {
// //printf("Help CHM Viewer Closed\n");
// helpWin = 0;
// }
// }
// if ( pid == helpWin )
// {
// //printf("Help CHM Viewer Closed\n");
// helpWin = 0;
// }
// }
//
//#endif
//}
std::string consoleWin_t::findHelpFile(void)
{
int ret, useNativeFileDialogVal;
QString filename;
std::string last;
std::string dir;
QFileDialog dialog(this, tr("Open Help File") );
QList<QUrl> urls;
//QDir d;
int ret, useNativeFileDialogVal;
QString filename;
std::string last;
std::string dir;
QFileDialog dialog(this, tr("Open Help File") );
QList<QUrl> urls;
//QDir d;
urls << QUrl::fromLocalFile( QDir::rootPath() );
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first());
urls << QUrl::fromLocalFile( QDir( FCEUI_GetBaseDirectory() ).absolutePath() );
urls << QUrl::fromLocalFile( QDir::rootPath() );
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first());
urls << QUrl::fromLocalFile( QDir( FCEUI_GetBaseDirectory() ).absolutePath() );
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setFileMode(QFileDialog::ExistingFile);
#ifdef WIN32
dialog.setNameFilter(tr("Compiled HTML Files (*.chm *.CHM) ;; All files (*)"));
dialog.setNameFilter(tr("Compiled HTML Files (*.chm *.CHM) ;; All files (*)"));
#else
dialog.setNameFilter(tr("QHelp Files (*.qhc *.QHC) ;; All files (*)"));
dialog.setNameFilter(tr("QHelp Files (*.qhc *.QHC) ;; All files (*)"));
#endif
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::AllDirs | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Open") );
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::AllDirs | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Open") );
g_config->getOption ("SDL.HelpFilePath", &last );
g_config->getOption ("SDL.HelpFilePath", &last );
if ( last.size() > 0 )
{
getDirFromFile( last.c_str(), dir );
if ( last.size() > 0 )
{
getDirFromFile( last.c_str(), dir );
dialog.setDirectory( tr(dir.c_str()) );
}
else
{
dialog.setDirectory( QDir( FCEUI_GetBaseDirectory() ).absolutePath() );
}
dialog.setDirectory( tr(dir.c_str()) );
}
else
{
dialog.setDirectory( QDir( FCEUI_GetBaseDirectory() ).absolutePath() );
}
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
dialog.setSidebarUrls(urls);
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
dialog.setSidebarUrls(urls);
ret = dialog.exec();
ret = dialog.exec();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
if ( filename.isNull() )
{
return last;
}
//qDebug() << "selected file path : " << filename.toLocal8Bit();
if ( filename.isNull() )
{
return last;
}
//qDebug() << "selected file path : " << filename.toLocal8Bit();
g_config->setOption ("SDL.HelpFilePath", filename.toLocal8Bit().constData() );
g_config->setOption ("SDL.HelpFilePath", filename.toLocal8Bit().constData() );
return filename.toLocal8Bit().constData();
return filename.toLocal8Bit().constData();
}
//#if defined(__linux__) || defined(__unix__) || defined(__APPLE__)
//static int forkHelpFileViewer( const char *chmViewer, const char *filepath )
//{
// int pid = 0;
// int pid = 0;
//
// if ( chmViewer[0] == 0 )
// {
// return -1;
// }
// if ( chmViewer[0] == 0 )
// {
// return -1;
// }
//
// pid = fork();
// pid = fork();
//
// if ( pid == 0 )
// { // Child process
// execl( chmViewer, chmViewer, filepath, NULL );
// exit(0);
// }
// return pid;
// if ( pid == 0 )
// { // Child process
// execl( chmViewer, chmViewer, filepath, NULL );
// exit(0);
// }
// return pid;
//}
//#endif
@ -248,146 +248,146 @@ std::string consoleWin_t::findHelpFile(void)
//--- Help Page Dialog
//-----------------------------------------------------------------------------------------------
HelpDialog::HelpDialog( const char *helpFileName, QWidget *parent)
: QDialog(parent, Qt::Window)
: QDialog(parent, Qt::Window)
{
int useNativeMenuBar;
QMenu *fileMenu;
QMenuBar *menuBar;
QToolBar *toolBar;
QAction *act;
QVBoxLayout *mainLayoutv;
QSettings settings;
int useNativeMenuBar;
QMenu *fileMenu;
QMenuBar *menuBar;
QToolBar *toolBar;
QAction *act;
QVBoxLayout *mainLayoutv;
QSettings settings;
mainLayoutv = new QVBoxLayout();
mainLayoutv = new QVBoxLayout();
setLayout( mainLayoutv );
setLayout( mainLayoutv );
toolBar = new QToolBar(this);
menuBar = new QMenuBar(this);
mainLayoutv->setMenuBar( menuBar );
toolBar = new QToolBar(this);
menuBar = new QMenuBar(this);
mainLayoutv->setMenuBar( menuBar );
// This is needed for menu bar to show up on MacOS
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
// This is needed for menu bar to show up on MacOS
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
menuBar->setNativeMenuBar( useNativeMenuBar ? true : false );
menuBar->setNativeMenuBar( useNativeMenuBar ? true : false );
helpEngine = new QHelpEngine( helpFileName, this );
helpEngine->setupData();
helpEngine = new QHelpEngine( helpFileName, this );
helpEngine->setupData();
hsplitter = new QSplitter( Qt::Horizontal );
tabWgt = new QTabWidget();
textViewer = new HelpBrowser( helpEngine );
hsplitter = new QSplitter( Qt::Horizontal );
tabWgt = new QTabWidget();
textViewer = new HelpBrowser( helpEngine );
textViewer->setSource(
textViewer->setSource(
QUrl("qthelp://TasVideos.fceux/doc/help/fceux.html"));
//-----------------------------------------------------------------------
// Menu Start
//-----------------------------------------------------------------------
// File
fileMenu = menuBar->addMenu(tr("&File"));
//-----------------------------------------------------------------------
// Menu Start
//-----------------------------------------------------------------------
// File
fileMenu = menuBar->addMenu(tr("&File"));
// File -> Close
act = new QAction(tr("&Close"), this);
act->setShortcut(QKeySequence::Close);
act->setStatusTip(tr("Close Window"));
connect(act, SIGNAL(triggered()), this, SLOT(closeWindow(void)) );
// File -> Close
act = new QAction(tr("&Close"), this);
act->setShortcut(QKeySequence::Close);
act->setStatusTip(tr("Close Window"));
connect(act, SIGNAL(triggered()), this, SLOT(closeWindow(void)) );
fileMenu->addAction(act);
fileMenu->addAction(act);
//-----------------------------------------------------------------------
// Menu End
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Tool Bar Setup Start
//-----------------------------------------------------------------------
backButton = act = new QAction(tr("&Backward"), this);
act->setShortcut( QKeySequence(tr("Alt+Left") ));
act->setToolTip(tr("Navigate Backward"));
act->setIcon( style()->standardIcon(QStyle::SP_ArrowBack) );
connect(act, SIGNAL(triggered(void)), textViewer, SLOT(backward(void)) );
//-----------------------------------------------------------------------
// Menu End
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Tool Bar Setup Start
//-----------------------------------------------------------------------
backButton = act = new QAction(tr("&Backward"), this);
act->setShortcut( QKeySequence(tr("Alt+Left") ));
act->setToolTip(tr("Navigate Backward"));
act->setIcon( style()->standardIcon(QStyle::SP_ArrowBack) );
connect(act, SIGNAL(triggered(void)), textViewer, SLOT(backward(void)) );
toolBar->addAction(act);
toolBar->addAction(act);
forwardButton = act = new QAction(tr("&Forward"), this);
act->setShortcut( QKeySequence(tr("Alt+Right") ));
act->setToolTip(tr("Navigate Forward"));
act->setIcon( style()->standardIcon(QStyle::SP_ArrowForward) );
connect(act, SIGNAL(triggered(void)), textViewer, SLOT(forward(void)) );
forwardButton = act = new QAction(tr("&Forward"), this);
act->setShortcut( QKeySequence(tr("Alt+Right") ));
act->setToolTip(tr("Navigate Forward"));
act->setIcon( style()->standardIcon(QStyle::SP_ArrowForward) );
connect(act, SIGNAL(triggered(void)), textViewer, SLOT(forward(void)) );
toolBar->addAction(act);
toolBar->addAction(act);
//-----------------------------------------------------------------------
// Tool Bar Setup End
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// Tool Bar Setup End
//-----------------------------------------------------------------------
backButton->setEnabled(false);
forwardButton->setEnabled(false);
backButton->setEnabled(false);
forwardButton->setEnabled(false);
tabWgt->addTab( helpEngine->contentWidget(), tr("Contents") );
tabWgt->addTab( helpEngine->indexWidget() , tr("Index") );
tabWgt->addTab( helpEngine->contentWidget(), tr("Contents") );
tabWgt->addTab( helpEngine->indexWidget() , tr("Index") );
hsplitter->addWidget( tabWgt );
hsplitter->addWidget( textViewer );
hsplitter->addWidget( tabWgt );
hsplitter->addWidget( textViewer );
mainLayoutv->addWidget( toolBar );
mainLayoutv->addWidget( hsplitter );
mainLayoutv->addWidget( toolBar );
mainLayoutv->addWidget( hsplitter );
connect(helpEngine->contentWidget(),
SIGNAL(linkActivated(QUrl)),
textViewer, SLOT(setSource(QUrl)));
connect(helpEngine->contentWidget(),
SIGNAL(linkActivated(QUrl)),
textViewer, SLOT(setSource(QUrl)));
connect(helpEngine->indexWidget(),
SIGNAL(linkActivated(QUrl, QString)),
textViewer, SLOT(setSource(QUrl)));
connect(helpEngine->indexWidget(),
SIGNAL(linkActivated(QUrl, QString)),
textViewer, SLOT(setSource(QUrl)));
connect( textViewer, SIGNAL(backwardAvailable(bool)), this, SLOT(navBackwardAvailable(bool)) );
connect( textViewer, SIGNAL(forwardAvailable(bool)) , this, SLOT(navForwardAvailable(bool)) );
// Restore Window Geometry
restoreGeometry(settings.value("HelpPage/geometry").toByteArray());
connect( textViewer, SIGNAL(backwardAvailable(bool)), this, SLOT(navBackwardAvailable(bool)) );
connect( textViewer, SIGNAL(forwardAvailable(bool)) , this, SLOT(navForwardAvailable(bool)) );
// Restore Window Geometry
restoreGeometry(settings.value("HelpPage/geometry").toByteArray());
// Restore Horizontal Panel State
hsplitter->restoreState( settings.value("HelpPage/hPanelState").toByteArray() );
// Restore Horizontal Panel State
hsplitter->restoreState( settings.value("HelpPage/hPanelState").toByteArray() );
}
//-----------------------------------------------------------------------------------------------
HelpDialog::~HelpDialog(void)
{
QSettings settings;
QSettings settings;
// Save Horizontal Panel State
settings.setValue("HelpPage/hPanelState", hsplitter->saveState());
// Save Horizontal Panel State
settings.setValue("HelpPage/hPanelState", hsplitter->saveState());
// Save Window Geometry
settings.setValue("HelpPage/geometry", saveGeometry());
// Save Window Geometry
settings.setValue("HelpPage/geometry", saveGeometry());
}
//-----------------------------------------------------------------------------------------------
void HelpDialog::closeEvent(QCloseEvent *event)
{
//printf("Help Dialog Close Window Event\n");
done(0);
deleteLater();
event->accept();
//printf("Help Dialog Close Window Event\n");
done(0);
deleteLater();
event->accept();
}
//-----------------------------------------------------------------------------------------------
void HelpDialog::closeWindow(void)
{
//printf("Close Window\n");
done(0);
deleteLater();
//printf("Close Window\n");
done(0);
deleteLater();
}
//-----------------------------------------------------------------------------------------------
void HelpDialog::navBackwardAvailable(bool avail)
{
backButton->setEnabled( avail );
backButton->setEnabled( avail );
}
//-----------------------------------------------------------------------------------------------
void HelpDialog::navForwardAvailable(bool avail)
{
forwardButton->setEnabled( avail );
forwardButton->setEnabled( avail );
}
//-----------------------------------------------------------------------------------------------
//---- Help Browser Class