Mmmm.... sento puzza di release stabile! Sembra proprio che ora che

Leonardo Robol [2010-02-10 17:49]
Mmmm.... sento puzza di release stabile! Sembra proprio che ora che
ho spostato tutte le chiamate alla grafica nel thread principale
il programma abbia smesso di crashare.
Filename
Dizzy/EventManager.cs
Dizzy/Log.cs
Dizzy/Main.cs
Dizzy/MainWindow.cs
Dizzy/Protocol.cs
gtk-gui/gui.stetic
diff --git a/Dizzy/EventManager.cs b/Dizzy/EventManager.cs
index ea9300e..703f821 100644
--- a/Dizzy/EventManager.cs
+++ b/Dizzy/EventManager.cs
@@ -1,6 +1,7 @@

 using System;
 using Gtk;
+using System.Collections.Generic;

 namespace Dizzy
 {
@@ -33,6 +34,8 @@ namespace Dizzy

 		public EventManager () {}

+		protected static Dictionary<string,TreeIter> iters = new Dictionary<string, TreeIter> ();
+
 		// Metodo generico per segnalare un'errore dell'applicazione.
 		public static void ErrorMessage (string message) {

@@ -136,5 +139,54 @@ namespace Dizzy
 				return false;
 			});
 		}
+
+		public static void TaskTreeViewAddTask (string filename, int perc)
+		{
+			if (taskTreeView == null)
+				return;
+			GLib.Idle.Add (delegate {
+				EventManager.AddIter(filename, taskTreeView.AddTask (filename, perc));
+				return false;
+			});
+
+		}
+
+		public static void TaskTreeViewSetProgress (TreeIter iter, int perc)
+		{
+			if (taskTreeView == null)
+				return;
+			GLib.Idle.Add(delegate {
+				taskTreeView.SetProgress (iter, perc);
+				return false;
+			});
+		}
+
+		public static void TaskTreeViewRemove (TreeIter iter)
+		{
+			if (taskTreeView == null)
+				return;
+			GLib.Idle.Add (delegate {
+				taskTreeView.DeleteRow (iter);
+				return false;
+			});
+		}
+
+		public static void AddIter (string filename, TreeIter iter)
+		{
+			iters.Add(filename, iter);
+		}
+
+		public static TreeIter GetIter (string filename)
+		{
+			try {return iters[filename];}
+			catch (Exception e)
+			{
+				// Aspettiamo nella speranza che le cose vadano meglio
+				Log.Warning ("Sto richiamando GetIter () per ottenre l'iter (" + e.Message + ")");
+				System.Threading.Thread.Sleep(200);
+			}
+			return GetIter(filename);
+		}
+
 	}
 }
diff --git a/Dizzy/Log.cs b/Dizzy/Log.cs
index 9e322b0..6be287e 100644
--- a/Dizzy/Log.cs
+++ b/Dizzy/Log.cs
@@ -21,8 +21,8 @@ namespace Dizzy
 			ConsoleColor initial = Console.ForegroundColor;
 			Console.ForegroundColor = ConsoleColor.DarkRed;
 			Console.Write (" ==> ");
-			Console.ForegroundColor = initial;
 			Console.WriteLine (message);
+			Console.ForegroundColor = initial;
 		}


@@ -32,8 +32,8 @@ namespace Dizzy
 			ConsoleColor initial = Console.ForegroundColor;
 			Console.ForegroundColor = ConsoleColor.Cyan;
 			Console.Write (" ==> ");
-			Console.ForegroundColor = initial;
 			Console.WriteLine (message);
+			Console.ForegroundColor = initial;
 		}


@@ -43,21 +43,19 @@ namespace Dizzy
 			ConsoleColor initial = Console.ForegroundColor;
 			Console.ForegroundColor = ConsoleColor.Green;
 			Console.Write (" ==> ");
-			Console.ForegroundColor = initial;
 			Console.WriteLine (message);
