[Libreoffice-commits] core.git: wizards/com

Xisco Fauli anistenis at gmail.com
Mon Feb 11 13:03:46 PST 2013


 wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py |   18 -
 wizards/com/sun/star/wizards/common/FileAccess.py             |  120 ----------
 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py       |   19 -
 wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py |   16 -
 wizards/com/sun/star/wizards/text/TextDocument.py             |    2 
 wizards/com/sun/star/wizards/ui/WizardDialog.py               |   11 
 6 files changed, 19 insertions(+), 167 deletions(-)

New commits:
commit 57041602e2e0c5d1035359108ff1237a324c39d6
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Mon Feb 11 22:01:25 2013 +0100

    pywizards: simplify paths handling
    
    Change-Id: I436ca81e180d595e018811823e8b77c8b675bef5

diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py
index 2c3e288..72f3b75 100644
--- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py
@@ -81,7 +81,8 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
             self.agenda.readConfiguration(root, "cp_")
 
             self.templateConsts = TemplateConsts
-                        
+
+            self.initializePaths()
             # initialize the agenda template
             self.agendaTemplate = AgendaDocument(
                 self.xMSF, self.agenda, self.resources,
@@ -103,7 +104,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
 
             self.topicsControl = TopicsControl(self, self.xMSF, self.agenda)
 
-            self.initializePaths()
             #special Control for setting the save Path:
             self.insertPathSelectionControl()
 
@@ -143,15 +143,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
         self.myPathSelection.sDefaultFilter = "writer8_template"
         self.myPathSelection.addSelectionListener(self)
 
-    def initializePaths(self):
-        try:
-            self.sTemplatePath = FileAccess.getOfficePath2(
-                self.xMSF, "Template", "share", "/wizard")
-            self.sUserTemplatePath = FileAccess.getOfficePath2(
-                self.xMSF, "Template", "user", "")
-        except NoValidPathException:
-            traceback.print_exc()
-
     '''
     bind controls to the agenda member (DataAware model)
     '''
@@ -227,10 +218,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
 
     def initializeTemplates(self):
         try:
-            self.sTemplatePath = FileAccess.getOfficePath2(
-                self.xMSF, "Template", "share", "/wizard")
-            sAgendaPath = FileAccess.combinePaths(
-                self.xMSF, self.sTemplatePath, "/wizard/agenda")
+            sAgendaPath = self.sTemplatePath + "/wizard/agenda"
             self.agendaTemplates = FileAccess.getFolderTitles(
                 self.xMSF, "aw", sAgendaPath)
             return True
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index fd7a97c..409c15c 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -16,10 +16,6 @@
 #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 #
 import traceback
-from .NoValidPathException import NoValidPathException
-
-from com.sun.star.ucb import CommandAbortedException
-from com.sun.star.awt.VclWindowPeerAttribute import OK, YES_NO
 
 '''
 This class delivers static convenience methods
@@ -41,109 +37,6 @@ class FileAccess(object):
             "com.sun.star.ucb.FileContentProvider")
             
     @classmethod
-    def deleteLastSlashfromUrl(self, _sPath):
-        if _sPath.endswith("/"):
-            return _sPath[:-1]
-        else:
-            return _sPath
-
-    '''
-    Further information on arguments value see in OO Developer Guide,
-    chapter 6.2.7
-    @param xMSF
-    @param sPath
-    @param xSimpleFileAccess
-    @return the respective path of the office application.
-    A probable following "/" at the end is trimmed.
-    '''
-
-    @classmethod
-    def getOfficePath(self, xMSF, sPath, xSimpleFileAccess):
-        try:
-            ResultPath = ""
-            xInterface = xMSF.createInstance("com.sun.star.util.PathSettings")
-            ResultPath = str(Helper.getUnoPropertyValue(xInterface, sPath))
-            ResultPath = self.deleteLastSlashfromUrl(ResultPath)
-            return ResultPath
-        except Exception:
-            traceback.print_exc()
-            return ""
-
-    '''
-    Further information on arguments value see in OO Developer Guide,
-    chapter 6.2.7
-    @param xMSF
-    @param sPath
-    @param sType use "share" or "user". Set to ""
-    f not needed eg for the WorkPath;
-    In the return Officepath a possible slash at the end is cut off
-    @param sSearchDir
-    @return
-    @throws NoValidPathException
-    '''
-
-    @classmethod
-    def getOfficePath2(self, xMSF, sPath, sType, sSearchDir):
-        #This method currently only works with sPath="Template"
-        bexists = False
-        try:
-            xPathInterface = xMSF.createInstance(
-                "com.sun.star.util.PathSettings")
-            ResultPath = ""
-            ReadPaths = ()
-            xUcbInterface = xMSF.createInstance(
-                "com.sun.star.ucb.SimpleFileAccess")
-            Template_writable = xPathInterface.getPropertyValue(
-                sPath + "_writable")
-            Template_internal = xPathInterface.getPropertyValue(
-                sPath + "_internal")
-            Template_user = xPathInterface.getPropertyValue(
-                sPath + "_user")
-            if not hasattr(Template_internal, '__dict__'):
-                ReadPaths = ReadPaths + Template_internal
-            if not hasattr(Template_user, '__dict__'):
-                ReadPaths = ReadPaths + Template_user
-            ReadPaths = ReadPaths + (Template_writable,)
-            if sType.lower() == "user":
-                ResultPath = Template_writable
-                bexists = True
-            else:
-                #find right path using the search sub path
-                for i in ReadPaths:
-                    tmpPath = i + sSearchDir
-                    if xUcbInterface.exists(tmpPath):
-                        ResultPath = i
-                        bexists = True
-                        break
-
-            ResultPath = self.deleteLastSlashfromUrl(ResultPath)
-        except Exception:
-            traceback.print_exc()
-            ResultPath = ""
-
-        if not bexists:
-            raise NoValidPathException (xMSF, "");
-        return ResultPath
-
-    @classmethod
-    def combinePaths(self, xMSF, _sFirstPath, _sSecondPath):
-        bexists = False
-        ReturnPath = ""
-        try:
-            xUcbInterface = xMSF.createInstance(
-                "com.sun.star.ucb.SimpleFileAccess")
-            ReturnPath = _sFirstPath + _sSecondPath
-            bexists = xUcbInterface.exists(ReturnPath)
-        except Exception:
-            traceback.print_exc()
-            return ""
-
-        if not bexists:
-            raise NoValidPathException (xMSF, "");
-
-        return ReturnPath
-
-    @classmethod
     def getFolderTitles(self, xMSF, FilterName, FolderName, resDict=None):
         #Returns and ordered dict containing the template's name and path
         
@@ -221,35 +114,22 @@ class FileAccess(object):
 
     '''
     return the filename out of a system-dependent path
-    @param path
-    @return
     '''
 
     @classmethod
     def getPathFilename(self, path):
         return self.getFilename(path, File.separator)
 
-    '''
-    @author rpiterman
-    @param path
-    @param pathSeparator
-    @return
-    '''
-
     @classmethod
     def getFilename(self, path, pathSeparator = "/"):
         return path.split(pathSeparator)[-1]
 
     '''
-    @param url
-    @return the parent dir of the given url.
     if the path points to file, gives the directory in which the file is.
     '''
 
     @classmethod
     def getParentDir(self, url):
-        while url[-1] == "/":
-            url = hello[:-1]
         return url[:url.rfind("/")]
 
     @classmethod
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 0c5ed84..ead90e1 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -59,8 +59,6 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.lstPrivateStylePos = None
         self.bSaveSuccess = False
         self.filenameChanged = False
-        self.UserTemplatePath = ""
-        self.sTemplatePath = ""
 
     @classmethod
     def main(self):
@@ -97,7 +95,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
             self.initializeSalutation()
             self.initializeGreeting()
             self.initializeCommunication()
-            self.__initializePaths()
+            self.initializePaths()
 
             #special Control for setting the save Path:
             self.insertPathSelectionControl()
@@ -251,25 +249,14 @@ class FaxWizardDialogImpl(FaxWizardDialog):
             5, 97, 70, 205, 45, self.resources.reslblTemplatePath_value,
             True, HelpIds.getHelpIdString(HID + 34),
             HelpIds.getHelpIdString(HID + 35))
-        self.myPathSelection.sDefaultDirectory = self.UserTemplatePath
+        self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
         self.myPathSelection.sDefaultName = "myFaxTemplate.ott"
         self.myPathSelection.sDefaultFilter = "writer8_template"
         self.myPathSelection.addSelectionListener(self)
 
-    def __initializePaths(self):
-        try:
-            self.sTemplatePath = FileAccess.getOfficePath2(self.xMSF,
-                "Template", "share", "/wizard")
-            self.UserTemplatePath = FileAccess.getOfficePath2(self.xMSF,
-                "Template", "user", "")
-        except NoValidPathException:
-            traceback.print_exc()
-
     def initializeTemplates(self, xMSF):
         try:
-            self.sFaxPath = FileAccess.combinePaths(xMSF, self.sTemplatePath,
-                "/wizard/fax")
-            self.sWorkPath = FileAccess.getOfficePath2(xMSF, "Work", "", "")
+            self.sFaxPath = self.sTemplatePath + "/wizard/fax"
             self.BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus",
                 self.sFaxPath, self.resources.dictBusinessTemplate)
             self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri",
diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
index a7ff8f6..f3b55fe 100644
--- a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py
@@ -99,7 +99,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
             self.buildStep4()
             self.buildStep5()
             self.buildStep6()
-            self.__initializePaths()
+            
+            self.initializePaths()
             self.initializeSalutation()
             self.initializeGreeting()
 
@@ -768,19 +769,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
         else:
             return None
 
-    def __initializePaths(self):
-        try:
-            self.sTemplatePath = \
-                FileAccess.getOfficePath2(
-                    self.xMSF, "Template", "share", "/wizard")
-            self.sUserTemplatePath = \
-                FileAccess.getOfficePath2(self.xMSF, "Template", "user", "")
-        except NoValidPathException:
-            traceback.print_exc()
-
     def initializeTemplates(self, xMSF):
-        sLetterPath = FileAccess.combinePaths(
-            xMSF, self.sTemplatePath, "/../common/wizard/letter")
+        sLetterPath = self.sTemplatePath + "/../common/wizard/letter"
         self.BusinessFiles = \
             FileAccess.getFolderTitles(
                 xMSF, "bus", sLetterPath, self.resources.dictBusinessTemplate)
diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py
index 5502978..aae3d59 100644
--- a/wizards/com/sun/star/wizards/text/TextDocument.py
+++ b/wizards/com/sun/star/wizards/text/TextDocument.py
@@ -148,7 +148,7 @@ class TextDocument(object):
         myFieldHandler = TextFieldHandler(self.xMSF, self.xTextDocument)
         myFieldHandler.updateDocInfoFields()
         return self.xTextDocument
-
+            
     def getPageSize(self):
         try:
             xNameAccess = self.xTextDocument.StyleFamilies
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py
index 52597a1..534122a 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.py
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py
@@ -102,6 +102,15 @@ class WizardDialog(UnoDialog2):
             traceback.print_exc()
             return -1
 
+
+    def initializePaths(self):
+        xPropertySet = \
+            self.xMSF.createInstance("com.sun.star.util.PathSettings")
+        self.sTemplatePath = \
+            xPropertySet.getPropertyValue("Template_user")[0]
+        self.sUserTemplatePath = \
+            xPropertySet.getPropertyValue("Template_writable")
+            
     def addRoadmap(self):
         try:
             iDialogHeight = self.xDialogModel.Height
@@ -353,8 +362,6 @@ class WizardDialog(UnoDialog2):
         except Exception:
             traceback.print_exc()
 
-    #TODO discuss with rp
-
     def getNextAvailableStep(self):
         if self.isRoadmapComplete():
             i = self.nNewStep + 1


More information about the Libreoffice-commits mailing list