summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/web/WWD_General.py
blob: 72a18b9915b210291d488fc59a28b54c7a3c0801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#
# 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 .
#
from WebWizardDialog import *
from WebWizardDialog import *
from common.SystemDialog import SystemDialog
from ui.event.ListModelBinder import ListModelBinder

'''
@author rpiterman
This class implements general methods, used by different sub-classes
(either WWD_Sturtup, or WWD_Events) or both.
'''

class WWD_General(WebWizardDialog):

    settings = None

    def __init__(self, xmsf):
        super(WWD_General, self).__init__(xmsf)
        self.xStringSubstitution = SystemDialog.createStringSubstitution(xmsf)

    def getStatusDialog(self):
        statusDialog = StatusDialog(
            self.xMSF, StatusDialog.STANDARD_WIDTH,
            self.resources.resLoadingSession, False,
            [self.resources.prodName, "", "", "", "", ""],
            HelpIds.getHelpIdString(HID0_STATUS_DIALOG))
        try:
            statusDialog.createWindowPeer(xControl.Peer)
        except Exception:
            traceback.print_exc()

        return statusDialog

    '''
     File Dialog methods
    '''

    def getDocAddDialog(self):
        self.docAddDialog = SystemDialog.createOpenDialog(self.xMSF)
        for i in xrange(WWD_General.settings.cp_Filters.getSize()):
            f = WWD_General.settings.cp_Filters.getElementAt(i)
            if f is not None:
                self.docAddDialog.addFilter(
                    f.cp_Name.replace("%PRODNAME", self.resources.prodName),
                    f.cp_Filter, i == 0)
        return self.docAddDialog

    def getZipDialog(self):
        if self.zipDialog is None:
            self.zipDialog = SystemDialog.createStoreDialog(xMSF)
            self.zipDialog.addFilter(self.resources.resZipFiles, "*.zip", True)

        return self.zipDialog

    def getFTPDialog(self, pub):
        if self.ftpDialog is None:
            try:
                self.ftpDialog = FTPDialog.FTPDialog_unknown(xMSF, pub)
                self.ftpDialog.createWindowPeer(xControl.getPeer())
            except Exception:
                traceback.print_exc()

        return self.ftpDialog

    def showFolderDialog(self, title, description, dir):
        if self.folderDialog is None:
            self.folderDialog = SystemDialog.createFolderDialog(xMSF)

        return self.folderDialog.callFolderDialog(title, description, dir)

    '''
    returns the document specified
    by the given short array.
    @param s
    @return
    '''

    @classmethod
    def getDoc(self, s):
        if len(s) == 0:
            return None
        elif WWD_General.settings.cp_DefaultSession.cp_Content.cp_Documents.getSize() <= s[0]:
            return None
        else:
            return \
                WWD_General.settings.cp_DefaultSession.cp_Content.cp_Documents.childrenList[s[0]]

    '''
    how many documents are in the list?
    @return the number of documents in the docs list.
    '''

    @classmethod
    def getDocsCount(self):
        return WWD_General.settings.cp_DefaultSession.cp_Content.cp_Documents.getSize()

    '''
    fills the export listbox.
    @param listContent
    '''

    def fillExportList(self, listContent):
        ListModelBinder.fillList(self.lstDocTargetType, listContent, None)

    '''
    returns a publisher object for the given name
    @param name one of the WebWizardConst constants : FTP
    @return
    '''

    def getPublisher(self, name):
        return WWD_General.settings.cp_DefaultSession.cp_Publishing.getElement(name)

    '''
    @return true if the checkbox "save session" is checked.
    '''

    def isSaveSession(self):
        return int(Helper.getUnoPropertyValue(
            chkSaveSettings.Model, PropertyNames.PROPERTY_STATE) == 1)

    '''
    @return the name to save the session (step 7)
    '''

    def getSessionSaveName(self):
        return Helper.getUnoPropertyValue(getModel(cbSaveSettings), "Text")

    '''
    This method checks the status of the wizards and
    enables or disables the 'next' and the 'create' button.
    '''

    def checkSteps(self):
        '''
        first I check the document list.
        If it is empty, then step3 and on are disabled.
        '''
        if self.checkDocList():
            self.checkPublish()

    '''
    enables/disables the steps 3 to 7)
    @param enabled true = enabled, false = disabled.
    '''

    def enableSteps(self, enabled):
        if not enabled and not self.isStepEnabled(3):
            #disbale steps 3-7
            return

        for i in xrange(3,8):
            self.setStepEnabled(i, enabled, True)
            '''
            in this place i just disable the finish button.
            later, in the checkPublish, which is only performed if
            this one is true, it will be enabled (if the check
            is positive)
            '''

        if not enabled:
            self.enableFinishButton(False)

    '''
    Checks if the documents list is
    empty. If it is, disables the steps 3-7, and the
    create button.
    @return
    '''

    def checkDocList(self):
        if WWD_General.settings.cp_DefaultSession.cp_Content.cp_Documents.getSize() \
                == 0:
            self.enableSteps(False)
            return False
        else:
            self.enableSteps(True)
            return True

    '''
    check if the save-settings input is ok.
    (eather the checkbox is unmarked, or,
    if it is marked, a session name exists.
    '''

    def checkSaveSession(self):
        return (not isSaveSession() or not getSessionSaveName() == "")

    '''
    @return false if this publisher is not active, or, if it
    active, returns true if the url is not empty...
    if the url is empty, throws an exception
    '''

    def checkPublish2(self, s, text, _property):
        p = self.getPublisher(s)
        if p.cp_Publish:
            url = Helper.getUnoPropertyValue(text.Model, _property)
            if url is None or url == "":
                raise IllegalArgumentException ()
            else:
                return True

        else:
            return False

    '''

    @return false either if publishing input is wrong or there
    are no publishing targets chosen. returns true when at least
    one target is chosen, *and* all
    which are chosen are legal.
    If proxies are on, ftp publisher is ignored.
    '''

    def checkPublish_(self):
        try:
            return \
                self.checkPublish2(LOCAL_PUBLISHER, self.txtLocalDir, "Text") \
                or (not self.proxies and self.checkPublish(
                    FTP_PUBLISHER, lblFTP, PropertyNames.PROPERTY_LABEL) \
                or self.checkPublish2(ZIP_PUBLISHER, self.txtZip, "Text")) \
                and self.checkSaveSession()
        except IllegalArgumentException, ex:
            return False

    '''
    This method checks if the publishing
    input is ok, and enables and disables
    the 'create' button.
    public because it is called from
    an event listener object.
    '''

    def checkPublish(self):
        self.enableFinishButton(self.checkPublish_())

    '''
    shows a message box "Unexpected Error... " :-)
    @param ex
    '''

    def unexpectedError(self, ex):
        ex.printStackTrace()
        peer = xControl.getPeer()
        AbstractErrorHandler.showMessage(
            self.xMSF, peer, self.resources.resErrUnexpected,
            ErrorHandler.ERROR_PROCESS_FATAL)

    '''
    substitutes path variables with the corresponding values.
    @param path a path, which might contain OOo path variables.
    @return the path, after substituing path variables.
    '''

    def substitute(self, path):
        try:
            return self.xStringSubstitution.substituteVariables(path, False)
        except Exception, ex:
            return path