-
+			Console.ForegroundColor = initial;
 			try {StatusBarUpdate(message);}
 			catch (Exception e) { Log.Error ("Impossibile loggare sulla statusbar" + e.Message); }
 		}

 		public static void Lock (string message)
 		{
-
 			ConsoleColor initial = Console.ForegroundColor;
-			Console.ForegroundColor = ConsoleColor.DarkGray;
 			Console.Write (" ==> ");
-			Console.ForegroundColor = initial;
+			Console.ForegroundColor = ConsoleColor.DarkGray;
 			Console.WriteLine (message);
+			Console.ForegroundColor = initial;
 		}
 	}
 }
diff --git a/Dizzy/Main.cs b/Dizzy/Main.cs
index b22d3d1..4f8260c 100644
--- a/Dizzy/Main.cs
+++ b/Dizzy/Main.cs
@@ -21,7 +21,7 @@ namespace Dizzy

 			win = new MainWindow (ref config);
 			win.ShowAll ();
-
+			Log.Info ("Starting application");
 			Application.Run ();

 		}
diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs
index 811d410..1f86831 100644
--- a/Dizzy/MainWindow.cs
+++ b/Dizzy/MainWindow.cs
@@ -85,7 +85,7 @@ public partial class MainWindow : Gtk.Window

 		string download_folder = this.downloadpathchooser.Filename;

-		this.protocol.Download(f, ref tasks, download_folder);
+		this.protocol.Download(f, download_folder);

 	}

@@ -108,8 +108,8 @@ public partial class MainWindow : Gtk.Window
 	{
 		// Come prima cosa otteniamo il file che il povero utente desidera
 		// caricare sul server.
-		string filename = uploadChooserButton.Filename;
-		this.protocol.Upload(filename, ref this.tasks);
+
+		this.protocol.Upload(uploadChooserButton.Filename);

 	}
 }
\ No newline at end of file
diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs
index 12858c0..102c777 100644
--- a/Dizzy/Protocol.cs
+++ b/Dizzy/Protocol.cs
@@ -200,7 +200,7 @@ namespace Dizzy
 		}


-		public void Download(File f, ref TaskTreeView tasks, string downloadFolder)
+		public void Download(File f, string downloadFolder)
 		{
 			// Preparo gli argomento da passare alla funzione.
 			if (!this.config.authenticated)
@@ -209,7 +209,6 @@ namespace Dizzy

 			ArrayList args = new ArrayList ();
 			args.Add (f);
-			args.Add (tasks);
 			args.Add (downloadFolder);
 			Thread t = new Thread (new ParameterizedThreadStart(_Download));
 			t.Start (args);
@@ -222,22 +221,21 @@ namespace Dizzy
 			// solo un oggetto a Download e quindi è il meglio che
 			// mi riesce di fare.
 			File f = (File) ((ArrayList) args)[0];
-			TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1];
 			string downloadFolder = (string) ((ArrayList) args)[2];
 			Log.Info ("Avvio il download di " + f.name);

 			try {
-				FileTransfer transfer = new FileTransfer (f, ref tasks, this.config.GetValue("user"), this.config.password, downloadFolder);
+				FileTransfer transfer = new FileTransfer (f, this.config.GetValue("user"), this.config.password, downloadFolder);
 				this.transfers.Add (transfer);
 			} catch (Exception e) {

 				Log.Error (e.Message);
 				this.config.authenticated = false;
-				this.Download (f, ref tasks, downloadFolder);
+				this.Download (f, downloadFolder);
 			}
 		}

-		public void Upload(string f, ref TaskTreeView tasks)
+		public void Upload(string f)
 		{
 			// Preparo gli argomento da passare alla funzione.
 			if (!this.config.authenticated)
@@ -246,7 +244,6 @@ namespace Dizzy

 			ArrayList args = new ArrayList ();
 			args.Add (f);
-			args.Add (tasks);
 			Thread t = new Thread (new ParameterizedThreadStart(_Upload));
 			t.Start (args);
 			this.threads.Add (t);
@@ -258,17 +255,16 @@ namespace Dizzy
 			// solo un oggetto a Download e quindi è il meglio che
 			// mi riesce di fare.
 			string f = (string) ((ArrayList) args)[0];
-			TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1];
 			Log.Info ("Avvio l'upload di " + f);

 			try {
-				FileUpload transfer = new FileUpload (f, ref tasks, this.config.GetValue("user"), this.config.password);
+				FileUpload transfer = new FileUpload (f, this.config.GetValue("user"), this.config.password);
 				this.transfers.Add (transfer);
 			} catch (Exception e) {

 				Log.Error (e.Message);
 				this.config.authenticated = false;
-				this.Upload (f, ref tasks);
+				this.Upload (f);
 			}
 		}

