From a2dd78131a9dfb2487a297fdfbf3e5b276151865 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Feb 2022 13:40:56 +0300 Subject: [PATCH] Fix broken documentation links --- src/LightApp/LightApp_Application.cxx | 166 ++++++++++++++------------ src/LightApp/resources/LightApp.xml | 14 +-- 2 files changed, 95 insertions(+), 85 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 88750b9f5..e687135f6 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -197,6 +197,10 @@ #include #define FIRST_HELP_ID 1000000 +#define HAS_WWW_URL true +#define HAS_FORUM_URL true +#define HAS_YOUTUBE_URL true +#define HAS_TUTORIAL_URL false #ifndef DISABLE_SALOMEOBJECT #include @@ -301,6 +305,24 @@ namespace result = QLocale( lang ).nativeLanguageName(); return result; } + + QString getHelpItem( const QString& section, const QString& parameter, const QString& root = QString() ) + { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + foreach( QString item, resMgr->stringValue( section, parameter ).split( ";;", QString::SkipEmptyParts ) ) + { + if ( item.startsWith( "http", Qt::CaseInsensitive ) ) + return item; + QString path = item; + path.remove( QRegExp( "#.*$" ) ); + QFileInfo fi( path ); + if ( fi.isRelative() && !root.isEmpty() ) + path = Qtx::addSlash( root ) + path; + if ( QFile::exists( path ) ) + return item; + } + return QString(); + } } /*!Create new instance of LightApp_Application.*/ @@ -601,54 +623,63 @@ void LightApp_Application::createActions() int id = LightApp_Application::UserID + FIRST_HELP_ID; + QString url; + // a) Link to web site - QString url = resMgr->stringValue("GUI", "site_url"); - if ( !url.isEmpty() ) { - QString title = tr ( "SALOME_SITE" ); - QAction* as = createAction( WebSiteId, title, - resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), - title, title, - 0, desk, false, this, SLOT( onHelpContentsModule() ) ); - as->setData( url ); - createMenu( as, helpMenu, -1, 0 ); + if ( HAS_WWW_URL ) { + url = resMgr->stringValue("GUI", "site_url"); + if ( !url.isEmpty() ) { + QString title = tr ( "SALOME_SITE" ); + QAction* as = createAction( WebSiteId, title, + resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), + title, title, + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + as->setData( url ); + createMenu( as, helpMenu, -1, 0 ); + } } // b) Link to Forum - url = resMgr->stringValue("GUI", "forum_url"); - if ( !url.isEmpty() ) { - QString title = tr ( "SALOME_FORUM" ); - QAction* af = createAction( ForumId, title, - resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), - title, title, - 0, desk, false, this, SLOT( onHelpContentsModule() ) ); - af->setData( url ); - createMenu( af, helpMenu, -1, 0 ); + if ( HAS_FORUM_URL ) { + url = resMgr->stringValue("GUI", "forum_url"); + if ( !url.isEmpty() ) { + QString title = tr ( "SALOME_FORUM" ); + QAction* af = createAction( ForumId, title, + resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), + title, title, + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + af->setData( url ); + createMenu( af, helpMenu, -1, 0 ); + } } // c) Link to YouTube channel - url = resMgr->stringValue("GUI", "channel_url"); - if ( !url.isEmpty() ) { - createMenu( separator(), helpMenu, -1, 0 ); - QString title = tr ( "SALOME_VIDEO_TUTORIALS" ); - QAction* av = createAction( VideosId, title, - resMgr->loadPixmap( "LightApp", tr( "ICON_LIFE_RIGN" ), false ), - title, tr( "PRP_SALOME_VIDEO_TUTORIALS" ), - 0, desk, false, this, SLOT( onHelpContentsModule() ) ); - av->setData( url ); - createMenu( av, helpMenu, -1, 0 ); + if ( HAS_YOUTUBE_URL ) { + url = resMgr->stringValue("GUI", "channel_url"); + if ( !url.isEmpty() ) { + createMenu( separator(), helpMenu, -1, 0 ); + QString title = tr ( "SALOME_VIDEO_TUTORIALS" ); + QAction* av = createAction( VideosId, title, + resMgr->loadPixmap( "LightApp", tr( "ICON_LIFE_RIGN" ), false ), + title, tr( "PRP_SALOME_VIDEO_TUTORIALS" ), + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + av->setData( url ); + createMenu( av, helpMenu, -1, 0 ); + } } // d) Link to Tutorials - - url = resMgr->stringValue("GUI", "tutorials_url"); - if ( !url.isEmpty() ) { - QString title = tr ( "SALOME_TUTORIALS" ); - QAction* as = createAction( TutorialsId, title, - resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), - title, tr( "PRP_SALOME_TUTORIALS" ), - 0, desk, false, this, SLOT( onHelpContentsModule() ) ); - as->setData( url ); - createMenu( as, helpMenu, -1, 0 ); + if ( HAS_TUTORIAL_URL ) { + url = resMgr->stringValue("GUI", "tutorials_url"); + if ( !url.isEmpty() ) { + QString title = tr ( "SALOME_TUTORIALS" ); + QAction* as = createAction( TutorialsId, title, + resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ), + title, tr( "PRP_SALOME_TUTORIALS" ), + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + as->setData( url ); + createMenu( as, helpMenu, -1, 0 ); + } } // e) Help for modules @@ -673,7 +704,7 @@ void LightApp_Application::createActions() QString modName = moduleName( aModule ); // module name if ( modName.isEmpty() ) modName = aModule; // for KERNEL and GUI QString rootDir = QString( "%1_ROOT_DIR" ).arg( modName ); // module root dir env variable - QString modDir = Qtx::getenv( rootDir.toUtf8().constData() ); // module root dir path + QString modDir = Qtx::getenv( rootDir.toUtf8().constData() ); // module root dir path QString docSection; if (resMgr->hasValue( modName, "documentation" ) ) docSection = resMgr->stringValue(modName, "documentation"); @@ -683,29 +714,11 @@ void LightApp_Application::createActions() helpSubMenu = resMgr->stringValue( docSection, "sub_menu", "" ); if ( helpSubMenu.contains( "%1" ) ) helpSubMenu = helpSubMenu.arg( aModule ); - QStringList listOfParam = resMgr->parameters( docSection ); - foreach( QString paramName, listOfParam ) { - QString valueStr = resMgr->stringValue( docSection, paramName ); - if ( !valueStr.isEmpty() ) { - QStringList valueItems = valueStr.split( ";;", QString::SkipEmptyParts ); - foreach( QString item, valueItems ) { - if ( item.startsWith( "http", Qt::CaseInsensitive ) ) { - QString key = paramName.contains( "%1" ) ? paramName.arg( aModule ) : paramName; - helpData.insert( key, item ); - break; - } - else { - QFileInfo fi( item ); - if ( fi.isRelative() && !modDir.isEmpty() ) - item = Qtx::addSlash( modDir ) + item; - if ( QFile::exists( item ) ) { - QString key = paramName.contains( "%1" ) ? paramName.arg( aModule ) : paramName; - helpData.insert( key, item ); - break; - } - } - } - } + foreach( QString paramName, resMgr->parameters( docSection ) ) { + QString key = paramName.contains( "%1" ) ? paramName.arg( aModule ) : paramName; + QString helpItem = getHelpItem( docSection, paramName ); + if ( !helpItem.isEmpty() ) + helpData.insert( key, helpItem ); } } @@ -756,20 +769,15 @@ void LightApp_Application::createActions() QStringList addHelpItems = resMgr->parameters( "add_help" ); foreach ( QString paramName, addHelpItems ) { - QString valueStr = resMgr->stringValue( "add_help", paramName ); - if ( !valueStr.isEmpty() ) { - QStringList valueItems = valueStr.split( ";;", QString::SkipEmptyParts ); - foreach( QString item, valueItems ) { - if ( item.startsWith( "http", Qt::CaseInsensitive ) || QFile::exists( item ) ) { - QPixmap helpIcon = item.startsWith( "http", Qt::CaseInsensitive ) ? - resMgr->loadPixmap( "STD", tr( "ICON_WWW" ), false ) : resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ); - QAction* a = createAction( id++, paramName, helpIcon, paramName, paramName, - 0, desk, false, this, SLOT( onHelpContentsModule() ) ); - a->setData( item ); - createMenu( a, helpMenu, -1, 10 ); - break; - } - } + QString helpItem = getHelpItem( "add_help", paramName ); + if ( !helpItem.isEmpty() ) + { + QPixmap helpIcon = helpItem.startsWith( "http", Qt::CaseInsensitive ) ? + resMgr->loadPixmap( "STD", tr( "ICON_WWW" ), false ) : resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ); + QAction* a = createAction( id++, paramName, helpIcon, paramName, paramName, + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + a->setData( helpItem ); + createMenu( a, helpMenu, -1, 10 ); } } @@ -4180,8 +4188,10 @@ void LightApp_Application::updateWindows() infoPanel()->addLabel( action( FileNewId )->statusTip(), grp ); infoPanel()->addAction( action( FileOpenId ), grp ); infoPanel()->addLabel( action( FileOpenId )->statusTip(), grp ); - infoPanel()->addAction( action( TutorialsId ), grp ); - infoPanel()->addLabel( action( TutorialsId )->statusTip(), grp ); + if ( HAS_TUTORIAL_URL ) { + infoPanel()->addAction( action( TutorialsId ), grp ); + infoPanel()->addLabel( action( TutorialsId )->statusTip(), grp ); + } infoPanel()->addAction( action( VideosId ), grp ); infoPanel()->addLabel( action( VideosId )->statusTip(), grp ); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index aec839256..4643e5859 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -220,20 +220,20 @@
- - - + + +
- - + +
- +
@@ -272,7 +272,7 @@
- +
-- 2.39.2