268 lines
8.7 KiB
C#
268 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Virtuoso.Miranda.Plugins;
|
|
using Virtuoso.Miranda.Plugins.Infrastructure;
|
|
using Virtuoso.Hyphen.Mini;
|
|
using Virtuoso.Hyphen.Mini.Custom;
|
|
using Virtuoso.Miranda.Plugins.ThirdParty.Updater;
|
|
using System.Windows.Forms;
|
|
using Speak;
|
|
using Speak.Opt;
|
|
using Speak.Storage;
|
|
using Speak.TTS;
|
|
using Speak.Structs;
|
|
|
|
[assembly: ExposingPlugin(typeof(MainClass))]
|
|
|
|
namespace Speak
|
|
{
|
|
/// <summary>
|
|
/// MainClass of Speak
|
|
/// </summary>
|
|
public class MainClass : StandalonePlugin
|
|
{
|
|
/// <summary>
|
|
/// Get Version
|
|
/// </summary>
|
|
public const String VERSION = "1.0.1.1";
|
|
|
|
private Options option;
|
|
private DateTime status_pause = DateTime.Now;
|
|
private Dictionary<string, StatusMode> statusmodes = new Dictionary<string, StatusMode>();
|
|
|
|
private MainClass()
|
|
{
|
|
this.option = new Options();
|
|
this.option.Changed += new Options.ChangedEventHandler(option_hasUpdated);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Run after the Plugin Initialisation
|
|
/// </summary>
|
|
protected override void AfterPluginInitialization()
|
|
{
|
|
option_hasUpdated(Options.EventChanged.Active);
|
|
option_hasUpdated(Options.EventChanged.Announce);
|
|
option_hasUpdated(Options.EventChanged.Engine);
|
|
RegisterUpdate();
|
|
EventManager.CreateEventHook(API.ME_OPT_INITIALISE, this.option.Opts, this);
|
|
EventManager.CreateEventHook(API.ME_DB_EVENT_ADDED, Message, this);
|
|
EventManager.CreateEventHook(API.ME_DB_CONTACT_SETTINGCHANGED, StatusChange, this);
|
|
Protocol.StatusChanged += StatusModeChange;
|
|
SpeakWelcome();
|
|
}
|
|
|
|
private bool StatusModeChange(object sender, ProtocolStatusChangeEventArgs e)
|
|
{
|
|
StatusMode old = StatusMode.Offline;
|
|
StatusMode neu = e.NewStatus;
|
|
if (statusmodes.ContainsKey(e.Protocol.Name))
|
|
{
|
|
old = statusmodes[e.Protocol.Name];
|
|
statusmodes[e.Protocol.Name] = neu;
|
|
}
|
|
else
|
|
{
|
|
statusmodes.Add(e.Protocol.Name, neu);
|
|
}
|
|
if (!Settings.getInstance().getActiveConnect())
|
|
{
|
|
if (old == StatusMode.Offline && neu != StatusMode.Offline)
|
|
{
|
|
this.status_pause = DateTime.Now.AddSeconds(5);
|
|
}
|
|
}
|
|
if (!Settings.getInstance().getActiveDisconnect())
|
|
{
|
|
if (old != StatusMode.Offline && neu == StatusMode.Offline)
|
|
{
|
|
this.status_pause = DateTime.Now.AddSeconds(5);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected override void BeforePluginDisable()
|
|
{
|
|
EventManager.RemoveEventHook(API.ME_OPT_INITIALISE, this);
|
|
EventManager.RemoveEventHook(API.ME_DB_EVENT_ADDED, this);
|
|
EventManager.RemoveEventHook(API.ME_DB_CONTACT_SETTINGCHANGED, this);
|
|
Protocol.StatusChanged -= null;
|
|
TextToSpeak.getInstance().Stop();
|
|
}
|
|
|
|
private int Message(UIntPtr wParam, IntPtr lParam)
|
|
{
|
|
DatabaseEventInfo d = DatabaseEventInfo.FromHandle(lParam);
|
|
if (d.Type == DatabaseEventType.Message && !((d.Flags & DatabaseEventProperties.Sent) == DatabaseEventProperties.Sent))
|
|
{
|
|
ContactInfo c = ContactInfo.FromHandle(wParam);
|
|
Settings s = Settings.getInstance();
|
|
if (s.canMessageRead(d.Data, c.UniqueID.ToString()))
|
|
{
|
|
TextToSpeak tts = TextToSpeak.getInstance();
|
|
string text = String.Format(s.getSpeakString(), c.DisplayName, d.Data);
|
|
string sig = text + d.Timestamp;
|
|
//MessageBox.Show(sig);
|
|
tts.speak(text, sig);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private int StatusChange(UIntPtr wParam, IntPtr lParam)
|
|
{
|
|
ContactInfo c = ContactInfo.FromHandle(wParam);
|
|
if (c.UniqueID == null) //Unknown User (maybe myself)
|
|
{
|
|
return 0;
|
|
}
|
|
Settings s = Settings.getInstance();
|
|
if (s.hasChangedStatus(c.UniqueID.ToString(), c.Status.ToString()))
|
|
{
|
|
if (s.canStatusRead(c.UniqueID.ToString()))
|
|
{
|
|
if (status_pause <= DateTime.Now)
|
|
{
|
|
TextToSpeak tts = TextToSpeak.getInstance();
|
|
string text = String.Format(s.getStatusString(c.Status), c.DisplayName, c.Status.ToString());
|
|
tts.speak(text, text + DateTime.Now.Ticks.ToString());
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private void option_hasUpdated(Options.EventChanged e)
|
|
{
|
|
if (e == Options.EventChanged.Engine)
|
|
{
|
|
TextToSpeak tts = TextToSpeak.getInstance();
|
|
tts.setVoice(Options.readDBString("engine", "speak_config"));
|
|
tts.setVolume(int.Parse(Options.readDBLong("volume", "speak_config").ToString()));
|
|
tts.setRate(int.Parse(Options.readDBLong("rate", "speak_config").ToString()));
|
|
tts.setPitch(int.Parse(Options.readDBLong("pitch", "speak_config").ToString()));
|
|
}
|
|
if (e == Options.EventChanged.Active)
|
|
{
|
|
Settings s = Settings.getInstance();
|
|
s.ReadContactList();
|
|
}
|
|
if (e == Options.EventChanged.Announce)
|
|
{
|
|
Settings s = Settings.getInstance();
|
|
s.SetGlobalSettings();
|
|
}
|
|
}
|
|
|
|
private void SpeakWelcome()
|
|
{
|
|
TextToSpeak tts = TextToSpeak.getInstance();
|
|
tts.speak(Options.readDBString("welcome_msg", "speak_config"), "welcome" + DateTime.Now);
|
|
}
|
|
|
|
private void RegisterUpdate()
|
|
{
|
|
try
|
|
{
|
|
Update update = new Update(this, new Uri(this.HomePage.ToString() + "files/speak_last.zip"), new Uri(this.HomePage.ToString() + "files/speak_updater_version.txt"), " ");
|
|
UpdaterPlugin.RegisterForUpdate(update);
|
|
}
|
|
catch (NotSupportedException) { }
|
|
}
|
|
|
|
#region Constants
|
|
/// <summary>
|
|
/// Get Author
|
|
/// </summary>
|
|
public override string Author
|
|
{
|
|
get { return "BlubbFish"; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Description
|
|
/// </summary>
|
|
public override string Description
|
|
{
|
|
get { return ".NET Speak Provider"; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get HasOptions
|
|
/// </summary>
|
|
public override bool HasOptions
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Hompage
|
|
/// </summary>
|
|
public override Uri HomePage
|
|
{
|
|
get { return new Uri("http://miranda.blubbfish.net"); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Name
|
|
/// </summary>
|
|
public override string Name
|
|
{
|
|
get { return "Speak"; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Version
|
|
/// </summary>
|
|
public override Version Version
|
|
{
|
|
get { return new Version(VERSION); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get AutorEmail
|
|
/// </summary>
|
|
public override string AuthorEmail
|
|
{
|
|
get { return "dev@blubbfish.net"; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Copyright String
|
|
/// </summary>
|
|
public override string Copyright
|
|
{
|
|
get { return "2013 © BlubbFish"; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get GUID PrluginInterfaces
|
|
/// </summary>
|
|
public override Guid[] PluginInterfaces
|
|
{
|
|
get { return new Guid[] { uuid }; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get ReplaceDefaultModule
|
|
/// </summary>
|
|
public override int ReplacesDefaultModule
|
|
{
|
|
get { return 0; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get GUID
|
|
/// </summary>
|
|
public override Guid UUID
|
|
{
|
|
get { return uuid; }
|
|
}
|
|
|
|
private static readonly Guid uuid = new Guid("65BC8980-1028-40A4-A52F-440C48035E02");
|
|
#endregion
|
|
}
|
|
}
|