Configuration.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. import uno
  19. import traceback
  20. class Configuration(object):
  21. '''This class gives access to the OO configuration api.'''
  22. @classmethod
  23. def getConfigurationRoot(self, xmsf, sPath, updateable):
  24. oConfigProvider = xmsf.createInstance(
  25. "com.sun.star.configuration.ConfigurationProvider")
  26. args = []
  27. aPathArgument = uno.createUnoStruct(
  28. 'com.sun.star.beans.PropertyValue')
  29. aPathArgument.Name = "nodepath"
  30. aPathArgument.Value = sPath
  31. args.append(aPathArgument)
  32. if updateable:
  33. sView = "com.sun.star.configuration.ConfigurationUpdateAccess"
  34. else:
  35. sView = "com.sun.star.configuration.ConfigurationAccess"
  36. return oConfigProvider.createInstanceWithArguments(sView, tuple(args))
  37. @classmethod
  38. def getProductName(self, xMSF):
  39. try:
  40. oProdNameAccess = self.getConfigurationRoot(xMSF, "org.openoffice.Setup/Product", False);
  41. return oProdNameAccess.getByName("ooName")
  42. except Exception:
  43. traceback.print_exc()
  44. return "Unknown"
  45. @classmethod
  46. def getNode(self, name, parent):
  47. return parent.getByName(name)
  48. @classmethod
  49. def commit(self, configView):
  50. configView.commitChanges()
  51. @classmethod
  52. def getInt(self, name, parent):
  53. o = getNode(name, parent)
  54. if (com.sun.star.uno.AnyConverter.isVoid(o)):
  55. return 0
  56. return com.sun.star.uno.AnyConverter.toInt(o)
  57. @classmethod
  58. def set(self, value, name, parent):
  59. parent.setHierarchicalPropertyValue(name, value)