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