[smuxi/stable] Frontend(-GNOME): fixed frontend commands with smuxi-server < 0.10
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/stable] Frontend(-GNOME): fixed frontend commands with smuxi-server < 0.10
- Date: Sun, 12 Jan 2014 07:24:26 +0000 (UTC)
commit d9ddbec5b6b69de7acad786744b8e5e402f9fbc9
Author: Mirco Bauer <meebey meebey net>
Date: Sat Jan 11 23:51:02 2014 +0100
Frontend(-GNOME): fixed frontend commands with smuxi-server < 0.10
Session.AddMessageToFrontend() was introduced with Smuxi 0.10 and thus we can't
simply assume it is available. So we check engine version now and fallback to
the unoptimized Session.AddMessageToChat() if needed.
src/Frontend-GNOME/Entry.cs | 1 +
src/Frontend-GNOME/Frontend.cs | 2 +-
src/Frontend/CommandManager.cs | 28 +++++++++++++++++++++++-----
3 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/Frontend-GNOME/Entry.cs b/src/Frontend-GNOME/Entry.cs
index 6258c69..1fdc580 100644
--- a/src/Frontend-GNOME/Entry.cs
+++ b/src/Frontend-GNOME/Entry.cs
@@ -849,6 +849,7 @@ namespace Smuxi.Frontend.Gnome
_CommandManager = null;
} else {
_CommandManager = new CommandManager(Frontend.Session);
+ _CommandManager.EngineVersion = Frontend.EngineVersion;
_CommandManager.ExceptionEvent +=
delegate(object sender, CommandExceptionEventArgs e) {
Gtk.Application.Invoke(delegate {
diff --git a/src/Frontend-GNOME/Frontend.cs b/src/Frontend-GNOME/Frontend.cs
index eb9b7ee..cb79c5c 100644
--- a/src/Frontend-GNOME/Frontend.cs
+++ b/src/Frontend-GNOME/Frontend.cs
@@ -456,9 +456,9 @@ namespace Smuxi.Frontend.Gnome
Thread.Sleep(30 * 1000);
}
}
- Session = _MainWindow.EngineManager.Session;
_UserConfig = _MainWindow.EngineManager.UserConfig;
EngineVersion = _MainWindow.EngineManager.EngineVersion;
+ Session = _MainWindow.EngineManager.Session;
Gtk.Application.Invoke(delegate {
Frontend.ConnectEngineToGUI();
diff --git a/src/Frontend/CommandManager.cs b/src/Frontend/CommandManager.cs
index 6e3773b..b8c445c 100644
--- a/src/Frontend/CommandManager.cs
+++ b/src/Frontend/CommandManager.cs
@@ -52,6 +52,8 @@ namespace Smuxi.Frontend
TaskQueue f_TaskQueue;
TimeSpan f_LastCommandTimeSpan;
+ public Version EngineVersion { get; set; }
+
public TimeSpan LastCommandTimeSpan {
get {
return f_LastCommandTimeSpan;
@@ -236,7 +238,7 @@ namespace Smuxi.Frontend
cmd.CommandCharacter, output));
} else {
var msg = new MessageBuilder().AppendText(output).ToMessage();
- f_Session.AddMessageToFrontend(cmd, msg);
+ AddMessageToFrontend(cmd, msg);
}
};
@@ -283,7 +285,7 @@ namespace Smuxi.Frontend
AppendErrorText("Executing '{0}' failed with: {1}",
command, ex.Message).
ToMessage();
- f_Session.AddMessageToFrontend(cmd, msg);
+ AddMessageToFrontend(cmd, msg);
}
}
}
@@ -296,7 +298,7 @@ namespace Smuxi.Frontend
AppendEventPrefix().
AppendText(cmd.Parameter).
ToMessage();
- f_Session.AddMessageToFrontend(cmd, msg);
+ AddMessageToFrontend(cmd, msg);
}
public void CommandGenerateMessages(CommandModel cmd, IChatView chat)
@@ -343,7 +345,7 @@ namespace Smuxi.Frontend
AppendEventPrefix().
AppendText(_("Unknown Command: {0}"), cmd.Command).
ToMessage();
- f_Session.AddMessageToFrontend(cmd, msg);
+ AddMessageToFrontend(cmd, msg);
}
void NotEnoughParameters(CommandModel cmd)
@@ -352,7 +354,7 @@ namespace Smuxi.Frontend
AppendEventPrefix().
AppendText(_("Not enough parameters for {0} command"), cmd.Command).
ToMessage();
- f_Session.AddMessageToFrontend(cmd, msg);
+ AddMessageToFrontend(cmd, msg);
}
MessageBuilder CreateMessageBuilder()
@@ -360,6 +362,22 @@ namespace Smuxi.Frontend
return new MessageBuilder();
}
+ void AddMessageToFrontend(CommandModel cmd, MessageModel msg)
+ {
+ if (cmd == null) {
+ throw new ArgumentNullException("cmd");
+ }
+ if (msg == null) {
+ throw new ArgumentNullException("msg");
+ }
+
+ if (EngineVersion != null && EngineVersion >= new Version(0, 10)) {
+ f_Session.AddMessageToFrontend(cmd, msg);
+ } else {
+ f_Session.AddMessageToChat(cmd.Chat, msg);
+ }
+ }
+
protected virtual void OnTaskQueueExceptionEvent(object sender, TaskQueueExceptionEventArgs e)
{
Trace.Call(sender, e);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]