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  m_xRecentDocLB->set_active(0);
75  if(!rDocs.hasElements())
76  {
77  m_xRecentDocRB->set_sensitive(false);
78  }
79 }
80 
82 {
83 }
84 
86 {
87  m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
88 
89  m_pWizard->UpdateRoadmap();
90  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
91 }
92 
93 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
94 {
95  bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
96 
97  if(bTemplate)
98  {
99  m_xLoadTemplateRB->set_active(true);
100  SfxNewFileDialog aNewFileDlg(m_pWizard->getDialog(), SfxNewFileDialogMode::NONE);
101  sal_uInt16 nRet = aNewFileDlg.run();
102  if(RET_TEMPLATE_LOAD == nRet)
103  bTemplate = false;
104  else if(RET_CANCEL != nRet)
105  m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
106  }
107  else
108  m_xLoadDocRB->set_active(true);
109 
110  if(!bTemplate)
111  {
112  sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
113  FileDialogFlags::NONE, m_pWizard->getDialog());
114  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
115 
116  xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
117 
118  SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
119  SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
120  SfxFilterMatcherIter aIter( aMatcher );
121  std::shared_ptr<const SfxFilter> pFlt = aIter.First();
122  while( pFlt )
123  {
124  if( pFlt && pFlt->IsAllowedAsTemplate() )
125  {
126  const OUString sWild = pFlt->GetWildcard().getGlob();
127  xFP->appendFilter( pFlt->GetUIName(), sWild );
128 
129  // #i40125
130  if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
131  xFP->setCurrentFilter( pFlt->GetUIName() ) ;
132  }
133 
134  pFlt = aIter.Next();
135  }
136 
137  if( ERRCODE_NONE == aDlgHelper.Execute() )
138  {
139  m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
140  }
141  }
142  m_pWizard->UpdateRoadmap();
143  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
144 }
145 
147 {
148  bool bReturn = false;
149  bool bNext = _eReason == ::vcl::WizardTypes::eTravelForward;
150  if(bNext || _eReason == ::vcl::WizardTypes::eValidate )
151  {
152  OUString sReloadDocument;
153  bReturn = m_xCurrentDocRB->get_active() ||
154  m_xNewDocRB->get_active();
155  if (!bReturn)
156  {
157  sReloadDocument = m_sLoadFileName;
158  bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
159  }
160  if (!bReturn)
161  {
162  sReloadDocument = m_sLoadTemplateName;
163  bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
164  }
165  if (!bReturn)
166  {
167  bReturn = m_xRecentDocRB->get_active();
168  if (bReturn)
169  {
170  sReloadDocument = m_xRecentDocLB->get_active_text();
171  bReturn = !sReloadDocument.isEmpty();
172  }
173  }
174  if( _eReason == ::vcl::WizardTypes::eValidate )
175  m_pWizard->SetDocumentLoad(!m_xCurrentDocRB->get_active());
176 
177  if(bNext && !m_xCurrentDocRB->get_active())
178  {
179  if(!sReloadDocument.isEmpty())
180  m_pWizard->SetReloadDocument( sReloadDocument );
183  }
184  }
185  return bReturn;
186 }
187 
188 /* 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:348
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