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 <shellio.hxx>
31 #include <swabstdlg.hxx>
32 #include <mmconfigitem.hxx>
33 
34 #include <dbui.hrc>
35 
36 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
38 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
39 
40 using namespace ::com::sun::star::ui::dialogs;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace svt;
44 
46  : vcl::OWizardPage(pPage, pWizard, "modules/swriter/ui/mmselectpage.ui", "MMSelectPage")
47  , m_pWizard(pWizard)
48  , m_xCurrentDocRB(m_xBuilder->weld_radio_button("currentdoc"))
49  , m_xNewDocRB(m_xBuilder->weld_radio_button("newdoc"))
50  , m_xLoadDocRB(m_xBuilder->weld_radio_button("loaddoc"))
51  , m_xLoadTemplateRB(m_xBuilder->weld_radio_button("template"))
52  , m_xRecentDocRB(m_xBuilder->weld_radio_button("recentdoc"))
53  , m_xBrowseDocPB(m_xBuilder->weld_button("browsedoc"))
54  , m_xBrowseTemplatePB(m_xBuilder->weld_button("browsetemplate"))
55  , m_xRecentDocLB(m_xBuilder->weld_combo_box("recentdoclb"))
56 {
57  m_xCurrentDocRB->set_active(true);
58  DocSelectHdl(*m_xNewDocRB);
59 
60  Link<weld::ToggleButton&,void> aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
61  m_xCurrentDocRB->connect_toggled(aDocSelectLink);
62  m_xNewDocRB->connect_toggled(aDocSelectLink);
63  m_xLoadDocRB->connect_toggled(aDocSelectLink);
64  m_xLoadTemplateRB->connect_toggled(aDocSelectLink);
65  m_xRecentDocRB->connect_toggled(aDocSelectLink);
66 
67  Link<weld::Button&,void> aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
68  m_xBrowseDocPB->connect_clicked(aFileSelectHdl);
69  m_xBrowseTemplatePB->connect_clicked(aFileSelectHdl);
70 
71  const uno::Sequence< OUString >& rDocs =
73  for(const auto& rDoc : rDocs)
74  {
75  //insert in reverse order
76  m_xRecentDocLB->insert_text(0, rDoc);
77  }
78  m_xRecentDocLB->set_active(0);
79  if(!rDocs.hasElements())
80  {
81  m_xRecentDocRB->set_sensitive(false);
82  }
83 }
84 
86 {
87 }
88 
90 {
91  m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
92 
93  m_pWizard->UpdateRoadmap();
94  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
95 }
96 
97 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
98 {
99  bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
100 
101  if(bTemplate)
102  {
103  m_xLoadTemplateRB->set_active(true);
104  SfxNewFileDialog aNewFileDlg(m_pWizard->getDialog(), SfxNewFileDialogMode::NONE);
105  sal_uInt16 nRet = aNewFileDlg.run();
106  if(RET_TEMPLATE_LOAD == nRet)
107  bTemplate = false;
108  else if(RET_CANCEL != nRet)
109  m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
110  }
111  else
112  m_xLoadDocRB->set_active(true);
113 
114  if(!bTemplate)
115  {
116  sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
117  FileDialogFlags::NONE, m_pWizard->getDialog());
118  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
119 
120  xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
121 
122  SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
123  SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
124  SfxFilterMatcherIter aIter( aMatcher );
125  std::shared_ptr<const SfxFilter> pFlt = aIter.First();
126  while( pFlt )
127  {
128  if( pFlt && pFlt->IsAllowedAsTemplate() )
129  {
130  const OUString sWild = pFlt->GetWildcard().getGlob();
131  xFP->appendFilter( pFlt->GetUIName(), sWild );
132 
133  // #i40125
134  if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
135  xFP->setCurrentFilter( pFlt->GetUIName() ) ;
136  }
137 
138  pFlt = aIter.Next();
139  }
140 
141  if( ERRCODE_NONE == aDlgHelper.Execute() )
142  {
143  m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
144  }
145  }
146  m_pWizard->UpdateRoadmap();
147  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
148 }
149 
151 {
152  bool bReturn = false;
153  bool bNext = _eReason == ::vcl::WizardTypes::eTravelForward;
154  if(bNext || _eReason == ::vcl::WizardTypes::eValidate )
155  {
156  OUString sReloadDocument;
157  bReturn = m_xCurrentDocRB->get_active() ||
158  m_xNewDocRB->get_active();
159  if (!bReturn)
160  {
161  sReloadDocument = m_sLoadFileName;
162  bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
163  }
164  if (!bReturn)
165  {
166  sReloadDocument = m_sLoadTemplateName;
167  bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
168  }
169  if (!bReturn)
170  {
171  bReturn = m_xRecentDocRB->get_active();
172  if (bReturn)
173  {
174  sReloadDocument = m_xRecentDocLB->get_active_text();
175  bReturn = !sReloadDocument.isEmpty();
176  }
177  }
178  if( _eReason == ::vcl::WizardTypes::eValidate )
179  m_pWizard->SetDocumentLoad(!m_xCurrentDocRB->get_active());
180 
181  if(bNext && !m_xCurrentDocRB->get_active())
182  {
183  if(!sReloadDocument.isEmpty())
184  m_pWizard->SetReloadDocument( sReloadDocument );
187  }
188  }
189  return bReturn;
190 }
191 
192 /* 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:344
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