summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/common/Configuration.py
blob: 9f768e9bfb8d6acef43cd79bf65e227183e57c3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
from PropertyNames import PropertyNames
from Helper import *
import traceback
import uno
'''
This class gives access to the OO configuration api.
It contains 4 get and 4 set convenience methods for getting and settings
properties in the configuration. <br/>
For the get methods, two parameters must be given: name and parent, where
name is the name of the property, parent is a HierarchyElement
(::com::sun::star::configuration::HierarchyElement)<br/>
The get and set methods support hieryrchical property names like
"options/gridX". <br/>
NOTE: not yet supported, but sometime later,
If you will ommit the "parent" parameter, then the "name" parameter must be
in hierarchy form from the root of the registry.
'''

class Configuration(object):

    @classmethod
    def getConfigurationRoot(self, xmsf, sPath, updateable):
        oConfigProvider = xmsf.createInstance(
            "com.sun.star.configuration.ConfigurationProvider")
        args = []

        aPathArgument = uno.createUnoStruct(
            'com.sun.star.beans.PropertyValue')
        aPathArgument.Name = "nodepath"
        aPathArgument.Value = sPath

        args.append(aPathArgument)
        if updateable:
            sView = "com.sun.star.configuration.ConfigurationUpdateAccess"
            aModeArgument = uno.createUnoStruct(
                'com.sun.star.beans.PropertyValue')
            aModeArgument.Name = "lazywrite"
            aModeArgument.Value = False
            args.append(aModeArgument)
        else:
            sView = "com.sun.star.configuration.ConfigurationAccess"

        return oConfigProvider.createInstanceWithArguments(sView, tuple(args))

    @classmethod
    def getProductName(self, xMSF):
        try:
            oProdNameAccess = self.getConfigurationRoot(xMSF,
                "org.openoffice.Setup/Product", False)
            ProductName = Helper.getUnoObjectbyName(oProdNameAccess, "ooName")
            return ProductName
        except Exception:
            traceback.print_exc()
            return None

    @classmethod
    def getOfficeLocaleString(self, xMSF):
        sLocale = ""
        try:
            aLocLocale = Locale.Locale()
            oMasterKey = self.getConfigurationRoot(xMSF,
                "org.openoffice.Setup/L10N/", False)
            sLocale = (String)
            Helper.getUnoObjectbyName(oMasterKey, "ooLocale")
        except Exception, exception:
            traceback.print_exc()

        return sLocale

    @classmethod
    def getOfficeLocale(self, xMSF):
        aLocLocale = Locale.Locale()
        sLocale = getOfficeLocaleString(xMSF)
        sLocaleList = JavaTools.ArrayoutofString(sLocale, "-")
        aLocLocale.Language = sLocaleList[0]
        if sLocaleList.length > 1:
            aLocLocale.Country = sLocaleList[1]

        return aLocLocale

    @classmethod
    def getOfficeLinguistic(self, xMSF):
        try:
            oMasterKey = self.getConfigurationRoot(xMSF,
                "org.openoffice.Setup/L10N/", False)
            sLinguistic = Helper.getUnoObjectbyName(oMasterKey, "ooLocale")
            return sLinguistic
        except Exception, exception:
            traceback.print_exc()
            return None

    @classmethod
    def removeNode(self, configView, name, xmsf=None):
        commitChanges = False
        if xmsf is not None:
            configView = self.getConfigurationRoot(xmsf, path, True)
            commit = True

        if configView.hasByName(name):
            configView.removeByName(name)

        if commitChanges:
            configView.commitChanges()

    @classmethod
    def updateConfiguration(self, xmsf, path, name, node, param):
        view = self.getConfigurationRoot(xmsf, path, True)
        addConfigNode(path, name)
        node.writeConfiguration(view, param)
        view.commitChanges()

    @classmethod
    def getNodeDisplayNames(self, _xNameAccessNode):
        snames = None
        return getNodeChildNames(_xNameAccessNode,
            PropertyNames.PROPERTY_NAME)

    @classmethod
    def getNodeChildNames(self, xNameAccessNode, _schildname):
        snames = None
        try:
            snames = xNameAccessNode.getElementNames()
            sdisplaynames = range(snames.length)
            i = 0
            while i < snames.length:
                oContent = Helper.getUnoPropertyValue(
                    xNameAccessNode.getByName(snames[i]), _schildname)
                if not AnyConverter.isVoid(oContent):
                    sdisplaynames[i] = (String)
                    Helper.getUnoPropertyValue(xNameAccessNode.getByName(
                        snames[i]), _schildname)
                else:
                    sdisplaynames[i] = snames[i]

                i += 1
            return sdisplaynames
        except Exception, e:
            traceback.print_exc()
            return snames

    @classmethod
    def getChildNodebyIndex(self, _xNameAccess, _index):
        try:
            snames = _xNameAccess.getElementNames()
            oNode = _xNameAccess.getByName(snames[_index])
            return oNode
        except Exception, e:
            traceback.print_exc()
            return None

    @classmethod
    def getChildNodebyName(self, _xNameAccessNode, _SubNodeName):
        try:
            if _xNameAccessNode.hasByName(_SubNodeName):
                return _xNameAccessNode.getByName(_SubNodeName)

        except Exception, e:
            traceback.print_exc()

        return None

    @classmethod
    def getChildNodebyDisplayName(self, _xNameAccessNode, _displayname):
        snames = None
        return getChildNodebyDisplayName(_xNameAccessNode, _displayname,
            PropertyNames.PROPERTY_NAME)

    @classmethod
    def getChildNodebyDisplayName(self, _xNameAccessNode, _displayname,
        _nodename):

        snames = None
        try:
            snames = _xNameAccessNode.getElementNames()
            sdisplaynames = range(snames.length)
            i = 0
            while i < snames.length:
                curdisplayname = Helper.getUnoPropertyValue(
                    _xNameAccessNode.getByName(snames[i]), _nodename)
                if curdisplayname.equals(_displayname):
                    return _xNameAccessNode.getByName(snames[i])

                i += 1
        except Exception, e:
            traceback.print_exc()

        return None

    @classmethod
    def getChildNodebyDisplayName(self, _xMSF, _aLocale, _xNameAccessNode,
        _displayname, _nodename, _nmaxcharcount):

        snames = None
        try:
            snames = _xNameAccessNode.getElementNames()
            sdisplaynames = range(snames.length)
            i = 0
            while i < snames.length:
                curdisplayname = Helper.getUnoPropertyValue(
                    _xNameAccessNode.getByName(snames[i]), _nodename)
                if (_nmaxcharcount > 0) and (_nmaxcharcount < \
                        curdisplayname.length()):
                    curdisplayname = curdisplayname.substring(0,
                        _nmaxcharcount)

                curdisplayname = Desktop.removeSpecialCharacters(_xMSF,
                    _aLocale, curdisplayname)
                if curdisplayname.equals(_displayname):
                    return _xNameAccessNode.getByName(snames[i])

                i += 1
        except Exception, e:
            traceback.print_exc()
        return None