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 setAttribute( Qt::WA_DeleteOnClose, false );
81 resourceMgr()->save();
86 QFile f( ":/COPYING" );
87 f.open( QIODevice::ReadOnly );
90 info << QtxWebBrowser::tr( "%1 has been developed using %2" ).arg( QString( "SALOME %1").arg( tr( "Help Browser" ) ) ).arg( "Qt Solutions Component: Single Application." );
92 info << in.readAll().split( "\n" );
94 QMessageBox::about( this, tr( "About %1" ).arg( tr( "Help Browser" ) ),
97 void load( const QString& url )
99 QtxWebBrowser::load( url );
100 RaiseWindowHelper* helper = new RaiseWindowHelper( this );
104 int main( int argc, char **argv )
106 // set application name (for preferences)
108 QtSingleApplication::setApplicationName( "salome" );
110 // specify application identifier via its name
111 QFileInfo fi( argv[0] );
113 // create application instance
115 QtSingleApplication instance( fi.fileName(), argc, argv );
117 // parse command line arguments
119 bool showHelp = false;
123 QRegExp rl( "--language=(.+)" );
124 rl.setMinimal( false );
126 for ( int a = 1; a < argc; ++a ) {
127 QString param = argv[a];
128 if ( param == "--help" || param == "-h" )
130 else if ( rl.exactMatch( param ) )
131 language = rl.cap( 1 );
136 // show help and exit if --help or -h option has been specified via command line
143 if ( instance.sendMessage( helpfile ) )
148 QtxTranslator tqt, tsal;
149 if ( !language.isEmpty() ) {
150 if ( tqt.load( QString( "qt_%1" ).arg( language ), QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) )
151 instance.installTranslator( &tqt );
153 QDir appDir = QtSingleApplication::applicationDirPath();
154 appDir.cdUp(); appDir.cdUp();
156 if ( tsal.load( QString( "Qtx_msg_%1" ).arg( language ), appDir.filePath( "share/salome/resources/gui" ) ) )
157 instance.installTranslator( &tsal );
160 // initialize resource manager (for preferences)
162 QtxResourceMgr* resMgr = new QtxResourceMgr( "HelpBrowser", "%1Config" );
163 resMgr->setCurrentFormat( "xml" );
164 QtxWebBrowser::setResourceMgr( resMgr );
171 // load file specified via command line
173 if ( helpfile.isEmpty() ) {
174 QString docdir = qgetenv( "DOCUMENTATION_ROOT_DIR" );
175 if ( !docdir.isEmpty() )
176 helpfile = QDir::toNativeSeparators( QString( "%1/index.html" ).arg( docdir ) );
179 if ( !helpfile.isEmpty() ) {
180 browser.load( helpfile );
183 // finalize main window activation
185 instance.setActivationWindow( &browser );
187 QObject::connect( &instance, SIGNAL( messageReceived( QString ) ),
188 &browser, SLOT( load ( QString ) ) );
190 return instance.exec();