|
Quantum GIS API Documentation
master-693a1fe
|
00001 /*************************************************************************** 00002 qgscontexthelp.cpp 00003 Display context help for a dialog 00004 ------------------- 00005 begin : 2005-06-19 00006 copyright : (C) 2005 by Gary E.Sherman 00007 email : sherman at mrcc.com 00008 ***************************************************************************/ 00009 00010 /*************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 00016 * * 00017 ***************************************************************************/ 00018 00019 #include <QString> 00020 #include <QProcess> 00021 #include <QTcpSocket> 00022 #include <QTextStream> 00023 00024 #include "qgscontexthelp.h" 00025 #include "qgsapplication.h" 00026 #include "qgslogger.h" 00027 00028 00029 QgsContextHelp *QgsContextHelp::gContextHelp = 0; // Singleton instance 00030 00031 void QgsContextHelp::run( QString context ) 00032 { 00033 if ( !gContextHelp ) 00034 { 00035 // Create singleton instance if it does not exist 00036 gContextHelp = new QgsContextHelp(); 00037 } 00038 00039 gContextHelp->showContext( context ); 00040 } 00041 00042 QgsContextHelp::QgsContextHelp() 00043 { 00044 mProcess = start(); 00045 } 00046 00047 QgsContextHelp::~QgsContextHelp() 00048 { 00049 delete mProcess; 00050 } 00051 00052 QProcess *QgsContextHelp::start() 00053 { 00054 // Get the path to the help viewer 00055 QString helpPath = QgsApplication::helpAppPath(); 00056 QgsDebugMsg( QString( "Help path is %1" ).arg( helpPath ) ); 00057 00058 QProcess *process = new QProcess; 00059 process->start( helpPath ); 00060 00061 // Delete this object if the process terminates 00062 connect( process, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( processExited() ) ); 00063 00064 // Delete the process if the application quits 00065 connect( qApp, SIGNAL( aboutToQuit() ), process, SLOT( terminate() ) ); 00066 00067 return process; 00068 } 00069 00070 void QgsContextHelp::showContext( QString context ) 00071 { 00072 init(); 00073 00074 QString helpContents = gContextHelpTexts.value( context, 00075 tr( "<h3>Oops! QGIS can't find help for this form.</h3>" 00076 "The help file for %1 was not found for your language<br>" 00077 "If you would like to create it, contact the QGIS development team" 00078 ).arg( context ) ); 00079 00080 QString myStyle = QgsApplication::reportStyleSheet(); 00081 helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>\nEOH\n"; 00082 00083 mProcess->write( helpContents.toUtf8() ); 00084 } 00085 00086 void QgsContextHelp::processExited() 00087 { 00088 // Delete this object if the process terminates 00089 delete gContextHelp; 00090 gContextHelp = NULL; 00091 }