diff --git a/Dizzy.csproj b/Dizzy.csproj
index 0c709c2..16d3ead 100644
--- a/Dizzy.csproj
+++ b/Dizzy.csproj
@@ -94,6 +94,7 @@
<Compile Include="Dizzy\Protocol.cs" />
<Compile Include="Dizzy\TaskTreeView.cs" />
<Compile Include="Dizzy\AssemblyInfo.cs" />
+ <Compile Include="Dizzy\Log.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Dizzy\app.desktop">
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 @@
</configuration>
<import>
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
- <widget-library name="../bin/Debug/Dizzy.exe" internal="true" />
+ <widget-library name="../bin/Release/Dizzy.exe" internal="true" />
</import>
<widget class="Gtk.Window" id="MainWindow" design-size="474 300">
<property name="MemberName" />
@@ -560,4 +560,61 @@ Libro</property>
</widget>
</child>
</widget>
+ <widget class="Gtk.Dialog" id="Dizzy.ErrorDialog" design-size="400 300">
+ <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>
+ <placeholder />
+ </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