UltraScan III
us_helpdaemon.cpp
Go to the documentation of this file.
1 #include <QtSingleApplication>
3 
4 #include "us_helpdaemon.h"
5 #include "us_settings.h"
6 
7 US_HelpDaemon::US_HelpDaemon( const QString& page, QObject* o ) : QObject( o )
8 {
9  QString location = US_Settings::appBaseDir() + "/bin/manual.qhc";
10  QString url = "qthelp://ultrascaniii/";
11  if ( !page.contains( "manual/" ) )
12  url.append( "manual/" );
13  url.append( page );
14 
15  QStringList args;
16 
17  args << QLatin1String( "-collectionFile" )
18  << location
19  << QLatin1String( "-enableRemoteControl" )
20  << QLatin1String( "-showURL" )
21  << url;
22 
23  debug( args.join( " " ) );
24 #ifndef Q_WS_MAC
25  daemon.start( QLatin1String( "assistant" ), args );
26 #else
27  QString assisloc = US_Settings::appBaseDir() + "/Developer/Applications/Qt/Assistant.app";
28  daemon.start( assisloc, args );
29 #endif
30  daemon.waitForStarted();
31 
32  connect( &daemon, SIGNAL( finished ( int, QProcess::ExitStatus ) ),
33  SLOT ( close ( int, QProcess::ExitStatus ) ) );
34 }
35 
36 void US_HelpDaemon::close( int /*exitCode*/, QProcess::ExitStatus /*status*/ )
37 {
38  exit( 0 );
39 }
40 
41 void US_HelpDaemon::show( const QString& helpPage )
42 {
43  if ( helpPage == "Quit" )
44  {
45  daemon.close();
46  exit( 0 );
47  }
48 
49  if ( daemon.state() == QProcess::NotRunning )
50  {
51  debug( "assistant not running" );
52  }
53 
54  QString page = helpPage;
55  if ( ! helpPage.contains( "manual/" ) ) page.prepend( "manual/" );
56 
57  debug( "setSource qthelp://ultrascaniii/" + page );
58 
59  QByteArray ba;
60  ba.append( "setSource qthelp://ultrascaniii/" );
61  ba.append( page.toAscii() );
62  ba.append( '\0' );
63 
64  daemon.write( ba );
65 }
66 
67 void US_HelpDaemon::debug( const QString& message )
68 {
69  QFile d( "/tmp/helpdaemon.log" );
70  d.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append );
71  QTextStream out ( &d );
72  out << message << endl;
73  d.close();
74 }
75 
82 int main( int argc, char* argv[] )
83 {
84  // Need to add uid to identifier ????
85  //note: for doc files to show properly after an update, it may be necessary
86  // to remove ~/.local/share/data/Trolltech/Assistant/manual.qhc
87  QtSingleApplication application( "UltraScan Help Daemon", argc, argv );
88 
89  QString message = QString( argv[ 1 ] );
90 
91  if ( application.sendMessage( message ) ) return 0;
92 
93  application.initialize();
94  US_HelpDaemon* daemon = new US_HelpDaemon( message );
95 
96  QObject::connect( &application, SIGNAL( messageReceived( const QString& ) ),
97  daemon, SLOT ( show ( const QString& ) ) );
98 
99  return application.exec();
100 }
101