?? gwireless.cs
字號:
using System;using Gtk;using Gdk;using Mono.Posix;public class GWireless : Gtk.Window { ItemContainer Container; Networks nets; Pixbuf LightOn, LightOff, Lock, Router; Legend[] Legends; string ConfigFile; DeviceSelection DeviceSel; CheckButton online; OS os; public GWireless (OS os1) : base(""){ Catalog.Init("domain","./locale"); os=os1; ConfigFile = String.Format("{0}/.gwireless",System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal ) ); LightOff = new Pixbuf(null,"LightOff.png").ScaleSimple(30,30,InterpType.Bilinear) ; LightOn = new Pixbuf(null,"LightOn.png").ScaleSimple(30,30,InterpType.Bilinear) ; Lock = new Pixbuf(null,"Lock.png").ScaleSimple(34,34,InterpType.Bilinear) ; Router = new Pixbuf(null,"Router.png").ScaleSimple(36,36,InterpType.Bilinear) ; Title = Catalog.GetString("Wireless Networks"); Icon = new Pixbuf(null,"Logo.png"); BorderWidth = 10; SetDefaultSize (500, 250); DeleteEvent += new DeleteEventHandler (OnMyWindowDelete); VBox box = new VBox(); if (!os.HasWirelessDevices){ MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, Catalog.GetString("Check your drivers!")); md.Run (); md.Destroy(); System.Environment.Exit(1); } DeviceSel = new DeviceSelection(os.WirelessDevices()); HBox hb = new HBox(); box.PackStart(hb); Container = new ItemContainer(LightOn, LightOff, Lock, Router); Container.RowActivated += EditConfig; ScrolledWindow sw = new ScrolledWindow(); sw.Add(Container); VBox vertbox = new VBox(); vertbox.PackStart(DeviceSel,false,false,0); vertbox.PackStart(new Label("") ,false,false,0); vertbox.PackStart(sw); hb.PackStart(vertbox); //Buttons VBox vb = new VBox(); Button connect = StockButton("gtk-connect",Catalog.GetString("Connect")); connect.Clicked += EditConfig; Button New = new Button("gtk-new"); New.Clicked += NewConfig; Button close = new Button("gtk-close"); close.Clicked += Quit; vb.PackStart (new Label(""),false,false,0); vb.PackStart (New,false,false,0); vb.PackStart (connect,false,false,0); vb.PackStart (close,false,false,0); vb.Spacing = 5; vb.BorderWidth=10; hb.PackStart(vb,false,false,0); //White Separator vb.PackStart(new Label("")); //Checkbutton online = new CheckButton(Catalog.GetString("Just online")); online.Active=true; vb.PackStart(online,false,false,0); online.Toggled += OnlyOnlineToggled; DeviceSel.combo.Changed += DeviceSelectionChanged; //Legends Legends = new Legend[]{ new Legend(LightOn), new Legend(Lock), new Legend(null) }; vb.PackStart(new HSeparator(),false,false,0); foreach (Legend legend in Legends) vb.PackStart(legend,false,false,0); Add(box); ShowAll(); //Try to remember.. if ( System.IO.File.Exists(ConfigFile) ) nets = Networks.LoadFrom(ConfigFile); else nets = new Networks(); DeviceSel.combo.Active=0; GLib.Timeout.Add (380, new GLib.TimeoutHandler (Tick)); } bool Tick(){ foreach ( Network net in os.WirelessNetworks()) if (!nets.Exist(net)){ nets.Add(net); Container.Add(net); } else if (!net.Equals(nets[net.SSID])){ //If the network was unavaible (and we didnt show it) //but now it is visible if (nets[net.SSID].Signal=="0" && online.Active ) Container.Add(net); //Update the list, without overriding profile info nets.UpdateNetInfoFrom(net); Container.Update(net); } //Update the legend string str = String.Format("<small> {0} {1}</small>",nets.TotalOnline,Catalog.GetString("on")); Legends[0].Update(str); str = String.Format("<small>{0} {1}</small>", nets.TotalEncripted,Catalog.GetString("lock")); Legends[1].Update(str); Legends[2].Update(String.Format(" <b>{1}:</b> {0}",nets.Total,Catalog.GetString("Total"))); return true; } void NewConfig(object o, EventArgs a){ new ConfigWindow(os); } void EditConfig(object o, EventArgs a){ string ssid=Container.SelectionId ; if (ssid!=null){ Network n = nets[ssid]; new ConfigWindow(n,os); } } void Quit(object o, EventArgs a){ nets.SaveTo(ConfigFile); Application.Quit (); } void OnMyWindowDelete (object sender, DeleteEventArgs a){ nets.SaveTo(ConfigFile); Application.Quit (); a.RetVal = true; } private void OnlyOnlineToggled(object o, EventArgs a){ Container.SetFrom(nets,online.Active); } private void DeviceSelectionChanged(object o, EventArgs a){ os.SelectedDevice=DeviceSel.Selected; nets.AllOffline(); Container.Clear(); Container.SetFrom(nets,online.Active); } ///http://cvs.gnome.org/viewcvs/beagle/Best/BestWindow.cs?rev=1.37 private Gtk.Button StockButton (string stockid, string label){ Gtk.HBox button_contents = new HBox (false,0); button_contents.Show (); Gtk.Widget button_image = new Gtk.Image (stockid, Gtk.IconSize.Button); button_image.Show (); button_contents.PackStart (button_image,false,false,0); Gtk.Label button_label = new Gtk.Label (label); button_label.Show (); button_contents.PackStart (button_label,false,false,0); Gtk.Button button = new Gtk.Button (); button.Add (button_contents); return button; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -