This commit is contained in:
cuu 2018-11-25 02:21:29 +08:00
parent 7b9f42ac2e
commit 515763d954
9 changed files with 275 additions and 39 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/cuu/LauncherGo/sysgo/UI"
)
var NetItemDefaultHeight = 30
type NetItemMultiIcon struct {
UI.MultiIconItem
@ -97,7 +98,7 @@ func NewNetItem() *NetItem {
p.bitrate = "auto"
p.dhcphostname = "GameShell"
p.Height = 30
p.Height = NetItemDefaultHeight
p.Labels = make(map[string]UI.LabelInterface)
p.Icons = make( map[string]UI.IconItemInterface)

View File

@ -9,6 +9,9 @@ import (
"github.com/cuu/gogame/time"
"github.com/cuu/LauncherGo/sysgo/UI"
"github.com/cuu/LauncherGo/sysgo/DBUS"
"github.com/cuu/LaucherGo/sysgo/wicd/misc"
)
type WifiDisconnectConfirmPage struct {
@ -384,9 +387,14 @@ type WifiList struct{
BlockCb BlockCbFunc
LastStatusMsg string
EncMethods []*misc.CurType
Scroller *UI.ListScroller
ListFontObj *ttf.Font
InfoPage *WifiInfoPage
MyList []*NetItem
}
func NewWifiList() *WifiList {
@ -395,11 +403,91 @@ func NewWifiList() *WifiList {
return p
}
func (self *WifiList) ShowBox(msg string ) {
self.MsgBox.Text = msg
self.ShowingMessageBox = true
self.Screen.Draw()
self.MsgBox.Draw()
self.Screen.SwapAndShow()
}
func (self *WifiList) HideBox() {
self.Draw()
self.ShowingMessageBox = false
self.Screen.SwapAndShow()
}
func (self *WifiList) Init() {
self.PosX = self.Index * self.Screen.Width
self.Width = self.Screen.Width
self.Height = self.Screen.Height
self.CanvasHWND = self.Screen.CanvasHWND
ps := NewWifiListSelector()
ps.Parent = self
ps.Width = UI.Width - 12
self.Ps = ps
self.PsIndex = 0
msgbox := NewWifiListMessageBox()
msgbox.CanvasHWND = self.CanvasHWND
msgbox.Init(" ",UI.Fonts["veramono12"])
msgbox.Parent = self
self.MsgBox = msgbox
self.EncMethods = misc.LoadEncryptionMethods() //# load predefined templates from /etc/wicd/...
/*
{
'fields': [],
'name': 'WPA 1/2 (Passphrase)',
'optional': [],
'protected': [
['apsk', 'Preshared_Key'],
],
'required': [
['apsk', 'Preshared_Key'],
],
'type': 'wpa-psk',
},
*/
self.UpdateNetList(true,true) // self.UpdateNetList(force_check=True,firstrun=True)
self.Scroller = UI.NewListScroller()
self.Scroller.Parent = self
self.Scroller.PosX = 2
self.Scroller.PosY = 2
self.Scroller.Init()
self.InfoPage = NewWifiInfoPage()
self.InfoPage.Screen = self.Screen
self.InfoPage.Name = "Wifi info"
self.InfoPage.Init()
}
func (self *WifiList) Draw() {
self.ClearCanvas()
if len(self.MyList) == 0 {
return
}
self.Ps.Draw()
for _,v := range self.MyList {
v.Draw()
}
self.Scroller.UpdateSize( len(self.MyList)*NetItemDefaultHeight, self.PsIndex*NetItemDefaultHeight)
self.Scroller.Draw()
}

View File

@ -16,6 +16,7 @@ import (
type ListPageSelector struct {
PageSelector
BackgroundColor *color.Color
Parent *ConfirmPage
}
func NewListPageSelector() *ListPageSelector {
@ -27,7 +28,7 @@ func NewListPageSelector() *ListPageSelector {
func (self *ListPageSelector) Draw() {
idx := self.Parent.GetPsIndex()
mylist := self.Parent.GetMyList()
mylist := self.Parent.MyList
if idx > (len(mylist) -1) {
idx = len(mylist)
if idx > 0 {
@ -78,33 +79,36 @@ func NewConfirmPage() *ConfirmPage {
}
func (self *ConfirmPage) GetMyList() []LabelInterface {
return self.MyList
}
func (self *ConfirmPage) Reset() {
self.MyList[0].SetText(self.ConfirmText)
x,y := self.MyList[0].Coord()
w,h := self.MyList[0].Size()
self.MyList[0].PosX = (self.Width - self.MyList[0].Width)/2
self.MyList[0].PosY = (self.Width - self.MyList[0].Height)/2
self.MyList[0].NewCoord( (self.Width - w)/2, (self.Width - h)/2)
self.BGPosX = self.MyList[0].PosX - 10
self.BGPosY = self.MyList[0].PosY - 10
x,y = self.MyList[0].Coord()
self.BGWidth = self.MyList[0].Width + 20
self.BGHeight = self.MyList[0].Height +20
self.BGPosX = x - 10
self.BGPosY = y - 10
self.BGWidth = w + 20
self.BGHeight = h + 20
}
func (self *ConfirmPage) SnapMsg(msg string) {
self.MyList[0].SetText(msg)
self.MyList[0].PosX = (self.Width - self.MyList[0].Width)/2
self.MyList[0].PosY = (self.Width - self.MyList[0].Height)/2
x,y := self.MyList[0].Coord()
w,h := self.MyList[0].Size()
self.MyList[0].NewCoord( (self.Width - w )/2, (self.Width - h)/2 )
self.BGPosX = self.MyList[0].PosX - 10
self.BGPosY = self.MyList[0].PosY - 10
x, y = self.MyList[0].Coord()
self.BGWidth = self.MyList[0].Width + 20
self.BGHeight = self.MyList[0].Height +20
self.BGPosX = x - 10
self.BGPosY = y - 10
self.BGWidth = w + 20
self.BGHeight = h +20
}
@ -123,7 +127,7 @@ func (self *ConfirmPage) Init() {
li := NewLabel()
li.SetCanvasHWND(self.CanvasHWND)
li.Init(self.ConfirmText,self.ListFont)
li.Init(self.ConfirmText,self.ListFont,nil)
li.PosX = (self.Width - li.Width)/2
li.PosY = (self.Height - li.Height)/2

View File

@ -48,7 +48,7 @@ func (self *InfoPageListItem) Draw() {
self.Labels["Text"].SetColor(&color.Color{83,83,83,255} ) // SkinManager().GiveColor("Text")
}
x,y := self.Labels["Text"].Coord()
x,_ := self.Labels["Text"].Coord()
w,h := self.Labels["Text"].Size()
self.Labels["Text"].NewCoord( x + self.PosX, self.PosY + (self.Height - h)/2 )
@ -58,7 +58,7 @@ func (self *InfoPageListItem) Draw() {
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height - h)/2 )
if _, ok := self.Labels["Small"]; ok {
x,y = self.Labels["Small"].Coord()
x,_ = self.Labels["Small"].Coord()
w,h = self.Labels["Small"].Size()
self.Labels["Small"].NewCoord( self.Width - w + 5 , self.PosY + (self.Height - h)/2 )

View File

@ -35,8 +35,8 @@ func (self *InfoPageSelector) Draw() {
mylist := self.Parent.GetMyList()
if idx < len(mylist) {
x,y := mylist[idx].Coord()
w,h := mylist[idx].Size()
_,y := mylist[idx].Coord()
_,h := mylist[idx].Size()
self.PosY = y+1
self.Height = h-3

View File

@ -1,7 +1,10 @@
package UI
import (
"fmt"
"strings"
"github.com/cuu/gogame/font"
"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/surface"
"github.com/cuu/gogame/color"
@ -52,12 +55,10 @@ func (self *KeyboardSelector) Draw() {
row_idx := self.Parent.RowIndex
idx := self.Parent.PsIndex
x := self.Parent.SecsKeys[sec_idx][row_idx][idx].PosX
y := self.Parent.SecsKeys[sec_idx][row_idx][idx].PosY
w := self.Parent.SecsKeys[sec_idx][row_idx][idx].Width+6
h := self.Parent.SecsKeys[sec_idx][row_idx][idx].Height+1
x, y := self.Parent.SecsKeys[sec_idx][row_idx][idx].Coord()
w, h := self.Parent.SecsKeys[sec_idx][row_idx][idx].Size()
rect_ := draw.MidRect(x,y,w,h,self.Parent.Width,self.Parent.Height)
rect_ := draw.MidRect(x,y,w+6,h+1,self.Parent.Width,self.Parent.Height)
if rect_.W <= 0 || rect_.H <= 0 {
return
@ -200,7 +201,7 @@ func (self *Keyboard) Init() {
start_y = 84 * j * (word_margin+14)
for idx,val := range self.Secs[i][j] {
for _,val := range self.Secs[i][j] {
ti := NewTextItem()
ti.FontObj = fontobj
ti.Parent = self
@ -248,9 +249,10 @@ func (self *Keyboard) Init() {
ps.Parent = self
ps.Init(start_x,start_y,25,25,128)
ps.OnShow = true
self.Ps = ps
self.PsIndex = 0
self.Ps.OnShow = true
}
@ -295,7 +297,7 @@ func (self *Keyboard) SelectNextChar() {
row_idx := self.RowIndex
self.PsIndex+=1
if self._PsIndex >= len(self.SecsKeys[sec_idx][row_idx]) {
if self.PsIndex >= len(self.SecsKeys[sec_idx][row_idx]) {
self.PsIndex = 0
self.RowIndex+=1
@ -330,7 +332,8 @@ func (self *Keyboard) SelectPrevChar() {
func (self *Keyboard) ClickOnChar() {
sec_idx := self.SectionIndex
alphabet := self.SecsKeys[sec_idx][self.RowIndex][self.PsIndex].Str
alphabet := self.SecsKeys[sec_idx][self.RowIndex][self.PsIndex].GetStr()
if alphabet == "Space"{
alphabet = " "
}
@ -387,7 +390,8 @@ func (self *Keyboard) KeyboardShift() {
for j:=0;j<self.SectionNumbers;j++ {
for _,u := range self.SecsKeys[j] {
for _,x := range u {
x.PosX = += self.LeftOrRight*v
x_,y_ := x.Coord()
x.NewCoord(x_+self.LeftOrRight*v,y_)
}
}
}
@ -399,7 +403,7 @@ func (self *Keyboard) KeyboardShift() {
}
}
func (self *keyboard) ShiftKeyboardPage() {
func (self *Keyboard) ShiftKeyboardPage() {
self.KeyboardShift()
self.SectionIndex -= self.LeftOrRight
self.Draw()

View File

@ -28,7 +28,7 @@ var (
plugin_flag = "plugin.config"
)
type ActionConifg struct {
type ActionConfig struct {
ROM string `json:"ROM"`
ROM_SO string `json:"ROM_SO"`
EXT []string `json:"EXT"`

View File

@ -12,10 +12,13 @@ import (
)
type TextItemInterface interface{
IconItemInterface
GetBold() bool
SetBold(bold bool)
GetStr() string
Draw()
}

136
sysgo/wicd/misc/misc.go Normal file
View File

@ -0,0 +1,136 @@
package misc
import (
"bufio"
"fmt"
"github.com/cuu/LauncherGo/sysgo/UI"
"log"
"os"
"strings"
)
var wpath_encryption = "/etc/wicd/encryption/templates/"
type CurType struct {
Type string
Fields [][]string
Optional [][]string
Required [][]string
Protected [][]string
Name string
}
func NewCurType() *CurType {
p := &CurType{}
return p
}
func parse_field_ent(field_line string, field_type string) [][]string {
if field_type == "" {
field_type = "require"
}
var ret [][]string
fields := strings.Split(field_line, " ")
if len(fields)%2 != 0 {
return ret
} else {
var t [][2]string
for i := 0; i < len(fields); i += 2 {
t = append(t, [2]string{fields[i], fields[i+1]})
}
for _, v := range t {
if strings.HasPrefix(string(v[0]), "*") || strings.HasPrefix(string(v[1]), "*") == false {
return ret
}
ret = append(ret, []string{string(v[0]), string(v[1])[1:]})
}
}
return ret
}
func parse_ent(line, key string) string {
line = strings.Replace(line, key, "", -1)
line = strings.Replace(line, "=", "", -1)
return strings.TrimSpace(line)
}
func parse_enc_templat(enctype string) *CurType {
file, err := os.Open(wpath_encryption + enctype)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
cur_type := NewCurType()
for scanner.Scan() {
line := scanner.Text()
//fmt.Println(line)
if strings.HasPrefix(line, "name") && cur_type.Name == "" {
cur_type.Name = parse_ent(line, "name")
} else if strings.HasPrefix(line, "require") {
cur_type.Required = parse_field_ent(parse_ent(line, "require"), "")
} else if strings.HasPrefix(line, "optional") {
cur_type.Optional = parse_field_ent(parse_ent(line, "optional"), "")
} else if strings.HasPrefix(line, "protected") {
cur_type.Protected = parse_field_ent(parse_ent(line, "protected"), "")
} else if strings.HasPrefix(line, "----") {
break
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
if len(cur_type.Name) == 0 {
cur_type = nil
}
if len(cur_type.Required) == 0 {
cur_type = nil
}
return cur_type
}
func LoadEncryptionMethods(wired bool) []*CurType {
active_fname := "active"
if wired == true {
active_fname = "active_wired"
} else {
active_fname = "active"
}
enctypes, _ := UI.ReadLines(wpath_encryption + active_fname)
fmt.Println(enctypes)
var encryptionTypes []*CurType
for _, v := range enctypes {
c := parse_enc_templat(v)
encryptionTypes = append(encryptionTypes, c)
}
return encryptionTypes
}