using System; using Gtk; using GtkSharp; using Glade; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; using Gst; using System.Threading; using System.Diagnostics; class PlaySample : Play { // new PlaySample ("sonido.wav"); public PlaySample (string sound) : base (GType) { /*this.SetDataSrc (ElementFactory.Make ("filesrc", "filesrc")); Element audiosink = ElementFactory.Make ("osssink", "osssink"); this.SetAudioSink (audiosink); this.SetLocation (sound); this.SetState (ElementState.Playing);*/ } public void play_alarm (string sound) { this.SetDataSrc (ElementFactory.Make ("filesrc", "filesrc")); Element audiosink = ElementFactory.Make ("alsasink", "alsasink"); this.SetAudioSink (audiosink); this.SetLocation (sound); this.SetState (ElementState.Playing); } } public class save_settings_class { public string sun_hour; public string sun_min; public string sun_active; public string mon_hour; public string mon_min; public string mon_active; public string tue_hour; public string tue_min; public string tue_active; public string wed_hour; public string wed_min; public string wed_active; public string thu_hour; public string thu_min; public string thu_active; public string fri_hour; public string fri_min; public string fri_active; public string sat_hour; public string sat_min; public string sat_active; public save_settings_class() { } public save_settings_class(System.Collections.ArrayList list_spinbuttons, System.Collections.ArrayList list_chkbx) { this.sun_hour = ((Gtk.SpinButton)list_spinbuttons[0]).Text; this.sun_min = ((Gtk.SpinButton)list_spinbuttons[1]).Text; this.sun_active = ((Gtk.CheckButton)list_chkbx[0]).Active.ToString().ToLower(); this.mon_hour = ((Gtk.SpinButton)list_spinbuttons[2]).Text; this.mon_min = ((Gtk.SpinButton)list_spinbuttons[3]).Text; this.mon_active = ((Gtk.CheckButton)list_chkbx[1]).Active.ToString().ToLower(); this.tue_hour = ((Gtk.SpinButton)list_spinbuttons[4]).Text; this.tue_min = ((Gtk.SpinButton)list_spinbuttons[5]).Text; this.tue_active = ((Gtk.CheckButton)list_chkbx[2]).Active.ToString().ToLower(); this.wed_hour = ((Gtk.SpinButton)list_spinbuttons[6]).Text; this.wed_min = ((Gtk.SpinButton)list_spinbuttons[7]).Text; this.wed_active = ((Gtk.CheckButton)list_chkbx[3]).Active.ToString().ToLower(); this.thu_hour = ((Gtk.SpinButton)list_spinbuttons[8]).Text; this.thu_min = ((Gtk.SpinButton)list_spinbuttons[9]).Text; this.thu_active = ((Gtk.CheckButton)list_chkbx[4]).Active.ToString().ToLower(); this.fri_hour = ((Gtk.SpinButton)list_spinbuttons[10]).Text; this.fri_min = ((Gtk.SpinButton)list_spinbuttons[11]).Text; this.fri_active = ((Gtk.CheckButton)list_chkbx[5]).Active.ToString().ToLower(); this.sat_hour = ((Gtk.SpinButton)list_spinbuttons[12]).Text; this.sat_min = ((Gtk.SpinButton)list_spinbuttons[13]).Text; this.sat_active = ((Gtk.CheckButton)list_chkbx[6]).Active.ToString().ToLower(); } } [XmlRoot( "save_settings_class")] public class restore_settings_class { public string sun_hour; public string sun_min; public bool sun_active; public string mon_hour; public string mon_min; public bool mon_active; public string tue_hour; public string tue_min; public bool tue_active; public string wed_hour; public string wed_min; public bool wed_active; public string thu_hour; public string thu_min; public bool thu_active; public string fri_hour; public string fri_min; public bool fri_active; public string sat_hour; public string sat_min; public bool sat_active; public restore_settings_class() {} } public class get_time_class { } public class GladeApp { [Glade.Widget] protected Gtk.Window gwakeup_window; [Glade.Widget] protected Gtk.Notebook notebook; [Glade.Widget] protected Gtk.HButtonBox hbuttonbox; protected Gtk.Image img_preferences; protected Gtk.Image img_about; protected Gtk.HBox vbox1; protected Gtk.HBox vbox2; protected Gtk.HBox hbox1; protected Gtk.HBox hbox2; protected Gtk.HBox hbox3; protected Gtk.HBox hbox4; protected Gtk.HBox hbox5; protected Gtk.HBox hbox6; protected Gtk.HBox hbox7; protected Gtk.HBox hbox8; protected Gtk.HBox hbox9; protected Gtk.HBox hbox10; protected Gtk.HBox hbox11; protected Gtk.HBox hbox12; protected Gtk.HBox hbox13; protected Gtk.HBox hbox14; protected Gtk.HBox hbox15; protected Gtk.HBox hbox16; protected Gtk.HBox hbox17; protected Gtk.Label hour_separator; protected Gtk.Label tab_preferences; protected Gtk.Label tab_about; protected Gtk.Label instructions; protected Gtk.Label about; protected Gtk.CheckButton check_sun; protected Gtk.CheckButton check_mon; protected Gtk.CheckButton check_tue; protected Gtk.CheckButton check_wed; protected Gtk.CheckButton check_thu; protected Gtk.CheckButton check_fri; protected Gtk.CheckButton check_sat; protected Gtk.SpinButton sun_hspin; protected Gtk.SpinButton mon_hspin; protected Gtk.SpinButton tue_hspin; protected Gtk.SpinButton wed_hspin; protected Gtk.SpinButton thu_hspin; protected Gtk.SpinButton fri_hspin; protected Gtk.SpinButton sat_hspin; protected Gtk.SpinButton sun_mspin; protected Gtk.SpinButton mon_mspin; protected Gtk.SpinButton tue_mspin; protected Gtk.SpinButton wed_mspin; protected Gtk.SpinButton thu_mspin; protected Gtk.SpinButton fri_mspin; protected Gtk.SpinButton sat_mspin; protected Gtk.Button savebtn; protected Gtk.Button helpbtn; protected Gtk.Button exitbtn; Timer Clock; public static void Main(string[] args) { Gst.Application.Init ("PlaySample"); new GladeApp (args); } public GladeApp (string[] args) { Gtk.Application.Init(); Glade.XML gxml = new Glade.XML ("gwakeup.glade", "gwakeup_window", null); gxml.Autoconnect (this); gwakeup_window.ShowAll(); restore_settings(); System.Threading.Thread gtimeth = new System.Threading.Thread(new System.Threading.ThreadStart (obtain_hour)); gtimeth.Start(); Gtk.Application.Run(); } public void obtain_hour() { bool i = true; bool sunday; bool monday; bool tuesday; bool wednesday; bool thursday; bool friday; bool saturday; int hsun; int hmon; int htue; int hwed; int hthu; int hfri; int hsat; int msun; int mmon; int mtue; int mwed; int mthu; int mfri; int msat; string today = DateTime.Now.ToString("dddd"); while(i == true ) { using (FileStream fs = new FileStream("days.xml", FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(restore_settings_class)); XmlReader reader = new XmlTextReader(fs); restore_settings_class restore_settings_instance; restore_settings_instance = (restore_settings_class) serializer.Deserialize(reader); sunday = Convert.ToBoolean(restore_settings_instance.sun_active); monday = Convert.ToBoolean(restore_settings_instance.mon_active); tuesday = Convert.ToBoolean(restore_settings_instance.tue_active); wednesday = Convert.ToBoolean(restore_settings_instance.wed_active); thursday = Convert.ToBoolean(restore_settings_instance.thu_active); friday = Convert.ToBoolean(restore_settings_instance.fri_active); saturday = Convert.ToBoolean(restore_settings_instance.sat_active); hsun = Convert.ToInt16(restore_settings_instance.sun_hour); msun = Convert.ToInt16(restore_settings_instance.sun_min); hmon = Convert.ToInt16(restore_settings_instance.mon_hour); mmon = Convert.ToInt16(restore_settings_instance.mon_min); htue = Convert.ToInt16(restore_settings_instance.tue_hour); mtue = Convert.ToInt16(restore_settings_instance.tue_min); hwed = Convert.ToInt16(restore_settings_instance.wed_hour); mwed = Convert.ToInt16(restore_settings_instance.wed_min); hthu = Convert.ToInt16(restore_settings_instance.thu_hour); mthu = Convert.ToInt16(restore_settings_instance.thu_min); hfri = Convert.ToInt16(restore_settings_instance.fri_hour); mfri = Convert.ToInt16(restore_settings_instance.fri_min); hsat = Convert.ToInt16(restore_settings_instance.sat_hour); msat = Convert.ToInt16(restore_settings_instance.sat_min); fs.Close(); } //System.Threading.Thread.Sleep(1000); //System.Threading.Thread.Suspend(); //System.Threading.Thread.Resume(); int now_hour = Convert.ToInt32(DateTime.Now.ToString("HH")); int now_minute = Convert.ToInt32(DateTime.Now.ToString("mm")); PlaySample play_alarm = new PlaySample("sonido.wav"); if (today == "Sunday" && sunday) //hack this string comparation { if (hsun == now_hour) if (msun == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Monday" && monday) { if (hmon == now_hour) if (mmon == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Tuesday" && tuesday) { if (htue == now_hour) if (mtue == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Wednesday" && wednesday) { if (hwed == now_hour) if (mwed == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Thursday" && thursday) { if (hthu == now_hour) if (mthu == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Friday" && friday) { if (hfri == now_hour) if (mfri == now_minute) play_alarm.play_alarm("sonido.wav"); } else if (today == "Saturday" && saturday) { if (hsat == now_hour) if (msat == now_minute) play_alarm.play_alarm("sonido.wav"); } } } public void save_settings(object o, EventArgs args) { System.Collections.ArrayList list_spinbuttons = new System.Collections.ArrayList(); // create an collection of spinbuttons System.Collections.ArrayList list_chkbx = new System.Collections.ArrayList(); // create an colection of checkboxes get_list_widgets(gwakeup_window, list_spinbuttons, list_chkbx); //extract a list of widgets childs of any container save_settings_class save_settings_instance = new save_settings_class (list_spinbuttons, list_chkbx); using (FileStream fs = new FileStream("days.xml", FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(save_settings_class)); serializer.Serialize(fs, save_settings_instance); } } void restore_settings() { System.Collections.ArrayList list_spinbuttons = new System.Collections.ArrayList(); // create an collection of spinbuttons System.Collections.ArrayList list_chkbx = new System.Collections.ArrayList(); // create an colection of checkboxes get_list_widgets(gwakeup_window, list_spinbuttons, list_chkbx); //extract a list of widgets childs of any container using (FileStream fs = new FileStream("days.xml", FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(restore_settings_class)); XmlReader reader = new XmlTextReader(fs); restore_settings_class restore_settings_instance; restore_settings_instance = (restore_settings_class) serializer.Deserialize(reader); ((Gtk.SpinButton)list_spinbuttons[0]).Value = Convert.ToInt32(restore_settings_instance.sun_hour); ((Gtk.SpinButton)list_spinbuttons[1]).Value = Convert.ToInt32(restore_settings_instance.sun_min); ((Gtk.SpinButton)list_spinbuttons[2]).Value = Convert.ToInt32(restore_settings_instance.mon_hour); ((Gtk.SpinButton)list_spinbuttons[3]).Value = Convert.ToInt32(restore_settings_instance.mon_min); ((Gtk.SpinButton)list_spinbuttons[4]).Value = Convert.ToInt32(restore_settings_instance.tue_hour); ((Gtk.SpinButton)list_spinbuttons[5]).Value = Convert.ToInt32(restore_settings_instance.tue_min); ((Gtk.SpinButton)list_spinbuttons[6]).Value = Convert.ToInt32(restore_settings_instance.wed_hour); ((Gtk.SpinButton)list_spinbuttons[7]).Value = Convert.ToInt32(restore_settings_instance.wed_min); ((Gtk.SpinButton)list_spinbuttons[8]).Value = Convert.ToInt32(restore_settings_instance.thu_hour); ((Gtk.SpinButton)list_spinbuttons[9]).Value = Convert.ToInt32(restore_settings_instance.thu_min); ((Gtk.SpinButton)list_spinbuttons[10]).Value = Convert.ToInt32(restore_settings_instance.fri_hour); ((Gtk.SpinButton)list_spinbuttons[11]).Value = Convert.ToInt32(restore_settings_instance.fri_min); ((Gtk.SpinButton)list_spinbuttons[12]).Value = Convert.ToInt32(restore_settings_instance.sat_hour); ((Gtk.SpinButton)list_spinbuttons[13]).Value = Convert.ToInt32(restore_settings_instance.sat_min); ((Gtk.CheckButton)list_chkbx[0]).Active = Convert.ToBoolean(restore_settings_instance.sun_active); ((Gtk.CheckButton)list_chkbx[1]).Active = Convert.ToBoolean(restore_settings_instance.mon_active); ((Gtk.CheckButton)list_chkbx[2]).Active = Convert.ToBoolean(restore_settings_instance.tue_active); ((Gtk.CheckButton)list_chkbx[3]).Active = Convert.ToBoolean(restore_settings_instance.wed_active); ((Gtk.CheckButton)list_chkbx[4]).Active = Convert.ToBoolean(restore_settings_instance.thu_active); ((Gtk.CheckButton)list_chkbx[5]).Active = Convert.ToBoolean(restore_settings_instance.fri_active); ((Gtk.CheckButton)list_chkbx[6]).Active = Convert.ToBoolean(restore_settings_instance.sat_active); } } public void get_list_widgets(Gtk.Container contenedor, System.Collections.ArrayList list_spinbuttons, System.Collections.ArrayList list_chkbx) { foreach(Gtk.Widget WidgetActual in contenedor.Children) { if (WidgetActual is Gtk.SpinButton) { list_spinbuttons.Add(WidgetActual); } else if (WidgetActual is Gtk.CheckButton) { list_chkbx.Add(WidgetActual); } else if (WidgetActual is Gtk.Container) { get_list_widgets((Gtk.Container)WidgetActual, list_spinbuttons, list_chkbx); } } } public void close_window (System.Object o, System.EventArgs args) { Gtk.Application.Quit (); } }