--- gb.desktop/src/gb.desktop/.src/Desktop.class (révision 5536) +++ gb.desktop/src/gb.desktop/.src/Desktop.class (révision 5537) @@ -1,6 +1,6 @@ ' Gambas class file -Export +Export Class _Desktop @@ -27,64 +27,64 @@ Static Private $aImgExt As String[] Static Public Sub SendMail({To} As String[], Optional Cc As String[], Optional Bcc As String[], Optional Subject As String, Optional Body As String, Optional Attachment As String) - + Dim aArg As String[] 'xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text ' ] [--attach file] { mailto-uri | address(es) } - + aArg = ["--utf8"] - If CC And If CC.Count Then + If CC And If CC.Count Then aArg.Add("--cc") aArg.Insert(CC) Endif - If BCC And If BCC.Count Then + If BCC And If BCC.Count Then aArg.Add("--bcc") aArg.Insert(BCC) Endif - If Subject Then + If Subject Then aArg.Add("--subject") aArg.Add(Subject) - Endif - If Body Then + Endif + If Body Then aArg.Add("--body") aArg.Add(Body) Endif - If Attachment Then + If Attachment Then aArg.Add("--attach") aArg.Add(Attachment) - Endif - - If {To} And If To.Count Then + Endif + + If {To} And If To.Count Then aArg.Insert({To}) Endif - + Main.RunXdgUtil("xdg-email", aArg) - + End Static Public Sub {Open}(URL As String, Optional {Wait} As Boolean) - + If URL = "~" Then URL = User.Home Else If URL Begins "~/" Then URL = User.Home & Mid$(URL, 2) Endif - + Main.RunXdgUtil("xdg-open", [URL], {Wait}) - + End ' Static Private Function Menus_Read() As _DesktopMenus -' -' Return _DesktopMenus -' +' +' Return _DesktopMenus +' ' End -' -' +' +' ' Static Private Function Icons_Read() As _DesktopIcons -' +' ' Return _DesktopIcons -' +' ' End Static Private Function ScreenSaver_Read() As _Desktop_ScreenSaver @@ -96,20 +96,20 @@ ' GB_STATIC_METHOD("Find", "Integer[]", CDESKTOP_find, "[(Title)s(Application)s(Role)s]"), Static Public Sub FindWindow(Optional Title As String, Application As String, Role As String) As Integer[] - + Return _Desktop.FindWindow(Title, Application, Role) - + End ' STATIC PRIVATE SUB InitKeys() -' +' ' $cKeys = NEW Collection ' $cKeys["é"] = "eacute" -' +' ' END Static Public Sub SendKeys(Keys As String) - + Dim iInd As Integer Dim sCar As String Dim iPos As Integer @@ -117,15 +117,15 @@ Dim bHold As Boolean Dim sErr As String Dim iLen As Integer = String.Len(Keys) - + Do - + Inc iInd If iInd > iLen Then Break - + sCar = String.Mid$(Keys, iInd, 1) - - If sCar = "[" Then + + If sCar = "[" Then iPos = String.InStr(Keys, "]", iInd) If iPos = 0 Then Break sCar = String.Mid$(Keys, iInd + 1, iPos - iInd - 1) @@ -134,7 +134,7 @@ Else If sCar = "{" And If Not bHold Then bHold = True Continue - Else If sCar = "}" And If bHold Then + Else If sCar = "}" And If bHold Then bHold = False aRelease.Reverse For Each sCar In aRelease @@ -144,11 +144,11 @@ aRelease.Clear Continue Endif - - If Len(sCar) >= 2 Then + + If Len(sCar) >= 2 Then Try sCar = Conv(sCar, "UTF-8", "LATIN1") Endif - + If bHold Then 'DEBUG sCar;; TRUE _Desktop.SendKey(sCar, True) @@ -159,25 +159,25 @@ 'DEBUG sCar;; FALSE _Desktop.SendKey(sCar, False) Endif - - Loop - -Catch + Loop + +Catch + sErr = Error.Text & ": '" & sCar & "'" - + For Each sCar In aRelease _Desktop.SendKey(sCar, False) Next Error.Raise(sErr) - + End Static Private Sub GetDesktop() As String - + If Not $sDesktop Then - + If Application.Env["KDE_FULL_SESSION"] Then If Application.Env["KDE_SESSION_VERSION"] = "4" Then $sDesktop = "KDE4" @@ -204,24 +204,23 @@ $sDesktop = "?" End Select Endif - + Endif - + '$sDesktop = "GNOME" Return $sDesktop - + End +Static Public Sub OpenTerminal(Optional {Dir} As String) ', Optional Command As String) -Static Public Sub OpenTerminal(Optional {Dir} As String) ', Optional Command As String) - Dim sExec As String Dim sCmd As String Dim bNoDir As Boolean Dim Command As String - + Select Case GetDesktop() - + Case "KDE" sExec = "konsole" Case "KDE4" @@ -247,7 +246,7 @@ Endif If Command Then sExec &= " -x " & Shell$(Command) Case "XFCE" - sExec = "Terminal" + sExec = "xfce4-terminal" If Command Then sExec &= " -x " & Shell$(Command) Case "LXDE" sExec = "lxterminal" @@ -255,46 +254,43 @@ Case Else sExec = "xterm" If Command Then sExec &= " -e " & Shell$(Command) - + End Select - + If {Dir} And If Not bNoDir Then sCmd = "(cd " & Shell$({Dir}) & "; " & sExec & ")" Else sCmd = sExec Endif - + Shell sCmd - + End - Static Private Function Type_Read() As String - Return GetDesktop() + Return GetDesktop() End - Static Public Sub _get(Index As Integer) As _DesktopVirtual Dim hVirtual As _DesktopVirtual - + If Not $cDesktop Then $cDesktop = New Collection - + hVirtual = $cDesktop[Index] If Not hVirtual Then hVirtual = New _DesktopVirtual(Index) $cDesktop[Index] = hVirtual Endif Return hVirtual - + End - Static Private Function Current_Read() As Integer - Try Return _Desktop.GetWindowProperty(Atom["_NET_CURRENT_DESKTOP"])[0] + Try Return _Desktop.GetWindowProperty(Atom["_NET_CURRENT_DESKTOP"])[0] End @@ -313,7 +309,7 @@ Static Private Sub Count_Write(Value As Integer) - _Desktop.SendClientMessageToRootWindow(Atom["_NET_NUMBER_OF_DESKTOPS"], [Value]) + _Desktop.SendClientMessageToRootWindow(Atom["_NET_NUMBER_OF_DESKTOPS"], [Value]) End @@ -343,40 +339,40 @@ Static Private Sub Showing_Write(Value As Boolean) - _Desktop.SendClientMessageToRootWindow(Atom["_NET_SHOWING_DESKTOP"], [If(Value, 1, 0)]) + _Desktop.SendClientMessageToRootWindow(Atom["_NET_SHOWING_DESKTOP"], [If(Value, 1, 0)]) End ' Static Private Function Width_Read() As Integer -' +' ' Dim iWidth As Integer -' +' ' Try iWidth = _Desktop.GetWindowProperty(Atom["_NET_DESKTOP_GEOMETRY"])[0] ' If iWidth = 0 Then iWidth = Super.Width ' Return iWidth -' +' ' End -' +' ' Static Private Function Height_Read() As Integer -' +' ' Dim iHeight As Integer -' +' ' Try iHeight = _Desktop.GetWindowProperty(Atom["_NET_DESKTOP_GEOMETRY"])[1] ' If iHeight = 0 Then iHeight = Super.Height ' Return iHeight -' +' ' End ' Static Private Function W_Read() As Integer -' +' ' Return Width_Read() -' +' ' End -' +' ' Static Private Function H_Read() As Integer -' +' ' Return Height_Read() -' +' ' End Static Private Function Passwords_Read() As _Desktop_Passwords @@ -385,7 +381,6 @@ End - Static Private Function Path_Read() As String Return Main.GetDesktopPath() @@ -399,34 +394,33 @@ End Static Public Sub RunAsRoot(Command As String) - + Main.RunXdgUtil("xdg-su", ["-c", Command]) - End Static Public Sub GetFileIcon(Path As String, Size As Integer, Optional Preview As Boolean) As Picture - + Dim hImage As Image Dim hIcon As Image Dim sIcon As String Dim hPict As Picture - + If IsDir(Path) Then Return Picture["icon:/" & CStr(Size) & "/directory"] - + If Preview And If $aImgExt.Exist(File.Ext(Path)) < 0 Then - If Stat(Path).Size <= 65536 Then - + If Stat(Path).Size <= 65536 Then + Try hImage = Image.Load(Path) If Not Error Then - If Not (hImage.Width = Size And hImage.Height = Size) Then - If hImage.Width > hImage.Height Then + If Not (hImage.Width = Size And hImage.Height = Size) Then + If hImage.Width > hImage.Height Then hImage = hImage.Stretch(Size, (Size * hImage.Height) \ hImage.Width) Else hImage = hImage.Stretch((Size * hImage.Width) \ hImage.Height, Size) Endif Endif - + hIcon = New Image(hImage.W + 4, hImage.H + 4, Color.Transparent) Paint.Begin(hIcon) Paint.AntiAlias = False @@ -435,38 +429,38 @@ Paint.Stroke Paint.End hIcon.DrawImage(hImage, 2, 2) - + Return hIcon.Picture Else - Return Picture["icon:/" & Size & "/image"] + Return Picture["icon:/" & Size & "/image"] Endif - + Endif - + Endif Try hPict = DesktopMime.FromFile(Path).GetIcon(Size).Picture If hPict Then Return hPict - + If Not $cExt Then InitFileExt - + Try sIcon = $cExt[File.Ext(Path)] If sIcon Then Return Picture["icon:/" & CStr(Size) &/ sIcon] - + With Stat(Path) - + If InStr(.Perm[System.User.Name], "x") Then Return Picture["icon:/" & CStr(Size) &/ "exec"] - + End With - + Catch - + Error "gb.desktop: unable to get icon for file: "; File.Name(Path) - + End Static Private Sub InitFileExt() - + $cExt = New Collection $cExt["html"] = "html" $cExt["htm"] = "html" @@ -502,7 +496,7 @@ $cExt["ico"] = "image" $cExt["xcf"] = "image" $cExt["svg"] = "image" - + $aImgExt = ["png", "jpeg", "jpg", "gif", "xpm", "bmp", "ico"] - + End