summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py
blob: c27a0249b0f2bce48eb2d155ad0ab7a2b8a4a352 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#
# 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 AgendaWizardDialog import *
from AgendaWizardDialog import *
from AgendaTemplate import *
from CGAgenda import CGAgenda
from wizards.ui.PathSelection import PathSelection
from wizards.ui.event.UnoDataAware import UnoDataAware
from wizards.ui.event.RadioDataAware import RadioDataAware
from wizards.common.NoValidPathException import NoValidPathException
from wizards.common.SystemDialog import SystemDialog

from com.sun.star.view.DocumentZoomType import OPTIMAL
from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO
from com.sun.star.awt.VclWindowPeerAttribute import OK

class AgendaWizardDialogImpl(AgendaWizardDialog):

    fileAccess1 = None
    pageDesign = None

    def __init__(self, xmsf):
        super(AgendaWizardDialogImpl, self).__init__(xmsf)
        self.filenameChanged = False

    def enterStep(self, OldStep, NewStep):
        pass

    def leaveStep(self, OldStep, NewStep):
        pass

    '''
    used in developement to start the wizard
    '''

    @classmethod
    def main(self, args):
        ConnectStr = \
            "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
        try:
            xLocMSF = Desktop.connect(ConnectStr)
            wizard = AgendaWizardDialogImpl(xLocMSF)
            wizard.startWizard()
        except Exception, exception:
            traceback.print_exc()

    '''
    read the configuration data, open the specified template,
    initialize the template controller (AgendaTemplate) and
    set the status of the displayed template to the one
    read from the configuration.
    build the dialog.
    Synchronize the dialog to the same status (read from
    the configuration).
    show the dialog.
    '''

    def startWizard(self):
        self.running = True
        try:
            #Number of steps on WizardDialog
            self.nMaxStep = 6

            # initialize the agenda template
            self.agenda = CGAgenda()
            self.agendaTemplate = AgendaTemplate(
                self.xMSF, self.agenda, self.resources, self)

            # build the dialog.
            self.drawNaviBar()

            self.buildStep1()
            self.buildStep2()
            self.buildStep3()
            self.buildStep4()
            self.buildStep5()
            self.buildStep6()

            self.topicsControl = TopicsControl(self, self.xMSF, self.agenda)

            self.initializePaths()
            #special Control for setting the save Path:
            self.insertPathSelectionControl()

            self.initializeTemplates()

            # synchronize GUI and CGAgenda object.
            self.initConfiguration()

            if self.myPathSelection.xSaveTextBox.Text.lower() == "":
                self.myPathSelection.initializePath()

            # create the peer
            xContainerWindow = self.agendaTemplate.xFrame.ContainerWindow
            self.createWindowPeer(xContainerWindow)

            # initialize roadmap
            self.insertRoadmap()

            self.pageDesignChanged()

            self.executeDialogFromComponent(self.agendaTemplate.xFrame)
            self.removeTerminateListener()
            self.closeDocument()
            self.running = False
        except Exception, ex:
            self.removeTerminateListener()
            traceback.print_exc()
            self.running = False
            return

    def insertPathSelectionControl(self):
        self.myPathSelection = PathSelection(
            self.xMSF, self, PathSelection.TransferMode.SAVE,
            PathSelection.DialogTypes.FILE)
        self.myPathSelection.insert(6, 97, 70, 205, 45,
            self.resources.reslblTemplatePath_value, True,
            HelpIds.getHelpIdString(HID + 24),
            HelpIds.getHelpIdString(HID + 25))
        self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
        self.myPathSelection.sDefaultName = "myAgendaTemplate.ott"
        self.myPathSelection.sDefaultFilter = "writer8_template"
        self.myPathSelection.addSelectionListener(
            self.myPathSelectionListener())

    def initializePaths(self):
        try:
            self.sTemplatePath = FileAccess.getOfficePath2(
                self.xMSF, "Template", "share", "/wizard")
            self.sUserTemplatePath = FileAccess.getOfficePath2(
                self.xMSF, "Template", "user", "")
            self.sBitmapPath = FileAccess.combinePaths(
                self.xMSF, self.sTemplatePath, "/../wizard/bitmap")
        except NoValidPathException:
            traceback.print_exc()

    def checkSavePath(self):
        if self.agenda.cp_TemplatePath is None \
            or self.agenda.cp_TemplatePath == "" \
            or not self.getFileAccess().exists(
                FileAccess.getParentDir(self.agenda.cp_TemplatePath), False) \
            or not self.getFileAccess().isDirectory(
                FileAccess.getParentDir(self.agenda.cp_TemplatePath)):
            try:
                self.agenda.cp_TemplatePath = FileAccess.connectURLs(
                    FileAccess.getOfficePath2(self.xMSF, "Work", "", ""),
                    self.resources.resDefaultFilename)
            except Exception, ex:
                traceback.print_exc()

    '''
    bind controls to the agenda member (DataAware model)
    '''

    def initConfiguration(self):
        # read configuration data.
        root = Configuration.getConfigurationRoot(
            self.xMSF, "/org.openoffice.Office.Writer/Wizards/Agenda", False)
        self.agenda.readConfiguration(root, "cp_")

        self.setControlProperty(
            "listPageDesign", "StringItemList", tuple(self.agendaTemplates[0]))
        self.checkSavePath()
        UnoDataAware.attachListBox(
            self.agenda, "cp_AgendaType", self.listPageDesign, True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_IncludeMinutes", self.chkMinutes, True).updateUI()
        UnoDataAware.attachEditControl(
            self.agenda, "cp_Title", self.txtTitle, True).updateUI()
        UnoDataAware.attachDateControl(
            self.agenda, "cp_Date", self.txtDate, True).updateUI()
        UnoDataAware.attachTimeControl(
            self.agenda, "cp_Time", self.txtTime, True).updateUI()
        UnoDataAware.attachEditControl(
            self.agenda, "cp_Location", self.cbLocation, True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowMeetingType", self.chkMeetingTitle,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowRead", self.chkRead, True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowBring", self.chkBring, True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowNotes", self.chkNotes, True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowCalledBy", self.chkConvenedBy,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowFacilitator", self.chkPresiding,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowNotetaker", self.chkNoteTaker,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowTimekeeper", self.chkTimekeeper,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowAttendees", self.chkAttendees,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowObservers", self.chkObservers,
            True).updateUI()
        UnoDataAware.attachCheckBox(
            self.agenda, "cp_ShowResourcePersons",self.chkResourcePersons,
            True).updateUI()
        UnoDataAware.attachEditControl(
            self.agenda, "cp_TemplateName", self.txtTemplateName,
            True).updateUI()
        RadioDataAware.attachRadioButtons(
            self.agenda, "cp_ProceedMethod",
                (self.optCreateAgenda, self.optMakeChanges), True).updateUI()

    def saveConfiguration(self):
        root = Configuration.getConfigurationRoot(
            self.xMSF, "/org.openoffice.Office.Writer/Wizards/Agenda", True)
        self.agenda.writeConfiguration(root, "cp_")
        root.commitChanges()

    def insertRoadmap(self):
        self.addRoadmap()

        self.insertRoadMapItems(
            [True, True, True, True, True, True],
            [self.resources.resStep1, self.resources.resStep2,
                self.resources.resStep3, self.resources.resStep4,
                self.resources.resStep5, self.resources.resStep6])

        self.setRoadmapInteractive(True)
        self.setRoadmapComplete(True)
        self.setCurrentRoadmapItemID(1)

    '''
    read the available agenda wizard templates.
    '''

    def initializeTemplates(self):
        try:
            self.sTemplatePath = FileAccess.getOfficePath2(
                self.xMSF, "Template", "share", "/wizard")
            sAgendaPath = FileAccess.combinePaths(
                self.xMSF, self.sTemplatePath, "/wizard/agenda")
            self.agendaTemplates = FileAccess.getFolderTitles(
                self.xMSF, "aw", sAgendaPath)
            return True
        except NoValidPathException:
            traceback.print_exc()
            return False

    '''
    first page, page design listbox changed.
    '''

    def pageDesignChanged(self):
        try:
            SelectedItemPos = self.listPageDesign.SelectedItemPos
            #avoid to load the same item again
            if AgendaWizardDialogImpl.pageDesign is not SelectedItemPos:
                AgendaWizardDialogImpl.pageDesign = SelectedItemPos
                self.agendaTemplate.load(
                    self.agendaTemplates[1][SelectedItemPos],
                    self.topicsControl.scrollfields)
        except Exception:
            traceback.print_exc()

    '''
    last page, template title changed...
    '''

    def templateTitleChanged(self):
        title = Helper.getUnoPropertyValue(getModel(txtTemplateName), "Text")
        self.agendaTemplate.setTemplateTitle(title)

    #textFields listeners
    def txtTitleTextChanged(self):
        AgendaTemplate.redrawTitle("txtTitle")

    def txtDateTextChanged(self):
        AgendaTemplate.redrawTitle("txtDate")

    def txtTimeTextChanged(self):
        AgendaTemplate.redrawTitle("txtTime")

    def txtLocationTextChanged(self):
        AgendaTemplate.redrawTitle("cbLocation")

    #checkbox listeners
    def chkUseMeetingTypeItemChanged(self):
        AgendaTemplate.agenda.cp_IncludeMinutes = bool(self.chkMinutes.State)

    def chkUseMeetingTypeItemChanged(self):
        AgendaTemplate.redraw(FILLIN_MEETING_TYPE)

    def chkUseReadItemChanged(self):
        AgendaTemplate.redraw(FILLIN_READ)

    def chkUseBringItemChanged(self):
        AgendaTemplate.redraw(FILLIN_BRING)

    def chkUseNotesItemChanged(self):
        AgendaTemplate.redraw(FILLIN_NOTES)

    def chkUseCalledByItemChanged(self):
        AgendaTemplate.redraw(FILLIN_CALLED_BY)

    def chkUseFacilitatorItemChanged(self):
        AgendaTemplate.redraw(FILLIN_FACILITATOR)

    def chkUseNoteTakerItemChanged(self):
        AgendaTemplate.redraw(FILLIN_NOTETAKER)

    def chkUseTimeKeeperItemChanged(self):
        AgendaTemplate.redraw(FILLIN_TIMEKEEPER)

    def chkUseAttendeesItemChanged(self):
        AgendaTemplate.redraw(FILLIN_PARTICIPANTS)

    def chkUseObserversItemChanged(self):
        AgendaTemplate.redraw(FILLIN_OBSERVERS)

    def chkUseResourcePersonsItemChanged(self):
        AgendaTemplate.redraw(FILLIN_RESOURCE_PERSONS)

    '''
    convenience method.
    instead of creating a FileAccess object every time
    it is needed, I have a FileAccess object memeber.
    the first time it is needed it will be created, and
    then be reused...
    @return the FileAccess memeber object.
    '''

    def getFileAccess(self):
        if AgendaWizardDialogImpl.fileAccess1 is None:
            try:
                AgendaWizardDialogImpl.fileAccess1 = FileAccess(self.xMSF)
            except Exception, e:
                traceback.print_exc()
        return AgendaWizardDialogImpl.fileAccess1

    '''
    last page, "browse" ("...") button was clicked...
    '''

    def saveAs(self):
        try:
            checkSavePath()
            saveAs = SystemDialog.createStoreDialog(xMSF)
            saveAs.addFilterToDialog("ott", "writer8_template", True)
            # call the saveAs dialog.
            url = saveAs.callStoreDialog(
                FileAccess.getParentDir(self.agenda.cp_TemplatePath),
                FileAccess.getFilename(self.agenda.cp_TemplatePath))
            if url != None:
                self.agenda.cp_TemplatePath = url
                setFilename(url)
                self.filenameChanged = True

        except Exception, ex:
            traceback.print_exc()

    '''
    is called when the user
    changes the path through the "save as" dialog.
    The path displayed is a translated, user-friendly, platform dependant path.
    @param url the new save url.
    '''

    def setFilename(self, url):
        try:
            path = getFileAccess().getPath(url, "")
            Helper.setUnoPropertyValue(
                getModel(self.myPathSelection.xSaveTextBox), "Text", path)
        except Exception, ex:
            traceback.print_exc()

    def insertRow(self):
        self.topicsControl.insertRow()

    def removeRow(self):
        self.topicsControl.removeRow()

    def rowUp(self):
        self.topicsControl.rowUp()

    def rowDown(self):
        self.topicsControl.rowDown()

    def cancelWizard(self):
        self.xUnoDialog.endExecute()
        self.running = False

    def finishWizard(self):
        self.switchToStep(self.getCurrentStep(), self.nMaxStep)
        bSaveSuccess = False
        endWizard = True
        try:
            fileAccess = FileAccess(self.xMSF)
            self.sPath = self.myPathSelection.getSelectedPath()
            if self.sPath == "":
                self.myPathSelection.triggerPathPicker()
                self.sPath = self.myPathSelection.getSelectedPath()

            self.sPath = fileAccess.getURL(self.sPath)
            #first, if the filename was not changed, thus
            #it is coming from a saved session, check if the
            # file exists and warn the user.
            if not self.filenameChanged:
                if fileAccess.exists(self.sPath, True):
                    answer = SystemDialog.showMessageBox(
                        self.xMSF, "MessBox", YES_NO + DEF_NO,
                        self.resources.resFileExists,
                        self.xUnoDialog.Peer)
                    if answer == 3:
                        # user said: no, do not overwrite
                        endWizard = False
                        return False

            xTextDocument = self.agendaTemplate.document
            bSaveSuccess = OfficeDocument.store(
                self.xMSF, AgendaTemplate.xTextDocument, self.sPath,
                "writer8_template")

            if bSaveSuccess:
                self.saveConfiguration()

                self.agendaTemplate.finish(self.topicsControl.scrollfields)

                loadValues = range(2)
                loadValues[0] = uno.createUnoStruct( \
                    'com.sun.star.beans.PropertyValue')
                loadValues[0].Name = "AsTemplate"
                if self.agenda.cp_ProceedMethod == 1:
                    loadValues[0].Value = True
                else:
                    loadValues[0].Value = False

                loadValues[1] = uno.createUnoStruct( \
                    'com.sun.star.beans.PropertyValue')
                loadValues[1].Name = "InteractionHandler"

                xIH = self.xMSF.createInstance(
                    "com.sun.star.comp.uui.UUIInteractionHandler")
                loadValues[1].Value = xIH

                oDoc = OfficeDocument.load(
                    Desktop.getDesktop(self.xMSF),
                    self.sPath, "_default", loadValues)
                myViewHandler = ViewHandler(self.xMSF, oDoc)
                myViewHandler.setViewSetting("ZoomType", OPTIMAL)
            else:
                pass

        except Exception, e:
            traceback.print_exc()
        finally:
            if endWizard:
                self.xUnoDialog.endExecute()
                self.running = False
        return True

    def closeDocument(self):
        try:
            xCloseable = self.agendaTemplate.xFrame
            xCloseable.close(False)
        except CloseVetoException, e:
            traceback.print_exc()