/src/libreoffice/sfx2/source/doc/objserv.cxx
Line | Count | Source |
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 <config_features.h> |
21 | | |
22 | | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
23 | | #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> |
24 | | #include <com/sun/star/util/CloseVetoException.hpp> |
25 | | #include <com/sun/star/beans/XPropertySet.hpp> |
26 | | #include <com/sun/star/beans/PropertyValue.hpp> |
27 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
28 | | #include <com/sun/star/document/XCmisDocument.hpp> |
29 | | #include <com/sun/star/drawing/LineStyle.hpp> |
30 | | #include <com/sun/star/frame/XModel3.hpp> |
31 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
32 | | #include <com/sun/star/security/XCertificate.hpp> |
33 | | #include <com/sun/star/task/ErrorCodeIOException.hpp> |
34 | | #include <com/sun/star/task/InteractionHandler.hpp> |
35 | | #include <com/sun/star/task/XStatusIndicator.hpp> |
36 | | #include <com/sun/star/task/XStatusIndicatorFactory.hpp> |
37 | | #include <comphelper/processfactory.hxx> |
38 | | #include <comphelper/servicehelper.hxx> |
39 | | #include <com/sun/star/drawing/XDrawView.hpp> |
40 | | |
41 | | #include <com/sun/star/security/DocumentSignatureInformation.hpp> |
42 | | #include <com/sun/star/security/DocumentDigitalSignatures.hpp> |
43 | | #include <comphelper/diagnose_ex.hxx> |
44 | | #include <tools/debug.hxx> |
45 | | #include <tools/stream.hxx> |
46 | | #include <tools/urlobj.hxx> |
47 | | #include <svl/whiter.hxx> |
48 | | #include <svl/intitem.hxx> |
49 | | #include <svl/eitem.hxx> |
50 | | #include <svl/visitem.hxx> |
51 | | #include <svtools/sfxecode.hxx> |
52 | | #include <svtools/ehdl.hxx> |
53 | | #include <sal/log.hxx> |
54 | | #include <sfx2/app.hxx> |
55 | | |
56 | | #include <comphelper/string.hxx> |
57 | | #include <basic/sbxcore.hxx> |
58 | | #include <basic/sberrors.hxx> |
59 | | #include <unotools/moduleoptions.hxx> |
60 | | #include <unotools/saveopt.hxx> |
61 | | #include <unotools/securityoptions.hxx> |
62 | | #include <svtools/DocumentToGraphicRenderer.hxx> |
63 | | #include <vcl/gdimtf.hxx> |
64 | | #include <vcl/svapp.hxx> |
65 | | #include <vcl/weld/MessageDialog.hxx> |
66 | | #include <comphelper/documentconstants.hxx> |
67 | | #include <comphelper/storagehelper.hxx> |
68 | | #include <comphelper/lok.hxx> |
69 | | #include <LibreOfficeKit/LibreOfficeKitEnums.h> |
70 | | #include <tools/link.hxx> |
71 | | #include <svl/cryptosign.hxx> |
72 | | |
73 | | #include <officecfg/Office/Common.hxx> |
74 | | #include <vcl/stdtext.hxx> |
75 | | #include <vcl/help.hxx> |
76 | | |
77 | | #include <sfx2/signaturestate.hxx> |
78 | | #include <sfx2/sfxresid.hxx> |
79 | | #include <sfx2/request.hxx> |
80 | | #include <sfx2/printer.hxx> |
81 | | #include <sfx2/viewsh.hxx> |
82 | | #include <sfx2/dinfdlg.hxx> |
83 | | #include <sfx2/docfilt.hxx> |
84 | | #include <sfx2/docfile.hxx> |
85 | | #include <sfx2/dispatch.hxx> |
86 | | #include <sfx2/objitem.hxx> |
87 | | #include <sfx2/objsh.hxx> |
88 | | #include <objshimp.hxx> |
89 | | #include <sfx2/module.hxx> |
90 | | #include <sfx2/viewfrm.hxx> |
91 | | #include <versdlg.hxx> |
92 | | #include <sfx2/strings.hrc> |
93 | | #include <sfx2/docfac.hxx> |
94 | | #include <sfx2/fcontnr.hxx> |
95 | | #include <sfx2/msgpool.hxx> |
96 | | #include <sfx2/objface.hxx> |
97 | | #include <checkin.hxx> |
98 | | #include <sfx2/infobar.hxx> |
99 | | #include <sfx2/sfxuno.hxx> |
100 | | #include <sfx2/sfxsids.hrc> |
101 | | #include <sfx2/lokhelper.hxx> |
102 | | #include <comphelper/dispatchcommand.hxx> |
103 | | #include <SfxRedactionHelper.hxx> |
104 | | |
105 | | #include <com/sun/star/util/XCloseable.hpp> |
106 | | #include <com/sun/star/document/XDocumentProperties.hpp> |
107 | | |
108 | | #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> |
109 | | #include <com/sun/star/frame/XDesktop2.hpp> |
110 | | #include <com/sun/star/frame/Desktop.hpp> |
111 | | |
112 | | #include <guisaveas.hxx> |
113 | | #include <saveastemplatedlg.hxx> |
114 | | #include <memory> |
115 | | #include <cppuhelper/implbase.hxx> |
116 | | #include <unotools/ucbstreamhelper.hxx> |
117 | | #include <unotools/streamwrap.hxx> |
118 | | #include <comphelper/sequenceashashmap.hxx> |
119 | | #include <editeng/unoprnms.hxx> |
120 | | #include <comphelper/base64.hxx> |
121 | | |
122 | | #include <autoredactdialog.hxx> |
123 | | |
124 | | #include <boost/property_tree/json_parser.hpp> |
125 | | |
126 | | #define ShellClass_SfxObjectShell |
127 | | #include <sfxslots.hxx> |
128 | | |
129 | | using namespace ::com::sun::star; |
130 | | using namespace ::com::sun::star::lang; |
131 | | using namespace ::com::sun::star::uno; |
132 | | using namespace ::com::sun::star::awt; |
133 | | using namespace ::com::sun::star::container; |
134 | | using namespace ::com::sun::star::beans; |
135 | | using namespace ::com::sun::star::document; |
136 | | using namespace ::com::sun::star::security; |
137 | | using namespace ::com::sun::star::task; |
138 | | using namespace ::com::sun::star::graphic; |
139 | | |
140 | | SFX_IMPL_SUPERCLASS_INTERFACE(SfxObjectShell, SfxShell) |
141 | | |
142 | | void SfxObjectShell::InitInterface_Impl() |
143 | 26 | { |
144 | 26 | } |
145 | | |
146 | | namespace { |
147 | | |
148 | | class SfxClosePreventer_Impl : public ::cppu::WeakImplHelper< css::util::XCloseListener > |
149 | | { |
150 | | bool m_bGotOwnership; |
151 | | bool m_bPreventClose; |
152 | | |
153 | | public: |
154 | | SfxClosePreventer_Impl(); |
155 | | |
156 | 0 | bool HasOwnership() const { return m_bGotOwnership; } |
157 | | |
158 | 0 | void SetPreventClose( bool bPrevent ) { m_bPreventClose = bPrevent; } |
159 | | |
160 | | virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership ) override; |
161 | | |
162 | | virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) override ; |
163 | | |
164 | | virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) override ; |
165 | | |
166 | | } ; |
167 | | |
168 | | } |
169 | | |
170 | | SfxClosePreventer_Impl::SfxClosePreventer_Impl() |
171 | 0 | : m_bGotOwnership( false ) |
172 | 0 | , m_bPreventClose( true ) |
173 | 0 | { |
174 | 0 | } |
175 | | |
176 | | void SAL_CALL SfxClosePreventer_Impl::queryClosing( const lang::EventObject&, sal_Bool bDeliverOwnership ) |
177 | 0 | { |
178 | 0 | if ( m_bPreventClose ) |
179 | 0 | { |
180 | 0 | if ( !m_bGotOwnership ) |
181 | 0 | m_bGotOwnership = bDeliverOwnership; |
182 | |
|
183 | 0 | throw util::CloseVetoException(); |
184 | 0 | } |
185 | 0 | } |
186 | | |
187 | | void SAL_CALL SfxClosePreventer_Impl::notifyClosing( const lang::EventObject& ) |
188 | 0 | {} |
189 | | |
190 | | void SAL_CALL SfxClosePreventer_Impl::disposing( const lang::EventObject& ) |
191 | 0 | {} |
192 | | |
193 | | namespace { |
194 | | |
195 | | class SfxInstanceCloseGuard_Impl |
196 | | { |
197 | | rtl::Reference<SfxClosePreventer_Impl> m_xPreventer; |
198 | | uno::Reference< util::XCloseable > m_xCloseable; |
199 | | |
200 | | public: |
201 | 0 | SfxInstanceCloseGuard_Impl() {} |
202 | | |
203 | | ~SfxInstanceCloseGuard_Impl(); |
204 | | |
205 | | bool Init_Impl( const uno::Reference< util::XCloseable >& xCloseable ); |
206 | | }; |
207 | | |
208 | | } |
209 | | |
210 | | bool SfxInstanceCloseGuard_Impl::Init_Impl( const uno::Reference< util::XCloseable >& xCloseable ) |
211 | 0 | { |
212 | 0 | bool bResult = false; |
213 | | |
214 | | // do not allow reinit after the successful init |
215 | 0 | if ( xCloseable.is() && !m_xCloseable.is() ) |
216 | 0 | { |
217 | 0 | try |
218 | 0 | { |
219 | 0 | m_xPreventer = new SfxClosePreventer_Impl(); |
220 | 0 | xCloseable->addCloseListener( m_xPreventer ); |
221 | 0 | m_xCloseable = xCloseable; |
222 | 0 | bResult = true; |
223 | 0 | } |
224 | 0 | catch( uno::Exception& ) |
225 | 0 | { |
226 | 0 | OSL_FAIL( "Could not register close listener!" ); |
227 | 0 | } |
228 | 0 | } |
229 | |
|
230 | 0 | return bResult; |
231 | 0 | } |
232 | | |
233 | | SfxInstanceCloseGuard_Impl::~SfxInstanceCloseGuard_Impl() |
234 | 0 | { |
235 | 0 | if ( !m_xCloseable.is() || !m_xPreventer.is() ) |
236 | 0 | return; |
237 | | |
238 | 0 | try |
239 | 0 | { |
240 | 0 | m_xCloseable->removeCloseListener( m_xPreventer ); |
241 | 0 | } |
242 | 0 | catch( uno::Exception& ) |
243 | 0 | { |
244 | 0 | } |
245 | |
|
246 | 0 | try |
247 | 0 | { |
248 | 0 | if ( m_xPreventer.is() ) |
249 | 0 | { |
250 | 0 | m_xPreventer->SetPreventClose( false ); |
251 | |
|
252 | 0 | if ( m_xPreventer->HasOwnership() ) |
253 | 0 | m_xCloseable->close( true ); // TODO: do it asynchronously |
254 | 0 | } |
255 | 0 | } |
256 | 0 | catch( uno::Exception& ) |
257 | 0 | { |
258 | 0 | } |
259 | 0 | } |
260 | | |
261 | | |
262 | | void SfxObjectShell::PrintExec_Impl(SfxRequest &rReq) |
263 | 0 | { |
264 | 0 | SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this); |
265 | 0 | if ( pFrame ) |
266 | 0 | { |
267 | 0 | rReq.SetSlot( SID_PRINTDOC ); |
268 | 0 | pFrame->GetViewShell()->ExecuteSlot(rReq); |
269 | 0 | } |
270 | 0 | } |
271 | | |
272 | | |
273 | | void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet) |
274 | 0 | { |
275 | 0 | bool bPrinting = false; |
276 | 0 | SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); |
277 | 0 | if ( pFrame ) |
278 | 0 | { |
279 | 0 | SfxPrinter *pPrinter = pFrame->GetViewShell()->GetPrinter(); |
280 | 0 | bPrinting = pPrinter && pPrinter->IsPrinting(); |
281 | 0 | } |
282 | 0 | rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) ); |
283 | 0 | } |
284 | | |
285 | | bool SfxObjectShell::APISaveAs_Impl(std::u16string_view aFileName, SfxItemSet& rItemSet, |
286 | | const css::uno::Sequence<css::beans::PropertyValue>& rArgs) |
287 | 0 | { |
288 | 0 | bool bOk = false; |
289 | |
|
290 | 0 | if ( GetMedium() ) |
291 | 0 | { |
292 | 0 | OUString aFilterName; |
293 | 0 | const SfxStringItem* pFilterNameItem = rItemSet.GetItem<SfxStringItem>(SID_FILTER_NAME, false); |
294 | 0 | if( pFilterNameItem ) |
295 | 0 | { |
296 | 0 | aFilterName = pFilterNameItem->GetValue(); |
297 | 0 | } |
298 | 0 | else |
299 | 0 | { |
300 | 0 | const SfxStringItem* pContentTypeItem = rItemSet.GetItem<SfxStringItem>(SID_CONTENTTYPE, false); |
301 | 0 | if ( pContentTypeItem ) |
302 | 0 | { |
303 | 0 | std::shared_ptr<const SfxFilter> pFilter = SfxFilterMatcher( GetFactory().GetFactoryName() ).GetFilter4Mime( pContentTypeItem->GetValue(), SfxFilterFlags::EXPORT ); |
304 | 0 | if ( pFilter ) |
305 | 0 | aFilterName = pFilter->GetName(); |
306 | 0 | } |
307 | 0 | } |
308 | | |
309 | | // in case no filter defined use default one |
310 | 0 | if( aFilterName.isEmpty() ) |
311 | 0 | { |
312 | 0 | std::shared_ptr<const SfxFilter> pFilt = SfxFilter::GetDefaultFilterFromFactory(GetFactory().GetFactoryName()); |
313 | |
|
314 | 0 | DBG_ASSERT( pFilt, "No default filter!\n" ); |
315 | 0 | if( pFilt ) |
316 | 0 | aFilterName = pFilt->GetFilterName(); |
317 | |
|
318 | 0 | rItemSet.Put(SfxStringItem(SID_FILTER_NAME, aFilterName)); |
319 | 0 | } |
320 | | |
321 | |
|
322 | 0 | { |
323 | 0 | SfxObjectShellRef xLock( this ); // ??? |
324 | | |
325 | | // use the title that is provided in the media descriptor |
326 | 0 | const SfxStringItem* pDocTitleItem = rItemSet.GetItem<SfxStringItem>(SID_DOCINFO_TITLE, false); |
327 | 0 | if ( pDocTitleItem ) |
328 | 0 | getDocProperties()->setTitle( pDocTitleItem->GetValue() ); |
329 | |
|
330 | 0 | bOk = CommonSaveAs_Impl(INetURLObject(aFileName), aFilterName, rItemSet, rArgs); |
331 | 0 | } |
332 | 0 | } |
333 | |
|
334 | 0 | return bOk; |
335 | 0 | } |
336 | | |
337 | | void SfxObjectShell::CheckOut( ) |
338 | 0 | { |
339 | 0 | try |
340 | 0 | { |
341 | 0 | uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW ); |
342 | 0 | xCmisDoc->checkOut( ); |
343 | | |
344 | | // Remove the info bar |
345 | 0 | if (SfxViewFrame* pViewFrame = GetFrame()) |
346 | 0 | pViewFrame->RemoveInfoBar( u"checkout" ); |
347 | 0 | } |
348 | 0 | catch ( const uno::RuntimeException& e ) |
349 | 0 | { |
350 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
351 | 0 | { |
352 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(), |
353 | 0 | VclMessageType::Warning, VclButtonsType::Ok, e.Message)); |
354 | 0 | xBox->run(); |
355 | 0 | } |
356 | 0 | } |
357 | 0 | } |
358 | | |
359 | | void SfxObjectShell::CancelCheckOut( ) |
360 | 0 | { |
361 | 0 | try |
362 | 0 | { |
363 | 0 | uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW ); |
364 | 0 | xCmisDoc->cancelCheckOut( ); |
365 | |
|
366 | 0 | uno::Reference< util::XModifiable > xModifiable( GetModel( ), uno::UNO_QUERY ); |
367 | 0 | if ( xModifiable.is( ) ) |
368 | 0 | xModifiable->setModified( false ); |
369 | 0 | } |
370 | 0 | catch ( const uno::RuntimeException& e ) |
371 | 0 | { |
372 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
373 | 0 | { |
374 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(), |
375 | 0 | VclMessageType::Warning, VclButtonsType::Ok, e.Message)); |
376 | 0 | xBox->run(); |
377 | 0 | } |
378 | 0 | } |
379 | 0 | } |
380 | | |
381 | | void SfxObjectShell::CheckIn( ) |
382 | 0 | { |
383 | 0 | try |
384 | 0 | { |
385 | 0 | uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW ); |
386 | | // Pop up dialog to ask for comment and major |
387 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
388 | 0 | { |
389 | 0 | SfxCheckinDialog checkinDlg(pFrame->GetFrameWeld()); |
390 | 0 | if (checkinDlg.run() == RET_OK) |
391 | 0 | { |
392 | 0 | xCmisDoc->checkIn(checkinDlg.IsMajor(), checkinDlg.GetComment()); |
393 | 0 | uno::Reference< util::XModifiable > xModifiable( GetModel( ), uno::UNO_QUERY ); |
394 | 0 | if ( xModifiable.is( ) ) |
395 | 0 | xModifiable->setModified( false ); |
396 | 0 | } |
397 | 0 | } |
398 | 0 | } |
399 | 0 | catch ( const uno::RuntimeException& e ) |
400 | 0 | { |
401 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
402 | 0 | { |
403 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(), |
404 | 0 | VclMessageType::Warning, VclButtonsType::Ok, e.Message)); |
405 | 0 | xBox->run(); |
406 | 0 | } |
407 | 0 | } |
408 | 0 | } |
409 | | |
410 | | uno::Sequence< document::CmisVersion > SfxObjectShell::GetCmisVersions( ) const |
411 | 0 | { |
412 | 0 | try |
413 | 0 | { |
414 | 0 | uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW ); |
415 | 0 | return xCmisDoc->getAllVersions( ); |
416 | 0 | } |
417 | 0 | catch ( const uno::RuntimeException& e ) |
418 | 0 | { |
419 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
420 | 0 | { |
421 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pFrame->GetFrameWeld(), |
422 | 0 | VclMessageType::Warning, VclButtonsType::Ok, e.Message)); |
423 | 0 | xBox->run(); |
424 | 0 | } |
425 | 0 | } |
426 | 0 | return uno::Sequence< document::CmisVersion > ( ); |
427 | 0 | } |
428 | | |
429 | | bool SfxObjectShell::IsSignPDF() const |
430 | 0 | { |
431 | 0 | if (pMedium && !pMedium->IsOriginallyReadOnly()) |
432 | 0 | { |
433 | 0 | const std::shared_ptr<const SfxFilter>& pFilter = pMedium->GetFilter(); |
434 | 0 | if (pFilter && pFilter->GetName() == "draw_pdf_import") |
435 | 0 | return true; |
436 | 0 | } |
437 | | |
438 | 0 | return false; |
439 | 0 | } |
440 | | |
441 | | static void sendErrorToLOK(const ErrCodeMsg& error) |
442 | 0 | { |
443 | 0 | if (error.GetCode().GetClass() == ErrCodeClass::NONE) |
444 | 0 | return; |
445 | | |
446 | 0 | SfxViewShell* pNotifier = SfxViewShell::Current(); |
447 | 0 | if (!pNotifier) |
448 | 0 | return; |
449 | | |
450 | 0 | boost::property_tree::ptree aTree; |
451 | 0 | aTree.put("code", error); |
452 | 0 | aTree.put("kind", ""); |
453 | 0 | aTree.put("cmd", ""); |
454 | |
|
455 | 0 | OUString aErr; |
456 | 0 | if (ErrorStringFactory::CreateString(error, aErr)) |
457 | 0 | aTree.put("message", aErr.toUtf8()); |
458 | |
|
459 | 0 | std::stringstream aStream; |
460 | 0 | boost::property_tree::write_json(aStream, aTree); |
461 | |
|
462 | 0 | pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, OString(aStream.str())); |
463 | 0 | } |
464 | | |
465 | | namespace |
466 | | { |
467 | | void SetDocProperties(const uno::Reference<document::XDocumentProperties>& xDP, |
468 | | const uno::Sequence<beans::PropertyValue>& rUpdatedProperties) |
469 | 0 | { |
470 | 0 | comphelper::SequenceAsHashMap aMap(rUpdatedProperties); |
471 | 0 | OUString aNamePrefix; |
472 | 0 | auto it = aMap.find(u"NamePrefix"_ustr); |
473 | 0 | if (it != aMap.end()) |
474 | 0 | { |
475 | 0 | it->second >>= aNamePrefix; |
476 | 0 | } |
477 | |
|
478 | 0 | uno::Sequence<beans::PropertyValue> aUserDefinedProperties; |
479 | 0 | it = aMap.find(u"UserDefinedProperties"_ustr); |
480 | 0 | if (it != aMap.end()) |
481 | 0 | { |
482 | 0 | it->second >>= aUserDefinedProperties; |
483 | 0 | } |
484 | |
|
485 | 0 | uno::Reference<beans::XPropertyContainer> xUDP = xDP->getUserDefinedProperties(); |
486 | 0 | if (!aNamePrefix.isEmpty()) |
487 | 0 | { |
488 | 0 | uno::Reference<beans::XPropertySet> xSet(xUDP, UNO_QUERY); |
489 | 0 | uno::Reference<beans::XPropertySetInfo> xSetInfo = xSet->getPropertySetInfo(); |
490 | 0 | const uno::Sequence<beans::Property> aProperties = xSetInfo->getProperties(); |
491 | 0 | for (const auto& rProperty : aProperties) |
492 | 0 | { |
493 | 0 | if (!rProperty.Name.startsWith(aNamePrefix)) |
494 | 0 | { |
495 | 0 | continue; |
496 | 0 | } |
497 | | |
498 | 0 | if (!(rProperty.Attributes & beans::PropertyAttribute::REMOVABLE)) |
499 | 0 | { |
500 | 0 | continue; |
501 | 0 | } |
502 | | |
503 | 0 | xUDP->removeProperty(rProperty.Name); |
504 | 0 | } |
505 | 0 | } |
506 | |
|
507 | 0 | for (const auto& rUserDefinedProperty : aUserDefinedProperties) |
508 | 0 | { |
509 | 0 | xUDP->addProperty(rUserDefinedProperty.Name, beans::PropertyAttribute::REMOVABLE, |
510 | 0 | rUserDefinedProperty.Value); |
511 | 0 | } |
512 | 0 | } |
513 | | } |
514 | | |
515 | | void SfxObjectShell::AfterSignContent(bool bHaveWeSigned, weld::Window* pDialogParent) |
516 | 0 | { |
517 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
518 | 0 | { |
519 | | // LOK signing certificates are per-view, don't store them in the model. |
520 | 0 | return; |
521 | 0 | } |
522 | | |
523 | 0 | if ( bHaveWeSigned && HasValidSignatures() ) |
524 | 0 | { |
525 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( pDialogParent, |
526 | 0 | VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_REMEMBERSIGNATURE))); |
527 | 0 | SetRememberCurrentSignature(xBox->run() == RET_YES); |
528 | 0 | } |
529 | 0 | } |
530 | | |
531 | | namespace |
532 | | { |
533 | | /// Updates the UI so it doesn't try to modify an already finalized signature line shape. |
534 | | void ResetSignatureSelection(SfxObjectShell& rObjectShell, SfxViewShell& rViewShell) |
535 | 0 | { |
536 | 0 | rViewShell.SetSignPDFCertificate({}); |
537 | 0 | comphelper::dispatchCommand(".uno:DeSelect", {}); |
538 | 0 | rObjectShell.RecheckSignature(false); |
539 | 0 | } |
540 | | } |
541 | | |
542 | | static weld::Window* GetReqDialogParent(const SfxRequest &rReq, const SfxObjectShell& rShell) |
543 | 0 | { |
544 | 0 | weld::Window* pDialogParent = rReq.GetFrameWeld(); |
545 | 0 | if (!pDialogParent) |
546 | 0 | { |
547 | 0 | SfxViewFrame* pFrame = rShell.GetFrame(); |
548 | 0 | if (!pFrame) |
549 | 0 | pFrame = SfxViewFrame::GetFirst(&rShell); |
550 | 0 | if (pFrame) |
551 | 0 | pDialogParent = pFrame->GetFrameWeld(); |
552 | 0 | } |
553 | 0 | return pDialogParent; |
554 | 0 | } |
555 | | |
556 | | void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) |
557 | 0 | { |
558 | 0 | sal_uInt16 nId = rReq.GetSlot(); |
559 | |
|
560 | 0 | bool bHaveWeSigned = false; |
561 | |
|
562 | 0 | if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId ) |
563 | 0 | { |
564 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
565 | |
|
566 | 0 | QueryHiddenInformation(HiddenWarningFact::WhenSigning); |
567 | |
|
568 | 0 | if (SID_SIGNATURE == nId) |
569 | 0 | { |
570 | 0 | SfxViewFrame* pFrame = GetFrame(); |
571 | 0 | SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; |
572 | 0 | uno::Reference<security::XCertificate> xCertificate = pViewShell ? pViewShell->GetSignPDFCertificate().m_xCertificate : nullptr; |
573 | 0 | if (xCertificate.is()) |
574 | 0 | { |
575 | |
|
576 | 0 | svl::crypto::SigningContext aSigningContext; |
577 | 0 | aSigningContext.m_xCertificate = std::move(xCertificate); |
578 | 0 | bHaveWeSigned |= SignDocumentContentUsingCertificate(aSigningContext); |
579 | | |
580 | | // Reset the picked certificate for PDF signing, then recheck signatures to show how |
581 | | // the PDF actually looks like after signing. Also change the "finish signing" on |
582 | | // the infobar back to "sign document". |
583 | 0 | if (pViewShell) |
584 | 0 | { |
585 | 0 | ResetSignatureSelection(*this, *pViewShell); |
586 | 0 | pFrame->RemoveInfoBar(u"readonly"); |
587 | 0 | pFrame->AppendReadOnlyInfobar(); |
588 | 0 | } |
589 | 0 | } |
590 | 0 | else |
591 | 0 | { |
592 | | // See if a signing cert is passed as a parameter: if so, parse that. |
593 | 0 | std::string aSignatureCert; |
594 | 0 | std::string aSignatureKey; |
595 | 0 | const SfxStringItem* pSignatureCert = rReq.GetArg<SfxStringItem>(FN_PARAM_1); |
596 | 0 | if (pSignatureCert) |
597 | 0 | { |
598 | 0 | aSignatureCert = pSignatureCert->GetValue().toUtf8(); |
599 | 0 | } |
600 | 0 | const SfxStringItem* pSignatureKey = rReq.GetArg<SfxStringItem>(FN_PARAM_2); |
601 | 0 | if (pSignatureKey) |
602 | 0 | { |
603 | 0 | aSignatureKey = pSignatureKey->GetValue().toUtf8(); |
604 | 0 | } |
605 | | |
606 | | // See if an external signature time/value is provided: if so, sign with those |
607 | | // instead of interactive signing via the dialog. |
608 | 0 | svl::crypto::SigningContext aSigningContext; |
609 | 0 | const SfxStringItem* pSignatureTime = rReq.GetArg<SfxStringItem>(FN_PARAM_3); |
610 | 0 | if (pSignatureTime) |
611 | 0 | { |
612 | 0 | sal_Int64 nSignatureTime = pSignatureTime->GetValue().toInt64(); |
613 | 0 | aSigningContext.m_nSignatureTime = nSignatureTime; |
614 | 0 | } |
615 | 0 | const SfxStringItem* pSignatureValue = rReq.GetArg<SfxStringItem>(FN_PARAM_4); |
616 | 0 | if (pSignatureValue) |
617 | 0 | { |
618 | 0 | OUString aSignatureValue = pSignatureValue->GetValue(); |
619 | 0 | uno::Sequence<sal_Int8> aBytes; |
620 | 0 | comphelper::Base64::decode(aBytes, aSignatureValue); |
621 | 0 | aSigningContext.m_aSignatureValue.assign( |
622 | 0 | aBytes.getArray(), aBytes.getArray() + aBytes.getLength()); |
623 | 0 | } |
624 | 0 | if (!aSigningContext.m_aSignatureValue.empty()) |
625 | 0 | { |
626 | 0 | SignDocumentContentUsingCertificate(aSigningContext); |
627 | 0 | if (pViewShell) |
628 | 0 | { |
629 | 0 | ResetSignatureSelection(*this, *pViewShell); |
630 | 0 | } |
631 | 0 | rReq.Done(); |
632 | 0 | return; |
633 | 0 | } |
634 | | |
635 | 0 | if (pViewShell) |
636 | 0 | { |
637 | 0 | svl::crypto::CertificateOrName aCertificateOrName; |
638 | 0 | if (!aSignatureCert.empty() && !aSignatureKey.empty()) |
639 | 0 | { |
640 | 0 | aCertificateOrName.m_xCertificate = SfxLokHelper::getSigningCertificate(aSignatureCert, aSignatureKey); |
641 | 0 | } |
642 | | // Always set the signing certificate, to clear data from a previous dispatch. |
643 | 0 | pViewShell->SetSigningCertificate(aCertificateOrName); |
644 | 0 | } |
645 | | |
646 | | // Async, all code before return has to go into the callback. |
647 | 0 | SignDocumentContent(pDialogParent, [this, pDialogParent] (bool bSigned) { |
648 | 0 | AfterSignContent(bSigned, pDialogParent); |
649 | 0 | }); |
650 | 0 | return; |
651 | 0 | } |
652 | 0 | } |
653 | 0 | else |
654 | 0 | { |
655 | | // Async, all code before return has to go into the callback. |
656 | 0 | SignScriptingContent(pDialogParent, [this, pDialogParent] (bool bSigned) { |
657 | 0 | AfterSignContent(bSigned, pDialogParent); |
658 | 0 | }); |
659 | 0 | return; |
660 | 0 | } |
661 | | |
662 | 0 | AfterSignContent(bHaveWeSigned, pDialogParent); |
663 | |
|
664 | 0 | return; |
665 | 0 | } |
666 | | |
667 | 0 | if ( !GetMedium() && nId != SID_CLOSEDOC ) |
668 | 0 | { |
669 | 0 | rReq.Ignore(); |
670 | 0 | return; |
671 | 0 | } |
672 | | |
673 | | // this guard is created here to have it destruction at the end of the method |
674 | 0 | SfxInstanceCloseGuard_Impl aModelGuard; |
675 | |
|
676 | 0 | bool bIsPDFExport = false; |
677 | 0 | bool bIsAutoRedact = false; |
678 | 0 | bool bIsAsync = false; |
679 | 0 | std::vector<std::pair<RedactionTarget, OUString>> aRedactionTargets; |
680 | 0 | switch(nId) |
681 | 0 | { |
682 | 0 | case SID_VERSION: |
683 | 0 | { |
684 | 0 | SfxViewFrame* pFrame = GetFrame(); |
685 | 0 | if ( !pFrame ) |
686 | 0 | pFrame = SfxViewFrame::GetFirst( this ); |
687 | 0 | if ( !pFrame ) |
688 | 0 | return; |
689 | | |
690 | 0 | if ( !IsOwnStorageFormat( *GetMedium() ) ) |
691 | 0 | return; |
692 | | |
693 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
694 | 0 | SfxVersionDialog aDlg(pDialogParent, pFrame, IsSaveVersionOnClose()); |
695 | 0 | aDlg.run(); |
696 | 0 | SetSaveVersionOnClose(aDlg.IsSaveVersionOnClose()); |
697 | 0 | rReq.Done(); |
698 | 0 | return; |
699 | 0 | } |
700 | | |
701 | | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
702 | 0 | case SID_DOCINFO: |
703 | 0 | { |
704 | 0 | const SfxDocumentInfoItem* pDocInfItem = rReq.GetArg(SID_DOCINFO); |
705 | 0 | if ( pDocInfItem ) |
706 | 0 | { |
707 | | // parameter, e.g. from replayed macro |
708 | 0 | pDocInfItem->UpdateDocumentInfo(getDocProperties(), true); |
709 | 0 | SetUseUserData( pDocInfItem->IsUseUserData() ); |
710 | 0 | SetUseThumbnailSave( pDocInfItem->IsUseThumbnailSave() ); |
711 | 0 | } |
712 | 0 | else if (const SfxUnoAnyItem* pItem = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_1)) |
713 | 0 | { |
714 | 0 | uno::Sequence<beans::PropertyValue> aUpdatedProperties; |
715 | 0 | pItem->GetValue() >>= aUpdatedProperties; |
716 | 0 | SetDocProperties(getDocProperties(), aUpdatedProperties); |
717 | 0 | } |
718 | 0 | else |
719 | 0 | { |
720 | | // no argument containing DocInfo; check optional arguments |
721 | 0 | bool bReadOnly = IsReadOnly(); |
722 | 0 | const SfxBoolItem* pROItem = rReq.GetArg(SID_DOC_READONLY); |
723 | 0 | if ( pROItem ) |
724 | | // override readonly attribute of document |
725 | | // e.g. if a readonly document is saved elsewhere and user asks for editing DocInfo before |
726 | 0 | bReadOnly = pROItem->GetValue(); |
727 | | |
728 | | // URL for dialog |
729 | 0 | const SfxStringItem* pFileSize = rReq.GetArg<SfxStringItem>(FN_PARAM_2); |
730 | 0 | sal_Int64 nFileSize = pFileSize ? pFileSize->GetValue().toInt64() : -1; |
731 | 0 | const OUString aURL( HasName() ? GetMedium()->GetName() : GetFactory().GetFactoryURL() ); |
732 | |
|
733 | 0 | Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY ); |
734 | 0 | uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties(); |
735 | |
|
736 | 0 | SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(), aCmisProperties, |
737 | 0 | IsUseUserData(), IsUseThumbnailSave(), nFileSize ); |
738 | 0 | const SfxPoolItemHolder aSlotState(GetSlotState(SID_DOCTEMPLATE)); |
739 | 0 | if (!aSlotState) |
740 | | // templates not supported |
741 | 0 | aDocInfoItem.SetTemplate(false); |
742 | |
|
743 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<SID_DOCINFO, SID_DOCINFO, SID_DOC_READONLY, SID_DOC_READONLY, |
744 | 0 | SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START, SID_BASEURL, SID_BASEURL> |
745 | 0 | (GetPool())); |
746 | 0 | aSet.Put( aDocInfoItem ); |
747 | 0 | aSet.Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) ); |
748 | 0 | aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, GetTitle() ) ); |
749 | 0 | aSet.Put( SfxStringItem( SID_BASEURL, GetMedium()->GetBaseURL() ) ); |
750 | | |
751 | | // creating dialog is done via virtual method; application will |
752 | | // add its own statistics page |
753 | 0 | std::shared_ptr<SfxDocumentInfoDialog> xDlg(CreateDocumentInfoDialog(rReq.GetFrameWeld(), aSet)); |
754 | 0 | auto aFunc = [this, xDlg, xCmisDoc, nFileSize](sal_Int32 nResult, SfxRequest& rRequest) |
755 | 0 | { |
756 | 0 | if (RET_OK == nResult) |
757 | 0 | { |
758 | 0 | const SfxDocumentInfoItem* pDocInfoItem = SfxItemSet::GetItem(xDlg->GetOutputItemSet(), SID_DOCINFO, false); |
759 | 0 | if ( pDocInfoItem ) |
760 | 0 | { |
761 | | // user has done some changes to DocumentInfo |
762 | 0 | pDocInfoItem->UpdateDocumentInfo(getDocProperties()); |
763 | 0 | const uno::Sequence< document::CmisProperty >& aNewCmisProperties = |
764 | 0 | pDocInfoItem->GetCmisProperties( ); |
765 | 0 | if ( aNewCmisProperties.hasElements( ) ) |
766 | 0 | xCmisDoc->updateCmisProperties( aNewCmisProperties ); |
767 | 0 | SetUseUserData( pDocInfoItem->IsUseUserData() ); |
768 | 0 | SetUseThumbnailSave( pDocInfoItem-> IsUseThumbnailSave() ); |
769 | | // add data from dialog for possible recording purpose |
770 | 0 | rRequest.AppendItem( SfxDocumentInfoItem( GetTitle(), |
771 | 0 | getDocProperties(), aNewCmisProperties, IsUseUserData(), IsUseThumbnailSave(), nFileSize ) ); |
772 | 0 | } |
773 | 0 | rRequest.Done(); |
774 | 0 | } |
775 | 0 | else |
776 | 0 | { |
777 | | // nothing done; no recording |
778 | 0 | rRequest.Ignore(); |
779 | 0 | } |
780 | 0 | }; |
781 | |
|
782 | 0 | if (!rReq.IsSynchronCall()) |
783 | 0 | { |
784 | 0 | std::shared_ptr<SfxRequest> xReq = std::make_shared<SfxRequest>(rReq); |
785 | 0 | SfxTabDialogController::runAsync(xDlg, [xReq=std::move(xReq), aFunc=std::move(aFunc)](sal_Int32 nResult) |
786 | 0 | { |
787 | 0 | aFunc(nResult, *xReq); |
788 | 0 | }); |
789 | 0 | rReq.Ignore(); |
790 | 0 | } |
791 | 0 | else |
792 | 0 | { |
793 | 0 | aFunc(xDlg->run(), rReq); |
794 | 0 | } |
795 | 0 | } |
796 | |
|
797 | 0 | return; |
798 | 0 | } |
799 | | |
800 | 0 | case SID_AUTOREDACTDOC: |
801 | 0 | { |
802 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
803 | | |
804 | | // Actual redaction takes place on a newly generated Draw document |
805 | 0 | if (!SvtModuleOptions().IsDrawInstalled()) |
806 | 0 | { |
807 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( |
808 | 0 | pDialogParent, VclMessageType::Warning, VclButtonsType::Ok, |
809 | 0 | SfxResId(STR_REDACTION_NO_DRAW_WARNING))); |
810 | |
|
811 | 0 | xBox->run(); |
812 | |
|
813 | 0 | return; |
814 | 0 | } |
815 | | |
816 | 0 | SfxAutoRedactDialog aDlg(pDialogParent); |
817 | 0 | sal_Int16 nResult = aDlg.run(); |
818 | |
|
819 | 0 | const SfxBoolItem* redactImage = rReq.GetArg<SfxBoolItem>(SID_REDACT_IMAGE); |
820 | |
|
821 | 0 | if (redactImage && redactImage->GetValue()) |
822 | 0 | { |
823 | 0 | RedactionTarget redactiontarget({ "Images", RedactionTargetType::REDACTION_TARGET_IMAGE, |
824 | 0 | "All Images", false, false, 0 }); |
825 | 0 | aRedactionTargets.push_back({redactiontarget, redactiontarget.sName}); |
826 | 0 | } |
827 | 0 | else if (nResult != RET_OK || !aDlg.hasTargets() || !aDlg.isValidState()) |
828 | 0 | { |
829 | | //Do nothing |
830 | 0 | return; |
831 | 0 | } |
832 | | |
833 | | // else continue with normal redaction |
834 | 0 | bIsAutoRedact = true; |
835 | 0 | aDlg.getTargets(aRedactionTargets); |
836 | |
|
837 | 0 | [[fallthrough]]; |
838 | 0 | } |
839 | | |
840 | 0 | case SID_REDACTDOC: |
841 | 0 | { |
842 | 0 | css::uno::Reference<css::frame::XModel> xModel = GetModel(); |
843 | 0 | if(!xModel.is()) |
844 | 0 | return; |
845 | | |
846 | 0 | uno::Reference< lang::XComponent > xSourceDoc( xModel ); |
847 | | |
848 | | // Actual redaction takes place on a newly generated Draw document |
849 | 0 | if (!SvtModuleOptions().IsDrawInstalled()) |
850 | 0 | { |
851 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
852 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( |
853 | 0 | pDialogParent, VclMessageType::Warning, VclButtonsType::Ok, |
854 | 0 | SfxResId(STR_REDACTION_NO_DRAW_WARNING))); |
855 | |
|
856 | 0 | xBox->run(); |
857 | |
|
858 | 0 | return; |
859 | 0 | } |
860 | | |
861 | 0 | DocumentToGraphicRenderer aRenderer(xSourceDoc, false); |
862 | | |
863 | | // Get the page margins of the original doc |
864 | 0 | PageMargins aPageMargins = {-1, -1, -1, -1}; |
865 | 0 | if (aRenderer.isWriter()) |
866 | 0 | aPageMargins = SfxRedactionHelper::getPageMarginsForWriter(xModel); |
867 | 0 | else if (aRenderer.isCalc()) |
868 | 0 | aPageMargins = SfxRedactionHelper::getPageMarginsForCalc(xModel); |
869 | |
|
870 | 0 | sal_Int32 nPages = aRenderer.getPageCount(); |
871 | 0 | std::vector< GDIMetaFile > aMetaFiles; |
872 | 0 | std::vector< ::Size > aPageSizes; |
873 | | |
874 | | // Convert the pages of the document to gdimetafiles |
875 | 0 | SfxRedactionHelper::getPageMetaFilesFromDoc(aMetaFiles, aPageSizes, nPages, aRenderer); |
876 | | |
877 | | // Create an empty Draw component. |
878 | 0 | uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); |
879 | 0 | uno::Reference<lang::XComponent> xComponent = xDesktop->loadComponentFromURL(u"private:factory/sdraw"_ustr, u"_default"_ustr, 0, {}); |
880 | |
|
881 | 0 | if (!xComponent.is()) |
882 | 0 | { |
883 | 0 | SAL_WARN("sfx.doc", "SID_REDACTDOC: Failed to load new draw component. loadComponentFromURL returned an empty reference."); |
884 | | |
885 | 0 | return; |
886 | 0 | } |
887 | | |
888 | | // Add the doc pages to the new draw document |
889 | 0 | SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, aPageMargins, aRedactionTargets, bIsAutoRedact); |
890 | | |
891 | | // Show the Redaction toolbar |
892 | 0 | SfxViewFrame* pViewFrame = SfxViewFrame::Current(); |
893 | 0 | if (!pViewFrame) |
894 | 0 | return; |
895 | 0 | SfxRedactionHelper::showRedactionToolbar(pViewFrame); |
896 | |
|
897 | 0 | return; |
898 | 0 | } |
899 | | |
900 | | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
901 | 0 | case SID_DIRECTEXPORTDOCASPDF: |
902 | 0 | { |
903 | 0 | uno::Reference< lang::XComponent > xComponent( GetCurrentComponent(), uno::UNO_QUERY ); |
904 | 0 | if (!xComponent.is()) |
905 | 0 | return; |
906 | | |
907 | 0 | uno::Reference< lang::XServiceInfo > xServiceInfo( xComponent, uno::UNO_QUERY); |
908 | | |
909 | | // Redaction finalization takes place in Draw |
910 | 0 | if ( xServiceInfo.is() && xServiceInfo->supportsService(u"com.sun.star.drawing.DrawingDocument"_ustr) |
911 | 0 | && SfxRedactionHelper::isRedactMode(rReq) ) |
912 | 0 | { |
913 | 0 | OUString sRedactionStyle(SfxRedactionHelper::getStringParam(rReq, SID_REDACTION_STYLE)); |
914 | | |
915 | | // Access the draw pages |
916 | 0 | uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); |
917 | 0 | uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages(); |
918 | |
|
919 | 0 | sal_Int32 nPageCount = xDrawPages->getCount(); |
920 | 0 | for (sal_Int32 nPageNum = 0; nPageNum < nPageCount; ++nPageNum) |
921 | 0 | { |
922 | | // Get the page |
923 | 0 | uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( nPageNum ), uno::UNO_QUERY ); |
924 | |
|
925 | 0 | if (!xPage.is()) |
926 | 0 | continue; |
927 | | |
928 | | // Go through all shapes |
929 | 0 | sal_Int32 nShapeCount = xPage->getCount(); |
930 | 0 | for (sal_Int32 nShapeNum = 0; nShapeNum < nShapeCount; ++nShapeNum) |
931 | 0 | { |
932 | 0 | uno::Reference< drawing::XShape > xCurrShape(xPage->getByIndex(nShapeNum), uno::UNO_QUERY); |
933 | 0 | if (!xCurrShape.is()) |
934 | 0 | continue; |
935 | | |
936 | 0 | uno::Reference< beans::XPropertySet > xPropSet(xCurrShape, uno::UNO_QUERY); |
937 | 0 | if (!xPropSet.is()) |
938 | 0 | continue; |
939 | | |
940 | 0 | uno::Reference< beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); |
941 | 0 | if (!xInfo.is()) |
942 | 0 | continue; |
943 | | |
944 | 0 | OUString sShapeName; |
945 | 0 | if (xInfo->hasPropertyByName(u"Name"_ustr)) |
946 | 0 | { |
947 | 0 | uno::Any aAnyShapeName = xPropSet->getPropertyValue(u"Name"_ustr); |
948 | 0 | aAnyShapeName >>= sShapeName; |
949 | 0 | } |
950 | 0 | else |
951 | 0 | continue; |
952 | | |
953 | | // Rectangle redaction |
954 | 0 | if (sShapeName == "RectangleRedactionShape" |
955 | 0 | && xInfo->hasPropertyByName(u"FillTransparence"_ustr) && xInfo->hasPropertyByName(u"FillColor"_ustr)) |
956 | 0 | { |
957 | 0 | xPropSet->setPropertyValue(u"FillTransparence"_ustr, css::uno::Any(static_cast<sal_Int16>(0))); |
958 | 0 | if (sRedactionStyle == "White") |
959 | 0 | { |
960 | 0 | xPropSet->setPropertyValue(u"FillColor"_ustr, css::uno::Any(COL_WHITE)); |
961 | 0 | xPropSet->setPropertyValue(u"LineStyle"_ustr, css::uno::Any(css::drawing::LineStyle::LineStyle_SOLID)); |
962 | 0 | xPropSet->setPropertyValue(u"LineColor"_ustr, css::uno::Any(COL_BLACK)); |
963 | 0 | } |
964 | 0 | else |
965 | 0 | { |
966 | 0 | xPropSet->setPropertyValue(u"FillColor"_ustr, css::uno::Any(COL_BLACK)); |
967 | 0 | xPropSet->setPropertyValue(u"LineStyle"_ustr, css::uno::Any(css::drawing::LineStyle::LineStyle_NONE)); |
968 | 0 | } |
969 | 0 | } |
970 | | // Freeform redaction |
971 | 0 | else if (sShapeName == "FreeformRedactionShape" |
972 | 0 | && xInfo->hasPropertyByName(u"LineTransparence"_ustr) && xInfo->hasPropertyByName(u"LineColor"_ustr)) |
973 | 0 | { |
974 | 0 | xPropSet->setPropertyValue(u"LineTransparence"_ustr, css::uno::Any(static_cast<sal_Int16>(0))); |
975 | |
|
976 | 0 | if (sRedactionStyle == "White") |
977 | 0 | { |
978 | 0 | xPropSet->setPropertyValue(u"LineColor"_ustr, css::uno::Any(COL_WHITE)); |
979 | 0 | } |
980 | 0 | else |
981 | 0 | { |
982 | 0 | xPropSet->setPropertyValue(u"LineColor"_ustr, css::uno::Any(COL_BLACK)); |
983 | 0 | } |
984 | 0 | } |
985 | 0 | } |
986 | 0 | } |
987 | 0 | } |
988 | 0 | } |
989 | 0 | [[fallthrough]]; |
990 | 0 | case SID_EXPORTDOCASPDF: |
991 | 0 | bIsPDFExport = true; |
992 | 0 | [[fallthrough]]; |
993 | 0 | case SID_EXPORTDOCASEPUB: |
994 | 0 | case SID_DIRECTEXPORTDOCASEPUB: |
995 | 0 | case SID_EXPORTDOC: |
996 | 0 | case SID_SAVEASDOC: |
997 | 0 | case SID_SAVEASREMOTE: |
998 | 0 | case SID_SAVEDOC: |
999 | 0 | { |
1000 | | // so far only pdf and epub support Async interface |
1001 | 0 | if (comphelper::LibreOfficeKit::isActive() && rReq.GetCallMode() == SfxCallMode::ASYNCHRON |
1002 | 0 | && (nId == SID_EXPORTDOCASEPUB || nId == SID_EXPORTDOCASPDF)) |
1003 | 0 | bIsAsync = true; |
1004 | | |
1005 | | // derived class may decide to abort this |
1006 | 0 | if( !QuerySlotExecutable( nId ) ) |
1007 | 0 | { |
1008 | 0 | rReq.SetReturnValue( SfxBoolItem( 0, false ) ); |
1009 | 0 | return; |
1010 | 0 | } |
1011 | | |
1012 | | //!! detailed analysis of an error code |
1013 | 0 | SfxObjectShellRef xLock( this ); |
1014 | | |
1015 | | // the model can not be closed till the end of this method |
1016 | | // if somebody tries to close it during this time the model will be closed |
1017 | | // at the end of the method |
1018 | 0 | aModelGuard.Init_Impl( uno::Reference< util::XCloseable >( GetModel(), uno::UNO_QUERY ) ); |
1019 | |
|
1020 | 0 | ErrCodeMsg nErrorCode = ERRCODE_NONE; |
1021 | | |
1022 | | // by default versions should be preserved always except in case of an explicit |
1023 | | // SaveAs via GUI, so the flag must be set accordingly |
1024 | 0 | pImpl->bPreserveVersions = (nId == SID_SAVEDOC); |
1025 | | |
1026 | | // do not save version infos --> (see 'Tools - Options - LibreOffice - Security') |
1027 | 0 | if (SvtSecurityOptions::IsOptionSet( |
1028 | 0 | SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo) && !SvtSecurityOptions::IsOptionSet( |
1029 | 0 | SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo)) |
1030 | 0 | { |
1031 | 0 | pImpl->bPreserveVersions = false; |
1032 | 0 | } |
1033 | |
|
1034 | 0 | try |
1035 | 0 | { |
1036 | 0 | SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, GetTitle() ); // ??? |
1037 | |
|
1038 | 0 | if ( nId == SID_SAVEASDOC || nId == SID_SAVEASREMOTE ) |
1039 | 0 | { |
1040 | | // in case of plugin mode the SaveAs operation means SaveTo |
1041 | 0 | const SfxBoolItem* pViewOnlyItem = GetMedium()->GetItemSet().GetItem(SID_VIEWONLY, false); |
1042 | 0 | if ( pViewOnlyItem && pViewOnlyItem->GetValue() ) |
1043 | 0 | rReq.AppendItem( SfxBoolItem( SID_SAVETO, true ) ); |
1044 | 0 | } |
1045 | | |
1046 | | // TODO/LATER: do the following GUI related actions in standalone method |
1047 | | |
1048 | | // Introduce a status indicator for GUI operation |
1049 | 0 | const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg(SID_PROGRESS_STATUSBAR_CONTROL); |
1050 | 0 | if ( !pStatusIndicatorItem ) |
1051 | 0 | { |
1052 | | // get statusindicator |
1053 | 0 | uno::Reference< task::XStatusIndicator > xStatusIndicator; |
1054 | 0 | uno::Reference < frame::XController > xCtrl( GetModel()->getCurrentController() ); |
1055 | 0 | if ( xCtrl.is() ) |
1056 | 0 | { |
1057 | 0 | uno::Reference< task::XStatusIndicatorFactory > xStatFactory( xCtrl->getFrame(), uno::UNO_QUERY ); |
1058 | 0 | if( xStatFactory.is() ) |
1059 | 0 | xStatusIndicator = xStatFactory->createStatusIndicator(); |
1060 | 0 | } |
1061 | |
|
1062 | 0 | OSL_ENSURE( xStatusIndicator.is(), "Can not retrieve default status indicator!" ); |
1063 | |
|
1064 | 0 | if ( xStatusIndicator.is() ) |
1065 | 0 | { |
1066 | 0 | SfxUnoAnyItem aStatIndItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::Any( xStatusIndicator ) ); |
1067 | |
|
1068 | 0 | if ( nId == SID_SAVEDOC ) |
1069 | 0 | { |
1070 | | // in case of saving it is not possible to transport the parameters from here |
1071 | | // but it is not clear here whether the saving will be done or saveAs operation |
1072 | 0 | GetMedium()->GetItemSet().Put( aStatIndItem ); |
1073 | 0 | } |
1074 | |
|
1075 | 0 | rReq.AppendItem( aStatIndItem ); |
1076 | 0 | } |
1077 | 0 | } |
1078 | 0 | else if ( nId == SID_SAVEDOC ) |
1079 | 0 | { |
1080 | | // in case of saving it is not possible to transport the parameters from here |
1081 | | // but it is not clear here whether the saving will be done or saveAs operation |
1082 | 0 | GetMedium()->GetItemSet().Put( *pStatusIndicatorItem ); |
1083 | 0 | } |
1084 | | |
1085 | | // Introduce an interaction handler for GUI operation |
1086 | 0 | const SfxUnoAnyItem* pInteractionHandlerItem = rReq.GetArg(SID_INTERACTIONHANDLER); |
1087 | 0 | if ( !pInteractionHandlerItem ) |
1088 | 0 | { |
1089 | 0 | uno::Reference<css::awt::XWindow> xParentWindow; |
1090 | 0 | uno::Reference<frame::XController> xCtrl(GetModel()->getCurrentController()); |
1091 | 0 | if (xCtrl.is()) |
1092 | 0 | xParentWindow = xCtrl->getFrame()->getContainerWindow(); |
1093 | |
|
1094 | 0 | const uno::Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
1095 | |
|
1096 | 0 | uno::Reference< task::XInteractionHandler2 > xInteract( |
1097 | 0 | task::InteractionHandler::createWithParent(xContext, xParentWindow) ); |
1098 | |
|
1099 | 0 | SfxUnoAnyItem aInteractionItem( SID_INTERACTIONHANDLER, uno::Any( xInteract ) ); |
1100 | 0 | if ( nId == SID_SAVEDOC ) |
1101 | 0 | { |
1102 | | // in case of saving it is not possible to transport the parameters from here |
1103 | | // but it is not clear here whether the saving will be done or saveAs operation |
1104 | 0 | GetMedium()->GetItemSet().Put( aInteractionItem ); |
1105 | 0 | } |
1106 | |
|
1107 | 0 | rReq.AppendItem( aInteractionItem ); |
1108 | 0 | } |
1109 | 0 | else if ( nId == SID_SAVEDOC ) |
1110 | 0 | { |
1111 | | // in case of saving it is not possible to transport the parameters from here |
1112 | | // but it is not clear here whether the saving will be done or saveAs operation |
1113 | 0 | GetMedium()->GetItemSet().Put( *pInteractionHandlerItem ); |
1114 | 0 | } |
1115 | | |
1116 | |
|
1117 | 0 | const SfxStringItem* pOldPasswordItem = GetMedium()->GetItemSet().GetItem(SID_PASSWORD, false); |
1118 | 0 | const SfxUnoAnyItem* pOldEncryptionDataItem = GetMedium()->GetItemSet().GetItem(SID_ENCRYPTIONDATA, false); |
1119 | 0 | const bool bPreselectPassword |
1120 | 0 | = pOldPasswordItem || pOldEncryptionDataItem |
1121 | 0 | || (IsLoadReadonly() |
1122 | 0 | && (GetModifyPasswordHash() || GetModifyPasswordInfo().hasElements())); |
1123 | |
|
1124 | 0 | uno::Sequence< beans::PropertyValue > aDispatchArgs; |
1125 | 0 | if ( rReq.GetArgs() ) |
1126 | 0 | aDispatchArgs = TransformItems(nId, *rReq.GetArgs()).getAsConstPropertyValueList(); |
1127 | |
|
1128 | 0 | bool bForceSaveAs = nId == SID_SAVEDOC && IsReadOnlyMedium(); |
1129 | |
|
1130 | 0 | if (comphelper::LibreOfficeKit::isActive() && bForceSaveAs) |
1131 | 0 | { |
1132 | | // Don't force save as in LOK but report that file cannot be written |
1133 | | // to avoid confusion with exporting for file download purpose |
1134 | |
|
1135 | 0 | throw task::ErrorCodeIOException( |
1136 | 0 | u"SfxObjectShell::ExecFile_Impl: ERRCODE_IO_CANTWRITE"_ustr, |
1137 | 0 | uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_IO_CANTWRITE)); |
1138 | 0 | } |
1139 | | |
1140 | 0 | const SfxSlot* pSlot = GetModule()->GetSlotPool()->GetSlot( bForceSaveAs ? SID_SAVEASDOC : nId ); |
1141 | 0 | if ( !pSlot ) |
1142 | 0 | throw uno::Exception(u"no slot"_ustr, nullptr); |
1143 | | |
1144 | 0 | std::shared_ptr<SfxStoringHelper> xHelper = std::make_shared<SfxStoringHelper>(); |
1145 | 0 | if (bIsAsync && SfxViewShell::Current()) |
1146 | 0 | SfxViewShell::Current()->SetStoringHelper(xHelper); |
1147 | |
|
1148 | 0 | QueryHiddenInformation(bIsPDFExport ? HiddenWarningFact::WhenCreatingPDF : HiddenWarningFact::WhenSaving); |
1149 | |
|
1150 | 0 | xHelper->GUIStoreModel( GetModel(), |
1151 | 0 | pSlot->GetUnoName(), |
1152 | 0 | aDispatchArgs, |
1153 | 0 | bPreselectPassword, |
1154 | 0 | GetDocumentSignatureState(), |
1155 | 0 | GetScriptingSignatureState(), |
1156 | 0 | bIsAsync ); |
1157 | | |
1158 | | // merge aDispatchArgs to the request |
1159 | 0 | SfxAllItemSet aResultParams( GetPool() ); |
1160 | 0 | TransformParameters( nId, |
1161 | 0 | aDispatchArgs, |
1162 | 0 | aResultParams ); |
1163 | 0 | rReq.SetArgs( aResultParams ); |
1164 | | |
1165 | | // the StoreAsURL/StoreToURL method have called this method with false |
1166 | | // so it has to be restored to true here since it is a call from GUI |
1167 | 0 | GetMedium()->SetUpdatePickList( true ); |
1168 | | |
1169 | | // TODO: in future it must be done in following way |
1170 | | // if document is opened from GUI, it immediately appears in the picklist |
1171 | | // if the document is a new one then it appears in the picklist immediately |
1172 | | // after SaveAs operation triggered from GUI |
1173 | 0 | } |
1174 | 0 | catch( const task::ErrorCodeIOException& aErrorEx ) |
1175 | 0 | { |
1176 | 0 | TOOLS_WARN_EXCEPTION_IF(ErrCode(aErrorEx.ErrCode) != ERRCODE_IO_ABORT, "sfx.doc", "Fatal IO error during save"); |
1177 | 0 | nErrorCode = { ErrCode(aErrorEx.ErrCode), aErrorEx.Message }; |
1178 | 0 | } |
1179 | 0 | catch( Exception& e ) |
1180 | 0 | { |
1181 | 0 | nErrorCode = { ERRCODE_IO_GENERAL, e.Message }; |
1182 | 0 | } |
1183 | | |
1184 | | // by default versions should be preserved always except in case of an explicit |
1185 | | // SaveAs via GUI, so the flag must be reset to guarantee this |
1186 | 0 | pImpl->bPreserveVersions = true; |
1187 | 0 | ErrCodeMsg lErr=GetErrorCode(); |
1188 | |
|
1189 | 0 | if ( !lErr && nErrorCode ) |
1190 | 0 | lErr = nErrorCode; |
1191 | |
|
1192 | 0 | if ( lErr && nErrorCode == ERRCODE_NONE ) |
1193 | 0 | { |
1194 | 0 | const SfxBoolItem* pWarnItem = rReq.GetArg(SID_FAIL_ON_WARNING); |
1195 | 0 | if ( pWarnItem && pWarnItem->GetValue() ) |
1196 | 0 | nErrorCode = lErr; |
1197 | 0 | } |
1198 | | |
1199 | | // may be nErrorCode should be shown in future |
1200 | 0 | if ( lErr != ERRCODE_IO_ABORT ) |
1201 | 0 | { |
1202 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
1203 | 0 | sendErrorToLOK(lErr); |
1204 | 0 | else |
1205 | 0 | { |
1206 | 0 | SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC,GetTitle()); |
1207 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
1208 | 0 | ErrorHandler::HandleError(lErr, pDialogParent); |
1209 | 0 | } |
1210 | 0 | } |
1211 | |
|
1212 | 0 | if (nId == SID_DIRECTEXPORTDOCASPDF && |
1213 | 0 | SfxRedactionHelper::isRedactMode(rReq)) |
1214 | 0 | { |
1215 | | // Return the finalized redaction shapes back to normal (gray & transparent) |
1216 | 0 | uno::Reference< lang::XComponent > xComponent( GetCurrentComponent(), uno::UNO_QUERY ); |
1217 | 0 | if (!xComponent.is()) |
1218 | 0 | return; |
1219 | | |
1220 | 0 | uno::Reference< lang::XServiceInfo > xServiceInfo( xComponent, uno::UNO_QUERY); |
1221 | | |
1222 | | // Redaction finalization takes place in Draw |
1223 | 0 | if ( xServiceInfo.is() && xServiceInfo->supportsService(u"com.sun.star.drawing.DrawingDocument"_ustr) ) |
1224 | 0 | { |
1225 | | // Access the draw pages |
1226 | 0 | uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); |
1227 | 0 | uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages(); |
1228 | |
|
1229 | 0 | sal_Int32 nPageCount = xDrawPages->getCount(); |
1230 | 0 | for (sal_Int32 nPageNum = 0; nPageNum < nPageCount; ++nPageNum) |
1231 | 0 | { |
1232 | | // Get the page |
1233 | 0 | uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( nPageNum ), uno::UNO_QUERY ); |
1234 | |
|
1235 | 0 | if (!xPage.is()) |
1236 | 0 | continue; |
1237 | | |
1238 | | // Go through all shapes |
1239 | 0 | sal_Int32 nShapeCount = xPage->getCount(); |
1240 | 0 | for (sal_Int32 nShapeNum = 0; nShapeNum < nShapeCount; ++nShapeNum) |
1241 | 0 | { |
1242 | 0 | uno::Reference< drawing::XShape > xCurrShape(xPage->getByIndex(nShapeNum), uno::UNO_QUERY); |
1243 | 0 | if (!xCurrShape.is()) |
1244 | 0 | continue; |
1245 | | |
1246 | 0 | uno::Reference< beans::XPropertySet > xPropSet(xCurrShape, uno::UNO_QUERY); |
1247 | 0 | if (!xPropSet.is()) |
1248 | 0 | continue; |
1249 | | |
1250 | 0 | uno::Reference< beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); |
1251 | 0 | if (!xInfo.is()) |
1252 | 0 | continue; |
1253 | | |
1254 | | // Not a shape we converted? |
1255 | 0 | if (!xInfo->hasPropertyByName(u"Name"_ustr)) |
1256 | 0 | continue; |
1257 | | |
1258 | 0 | OUString sShapeName; |
1259 | 0 | if (xInfo->hasPropertyByName(u"Name"_ustr)) |
1260 | 0 | { |
1261 | 0 | uno::Any aAnyShapeName = xPropSet->getPropertyValue(u"Name"_ustr); |
1262 | 0 | aAnyShapeName >>= sShapeName; |
1263 | 0 | } |
1264 | 0 | else |
1265 | 0 | continue; |
1266 | | |
1267 | | // Rectangle redaction |
1268 | 0 | if (sShapeName == "RectangleRedactionShape" |
1269 | 0 | && xInfo->hasPropertyByName(u"FillTransparence"_ustr) && xInfo->hasPropertyByName(u"FillColor"_ustr)) |
1270 | 0 | { |
1271 | 0 | xPropSet->setPropertyValue(u"FillTransparence"_ustr, css::uno::Any(static_cast<sal_Int16>(50))); |
1272 | 0 | xPropSet->setPropertyValue(u"FillColor"_ustr, css::uno::Any(COL_GRAY7)); |
1273 | 0 | xPropSet->setPropertyValue(u"LineStyle"_ustr, css::uno::Any(css::drawing::LineStyle::LineStyle_NONE)); |
1274 | |
|
1275 | 0 | } |
1276 | | // Freeform redaction |
1277 | 0 | else if (sShapeName == "FreeformRedactionShape") |
1278 | 0 | { |
1279 | 0 | xPropSet->setPropertyValue(u"LineTransparence"_ustr, css::uno::Any(static_cast<sal_Int16>(50))); |
1280 | 0 | xPropSet->setPropertyValue(u"LineColor"_ustr, css::uno::Any(COL_GRAY7)); |
1281 | 0 | } |
1282 | 0 | } |
1283 | 0 | } |
1284 | | |
1285 | |
|
1286 | 0 | } |
1287 | 0 | } |
1288 | | |
1289 | 0 | if ( nId == SID_EXPORTDOCASPDF ) |
1290 | 0 | { |
1291 | | // This function is used by the SendMail function that needs information if an export |
1292 | | // file was written or not. This could be due to cancellation of the export |
1293 | | // or due to an error. So IO abort must be handled like an error! |
1294 | 0 | nErrorCode = ( lErr != ERRCODE_IO_ABORT ) && ( nErrorCode == ERRCODE_NONE ) ? nErrorCode : lErr; |
1295 | 0 | } |
1296 | |
|
1297 | 0 | if ( ( nId == SID_SAVEASDOC || nId == SID_SAVEASREMOTE ) && nErrorCode == ERRCODE_NONE ) |
1298 | 0 | { |
1299 | 0 | const SfxBoolItem* saveTo = rReq.GetArg(SID_SAVETO); |
1300 | | // IsReadOnly may still return true, e.g. when embedded fonts disallow editing |
1301 | 0 | if ((saveTo == nullptr || !saveTo->GetValue()) && !IsReadOnly()) |
1302 | 0 | { |
1303 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
1304 | 0 | pFrame->RemoveInfoBar(u"readonly"); |
1305 | 0 | SetReadOnlyUI(false); |
1306 | 0 | } |
1307 | 0 | } |
1308 | |
|
1309 | 0 | if (nId == SID_SAVEDOC && bRememberSignature && rSignatureInfosRemembered.hasElements()) |
1310 | 0 | ResignDocument(rSignatureInfosRemembered); |
1311 | |
|
1312 | 0 | rReq.SetReturnValue( SfxBoolItem(0, nErrorCode == ERRCODE_NONE ) ); |
1313 | |
|
1314 | 0 | ResetError(); |
1315 | |
|
1316 | 0 | Invalidate(); |
1317 | 0 | break; |
1318 | 0 | } |
1319 | | |
1320 | 0 | case SID_SAVEACOPY: |
1321 | 0 | { |
1322 | 0 | SfxAllItemSet aArgs( GetPool() ); |
1323 | 0 | aArgs.Put( SfxBoolItem( SID_SAVEACOPYITEM, true ) ); |
1324 | 0 | SfxRequest aSaveACopyReq( SID_EXPORTDOC, SfxCallMode::API, aArgs ); |
1325 | 0 | ExecFile_Impl( aSaveACopyReq ); |
1326 | 0 | if ( !aSaveACopyReq.IsDone() ) |
1327 | 0 | { |
1328 | 0 | rReq.Ignore(); |
1329 | 0 | return; |
1330 | 0 | } |
1331 | 0 | break; |
1332 | 0 | } |
1333 | | |
1334 | | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
1335 | | |
1336 | 0 | case SID_CLOSEDOC: |
1337 | 0 | { |
1338 | | // Evaluate Parameter |
1339 | 0 | const SfxBoolItem* pSaveItem = rReq.GetArg<SfxBoolItem>(SID_CLOSEDOC_SAVE); |
1340 | 0 | const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_CLOSEDOC_FILENAME); |
1341 | 0 | if ( pSaveItem ) |
1342 | 0 | { |
1343 | 0 | if ( pSaveItem->GetValue() ) |
1344 | 0 | { |
1345 | 0 | if ( !pNameItem ) |
1346 | 0 | { |
1347 | | #if HAVE_FEATURE_SCRIPTING |
1348 | | SbxBase::SetError( ERRCODE_BASIC_WRONG_ARGS ); |
1349 | | #endif |
1350 | 0 | rReq.Ignore(); |
1351 | 0 | return; |
1352 | 0 | } |
1353 | 0 | SfxAllItemSet aArgs( GetPool() ); |
1354 | 0 | SfxStringItem aTmpItem( SID_FILE_NAME, pNameItem->GetValue() ); |
1355 | 0 | aArgs.Put( aTmpItem ); |
1356 | 0 | SfxRequest aSaveAsReq( SID_SAVEASDOC, SfxCallMode::API, aArgs ); |
1357 | 0 | ExecFile_Impl( aSaveAsReq ); |
1358 | 0 | if ( !aSaveAsReq.IsDone() ) |
1359 | 0 | { |
1360 | 0 | rReq.Ignore(); |
1361 | 0 | return; |
1362 | 0 | } |
1363 | 0 | } |
1364 | 0 | else |
1365 | 0 | SetModified(false); |
1366 | 0 | } |
1367 | | |
1368 | | // Cancelled by the user? |
1369 | 0 | if (!PrepareClose()) |
1370 | 0 | { |
1371 | 0 | rReq.SetReturnValue( SfxBoolItem(0, false) ); |
1372 | 0 | rReq.Done(); |
1373 | 0 | return; |
1374 | 0 | } |
1375 | | |
1376 | 0 | SetModified( false ); |
1377 | 0 | ErrCodeMsg lErr = GetErrorCode(); |
1378 | |
|
1379 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
1380 | 0 | sendErrorToLOK(lErr); |
1381 | 0 | else |
1382 | 0 | { |
1383 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
1384 | 0 | ErrorHandler::HandleError(lErr, pDialogParent); |
1385 | 0 | } |
1386 | |
|
1387 | 0 | rReq.SetReturnValue( SfxBoolItem(0, true) ); |
1388 | 0 | rReq.Done(); |
1389 | 0 | rReq.ReleaseArgs(); // because the pool is destroyed in Close |
1390 | 0 | DoClose(); |
1391 | 0 | return; |
1392 | 0 | } |
1393 | | |
1394 | | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
1395 | 0 | case SID_DOCTEMPLATE: |
1396 | 0 | { |
1397 | | // save as document templates |
1398 | 0 | weld::Window* pDialogParent = GetReqDialogParent(rReq, *this); |
1399 | 0 | SfxSaveAsTemplateDialog aDlg(pDialogParent, GetModel()); |
1400 | 0 | (void)aDlg.run(); |
1401 | 0 | break; |
1402 | 0 | } |
1403 | | |
1404 | 0 | case SID_CHECKOUT: |
1405 | 0 | { |
1406 | 0 | CheckOut( ); |
1407 | 0 | break; |
1408 | 0 | } |
1409 | 0 | case SID_CANCELCHECKOUT: |
1410 | 0 | { |
1411 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr, |
1412 | 0 | VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_CANCELCHECKOUT))); |
1413 | 0 | if (xBox->run() == RET_YES) |
1414 | 0 | { |
1415 | 0 | CancelCheckOut( ); |
1416 | | |
1417 | | // Reload the document as we may still have local changes |
1418 | 0 | if (SfxViewFrame* pFrame = GetFrame()) |
1419 | 0 | pFrame->GetDispatcher()->Execute(SID_RELOAD); |
1420 | 0 | } |
1421 | 0 | break; |
1422 | 0 | } |
1423 | 0 | case SID_CHECKIN: |
1424 | 0 | { |
1425 | 0 | CheckIn( ); |
1426 | 0 | break; |
1427 | 0 | } |
1428 | 0 | } |
1429 | | |
1430 | | // Prevent entry in the Pick-lists |
1431 | 0 | if ( rReq.IsAPI() ) |
1432 | 0 | GetMedium()->SetUpdatePickList( false ); |
1433 | | |
1434 | | // Ignore()-branches have already returned |
1435 | 0 | rReq.Done(); |
1436 | 0 | } |
1437 | | |
1438 | | |
1439 | | void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) |
1440 | 0 | { |
1441 | 0 | SfxWhichIter aIter( rSet ); |
1442 | |
|
1443 | 0 | for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() ) |
1444 | 0 | { |
1445 | 0 | switch ( nWhich ) |
1446 | 0 | { |
1447 | 0 | case SID_CHECKOUT: |
1448 | 0 | { |
1449 | 0 | bool bShow = false; |
1450 | 0 | Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY ); |
1451 | 0 | const uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties(); |
1452 | |
|
1453 | 0 | if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) ) |
1454 | 0 | { |
1455 | | // Loop over the CMIS Properties to find cmis:isVersionSeriesCheckedOut |
1456 | 0 | bool bIsGoogleFile = false; |
1457 | 0 | bool bCheckedOut = false; |
1458 | 0 | for ( const auto& rCmisProperty : aCmisProperties ) |
1459 | 0 | { |
1460 | 0 | if ( rCmisProperty.Id == "cmis:isVersionSeriesCheckedOut" ) |
1461 | 0 | { |
1462 | 0 | uno::Sequence< sal_Bool > bTmp; |
1463 | 0 | rCmisProperty.Value >>= bTmp; |
1464 | 0 | bCheckedOut = bTmp[0]; |
1465 | 0 | } |
1466 | | // using title to know if it's a Google Drive file |
1467 | | // maybe there's a safer way. |
1468 | 0 | if ( rCmisProperty.Name == "title" ) |
1469 | 0 | bIsGoogleFile = true; |
1470 | 0 | } |
1471 | 0 | bShow = !bCheckedOut && !bIsGoogleFile; |
1472 | 0 | } |
1473 | |
|
1474 | 0 | if ( !bShow ) |
1475 | 0 | { |
1476 | 0 | rSet.DisableItem( nWhich ); |
1477 | 0 | rSet.Put( SfxVisibilityItem( nWhich, false ) ); |
1478 | 0 | } |
1479 | 0 | } |
1480 | 0 | break; |
1481 | | |
1482 | 0 | case SID_CANCELCHECKOUT: |
1483 | 0 | case SID_CHECKIN: |
1484 | 0 | { |
1485 | 0 | bool bShow = false; |
1486 | 0 | Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY ); |
1487 | 0 | const uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties( ); |
1488 | |
|
1489 | 0 | if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) ) |
1490 | 0 | { |
1491 | | // Loop over the CMIS Properties to find cmis:isVersionSeriesCheckedOut |
1492 | 0 | bool bCheckedOut = false; |
1493 | 0 | auto pProp = std::find_if(aCmisProperties.begin(), aCmisProperties.end(), |
1494 | 0 | [](const document::CmisProperty& rProp) { return rProp.Id == "cmis:isVersionSeriesCheckedOut"; }); |
1495 | 0 | if (pProp != aCmisProperties.end()) |
1496 | 0 | { |
1497 | 0 | uno::Sequence< sal_Bool > bTmp; |
1498 | 0 | pProp->Value >>= bTmp; |
1499 | 0 | bCheckedOut = bTmp[0]; |
1500 | 0 | } |
1501 | 0 | bShow = bCheckedOut; |
1502 | 0 | } |
1503 | |
|
1504 | 0 | if ( !bShow ) |
1505 | 0 | { |
1506 | 0 | rSet.DisableItem( nWhich ); |
1507 | 0 | rSet.Put( SfxVisibilityItem( nWhich, false ) ); |
1508 | 0 | } |
1509 | 0 | } |
1510 | 0 | break; |
1511 | | |
1512 | 0 | case SID_VERSION: |
1513 | 0 | { |
1514 | 0 | SfxObjectShell *pDoc = this; |
1515 | 0 | SfxViewFrame* pFrame = GetFrame(); |
1516 | 0 | if ( !pFrame ) |
1517 | 0 | pFrame = SfxViewFrame::GetFirst( this ); |
1518 | |
|
1519 | 0 | if ( !pFrame || !pDoc->HasName() || |
1520 | 0 | !IsOwnStorageFormat( *pDoc->GetMedium() ) ) |
1521 | 0 | rSet.DisableItem( nWhich ); |
1522 | 0 | break; |
1523 | 0 | } |
1524 | 0 | case SID_SAVEDOC: |
1525 | 0 | { |
1526 | 0 | if ( IsReadOnly() || isSaveLocked()) |
1527 | 0 | { |
1528 | 0 | rSet.DisableItem(nWhich); |
1529 | 0 | break; |
1530 | 0 | } |
1531 | 0 | rSet.Put(SfxStringItem(nWhich, SfxResId(STR_SAVEDOC))); |
1532 | 0 | } |
1533 | 0 | break; |
1534 | | |
1535 | 0 | case SID_DOCINFO: |
1536 | 0 | break; |
1537 | | |
1538 | 0 | case SID_CLOSEDOC: |
1539 | 0 | { |
1540 | 0 | rSet.Put(SfxStringItem(nWhich, SfxResId(STR_CLOSEDOC))); |
1541 | 0 | break; |
1542 | 0 | } |
1543 | | |
1544 | 0 | case SID_SAVEASDOC: |
1545 | 0 | { |
1546 | 0 | if (!(pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT) |
1547 | 0 | || isExportLocked()) |
1548 | 0 | { |
1549 | 0 | rSet.DisableItem( nWhich ); |
1550 | 0 | break; |
1551 | 0 | } |
1552 | 0 | if ( /*!pCombinedFilters ||*/ !GetMedium() ) |
1553 | 0 | rSet.DisableItem( nWhich ); |
1554 | 0 | else |
1555 | 0 | rSet.Put( SfxStringItem( nWhich, SfxResId(STR_SAVEASDOC) ) ); |
1556 | 0 | break; |
1557 | 0 | } |
1558 | | |
1559 | 0 | case SID_SAVEACOPY: |
1560 | 0 | { |
1561 | 0 | if (!(pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT) || isExportLocked()) |
1562 | 0 | { |
1563 | 0 | rSet.DisableItem( nWhich ); |
1564 | 0 | break; |
1565 | 0 | } |
1566 | 0 | if ( /*!pCombinedFilters ||*/ !GetMedium() ) |
1567 | 0 | rSet.DisableItem( nWhich ); |
1568 | 0 | else |
1569 | 0 | rSet.Put( SfxStringItem( nWhich, SfxResId(STR_SAVEACOPY) ) ); |
1570 | 0 | break; |
1571 | 0 | } |
1572 | | |
1573 | 0 | case SID_DOCTEMPLATE: |
1574 | 0 | case SID_EXPORTDOC: |
1575 | 0 | case SID_EXPORTDOCASPDF: |
1576 | 0 | case SID_DIRECTEXPORTDOCASPDF: |
1577 | 0 | case SID_EXPORTDOCASEPUB: |
1578 | 0 | case SID_DIRECTEXPORTDOCASEPUB: |
1579 | 0 | case SID_REDACTDOC: |
1580 | 0 | case SID_AUTOREDACTDOC: |
1581 | 0 | case SID_SAVEASREMOTE: |
1582 | 0 | { |
1583 | 0 | if (isExportLocked()) |
1584 | 0 | rSet.DisableItem( nWhich ); |
1585 | 0 | break; |
1586 | 0 | } |
1587 | | |
1588 | 0 | case SID_DOC_MODIFIED: |
1589 | 0 | { |
1590 | 0 | rSet.Put( SfxBoolItem( SID_DOC_MODIFIED, IsModified() ) ); |
1591 | 0 | break; |
1592 | 0 | } |
1593 | | |
1594 | 0 | case SID_MODIFIED: |
1595 | 0 | { |
1596 | 0 | rSet.Put( SfxBoolItem( SID_MODIFIED, IsModified() ) ); |
1597 | 0 | break; |
1598 | 0 | } |
1599 | | |
1600 | 0 | case SID_DOCINFO_TITLE: |
1601 | 0 | { |
1602 | 0 | rSet.Put( SfxStringItem( |
1603 | 0 | SID_DOCINFO_TITLE, getDocProperties()->getTitle() ) ); |
1604 | 0 | break; |
1605 | 0 | } |
1606 | 0 | case SID_FILE_NAME: |
1607 | 0 | { |
1608 | 0 | if( GetMedium() && HasName() ) |
1609 | 0 | rSet.Put( SfxStringItem( |
1610 | 0 | SID_FILE_NAME, GetMedium()->GetName() ) ); |
1611 | 0 | break; |
1612 | 0 | } |
1613 | 0 | case SID_SIGNATURE: |
1614 | 0 | { |
1615 | 0 | SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this); |
1616 | 0 | if ( pFrame ) |
1617 | 0 | { |
1618 | 0 | SignatureState eState = GetDocumentSignatureState(); |
1619 | 0 | InfobarType aInfobarType(InfobarType::INFO); |
1620 | 0 | OUString sMessage(u""_ustr); |
1621 | |
|
1622 | 0 | switch (eState) |
1623 | 0 | { |
1624 | 0 | case SignatureState::BROKEN: |
1625 | 0 | sMessage = SfxResId(STR_SIGNATURE_BROKEN); |
1626 | 0 | aInfobarType = InfobarType::DANGER; |
1627 | 0 | break; |
1628 | 0 | case SignatureState::INVALID: |
1629 | | // If we are remembering the certificates, it should be kept as valid |
1630 | 0 | sMessage = SfxResId(bRememberSignature ? STR_SIGNATURE_OK : STR_SIGNATURE_INVALID); |
1631 | | // Warning only, I've tried Danger and it looked too scary |
1632 | 0 | aInfobarType = ( bRememberSignature ? InfobarType::INFO : InfobarType::WARNING ); |
1633 | 0 | break; |
1634 | 0 | case SignatureState::NOTVALIDATED: |
1635 | 0 | sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); |
1636 | 0 | aInfobarType = InfobarType::WARNING; |
1637 | 0 | break; |
1638 | 0 | case SignatureState::PARTIAL_OK: |
1639 | 0 | sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); |
1640 | 0 | aInfobarType = InfobarType::WARNING; |
1641 | 0 | break; |
1642 | 0 | case SignatureState::OK: |
1643 | 0 | sMessage = SfxResId(STR_SIGNATURE_OK); |
1644 | 0 | aInfobarType = InfobarType::INFO; |
1645 | 0 | break; |
1646 | 0 | case SignatureState::NOTVALIDATED_PARTIAL_OK: |
1647 | 0 | sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK); |
1648 | 0 | aInfobarType = InfobarType::WARNING; |
1649 | 0 | break; |
1650 | | //FIXME SignatureState::Unknown, own message? |
1651 | 0 | default: |
1652 | 0 | break; |
1653 | 0 | } |
1654 | | |
1655 | | // new info bar |
1656 | 0 | if ( !pFrame->HasInfoBarWithID(u"signature") ) |
1657 | 0 | { |
1658 | 0 | if ( !sMessage.isEmpty() ) |
1659 | 0 | { |
1660 | 0 | auto pInfoBar = pFrame->AppendInfoBar(u"signature"_ustr, u""_ustr, sMessage, aInfobarType); |
1661 | 0 | if (pInfoBar == nullptr || pInfoBar->isDisposed()) |
1662 | 0 | return; |
1663 | 0 | weld::Button& rBtn = pInfoBar->addButton(); |
1664 | 0 | rBtn.set_label(SfxResId(STR_SIGNATURE_SHOW)); |
1665 | 0 | rBtn.connect_clicked(LINK(this, SfxObjectShell, SignDocumentHandler)); |
1666 | 0 | } |
1667 | 0 | } |
1668 | 0 | else // info bar exists already |
1669 | 0 | { |
1670 | 0 | if ( eState == SignatureState::NOSIGNATURES ) |
1671 | 0 | pFrame->RemoveInfoBar(u"signature"); |
1672 | 0 | else |
1673 | 0 | pFrame->UpdateInfoBar(u"signature", u""_ustr, sMessage, aInfobarType); |
1674 | 0 | } |
1675 | 0 | } |
1676 | | |
1677 | 0 | rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(GetDocumentSignatureState()) ) ); |
1678 | 0 | break; |
1679 | 0 | } |
1680 | 0 | case SID_MACRO_SIGNATURE: |
1681 | 0 | { |
1682 | | // the slot makes sense only if there is a macro in the document |
1683 | 0 | if ( pImpl->documentStorageHasMacros() || pImpl->aMacroMode.hasMacroLibrary() ) |
1684 | 0 | rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, static_cast<sal_uInt16>(GetScriptingSignatureState()) ) ); |
1685 | 0 | else |
1686 | 0 | rSet.DisableItem( nWhich ); |
1687 | 0 | break; |
1688 | 0 | } |
1689 | 0 | case SID_DOC_REPAIR: |
1690 | 0 | { |
1691 | 0 | SfxUndoManager* pIUndoMgr = GetUndoManager(); |
1692 | 0 | if (pIUndoMgr) |
1693 | 0 | rSet.Put( SfxBoolItem(nWhich, pIUndoMgr->IsEmptyActions()) ); |
1694 | 0 | else |
1695 | 0 | rSet.DisableItem( nWhich ); |
1696 | 0 | break; |
1697 | 0 | } |
1698 | 0 | } |
1699 | 0 | } |
1700 | 0 | } |
1701 | | |
1702 | | IMPL_LINK_NOARG(SfxObjectShell, SignDocumentHandler, weld::Button&, void) |
1703 | 0 | { |
1704 | 0 | SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst(this); |
1705 | 0 | if (!pViewFrm) |
1706 | 0 | { |
1707 | 0 | SAL_WARN("sfx.appl", "There should be some SfxViewFrame associated here"); |
1708 | 0 | return; |
1709 | 0 | } |
1710 | 0 | SfxUnoFrameItem aDocFrame(SID_FILLFRAME, pViewFrm->GetFrame().GetFrameInterface()); |
1711 | 0 | pViewFrm->GetDispatcher()->ExecuteList(SID_SIGNATURE, SfxCallMode::SLOT, {}, { &aDocFrame }); |
1712 | 0 | } |
1713 | | |
1714 | | void SfxObjectShell::PerformLinkUpdate() |
1715 | 0 | { |
1716 | 0 | } |
1717 | | |
1718 | | void SfxObjectShell::CheckPendingLinkUpdateInfobar() |
1719 | 4.16k | { |
1720 | 4.16k | if (!bPendingLinkUpdateInfobar) |
1721 | 4.16k | return; |
1722 | 0 | bPendingLinkUpdateInfobar = false; |
1723 | 0 | ShowLinkUpdateInfobar(); |
1724 | 0 | } |
1725 | | |
1726 | | namespace |
1727 | | { |
1728 | | class LinkUpdateHelp |
1729 | | { |
1730 | | public: |
1731 | | DECL_STATIC_LINK(LinkUpdateHelp, DispatchHelpLinksHdl, weld::Button&, void); |
1732 | | }; |
1733 | | |
1734 | | IMPL_STATIC_LINK(LinkUpdateHelp, DispatchHelpLinksHdl, weld::Button&, rBtn, void) |
1735 | 0 | { |
1736 | 0 | if (Help* pHelp = Application::GetHelp()) |
1737 | 0 | pHelp->Start(u"cui/ui/baselinksdialog/UPDATE_NOW"_ustr, &rBtn); |
1738 | 0 | } |
1739 | | } |
1740 | | |
1741 | | void SfxObjectShell::ShowLinkUpdateInfobar() |
1742 | 0 | { |
1743 | 0 | SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(this); |
1744 | 0 | if (!pViewFrame) |
1745 | 0 | return; |
1746 | | |
1747 | 0 | pViewFrame->RemoveInfoBar(u"enablecontent"); |
1748 | 0 | auto pInfoBar = pViewFrame->AppendInfoBar( |
1749 | 0 | u"enablecontent"_ustr, SfxResId(RID_SECURITY_WARNING_TITLE), |
1750 | 0 | SfxResId(STR_INFOBAR_LINKS_DISABLED), InfobarType::WARNING); |
1751 | 0 | if (!pInfoBar) |
1752 | 0 | return; |
1753 | | |
1754 | 0 | weld::Button& rHelpBtn = pInfoBar->addButton(); |
1755 | 0 | rHelpBtn.set_label(GetStandardText(StandardButtonType::Help).replaceFirst("~", "")); |
1756 | 0 | rHelpBtn.connect_clicked(LINK(nullptr, LinkUpdateHelp, DispatchHelpLinksHdl)); |
1757 | |
|
1758 | 0 | weld::Button& rBtn = pInfoBar->addButton(); |
1759 | 0 | rBtn.set_label(SfxResId(STR_INFOBAR_ALLOW_UPDATING)); |
1760 | 0 | rBtn.set_tooltip_text(SfxResId(STR_INFOBAR_ALLOW_UPDATING_TOOLTIP)); |
1761 | 0 | rBtn.connect_clicked(LINK(this, SfxObjectShell, AllowLinksUpdateHdl)); |
1762 | |
|
1763 | 0 | if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()) |
1764 | 0 | { |
1765 | 0 | rBtn.set_tooltip_text(SfxResId(STR_INFOBAR_ALLOW_UPDATING_TOOLTIP_DISABLED)); |
1766 | 0 | rBtn.set_sensitive(false); |
1767 | 0 | } |
1768 | 0 | } |
1769 | | |
1770 | | IMPL_LINK_NOARG(SfxObjectShell, AllowLinksUpdateHdl, weld::Button&, void) |
1771 | 0 | { |
1772 | 0 | getEmbeddedObjectContainer().setUserAllowsLinkUpdate(true); |
1773 | 0 | PerformLinkUpdate(); |
1774 | 0 | SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(this); |
1775 | 0 | if (pViewFrame) |
1776 | 0 | pViewFrame->RemoveInfoBar(u"enablecontent"); |
1777 | 0 | } |
1778 | | |
1779 | | void SfxObjectShell::ExecProps_Impl(SfxRequest &rReq) |
1780 | 0 | { |
1781 | 0 | switch ( rReq.GetSlot() ) |
1782 | 0 | { |
1783 | 0 | case SID_MODIFIED: |
1784 | 0 | { |
1785 | 0 | SetModified( rReq.GetArgs()->Get(SID_MODIFIED).GetValue() ); |
1786 | 0 | rReq.Done(); |
1787 | 0 | break; |
1788 | 0 | } |
1789 | | |
1790 | 0 | case SID_DOCTITLE: |
1791 | 0 | SetTitle( rReq.GetArgs()->Get(SID_DOCTITLE).GetValue() ); |
1792 | 0 | rReq.Done(); |
1793 | 0 | break; |
1794 | | |
1795 | 0 | case SID_DOCINFO_AUTHOR : |
1796 | 0 | getDocProperties()->setAuthor( static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue() ); |
1797 | 0 | break; |
1798 | | |
1799 | 0 | case SID_DOCINFO_COMMENTS : |
1800 | 0 | getDocProperties()->setDescription( static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue() ); |
1801 | 0 | break; |
1802 | | |
1803 | 0 | case SID_DOCINFO_KEYWORDS : |
1804 | 0 | { |
1805 | 0 | const OUString aStr = static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue(); |
1806 | 0 | getDocProperties()->setKeywords( |
1807 | 0 | ::comphelper::string::convertCommaSeparated(aStr) ); |
1808 | 0 | break; |
1809 | 0 | } |
1810 | 0 | } |
1811 | 0 | } |
1812 | | |
1813 | | |
1814 | | void SfxObjectShell::StateProps_Impl(SfxItemSet &rSet) |
1815 | 0 | { |
1816 | 0 | SfxWhichIter aIter(rSet); |
1817 | 0 | for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() ) |
1818 | 0 | { |
1819 | 0 | switch ( nSID ) |
1820 | 0 | { |
1821 | 0 | case SID_DOCINFO_AUTHOR : |
1822 | 0 | { |
1823 | 0 | rSet.Put( SfxStringItem( nSID, |
1824 | 0 | getDocProperties()->getAuthor() ) ); |
1825 | 0 | break; |
1826 | 0 | } |
1827 | | |
1828 | 0 | case SID_DOCINFO_COMMENTS : |
1829 | 0 | { |
1830 | 0 | rSet.Put( SfxStringItem( nSID, |
1831 | 0 | getDocProperties()->getDescription()) ); |
1832 | 0 | break; |
1833 | 0 | } |
1834 | | |
1835 | 0 | case SID_DOCINFO_KEYWORDS : |
1836 | 0 | { |
1837 | 0 | rSet.Put( SfxStringItem( nSID, ::comphelper::string:: |
1838 | 0 | convertCommaSeparated(getDocProperties()->getKeywords())) ); |
1839 | 0 | break; |
1840 | 0 | } |
1841 | | |
1842 | 0 | case SID_DOCPATH: |
1843 | 0 | { |
1844 | 0 | OSL_FAIL( "Not supported anymore!" ); |
1845 | 0 | break; |
1846 | 0 | } |
1847 | | |
1848 | 0 | case SID_DOCFULLNAME: |
1849 | 0 | { |
1850 | 0 | rSet.Put( SfxStringItem( SID_DOCFULLNAME, GetTitle(SFX_TITLE_FULLNAME) ) ); |
1851 | 0 | break; |
1852 | 0 | } |
1853 | | |
1854 | 0 | case SID_DOCTITLE: |
1855 | 0 | { |
1856 | 0 | rSet.Put( SfxStringItem( SID_DOCTITLE, GetTitle() ) ); |
1857 | 0 | break; |
1858 | 0 | } |
1859 | | |
1860 | 0 | case SID_DOC_READONLY: |
1861 | 0 | { |
1862 | 0 | rSet.Put( SfxBoolItem( SID_DOC_READONLY, IsReadOnly() ) ); |
1863 | 0 | break; |
1864 | 0 | } |
1865 | | |
1866 | 0 | case SID_DOC_SAVED: |
1867 | 0 | { |
1868 | 0 | rSet.Put( SfxBoolItem( SID_DOC_SAVED, !IsModified() ) ); |
1869 | 0 | break; |
1870 | 0 | } |
1871 | | |
1872 | 0 | case SID_CLOSING: |
1873 | 0 | { |
1874 | 0 | rSet.Put( SfxBoolItem( SID_CLOSING, false ) ); |
1875 | 0 | break; |
1876 | 0 | } |
1877 | | |
1878 | 0 | case SID_DOC_LOADING: |
1879 | 0 | rSet.Put( SfxBoolItem( nSID, ! ( pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ) ) ); |
1880 | 0 | break; |
1881 | | |
1882 | 0 | case SID_IMG_LOADING: |
1883 | 0 | rSet.Put( SfxBoolItem( nSID, ! ( pImpl->nLoadedFlags & SfxLoadedFlags::IMAGES ) ) ); |
1884 | 0 | break; |
1885 | 0 | } |
1886 | 0 | } |
1887 | 0 | } |
1888 | | |
1889 | | |
1890 | | void SfxObjectShell::ExecView_Impl(SfxRequest &rReq) |
1891 | 0 | { |
1892 | 0 | switch ( rReq.GetSlot() ) |
1893 | 0 | { |
1894 | 0 | case SID_ACTIVATE: |
1895 | 0 | { |
1896 | 0 | SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this ); |
1897 | 0 | if ( pFrame ) |
1898 | 0 | pFrame->GetFrame().Appear(); |
1899 | 0 | rReq.SetReturnValue( SfxObjectItem( 0, pFrame ) ); |
1900 | 0 | rReq.Done(); |
1901 | 0 | break; |
1902 | 0 | } |
1903 | 0 | } |
1904 | 0 | } |
1905 | | |
1906 | | |
1907 | | void SfxObjectShell::StateView_Impl(SfxItemSet& /*rSet*/) |
1908 | 0 | { |
1909 | 0 | } |
1910 | | |
1911 | | /// Does this ZIP storage have a signature stream? |
1912 | | static bool HasSignatureStream(const uno::Reference<embed::XStorage>& xStorage) |
1913 | 0 | { |
1914 | 0 | if (!xStorage.is()) |
1915 | 0 | return false; |
1916 | | |
1917 | 0 | if (xStorage->hasByName(u"META-INF"_ustr)) |
1918 | 0 | { |
1919 | | // ODF case. |
1920 | 0 | try |
1921 | 0 | { |
1922 | 0 | uno::Reference<embed::XStorage> xMetaInf |
1923 | 0 | = xStorage->openStorageElement(u"META-INF"_ustr, embed::ElementModes::READ); |
1924 | 0 | if (xMetaInf.is()) |
1925 | 0 | { |
1926 | 0 | return xMetaInf->hasByName(u"documentsignatures.xml"_ustr) |
1927 | 0 | || xMetaInf->hasByName(u"macrosignatures.xml"_ustr) |
1928 | 0 | || xMetaInf->hasByName(u"packagesignatures.xml"_ustr); |
1929 | 0 | } |
1930 | 0 | } |
1931 | 0 | catch (const css::io::IOException&) |
1932 | 0 | { |
1933 | 0 | TOOLS_WARN_EXCEPTION("sfx.doc", "HasSignatureStream: failed to open META-INF"); |
1934 | 0 | } |
1935 | 0 | } |
1936 | | |
1937 | | // OOXML case. |
1938 | 0 | return xStorage->hasByName(u"_xmlsignatures"_ustr); |
1939 | 0 | } |
1940 | | |
1941 | | uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::GetDocumentSignatureInformation( bool bScriptingContent, const uno::Reference< security::XDocumentDigitalSignatures >& xSigner ) |
1942 | 8.32k | { |
1943 | 8.32k | uno::Sequence< security::DocumentSignatureInformation > aResult; |
1944 | 8.32k | uno::Reference< security::XDocumentDigitalSignatures > xLocSigner = xSigner; |
1945 | | |
1946 | 8.32k | bool bSupportsSigning = GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->GetSupportsSigning(); |
1947 | 8.32k | if (GetMedium() && !GetMedium()->GetName().isEmpty() && ((IsOwnStorageFormat(*GetMedium()) && GetMedium()->GetStorage().is()) || bSupportsSigning)) |
1948 | 0 | { |
1949 | 0 | try |
1950 | 0 | { |
1951 | 0 | if ( !xLocSigner.is() ) |
1952 | 0 | { |
1953 | 0 | OUString aVersion; |
1954 | 0 | try |
1955 | 0 | { |
1956 | 0 | uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY ); |
1957 | 0 | if (xPropSet) |
1958 | 0 | xPropSet->getPropertyValue(u"Version"_ustr) >>= aVersion; |
1959 | 0 | } |
1960 | 0 | catch( uno::Exception& ) |
1961 | 0 | { |
1962 | 0 | } |
1963 | |
|
1964 | 0 | xLocSigner.set( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) ); |
1965 | |
|
1966 | 0 | } |
1967 | |
|
1968 | 0 | if ( bScriptingContent ) |
1969 | 0 | { |
1970 | 0 | aResult = xLocSigner->verifyScriptingContentSignatures( |
1971 | 0 | GetMedium()->GetScriptingStorageToSign_Impl(), |
1972 | 0 | uno::Reference<io::XInputStream>()); |
1973 | 0 | } |
1974 | 0 | else |
1975 | 0 | { |
1976 | 0 | if (GetMedium()->GetStorage(false).is()) |
1977 | 0 | { |
1978 | | // Something ZIP-based. |
1979 | | // Only call into xmlsecurity if we see a signature stream, |
1980 | | // as libxmlsec init is expensive. |
1981 | 0 | if (HasSignatureStream(GetMedium()->GetZipStorageToSign_Impl())) |
1982 | 0 | aResult = xLocSigner->verifyDocumentContentSignatures( GetMedium()->GetZipStorageToSign_Impl(), |
1983 | 0 | uno::Reference< io::XInputStream >() ); |
1984 | 0 | } |
1985 | 0 | else |
1986 | 0 | { |
1987 | | // Not ZIP-based, e.g. PDF. |
1988 | | |
1989 | | // Create temp file if needed. |
1990 | 0 | GetMedium()->CreateTempFile(/*bReplace=*/false); |
1991 | |
|
1992 | 0 | std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ)); |
1993 | 0 | uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream)); |
1994 | 0 | uno::Reference<io::XInputStream> xInputStream(xStream, uno::UNO_QUERY); |
1995 | 0 | aResult = xLocSigner->verifyDocumentContentSignatures(uno::Reference<embed::XStorage>(), xInputStream); |
1996 | 0 | } |
1997 | 0 | } |
1998 | 0 | } |
1999 | 0 | catch( css::uno::Exception& ) |
2000 | 0 | { |
2001 | 0 | TOOLS_WARN_EXCEPTION("sfx.doc", "Failed to get document signature information"); |
2002 | 0 | } |
2003 | 0 | } |
2004 | | |
2005 | 8.32k | return aResult; |
2006 | 8.32k | } |
2007 | | |
2008 | | void SfxObjectShell::SetRememberCurrentSignature(bool bRemember) |
2009 | 0 | { |
2010 | 0 | if (bRemember) |
2011 | 0 | { |
2012 | 0 | rSignatureInfosRemembered = GetDocumentSignatureInformation(false); |
2013 | 0 | bRememberSignature = true; |
2014 | 0 | } |
2015 | 0 | else |
2016 | 0 | { |
2017 | 0 | rSignatureInfosRemembered = uno::Sequence<security::DocumentSignatureInformation>(); |
2018 | 0 | bRememberSignature = false; |
2019 | 0 | } |
2020 | 0 | } |
2021 | | |
2022 | | SignatureState SfxObjectShell::ImplGetSignatureState( bool bScriptingContent ) |
2023 | 12.4k | { |
2024 | 12.4k | SignatureState* pState = bScriptingContent ? &pImpl->nScriptingSignatureState : &pImpl->nDocumentSignatureState; |
2025 | | |
2026 | 12.4k | if ( *pState == SignatureState::UNKNOWN ) |
2027 | 8.32k | { |
2028 | 8.32k | *pState = SignatureState::NOSIGNATURES; |
2029 | | |
2030 | 8.32k | uno::Sequence< security::DocumentSignatureInformation > aInfos = GetDocumentSignatureInformation( bScriptingContent ); |
2031 | 8.32k | *pState = DocumentSignatures::getSignatureState(aInfos); |
2032 | | |
2033 | | // repaired package cannot be trusted |
2034 | 8.32k | if (*pState != SignatureState::NOSIGNATURES |
2035 | 0 | && GetMedium()->IsRepairPackage()) |
2036 | 0 | { |
2037 | 0 | *pState = SignatureState::BROKEN; |
2038 | 0 | } |
2039 | 8.32k | } |
2040 | | |
2041 | 12.4k | if ( *pState == SignatureState::OK || *pState == SignatureState::NOTVALIDATED |
2042 | 12.4k | || *pState == SignatureState::PARTIAL_OK) |
2043 | 0 | { |
2044 | 0 | if ( IsModified() ) |
2045 | 0 | *pState = SignatureState::INVALID; |
2046 | 0 | } |
2047 | | |
2048 | 12.4k | return *pState; |
2049 | 12.4k | } |
2050 | | |
2051 | | bool SfxObjectShell::PrepareForSigning(weld::Window* pDialogParent) |
2052 | 0 | { |
2053 | | // check whether the document is signed |
2054 | 0 | ImplGetSignatureState(); // document signature |
2055 | 0 | if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat()) |
2056 | 0 | ImplGetSignatureState( true ); // script signature |
2057 | 0 | bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES ); |
2058 | | |
2059 | | // the target ODF version on saving (only valid when signing ODF of course) |
2060 | 0 | SvtSaveOptions::ODFSaneDefaultVersion nVersion = GetODFSaneDefaultVersion(); |
2061 | | |
2062 | | // the document is not new and is not modified |
2063 | 0 | OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); |
2064 | |
|
2065 | 0 | if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() |
2066 | 0 | || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion.compareTo(ODFVER_012_TEXT) < 0 && !bHasSign)) |
2067 | 0 | { |
2068 | | // the document might need saving ( new, modified or in ODF1.1 format without signature ) |
2069 | |
|
2070 | 0 | if (nVersion >= SvtSaveOptions::ODFSVER_012) |
2071 | 0 | { |
2072 | 0 | OUString sQuestion(bHasSign ? SfxResId(STR_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN) : SfxResId(RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN)); |
2073 | 0 | std::unique_ptr<weld::MessageDialog> xQuestion; |
2074 | |
|
2075 | 0 | if (!bRememberSignature) |
2076 | 0 | { |
2077 | 0 | xQuestion = std::unique_ptr<weld::MessageDialog>(Application::CreateMessageDialog(pDialogParent, |
2078 | 0 | VclMessageType::Question, VclButtonsType::YesNo, sQuestion)); |
2079 | 0 | } |
2080 | |
|
2081 | 0 | if ( bRememberSignature || ( xQuestion != nullptr && xQuestion->run() == RET_YES ) ) |
2082 | 0 | { |
2083 | 0 | sal_uInt16 nId = SID_SAVEDOC; |
2084 | 0 | if ( !GetMedium() || GetMedium()->GetName().isEmpty() ) |
2085 | 0 | nId = SID_SAVEASDOC; |
2086 | 0 | SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() ); |
2087 | | //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. |
2088 | 0 | SetModified(); |
2089 | 0 | ExecFile_Impl( aSaveRequest ); |
2090 | | |
2091 | | // Check if it is stored a format which supports signing |
2092 | 0 | if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty() |
2093 | 0 | && ((!GetMedium()->GetFilter()->IsOwnFormat() |
2094 | 0 | && !GetMedium()->GetFilter()->GetSupportsSigning()) |
2095 | 0 | || (GetMedium()->GetFilter()->IsOwnFormat() |
2096 | 0 | && !GetMedium()->HasStorage_Impl()))) |
2097 | 0 | { |
2098 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( |
2099 | 0 | pDialogParent, VclMessageType::Info, VclButtonsType::Ok, |
2100 | 0 | SfxResId(STR_INFO_WRONGDOCFORMAT))); |
2101 | |
|
2102 | 0 | xBox->run(); |
2103 | 0 | return false; |
2104 | 0 | } |
2105 | 0 | } |
2106 | 0 | else |
2107 | 0 | { |
2108 | | // When the document is modified then we must not show the |
2109 | | // digital signatures dialog |
2110 | | // If we have come here then the user denied to save. |
2111 | 0 | if (!bHasSign) |
2112 | 0 | return false; |
2113 | 0 | } |
2114 | 0 | } |
2115 | 0 | else |
2116 | 0 | { |
2117 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pDialogParent, |
2118 | 0 | VclMessageType::Warning, VclButtonsType::Ok, SfxResId(STR_XMLSEC_ODF12_EXPECTED))); |
2119 | 0 | xBox->run(); |
2120 | 0 | return false; |
2121 | 0 | } |
2122 | | |
2123 | 0 | if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() ) |
2124 | 0 | return false; |
2125 | 0 | } |
2126 | | |
2127 | | // the document is not modified currently, so it can not become modified after signing |
2128 | 0 | pImpl->m_bAllowModifiedBackAfterSigning = false; |
2129 | 0 | if ( IsEnableSetModified() || /*bRememberSignature == */true ) |
2130 | 0 | { |
2131 | 0 | EnableSetModified( false ); |
2132 | 0 | pImpl->m_bAllowModifiedBackAfterSigning = true; |
2133 | 0 | } |
2134 | | |
2135 | | // we have to store to the original document, the original medium should be closed for this time |
2136 | 0 | if ( ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) ) |
2137 | 0 | { |
2138 | 0 | GetMedium()->CloseAndRelease(); |
2139 | 0 | return true; |
2140 | 0 | } |
2141 | 0 | return false; |
2142 | 0 | } |
2143 | | |
2144 | | void SfxObjectShell::RecheckSignature(bool bAlsoRecheckScriptingSignature) |
2145 | 0 | { |
2146 | 0 | if (bAlsoRecheckScriptingSignature) |
2147 | 0 | pImpl->nScriptingSignatureState = SignatureState::UNKNOWN; // Re-Check |
2148 | |
|
2149 | 0 | pImpl->nDocumentSignatureState = SignatureState::UNKNOWN; // Re-Check |
2150 | |
|
2151 | 0 | Invalidate(SID_SIGNATURE); |
2152 | 0 | Invalidate(SID_MACRO_SIGNATURE); |
2153 | 0 | Broadcast(SfxHint(SfxHintId::TitleChanged)); |
2154 | 0 | } |
2155 | | |
2156 | | void SfxObjectShell::AfterSigning(bool bSignSuccess, bool bSignScriptingContent) |
2157 | 0 | { |
2158 | 0 | pImpl->m_bSavingForSigning = true; |
2159 | 0 | DoSaveCompleted( GetMedium() ); |
2160 | 0 | pImpl->m_bSavingForSigning = false; |
2161 | |
|
2162 | 0 | if ( bSignSuccess ) |
2163 | 0 | RecheckSignature(bSignScriptingContent); |
2164 | |
|
2165 | 0 | if ( pImpl->m_bAllowModifiedBackAfterSigning || /* bRememberSignature ==*/ true ) |
2166 | 0 | EnableSetModified(); |
2167 | 0 | } |
2168 | | |
2169 | | bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent, weld::Window* pDialogParent) |
2170 | 0 | { |
2171 | 0 | if (GetMedium()->IsOriginallyReadOnly()) |
2172 | 0 | { |
2173 | | // If the file is physically read-only, we just show the existing signatures |
2174 | 0 | try |
2175 | 0 | { |
2176 | 0 | OUString aODFVersion( |
2177 | 0 | comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); |
2178 | 0 | uno::Reference<security::XDocumentDigitalSignatures> xSigner( |
2179 | 0 | security::DocumentDigitalSignatures::createWithVersionAndValidSignature( |
2180 | 0 | comphelper::getProcessComponentContext(), aODFVersion, HasValidSignatures())); |
2181 | |
|
2182 | 0 | if (pDialogParent) |
2183 | 0 | xSigner->setParentWindow(pDialogParent->GetXWindow()); |
2184 | |
|
2185 | 0 | if (bSignScriptingContent) |
2186 | 0 | xSigner->showScriptingContentSignatures(GetMedium()->GetScriptingStorageToSign_Impl(), |
2187 | 0 | uno::Reference<io::XInputStream>()); |
2188 | 0 | else |
2189 | 0 | { |
2190 | 0 | uno::Reference<embed::XStorage> xStorage = GetMedium()->GetZipStorageToSign_Impl(); |
2191 | 0 | if (xStorage.is()) |
2192 | 0 | xSigner->showDocumentContentSignatures(xStorage, |
2193 | 0 | uno::Reference<io::XInputStream>()); |
2194 | 0 | else |
2195 | 0 | { |
2196 | 0 | std::unique_ptr<SvStream> pStream( |
2197 | 0 | utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ)); |
2198 | |
|
2199 | 0 | if (!pStream) |
2200 | 0 | { |
2201 | 0 | pStream = utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ); |
2202 | |
|
2203 | 0 | if (!pStream) |
2204 | 0 | { |
2205 | 0 | SAL_WARN( "sfx.doc", "Couldn't use signing functionality!" ); |
2206 | 0 | return true; |
2207 | 0 | } |
2208 | 0 | } |
2209 | | |
2210 | 0 | uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(*pStream)); |
2211 | 0 | xSigner->showDocumentContentSignatures(uno::Reference<embed::XStorage>(), |
2212 | 0 | xStream); |
2213 | 0 | } |
2214 | 0 | } |
2215 | 0 | } |
2216 | 0 | catch (const uno::Exception&) |
2217 | 0 | { |
2218 | 0 | SAL_WARN("sfx.doc", "Couldn't use signing functionality!"); |
2219 | 0 | } |
2220 | 0 | return true; |
2221 | 0 | } |
2222 | 0 | return false; |
2223 | 0 | } |
2224 | | |
2225 | | bool SfxObjectShell::HasValidSignatures() const |
2226 | 4.16k | { |
2227 | 4.16k | return pImpl->nDocumentSignatureState == SignatureState::OK |
2228 | 4.16k | || pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED |
2229 | 4.16k | || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK; |
2230 | 4.16k | } |
2231 | | |
2232 | | SignatureState SfxObjectShell::GetDocumentSignatureState() |
2233 | 8.32k | { |
2234 | 8.32k | return ImplGetSignatureState(); |
2235 | 8.32k | } |
2236 | | |
2237 | | void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback) |
2238 | 0 | { |
2239 | 0 | if (!PrepareForSigning(pDialogParent)) |
2240 | 0 | { |
2241 | 0 | rCallback(false); |
2242 | 0 | return; |
2243 | 0 | } |
2244 | | |
2245 | 0 | if (CheckIsReadonly(false, pDialogParent)) |
2246 | 0 | { |
2247 | 0 | rCallback(false); |
2248 | 0 | return; |
2249 | 0 | } |
2250 | | |
2251 | 0 | SfxViewFrame* pFrame = GetFrame(); |
2252 | 0 | SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; |
2253 | | // Async, all code before the end has to go into the callback. |
2254 | 0 | GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures(), pViewShell, [this, rCallback](bool bSignSuccess) { |
2255 | 0 | AfterSigning(bSignSuccess, false); |
2256 | |
|
2257 | 0 | rCallback(bSignSuccess); |
2258 | 0 | }); |
2259 | 0 | } |
2260 | | |
2261 | | bool SfxObjectShell::ResignDocument(uno::Sequence< security::DocumentSignatureInformation >& rSignaturesInfo) |
2262 | 0 | { |
2263 | 0 | bool bSignSuccess = true; |
2264 | | |
2265 | | // This should be at most one element, automatic iteration to avoid pointing issues in case no signs |
2266 | 0 | for (auto & rInfo : rSignaturesInfo) |
2267 | 0 | { |
2268 | 0 | auto xCert = rInfo.Signer; |
2269 | 0 | if (xCert.is()) |
2270 | 0 | { |
2271 | 0 | svl::crypto::SigningContext aSigningContext; |
2272 | 0 | aSigningContext.m_xCertificate = std::move(xCert); |
2273 | 0 | bSignSuccess &= SignDocumentContentUsingCertificate(aSigningContext); |
2274 | 0 | } |
2275 | 0 | } |
2276 | |
|
2277 | 0 | return bSignSuccess; |
2278 | 0 | } |
2279 | | |
2280 | | bool SfxObjectShell::SignDocumentContentUsingCertificate(svl::crypto::SigningContext& rSigningContext) |
2281 | 0 | { |
2282 | | // 1. PrepareForSigning |
2283 | | |
2284 | | // check whether the document is signed |
2285 | 0 | ImplGetSignatureState(false); // document signature |
2286 | 0 | if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat()) |
2287 | 0 | ImplGetSignatureState( true ); // script signature |
2288 | 0 | bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES ); |
2289 | | |
2290 | | // the target ODF version on saving (only valid when signing ODF of course) |
2291 | 0 | SvtSaveOptions::ODFSaneDefaultVersion nVersion = GetODFSaneDefaultVersion(); |
2292 | | |
2293 | | // the document is not new and is not modified |
2294 | 0 | OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); |
2295 | |
|
2296 | 0 | if (IsModified() && IsSignPDF()) |
2297 | 0 | { |
2298 | | // When signing a PDF, then adding/resizing/moving the signature line would nominally modify |
2299 | | // the document, but ignore that for signing. |
2300 | 0 | SetModified(false); |
2301 | 0 | } |
2302 | |
|
2303 | 0 | if (IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() |
2304 | 0 | || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion.compareTo(ODFVER_012_TEXT) < 0 && !bHasSign)) |
2305 | 0 | { |
2306 | 0 | if (nVersion >= SvtSaveOptions::ODFSVER_012) |
2307 | 0 | { |
2308 | 0 | sal_uInt16 nId = SID_SAVEDOC; |
2309 | 0 | if ( !GetMedium() || GetMedium()->GetName().isEmpty() ) |
2310 | 0 | nId = SID_SAVEASDOC; |
2311 | 0 | SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() ); |
2312 | | //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. |
2313 | 0 | SetModified(); |
2314 | 0 | ExecFile_Impl( aSaveRequest ); |
2315 | | |
2316 | | // Check if it is stored a format which supports signing |
2317 | 0 | if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty() |
2318 | 0 | && ((!GetMedium()->GetFilter()->IsOwnFormat() |
2319 | 0 | && !GetMedium()->GetFilter()->GetSupportsSigning()) |
2320 | 0 | || (GetMedium()->GetFilter()->IsOwnFormat() |
2321 | 0 | && !GetMedium()->HasStorage_Impl()))) |
2322 | 0 | { |
2323 | 0 | return false; |
2324 | 0 | } |
2325 | 0 | } |
2326 | 0 | else |
2327 | 0 | { |
2328 | 0 | return false; |
2329 | 0 | } |
2330 | | |
2331 | 0 | if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() ) |
2332 | 0 | return false; |
2333 | 0 | } |
2334 | | |
2335 | | // the document is not modified currently, so it can not become modified after signing |
2336 | 0 | pImpl->m_bAllowModifiedBackAfterSigning = false; |
2337 | 0 | if ( IsEnableSetModified() ) |
2338 | 0 | { |
2339 | 0 | EnableSetModified( false ); |
2340 | 0 | pImpl->m_bAllowModifiedBackAfterSigning = true; |
2341 | 0 | } |
2342 | | |
2343 | | // we have to store to the original document, the original medium should be closed for this time |
2344 | 0 | bool bResult = ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium); |
2345 | |
|
2346 | 0 | if (!bResult) |
2347 | 0 | return false; |
2348 | | |
2349 | 0 | GetMedium()->CloseAndRelease(); |
2350 | | |
2351 | | // 2. Check Read-Only |
2352 | 0 | if (GetMedium()->IsOriginallyReadOnly()) |
2353 | 0 | return false; |
2354 | | |
2355 | | // 3. Sign |
2356 | 0 | bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate( |
2357 | 0 | GetBaseModel(), HasValidSignatures(), rSigningContext); |
2358 | | |
2359 | | // 4. AfterSigning |
2360 | 0 | AfterSigning(bSignSuccess, false); |
2361 | |
|
2362 | 0 | return true; |
2363 | 0 | } |
2364 | | |
2365 | | void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, |
2366 | | const OUString& aSignatureLineId, |
2367 | | const Reference<XCertificate>& xCert, |
2368 | | const Reference<XGraphic>& xValidGraphic, |
2369 | | const Reference<XGraphic>& xInvalidGraphic, |
2370 | | const OUString& aComment) |
2371 | 0 | { |
2372 | 0 | if (!PrepareForSigning(pDialogParent)) |
2373 | 0 | return; |
2374 | | |
2375 | 0 | if (CheckIsReadonly(false, pDialogParent)) |
2376 | 0 | return; |
2377 | | |
2378 | 0 | SfxViewFrame* pFrame = GetFrame(); |
2379 | 0 | SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; |
2380 | 0 | GetMedium()->SignContents_Impl(pDialogParent, |
2381 | 0 | false, HasValidSignatures(), pViewShell, [this, pFrame](bool bSignSuccess) { |
2382 | 0 | AfterSigning(bSignSuccess, false); |
2383 | | |
2384 | | // Reload the document to get the updated graphic |
2385 | | // FIXME: Update just the signature line graphic instead of reloading the document |
2386 | 0 | if (pFrame) |
2387 | 0 | pFrame->GetDispatcher()->Execute(SID_RELOAD); |
2388 | 0 | }, aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); |
2389 | 0 | } |
2390 | | |
2391 | | SignatureState SfxObjectShell::GetScriptingSignatureState() |
2392 | 4.16k | { |
2393 | 4.16k | return ImplGetSignatureState( true ); |
2394 | 4.16k | } |
2395 | | |
2396 | | void SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback) |
2397 | 0 | { |
2398 | 0 | if (!PrepareForSigning(pDialogParent)) |
2399 | 0 | { |
2400 | 0 | rCallback(false); |
2401 | 0 | return; |
2402 | 0 | } |
2403 | | |
2404 | 0 | if (CheckIsReadonly(true, pDialogParent)) |
2405 | 0 | { |
2406 | 0 | rCallback(false); |
2407 | 0 | return; |
2408 | 0 | } |
2409 | | |
2410 | 0 | SfxViewFrame* pFrame = GetFrame(); |
2411 | 0 | SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; |
2412 | 0 | GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures(), pViewShell, [this, rCallback](bool bSignSuccess) { |
2413 | 0 | AfterSigning(bSignSuccess, true); |
2414 | |
|
2415 | 0 | rCallback(bSignSuccess); |
2416 | 0 | }); |
2417 | 0 | } |
2418 | | |
2419 | | const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId() |
2420 | 74.7k | { |
2421 | 74.7k | static const comphelper::UnoIdInit theSfxObjectShellUnoTunnelId; |
2422 | 74.7k | return theSfxObjectShellUnoTunnelId.getSeq(); |
2423 | 74.7k | } |
2424 | | |
2425 | | uno::Sequence< beans::PropertyValue > SfxObjectShell::GetDocumentProtectionFromGrabBag() const |
2426 | 0 | { |
2427 | 0 | uno::Reference<frame::XModel> xModel = GetBaseModel(); |
2428 | |
|
2429 | 0 | if (!xModel.is()) |
2430 | 0 | { |
2431 | 0 | return uno::Sequence< beans::PropertyValue>(); |
2432 | 0 | } |
2433 | | |
2434 | 0 | uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW ); |
2435 | 0 | uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); |
2436 | 0 | const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; |
2437 | 0 | if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) ) |
2438 | 0 | { |
2439 | 0 | uno::Sequence< beans::PropertyValue > propList; |
2440 | 0 | xPropSet->getPropertyValue( aGrabBagName ) >>= propList; |
2441 | 0 | for (const auto& rProp : propList) |
2442 | 0 | { |
2443 | 0 | if (rProp.Name == "DocumentProtection") |
2444 | 0 | { |
2445 | 0 | uno::Sequence< beans::PropertyValue > rAttributeList; |
2446 | 0 | rProp.Value >>= rAttributeList; |
2447 | 0 | return rAttributeList; |
2448 | 0 | } |
2449 | 0 | } |
2450 | 0 | } |
2451 | | |
2452 | 0 | return uno::Sequence< beans::PropertyValue>(); |
2453 | 0 | } |
2454 | | |
2455 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |