1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <HYDROGUI_RunBrowser.h>
27 #include <QApplication>
30 #include <LightApp_Application.h>
32 #include <QtxWebBrowser.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
37 #include <SALOME_Event.h>
39 HYDROGUI_RunBrowser::HYDROGUI_RunBrowser( LightApp_Application* app,
40 const QString& theApp,
41 const QString& theParams,
42 const QString& theHelpFile,
43 const QString& theContext )
45 myParams( theParams ),
46 myContext( theContext ),
50 //For the external browser always specify 'file://' protocol,
51 //because some WEB browsers (for example Mozilla Firefox) can't open local file without protocol.
52 myHelpFile = QString("file://%1").arg( QFileInfo( theHelpFile ).canonicalFilePath() );
55 void HYDROGUI_RunBrowser::run()
57 if ( !myApp.isEmpty() && !myHelpFile.isEmpty()) {
58 QString aCommand = QString( "%1 %2 \"%3%4\"" ).arg( myApp, myParams, myHelpFile, myContext.isEmpty() ? QString("") : QString( "#%1" ).arg( myContext ) );
60 QProcess* proc = new QProcess();
62 //proc->start( aCommand );
63 if ( true || !proc->waitForStarted() ) {
64 SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 );
65 QString* msg = new QString( QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).arg( myApp, myHelpFile ) );
66 ce2000->setData( msg );
67 QApplication::postEvent( myLApp, ce2000 );
72 void HYDROGUI_RunBrowser::showPage( LightApp_Application* theApp,
73 const QString& thePage )
75 SUIT_ResourceMgr* resMgr = theApp->resourceMgr();
78 platform = "winapplication";
80 platform = "application";
82 QString anApp = resMgr->stringValue( "ExternalBrowser", platform );
84 QString quote( "\"" );
85 anApp.prepend( quote );
86 anApp.append( quote );
88 QString aParams = resMgr->stringValue( "ExternalBrowser", "parameters" );
89 bool useExtBrowser = resMgr->booleanValue( "ExternalBrowser", "use_external_browser", false );
92 if ( !anApp.isEmpty() ) {
93 HYDROGUI_RunBrowser* rs = new HYDROGUI_RunBrowser( theApp, anApp, aParams, thePage );
97 SUIT_MessageBox::warning(theApp->desktop(), tr( "WRN_WARNING" ), tr( "WRN_DEFINE_EXTERNAL_BROWSER" ));
101 // On Win32 platform QWebKit of the Qt 4.6.3 hang up in case 'file://' protocol
102 // is defined. On Linux platform QWebKit doesn't work correctly without 'file://' protocol.
103 QtxWebBrowser::loadUrl( thePage );
105 QtxWebBrowser::loadUrl( QString( "file://%1" ).arg( helpFile ) );
110 QString HYDROGUI_RunBrowser::getPagePath( const QString& theModuleName )
114 QString rootDir = QString( "%1_ROOT_DIR" ).arg( theModuleName ); // module root dir variable
115 QString modDir = getenv( rootDir.toLatin1().constData() ); // module root dir
116 if ( !modDir.isEmpty() ) {
117 QStringList idxLst = QStringList() << modDir << "share" << "doc" << "salome"
118 << "gui" << theModuleName;
119 QString indexFile = idxLst.join( QDir::separator() ); // index file
120 if ( QFile::exists( indexFile ) )
121 aPagePath = indexFile;