Coding

Obsolete

The functionality of this plugin has been rolled into MuinePluginsUnofficial.

Why Cuckoo?

Someone just asked. If you have a cool plugin you want, just ask for someone to make it on the Muine-List, and someone may hear your plea. As it goes, this plugin has been very useful and an asset to my waking up on time.

Requirements

  • Muine 8.2+

Installation

cd ~/.gnome2/muine/plugins
wget http://www.public.asu.edu/~bnickel/Cuckoo/Cuckoo.cs
wget http://www.public.asu.edu/~bnickel/Cuckoo/Cuckoo.glade
mcs -target:library -out:Cuckoo.dll Cuckoo.cs -pkg:muine-plugin\
 -pkg:glade-sharp -pkg:gconf-sharp -res:Cuckoo.glade
[[Restart "muine"]]

Files

Cuckoo.cs Source

// Cuckoo.cs - Muine GNotify Plugin
// Copyright (C) 2005 Brian Nickel <kerrick@asu.edu>
// Licensed under GNU GPL V2.

using Muine.PluginLib;
using System;
using Gtk;

public class Cuckoo : Plugin
{
	private IPlayer player;
	private GConf.Client gconf_client;
	
	[Glade.Widget]
	private Button CloseButton;
	[Glade.Widget]
	private CheckButton EnableCheckButton;
	[Glade.Widget]
	private ComboBox VolumeComboBox;
	[Glade.Widget]
	private SpinButton HourSpinButton;
	[Glade.Widget]
	private SpinButton MinuteSpinButton;
	[Glade.Widget]
	private Window AlarmClockWindow;

	public override void Initialize(IPlayer player)
	{
		this.player = player;
		gconf_client = new GConf.Client ();
		
		ActionEntry [] action_entries = new Gtk.ActionEntry [] {
			new ActionEntry ("SetAlarm", Gtk.Stock.Properties, "Set _Alarm ",
			"<control><shift>A", null, new EventHandler (OnSetAlarm))
		};
		ActionGroup action_group = new ActionGroup ("CuckooPluginActions");
		action_group.Add (action_entries);

		player.UIManager.InsertActionGroup (action_group, -1);
		player.UIManager.AddUi (this.player.UIManager.NewMergeId (),
		"/MenuBar/FileMenu/ExtraFileActions", "SetAlarmMenuItem", "SetAlarm",
		UIManagerItemType.Menuitem, false);
		
		Glade.XML glade_xml = new Glade.XML (null, "Cuckoo.glade",
		"AlarmClockWindow", null);
		glade_xml.Autoconnect (this);
		GLib.Timeout.Add (60000, new GLib.TimeoutHandler (OnTick));
	}
	
	private void OnSetAlarm (object sender, EventArgs e)
	{
		EnableCheckButton.Active = Enabled;
		VolumeComboBox.Active = Volume;
		HourSpinButton.Value = (double)Hour;
		MinuteSpinButton.Value = (double)Minute;
		AlarmClockWindow.Show ();
	}
	private void OnCloseButtonClicked (object sender, EventArgs e)
	{
		AlarmClockWindow.Hide ();
	}
	private void OnAlarmClockWindowDeleteEvent (object sender, DeleteEventArgs e)
	{
		AlarmClockWindow.Hide ();
		e.RetVal = true;
	}
	private void OnEnableCheckButtonToggled (object sender, EventArgs e)
	{
		bool enabled = EnableCheckButton.Active;
		Enabled = enabled;
		VolumeComboBox.Sensitive = enabled;
		HourSpinButton.Sensitive = enabled;
		MinuteSpinButton.Sensitive = enabled;
	}
	private void OnHourSpinButtonValueChanged (object sender, EventArgs e)
	{
		Hour = HourSpinButton.ValueAsInt;
	}
	private void OnMinuteSpinButtonValueChanged (object sender, EventArgs e)
	{
		Minute = MinuteSpinButton.ValueAsInt;
	}
	private void OnVolumeComboBoxChanged (object sender, EventArgs e)
	{
		Volume = VolumeComboBox.Active;
	}
	private bool OnTick ()
	{
		if (Enabled == false)
			return true;
		
		DateTime dt = DateTime.Now;
		
		if (dt.Hour != Hour || dt.Minute != Minute)
			return true;
		
		if (Volume != 0)
			player.Volume = 100 - 20 * (Volume - 1);
		
		player.Playing = true;
		
		return true;
	}
	
	
	private bool Enabled {
		get {
			return (bool) GetGConfValue ("/apps/muine/plugins/cuckoo/enable",
			false);
		}
		set {
			SetGConfValue ("/apps/muine/plugins/cuckoo/enable", value);
		}
	}
	
	private int Hour {
		get {
			int ret = (int) GetGConfValue ("/apps/muine/plugins/cuckoo/hour", 7);
			if (ret < 0) ret = 0;
			if (ret > 23) ret = 23;
			return ret;
		}
		set {
			SetGConfValue ("/apps/muine/plugins/cuckoo/hour", value);
		}
	}
	
	private int Minute {
		get {
			int ret = (int) GetGConfValue ("/apps/muine/plugins/cuckoo/minute",
			30);
			if (ret < 0) ret = 0;
			if (ret > 59) ret = 59;
			return ret;
		}
		set {
			SetGConfValue ("/apps/muine/plugins/cuckoo/minute", value);
		}
	}
	
	private int Volume {
		get {
			int ret = (int) GetGConfValue ("/apps/muine/plugins/cuckoo/volume", 0);
			if (ret < 0) ret = 0;
			if (ret > 5) ret = 5;
			return ret;
		}
		set {
			SetGConfValue ("/apps/muine/plugins/cuckoo/volume", value);
		}
	}
	
	private object GetGConfValue (string key, object default_val)
	{
		object val;
		try {
			val = gconf_client.Get (key);
		} catch {
			val = default_val;
		}
		return val;
	}
	private void SetGConfValue (string key, object val)
	{
		gconf_client.Set (key, val);        	
	}
}