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 
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 {
53  m_xCurrentDocRB->set_active(true);
54  DocSelectHdl(*m_xNewDocRB);
55 
56  Link<weld::ToggleButton&,void> aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
57  m_xCurrentDocRB->connect_toggled(aDocSelectLink);
58  m_xNewDocRB->connect_toggled(aDocSelectLink);
59  m_xLoadDocRB->connect_toggled(aDocSelectLink);
60  m_xLoadTemplateRB->connect_toggled(aDocSelectLink);
61  m_xRecentDocRB->connect_toggled(aDocSelectLink);
62 
63  Link<weld::Button&,void> aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
64  m_xBrowseDocPB->connect_clicked(aFileSelectHdl);
65  m_xBrowseTemplatePB->connect_clicked(aFileSelectHdl);
66 
67  const uno::Sequence< OUString >& rDocs =
69  for(const auto& rDoc : rDocs)
70  {
71  //insert in reverse order
72  m_xRecentDocLB->insert_text(0, rDoc);
73  }
74  if (!rDocs.hasElements())
75  m_xRecentDocRB->set_sensitive(false);
76  else
77  m_xRecentDocLB->set_active(0);
78 }
79 
81 {
82 }
83 
85 {
86  m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
87 
88  m_pWizard->UpdateRoadmap();
89  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
90 }
91 
92 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
93 {
94  bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
95 
96  if(bTemplate)
97  {
98  m_xLoadTemplateRB->set_active(true);
99  SfxNewFileDialog aNewFileDlg(m_pWizard->getDialog(), SfxNewFileDialogMode::NONE);
100  sal_uInt16 nRet = aNewFileDlg.run();
101  if(RET_TEMPLATE_LOAD == nRet)
102  bTemplate = false;
103  else if(RET_CANCEL != nRet)
104  m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
105  }
106  else
107  m_xLoadDocRB->set_active(true);
108 
109  if(!bTemplate)
110  {
111  sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
112  FileDialogFlags::NONE, m_pWizard->getDialog());
113  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
114 
115  xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
116 
117  SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
118  SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
119  SfxFilterMatcherIter aIter( aMatcher );
120  std::shared_ptr<const SfxFilter> pFlt = aIter.First();
121  while( pFlt )
122  {
123  if( pFlt && pFlt->IsAllowedAsTemplate() )
124  {
125  const OUString sWild = pFlt->GetWildcard().getGlob();
126  xFP->appendFilter( pFlt->GetUIName(), sWild );
127 
128  // #i40125
129  if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
130  xFP->setCurrentFilter( pFlt->GetUIName() ) ;
131  }
132 
133  pFlt = aIter.Next();
134  }
135 
136  if( ERRCODE_NONE == aDlgHelper.Execute() )
137  {
138  m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
139  }
140  }
141  m_pWizard->UpdateRoadmap();
142  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
143 }
144 
146 {
147  bool bReturn = false;
148  bool bNext = _eReason == ::vcl::WizardTypes::eTravelForward;
149  if(bNext || _eReason == ::vcl::WizardTypes::eValidate )
150  {
151  OUString sReloadDocument;
152  bReturn = m_xCurrentDocRB->get_active() ||
153  m_xNewDocRB->get_active();
154  if (!bReturn)
155  {
156  sReloadDocument = m_sLoadFileName;
157  bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
158  }
159  if (!bReturn)
160  {
161  sReloadDocument = m_sLoadTemplateName;
162  bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
163  }
164  if (!bReturn)
165  {
166  bReturn = m_xRecentDocRB->get_active();
167  if (bReturn)
168  {
169  sReloadDocument = m_xRecentDocLB->get_active_text();
170  bReturn = !sReloadDocument.isEmpty();
171  }
172  }
173  if( _eReason == ::vcl::WizardTypes::eValidate )
174  m_pWizard->SetDocumentLoad(!m_xCurrentDocRB->get_active());
175 
176  if(bNext && !m_xCurrentDocRB->get_active())
177  {
178  if(!sReloadDocument.isEmpty())
179  m_pWizard->SetReloadDocument( sReloadDocument );
182  }
183  }
184  return bReturn;
185 }
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::RadioButton > m_xNewDocRB
SwMailMergeConfigItem & GetConfigItem()
const OUString & GetFactoryName() const
#define MM_OUTPUTTYPETPAGE
IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button &, rButton, void)
#define RET_LOAD_DOC
Definition: swabstdlg.hxx:349
std::unique_ptr< weld::RadioButton > m_xRecentDocRB
virtual ~SwMailMergeDocSelectPage() override
SwMailMergeDocSelectPage(weld::Container *pPage, SwMailMergeWizard *pWizard)
RET_CANCEL
#define RET_TEMPLATE_LOAD
std::unique_ptr< weld::RadioButton > m_xLoadDocRB
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
const css::uno::Sequence< OUString > & GetSavedDocuments() const
std::unique_ptr< weld::RadioButton > m_xCurrentDocRB
IMPL_LINK_NOARG(SwMailMergeDocSelectPage, DocSelectHdl, weld::ToggleButton &, void)
void SetDocumentLoad(bool bSet)
OUString GetTemplateFileName() const
void SetRestartPage(sal_uInt16 nPage)
void SetReloadDocument(const OUString &rURL)
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
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const