From aa54c23d30a43c84101bce965aae2200b8042366 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 10 Feb 2010 09:47:27 +0100 Subject: [PATCH] Aggiunta gestione degli eventi con finestre (ovvero: quando succede qualcosa di problematico l'utente viene avvisato senza che le gtk vadano in crash). --- Dizzy.csproj | 1 + Dizzy/EventManager.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ Dizzy/MainWindow.cs | 14 +------------- Dizzy/Protocol.cs | 3 +-- gtk-gui/MainWindow.cs | 1 + gtk-gui/gui.stetic | 40 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 Dizzy/EventManager.cs diff --git a/Dizzy.csproj b/Dizzy.csproj index 16d3ead..ff280a4 100644 --- a/Dizzy.csproj +++ b/Dizzy.csproj @@ -95,6 +95,7 @@ + diff --git a/Dizzy/EventManager.cs b/Dizzy/EventManager.cs new file mode 100644 index 0000000..393e660 --- /dev/null +++ b/Dizzy/EventManager.cs @@ -0,0 +1,43 @@ + +using System; +using Gtk; + +namespace Dizzy +{ + + /* + * Problema: Supponiamo di avere un thread disperso per il programma + * che ad un certo punto decide che deve comunicare all'utente che è + * successo un gran casino. Come va? + * + * Soluzione 1: Emette un evento che da qualche altra parte è stato + * collegato ad una funzione che crea un dialog. Questo crea problemi + * con il fatto che le chiamate alle gtk vengono fatte dal thread sbagliato. + * + * Soluzione attuale: Riceviamo le chiamate qua dentro. Questo oggetto + * inserisce le chiamate corrette nel thread principale. + */ + + public class EventManager + { + + public EventManager () {} + + // Metodo generico per segnalare un'errore dell'applicazione. + public static void ErrorMessage (string message) { + + GLib.Idle.Add(delegate { + Log.Error (message); + + MessageDialog d = new Gtk.MessageDialog(null, + Gtk.DialogFlags.DestroyWithParent, + Gtk.MessageType.Error, + Gtk.ButtonsType.Ok, ""); + d.Markup = message; + d.Run (); + d.Destroy (); + return false; + }); + } + } +} diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs index 95fc4db..24ea7e1 100644 --- a/Dizzy/MainWindow.cs +++ b/Dizzy/MainWindow.cs @@ -52,19 +52,7 @@ public partial class MainWindow : Gtk.Window } - public static bool OnAuthenticationFailed () { - - 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; - } + protected void OnDeleteEvent (object sender, DeleteEventArgs a) diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index 65bc3ee..79a59af 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -152,8 +152,7 @@ namespace Dizzy if(!this.config.authenticated) { - // Chiamiamo questo con Glib per non far crashare tutto. - GLib.Idle.Add (new GLib.IdleHandler(MainWindow.OnAuthenticationFailed)); + EventManager.ErrorMessage ("Autenticazione fallita"); } else { diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs index b07e19b..974702f 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -246,6 +246,7 @@ public partial class MainWindow { this.label3.ShowAll(); // Container child notebook1.Gtk.Notebook+NotebookChild this.table2 = new Gtk.Table(((uint)(4)), ((uint)(2)), false); + this.table2.Name = "table2"; this.table2.RowSpacing = ((uint)(6)); this.table2.ColumnSpacing = ((uint)(6)); this.table2.BorderWidth = ((uint)(5)); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index 71809dc..b969804 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -640,7 +640,7 @@ Libro - + CenterOnParent 2 @@ -650,7 +650,43 @@ Libro 2 - + + + 6 + + + + 64 + 64 + stock:gtk-dialog-error Menu + + + 0 + True + False + False + + + + + + label4 + True + + + 1 + True + False + False + + + + + 0 + True + False + False + -- 2.1.4