[or-cvs] r13247: Test code for terminating a process from Qt (torbrowser/trunk/src/processtest)

sjm217 at seul.org sjm217 at seul.org
Thu Jan 24 01:06:42 UTC 2008


Author: sjm217
Date: 2008-01-23 20:06:42 -0500 (Wed, 23 Jan 2008)
New Revision: 13247

Modified:
   torbrowser/trunk/src/processtest/processtest.cpp
   torbrowser/trunk/src/processtest/processtest.h
Log:
Test code for terminating a process from Qt

Modified: torbrowser/trunk/src/processtest/processtest.cpp
===================================================================
--- torbrowser/trunk/src/processtest/processtest.cpp	2008-01-23 19:08:53 UTC (rev 13246)
+++ torbrowser/trunk/src/processtest/processtest.cpp	2008-01-24 01:06:42 UTC (rev 13247)
@@ -48,6 +48,7 @@
 
     // Initialize the process handler
     _browser = new BrowserProcess();
+    _isRunning = false;
  
     // Connect up the button
     QObject::connect(_button, SIGNAL(clicked()), this, SLOT(onClicked()));
@@ -60,25 +61,37 @@
 
 void ProcessTest::onClicked()
 {
-    // Start the application
-    _button->setText(tr("Starting...") + _cmd);
-    _browser->start(_cmd, QStringList());
+    if (isRunning)
+    {
+        // Application is running: kill it
+        _button->setText(tr("Terminating..."));
+        _browser->terminate();
+    }
+    else
+    {
+        // Application is not running: start it
+        _button->setText(tr("Starting...") + _cmd);
+        _browser->start(_cmd, QStringList());
+    }
 }
 
 void ProcessTest::onStarted()
 {
     // Application has started
     _button->setText(tr("Running..."));
+    _isRunning = true;
 }
 
 void ProcessTest::onFinished()
 {
     // Application has finished
     _button->setText(tr("Stopped"));
+    _isRunning = false;
 }
 
 void ProcessTest::onFailed()
 {
     // Application failed to start
     _button->setText(tr("Failed"));
+    _isRunning = false;
 }

Modified: torbrowser/trunk/src/processtest/processtest.h
===================================================================
--- torbrowser/trunk/src/processtest/processtest.h	2008-01-23 19:08:53 UTC (rev 13246)
+++ torbrowser/trunk/src/processtest/processtest.h	2008-01-24 01:06:42 UTC (rev 13247)
@@ -56,6 +56,8 @@
     BrowserProcess *_browser;
     // Command line to start
     QString _cmd;
+    // Is the application running
+    bool _isRunning;
 };
 
 #endif



More information about the tor-commits mailing list