1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22import uno
23import unohelper
24
25from com.sun.star.awt import Rectangle
26from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
27from com.sun.star.frame import XDispatch, XDispatchProvider
28from com.sun.star.lang import XServiceInfo
29from com.sun.star.registry import InvalidRegistryException
30
31class Provider(unohelper.Base, XServiceInfo, XDispatchProvider):
32    implementationName = "com.sun.star.comp.test.deployment.active_python"
33
34    serviceNames = ("com.sun.star.test.deployment.active_python",)
35
36    def __init__(self, context):
37        self.context = context
38
39    def getImplementationName(self):
40        return self.implementationName
41
42    def supportsService(self, ServiceName):
43        return ServiceName in self.serviceNames
44
45    def getSupportedServiceNames(self):
46        return self.serviceNames
47
48    def queryDispatch(self, URL, TargetFrame, SearchFlags):
49        return self.context.getValueByName( \
50            "/singletons/com.sun.star.test.deployment.active_python_singleton")
51
52    def queryDispatches(self, Requests):
53        tuple( \
54            self.queryDispatch(i.FeatureURL, i.FrameName, i.SearchFlags) \
55                for i in Requests)
56
57class Dispatch(unohelper.Base, XServiceInfo, XDispatch):
58    implementationName = \
59        "com.sun.star.comp.test.deployment.active_python_singleton"
60
61    serviceNames = ()
62
63    def __init__(self, context):
64        self.context = context
65
66    def getImplementationName(self):
67        return self.implementationName
68
69    def supportsService(self, ServiceName):
70        return ServiceName in self.serviceNames
71
72    def getSupportedServiceNames(self):
73        return self.serviceNames
74
75    def dispatch(self, URL, Arguments):
76        smgr = self.context.getServiceManager()
77        box = smgr.createInstanceWithContext( \
78            "com.sun.star.awt.Toolkit", self.context).createMessageBox( \
79                smgr.createInstanceWithContext( \
80                    "com.sun.star.frame.Desktop", self.context). \
81                    getCurrentFrame().getComponentWindow(), \
82                Rectangle(), "infobox", BUTTONS_OK, "active", "python")
83        box.execute();
84        box.dispose();
85
86    def addStatusListener(self, Control, URL):
87        pass
88
89    def removeStatusListener(self, Control, URL):
90        pass
91
92def getComponentFactory(implementationName, smgr, regKey):
93    if implementationName == Provider.implementationName:
94        return unohelper.createSingleServiceFactory( \
95            Provider, Provider.implementationName, Provider.serviceNames)
96    elif implementationName == Dispatch.implementationName:
97        return unohelper.createSingleServiceFactory( \
98            Dispatch, Dispatch.implementationName, Dispatch.serviceNames)
99    else:
100        return None
101
102def writeRegistryInfo(smgr, regKey):
103    try:
104        for i in (Provider, Dispatch):
105            key = regKey.createKey("/" + i.implementationName + "/UNO")
106            for j in i.serviceNames:
107                key.createKey("/SERVICES/" + j);
108        regKey.createKey( \
109            "/" + Dispatch.implementationName + "/UNO/SINGLETONS/" \
110                "com.sun.star.test.deployment.active_python_singleton"). \
111            setStringValue(Dispatch.implementationName)
112    except InvalidRegistryException:
113        return False
114    return True
115