@@ -398,7 +394,6 @@ namespace Dizzy
 	public class FileTransfer
 	{

-		TaskTreeView tasks;
 		File file;
 		Gtk.TreeIter iter;

@@ -407,13 +402,12 @@ namespace Dizzy
 		public delegate void Handler(string src, string dest, int transferredBytes,
 		                             int totalBytes, string message);

-		public FileTransfer (File f, ref TaskTreeView tasks, string user, string password, string downloadFolder)
+		public FileTransfer (File f,  string user, string password, string downloadFolder)
 		{
 			// Connessione al server
 			this.sftp = new SFTPConnection (user, password);
 			this.sftp.Connect ();

-			this.tasks = tasks;
 			this.file = f;

 			sftp.TransferStarted += new SFTPConnection.SFTPEvent(OnTransferStarted);
@@ -432,20 +426,21 @@ namespace Dizzy
 		public void OnTransferStarted (string src, string dest, int transferredBytes,
 		                          int totalBytes, string message)
 		{
-			this.iter = this.tasks.AddTask(file.name, 0);
+			EventManager.TaskTreeViewAddTask (file.name, 0);
+			this.iter = EventManager.GetIter (file.name);
 		}

 		public void OnTransferProgress(string src, string dest, int transferredBytes,
 		                               int totalBytes, string message)
 		{
 			int perc = transferredBytes / (totalBytes / 100);
-			this.tasks.SetProgress(this.iter, perc);
+			EventManager.TaskTreeViewSetProgress (this.iter, perc);
 		}

 		public void OnTransferStopped (string src, string dest, int transferredBytes,
 		                               int totalBytes, string message)
 		{
-			this.tasks.DeleteRow (this.iter);
+			EventManager.TaskTreeViewRemove (iter);
 		}
 	}

@@ -453,7 +448,6 @@ namespace Dizzy
 	public class FileUpload
 	{

-		TaskTreeView tasks;
 		string filename;
 		Gtk.TreeIter iter;

@@ -462,13 +456,12 @@ namespace Dizzy
 		public delegate void Handler(string src, string dest, int transferredBytes,
 		                             int totalBytes, string message);

-		public FileUpload (string filename, ref TaskTreeView tasks, string user, string password)
+		public FileUpload (string filename, string user, string password)
 		{
 			// Connessione al server
 			this.sftp = new SFTPConnection (user, password);
 			this.sftp.Connect ();

-			this.tasks = tasks;
 			this.filename = filename;

 			sftp.TransferStarted += new SFTPConnection.SFTPEvent(OnTransferStarted);
@@ -487,55 +480,26 @@ namespace Dizzy
 		public void OnTransferStarted (string src, string dest, int transferredBytes,
 		                          int totalBytes, string message)
 		{
-			this.iter = this.tasks.AddTask(filename, 0);
+			EventManager.TaskTreeViewAddTask (filename, 0);
+			this.iter = EventManager.GetIter (filename);
 		}

 		public void OnTransferProgress(string src, string dest, int transferredBytes,
 		                               int totalBytes, string message)
 		{
 			int perc = transferredBytes / (totalBytes / 100);
-			this.tasks.SetProgress(this.iter, perc);
+			EventManager.TaskTreeViewSetProgress (iter, perc);
 		}

 		public void OnTransferStopped (string src, string dest, int transferredBytes,
 		                               int totalBytes, string message)
 		{
-			this.tasks.DeleteRow (this.iter);
+			EventManager.TaskTreeViewRemove (iter);
 		}
 	}


-	class FileSearch
-{
-	SshExec sshexec;
-	string username, password, keywords;
-	FileTreeView f;
-
-	public FileSearch (string username, string password, string keywords, ref FileTreeView f)
-	{
-		this.username = username;
-		this.password = password;
-		this.keywords = keywords;
-		this.f = f;
-	}
-
-	public void DoSearch ()
-	{
-		sshexec = new SshExec("poisson.phc.unipi.it", this.username, this.password);
-		sshexec.Connect ();
-
-		string command = "locate -i -e --regex /nobackup/.+" + this.keywords;
-		string output = sshexec.RunCommand (command);
-		f.Clear ();
-		foreach(string line in Regex.Split(output, "\n"))
-		{
-			if (line.StartsWith("/nobackup/") && Regex.Match(line,".*[.].*").Success)
-				this.f.AddFile (new File(line, ""));
-		}
-		sshexec.Close ();
-	}
-
-}
+

 	public class FileList
 	{
diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic
index ff37542..6195a84 100644
--- a/gtk-gui/gui.stetic
+++ b/gtk-gui/gui.stetic
@@ -706,97 +706,4 @@ Libro</property>
       </widget>
     </child>
   </widget>
-  <widget class="Gtk.Dialog" id="Dizzy.ErrorDialog" design-size="210 131">
-    <property name="MemberName" />
-    <property name="WindowPosition">CenterOnParent</property>
-    <property name="Buttons">2</property>
-    <property name="HelpButton">False</property>
-    <child internal-child="VBox">
-      <widget class="Gtk.VBox" id="dialog1_VBox">
-        <property name="MemberName" />
-        <property name="BorderWidth">2</property>
-        <child>
-          <widget class="Gtk.HBox" id="hbox2">
-            <property name="MemberName" />
-            <property name="Spacing">6</property>
-            <child>
-              <widget class="Gtk.Image" id="image1">
-                <property name="MemberName" />
-                <property name="WidthRequest">64</property>
-                <property name="HeightRequest">64</property>
-                <property name="Pixbuf">stock:gtk-dialog-error Menu</property>
-              </widget>
-              <packing>
-                <property name="Position">0</property>
-                <property name="AutoSize">True</property>
-                <property name="Expand">False</property>
-                <property name="Fill">False</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="Gtk.Label" id="message">
-                <property name="MemberName" />
-                <property name="LabelProp" translatable="yes">label4</property>
-                <property name="UseMarkup">True</property>
-              </widget>
-              <packing>
-                <property name="Position">1</property>
-                <property name="AutoSize">True</property>
-                <property name="Expand">False</property>
-                <property name="Fill">False</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="Position">0</property>
-            <property name="AutoSize">True</property>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-    <child internal-child="ActionArea">
-      <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
-        <property name="MemberName" />
-        <property name="Spacing">10</property>
-        <property name="BorderWidth">5</property>
-        <property name="Size">2</property>
-        <property name="LayoutStyle">End</property>
-        <child>
-          <widget class="Gtk.Button" id="buttonCancel">
-            <property name="MemberName" />
-            <property name="CanDefault">True</property>
-            <property name="CanFocus">True</property>
-            <property name="UseStock">True</property>
-            <property name="Type">StockItem</property>
-            <property name="StockId">gtk-cancel</property>
-            <property name="ResponseId">-6</property>
-            <property name="label">gtk-cancel</property>
-          </widget>
-          <packing>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
-          </packing>
-        </child>
-        <child>
-          <widget class="Gtk.Button" id="buttonOk">
-            <property name="MemberName" />
-            <property name="CanDefault">True</property>
-            <property name="CanFocus">True</property>
-            <property name="UseStock">True</property>
-            <property name="Type">StockItem</property>
-            <property name="StockId">gtk-ok</property>
-            <property name="ResponseId">-5</property>
-            <property name="label">gtk-ok</property>
-          </widget>
-          <packing>
-            <property name="Position">1</property>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
 </stetic-interface>
\ No newline at end of file
ViewGit