diff options
-rw-r--r-- | wizards/source/scriptforge/SF_Platform.xba | 39 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Root.xba | 8 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Utils.xba | 56 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 7 |
4 files changed, 89 insertions, 21 deletions
diff --git a/wizards/source/scriptforge/SF_Platform.xba b/wizards/source/scriptforge/SF_Platform.xba index a19ee2bc7a6c..8bd7b5cad35f 100644 --- a/wizards/source/scriptforge/SF_Platform.xba +++ b/wizards/source/scriptforge/SF_Platform.xba @@ -83,8 +83,16 @@ Property Get Fonts() As Variant End Property ' ScriptForge.SF_Platform.Fonts (get) REM ----------------------------------------------------------------------------- +Property Get FormatLocale() As String +''' Returns the locale used for number and date formats, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.FormatLocale + FormatLocale = _PropertyGet("FormatLocale") +End Property ' ScriptForge.SF_Platform.FormatLocale (get) + +REM ----------------------------------------------------------------------------- Property Get Locale() As String -''' Returns the locale combining language-COUNTRY (la-CO) +''' Returns the locale of the operating system, combining language-COUNTRY (la-CO) ''' Example: ''' MsgBox platform.Locale Locale = _PropertyGet("Locale") @@ -105,6 +113,14 @@ Property Get ObjectType As String End Property ' ScriptForge.SF_Platform.ObjectType REM ----------------------------------------------------------------------------- +Property Get OfficeLocale() As String +''' Returns the locale of the user interface, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.OfficeLocale + OfficeLocale = _PropertyGet("OfficeLocale") +End Property ' ScriptForge.SF_Platform.OfficeLocale (get) + +REM ----------------------------------------------------------------------------- Property Get OfficeVersion() As String ''' Returns the office software version in the form 'LibreOffice w.x.y.z (The Document Foundation)' ''' Example: @@ -175,6 +191,14 @@ Property Get ServiceName As String ServiceName = "ScriptForge.Platform" End Property ' ScriptForge.SF_Platform.ServiceName +REM ----------------------------------------------------------------------------- +Property Get SystemLocale() As String +''' Returns the locale of the operating system, combining language-COUNTRY (la-CO) +''' Example: +''' MsgBox platform.SystemLocale + SystemLocale = _PropertyGet("SystemLocale") +End Property ' ScriptForge.SF_Platform.SystemLocale (get) + REM ===================================================================== METHODS REM ----------------------------------------------------------------------------- @@ -228,8 +252,10 @@ Public Function Properties() As Variant , "CPUCount" _ , "CurrentUser" _ , "Fonts" _ + , "FormatLocale" _ , "Locale" _ , "Machine" _ + , "OfficeLocale" _ , "OfficeVersion" _ , "OSName" _ , "OSPlatform" _ @@ -238,6 +264,7 @@ Public Function Properties() As Variant , "Printers" _ , "Processor" _ , "PythonVersion" _ + , "SystemLocale" _ ) End Function ' ScriptForge.SF_Platform.Properties @@ -350,8 +377,11 @@ Const cstSubArgs = "" Next i ' Remove leading and trailing commas If Len(sFonts) > 1 Then _PropertyGet = Split(Mid(sFonts, 2, Len(sFonts) - 2), ",") Else _PropertyGet = Array() - Case "Locale" - Set oLocale = SF_Utils._GetUNOService("SystemLocale") + Case "FormatLocale" + Set oLocale = SF_Utils._GetUNOService("FormatLocale") + _PropertyGet = oLocale.Language & "-" & oLocale.Country + Case "OfficeLocale" + Set oLocale = SF_Utils._GetUNOService("OfficeLocale") _PropertyGet = oLocale.Language & "-" & oLocale.Country Case "OfficeVersion" _PropertyGet = _GetProductName() @@ -371,6 +401,9 @@ Const cstSubArgs = "" _PropertyGet = sOSName Case "Printers" _PropertyGet = _GetPrinters() + Case "SystemLocale", "Locale" + Set oLocale = SF_Utils._GetUNOService("SystemLocale") + _PropertyGet = oLocale.Language & "-" & oLocale.Country Case Else _PropertyGet = Null End Select diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index 9d03fcd6f160..d14e121173cd 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -58,7 +58,9 @@ Private CoreReflection As Object ' com.sun.star.reflection.CoreReflection Private DispatchHelper As Object ' com.sun.star.frame.DispatchHelper Private TextSearch As Object ' com.sun.star.util.TextSearch Private SearchOptions As Object ' com.sun.star.util.SearchOptions -Private Locale As Object ' com.sun.star.lang.Locale +Private SystemLocale As Object ' com.sun.star.lang.Locale +Private OfficeLocale As Object ' com.sun.star.lang.Locale +Private FormatLocale As Object ' com.sun.star.lang.Locale Private PrinterServer As Object ' com.sun.star.awt.PrinterServer Private CharacterClass As Object ' com.sun.star.i18n.CharacterClassification Private FileAccess As Object ' com.sun.star.ucb.SimpleFileAccess @@ -118,7 +120,9 @@ Private Sub Class_Initialize() Set DispatchHelper = Nothing Set TextSearch = Nothing Set SearchOptions = Nothing - Set Locale = Nothing + Set OfficeLocale = Nothing + Set FormatLocale = Nothing + Set SystemLocale = Nothing Set PrinterServer = Nothing Set CharacterClass = Nothing Set FileAccess = Nothing diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba index c0d63bcc6b36..cbe07ce2b0ae 100644 --- a/wizards/source/scriptforge/SF_Utils.xba +++ b/wizards/source/scriptforge/SF_Utils.xba @@ -288,6 +288,23 @@ Const cstConfigUpdate = "com.sun.star.configuration.ConfigurationUpdateAcce End Function ' ScriptForge.SF_Utils._GetRegistryKeyContent REM ----------------------------------------------------------------------------- +Private Function _GetSetting(ByVal psPreference As String, psProperty As String) As Variant +''' Find in the configuration a specific setting based on its location in the +''' settings registry + +Dim oConfigProvider As Object ' com.sun.star.configuration.ConfigurationProvider +Dim vNodePath As Variant ' Array of com.sun.star.beans.PropertyValue + + ' Derived from the Tools library + Set oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") + vNodePath = Array(SF_Utils._MakePropertyValue("nodepath", psPreference)) + + _GetSetting = oConfigProvider.createInstanceWithArguments( _ + "com.sun.star.configuration.ConfigurationAccess", vNodePath()).getByName(psProperty) + +End Function ' ScriptForge.SF_Utils._GetSetting + +REM ----------------------------------------------------------------------------- Public Function _GetUNOService(ByVal psService As String _ , Optional ByVal pvArg As Variant _ ) As Object @@ -298,9 +315,7 @@ Public Function _GetUNOService(ByVal psService As String _ ''' pvArg: some services might require an argument Dim sLocale As String ' fr-BE f.i. -Dim oConfigProvider As Object Dim oDefaultContext As Object -Dim vNodePath As Variant Set _GetUNOService = Nothing With _SF_ @@ -353,6 +368,16 @@ Dim vNodePath As Variant Set .FolderPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker") End If Set _GetUNOService = .FolderPicker + Case "FormatLocale" + If IsEmpty(.FormatLocale) Or IsNull(.FormatLocale) Then + .FormatLocale = CreateUnoStruct("com.sun.star.lang.Locale") + ' 1st and 2nd chance + sLocale = SF_Utils._GetSetting("org.openoffice.Setup/L10N", "ooSetupSystemLocale") + If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "UILocale") + .FormatLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .FormatLocale.Country = Right(sLocale, 2) + End If + Set _GetUNOService = .FormatLocale Case "FunctionAccess" If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then Set .FunctionAccess = CreateUnoService("com.sun.star.sheet.FunctionAccess") @@ -380,6 +405,16 @@ Dim vNodePath As Variant End If End If Set _GetUNOService = .MailService + Case "OfficeLocale" + If IsEmpty(.OfficeLocale) Or IsNull(.OfficeLocale) Then + .OfficeLocale = CreateUnoStruct("com.sun.star.lang.Locale") + ' 1st and 2nd chance + sLocale = SF_Utils._GetSetting("org.openoffice.Setup/L10N", "ooLocale") + If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "UILocale") + .OfficeLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .OfficeLocale.Country = Right(sLocale, 2) + End If + Set _GetUNOService = .OfficeLocale Case "PathSettings" If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then Set .PathSettings = CreateUnoService("com.sun.star.util.PathSettings") @@ -417,18 +452,13 @@ Dim vNodePath As Variant End If Set _GetUNOService = .SearchOptions Case "SystemLocale", "Locale" - If IsEmpty(.Locale) Or IsNull(.Locale) Then - .Locale = CreateUnoStruct("com.sun.star.lang.Locale") - ' Derived from the Tools library - Set oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") - vNodePath = Array() : ReDim vNodePath(0) - vNodePath(0) = New com.sun.star.beans.PropertyValue - vNodePath(0).Name = "nodepath" : vNodePath(0).Value = "org.openoffice.System/L10N" - sLocale = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", vNodePath()).getByName("SystemLocale") - .Locale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always - .Locale.Country = Right(sLocale, 2) + If IsEmpty(.SystemLocale) Or IsNull(.SystemLocale) Then + .SystemLocale = CreateUnoStruct("com.sun.star.lang.Locale") + sLocale = SF_Utils._GetSetting("org.openoffice.System/L10N", "SystemLocale") + .SystemLocale.Language = Split(sLocale, "-")(0) ' Language is most often 2 chars long, but not always + .SystemLocale.Country = Right(sLocale, 2) End If - Set _GetUNOService = .Locale + Set _GetUNOService = .SystemLocale Case "SystemShellExecute" If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then Set .SystemShellExecute = CreateUnoService("com.sun.star.system.SystemShellExecute") diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 858a3ec77a71..94d5a3de7d58 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1218,9 +1218,10 @@ class SFScriptForge: servicename = 'ScriptForge.Platform' servicesynonyms = ('platform', 'scriptforge.platform') serviceproperties = dict(Architecture = False, ComputerName = False, CPUCount = False, CurrentUser = False, - Fonts = False, Locale = False, Machine = False, OfficeVersion = False, OSName = False, - OSPlatform = False, OSRelease = False, OSVersion = False, Printers = False, - Processor = False, PythonVersion = False) + Fonts = False, FormatLocale = False, Locale = False, Machine = False, + OfficeLocale = False, OfficeVersion = False, OSName = False, OSPlatform = False, + OSRelease = False, OSVersion = False, Printers = False, Processor = False, + PythonVersion = False, SystemLocale = False) # Python helper functions py = ScriptForge.pythonhelpermodule + '$' + '_SF_Platform' |