UltraScan III
us_help.cpp
Go to the documentation of this file.
1 #include "us_help.h"
2 #include "us_settings.h"
3 
4 // Null constructor
5 US_Help::US_Help( QObject* parent ) : QObject( parent ) { }
6 
7 // Show a specified help page in US3 manual
8 void US_Help::show_help( const QString& helpFile )
9 {
10  // Create a new process each time. If show_help() is called multiple
11  // times from a process, the previous process will become unavailable,
12  // but we don't use it. It's a 'memory leak', but should be minimal.
13  // This is done because a QProcess can't be started multiple times
14  // and we would still need a way to get the helpFile to assistant.
15  // QProcess is a link to the daemon and is each program that calls
16  // help needs its own Qprocess instance.
17 
18  // If we wanted to clean up, we would need to do something like the
19  // following (not tested). This seems like a lot of work for
20  // little gain.
21 
22  // header:
23  // QList< QProcess*> processes;
24 
25  // here:
26  // assistant = new QProcess;
27  // processes << assistant;
28  // connect( assistant, SIGNAL( finished ( int, QProcess::ExitStatus ) )
29  // ( this , SLOT ( endProcess( ( int, QProcess::ExitStatus ) ) );
30 
31  // Function ( note that we don't really need status
32  // void US_Help::end_process( int, QProcess::ExitStatus )
33  // {
34  // for ( int i = processes.size() - 1; i >= 0; i-- )
35  // {
36  // if ( processes[ i ]->state() == QProcess::NotRunning )
37  // {
38  // delete processes[ i ];
39  // processes.takeAt( i );
40  // }
41  // }
42  // }
43 
44  assistant = new QProcess;
45  QStringList args;
46  args << helpFile;
47 
48  // This us_helpdaemon will check if an instance is already running and
49  // exit immediately if it is.
50 
51 #ifndef Q_WS_MAC
52  assistant->start( "us_helpdaemon", args );
53 #else
54  QString helpbin = US_Settings::appBaseDir() + "/bin/us_helpdaemon";
55  QString helpapp = helpbin + ".app";
56  if ( QFile( helpapp ).exists() )
57  assistant->start( helpapp, args );
58  else
59  assistant->start( helpbin, args );
60 #endif
61  // Don't bother to wait
62 }
63 
64 // Show a specified URL in the user's configured browser
65 void US_Help::show_URL( const QString& location )
66 {
67  openBrowser( location );
68 }
69 
70 // Show a specified HTML file in the user's configured browser
71 void US_Help::show_html_file( const QString& location )
72 {
73  openBrowser( "file://" + location );
74 }
75 
76 // Open a web page or file in the user's configured browser
77 void US_Help::openBrowser( const QString& location )
78 {
79  QProcess* proc = new QProcess( this );
80  QString program = US_Settings::browser();
81  QStringList args;
82 
83 #ifndef Q_WS_MAC
84  args << location;
85 #else
86  args << "-a" << program << location;
87  program = "open";
88 #endif
89 
90  proc->start( program, args );
91 
92  if ( !proc->waitForStarted( 10000 ) )
93  {
94  QMessageBox::warning( 0,
95  tr( "Ultrascan III Error" ),
96  tr( "Cannot start browser window ...\n"
97  "Please insure you have the configured browser installed.\n\n"
98  " Configured browser: %1\n"
99  " URL: %2" ).arg( program ).arg( location ) );
100  }
101 }
102