[Gambas-user] Get the default file manager
Bruce Steers
bsteers4 at gmail.com
Sun Feb 18 12:58:35 CET 2024
Wow that's getting a little long though now.
The /usr/share/applications folder can be huge, i'd rather not have to scan
it.
I got it down to this using your cool suggestion of
$HOME/.config/mimeapps.list.....
Dim aIniFile As String[] = Split(File.Load(User.Home &/
".config/mimeapps.list"), "\n")
Dim iPos As Integer = aIniFile.Find("[Default Applications]") ' search
for inode in the default apps part
iPos = aIniFile.Find("inode/directory=*", gb.like, iPos)
Dim sApp As String = Split(aIniFile[iPos], "=")[1]
Dim hDF As DesktopFile = New DesktopFile("/usr/share/applications" &/
sApp)
hdf.Run(User.Home)
But I bet ~/.config/mimeapps.list does not exist on all systems.
Respects
BruceS
On Sun, 18 Feb 2024 at 11:47, System64 Development <64xcode at gmail.com>
wrote:
> play whit this if you want, maybe this code shows Caja.
>
> ' Gambas class file
>
> Public Sub Form_Open()
>
> Dim o As Collection
> Dim sMessage As String
>
> 'o = DeskApps("FileManager")
> o = DeskApps()
>
> If o.Count > 0 Then
> If o.Count > 1 Then
> sMessage = Subst(("You have &1 file managers in your desktop"),
> CStr(o.Count)) & gb.NewLine & o.Keys.Join("\n")
> Else
> sMessage = Subst(("You have &1 file manager in your desktop"),
> CStr(o.Count)) & gb.NewLine & o.Keys.Join("\n")
> Endif
> sMessage &= gb.NewLine & ("Your default file manager application
> is:") & gb.NewLine & DesktopFile.FromMime("inode/directory")[0].ProgramName
> Message.Info(sMessage)
>
> 'If
> DesktopFile.FromMime("inode/directory")[0].Categories.Exist("FileManager")
> Then
> ' DesktopFile.FromMime("inode/directory")[0].Run(User.Home)
> 'Endif
>
> Endif
>
> End
>
> '' This function list all the .desktop applications in the directory
> /usr/share/applications with the asociated relevant data in a
> collection. Is possible provide a text filter for the categories section.
>
> Public Function DeskApps(Optional sFilter As String) As Collection
>
> Dim a As String[]
> Dim aTags As String[] = ["Name", "Comment", "GenericName",
> "Keywords", "Exec", "Icon", "Terminal", "Type", "Categories", "MimeType"]
> Dim q As Integer
> Dim s As String
> Dim sEntry As String
> Dim oTmp As New Collection
> Dim oData As New Collection
> Dim l As String
> Dim sTag As String
> Dim sVal As String
> Dim k As String
>
> 'a = ScanFiles("/usr/share/applications", ["desktop"], 1)
> a = ScanFiles("/usr/share/applications", [], 1)
> a.Sort(gb.Ascent)
> For Each s In a
> sEntry = File.Load(s)
> q = 0
> oTmp.Clear
>
> For Each k In aTags
> For Each l In Split(sEntry, "\n")
> If InStr(l, "=") > 0 Then
> sTag = Split(l, "=")[0]
> sVal = Split(l, "=")[1]
> If Not oTmp.Exist(sTag) Then
> If k = sTag Then
> oTmp[sTag] = sVal
> Inc q
> If q > aTags.Count + 1 Then
> Break
> Endif
> Endif
> Endif
> Endif
> Next
> Next
> 'If sFilter <> "" Then
> 'If oTmp.Exist("Categories") Then
> ' If InStr(Lower(oTmp["Categories"]), Lower(sFilter)) > 0 Then
> ' oData[s] = oTmp.Copy()
> ' Endif
> 'Endif
> 'Else
> oData[s] = oTmp.Copy()
> 'Endif
>
> Next
>
> Return oData
>
> End
>
> '' <b>RAD Extension.</b><br>
> '' Return a files list nested in a directory using a find command
>
> Static Public Function ScanFiles(sPath As String, ext As String[],
> Optional maxdepth As Integer, Optional sFilter As String) As String[]
>
> Dim out As New String[]
> Dim t As String
> Dim ex As String
> Dim sTmp As String
> Dim aOut As New String[]
>
> If maxdepth = Null Or maxdepth < 1 Then
> maxdepth = 1
> Endif
>
> If Exist(sPath) Then
> Select ext.Count
> Case 0
> Shell "find '" & sPath & "' -maxdepth " & CStr(maxdepth) & "
> -type f -printf '%p\n' 2>&1" To t
> Case 1
> Shell "find '" & sPath & "' -maxdepth " & CStr(maxdepth) & "
> -type f -name '*.'" & ext[0] & " -printf '%p\n' 2>&1" To t
> Case Else
> ex = "\\( -name \"*."
> ex &= ext.Join("\" -o -name \"*.")
> ex &= "\" \\)"
> Shell "find '" & sPath & "' -maxdepth " & CStr(maxdepth) & "
> -type f " & ex & " -printf '%p\n' 2>&1" To t
> End Select
>
> out = Split(t, "\n")
>
> If out.Count > 0 Then
> If out[out.Max] = "" Then
> out.Remove(out.Max, 1)
> Endif
> Endif
>
> Endif
>
> If sFilter <> "" Then
> For Each sTmp In out
> If InStr(sTmp, sFilter) > 0 Then
> aOut.Add(sTmp)
> Endif
> Next
> Else
> aOut = out.Copy()
> Endif
>
> Return aOut
>
> End
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20240218/6e8f1a10/attachment.htm>
More information about the User
mailing list