Line data Source code
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 <vcl/msgbox.hxx>
27 : #include <view.hxx>
28 : #include <docsh.hxx>
29 : #include <mmdocselectpage.hxx>
30 : #include <mailmergewizard.hxx>
31 : #include <shellio.hxx>
32 : #include <swabstdlg.hxx>
33 : #include <mmconfigitem.hxx>
34 :
35 : #include <dbui.hrc>
36 :
37 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
38 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
39 : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
40 :
41 : using namespace ::com::sun::star::ui::dialogs;
42 : using namespace ::com::sun::star;
43 : using namespace ::com::sun::star::uno;
44 : using namespace svt;
45 :
46 0 : SwMailMergeDocSelectPage::SwMailMergeDocSelectPage(SwMailMergeWizard* pParent)
47 : : svt::OWizardPage(pParent, "MMSelectPage",
48 : "modules/swriter/ui/mmselectpage.ui")
49 0 : , m_pWizard(pParent)
50 : {
51 0 : get(m_pCurrentDocRB, "currentdoc");
52 0 : get(m_pNewDocRB, "newdoc");
53 0 : get(m_pLoadDocRB, "loaddoc");
54 0 : get(m_pLoadTemplateRB, "template");
55 0 : get(m_pRecentDocRB, "recentdoc");
56 0 : get(m_pBrowseDocPB, "browsedoc");
57 0 : get(m_pBrowseTemplatePB, "browsetemplate");
58 0 : get(m_pRecentDocLB, "recentdoclb");
59 :
60 0 : m_pCurrentDocRB->Check();
61 0 : DocSelectHdl(m_pNewDocRB);
62 :
63 0 : Link aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
64 0 : m_pCurrentDocRB->SetClickHdl(aDocSelectLink);
65 0 : m_pNewDocRB->SetClickHdl(aDocSelectLink);
66 0 : m_pLoadDocRB->SetClickHdl(aDocSelectLink);
67 0 : m_pLoadTemplateRB->SetClickHdl(aDocSelectLink);
68 0 : m_pRecentDocRB->SetClickHdl(aDocSelectLink);
69 :
70 0 : Link aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
71 0 : m_pBrowseDocPB->SetClickHdl(aFileSelectHdl);
72 0 : m_pBrowseTemplatePB->SetClickHdl(aFileSelectHdl);
73 :
74 : const uno::Sequence< OUString >& rDocs =
75 0 : m_pWizard->GetConfigItem().GetSavedDocuments();
76 0 : for(sal_Int32 nDoc = 0; nDoc < rDocs.getLength(); ++nDoc)
77 : {
78 : //insert in reverse order
79 0 : m_pRecentDocLB->InsertEntry(rDocs[nDoc], 0);
80 : }
81 0 : m_pRecentDocLB->SelectEntryPos(0);
82 0 : if(!rDocs.getLength())
83 : {
84 0 : m_pRecentDocRB->Enable(false);
85 : }
86 :
87 : //Temp hack until all pages are converted to .ui and wizard
88 : //base class adapted
89 0 : SetSizePixel(LogicToPixel(Size(260 , 250), MapMode(MAP_APPFONT)));
90 0 : }
91 :
92 0 : SwMailMergeDocSelectPage::~SwMailMergeDocSelectPage()
93 : {
94 0 : }
95 :
96 0 : IMPL_LINK(SwMailMergeDocSelectPage, DocSelectHdl, RadioButton*, pButton)
97 : {
98 0 : m_pRecentDocLB->Enable(m_pRecentDocRB == pButton);
99 :
100 0 : m_pWizard->UpdateRoadmap();
101 0 : m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
102 :
103 0 : return 0;
104 : }
105 :
106 0 : IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, PushButton*, pButton)
107 : {
108 0 : bool bTemplate = m_pBrowseTemplatePB == pButton;
109 :
110 0 : if(bTemplate)
111 : {
112 0 : m_pLoadTemplateRB->Check();
113 0 : SfxNewFileDialog* pNewFileDlg = new SfxNewFileDialog(this, 0);
114 0 : sal_uInt16 nRet = pNewFileDlg->Execute();
115 0 : if(RET_TEMPLATE_LOAD == nRet)
116 0 : bTemplate = false;
117 0 : else if(RET_CANCEL != nRet)
118 0 : m_sLoadTemplateName = pNewFileDlg->GetTemplateFileName();
119 0 : delete pNewFileDlg;
120 : }
121 : else
122 0 : m_pLoadDocRB->Check();
123 :
124 0 : if(!bTemplate)
125 : {
126 0 : sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
127 0 : Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
128 :
129 0 : xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
130 :
131 0 : SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
132 0 : SfxFilterMatcher aMatcher( OUString::createFromAscii(rFact.GetShortName()) );
133 0 : SfxFilterMatcherIter aIter( aMatcher );
134 0 : Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
135 0 : const SfxFilter* pFlt = aIter.First();
136 0 : while( pFlt )
137 : {
138 0 : if( pFlt && pFlt->IsAllowedAsTemplate() )
139 : {
140 0 : const OUString sWild = pFlt->GetWildcard().getGlob();
141 0 : xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
142 :
143 : // #i40125
144 0 : if(pFlt->GetFilterFlags() & SFX_FILTER_DEFAULT)
145 0 : xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
146 : }
147 :
148 0 : pFlt = aIter.Next();
149 : }
150 :
151 0 : if( ERRCODE_NONE == aDlgHelper.Execute() )
152 : {
153 0 : m_sLoadFileName = xFP->getFiles().getConstArray()[0];
154 0 : }
155 : }
156 0 : m_pWizard->UpdateRoadmap();
157 0 : m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
158 :
159 0 : return 0;
160 : }
161 :
162 0 : bool SwMailMergeDocSelectPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
163 : {
164 0 : bool bReturn = false;
165 0 : bool bNext = _eReason == ::svt::WizardTypes::eTravelForward;
166 0 : if(bNext || _eReason == ::svt::WizardTypes::eValidate )
167 : {
168 0 : OUString sReloadDocument;
169 0 : bReturn = m_pCurrentDocRB->IsChecked() ||
170 0 : m_pNewDocRB->IsChecked() ||
171 0 : (!(sReloadDocument = m_sLoadFileName).isEmpty() && m_pLoadDocRB->IsChecked() )||
172 0 : (!(sReloadDocument = m_sLoadTemplateName).isEmpty() && m_pLoadTemplateRB->IsChecked())||
173 0 : (m_pRecentDocRB->IsChecked() && !(sReloadDocument = m_pRecentDocLB->GetSelectEntry()).isEmpty());
174 0 : if( _eReason == ::svt::WizardTypes::eValidate )
175 0 : m_pWizard->SetDocumentLoad(!m_pCurrentDocRB->IsChecked());
176 :
177 0 : if(bNext && !m_pCurrentDocRB->IsChecked())
178 : {
179 0 : if(!sReloadDocument.isEmpty())
180 0 : m_pWizard->SetReloadDocument( sReloadDocument );
181 0 : m_pWizard->SetRestartPage(MM_OUTPUTTYPETPAGE);
182 0 : m_pWizard->EndDialog(RET_LOAD_DOC);
183 0 : }
184 : }
185 0 : return bReturn;
186 0 : }
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|