using System;
using Mono.Unix;
using Mono.Unix.Native;
using Banshee.Base;
using Banshee.Sources;
using Banshee.Configuration;
using Banshee.Dap;
public static class PluginModuleEntry
{
public static Type [] GetTypes()
{
return new Type [] {
typeof(Banshee.Plugins.DapCommand.DapCommandPlugin)
};
}
}
namespace Banshee.Plugins.DapCommand
{
public class DapCommandPlugin : Banshee.Plugins.Plugin
{
protected override string ConfigurationName { get { return "dapcommand"; } }
public override string DisplayName { get { Catalog.GetString ("Custom Dap Command"); } }
private const string SchemaNamespace = "plugins." + ConfigurationName;
public override string Description {
get {
return Catalog.GetString(
"Executes a user configured command after an audio player is " +
"synchronized."
);
}
}
public override string [] Authors {
get {
return new string [] {
"Richard Bailey",
"David Bailey"
};
}
}
// --------------------------------------------------------------- //
protected override void PluginInitialize()
{
Console.WriteLine("Initializing DapCommandPlugin");
DapDevice.SaveFinished += OnDapSaveFinished;
}
private void OnDapSaveFinished (object o, DapEventArgs args)
{
string command;
string [] argv;
// check if enabled
if (Enabled) {
// if command is set
command = Command;
if (command != null && command != "") {
// if command exists and is executable
if (Syscall.access (command, X_OK))
// then run command
Syscall.execv (command, argv);
}
}
}
internal bool Enabled {
get { return EnabledSchema.Get(); }
set {
EnabledSchema.Set(value);
}
}
internal string Command {
get { return CommandSchema.Get(); }
set {
CommandSchema.Set(value);
}
}
public static readonly SchemaEntry<bool> EnabledSchema = new SchemaEntry<bool>(
SchemaNamespace, "enabled",
true,
"Plugin enabled",
"Dap custom command plugin enabled"
);
public static readonly SchemaEntry<string> CommandSchema = new SchemaEntry<string>(
SchemaNamespace, "command",
String.Empty,
"Command",
"Custom command to be executed"
);
// // optional, this is a virtual override, only
// // only provide an implementation if there are
// // resources to dispose of or other objects that
// // need notification, etc.
// protected override void PluginDispose()
// {
// Console.WriteLine("Disposing Sample Plugin");
// GLib.Source.Remove(timeout_id);
// timeout_id = 0;
// SourceManager.RemoveSource(source);
// }
//
// // optional, this is a virtual override, only
// // provide an implementation if there is a
// // configuration GUI to show
// private Gtk.Button button = new Gtk.Button("Configure Me");
//
// public override Gtk.Widget GetConfigurationWidget()
// {
// return button;
// }
//
// private bool OnTimeout()
// {
// int track_id = Convert.ToInt32(Globals.Library.Db.QuerySingle(
// "SELECT TrackID FROM Tracks ORDER BY RANDOM() LIMIT 1"));
// Console.WriteLine(Globals.Library.GetTrack(track_id));
// return true;
// }
}
}