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
22 // File : HelpBrowser.cxx
23 // Author : Vadim SANDLER, OpenCASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "qtsingleapplication.h"
29 #include <QLibraryInfo>
30 #include <QMessageBox>
31 #include <QTextStream>
33 #include <QtxResourceMgr.h>
34 #include <QtxTranslator.h>
35 #include <QtxWebBrowser.h>
43 QFileInfo fi( QtSingleApplication::arguments().at(0) );
45 std::cout << std::endl;
46 std::cout << "SALOME Help Browser" << std::endl;
47 std::cout << std::endl;
48 std::cout << "usage: " << qPrintable( fi.fileName() ) << " [options] file" << std::endl;
49 std::cout << " file is a help file to be opened" << std::endl;
50 std::cout << std::endl;
51 std::cout << "Options:" << std::endl;
52 std::cout << "-h, --help Prints this help and quits." << std::endl;
53 std::cout << "--language=LANG Use LANG language in menus." << std::endl;
54 std::cout << std::endl;
58 class RaiseWindowHelper: public QDialog
61 RaiseWindowHelper( QWidget* parent ) : QDialog( parent, Qt::FramelessWindowHint )
63 setAttribute( Qt::WA_DeleteOnClose, true );
66 QTimer::singleShot( 100, this, SLOT( close() ) );
67 QTimer::singleShot( 500, parent, SLOT( setFocus() ) );
71 class HelpBrowser: public QtxWebBrowser
74 HelpBrowser() : QtxWebBrowser()
76 Q_INIT_RESOURCE( Qtx );
78 setAttribute( Qt::WA_DeleteOnClose, false );
83 resourceMgr()->save();
88 QFile f( ":/COPYING" );
89 f.open( QIODevice::ReadOnly );
92 info << QtxWebBrowser::tr( "%1 has been developed using %2" ).arg( QString( "SALOME %1").arg( tr( "Help Browser" ) ) ).arg( "Qt Solutions Component: Single Application." );
94 info << in.readAll().split( "\n" );
96 QMessageBox::about( this, tr( "About %1" ).arg( tr( "Help Browser" ) ),
99 void load( const QString& url )
101 QtxWebBrowser::load( url );
102 RaiseWindowHelper* helper = new RaiseWindowHelper( this );
106 int main( int argc, char **argv )
108 // set application name (for preferences)
110 QtSingleApplication::setApplicationName( "salome" );
112 // create application instance
114 QtSingleApplication instance( argc, argv );
116 // parse command line arguments
118 bool showHelp = false;
122 QRegExp rl( "--language=(.+)" );
123 rl.setMinimal( false );
125 for ( int a = 1; a < argc; ++a ) {
126 QString param = argv[a];
127 if ( param == "--help" || param == "-h" )
129 else if ( rl.exactMatch( param ) )
130 language = rl.cap( 1 );
135 // show help and exit if --help or -h option has been specified via command line
142 if ( instance.sendMessage( helpfile ) )
147 QtxTranslator tqt, tsal;
148 if ( !language.isEmpty() ) {
149 if ( tqt.load( QString( "qt_%1" ).arg( language ), QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) )
150 instance.installTranslator( &tqt );
152 QDir appDir = QtSingleApplication::applicationDirPath();
153 appDir.cdUp(); appDir.cdUp();
155 if ( tsal.load( QString( "Qtx_msg_%1" ).arg( language ), appDir.filePath( "share/salome/resources/gui" ) ) )
156 instance.installTranslator( &tsal );
159 // initialize resource manager (for preferences)
161 QtxResourceMgr* resMgr = new QtxResourceMgr( "HelpBrowser", "%1Config" );
162 resMgr->setCurrentFormat( "xml" );
163 QtxWebBrowser::setResourceMgr( resMgr );
170 // load file specified via command line
172 if ( helpfile.isEmpty() ) {
173 QString docdir = qgetenv( "DOCUMENTATION_ROOT_DIR" );
174 if ( !docdir.isEmpty() )
175 helpfile = QDir::toNativeSeparators( QString( "%1/index.html" ).arg( docdir ) );
178 if ( !helpfile.isEmpty() ) {
179 browser.load( helpfile );
182 // finalize main window activation
184 instance.setActivationWindow( &browser );
186 QObject::connect( &instance, SIGNAL( messageReceived( QString ) ),
187 &browser, SLOT( load ( QString ) ) );
189 return instance.exec();