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(pParent, "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  //Temp hack until all pages are converted to .ui and wizard
85  //base class adapted
86  SetSizePixel(LogicToPixel(Size(260 , 250), MapMode(MapUnit::MapAppFont)));
87 }
88 
90 {
91 }
92 
94 {
95  m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
96 
97  m_pWizard->UpdateRoadmap();
98  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
99 }
100 
101 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
102 {
103  bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
104 
105  if(bTemplate)
106  {
107  m_xLoadTemplateRB->set_active(true);
108  SfxNewFileDialog aNewFileDlg(GetFrameWeld(), SfxNewFileDialogMode::NONE);
109  sal_uInt16 nRet = aNewFileDlg.run();
110  if(RET_TEMPLATE_LOAD == nRet)
111  bTemplate = false;
112  else if(RET_CANCEL != nRet)
113  m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
114  }
115  else
116  m_xLoadDocRB->set_active(true);
117 
118  if(!bTemplate)
119  {
120  sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
121  FileDialogFlags::NONE, GetFrameWeld());
122  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
123 
124  xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
125 
126  SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
127  SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
128  SfxFilterMatcherIter aIter( aMatcher );
129  std::shared_ptr<const SfxFilter> pFlt = aIter.First();
130  while( pFlt )
131  {
132  if( pFlt && pFlt->IsAllowedAsTemplate() )
133  {
134  const OUString sWild = pFlt->GetWildcard().getGlob();
135  xFP->appendFilter( pFlt->GetUIName(), sWild );
136 
137  // #i40125
138  if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
139  xFP->setCurrentFilter( pFlt->GetUIName() ) ;
140  }
141 
142  pFlt = aIter.Next();
143  }
144 
145  if( ERRCODE_NONE == aDlgHelper.Execute() )
146  {
147  m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
148  }
149  }
150  m_pWizard->UpdateRoadmap();
151  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
152 }
153 
155 {
156  bool bReturn = false;
157  bool bNext = _eReason == ::vcl::WizardTypes::eTravelForward;
158  if(bNext || _eReason == ::vcl::WizardTypes::eValidate )
159  {
160  OUString sReloadDocument;
161  bReturn = m_xCurrentDocRB->get_active() ||
162  m_xNewDocRB->get_active();
163  if (!bReturn)
164  {
165  sReloadDocument = m_sLoadFileName;
166  bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
167  }
168  if (!bReturn)
169  {
170  sReloadDocument = m_sLoadTemplateName;
171  bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
172  }
173  if (!bReturn)
174  {
175  bReturn = m_xRecentDocRB->get_active();
176  if (bReturn)
177  {
178  sReloadDocument = m_xRecentDocLB->get_active_text();
179  bReturn = !sReloadDocument.isEmpty();
180  }
181  }
182  if( _eReason == ::vcl::WizardTypes::eValidate )
183  m_pWizard->SetDocumentLoad(!m_xCurrentDocRB->get_active());
184 
185  if(bNext && !m_xCurrentDocRB->get_active())
186  {
187  if(!sReloadDocument.isEmpty())
188  m_pWizard->SetReloadDocument( sReloadDocument );
191  }
192  }
193  return bReturn;
194 }
195 
196 /* 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
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
SwMailMergeDocSelectPage(SwMailMergeWizard *pWizard, TabPageParent pParent)
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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)
virtual void SetSizePixel(const Size &rNewSize) override
void response(int nResponse)
Point LogicToPixel(const Point &rLogicPt) const
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