android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / dbui / mailmergewizard.cxx
blob634e984f2e300e6e25ebd03c26ec40fe9c85b53d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <mailmergewizard.hxx>
21 #include "mmdocselectpage.hxx"
22 #include "mmoutputtypepage.hxx"
23 #include "mmaddressblockpage.hxx"
24 #include "mmgreetingspage.hxx"
25 #include "mmlayoutpage.hxx"
26 #include <mmconfigitem.hxx>
27 #include <swabstdlg.hxx>
28 #include <strings.hrc>
29 #include <utility>
30 #include <view.hxx>
32 #include <helpids.h>
34 using namespace svt;
35 using namespace ::com::sun::star;
37 SwMailMergeWizard::SwMailMergeWizard(SwView& rView, std::shared_ptr<SwMailMergeConfigItem> xItem)
38 : RoadmapWizardMachine(rView.GetFrameWeld())
39 , m_pSwView(&rView)
40 , m_bDocumentLoad(false)
41 , m_xConfigItem(std::move(xItem))
42 , m_sStarting(SwResId(ST_STARTING))
43 , m_sDocumentType(SwResId(ST_DOCUMENTTYPE))
44 , m_sAddressBlock(SwResId(ST_ADDRESSBLOCK))
45 , m_sAddressList(SwResId(ST_ADDRESSLIST))
46 , m_sGreetingsLine(SwResId(ST_GREETINGSLINE))
47 , m_sLayout(SwResId(ST_LAYOUT))
48 , m_nRestartPage(MM_DOCUMENTSELECTPAGE)
50 defaultButton(WizardButtonFlags::NEXT);
51 enableButtons(WizardButtonFlags::FINISH, false);
53 setTitleBase(SwResId(ST_MMWTITLE));
55 m_xFinish->set_label(SwResId( ST_FINISH ));
56 m_xNextPage->set_help_id(HID_MM_NEXT_PAGE);
57 m_xPrevPage->set_help_id(HID_MM_PREV_PAGE);
59 //#i51949# no output type page visible if e-Mail is not supported
60 if (m_xConfigItem->IsMailAvailable())
61 declarePath(
63 {MM_DOCUMENTSELECTPAGE,
64 MM_OUTPUTTYPETPAGE,
65 MM_ADDRESSBLOCKPAGE,
66 MM_GREETINGSPAGE,
67 MM_LAYOUTPAGE}
69 else
70 declarePath(
72 {MM_DOCUMENTSELECTPAGE,
73 MM_ADDRESSBLOCKPAGE,
74 MM_GREETINGSPAGE,
75 MM_LAYOUTPAGE}
78 ActivatePage();
79 m_xAssistant->set_current_page(0);
80 UpdateRoadmap();
83 SwMailMergeWizard::~SwMailMergeWizard()
87 std::unique_ptr<BuilderPage> SwMailMergeWizard::createPage(WizardState _nState)
89 OUString sIdent(OUString::number(_nState));
90 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
92 std::unique_ptr<vcl::OWizardPage> xRet;
93 switch(_nState)
95 case MM_DOCUMENTSELECTPAGE :
96 xRet = std::make_unique<SwMailMergeDocSelectPage>(pPageContainer, this);
98 /* tdf#52986 Set help ID using SetRoadmapHelpId for all pages
99 so that when by default the focus is on the left side pane of
100 the wizard the relevant help page is displayed when hitting
101 the Help / F1 button */
102 SetRoadmapHelpId("modules/swriter/ui/mmselectpage/MMSelectPage");
103 break;
104 case MM_OUTPUTTYPETPAGE :
105 xRet = std::make_unique<SwMailMergeOutputTypePage>(pPageContainer, this);
106 SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
107 break;
108 case MM_ADDRESSBLOCKPAGE :
109 xRet = std::make_unique<SwMailMergeAddressBlockPage>(pPageContainer, this);
110 SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
111 break;
112 case MM_GREETINGSPAGE :
113 xRet = std::make_unique<SwMailMergeGreetingsPage>(pPageContainer, this);
114 SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
115 break;
116 case MM_LAYOUTPAGE :
117 xRet = std::make_unique<SwMailMergeLayoutPage>(pPageContainer, this);
118 SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
119 break;
122 m_xAssistant->set_page_title(sIdent, getStateDisplayName(_nState));
124 OSL_ENSURE(xRet, "no page created in ::createPage");
125 return xRet;
128 void SwMailMergeWizard::enterState( WizardState _nState )
130 ::vcl::RoadmapWizardMachine::enterState( _nState );
132 if (m_xConfigItem->GetTargetView())
134 //close the dialog, remove the target view, show the source view
135 m_nRestartPage = _nState;
136 //set ResultSet back to start
137 m_xConfigItem->MoveResultSet(1);
138 m_xAssistant->response(RET_REMOVE_TARGET);
139 return;
141 bool bEnablePrev = true;
142 bool bEnableNext = true;
143 switch(_nState)
145 case MM_DOCUMENTSELECTPAGE:
147 bEnablePrev = false; // the first page
149 OUString sDataSourceName = GetSwView()->GetDataSourceName();
150 if(!sDataSourceName.isEmpty() &&
151 !SwView::IsDataSourceAvailable(sDataSourceName))
153 bEnableNext = false;
156 break;
157 case MM_ADDRESSBLOCKPAGE :
158 bEnableNext = m_xConfigItem->GetResultSet().is();
159 break;
160 case MM_LAYOUTPAGE:
161 bEnableNext = false; // the last page
162 break;
164 enableButtons( WizardButtonFlags::PREVIOUS, bEnablePrev);
165 enableButtons( WizardButtonFlags::NEXT, bEnableNext);
167 UpdateRoadmap();
170 OUString SwMailMergeWizard::getStateDisplayName( WizardState _nState ) const
172 switch(_nState)
174 case MM_DOCUMENTSELECTPAGE:
175 return m_sStarting;
176 case MM_OUTPUTTYPETPAGE:
177 return m_sDocumentType;
178 case MM_ADDRESSBLOCKPAGE:
179 return m_xConfigItem->IsOutputToLetter() ?
180 m_sAddressBlock : m_sAddressList;
181 case MM_GREETINGSPAGE:
182 return m_sGreetingsLine;
183 case MM_LAYOUTPAGE:
184 return m_sLayout;
186 return OUString();
189 // enables/disables pages in the roadmap depending on the current page and state
190 void SwMailMergeWizard::UpdateRoadmap()
193 MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
194 MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
195 MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
196 MM_GREETINGSPAGE > inactive after the layoutpage
197 MM_LAYOUTPAGE > inactive after the layoutpage
198 inactive if address block and greeting are switched off
199 or are already inserted into the source document
202 // enableState( <page id>, false );
203 const sal_uInt16 nCurPage = m_xAssistant->get_current_page();
204 BuilderPage* pCurPage = GetPage( nCurPage );
205 if(!pCurPage)
206 return;
207 bool bAddressFieldsConfigured = !m_xConfigItem->IsOutputToLetter() ||
208 !m_xConfigItem->IsAddressBlock() ||
209 m_xConfigItem->IsAddressFieldsAssigned();
210 bool bGreetingFieldsConfigured = !m_xConfigItem->IsGreetingLine(false) ||
211 !m_xConfigItem->IsIndividualGreeting(false) ||
212 m_xConfigItem->IsGreetingFieldsAssigned();
214 //#i97436# if a document has to be loaded then enable output type page only
215 m_bDocumentLoad = false;
216 bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
217 static_cast<vcl::OWizardPage*>(pCurPage)->commitPage( ::vcl::WizardTypes::eValidate );
219 // handle the Finish button
220 bool bCanFinish = !m_bDocumentLoad && bEnableOutputTypePage &&
221 m_xConfigItem->GetResultSet().is() &&
222 bAddressFieldsConfigured &&
223 bGreetingFieldsConfigured;
224 enableButtons(WizardButtonFlags::FINISH, (nCurPage != MM_DOCUMENTSELECTPAGE) && bCanFinish);
226 for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_LAYOUTPAGE; ++nPage)
228 bool bEnable = true;
229 switch(nPage)
231 case MM_DOCUMENTSELECTPAGE:
232 bEnable = true;
233 break;
234 case MM_OUTPUTTYPETPAGE:
235 bEnable = bEnableOutputTypePage;
236 break;
237 case MM_ADDRESSBLOCKPAGE:
238 bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
239 // update page title for email vs letter
240 m_xAssistant->set_page_title(OUString::number(MM_ADDRESSBLOCKPAGE), getStateDisplayName(MM_ADDRESSBLOCKPAGE));
241 break;
242 case MM_GREETINGSPAGE:
243 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
244 m_xConfigItem->GetResultSet().is() &&
245 bAddressFieldsConfigured;
246 break;
247 case MM_LAYOUTPAGE:
248 bEnable = bCanFinish &&
249 ((m_xConfigItem->IsAddressBlock() && !m_xConfigItem->IsAddressInserted()) ||
250 (m_xConfigItem->IsGreetingLine(false) && !m_xConfigItem->IsGreetingInserted() ));
251 break;
253 enableState( nPage, bEnable );
257 short SwMailMergeWizard::run()
259 OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
260 "It creates a thread (MailDispatcher instance) that will call"
261 "back to VCL apartment => deadlock!\n"
262 "Use Dialog::StartExecuteAsync to execute the dialog!" );
263 return RET_CANCEL;
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */