[PATCH] Ugly Hack: using our own WebConfigSet while the Topic stuff ...

Javier Fernandez (via Code Review) gerrit at gerrit.libreoffice.org
Mon Mar 25 03:47:45 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3028

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/28/3028/1

Ugly Hack: using our own WebConfigSet while the Topic stuff is not integrated.

Change-Id: I0df92af6b01e5eab99212bb1587f7165c70fd59b
---
M wizards/Pyuno_web.mk
A wizards/com/sun/star/wizards/web/WebConfigSet.py
M wizards/com/sun/star/wizards/web/data/CGContent.py
M wizards/com/sun/star/wizards/web/data/CGExporter.py
M wizards/com/sun/star/wizards/web/data/CGSession.py
M wizards/com/sun/star/wizards/web/data/CGSettings.py
6 files changed, 227 insertions(+), 17 deletions(-)



diff --git a/wizards/Pyuno_web.mk b/wizards/Pyuno_web.mk
index 5a6ae77..93b312f 100644
--- a/wizards/Pyuno_web.mk
+++ b/wizards/Pyuno_web.mk
@@ -54,6 +54,7 @@
 	WebWizardDialogResources.py \
 	TypeDetection.py \
 	ExtensionVerifier.py\
+	WebConfigSet.py\
 	__init__.py \
 	data/CGArgument.py \
 	data/CGContent.py \
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 0000000..88b49f2
--- /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 c85d7df..49e3aba 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 @@
     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 74288c7..0368d0e 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 @@
     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 211cea9..a2c32d1 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 @@
     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 @@
         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 ecada3f..5a8a85f 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 ...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 @@
     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

-- 
To view, visit https://gerrit.libreoffice.org/3028
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0df92af6b01e5eab99212bb1587f7165c70fd59b
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Javier Fernandez <javier.fgb at gmail.com>



More information about the LibreOffice mailing list