using System; using Gtk; using lliurex.controlcenter; using System.Collections.Generic; using NDesk.DBus; using org.freedesktop.DBus; [Interface ("org.Lliurex.ZeroCenter.Manager")] public interface ZeroCenterManager { void register_instance(string user, string name, string path); void delete_instance(string name); } [NDesk.DBus.Interface("org.Lliurex.ZeroCenter")] public partial class MainWindow: Gtk.Window { private static MainWindow instance; public List appboxes; private bool step1,step2,step3,step4,step5,step6,step7,step8,step9,step10; public MainWindow (): base (Gtk.WindowType.Toplevel) { Build (); MainWindow.instance=this; try { NDesk.DBus.BusG.Init(); string rand=getRandomString(); while(Bus.System.NameHasOwner("org.Lliurex.ZeroCenter.z" + rand)) { rand=getRandomString(); } string bus_name="org.Lliurex.ZeroCenter.z" + rand; Core.getCore().name=bus_name; string path_string="/org/Lliurex/ZeroCenter/z" + rand; ObjectPath path=new ObjectPath("/org/Lliurex/ZeroCenter/z" + rand); if(Bus.Session.RequestName(bus_name) == RequestNameReply.PrimaryOwner) { Bus.Session.Register(path,this); } try { ZeroCenterManager zcm =Bus.System.GetObject("org.Lliurex.ZeroCenter.Manager",new ObjectPath("/org/Lliurex/ZeroCenter/Manager")); zcm.register_instance(Core.getCore().user,bus_name,path_string); } catch { Console.WriteLine("[MainWindow] ZeroCenter failed to register in zero-center-manager"); } } catch(Exception e) { Console.WriteLine("[MainWindow] ZeroCenter connection to dbus failed"); Console.WriteLine(e); } } public static MainWindow getInstance() { return instance; } public string getRandomString() { string tmp_string=System.IO.Path.GetRandomFileName(); int dot=tmp_string.IndexOf('.'); tmp_string=tmp_string.Substring(0,dot-1); return tmp_string; } public string getUser() { return Core.getCore().user; } public void SetSensible(bool state) { hboxL1.Sensitive = state; } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { try { ZeroCenterManager zcm =Bus.System.GetObject("org.Lliurex.ZeroCenter.Manager",new ObjectPath("/org/Lliurex/ZeroCenter/Manager")); zcm.delete_instance(Core.getCore().name); } catch { Console.WriteLine("[MainWindow] Failed to delete zero instance in zero-center-manager"); } Application.Quit (); a.RetVal=true; } public void fillTree(String category) {/* System.Console.WriteLine(" -Filling category-"); store.Clear(); foreach(ConfigApplication c in Core.getCore().applications) { if (c.category==category) { System.Console.WriteLine(" filling: " + c.name ); store.AppendValues(null,c.icon,c.name); } } */ appboxes=new List(); foreach(Gtk.Widget w in vboxPanelList.Children) { w.Destroy(); } foreach(ConfigApplication c in Core.getCore().applications) { if(c.category==category) { ApplicationBox abox = new ApplicationBox(c); // creates buttons based on confapplications. Should initializate // them properly if status is edited before this // list is needed to refresh the status of every single zopplet vboxPanelList.PackStart(abox); vboxPanelList.SetChildPacking(abox,false,false,5,PackType.Start); appboxes.Add(abox); } } // Locking applicationboxes lockButtons(); //vboxPanelList.PackStart(custombox); //vboxPanelList.SetChildPacking(custombox,false,false,5,PackType.Start); } public void refresStatus() { Core.getCore().sm.refresh(); foreach(ApplicationBox abox in appboxes) { abox.SetStatusText(); } Console.WriteLine("[MainWindow] Refreshing..."); } public void lockButtons() { foreach(ApplicationBox abox in appboxes) { if (abox.conf.locks.Capacity!=0 && (abox.conf.status==Core.S_RUNNING || abox.conf.status==Core.S_CONFIGURED )) { foreach(string n in abox.conf.locks) { foreach(ApplicationBox abox2 in appboxes) { if(abox2.conf.name==n && (abox.conf.status==Core.S_RUNNING || abox.conf.status==Core.S_CONFIGURED )) abox2.btnapp.Sensitive=false; } } } } } protected virtual void OnBtnHardwareClicked (object sender, System.EventArgs e) { fillTree("Hardware"); label4.Text=Mono.Unix.Catalog.GetString("Hardware"); image4.Pixbuf=imgHardware.Pixbuf; } protected virtual void OnBtnNetworkClicked (object sender, System.EventArgs e) { fillTree("Network"); label4.Text=Mono.Unix.Catalog.GetString("Network"); image4.Pixbuf=imgNetwork.Pixbuf;; } protected virtual void OnBtnSystemClicked (object sender, System.EventArgs e) { fillTree("System"); label4.Text=Mono.Unix.Catalog.GetString("System"); image4.Pixbuf=imgSystem.Pixbuf; } protected virtual void OnBtnPreferencesClicked (object sender, System.EventArgs e) { fillTree("Preferences"); label4.Text=Mono.Unix.Catalog.GetString("Preferences"); image4.Pixbuf=imgPreferences.Pixbuf; } protected virtual void OnBtnOthersClicked (object sender, System.EventArgs e) { fillTree("Others"); label4.Text=Mono.Unix.Catalog.GetString("Others"); image4.Pixbuf=imgOthers.Pixbuf; } protected virtual void OnSoftwareButtonClicked (object sender, System.EventArgs e) { fillTree("Software"); label4.Text=Mono.Unix.Catalog.GetString("Software"); image4.Pixbuf=softImage.Pixbuf; } //Publish an info message public void Info(String message) { imgStatus.Pixbuf = Core.getCore().pixinfo; lblStatus.Text=message; } //Publish and Error message public void Error(String message) { imgStatus.Pixbuf = Core.getCore().pixerror; lblStatus.Text=message; } protected virtual void OnBtnRefreshClicked (object sender, System.EventArgs e) { //it doesn't have a menu, so we just need to call this function Core.getCore().sm.refresh(); } protected virtual void OnBtnExitClicked (object sender, System.EventArgs e) { Console.WriteLine("Clicking on exit button"); Application.Quit(); } protected virtual void OnKeyPressEvent (object o, Gtk.KeyPressEventArgs args) { string key = args.Event.Key.ToString(); if(!step1) { if(key.Equals("KP_8")) { step1=true; } } else if(!step2) { if(key.Equals("KP_8")) step2=true; else step1=false; } else if(!step3) { if(key.Equals("KP_2")) step3=true; else { step1=false; step2=false; } } else if(!step4) { if(key.Equals("KP_2")) step4=true; else { step1=false; step2=false; step3=false; } } else if(!step5) { if(key.Equals("KP_4")) step5=true; else { step1=false; step2=false; step3=false; step4=false; } } else if(!step6) { if(key.Equals("KP_6")) step6=true; else { step1=false; step2=false; step3=false; step4=false; step5=false; } } else if(!step7) { if(key.Equals("KP_4")) step7=true; else { step1=false; step2=false; step3=false; step4=false; step5=false; step6=false; } } else if(!step8) { if(key.Equals("KP_6")) step8=true; else { step1=false; step2=false; step3=false; step4=false; step5=false; step6=false; step7=false; } } else if(!step9) { if(key.Equals("b")) step9=true; else { step1=false; step2=false; step3=false; step4=false; step5=false; step6=false; step7=false; step8=false; } } else if(!step10) { if(key.Equals("a")) { step10=true; Core.getCore().win.Iconify(); System.Threading.Thread.Sleep(1000); step1=false; step2=false; step3=false; step4=false; step5=false; step6=false; step7=false; step8=false; step9=false; step10=false; //Console.WriteLine("success!"); //gconftool --type string --set /desktop/gnome/background/picture_filename /home/hector/arbol.jpg string std_out=""; string std_error=""; string std_out2=""; string std_error2=""; System.Threading.ThreadStart starter1 = delegate { lliurex.utils.Commands.run("gconftool","--type string --set /desktop/gnome/background/picture_filename /usr/share/wallpapers/leia-rebel.png",out std_out,out std_error); }; new System.Threading.Thread(starter1).Start(); System.Threading.ThreadStart starter2 = delegate { lliurex.utils.Commands.run("python","/usr/share/zero-center/lliurex-credits/credits.py",out std_out2, out std_error2); Console.WriteLine(std_out2 + " " + std_error2);}; new System.Threading.Thread(starter2).Start(); } else { step1=false; step2=false; step3=false; step4=false; step5=false; step6=false; step7=false; step8=false; step9=false; } } } protected virtual void OnUnlockClicked (object sender, System.EventArgs e) { //Console.WriteLine("unlock unlock"); if (appboxes!=null) { foreach(ApplicationBox abox in appboxes) { if (!abox.btnapp.Sensitive) { //Console.WriteLine("no eres sensitivo :'("); abox.btnapp.Sensitive=true; } } } } }