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  : svt::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  disposeOnce();
92 }
93 
95 {
96  m_pWizard.clear();
98 }
99 
101 {
102  m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
103 
104  m_pWizard->UpdateRoadmap();
105  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
106 }
107 
108 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, void)
109 {
110  bool bTemplate = m_xBrowseTemplatePB.get() == &rButton;
111 
112  if(bTemplate)
113  {
114  m_xLoadTemplateRB->set_active(true);
115  SfxNewFileDialog aNewFileDlg(GetFrameWeld(), SfxNewFileDialogMode::NONE);
116  sal_uInt16 nRet = aNewFileDlg.run();
117  if(RET_TEMPLATE_LOAD == nRet)
118  bTemplate = false;
119  else if(RET_CANCEL != nRet)
120  m_sLoadTemplateName = aNewFileDlg.GetTemplateFileName();
121  }
122  else
123  m_xLoadDocRB->set_active(true);
124 
125  if(!bTemplate)
126  {
127  sfx2::FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
128  FileDialogFlags::NONE, GetFrameWeld());
129  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
130 
131  xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
132 
133  SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
134  SfxFilterMatcher aMatcher( rFact.GetFactoryName() );
135  SfxFilterMatcherIter aIter( aMatcher );
136  Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
137  std::shared_ptr<const SfxFilter> pFlt = aIter.First();
138  while( pFlt )
139  {
140  if( pFlt && pFlt->IsAllowedAsTemplate() )
141  {
142  const OUString sWild = pFlt->GetWildcard().getGlob();
143  xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
144 
145  // #i40125
146  if(pFlt->GetFilterFlags() & SfxFilterFlags::DEFAULT)
147  xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
148  }
149 
150  pFlt = aIter.Next();
151  }
152 
153  if( ERRCODE_NONE == aDlgHelper.Execute() )
154  {
155  m_sLoadFileName = xFP->getSelectedFiles().getConstArray()[0];
156  }
157  }
158  m_pWizard->UpdateRoadmap();
159  m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
160 }
161 
163 {
164  bool bReturn = false;
165  bool bNext = _eReason == ::svt::WizardTypes::eTravelForward;
166  if(bNext || _eReason == ::svt::WizardTypes::eValidate )
167  {
168  OUString sReloadDocument;
169  bReturn = m_xCurrentDocRB->get_active() ||
170  m_xNewDocRB->get_active();
171  if (!bReturn)
172  {
173  sReloadDocument = m_sLoadFileName;
174  bReturn = !sReloadDocument.isEmpty() && m_xLoadDocRB->get_active();
175  }
176  if (!bReturn)
177  {
178  sReloadDocument = m_sLoadTemplateName;
179  bReturn = !sReloadDocument.isEmpty() && m_xLoadTemplateRB->get_active();
180  }
181  if (!bReturn)
182  {
183  bReturn = m_xRecentDocRB->get_active();
184  if (bReturn)
185  {
186  sReloadDocument = m_xRecentDocLB->get_active_text();
187  bReturn = !sReloadDocument.isEmpty();
188  }
189  }
190  if( _eReason == ::svt::WizardTypes::eValidate )
191  m_pWizard->SetDocumentLoad(!m_xCurrentDocRB->get_active());
192 
193  if(bNext && !m_xCurrentDocRB->get_active())
194  {
195  if(!sReloadDocument.isEmpty())
196  m_pWizard->SetReloadDocument( sReloadDocument );
198  m_pWizard->EndDialog(RET_LOAD_DOC);
199  }
200  }
201  return bReturn;
202 }
203 
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void dispose() override
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
VclPtr< SwMailMergeWizard > m_pWizard
std::unique_ptr< weld::RadioButton > m_xRecentDocRB
virtual ~SwMailMergeDocSelectPage() override
RET_CANCEL
virtual bool commitPage(::svt::WizardTypes::CommitPageReason _eReason) override
#define RET_TEMPLATE_LOAD
std::unique_ptr< weld::RadioButton > m_xLoadDocRB
const css::uno::Sequence< OUString > & GetSavedDocuments() const
void clear()
SwMailMergeDocSelectPage(SwMailMergeWizard *pWizard, TabPageParent pParent)
virtual void dispose() override
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)
std::unique_ptr< weld::Button > m_xBrowseTemplatePB
std::unique_ptr< weld::Button > m_xBrowseDocPB
#define ERRCODE_NONE
std::unique_ptr< weld::RadioButton > m_xLoadTemplateRB
std::unique_ptr< weld::ComboBox > m_xRecentDocLB
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const