using System; namespace zero { namespace netboot { [System.ComponentModel.ToolboxItem(true)] public partial class TcosWidget : Gtk.Bin { public Gtk.ListStore store; private Gtk.ListStore combostore; public Gtk.CellRendererPixbuf cellpix; public Gtk.CellRendererText celltext; public Gtk.CellRendererText id_cell; public Gtk.CellRendererCombo cellcombo; public Gtk.CellRendererToggle celltoggle; public Gtk.TreeViewColumn idcol; public Gtk.TreeViewColumn pixcol; public Gtk.TreeViewColumn textcol; public Gtk.TreeViewColumn combocol; private bool tree_init=true; private string extractedModel; //private Gtk.ListStore cmodel; public TcosWidget () { this.Build (); combostore=new Gtk.ListStore(typeof(string),typeof(string)); defaultIsoCombobox.Model=combostore; cellpix=new Gtk.CellRendererPixbuf(); pixcol=new Gtk.TreeViewColumn(); pixcol.PackStart(cellpix,true); pixcol.AddAttribute(cellpix,"pixbuf",0); pixcol.Title=Mono.Unix.Catalog.GetString("Image"); treeview1.AppendColumn(pixcol); celltext=new Gtk.CellRendererText(); textcol=new Gtk.TreeViewColumn(); textcol.PackStart(celltext,true); textcol.AddAttribute(celltext,"text",1); textcol.Title=Mono.Unix.Catalog.GetString("Adaptation"); treeview1.AppendColumn(textcol); celltoggle=new Gtk.CellRendererToggle(); celltoggle.Toggled+=new Gtk.ToggledHandler(cellEdited); combocol=new Gtk.TreeViewColumn(); combocol.Title=Mono.Unix.Catalog.GetString("Enabled"); combocol.PackStart(celltoggle,true); combocol.AddAttribute(celltoggle,"active",2); treeview1.AppendColumn(combocol); id_cell=new Gtk.CellRendererText(); idcol=new Gtk.TreeViewColumn(); idcol.PackStart(id_cell,true); idcol.AddAttribute(id_cell,"text",3); idcol.Title=Mono.Unix.Catalog.GetString("ID"); treeview1.AppendColumn(idcol); idcol.Visible=false; store=new Gtk.ListStore(typeof(Gdk.Pixbuf),typeof(string),typeof(bool),typeof(string)); // store.AppendValues(Gdk.Pixbuf.LoadFromResource("zeronetboot.rsrc.music_button.svg"),"tralari",false); // store.Append(); populateTreeView(); } public void populateTreeView() { store=new Gtk.ListStore(typeof(Gdk.Pixbuf),typeof(string),typeof(bool),typeof(string)); zero.netboot.Core core=zero.netboot.Core.getCore(); foreach(zero.netboot.IsoInfo info in core.isoList) { try { extractedModel = info.version.Split(' ')[0].Replace("modelo-",""); store.AppendValues(Gdk.Pixbuf.LoadFromResource(zero.netboot.Core.getCore().lliurexsvglist[extractedModel]), zero.netboot.Core.getCore().lliurexlist[extractedModel] + " " + info.version.Split(' ')[1], info.enabled, Convert.ToString(info.id)); } catch(Exception e) { } } treeview1.Model=store; treeview1.ShowAll(); if (store.IterNChildren()>0) { Gtk.TreeIter iter; store.GetIterFirst(out iter); treeview1.Selection.SelectIter(iter); treeview1.Sensitive=true; } else treeview1.Sensitive=false; // defaultIsoCombobox.AppendText("hola"); populate_store(); //defaultIsoCombobox.Active=0; tree_init=false; if(core.confman.options["installation_enabled"]=="true") installCheckbutton.Active=true; else installCheckbutton.Active=false; if(core.confman.options["language_enabled"]=="qcv_ES") radioButtonQcv.Active=true; else radioButtonEs.Active=true; liveUser.Text=core.confman.options["liveuser"]; if (liveUser.Text.Equals("")) livePasswd.Text=""; else livePasswd.Text=core.confman.options["livepasswd"]; pxePassword.Text=core.confman.options["pxepassword"]; } public void cellEdited(object sender, Gtk.ToggledArgs args) { if(!tree_init) { Gtk.TreeIter iter; Gtk.TreePath path = new Gtk.TreePath(args.Path); store.GetIter(out iter,path); bool tmp=(bool)store.GetValue(iter,2); int id = Convert.ToInt32((string) store.GetValue(iter,3)); store.SetValue(iter,2,!tmp); //string model=(string)store.GetValue(iter,1); foreach(zero.netboot.IsoInfo info in zero.netboot.Core.getCore().isoList) { if(info.id == id) { info.enabled=!tmp; populate_store(); break; } } } } private void populate_store() { combostore.Clear(); foreach(System.Collections.Generic.KeyValuePair thin in zero.netboot.Core.getCore().tcoslist) { combostore.AppendValues(thin.Value.ToString(), thin.Key.ToString()); } foreach(zero.netboot.IsoInfo info in zero.netboot.Core.getCore().isoList) { if(info.enabled) { extractedModel = info.version.Split(' ')[0].Replace("modelo-",""); combostore.AppendValues(zero.netboot.Core.getCore().lliurexlist[extractedModel] + " " + info.version.Split(' ')[1], extractedModel); } } defaultIsoCombobox.Model=combostore; Gtk.TreeIter iter; combostore.GetIterFirst (out iter); defaultIsoCombobox.Active=0; string model; do { model = combostore.GetValue(iter,1).ToString(); if (model.Equals(zero.netboot.Core.getCore().confman.options["default_iso"])) { defaultIsoCombobox.SetActiveIter(iter); break; } } while(combostore.IterNext(ref iter)); } protected virtual void OnApplyButtonClicked (object sender, System.EventArgs e) { if (!zero.netboot.Core.getCore().iso_options_running) { System.Threading.ThreadStart apliyingConf = delegate { Gtk.Application.Invoke(delegate {zero.netboot.Core.getCore().progresswin=new zero.netboot.ProgressWindow(Mono.Unix.Catalog.GetString("Updating configuration..."));}); zero.netboot.Core core=zero.netboot.Core.getCore(); int id; string enable; bool enabled; core.confman.options["default_iso"]="tcos"; if(combostore.IterNChildren()>0) { Gtk.TreeIter itercombo; if (defaultIsoCombobox.GetActiveIter(out itercombo)) { core.confman.options["default_iso"]=(string) combostore.GetValue(itercombo,1); } } lliurex.utils.Variables.SetVar("ZNB_BOOT_DEFAULT", core.confman.options["default_iso"]); if(installCheckbutton.Active) { core.confman.options["installation_enabled"]="true"; lliurex.utils.Variables.SetVar("ZNB_ENABLE_INSTALL", "Y"); } else { core.confman.options["installation_enabled"]="false"; lliurex.utils.Variables.SetVar("ZNB_ENABLE_INSTALL", "N"); } core.confman.options["liveuser"]=liveUser.Text; if (liveUser.Text.Equals("")) livePasswd.Text=""; core.confman.options["livepasswd"]=livePasswd.Text; core.confman.options["pxepassword"]=pxePassword.Text; // if (!pxePassword.Text.Equals("")) { // string std_out=""; // string std_error=""; // lliurex.utils.Commands.run(zero.netboot.Core.getCore().sha1_script, pxePassword.Text , out std_out,out std_error); // string[] list_values=std_out.Split('\n'); // if (zero.netboot.Core.getCore().debug) Console.WriteLine("SHA1: " + std_out + " " + std_error); // if (list_values.Length > 0) { // lliurex.utils.Variables.SetVar("ZNB_PXE_SHA1", list_values[0]); // } else lliurex.utils.Variables.SetVar("ZNB_PXE_SHA1", ""); // } else lliurex.utils.Variables.SetVar("ZNB_PXE_SHA1", ""); if (radioButtonQcv.Active == true) core.confman.options["language_enabled"]="qcv_ES"; else core.confman.options["language_enabled"]="es_ES"; Gtk.TreeIter iter; if (store.IterNChildren() > 0) { store.GetIterFirst(out iter); do { id = Convert.ToInt32((string) store.GetValue(iter,3)); enabled=(bool)store.GetValue(iter,2); foreach(zero.netboot.IsoInfo info in core.isoList) { if(info.id==id) { core.sqlman.enable_iso(info.id,enabled); if (enabled) enable="Y"; else enable="N"; lliurex.utils.Variables.SetVar("ZNB_" + info.version.Split(' ')[0].Replace("modelo-","").ToUpper() + "_ENABLE", enable); lliurex.utils.Commands.run(zero.netboot.Core.getCore().chroot_script,"update_simple " + info.fileName + " " + info.version.Split(' ')[0].Replace("modelo-","") + " " + zero.netboot.Core.getCore().confman.options["language_enabled"] + " " + zero.netboot.Core.getCore().confman.options["isos-sources-list"] + " " + zero.netboot.Core.getCore().debug + " " + liveUser.Text + " " + livePasswd.Text); } } } while(store.IterNext(ref iter)); } lliurex.utils.Variables.SetVar("ZNB_LANGUAGE_DEFAULT", core.confman.options["language_enabled"]); core.confman.writeFile(); lliurex.utils.Commands.run(zero.netboot.Core.getCore().mount_script,"update-pxe"); core.win.helpMSG=Mono.Unix.Catalog.GetString("Configuration saved"); Gtk.Application.Invoke(delegate {zero.netboot.Core.getCore().progresswin.Hide();}); Gtk.Application.Invoke(delegate {zero.netboot.Core.getCore().progresswin.Destroy();}); }; zero.netboot.Core.getCore().progressThread= new System.Threading.Thread(apliyingConf); zero.netboot.Core.getCore().progressThread.Start(); } } } } }