Ripulita la chiusura dell'applicazione e messe le premesse
Leonardo Robol [2010-02-10 23:02]
Ripulita la chiusura dell'applicazione e messe le premesse
per poter creare un pulsante per interrompere il trasferimento
in corso.
diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs
index 1f86831..3b170ff 100644
--- a/Dizzy/MainWindow.cs
+++ b/Dizzy/MainWindow.cs
@@ -61,7 +61,10 @@ public partial class MainWindow : Gtk.Window
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
if (protocol != null)
+ {
+ Log.Info ("Calling Protocol.Disconnect ()");
protocol.Disconnect ();
+ }
Application.Quit ();
diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs
index d2fb6dd..bc238c4 100644
--- a/Dizzy/Protocol.cs
+++ b/Dizzy/Protocol.cs
@@ -183,20 +183,12 @@ namespace Dizzy
public void Disconnect ()
{
- /*foreach(FileTransfer t in this.transfers)
+ foreach(FileTransfer t in this.transfers)
{
+ Log.Info ("Stopping transfer");
t.Stop ();
}
- foreach(Thread t in this.threads)
- {
- if(t.IsAlive)
- t.Abort ();
- }
- if(this.finder != null && this.finder.IsAlive)
- {
- this.finder.Abort ();
- }
- */
+
}
@@ -227,12 +219,15 @@ namespace Dizzy
try {
FileTransfer transfer = new FileTransfer (f, this.config.GetValue("user"), this.config.password, downloadFolder);
this.transfers.Add (transfer);
- } catch (Exception e) {
-
+ transfer.Start ();
+ } catch (Exception e) {
Log.Error (e.Message);
this.config.authenticated = false;
- this.Download (f, downloadFolder);
+
+ EventManager.ErrorMessage ("Autenticazione fallita");
}
+
+
}
public void Upload(string f)
@@ -260,11 +255,12 @@ namespace Dizzy
try {
FileUpload 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;
- this.Upload (f);
+ EventManager.ErrorMessage ("Autenticazione fallita");
}
}
@@ -301,6 +297,10 @@ namespace Dizzy
}
+ public void Abort () {
+ this.sftp.Cancel ();
+ }
+
private void TransferStartedHandler(string src, string dest, int transferredBytes,
int totalBytes, string message)
{
@@ -398,6 +398,7 @@ namespace Dizzy
Gtk.TreeIter iter;
SFTPConnection sftp;
+ string downloadFolder;
public delegate void Handler(string src, string dest, int transferredBytes,
int totalBytes, string message);
@@ -407,6 +408,7 @@ namespace Dizzy
// Connessione al server
this.sftp = new SFTPConnection (user, password);
this.sftp.Connect ();
+ this.downloadFolder = downloadFolder;
this.file = f;
@@ -414,12 +416,17 @@ namespace Dizzy
sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress);
sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped);
- sftp.Download (this.file, downloadFolder);
+ }
+
+ public void Start ()
+ {
+ sftp.Download (this.file, this.downloadFolder);
sftp.Disconnect ();
}
public void Stop ()
{
+ this.sftp.Abort ();
this.sftp.Disconnect ();
}
@@ -468,6 +475,10 @@ namespace Dizzy
sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress);
sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped);
+ }
+
+ public void Start ()
+ {
sftp.Upload (this.filename);
sftp.Disconnect ();
}