[Solved] How to get version of installed OOo

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
lunter
Posts: 28
Joined: Fri May 29, 2009 9:16 am

[Solved] How to get version of installed OOo

Post by lunter »

Code: Select all

<?php
  //Invoke the OpenOffice.org service manager
  $osm = new COM("com.sun.star.ServiceManager",null,CP_UTF8);
?>
How to get version of installed OO??
Any method or property?
Last edited by lunter on Fri May 29, 2009 3:41 pm, edited 1 time in total.
OOo 3.3.X on MS Windows 7
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to get version of installed OOo

Post by Villeroy »

Let me answer by means of a Python class, creating a reference to the service manager as "root" at initialisation.
Calling the class routine getOOoSetupValue with node path /org.openoffice.Setup/Product and property "ooSetupVersion" returns "3.0" which is the property value named "ooSetupVersion" in node /Product stored in the XML-file <user profile>/registry/data/org/openoffice/Setup.xcu

Code: Select all

class Office:
    '''Frequently used methods in office context'''
    def __init__(self, ctx=uno.getComponentContext()):
        self.ctx = ctx
        self.smgr = self.ctx.ServiceManager
        
    def createUnoService(self, service):
        return self.smgr.createInstance(service)

    def getDesktop(self):
        return self.smgr.createInstanceWithContext("com.sun.star.frame.Desktop",self.ctx)

    def getCurrentComponent(self):
        return self.getDesktop().getCurrentComponent()

    def getCurrentFrame(self):
        return self.getDesktop().getCurrentFrame()

    def getCurrentComponentWindow(self):
        return self.getCurrentFrame().getComponentWindow()

    def getCurrentContainerWindow(self):
        return self.getCurrentFrame().getContainerWindow()

    def getCurrentController(self):
        return self.getCurrentFrame().getController()

    def callXray(self, obj=None):
        """Macro to call Basic XRay by Bernard Marcelly from Python.
        If no object is given, the current document's selection is used"""
        sURL = "vnd.sun.star.script:XRayTool._Main.Xray?language=Basic&location=application"
        if not obj:
            obj = self.getCurrentController().getSelection()

        oMSPF = self.createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
        oMSP = oMSPF.createScriptProvider('')
        oScript = oMSP.getScript(sURL)
        oScript.invoke((obj,), (), ()) 


        oMSPF = self.createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
        oMSP = oMSPF.createScriptProvider('')
        oScript = oMSP.getScript(sURL)
        x = oScript.invoke((thisComponent,), (), ())

    def callMRI(self,obj=None):
        '''Create an instance of MRI inspector and inspect the given object (default is selection)'''
        if not obj:
            obj = self.getCurrentController().getSelection()
        mri = self.createUnoService("mytools.Mri")
        mri.inspect(obj)

    def getOOoSetupNode(self, sNodePath):
        aConfigProvider = self.createUnoService("com.sun.star.configuration.ConfigurationProvider")
        arg = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
        arg.Name = "nodepath"
        arg.Value = sNodePath
        return aConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", (arg,))

    def getOOoSetupValue(self, sNodePath,sProperty):
        oNode = self.getOOoSetupNode(sNodePath)
        return oNode.getByName(sProperty)

    def setOOoSetupValue(self, sNodePath, sProperty, sValue):
        xconfig = self.createUnoService("com.sun.star.configuration.ConfigurationProvider")
        arg = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
        arg.Name = "nodepath"
        arg.Value = sNodePath
        try:
            xAccess = xconfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",(arg,))
            xAccess.setPropertyValue(sProperty, sValue)
            xAccess.commitChanges()
        except:
            return False
        else:
            return True

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
lunter
Posts: 28
Joined: Fri May 29, 2009 9:16 am

Re: How to get version of installed OOo

Post by lunter »

Thanks for help. It works.
OOo 3.3.X on MS Windows 7
Post Reply