Aggiunta gestione degli eventi con finestre (ovvero: quando succede
Leonardo Robol [2010-02-10 08:47]
Aggiunta gestione degli eventi con finestre (ovvero: quando succede
qualcosa di problematico l'utente viene avvisato senza che le gtk
vadano in crash).
diff --git a/Dizzy.csproj b/Dizzy.csproj
index 16d3ead..ff280a4 100644
--- a/Dizzy.csproj
+++ b/Dizzy.csproj
@@ -95,6 +95,7 @@
<Compile Include="Dizzy\TaskTreeView.cs" />
<Compile Include="Dizzy\AssemblyInfo.cs" />
<Compile Include="Dizzy\Log.cs" />
+ <Compile Include="Dizzy\EventManager.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Dizzy\app.desktop">
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</property>
</widget>
</child>
</widget>
- <widget class="Gtk.Dialog" id="Dizzy.ErrorDialog" design-size="400 300">
+ <widget class="Gtk.Dialog" id="Dizzy.ErrorDialog" design-size="210 131">
<property name="MemberName" />
<property name="WindowPosition">CenterOnParent</property>
<property name="Buttons">2</property>
@@ -650,7 +650,43 @@ Libro</property>
<property name="MemberName" />
<property name="BorderWidth">2</property>
<child>
- <placeholder />
+ <widget class="Gtk.HBox" id="hbox2">
+ <property name="MemberName" />
+ <property name="Spacing">6</property>
+ <child>
+ <widget class="Gtk.Image" id="image1">
+ <property name="MemberName" />
+ <property name="WidthRequest">64</property>
+ <property name="HeightRequest">64</property>
+ <property name="Pixbuf">stock:gtk-dialog-error Menu</property>
+ </widget>
+ <packing>
+ <property name="Position">0</property>
+ <property name="AutoSize">True</property>
+ <property name="Expand">False</property>
+ <property name="Fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="Gtk.Label" id="message">
+ <property name="MemberName" />
+ <property name="LabelProp" translatable="yes">label4</property>
+ <property name="UseMarkup">True</property>
+ </widget>
+ <packing>
+ <property name="Position">1</property>
+ <property name="AutoSize">True</property>
+ <property name="Expand">False</property>
+ <property name="Fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="Position">0</property>
+ <property name="AutoSize">True</property>
+ <property name="Expand">False</property>
+ <property name="Fill">False</property>
+ </packing>
</child>
</widget>
</child>