From 6db890bfbb4cc86d0963599b70033b4eb32ff154 Mon Sep 17 00:00:00 2001 From: Javier Fernandez Date: Fri, 8 Mar 2013 12:56:16 +0000 Subject: Ugly Hack: using our own WebConfigSet while the Topic stuff is not integrated. Change-Id: I0df92af6b01e5eab99212bb1587f7165c70fd59b --- wizards/Pyuno_web.mk | 80 ++++++++ wizards/com/sun/star/wizards/web/WebConfigSet.py | 209 +++++++++++++++++++++ wizards/com/sun/star/wizards/web/data/CGContent.py | 6 +- .../com/sun/star/wizards/web/data/CGExporter.py | 4 +- wizards/com/sun/star/wizards/web/data/CGSession.py | 6 +- .../com/sun/star/wizards/web/data/CGSettings.py | 18 +- 6 files changed, 306 insertions(+), 17 deletions(-) create mode 100644 wizards/Pyuno_web.mk create mode 100644 wizards/com/sun/star/wizards/web/WebConfigSet.py (limited to 'wizards') diff --git a/wizards/Pyuno_web.mk b/wizards/Pyuno_web.mk new file mode 100644 index 000000000000..93b312f9da8b --- /dev/null +++ b/wizards/Pyuno_web.mk @@ -0,0 +1,80 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# Major Contributor(s): +# Copyright (C) 2011 Red Hat, Inc., David Tardon +# (initial developer) +# +# All Rights Reserved. +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. + +$(eval $(call gb_Pyuno_Pyuno,web,$(SRCDIR)/wizards/com/sun/star/wizards/web)) + +$(eval $(call gb_Pyuno_add_files,web,\ + CallWizard.py \ + BackgroundsDialog.py \ + ErrorHandler.py \ + AbstractErrorHandler.py \ + FTPDialog.py \ + FTPDialogResources.py \ + IconsDialog.py \ + ImageListDialog.py \ + LogTaskListener.py \ + Process.py \ + ProcessErrorHandler.py \ + ProcessErrors.py \ + ProcessStatusRenderer.py \ + StatusDialog.py \ + StylePreview.py \ + TOCPreview.py \ + WWD_Events.py \ + WWD_General.py \ + WWD_Startup.py \ + WWHID.py \ + WebWizard.py \ + WebWizardConst.py \ + WebWizardDialog.py \ + WebWizardDialogResources.py \ + TypeDetection.py \ + ExtensionVerifier.py\ + WebConfigSet.py\ + __init__.py \ + data/CGArgument.py \ + data/CGContent.py \ + data/CGDesign.py \ + data/CGDocument.py \ + data/CGExporter.py \ + data/CGFilter.py \ + data/CGGeneralInfo.py \ + data/CGIconSet.py \ + data/CGImage.py \ + data/CGLayout.py \ + data/CGPublish.py \ + data/CGSession.py \ + data/CGSessionName.py \ + data/CGSettings.py \ + data/CGStyle.py\ + data/__init__.py \ + export/Exporter.py \ + export/AbstractExporter.py \ + export/CopyExporter.py \ + export/__init__.py \ +)) +$(eval $(call gb_Pyuno_set_componentfile_full,web,wizards/com/sun/star/wizards/web/web,vnd.openoffice.pymodule:wizards.web,.CallWizard)) diff --git a/wizards/com/sun/star/wizards/web/WebConfigSet.py b/wizards/com/sun/star/wizards/web/WebConfigSet.py new file mode 100644 index 000000000000..88b49f227666 --- /dev/null +++ b/wizards/com/sun/star/wizards/web/WebConfigSet.py @@ -0,0 +1,209 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +from ..common.ConfigGroup import ConfigGroup +from ..common.Configuration import Configuration +from ..common.XMLProvider import XMLProvider + +class WebConfigSet(ConfigGroup): + ''' + After reading the configuration set items, + the ConfigSet checks this field. + If it is true, it will remove any nulls from + the vector. + subclasses can change this field in the constructor + to avoid this "deletion" of nulls. + ''' + + def __init__(self, childType): + print ("DEBUG !!! childType: ", childType) + self.childClass = childType + self.childrenMap = {} + self.childrenList = [] + self.noNulls = False + + def add(self, name, o): + print ("DEBUG !!! WebConfigSet.add -- name: ", name) + if (o is None): + print ("DEBUG !!! WebConfigSet.add -- Received None object as argument.") + oldO = None + if (name in self.childrenMap): + oldO = self.childrenMap[name] + self.childrenMap[name] = o + try: + i = int(name) + print ("DEBUG !!! WebConfigSet.add -- name IS an integer.") + self.childrenList.insert(i, o) + except Exception: + print ("DEBUG !!! WebConfigSet.add -- name IS NOT an integer.") + try: + i = o.cp_Index + print ("DEBUG !!! WebConfigSet.add -- index: ", i) + oldSize = self.getSize() + print ("DEBUG !!! WebConfigSet.add -- oldSize: ", oldSize) + if oldSize < i: + newSize = i - oldSize + self.childrenList += [None] * newSize + self.noNulls |= True + else: + self.noNulls |= False + print ("DEBUG !!! WebConfigSet.add -- inserting object o: ", o) + self.childrenList.insert(i, o) + if oldSize > i: + oldSize = i + except Exception: + if (oldO is not None): + print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, but element already present, so replace it.") + i = self.childrenList.index(oldO) + self.childrenList[i] = o + else: + print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, so just append it.") + self.childrenList.append(o) + + + def writeConfiguration(self, configView, param): + print ("DEBUG !!! writeConfiguration --") + names = self.childrenMap.keys() + #first I remove all the children from the configuration. + children = configView.ElementNames + print ("DEBUG !!! writeConfiguration -- children length: ", len(children)) + if children: + print ("DEBUG !!! writeConfiguration -- removing childrens.") + for i in children: + try: + Configuration.removeNode(configView, i) + except Exception: + traceback.print_exc() + + # and add them new. + for i in names: + try: + child = self.getElement(i) + childView = Configuration.addConfigNode(configView, i) + child.writeConfiguration(childView, param) + except Exception: + traceback.print_exc() + + def readConfiguration(self, configurationView, param): + names = configurationView.ElementNames + if names: + for i in names: + print ("DEBUG !!! readConfiguration -- name: ", i) + try: + child = self.childClass() + child.root = self.root + child.readConfiguration( + configurationView.getByName(i), param) + self.add(i, child) + except Exception: + traceback.print_exc() + #remove any nulls from the list + if self.noNulls: + i = 0 + while i < len(self.childrenList): + if self.childrenList[i] is None: + del self.childrenList[i] + i -= 1 + i += 1 + + def remove(self, obj): + key = getKey(obj) + self.childrenMap.remove(key) + i = self.childrenList.indexOf(obj) + self.childrenList.remove(obj) + #fireListDataListenerIntervalRemoved(i, i) + + def remove(self, i): + o = getElementAt(i) + remove(o) + + def clear(self): + self.childrenMap.clear() + del self.childrenList[:] + + def createDOM(self, parent): + items = self.childrenList + i = 0 + while i < len(items): + item = items[i] + if isinstance(item, XMLProvider): + item.createDOM(parent) + + i += 1 + return parent + + def getKey(self, _object): + for k,v in self.childrenMap.items(): + if v is _object: + return k + return None + + def getElementAt(self, i): + return self.childrenList[i] + + def getElement(self, o): + return self.childrenMap[o] + + def getSize(self): + return len(self.childrenList) + + def getIndexOf(self, item): + return self.childrenList.index(item) + + ''' + Set members might include a property + which orders them. + This method reindexes the given member to be + the index number 0 + Do not forget to call commit() after calling this method. + @param confView + @param memebrName + ''' + + def reindexSet(self, confView, memberName, indexPropertyName): + ''' + First I read all memebrs of the set, + except the one that should be number 0 + to a vector, ordered by there index property + ''' + names = Configuration.getChildrenNames(confView) + v = [] + member = None + index = 0 + i = 0 + while i < len(names): + if not names[i] == memberName: + member = Configuration.getNode(names[i], confView) + index = Configuration.getInt(indexPropertyName, member) + while index >= v.size(): + v.append(None) + v[index] = member + ''' + Now I reindex them + ''' + i += 1 + index = 1 + i = 0 + while i < len(v): + member = v[i] + if member != None: + Configuration.set((index + 1), indexPropertyName, member) + i += 1 + + def sort(self, comparator): + self.childrenList.sort(comparator) diff --git a/wizards/com/sun/star/wizards/web/data/CGContent.py b/wizards/com/sun/star/wizards/web/data/CGContent.py index c85d7dfb301a..49e3aba0400c 100644 --- a/wizards/com/sun/star/wizards/web/data/CGContent.py +++ b/wizards/com/sun/star/wizards/web/data/CGContent.py @@ -16,7 +16,7 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.XMLHelper import XMLHelper from .CGDocument import CGDocument @@ -27,8 +27,8 @@ class CGContent(ConfigGroup): cp_Name = str() cp_Description = str() #COMMENTED - #cp_Contents = ConfigSet(CGContent) - cp_Documents = ConfigSet(CGDocument()) + #cp_Contents = WebConfigSet(CGContent) + cp_Documents = WebConfigSet(CGDocument()) def createDOM(self, parent): myElement = XMLHelper.addElement( diff --git a/wizards/com/sun/star/wizards/web/data/CGExporter.py b/wizards/com/sun/star/wizards/web/data/CGExporter.py index 74288c755182..0368d0eeab97 100644 --- a/wizards/com/sun/star/wizards/web/data/CGExporter.py +++ b/wizards/com/sun/star/wizards/web/data/CGExporter.py @@ -15,7 +15,7 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.ConfigGroup import ConfigGroup from .CGArgument import CGArgument @@ -33,7 +33,7 @@ class CGExporter(ConfigGroup): cp_Binary = bool() cp_PageType = int() targetTypeName = "" - cp_Arguments = ConfigSet(CGArgument()) + cp_Arguments = WebConfigSet(CGArgument) def supports(self, mime): return CGExporter.cp_SupportedMimeTypes == "" or \ diff --git a/wizards/com/sun/star/wizards/web/data/CGSession.py b/wizards/com/sun/star/wizards/web/data/CGSession.py index 211cea996b3d..a2c32d1d06ac 100644 --- a/wizards/com/sun/star/wizards/web/data/CGSession.py +++ b/wizards/com/sun/star/wizards/web/data/CGSession.py @@ -18,7 +18,7 @@ import uno from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet +from ..WebConfigSet import WebConfigSet from ...common.XMLHelper import XMLHelper from .CGContent import CGContent from .CGDesign import CGDesign @@ -36,7 +36,7 @@ class CGSession(ConfigGroup): cp_Content = CGContent() cp_Design = CGDesign() cp_GeneralInfo = CGGeneralInfo() - cp_Publishing = ConfigSet(CGPublish()) + cp_Publishing = WebConfigSet(CGPublish) valid = False def createDOM(self, parent): @@ -62,7 +62,7 @@ class CGSession(ConfigGroup): return self.root.cp_Layouts.getElement(self.cp_Design.cp_Layout) def getStyle(self): - return self.root.cp_Styles.getElementAt(self.cp_Design.cp_Style) + return self.root.cp_Styles.getElement(self.cp_Design.cp_Style) def createDOM1(self): doc = Document() diff --git a/wizards/com/sun/star/wizards/web/data/CGSettings.py b/wizards/com/sun/star/wizards/web/data/CGSettings.py index ecada3f14b82..5a8a85f6f4fe 100644 --- a/wizards/com/sun/star/wizards/web/data/CGSettings.py +++ b/wizards/com/sun/star/wizards/web/data/CGSettings.py @@ -21,9 +21,9 @@ from datetime import date as dateTimeObject from ...common.FileAccess import FileAccess from ...common.ConfigGroup import ConfigGroup -from ...common.ConfigSet import ConfigSet from ...common.NumberFormatter import NumberFormatter from ...common.Properties import Properties +from ..WebConfigSet import WebConfigSet from .CGExporter import CGExporter from .CGLayout import CGLayout from .CGStyle import CGStyle @@ -45,14 +45,14 @@ class CGSettings(ConfigGroup): RESOURCE_SIZE_TEMPLATE = 4 cp_WorkDir = str() - cp_Exporters = ConfigSet(CGExporter()) - cp_Layouts = ConfigSet(CGLayout()) - cp_Styles = ConfigSet(CGStyle()) - cp_IconSets = ConfigSet(CGIconSet()) - cp_BackgroundImages = ConfigSet(CGImage()) - cp_SavedSessions = ConfigSet(CGSessionName()) - cp_Filters = ConfigSet(CGFilter()) - savedSessions = ConfigSet(CGSessionName()) + cp_Exporters = WebConfigSet(CGExporter) + cp_Layouts = WebConfigSet(CGLayout) + cp_Styles = WebConfigSet(CGStyle) + cp_IconSets = WebConfigSet(CGIconSet) + cp_BackgroundImages = WebConfigSet(CGImage) + cp_SavedSessions = WebConfigSet(CGSessionName) + cp_Filters = WebConfigSet(CGFilter) + savedSessions = WebConfigSet(CGSessionName) cp_DefaultSession = CGSession() cp_LastSavedSession = str() fileAccess = None -- cgit