using System; using Gtk; using GtkSharp; using Glade; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; 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 = Convert.ToString(list_chkbx[0]); this.mon_hour = ((Gtk.SpinButton)list_spinbuttons[2]).Text; this.mon_min = ((Gtk.SpinButton)list_spinbuttons[3]).Text; this.mon_active = Convert.ToString(list_chkbx[1]); this.tue_hour = ((Gtk.SpinButton)list_spinbuttons[4]).Text; this.tue_min = ((Gtk.SpinButton)list_spinbuttons[5]).Text; this.tue_active = Convert.ToString(list_chkbx[2]); this.wed_hour = ((Gtk.SpinButton)list_spinbuttons[6]).Text; this.wed_min = ((Gtk.SpinButton)list_spinbuttons[7]).Text; this.wed_active = Convert.ToString(list_chkbx[3]); this.thu_hour = ((Gtk.SpinButton)list_spinbuttons[8]).Text; this.thu_min = ((Gtk.SpinButton)list_spinbuttons[9]).Text; this.thu_active = Convert.ToString(list_chkbx[4]); this.fri_hour = ((Gtk.SpinButton)list_spinbuttons[10]).Text; this.fri_min = ((Gtk.SpinButton)list_spinbuttons[11]).Text; this.fri_active = Convert.ToString(list_chkbx[5]); this.sat_hour = ((Gtk.SpinButton)list_spinbuttons[12]).Text; this.sat_min = ((Gtk.SpinButton)list_spinbuttons[13]).Text; this.sat_active = Convert.ToString(list_chkbx[6]); } } [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 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 restore_settings_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.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; public static void Main(string[] args) { //new obtain_hour(); new GladeApp (args); } public GladeApp (string[] args) { Application.Init(); Glade.XML gxml = new Glade.XML ("gwakeup.glade", "gwakeup_window", null); gxml.Autoconnect (this); gwakeup_window.ShowAll(); restore_settings(); Application.Run(); } public void obtain_hour(System.Object o, System.EventArgs args) { bool i = true; while (i) { string formattedDate = DateTime.Now.ToString("h:mm:ss"); Console.WriteLine ("La hora esacta es: {0}", formattedDate); } } 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); } } 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) { Application.Quit (); } }