1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#***********************************************************************/
27
28import uno
29import unohelper
30
31from com.sun.star.awt import Rectangle
32from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
33from com.sun.star.frame import XDispatch, XDispatchProvider
34from com.sun.star.lang import XServiceInfo
35from com.sun.star.registry import InvalidRegistryException
36
37class Provider(unohelper.Base, XServiceInfo, XDispatchProvider):
38    implementationName = "com.sun.star.comp.test.deployment.active_python"
39
40    serviceNames = ("com.sun.star.test.deployment.active_python",)
41
42    def __init__(self, context):
43        self.context = context
44
45    def getImplementationName(self):
46        return self.implementationName
47
48    def supportsService(self, ServiceName):
49        return ServiceName in self.serviceNames
50
51    def getSupportedServiceNames(self):
52        return self.serviceNames
53
54    def queryDispatch(self, URL, TargetFrame, SearchFlags):
55        return self.context.getValueByName( \
56            "/singletons/com.sun.star.test.deployment.active_python_singleton")
57
58    def queryDispatches(self, Requests):
59        tuple( \
60            self.queryDispatch(i.FeatureURL, i.FrameName, i.SearchFlags) \
61                for i in Requests)
62
63class Dispatch(unohelper.Base, XServiceInfo, XDispatch):
64    implementationName = \
65        "com.sun.star.comp.test.deployment.active_python_singleton"
66
67    serviceNames = ()
68
69    def __init__(self, context):
70        self.context = context
71
72    def getImplementationName(self):
73        return self.implementationName
74
75    def supportsService(self, ServiceName):
76        return ServiceName in self.serviceNames
77
78    def getSupportedServiceNames(self):
79        return self.serviceNames
80
81    def dispatch(self, URL, Arguments):
82        smgr = self.context.getServiceManager()
83        box = smgr.createInstanceWithContext( \
84            "com.sun.star.awt.Toolkit", self.context).createMessageBox( \
85                smgr.createInstanceWithContext( \
86                    "com.sun.star.frame.Desktop", self.context). \
87                    getCurrentFrame().getComponentWindow(), \
88                Rectangle(), "infobox", BUTTONS_OK, "active", "python")
89        box.execute();
90        box.dispose();
91
92    def addStatusListener(self, Control, URL):
93        pass
94
95    def removeStatusListener(self, Control, URL):
96        pass
97
98def getComponentFactory(implementationName, smgr, regKey):
99    if implementationName == Provider.implementationName:
100        return unohelper.createSingleServiceFactory( \
101            Provider, Provider.implementationName, Provider.serviceNames)
102    elif implementationName == Dispatch.implementationName:
103        return unohelper.createSingleServiceFactory( \
104            Dispatch, Dispatch.implementationName, Dispatch.serviceNames)
105    else:
106        return None
107
108def writeRegistryInfo(smgr, regKey):
109    try:
110        for i in (Provider, Dispatch):
111            key = regKey.createKey("/" + i.implementationName + "/UNO")
112            for j in i.serviceNames:
113                key.createKey("/SERVICES/" + j);
114        regKey.createKey( \
115            "/" + Dispatch.implementationName + "/UNO/SINGLETONS/" \
116                "com.sun.star.test.deployment.active_python_singleton"). \
117            setStringValue(Dispatch.implementationName)
118    except InvalidRegistryException:
119        return False
120    return True
121