Author: remi
Date: 2009-07-31 11:13:29 +0200 (Fri, 31 Jul 2009)
New Revision: 5255

Modified:
   
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dfm
   
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
Log:
* Improved program exiting method

Modified: 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dfm
===================================================================
--- 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dfm
 2009-07-31 09:12:56 UTC (rev 5254)
+++ 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dfm
 2009-07-31 09:13:29 UTC (rev 5255)
@@ -90,7 +90,7 @@
   end
   object StatusBar1: TStatusBar
     Left = 0
-    Top = 600
+    Top = 607
     Width = 955
     Height = 19
     Panels = <>

Modified: 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
===================================================================
--- 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
 2009-07-31 09:12:56 UTC (rev 5254)
+++ 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
 2009-07-31 09:13:29 UTC (rev 5255)
@@ -157,6 +157,7 @@
     procedure OpenUrl(const url : String);
     procedure ShowSplashScreen;
     procedure HideSplashScreen;
+    procedure ExitApplication(windowsIsShutdown : boolean);
 
   public
     { D�clarations publiques }
@@ -175,6 +176,8 @@
   balloonShowed    : boolean;
   splashScreenMustBeShowed : boolean;
   startInForeground: boolean;
+  exitingFlag      : boolean;
+  connCheckerFlag  : boolean;
   properties       : TStringList;
   reduce_balloon   : boolean;
   ready_balloon    : boolean;
@@ -216,6 +219,12 @@
 //Form initialization.
 procedure TForm1.FormCreate(Sender: TObject);
 begin
+  //Initializing some flags
+  started := false;
+  smartcoreReady := false;
+  exitingFlag := false;
+  connCheckerFlag := false;
+
   //Get if the splash screen must be showed or not
   splashScreenMustBeShowed := true;
   startInForeground := false;
@@ -246,9 +255,6 @@
 
   language := properties.Values['language'];
 
-  started := false;
-  smartcoreReady := false;
-
   DelegateInit.Enabled := true;
 end;
 
@@ -349,7 +355,7 @@
 procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession);
 begin
   inherited;
-  Form1.Quit1Click(nil);
+  ExitApplication(false);
   Message.Result := 1;
 end;
 
@@ -426,31 +432,41 @@
 end;
 
 
-//Tray menu 'quit' click.
-procedure TForm1.Quit1Click(Sender: TObject);
+//Exit the application.
+procedure TForm1.ExitApplication(windowsIsShutdown : boolean);
 begin
   try
-    if TuxUtils.stopServer() then
+    //Stop connection checker
+    exitingFlag := true;
+    smartcoreReady := false;
+    while connCheckerFlag do
+      Sleep(250);
+    ConnectionChecker.Enabled := false;
+    //Store properties
+    Form1.saveProperties;
+    properties.Free;
+    if not windowsIsShutdown then
       begin
-        Form1.saveProperties;
-        properties.Free;
-        ConnectionChecker.Enabled := false;
-        AppIcon.Free;
+        //Remove tray icon
         Form1.DeleteSysTrayIcon;
-        Application.Terminate;
-      end
-    else if TuxUtils.isTuxDroidServerStarted() then
-      begin
-        Form1.ShowBalloonTips(gettext(SERVER_STOP_ERROR_0) + slinebreak +
-                              gettext(SERVER_STOP_ERROR_1));
+        //AppIcon.Free;
+        //Stop server
+        TuxUtils.stopServer();
       end;
-    except
-      on e : Exception do
-        Application.Terminate;
-    end;
+    Sleep(100);
+  except
+  end;
+  Application.Terminate;
 end;
 
 
+//Tray menu 'quit' click.
+procedure TForm1.Quit1Click(Sender: TObject);
+begin
+  ExitApplication(false);
+end;
+
+
 {###############################################}
 {####### Private functions and procedures ######}
 {###############################################}
@@ -573,10 +589,23 @@
   temp : TStringList;
 
 begin
+  connCheckerFlag := true;
   ConnectionChecker.Enabled := false;
 
+  if exitingFlag then
+    begin
+      connCheckerFlag := false;
+      exit;
+    end;
+
   server := TuxUtils.isTuxDroidServerStarted();
 
+  if exitingFlag then
+    begin
+      connCheckerFlag := false;
+      exit;
+    end;
+
   //Trying to get states only if server is started.
   if server then
     begin
@@ -679,6 +708,7 @@
 
   Application.ProcessMessages;
   ConnectionChecker.Enabled := true;
+  connCheckerFlag := false;
 end;
 
 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to