From 46a5ad0c3f326deda29dc9b1662933ddcfa7e309 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Tue, 9 Feb 2010 23:58:01 +0100 Subject: [PATCH] =?UTF-8?q?Ora=20sembra=20non=20crashare=20pi=C3=B9=20con?= =?UTF-8?q?=20l'evento=20AuthenticationFailed=20()=20anche=20perch=C3=A9?= =?UTF-8?q?=20l'ho=20rimosso=20:).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dizzy.csproj | 1 + Dizzy/Main.cs | 1 - Dizzy/MainWindow.cs | 27 ++++++++--------- Dizzy/Protocol.cs | 82 ++++++++++++++++++++++++++------------------------- gtk-gui/MainWindow.cs | 1 + gtk-gui/gui.stetic | 59 +++++++++++++++++++++++++++++++++++- 6 files changed, 115 insertions(+), 56 deletions(-) diff --git a/Dizzy.csproj b/Dizzy.csproj index 0c709c2..16d3ead 100644 --- a/Dizzy.csproj +++ b/Dizzy.csproj @@ -94,6 +94,7 @@ + diff --git a/Dizzy/Main.cs b/Dizzy/Main.cs index a3eec63..b22d3d1 100644 --- a/Dizzy/Main.cs +++ b/Dizzy/Main.cs @@ -19,7 +19,6 @@ namespace Dizzy // Cosa vogliamo fare MainWindow win; - win = new MainWindow (ref config); win.ShowAll (); diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs index 90882d5..0aa539f 100644 --- a/Dizzy/MainWindow.cs +++ b/Dizzy/MainWindow.cs @@ -31,7 +31,7 @@ public partial class MainWindow : Gtk.Window this.protocol = new Protocol (ref this.config); this.protocol.AuthenticationRequired += this.Connect; - this.protocol.AuthenticationFailed += this.OnAuthenticationFailed; + // this.protocol.AuthenticationFailed += this.OnAuthenticationFailed; } protected void Connect () @@ -45,19 +45,18 @@ public partial class MainWindow : Gtk.Window } - public void OnAuthenticationFailed () { + public static bool OnAuthenticationFailed () { - Console.WriteLine ("Auth Failed"); - // return; - Gtk.MessageDialog dialog = new Gtk.MessageDialog(this, - DialogFlags.Modal, - MessageType.Error, - ButtonsType.Ok, - true, - ""); - dialog.Markup = "Autenticazione fallita"; - dialog.Run (); - // dialog.Destroy (); + Log.Error ("Autenticazione fallita"); + + MessageDialog d = new Gtk.MessageDialog(null, + Gtk.DialogFlags.DestroyWithParent, + Gtk.MessageType.Error, + Gtk.ButtonsType.Ok, ""); + d.Markup = "Autenticazione fallita."; + d.Run (); + d.Destroy (); + return false; } @@ -83,7 +82,7 @@ public partial class MainWindow : Gtk.Window protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) { - Console.WriteLine("row_activated called"); + File f = this.files.GetFileFromPath (args.Path); // Piccolo hack per evitare che ci freghino :) diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index 5c56a77..4d22c2f 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -40,8 +40,11 @@ namespace Dizzy GlobalConfig config; public delegate void ProtocolEvent (); + + // Questo evento sembra non dare problemi perché ogni volta che + // è emesso aspettiamo che l'utente inserisca i dati necessari + // con while(!this.config.authenticated) {} public event ProtocolEvent AuthenticationRequired; - public event ProtocolEvent AuthenticationFailed; public Protocol (ref GlobalConfig config) { @@ -53,18 +56,18 @@ namespace Dizzy { if (this.finder != null && this.finder.IsAlive) { - Console.WriteLine (" => Ricerca in corso"); + Log.Info ("Ricerca in corso"); return; } if (!System.IO.File.Exists(this.config.ListFileName ())) { - this.UpdateFileList (); // Dovremmo notificare l'utente che non c'è la lista - Console.WriteLine (" => Ops, non c'è la lista!"); + Log.Warning ("La lista non è presente, chiedo di scaricarla"); + this.UpdateFileList (); } else { - Console.WriteLine (" => Comincio a cercare..."); + Log.Info ("Avvio la ricerca nel database"); this.keyword = keyword; this.fileTreeView = f; this.finder = new Thread(new ThreadStart (this._Search)); @@ -103,11 +106,11 @@ namespace Dizzy { if(this.listUpdater != null && this.listUpdater.IsAlive) { - Console.WriteLine (" => Lista in fase di aggiornamento"); + Log.Warning ("La lista è già in fase di aggiornamento, non faccio nulla"); return; } - this.listUpdater = new Thread( new ThreadStart (this._UpdateFileList)); + this.listUpdater = new Thread (new ThreadStart (this._UpdateFileList)); this.listUpdater.Start (); } @@ -119,32 +122,43 @@ namespace Dizzy if (!this.config.authenticated) { - Console.WriteLine ("Requesting authentication..."); + Log.Info ("I dati di autenticazione non sono presenti"); this.AuthenticationRequired (); // Aspetto che l'utente abbia fatto. while(!this.config.authenticated) {} - Console.WriteLine ("Ok, ora siamo autenticati"); + Log.Info ("Ho acquisito utente e password"); } + // Inizializziamo la connessione con i dati che supponiamo + // di avere. + s = new SFTPConnection (this.config.GetValue("user"), + this.config.password); + Log.Info ("Oggetto SFTPConnection creato"); + try { - s = new SFTPConnection (this.config.GetValue("user"), - this.config.password); s.Connect (); } catch (Exception e) { - Console.WriteLine ("mmm... {0}", e.Message); + Log.Error ("Autenticazione errata (" + e.Message + ")"); this.config.authenticated = false; - this.AuthenticationFailed (); - return; } - - Console.WriteLine (" => Aggiorno la lista"); - s.Download (new File("/nobackup/robol/index.db", "robol"), - this.config.ConfigDir ()); - Console.WriteLine (" => Lista aggiornata"); - s.Disconnect (); + if(!this.config.authenticated) + { + // Chiamiamo questo con Glib per non far crashare tutto. + GLib.Idle.Add (new GLib.IdleHandler(MainWindow.OnAuthenticationFailed)); + } + else + { + Log.Info ("Aggiornamento della lista"); + + s.Download (new File("/nobackup/robol/index.db", "robol"), + this.config.ConfigDir ()); + + Log.Info ("Lista Aggiornata"); + s.Disconnect (); + } } @@ -173,7 +187,7 @@ namespace Dizzy if (!this.config.authenticated) this.AuthenticationRequired (); while(!this.config.authenticated) {} - Console.WriteLine ("Ok, ora possiamo andare"); + Log.Info ("Dati di autenticazione trovati, procedo con il download"); ArrayList args = new ArrayList (); args.Add (f); @@ -192,13 +206,14 @@ namespace Dizzy File f = (File) ((ArrayList) args)[0]; TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1]; string downloadFolder = (string) ((ArrayList) args)[2]; - Console.WriteLine (" => Download starting"); + Log.Info ("Avvio il download"); try { FileTransfer transfer = new FileTransfer (f, ref tasks, this.config.GetValue("user"), this.config.password, downloadFolder); this.transfers.Add (transfer); } catch (Exception e) { - Console.WriteLine(e.Message); + + Log.Error (e.Message); this.config.authenticated = false; this.Download (f, ref tasks, downloadFolder); } @@ -236,8 +251,7 @@ namespace Dizzy private void TransferStartedHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { - Console.WriteLine (" => TransferStarted"); - + Log.Info ("Il download si è avviato"); if(TransferStarted != null) TransferStarted(src, dest, transferredBytes, totalBytes, message); } @@ -311,17 +325,7 @@ namespace Dizzy public void Download(File f, string downloadFolder) { - Console.WriteLine (" => Getting {0}", f.name); - // try - // { - Console.WriteLine (f.path); - this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name); - // } - /* catch() - { - Console.WriteLine("Error in Get... "); - Console.WriteLine(e.Message); - } */ + this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name); } public void Disconnect () @@ -355,7 +359,7 @@ namespace Dizzy sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress); sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped); - Console.WriteLine(" => Starting sftp command"); + Log.Info ("Eseguo SFTPConnection.Download ()"); sftp.Download (this.file, downloadFolder); sftp.Disconnect (); } @@ -368,15 +372,13 @@ namespace Dizzy public void OnTransferStarted (string src, string dest, int transferredBytes, int totalBytes, string message) { - Console.WriteLine(" => TransferStarted received"); + Log.Info ("Evento TransferStart () ricevuto"); this.iter = this.tasks.AddTask(file.name, 0); } public void OnTransferProgress(string src, string dest, int transferredBytes, int totalBytes, string message) { - // if(message != "") - // Console.WriteLine(message); int perc = transferredBytes / (totalBytes / 100); this.tasks.SetProgress(this.iter, perc); } diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs index ea99b78..b043054 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -92,6 +92,7 @@ public partial class MainWindow { // Container child vbox1.Gtk.Box+BoxChild this.notebook1 = new Gtk.Notebook(); this.notebook1.CanFocus = true; + this.notebook1.Name = "notebook1"; this.notebook1.CurrentPage = 2; // Container child notebook1.Gtk.Notebook+NotebookChild this.vbox3 = new Gtk.VBox(); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index f98f3a6..0d942e9 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -6,7 +6,7 @@ - + @@ -560,4 +560,61 @@ Libro + + + CenterOnParent + 2 + False + + + + 2 + + + + + + + + + 10 + 5 + 2 + End + + + + True + True + True + StockItem + gtk-cancel + -6 + gtk-cancel + + + False + False + + + + + + True + True + True + StockItem + gtk-ok + -5 + gtk-ok + + + 1 + False + False + + + + + \ No newline at end of file -- 2.1.4