From a406160c18c2a05c174cf0ea09fd86c9d9c1c304 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Thu, 11 Feb 2010 22:25:54 +0100 Subject: [PATCH] Ora si possono annulare in maniera sicura i trasferimenti. --- Dizzy/EventManager.cs | 28 +++++++++-- Dizzy/FileTransfer.cs | 19 +++++--- Dizzy/MainWindow.cs | 23 +++++++++ Dizzy/Protocol.cs | 39 +++++++++++++-- Dizzy/TaskTreeView.cs | 13 +++++ gtk-gui/MainWindow.cs | 131 ++++++++++++++++++++++++++++---------------------- gtk-gui/gui.stetic | 21 +++++++- 7 files changed, 200 insertions(+), 74 deletions(-) diff --git a/Dizzy/EventManager.cs b/Dizzy/EventManager.cs index b71aeda..efa2a88 100644 --- a/Dizzy/EventManager.cs +++ b/Dizzy/EventManager.cs @@ -151,24 +151,36 @@ namespace Dizzy } - public static void TaskTreeViewSetProgress (TreeIter iter, int perc) + public static void TaskTreeViewSetProgress (string GUID, int perc) { if (taskTreeView == null) return; + TreeIter iter; + try {iter = iters[GUID];} + catch (System.Collections.Generic.KeyNotFoundException) + { + // Questo si può verificare se abbiamo annullato il trasferimento + // e già tolto il task, ma _get di sharpssh se ne deve ancora + // rendere conto. In questo caso facciamo finta di nulla, tanto + // se ne accorgerà appena avrà svuotato il buffer. + return; + } GLib.Idle.Add(delegate { taskTreeView.SetProgress (iter, perc); return false; }); } - public static void TaskTreeViewRemove (TreeIter iter) + public static void TaskTreeViewRemove (string GUID) { if (taskTreeView == null) return; + TreeIter iter = iters[GUID]; GLib.Idle.Add (delegate { taskTreeView.DeleteRow (iter); return false; }); + iters.Remove (GUID); } public static void AddIter (string GUID, TreeIter iter) @@ -181,7 +193,6 @@ namespace Dizzy TreeIter ret; try { ret = iters[GUID]; - iters.Remove (GUID); return ret; } catch (Exception e) @@ -193,5 +204,16 @@ namespace Dizzy return GetIter(GUID); } + public static string GetGUID (TreePath path) + { + foreach(KeyValuePair pair in iters) + { + if (taskTreeView.IterToPath (pair.Value).Compare(path) == 0) + return pair.Key; + } + Log.Warning ("TreePath non trovato, ritorno null"); + return null; + } + } } diff --git a/Dizzy/FileTransfer.cs b/Dizzy/FileTransfer.cs index bb24a5b..993eec0 100644 --- a/Dizzy/FileTransfer.cs +++ b/Dizzy/FileTransfer.cs @@ -6,11 +6,7 @@ namespace Dizzy public abstract class FileTransfer { - - // Questo è il riferimento all'elemento della taskview che - // creeremo per monitorare il progress. - protected Gtk.TreeIter iter; - + // La connessione vera e propria al server protected SFTPConnection sftp; @@ -38,6 +34,8 @@ namespace Dizzy this.label = label; } + public string GetGUID () {return GUID;} + public virtual void Start () {} public void Stop () @@ -45,6 +43,11 @@ namespace Dizzy // Queste chiamate dovrebbero essere piuttosto standard in tutti // i trasferimenti di file che per il momento ci possiamo immaginare. this.sftp.Abort (); + EventManager.TaskTreeViewRemove (GUID); + + // Aspettiamo un momento sperando di riuscire ad evitare + // che _get si blocchi. + System.Threading.Thread.Sleep (200); this.sftp.Disconnect (); } @@ -58,20 +61,20 @@ namespace Dizzy { GUID = System.Guid.NewGuid().ToString(); EventManager.TaskTreeViewAddTask (label, 0, GUID); - this.iter = EventManager.GetIter (GUID); + // this.iter = EventManager.GetIter (GUID); } public void OnTransferProgress(string src, string dest, int transferredBytes, int totalBytes, string message) { int perc = transferredBytes / (totalBytes / 100); - EventManager.TaskTreeViewSetProgress (this.iter, perc); + EventManager.TaskTreeViewSetProgress (GUID, perc); } public void OnTransferStopped (string src, string dest, int transferredBytes, int totalBytes, string message) { - EventManager.TaskTreeViewRemove (iter); + EventManager.TaskTreeViewRemove (GUID); } } } diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs index 3b170ff..983f89f 100644 --- a/Dizzy/MainWindow.cs +++ b/Dizzy/MainWindow.cs @@ -115,4 +115,27 @@ public partial class MainWindow : Gtk.Window this.protocol.Upload(uploadChooserButton.Filename); } + + + protected virtual void OnTasklistCursorChanged (object sender, System.EventArgs e) + { + if (tasklist.Selection != null) + blockTransfer.Sensitive = true; + else + blockTransfer.Sensitive = false; + } + + protected virtual void OnBlockTransferClicked (object sender, System.EventArgs e) + { + // Dobbiamo determinare che trasferimento bloccare + TreePath path; + path = tasks.GetActivePath (); + string GUID = EventManager.GetGUID (path); + this.protocol.DisconnectPath (GUID); + } + + + + + } \ No newline at end of file diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index ee6a979..7cdec44 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -190,7 +190,22 @@ namespace Dizzy } } - + + public void DisconnectPath (string GUID) + { + FileTransfer stoppedTransfer = null; + foreach(FileTransfer t in this.transfers) + { + if ( t.GetGUID () == GUID) + { + t.Stop (); + stoppedTransfer = t; + } + } + if(stoppedTransfer != null) + transfers.Remove (stoppedTransfer); + } + public void Download(File f, string downloadFolder) { @@ -216,17 +231,23 @@ namespace Dizzy string downloadFolder = (string) ((ArrayList) args)[1]; Log.Info ("Avvio il download di " + f.name); + FileDownlad transfer; try { - FileDownlad transfer = new FileDownlad (f, this.config.GetValue("user"), this.config.password, downloadFolder); + transfer = new FileDownlad (f, this.config.GetValue("user"), this.config.password, downloadFolder); this.transfers.Add (transfer); - transfer.Start (); } catch (Exception e) { Log.Error (e.Message); this.config.authenticated = false; EventManager.ErrorMessage ("Autenticazione fallita"); + return; } + try {transfer.Start ();} + catch (Exception) { + // Si lamenterà se e quando termineremo il trasferimento + // brutalmente ma per ora sembra che non ci possiamo fare niente. + } } @@ -252,15 +273,23 @@ namespace Dizzy string f = (string) ((ArrayList) args)[0]; Log.Info ("Avvio l'upload di " + f); + FileUpload transfer; try { - FileUpload transfer = new FileUpload (f, this.config.GetValue("user"), this.config.password); + transfer = new FileUpload (f, this.config.GetValue("user"), this.config.password); this.transfers.Add (transfer); - transfer.Start (); + } catch (Exception e) { Log.Error (e.Message); this.config.authenticated = false; EventManager.ErrorMessage ("Autenticazione fallita"); + return; + } + + try {transfer.Start ();} + catch (Exception) { + // Ci potrebbero essere dei problemi ma per ora non + // vogliamo occuparcene. } } diff --git a/Dizzy/TaskTreeView.cs b/Dizzy/TaskTreeView.cs index 8f90d4b..7e02605 100644 --- a/Dizzy/TaskTreeView.cs +++ b/Dizzy/TaskTreeView.cs @@ -38,6 +38,19 @@ namespace Dizzy this.tree.Model = tasklist; } + public TreePath GetActivePath () + { + TreeIter iter; + TreeSelection sel = tree.Selection; + sel.GetSelected (out iter); + return tasklist.GetPath (iter); + } + + public TreePath IterToPath (TreeIter iter) + { + return tasklist.GetPath (iter); + } + protected void CellSetup () { CellRendererText fileRenderer = new CellRendererText (); diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs index c77515f..3fa436f 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -50,6 +50,8 @@ public partial class MainWindow { private Gtk.FileChooserButton downloadpathchooser; + private Gtk.Button blockTransfer; + private Gtk.Label label3; private Gtk.Table table2; @@ -100,7 +102,7 @@ public partial class MainWindow { this.notebook1 = new Gtk.Notebook(); this.notebook1.CanFocus = true; this.notebook1.Name = "notebook1"; - this.notebook1.CurrentPage = 2; + this.notebook1.CurrentPage = 1; // Container child notebook1.Gtk.Notebook+NotebookChild this.vbox3 = new Gtk.VBox(); this.vbox3.Name = "vbox3"; @@ -241,14 +243,27 @@ public partial class MainWindow { this.hbox2.Add(this.downloadpathchooser); Gtk.Box.BoxChild w14 = ((Gtk.Box.BoxChild)(this.hbox2[this.downloadpathchooser])); w14.Position = 1; - this.vbox2.Add(this.hbox2); - Gtk.Box.BoxChild w15 = ((Gtk.Box.BoxChild)(this.vbox2[this.hbox2])); - w15.Position = 1; + // Container child hbox2.Gtk.Box+BoxChild + this.blockTransfer = new Gtk.Button(); + this.blockTransfer.Sensitive = false; + this.blockTransfer.CanFocus = true; + this.blockTransfer.Name = "blockTransfer"; + this.blockTransfer.UseUnderline = true; + this.blockTransfer.Label = Mono.Unix.Catalog.GetString("Blocca trasferimento"); + this.hbox2.Add(this.blockTransfer); + Gtk.Box.BoxChild w15 = ((Gtk.Box.BoxChild)(this.hbox2[this.blockTransfer])); + w15.PackType = ((Gtk.PackType)(1)); + w15.Position = 2; w15.Expand = false; w15.Fill = false; - this.notebook1.Add(this.vbox2); - Gtk.Notebook.NotebookChild w16 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.vbox2])); + this.vbox2.Add(this.hbox2); + Gtk.Box.BoxChild w16 = ((Gtk.Box.BoxChild)(this.vbox2[this.hbox2])); w16.Position = 1; + w16.Expand = false; + w16.Fill = false; + this.notebook1.Add(this.vbox2); + Gtk.Notebook.NotebookChild w17 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.vbox2])); + w17.Position = 1; // Notebook tab this.label3 = new Gtk.Label(); this.label3.Name = "label3"; @@ -272,11 +287,11 @@ public partial class MainWindow { this.label10.UseMarkup = true; this.alignment1.Add(this.label10); this.table2.Add(this.alignment1); - Gtk.Table.TableChild w18 = ((Gtk.Table.TableChild)(this.table2[this.alignment1])); - w18.TopAttach = ((uint)(3)); - w18.BottomAttach = ((uint)(4)); - w18.XOptions = ((Gtk.AttachOptions)(4)); - w18.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w19 = ((Gtk.Table.TableChild)(this.table2[this.alignment1])); + w19.TopAttach = ((uint)(3)); + w19.BottomAttach = ((uint)(4)); + w19.XOptions = ((Gtk.AttachOptions)(4)); + w19.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.alignment2 = new Gtk.Alignment(0.5F, 0.5F, 1F, 1F); this.alignment2.Name = "alignment2"; @@ -288,9 +303,9 @@ public partial class MainWindow { this.label5.UseMarkup = true; this.alignment2.Add(this.label5); this.table2.Add(this.alignment2); - Gtk.Table.TableChild w20 = ((Gtk.Table.TableChild)(this.table2[this.alignment2])); - w20.XOptions = ((Gtk.AttachOptions)(4)); - w20.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w21 = ((Gtk.Table.TableChild)(this.table2[this.alignment2])); + w21.XOptions = ((Gtk.AttachOptions)(4)); + w21.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.alignment3 = new Gtk.Alignment(0F, 0.5F, 1F, 1F); this.alignment3.Name = "alignment3"; @@ -302,10 +317,10 @@ public partial class MainWindow { this.label8.Wrap = true; this.alignment3.Add(this.label8); this.table2.Add(this.alignment3); - Gtk.Table.TableChild w22 = ((Gtk.Table.TableChild)(this.table2[this.alignment3])); - w22.TopAttach = ((uint)(1)); - w22.BottomAttach = ((uint)(2)); - w22.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w23 = ((Gtk.Table.TableChild)(this.table2[this.alignment3])); + w23.TopAttach = ((uint)(1)); + w23.BottomAttach = ((uint)(2)); + w23.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.alignment4 = new Gtk.Alignment(0.5F, 0.5F, 1F, 1F); this.alignment4.Name = "alignment4"; @@ -317,11 +332,11 @@ public partial class MainWindow { this.label9.Wrap = true; this.alignment4.Add(this.label9); this.table2.Add(this.alignment4); - Gtk.Table.TableChild w24 = ((Gtk.Table.TableChild)(this.table2[this.alignment4])); - w24.TopAttach = ((uint)(2)); - w24.BottomAttach = ((uint)(3)); - w24.XOptions = ((Gtk.AttachOptions)(4)); - w24.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w25 = ((Gtk.Table.TableChild)(this.table2[this.alignment4])); + w25.TopAttach = ((uint)(2)); + w25.BottomAttach = ((uint)(3)); + w25.XOptions = ((Gtk.AttachOptions)(4)); + w25.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.button182 = new Gtk.Button(); this.button182.CanFocus = true; @@ -329,13 +344,13 @@ public partial class MainWindow { this.button182.UseUnderline = true; this.button182.Label = Mono.Unix.Catalog.GetString("Disconnetti"); this.table2.Add(this.button182); - Gtk.Table.TableChild w25 = ((Gtk.Table.TableChild)(this.table2[this.button182])); - w25.TopAttach = ((uint)(1)); - w25.BottomAttach = ((uint)(2)); - w25.LeftAttach = ((uint)(1)); - w25.RightAttach = ((uint)(2)); - w25.XOptions = ((Gtk.AttachOptions)(4)); - w25.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w26 = ((Gtk.Table.TableChild)(this.table2[this.button182])); + w26.TopAttach = ((uint)(1)); + w26.BottomAttach = ((uint)(2)); + w26.LeftAttach = ((uint)(1)); + w26.RightAttach = ((uint)(2)); + w26.XOptions = ((Gtk.AttachOptions)(4)); + w26.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.button183 = new Gtk.Button(); this.button183.CanFocus = true; @@ -343,13 +358,13 @@ public partial class MainWindow { this.button183.UseUnderline = true; this.button183.Label = Mono.Unix.Catalog.GetString("Aggiorna lista"); this.table2.Add(this.button183); - Gtk.Table.TableChild w26 = ((Gtk.Table.TableChild)(this.table2[this.button183])); - w26.TopAttach = ((uint)(2)); - w26.BottomAttach = ((uint)(3)); - w26.LeftAttach = ((uint)(1)); - w26.RightAttach = ((uint)(2)); - w26.XOptions = ((Gtk.AttachOptions)(4)); - w26.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w27 = ((Gtk.Table.TableChild)(this.table2[this.button183])); + w27.TopAttach = ((uint)(2)); + w27.BottomAttach = ((uint)(3)); + w27.LeftAttach = ((uint)(1)); + w27.RightAttach = ((uint)(2)); + w27.XOptions = ((Gtk.AttachOptions)(4)); + w27.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.button184 = new Gtk.Button(); this.button184.CanFocus = true; @@ -357,25 +372,25 @@ public partial class MainWindow { this.button184.UseUnderline = true; this.button184.Label = Mono.Unix.Catalog.GetString("Carica file"); this.table2.Add(this.button184); - Gtk.Table.TableChild w27 = ((Gtk.Table.TableChild)(this.table2[this.button184])); - w27.TopAttach = ((uint)(4)); - w27.BottomAttach = ((uint)(5)); - w27.LeftAttach = ((uint)(1)); - w27.RightAttach = ((uint)(2)); - w27.XOptions = ((Gtk.AttachOptions)(4)); - w27.YOptions = ((Gtk.AttachOptions)(4)); - // Container child table2.Gtk.Table+TableChild - this.uploadChooserButton = new Gtk.FileChooserButton(Mono.Unix.Catalog.GetString("Seleziona un file"), ((Gtk.FileChooserAction)(0))); - this.uploadChooserButton.Name = "uploadChooserButton"; - this.table2.Add(this.uploadChooserButton); - Gtk.Table.TableChild w28 = ((Gtk.Table.TableChild)(this.table2[this.uploadChooserButton])); + Gtk.Table.TableChild w28 = ((Gtk.Table.TableChild)(this.table2[this.button184])); w28.TopAttach = ((uint)(4)); w28.BottomAttach = ((uint)(5)); + w28.LeftAttach = ((uint)(1)); + w28.RightAttach = ((uint)(2)); w28.XOptions = ((Gtk.AttachOptions)(4)); w28.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.uploadChooserButton = new Gtk.FileChooserButton(Mono.Unix.Catalog.GetString("Seleziona un file"), ((Gtk.FileChooserAction)(0))); + this.uploadChooserButton.Name = "uploadChooserButton"; + this.table2.Add(this.uploadChooserButton); + Gtk.Table.TableChild w29 = ((Gtk.Table.TableChild)(this.table2[this.uploadChooserButton])); + w29.TopAttach = ((uint)(4)); + w29.BottomAttach = ((uint)(5)); + w29.XOptions = ((Gtk.AttachOptions)(4)); + w29.YOptions = ((Gtk.AttachOptions)(4)); this.notebook1.Add(this.table2); - Gtk.Notebook.NotebookChild w29 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); - w29.Position = 2; + Gtk.Notebook.NotebookChild w30 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); + w30.Position = 2; // Notebook tab this.label7 = new Gtk.Label(); this.label7.Name = "label7"; @@ -383,17 +398,17 @@ public partial class MainWindow { this.notebook1.SetTabLabel(this.table2, this.label7); this.label7.ShowAll(); this.vbox1.Add(this.notebook1); - Gtk.Box.BoxChild w30 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); - w30.Position = 0; + Gtk.Box.BoxChild w31 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); + w31.Position = 0; // Container child vbox1.Gtk.Box+BoxChild this.dizzystatus = new Gtk.Statusbar(); this.dizzystatus.Name = "dizzystatus"; this.dizzystatus.Spacing = 6; this.vbox1.Add(this.dizzystatus); - Gtk.Box.BoxChild w31 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); - w31.Position = 1; - w31.Expand = false; - w31.Fill = false; + Gtk.Box.BoxChild w32 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); + w32.Position = 1; + w32.Expand = false; + w32.Fill = false; this.Add(this.vbox1); if ((this.Child != null)) { this.Child.ShowAll(); @@ -402,7 +417,9 @@ public partial class MainWindow { this.DeleteEvent += new Gtk.DeleteEventHandler(this.OnDeleteEvent); this.button1.Clicked += new System.EventHandler(this.OnSearchRequested); this.filelist.RowActivated += new Gtk.RowActivatedHandler(this.OnRowActivated); + this.tasklist.CursorChanged += new System.EventHandler(this.OnTasklistCursorChanged); this.downloadpathchooser.SelectionChanged += new System.EventHandler(this.OnDownloadPathSelectionChanged); + this.blockTransfer.Clicked += new System.EventHandler(this.OnBlockTransferClicked); this.button184.Clicked += new System.EventHandler(this.OnUploadRequested); this.button183.Clicked += new System.EventHandler(this.OnListUpdateRequired); this.button182.Clicked += new System.EventHandler(this.OnDisconnectionRequested); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index 6195a84..cd9154e 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -25,7 +25,7 @@ True - 2 + 1 @@ -215,6 +215,7 @@ Libro True True + @@ -252,6 +253,24 @@ Libro True + + + + False + True + TextOnly + Blocca trasferimento + True + + + + End + 2 + True + False + False + + 1 -- 2.1.4