AgendaWizardDialogImpl.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. import traceback
  19. import os.path
  20. from .AgendaWizardDialog import AgendaWizardDialog, uno
  21. from .AgendaWizardDialogConst import HID
  22. from .AgendaDocument import AgendaDocument, TextElement
  23. from .TemplateConsts import TemplateConsts
  24. from .TopicsControl import TopicsControl
  25. from .CGAgenda import CGAgenda
  26. from ..ui.PathSelection import PathSelection
  27. from ..ui.event.UnoDataAware import UnoDataAware
  28. from ..ui.event.RadioDataAware import RadioDataAware
  29. from ..ui.event.CommonListener import TerminateListenerProcAdapter
  30. from ..common.NoValidPathException import NoValidPathException
  31. from ..common.SystemDialog import SystemDialog
  32. from ..common.Desktop import Desktop
  33. from ..common.HelpIds import HelpIds
  34. from ..common.Configuration import Configuration
  35. from ..common.FileAccess import FileAccess
  36. from ..document.OfficeDocument import OfficeDocument
  37. from com.sun.star.util import CloseVetoException
  38. from com.sun.star.view.DocumentZoomType import OPTIMAL
  39. from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO
  40. class AgendaWizardDialogImpl(AgendaWizardDialog):
  41. def __init__(self, xmsf):
  42. super(AgendaWizardDialogImpl, self).__init__(xmsf)
  43. self.filenameChanged = False
  44. self.pageDesign = -1
  45. def enterStep(self, OldStep, NewStep):
  46. pass
  47. def leaveStep(self, OldStep, NewStep):
  48. pass
  49. def startWizard(self, xMSF):
  50. self.running = True
  51. try:
  52. #Number of steps on WizardDialog
  53. self.nMaxStep = 6
  54. self.agenda = CGAgenda()
  55. # read configuration data before we initialize the topics
  56. root = Configuration.getConfigurationRoot(
  57. self.xMSF, "/org.openoffice.Office.Writer/Wizards/Agenda",
  58. False)
  59. self.agenda.readConfiguration(root, "cp_")
  60. self.templateConsts = TemplateConsts
  61. self.initializePaths()
  62. # initialize the agenda template
  63. self.terminateListener = TerminateListenerProcAdapter(self.queryTermination)
  64. self.myAgendaDoc = AgendaDocument(
  65. self.xMSF, self.agenda, self.resources,
  66. self.templateConsts, self.terminateListener)
  67. self.initializeTemplates()
  68. self.myAgendaDoc.load(
  69. self.agendaTemplates[1][self.agenda.cp_AgendaType])
  70. self.drawConstants()
  71. # build the dialog.
  72. self.drawNaviBar()
  73. self.buildStep1()
  74. self.buildStep2()
  75. self.buildStep3()
  76. self.buildStep4()
  77. self.buildStep5()
  78. self.buildStep6()
  79. self.topicsControl = TopicsControl(self, self.xMSF, self.agenda)
  80. #special Control for setting the save Path:
  81. self.insertPathSelectionControl()
  82. # synchronize GUI and CGAgenda object.
  83. self.initConfiguration()
  84. if self.myPathSelection.xSaveTextBox.Text.lower() == "":
  85. self.myPathSelection.initializePath()
  86. # create the peer
  87. xContainerWindow = self.myAgendaDoc.xFrame.ContainerWindow
  88. self.createWindowPeer(xContainerWindow)
  89. # initialize roadmap
  90. self.insertRoadmap()
  91. self.executeDialogFromComponent(self.myAgendaDoc.xFrame)
  92. self.removeTerminateListener()
  93. self.closeDocument()
  94. self.running = False
  95. except Exception:
  96. self.removeTerminateListener()
  97. traceback.print_exc()
  98. self.running = False
  99. return
  100. def insertPathSelectionControl(self):
  101. self.myPathSelection = PathSelection(
  102. self.xMSF, self, PathSelection.TransferMode.SAVE,
  103. PathSelection.DialogTypes.FILE)
  104. self.myPathSelection.insert(6, 97, 70, 205, 45,
  105. self.resources.reslblTemplatePath_value, True,
  106. HelpIds.getHelpIdString(HID + 24),
  107. HelpIds.getHelpIdString(HID + 25))
  108. self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
  109. self.myPathSelection.sDefaultName = "myAgendaTemplate.ott"
  110. self.myPathSelection.sDefaultFilter = "writer8_template"
  111. self.myPathSelection.addSelectionListener(self)
  112. '''
  113. bind controls to the agenda member (DataAware model)
  114. '''
  115. def initConfiguration(self):
  116. self.xDialogModel.listPageDesign.StringItemList = \
  117. tuple(self.agendaTemplates[0])
  118. UnoDataAware.attachListBox(
  119. self.agenda, "cp_AgendaType", self.listPageDesign, True).updateUI()
  120. self.pageDesign = self.agenda.cp_AgendaType
  121. UnoDataAware.attachCheckBox(
  122. self.agenda, "cp_IncludeMinutes", self.chkMinutes, True).updateUI()
  123. UnoDataAware.attachEditControl(
  124. self.agenda, "cp_Title", self.txtTitle, True).updateUI()
  125. UnoDataAware.attachDateControl(
  126. self.agenda, "cp_Date", self.txtDate, True).updateUI()
  127. UnoDataAware.attachTimeControl(
  128. self.agenda, "cp_Time", self.txtTime, True).updateUI()
  129. UnoDataAware.attachEditControl(
  130. self.agenda, "cp_Location", self.cbLocation, True).updateUI()
  131. UnoDataAware.attachCheckBox(
  132. self.agenda, "cp_ShowMeetingType", self.chkMeetingTitle,
  133. True).updateUI()
  134. UnoDataAware.attachCheckBox(
  135. self.agenda, "cp_ShowRead", self.chkRead, True).updateUI()
  136. UnoDataAware.attachCheckBox(
  137. self.agenda, "cp_ShowBring", self.chkBring, True).updateUI()
  138. UnoDataAware.attachCheckBox(
  139. self.agenda, "cp_ShowNotes", self.chkNotes, True).updateUI()
  140. UnoDataAware.attachCheckBox(
  141. self.agenda, "cp_ShowCalledBy", self.chkConvenedBy,
  142. True).updateUI()
  143. UnoDataAware.attachCheckBox(
  144. self.agenda, "cp_ShowFacilitator", self.chkPresiding,
  145. True).updateUI()
  146. UnoDataAware.attachCheckBox(
  147. self.agenda, "cp_ShowNotetaker", self.chkNoteTaker,
  148. True).updateUI()
  149. UnoDataAware.attachCheckBox(
  150. self.agenda, "cp_ShowTimekeeper", self.chkTimekeeper,
  151. True).updateUI()
  152. UnoDataAware.attachCheckBox(
  153. self.agenda, "cp_ShowAttendees", self.chkAttendees,
  154. True).updateUI()
  155. UnoDataAware.attachCheckBox(
  156. self.agenda, "cp_ShowObservers", self.chkObservers,
  157. True).updateUI()
  158. UnoDataAware.attachCheckBox(
  159. self.agenda, "cp_ShowResourcePersons",self.chkResourcePersons,
  160. True).updateUI()
  161. UnoDataAware.attachEditControl(
  162. self.agenda, "cp_TemplateName", self.txtTemplateName,
  163. True).updateUI()
  164. RadioDataAware.attachRadioButtons(
  165. self.agenda, "cp_ProceedMethod",
  166. (self.optCreateAgenda, self.optMakeChanges), True).updateUI()
  167. def insertRoadmap(self):
  168. self.addRoadmap()
  169. self.insertRoadMapItems(
  170. self.resources.RoadmapLabels, [True, True, True, True, True, True])
  171. self.setRoadmapInteractive(True)
  172. self.setRoadmapComplete(True)
  173. self.setCurrentRoadmapItemID(1)
  174. '''
  175. read the available agenda wizard templates.
  176. '''
  177. def initializeTemplates(self):
  178. try:
  179. sAgendaPath = self.sTemplatePath + "/wizard/agenda"
  180. self.agendaTemplates = FileAccess.getFolderTitles(
  181. self.xMSF, "aw", sAgendaPath, self.resources.dictPageDesign)
  182. return True
  183. except NoValidPathException:
  184. traceback.print_exc()
  185. return False
  186. '''
  187. first page, page design listbox changed.
  188. '''
  189. def pageDesignChanged(self):
  190. try:
  191. SelectedItemPos = self.listPageDesign.SelectedItemPos
  192. #avoid to load the same item again
  193. if self.pageDesign is not SelectedItemPos:
  194. self.pageDesign = SelectedItemPos
  195. self.myAgendaDoc.load(
  196. self.agendaTemplates[1][SelectedItemPos])
  197. self.drawConstants()
  198. except Exception:
  199. traceback.print_exc()
  200. #textFields listeners
  201. def txtTitleTextChanged(self):
  202. self.myAgendaDoc.redrawTitle("txtTitle")
  203. def txtDateTextChanged(self):
  204. self.myAgendaDoc.redrawTitle("txtDate")
  205. def txtTimeTextChanged(self):
  206. self.myAgendaDoc.redrawTitle("txtTime")
  207. def txtLocationTextChanged(self):
  208. self.myAgendaDoc.redrawTitle("cbLocation")
  209. #checkbox listeners
  210. def chkUseMeetingTypeItemChanged(self):
  211. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_MEETING_TYPE)
  212. def chkUseReadItemChanged(self):
  213. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_READ)
  214. def chkUseBringItemChanged(self):
  215. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_BRING)
  216. def chkUseNotesItemChanged(self):
  217. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_NOTES)
  218. def chkUseCalledByItemChanged(self):
  219. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_CALLED_BY)
  220. def chkUseFacilitatorItemChanged(self):
  221. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_FACILITATOR)
  222. def chkUseNoteTakerItemChanged(self):
  223. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_NOTETAKER)
  224. def chkUseTimeKeeperItemChanged(self):
  225. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_TIMEKEEPER)
  226. def chkUseAttendeesItemChanged(self):
  227. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_PARTICIPANTS)
  228. def chkUseObserversItemChanged(self):
  229. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_OBSERVERS)
  230. def chkUseResourcePersonsItemChanged(self):
  231. self.myAgendaDoc.redraw(self.templateConsts.FILLIN_RESOURCE_PERSONS)
  232. def insertRow(self):
  233. self.topicsControl.insertRow()
  234. def removeRow(self):
  235. self.topicsControl.removeRow()
  236. def rowUp(self):
  237. self.topicsControl.rowUp()
  238. def rowDown(self):
  239. self.topicsControl.rowDown()
  240. def cancelWizard(self):
  241. self.xUnoDialog.endExecute()
  242. self.running = False
  243. def finishWizard(self):
  244. self.switchToStep(self.getCurrentStep(), self.nMaxStep)
  245. bSaveSuccess = False
  246. endWizard = True
  247. try:
  248. self.sPath = self.myPathSelection.getSelectedPath()
  249. if not self.sPath or not os.path.exists(self.sPath):
  250. self.myPathSelection.triggerPathPicker()
  251. self.sPath = self.myPathSelection.getSelectedPath()
  252. #first, if the filename was not changed, thus
  253. #it is coming from a saved session, check if the
  254. # file exists and warn the user.
  255. if not self.filenameChanged:
  256. answer = SystemDialog.showMessageBox(
  257. self.xMSF, "MessBox", YES_NO + DEF_NO,
  258. self.resources.resOverwriteWarning,
  259. self.xUnoDialog.Peer)
  260. if answer == 3:
  261. # user said: no, do not overwrite
  262. endWizard = False
  263. return False
  264. xDocProps = self.myAgendaDoc.xTextDocument.DocumentProperties
  265. xDocProps.Title = self.txtTemplateName.Text
  266. self.myAgendaDoc.setWizardTemplateDocInfo( \
  267. self.resources.resAgendaWizardDialog_title,
  268. self.resources.resTemplateDescription)
  269. bSaveSuccess = OfficeDocument.store(
  270. self.xMSF, self.myAgendaDoc.xTextDocument, self.sPath,
  271. "writer8_template")
  272. if bSaveSuccess:
  273. self.topicsControl.saveTopics(self.agenda)
  274. root = Configuration.getConfigurationRoot(
  275. self.xMSF, "/org.openoffice.Office.Writer/Wizards/Agenda",
  276. True)
  277. self.agenda.writeConfiguration(root, "cp_")
  278. root.commitChanges()
  279. self.myAgendaDoc.finish(self.topicsControl.scrollfields)
  280. loadValues = list(range(2))
  281. loadValues[0] = uno.createUnoStruct( \
  282. 'com.sun.star.beans.PropertyValue')
  283. loadValues[0].Name = "AsTemplate"
  284. if self.agenda.cp_ProceedMethod == 1:
  285. loadValues[0].Value = True
  286. else:
  287. loadValues[0].Value = False
  288. loadValues[1] = uno.createUnoStruct( \
  289. 'com.sun.star.beans.PropertyValue')
  290. loadValues[1].Name = "InteractionHandler"
  291. xIH = self.xMSF.createInstance(
  292. "com.sun.star.comp.uui.UUIInteractionHandler")
  293. loadValues[1].Value = xIH
  294. oDoc = OfficeDocument.load(
  295. Desktop.getDesktop(self.xMSF),
  296. self.sPath, "_default", loadValues)
  297. oDoc.CurrentController.ViewSettings.ZoomType = OPTIMAL
  298. else:
  299. pass
  300. except Exception:
  301. traceback.print_exc()
  302. finally:
  303. if endWizard:
  304. self.xUnoDialog.endExecute()
  305. self.running = False
  306. return True
  307. def closeDocument(self):
  308. try:
  309. self.myAgendaDoc.xFrame.close(False)
  310. except CloseVetoException:
  311. traceback.print_exc()
  312. def drawConstants(self):
  313. '''Localise the template'''
  314. constRangeList = self.myAgendaDoc.searchFillInItems(1)
  315. for i in constRangeList:
  316. text = i.String.lower()
  317. aux = TextElement(i, self.resources.dictConstants[text])
  318. aux.write()
  319. def validatePath(self):
  320. if self.myPathSelection.usedPathPicker:
  321. self.filenameChanged = True
  322. self.myPathSelection.usedPathPicker = False