UnixOperatingSystem.st
changeset 18923 fc32a7567437
parent 18758 fd717520a5ef
child 18930 59e70e261e49
child 19044 318352c827d7
equal deleted inserted replaced
18922:aee337248062 18923:fc32a7567437
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   623 
   621 
   624 %}
   622 %}
   625 ! !
   623 ! !
   626 
   624 
   627 !UnixOperatingSystem primitiveFunctions!
   625 !UnixOperatingSystem primitiveFunctions!
   628 
       
   629 %{
   626 %{
   630 
   627 
   631 /*
   628 /*
   632  * some systems' system() is broken in that it does not correctly
   629  * some systems' system() is broken in that it does not correctly
   633  * handle EINTR and returns failure even though it actually succeeded.
   630  * handle EINTR and returns failure even though it actually succeeded.
  1960 
  1957 
  1961 openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil ifNone:exceptionBlock
  1958 openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil ifNone:exceptionBlock
  1962     "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
  1959     "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
  1963      This is typically used to present help-files, html documents, pdf documents etc.
  1960      This is typically used to present help-files, html documents, pdf documents etc.
  1964      operationSymbol is one of:
  1961      operationSymbol is one of:
  1965 	open
  1962         open
  1966 	edit
  1963         edit
  1967 	explore
  1964         explore
  1968      mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf';
  1965      mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf';
  1969      if nil is passed in, the file's suffix is used to guess it.
  1966      if nil is passed in, the file's suffix is used to guess it.
  1970     "
  1967     "
  1971 
  1968 
  1972     | cmd |
  1969     | cmd |
  1973 
  1970 
  1974     cmd := self openApplicationHelperCommand.
  1971     cmd := self openApplicationHelperCommand.
  1975     cmd notNil ifTrue:[
  1972     cmd notNil ifTrue:[
  1976 	(cmd includesSubString:'%1') ifTrue:[
  1973         (cmd includesSubString:'%1') ifTrue:[
  1977 	    cmd := cmd bindWith:aFilenameOrString asString.
  1974             cmd := cmd bindWith:aFilenameOrString asString.
  1978 	] ifFalse:[
  1975         ] ifFalse:[
  1979 	    cmd := cmd, ' "', aFilenameOrString asString, '"'.
  1976             cmd := cmd, ' "', aFilenameOrString asString, '"'.
  1980 	].
  1977         ].
  1981 	(self
  1978         (self
  1982 		startProcess:cmd
  1979             startProcess:cmd
  1983 		inputFrom:nil outputTo:nil
  1980             inputFrom:nil outputTo:nil
  1984 		errorTo:nil auxFrom:nil
  1981             errorTo:nil auxFrom:nil
  1985 		environment: self getEnvironment inDirectory:nil) notNil ifTrue:[ ^ self ]
  1982             environment: self getEnvironment inDirectory:nil) notNil ifTrue:[ ^ self ]
  1986     ].
  1983     ].
  1987     ^ super openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil ifNone:exceptionBlock
  1984     ^ super openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil ifNone:exceptionBlock
  1988 
  1985 
  1989 
  1986 
  1990     "
  1987     "
  1999 !
  1996 !
  2000 
  1997 
  2001 openApplicationHelperCommand
  1998 openApplicationHelperCommand
  2002     "Return a command line helper to open a default application for file or URL"
  1999     "Return a command line helper to open a default application for file or URL"
  2003 
  2000 
  2004     | xdgCurrentDesktop |
  2001     | xdgCurrentDesktop usersPref |
       
  2002 
       
  2003     ((usersPref := UserPreferences current osFileExplorerCommand) notEmptyOrNil
       
  2004     and:[ self canExecuteCommand:(usersPref subStrings first) ]) ifTrue:[
       
  2005         ^ usersPref
       
  2006     ].    
  2005 
  2007 
  2006     xdgCurrentDesktop := self getEnvironment: 'XDG_CURRENT_DESKTOP'.
  2008     xdgCurrentDesktop := self getEnvironment: 'XDG_CURRENT_DESKTOP'.
  2007     ((xdgCurrentDesktop = 'GNOME') and:[self canExecuteCommand: 'gnome-open']) ifTrue:[
  2009     ((xdgCurrentDesktop = 'GNOME') and:[self canExecuteCommand: 'gnome-open']) ifTrue:[
  2008 	^ 'gnome-open'
  2010         ^ 'gnome-open'
  2009     ].
  2011     ].
  2010     "/ Guess...
  2012     "/ Guess...
  2011     ((xdgCurrentDesktop = 'KDE') and:[self canExecuteCommand: 'kde-open']) ifTrue:[
  2013     ((xdgCurrentDesktop = 'KDE') and:[self canExecuteCommand: 'kde-open']) ifTrue:[
  2012 	^ 'kde-open'
  2014         ^ 'kde-open'
  2013     ].
  2015     ].
  2014     (self canExecuteCommand: 'xdg-open') ifTrue:[
  2016     (self canExecuteCommand: 'xdg-open') ifTrue:[
  2015 	^ 'xdg-open'
  2017         ^ 'xdg-open'
       
  2018     ].
       
  2019     (self canExecuteCommand: 'nautilus') ifTrue:[
       
  2020         ^ 'nautilus'
  2016     ].
  2021     ].
  2017     ^ nil
  2022     ^ nil
  2018 
  2023 
  2019     "
  2024     "
  2020      self openApplicationHelperCommand
  2025      self openApplicationHelperCommand
  2022      self openApplicationForDocument: 'https://www.exept.de' operation: #open.
  2027      self openApplicationForDocument: 'https://www.exept.de' operation: #open.
  2023      self openApplicationForDocument: Filename currentDirectory operation:#open
  2028      self openApplicationForDocument: Filename currentDirectory operation:#open
  2024     "
  2029     "
  2025 
  2030 
  2026     "Created: / 13-01-2015 / 09:02:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2031     "Created: / 13-01-2015 / 09:02:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2027 
       
  2028 ! !
  2032 ! !
  2029 
  2033 
  2030 !UnixOperatingSystem class methodsFor:'error messages'!
  2034 !UnixOperatingSystem class methodsFor:'error messages'!
  2031 
  2035 
  2032 currentErrorNumber
  2036 currentErrorNumber
  9533 
  9537 
  9534     "
  9538     "
  9535      Codeset := #'utf8-mac'.
  9539      Codeset := #'utf8-mac'.
  9536      CodesetEncoder := nil.
  9540      CodesetEncoder := nil.
  9537      OperatingSystem getCodesetEncoder
  9541      OperatingSystem getCodesetEncoder
  9538      OperatingSystem encodePath:'äöü'
  9542      OperatingSystem encodePath:'äöü'
  9539     "
  9543     "
  9540 
  9544 
  9541     "Modified: / 23-01-2013 / 10:00:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  9545     "Modified: / 23-01-2013 / 10:00:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  9542 ! !
  9546 ! !
  9543 
  9547 
 13058 	    domain:nil type:nil protocol:nil flags:nil
 13062 	    domain:nil type:nil protocol:nil flags:nil
 13059      self getAddressInfo:'www.exept.de' serviceName:nil
 13063      self getAddressInfo:'www.exept.de' serviceName:nil
 13060 	    domain:#'AF_INET' type:nil protocol:nil flags:nil
 13064 	    domain:#'AF_INET' type:nil protocol:nil flags:nil
 13061      self getAddressInfo:'www.exept.de' serviceName:nil
 13065      self getAddressInfo:'www.exept.de' serviceName:nil
 13062 	    domain:#'AF_INET6' type:nil protocol:nil flags:nil
 13066 	    domain:#'AF_INET6' type:nil protocol:nil flags:nil
 13063      self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
 13067      self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
 13064 	    domain:#'AF_INET' type:#stream protocol:nil flags:nil
 13068 	    domain:#'AF_INET' type:#stream protocol:nil flags:nil
 13065     "
 13069     "
 13066 !
 13070 !
 13067 
 13071 
 13068 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags
 13072 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags