LibreOffice Module sw (master) 1
mmdocselectpage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <sfx2/new.hxx>
22#include <sfx2/docfilt.hxx>
23#include <sfx2/fcontnr.hxx>
24#include <sfx2/docfac.hxx>
25#include <view.hxx>
26#include <docsh.hxx>
27#include "mmdocselectpage.hxx"
28#include <mailmergewizard.hxx>
29#include <swabstdlg.hxx>
30#include <mmconfigitem.hxx>
31#include <swuiexp.hxx>
32#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
34
35using namespace ::com::sun::star::ui::dialogs;
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::uno;
38using namespace svt;
39
41 : vcl::OWizardPage(pPage, pWizard, "modules/swriter/ui/mmselectpage.ui", "MMSelectPage")
42 , m_pWizard(pWizard)
43 , m_xCurrentDocRB(m_xBuilder->weld_radio_button("currentdoc"))
44 , m_xNewDocRB(m_xBuilder->weld_radio_button("newdoc"))
45 , m_xLoadDocRB(m_xBuilder->weld_radio_button("loaddoc"))
46 , m_xLoadTemplateRB(m_xBuilder->weld_radio_button("template"))
47 , m_xRecentDocRB(m_xBuilder->weld_radio_button("recentdoc"))
48 , m_xBrowseDocPB(m_xBuilder->weld_button("browsedoc"))
49 , m_xBrowseTemplatePB(m_xBuilder->weld_button("browsetemplate"))
50 , m_xRecentDocLB(m_xBuilder->weld_combo_box("recentdoclb"))
51 , m_xDataSourceWarningFT(m_xBuilder->weld_label("datasourcewarning"))
52 , m_xExchangeDatabasePB(m_xBuilder->weld_button("exchangedatabase"))
53{
55 m_xCurrentDocRB->set_active(true);
56 DocSelectHdl(*m_xNewDocRB);
57
58 Link<weld::Toggleable&,void> aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
59 m_xCurrentDocRB->connect_toggled(aDocSelectLink);
60 m_xNewDocRB->connect_toggled(aDocSelectLink);
61 m_xLoadDocRB->connect_toggled(aDocSelectLink);
62 m_xLoadTemplateRB->connect_toggled(aDocSelectLink);
63 m_xRecentDocRB->connect_toggled(aDocSelectLink);
64
65 Link<weld::Button&,void> aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
66 m_xBrowseDocPB->connect_clicked(aFileSelectHdl);
67 m_xBrowseTemplatePB->connect_clicked(aFileSelectHdl);
68
69 Link<weld::Button&,void> aExchangeDatabaseHdl = LINK(this, SwMailMergeDocSelectPage, ExchangeDatabaseHdl);
70 m_xExchangeDatabasePB->connect_clicked(aExchangeDatabaseHdl);
71
72 const uno::Sequence< OUString >& rDocs =
74 for(const auto& rDoc : rDocs)
75 {
76 //insert in reverse order
77 m_xRecentDocLB->insert_text(0, rDoc);
78 }
79 if (!rDocs.hasElements())
80 m_xRecentDocRB->set_sensitive(false);
81 else
82 m_xRecentDocLB->set_active(0);
83}
84
86{
87}
88
90{
91 m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
92 m_pWizard->UpdateRoadmap();
93 OUString sDataSourceName = m_pWizard->GetSwView()->GetDataSourceName();
94
95 if(m_xCurrentDocRB->get_active() &&
96 !sDataSourceName.isEmpty() &&
97 !SwView::IsDataSourceAvailable(sDataSourceName))
98 {
99 m_xDataSourceWarningFT->show();
100 m_pWizard->enableButtons(WizardButtonFlags::NEXT, false);
101 }
102 else
103 {
104 m_xDataSourceWarningFT->hide();
105 m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
106 }
107
108 if(m_xCurrentDocRB->get_active())
109 m_xExchangeDatabasePB->set_sensitive(true);
110 else
111 m_xExchangeDatabasePB->set_sensitive(false);
112}
113
114IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
115{
116 bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
117
118 if(bTemplate)
119 {
120 m_xLoadTemplateRB->set_active(true);
121 SfxNewFileDialog aNewFileDlg(m_pWizard->getDialog(), SfxNewFileDialogMode::NONE);
122 sal_uInt16 nRet = aNewFileDlg.run();
123 if(RET_TEMPLATE_LOAD == nRet)
124 bTemplate = false;
125 else if(RET_CANCEL != nRet)
126 m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
127 }
128 else
129 m_xLoadDocRB->set_active(true);
130
131 if(!bTemplate)
132 {
133 sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
134 FileDialogFlags::NONE, m_pWizard->getDialog());
136 Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
137
138 SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
139 SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
140 SfxFilterMatcherIter aIter( aMatcher );
141 std::shared_ptr<const SfxFilter> pFlt = aIter.First();
142 while( pFlt )
143 {
144 if( pFlt && pFlt->IsAllowedAsTemplate() )
145 {
146 const OUString sWild = pFlt->GetWildcard().getGlob();
147 xFP->appendFilter( pFlt->GetUIName(), sWild );
148
149 // #i40125
150 if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
151 xFP->setCurrentFilter( pFlt->GetUIName() ) ;
152 }
153
154 pFlt = aIter.Next();
155 }
156
157 if( ERRCODE_NONE == aDlgHelper.Execute() )
158 {
159 m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
160 }
161 }
162 m_pWizard->UpdateRoadmap();
163 m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
164}
165
167{
168
169 SwAbstractDialogFactory& rFact = ::swui::GetFactory();
170 ScopedVclPtr<VclAbstractDialog> pDlg(rFact.CreateSwChangeDBDlg(*m_pWizard->GetSwView()));
171 pDlg->Execute();
172
173 OUString sDataSourceName = m_pWizard->GetSwView()->GetDataSourceName();
174
175 if(m_xCurrentDocRB->get_active() &&
176 !sDataSourceName.isEmpty() &&
177 SwView::IsDataSourceAvailable(sDataSourceName))
178 {
179 m_xDataSourceWarningFT->hide();
180 m_pWizard->enableButtons(WizardButtonFlags::NEXT, true);
181 }
182}
183
185{
186 bool bReturn = false;
187 bool bNext = _eReason == ::vcl::WizardTypes::eTravelForward;
188 if(bNext || _eReason == ::vcl::WizardTypes::eValidate )
189 {
190 OUString sReloadDocument;
191 bReturn = m_xCurrentDocRB->get_active() ||
192 m_xNewDocRB->get_active();
193 if (!bReturn)
194 {
195 sReloadDocument = m_sLoadFileName;
196 bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
197 }
198 if (!bReturn)
199 {
200 sReloadDocument = m_sLoadTemplateName;
201 bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
202 }
203 if (!bReturn)
204 {
205 bReturn = m_xRecentDocRB->get_active();
206 if (bReturn)
207 {
208 sReloadDocument = m_xRecentDocLB->get_active_text();
209 bReturn = !sReloadDocument.isEmpty();
210 }
211 }
212 if( _eReason == ::vcl::WizardTypes::eValidate )
214
215 if(bNext && !m_xCurrentDocRB->get_active())
216 {
217 if(!sReloadDocument.isEmpty())
218 m_pWizard->SetReloadDocument( sReloadDocument );
221 }
222 }
223 return bReturn;
224}
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< const SfxFilter > First()
std::shared_ptr< const SfxFilter > Next()
OUString GetTemplateFileName() const
const OUString & GetFactoryName() const
virtual VclPtr< VclAbstractDialog > CreateSwChangeDBDlg(SwView &rVw)=0
const css::uno::Sequence< OUString > & GetSavedDocuments() const
std::unique_ptr< weld::RadioButton > m_xNewDocRB
SwMailMergeDocSelectPage(weld::Container *pPage, SwMailMergeWizard *pWizard)
std::unique_ptr< weld::RadioButton > m_xRecentDocRB
std::unique_ptr< weld::RadioButton > m_xCurrentDocRB
virtual ~SwMailMergeDocSelectPage() override
std::unique_ptr< weld::Button > m_xBrowseTemplatePB
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
std::unique_ptr< weld::Label > m_xDataSourceWarningFT
std::unique_ptr< weld::RadioButton > m_xLoadTemplateRB
std::unique_ptr< weld::Button > m_xExchangeDatabasePB
SwMailMergeWizard * m_pWizard
std::unique_ptr< weld::RadioButton > m_xLoadDocRB
std::unique_ptr< weld::ComboBox > m_xRecentDocLB
std::unique_ptr< weld::Button > m_xBrowseDocPB
SwMailMergeConfigItem & GetConfigItem()
void SetDocumentLoad(bool bSet)
void SetRestartPage(sal_uInt16 nPage)
void SetReloadDocument(const OUString &rURL)
static bool IsDataSourceAvailable(const OUString sDataSourceName)
Definition: view.cxx:1982
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
void SetContext(Context _eNewContext)
void response(int nResponse)
#define ERRCODE_NONE
#define MM_OUTPUTTYPETPAGE
IMPL_LINK_NOARG(SwMailMergeDocSelectPage, DocSelectHdl, weld::Toggleable &, void)
IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button &, rButton, void)
#define RET_TEMPLATE_LOAD
#define RET_LOAD_DOC
Definition: swabstdlg.hxx:385
RET_CANCEL