1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SFX2_DOCFILE_HXX
21 #define INCLUDED_SFX2_DOCFILE_HXX
24 #include <sal/config.h>
25 #include <sfx2/dllapi.h>
26 #include <sfx2/signaturestate.hxx>
27 #include <svl/lockfilecommon.hxx>
28 #include <sal/types.h>
29 #include <rtl/ustring.hxx>
30 #include <svl/itemset.hxx>
31 #include <tools/link.hxx>
32 #include <tools/stream.hxx>
35 namespace com::sun::star::beans
{ struct PropertyValue
; }
36 namespace com::sun::star::embed
{ class XStorage
; }
37 namespace com::sun::star::graphic
{ class XGraphic
; }
38 namespace com::sun::star::io
{ class XInputStream
; }
39 namespace com::sun::star::security
{ class XCertificate
; }
40 namespace com::sun::star::task
{ class XInteractionHandler
; }
41 namespace com::sun::star::ucb
{ class XCommandEnvironment
; }
42 namespace com::sun::star::ucb
{ class XContent
; }
43 namespace com::sun::star::util
{ struct DateTime
; }
44 namespace com::sun::star::util
{ struct RevisionTag
; }
45 namespace com::sun::star::frame
49 namespace ucbhelper
{ class Content
; }
51 class SvKeyValueIterator
;
64 class SFX2_DLLPUBLIC SfxMedium final
: public SvRefBase
66 std::unique_ptr
< SfxMedium_Impl
> pImpl
;
68 SAL_DLLPRIVATE
void SetIsRemote_Impl();
69 SAL_DLLPRIVATE
void CloseInStream_Impl(bool bInDestruction
= false);
70 SAL_DLLPRIVATE
void CloseOutStream_Impl();
71 SAL_DLLPRIVATE
void CloseStreams_Impl(bool bInDestruction
= false);
73 SAL_DLLPRIVATE
bool SetEncryptionDataToStorage_Impl();
78 SfxMedium( const OUString
&rName
,
80 std::shared_ptr
<const SfxFilter
> pFilter
= nullptr,
81 const std::shared_ptr
<SfxItemSet
>& pSet
= nullptr );
82 SfxMedium( const OUString
&rName
,
83 const OUString
&rReferer
,
85 std::shared_ptr
<const SfxFilter
> pFilter
= nullptr,
86 const std::shared_ptr
<SfxItemSet
>& pSet
= nullptr );
87 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
88 const OUString
& rBaseURL
,
89 const std::shared_ptr
<SfxItemSet
>& pSet
= nullptr );
90 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
91 const OUString
& rBaseURL
,
92 const OUString
& rTypeName
,
93 const std::shared_ptr
<SfxItemSet
>& pSet
= nullptr );
94 SfxMedium( const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
);
96 virtual ~SfxMedium() override
;
98 DECL_DLLPRIVATE_STATIC_LINK(SfxMedium
, ShowReloadEditableDialog
, void*, void);
99 bool CheckCanGetLockfile() const;
100 void SetOriginallyReadOnly(bool val
);
101 void AddToCheckEditableWorkerList();
102 void SetWorkerReloadEvent(ImplSVEvent
* pEvent
);
103 ImplSVEvent
* GetWorkerReloadEvent() const;
104 const std::shared_ptr
<std::recursive_mutex
>& GetCheckEditableMutex() const;
105 void CancelCheckEditableEntry(bool bRemoveEvent
= true);
107 void UseInteractionHandler( bool );
108 css::uno::Reference
< css::task::XInteractionHandler
>
109 GetInteractionHandler( bool bGetAlways
= false );
111 void setStreamToLoadFrom(
112 const css::uno::Reference
<css::io::XInputStream
>& xInputStream
,
115 void SetLoadTargetFrame(SfxFrame
* pFrame
);
116 SfxFrame
* GetLoadTargetFrame() const;
119 * Does not take ownership of pFlt but pFlt needs to be around as long as the SfxMedium instance.
121 void SetFilter(const std::shared_ptr
<const SfxFilter
>& pFilter
);
122 const std::shared_ptr
<const SfxFilter
>& GetFilter() const;
123 const OUString
& GetOrigURL() const;
125 SfxItemSet
& GetItemSet() const;
126 void SetArgs(const css::uno::Sequence
<css::beans::PropertyValue
>& rArgs
);
127 const css::uno::Sequence
<css::beans::PropertyValue
> & GetArgs() const;
128 void Close(bool bInDestruction
= false);
129 void CloseAndRelease();
131 void CompleteReOpen();
132 const OUString
& GetName() const;
133 const INetURLObject
& GetURLObject() const;
135 void CheckFileDate( const css::util::DateTime
& aInitDate
);
136 [[nodiscard
]] bool DocNeedsFileDateCheck() const;
137 css::util::DateTime
const & GetInitFileDate( bool bIgnoreOldValue
);
139 css::uno::Reference
< css::ucb::XContent
> GetContent() const;
140 const OUString
& GetPhysicalName() const;
141 [[nodiscard
]] bool IsRemote() const;
142 [[nodiscard
]] bool IsOpen() const; // { return aStorage.Is() || pInStream; }
143 void Download( const Link
<void*,void>& aLink
= Link
<void*,void>());
144 void SetDoneLink( const Link
<void*,void>& rLink
);
146 ErrCodeMsg
GetErrorCode() const;
147 ErrCodeMsg
GetErrorIgnoreWarning() const
148 { return GetErrorCode().IgnoreWarning(); }
149 ErrCodeMsg
const & GetWarningError() const;
150 ErrCodeMsg
const & GetLastStorageCreationState() const;
152 void SetError(ErrCodeMsg nError
);
153 void SetWarningError(const ErrCodeMsg
& nWarningError
);
155 void CloseInStream();
156 void CloseOutStream();
160 StreamMode
GetOpenMode() const;
161 void SetOpenMode( StreamMode nStorOpen
, bool bDontClose
= false );
163 SvStream
* GetInStream();
164 SvStream
* GetOutStream();
169 enum class LockFileResult
172 FailedLockFile
, // there was only lock file that prevented success - no syslock or IO error
175 LockFileResult
LockOrigFileOnDemand(bool bLoading
, bool bNoUI
, bool bTryIgnoreLockFile
= false,
176 LockFileEntry
* pLockData
= nullptr);
177 void DisableUnlockWebDAV( bool bDisableUnlockWebDAV
= true );
178 void UnlockFile( bool bReleaseLockStream
);
179 /// Lets Transfer_Impl() not fsync the output file.
180 void DisableFileSync(bool bDisableFileSync
);
182 css::uno::Reference
< css::embed::XStorage
> GetStorage( bool bCreateTempFile
= true );
183 css::uno::Reference
< css::embed::XStorage
> GetOutputStorage();
185 [[nodiscard
]] bool IsExpired() const;
186 void SetName( const OUString
& rName
, bool bSetOrigURL
= false );
188 const css::uno::Sequence
< css::util::RevisionTag
>&
189 GetVersionList( bool _bNoReload
= false );
190 [[nodiscard
]] bool IsReadOnly() const;
192 // Whether the medium had originally been opened r/o (either because it is
193 // "physically" r/o, or because it was requested to be opened r/o,
194 // independent of later changes via SetOpenMode; used to keep track of the
195 // "true" state of the medium across toggles via SID_EDITDOC (which do
196 // change SetOpenMode):
197 [[nodiscard
]] bool IsOriginallyReadOnly() const;
199 // Whether the medium had originally been requested to be opened r/o,
200 // independent of later changes via SetOpenMode; used for SID_RELOAD:
201 [[nodiscard
]] bool IsOriginallyLoadedReadOnly() const;
203 [[nodiscard
]] bool IsRepairPackage() const;
205 css::uno::Reference
< css::io::XInputStream
> const & GetInputStream();
207 void CreateTempFile( bool bReplace
= true );
208 void CreateTempFileNoCopy();
209 OUString
SwitchDocumentToTempFile();
210 bool SwitchDocumentToFile( const OUString
& aURL
);
212 OUString
GetBaseURL( bool bForSaving
=false );
213 void SetInCheckIn( bool bInCheckIn
);
214 bool IsInCheckIn( ) const;
215 bool IsSkipImages( ) const;
217 SAL_DLLPRIVATE
bool HasStorage_Impl() const;
219 SAL_DLLPRIVATE
void StorageBackup_Impl();
220 SAL_DLLPRIVATE OUString
const & GetBackup_Impl();
222 SAL_DLLPRIVATE
css::uno::Reference
< css::embed::XStorage
> const & GetZipStorageToSign_Impl( bool bReadOnly
= true );
223 SAL_DLLPRIVATE
css::uno::Reference
<css::embed::XStorage
> GetScriptingStorageToSign_Impl();
224 SAL_DLLPRIVATE
void CloseZipStorage_Impl();
226 // the storage that will be returned by the medium on GetStorage request
227 SAL_DLLPRIVATE
void SetStorage_Impl( const css::uno::Reference
< css::embed::XStorage
>& xNewStorage
);
228 SAL_DLLPRIVATE
void SetInnerStorage_Impl(const css::uno::Reference
<css::embed::XStorage
>& xStorage
);
229 SAL_DLLPRIVATE
css::uno::Reference
<css::embed::XStorage
>
230 TryEncryptedInnerPackage(css::uno::Reference
<css::embed::XStorage
> xStorage
);
232 SAL_DLLPRIVATE
void CloseAndReleaseStreams_Impl();
233 SAL_DLLPRIVATE
void AddVersion_Impl( css::util::RevisionTag
& rVersion
);
234 SAL_DLLPRIVATE
bool TransferVersionList_Impl( SfxMedium
const & rMedium
);
235 SAL_DLLPRIVATE
void SaveVersionList_Impl();
236 SAL_DLLPRIVATE
void RemoveVersion_Impl( const OUString
& rVersion
);
238 SAL_DLLPRIVATE
void SetExpired_Impl( const DateTime
& rDateTime
);
239 SAL_DLLPRIVATE SvKeyValueIterator
* GetHeaderAttributes_Impl();
241 SAL_DLLPRIVATE
void Init_Impl();
243 SAL_DLLPRIVATE
void GetLockingStream_Impl();
244 SAL_DLLPRIVATE
void GetMedium_Impl();
245 SAL_DLLPRIVATE
bool TryDirectTransfer( const OUString
& aURL
, SfxItemSet
const & aTargetSet
);
246 SAL_DLLPRIVATE
void Transfer_Impl();
247 SAL_DLLPRIVATE
void CreateFileStream();
248 SAL_DLLPRIVATE
void SetUpdatePickList(bool);
249 SAL_DLLPRIVATE
bool IsUpdatePickList() const;
251 SAL_DLLPRIVATE
void SetLongName(const OUString
&rName
);
252 SAL_DLLPRIVATE
const OUString
& GetLongName() const;
253 SAL_DLLPRIVATE
bool IsPreview_Impl() const;
254 SAL_DLLPRIVATE
void ClearBackup_Impl();
255 SAL_DLLPRIVATE
void SetPhysicalName_Impl(const OUString
& rName
);
256 SAL_DLLPRIVATE
void CanDisposeStorage_Impl( bool bDisposeStorage
);
257 SAL_DLLPRIVATE
bool WillDisposeStorageOnClose_Impl();
259 SAL_DLLPRIVATE
void DoBackup_Impl(bool bForceUsingBackupPath
);
260 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
);
261 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
,
262 std::u16string_view aPrefix
,
263 std::u16string_view aExtension
,
264 const OUString
& aDestDir
);
266 SAL_DLLPRIVATE
bool UseBackupToRestore_Impl( ::ucbhelper::Content
& aOriginalContent
,
267 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
269 SAL_DLLPRIVATE
bool StorageCommit_Impl();
271 SAL_DLLPRIVATE
void TransactedTransferForFS_Impl( const INetURLObject
& aSource
,
272 const INetURLObject
& aDest
,
273 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
276 SignContents_Impl(weld::Window
* pDialogParent
,
277 bool bSignScriptingContent
, bool bHasValidDocumentSignature
,
278 const OUString
& aSignatureLineId
= OUString(),
279 const css::uno::Reference
<css::security::XCertificate
>& xCert
280 = css::uno::Reference
<css::security::XCertificate
>(),
281 const css::uno::Reference
<css::graphic::XGraphic
>& xValidGraphic
282 = css::uno::Reference
<css::graphic::XGraphic
>(),
283 const css::uno::Reference
<css::graphic::XGraphic
>& xInvalidGraphic
284 = css::uno::Reference
<css::graphic::XGraphic
>(),
285 const OUString
& aComment
= OUString());
287 SAL_DLLPRIVATE
bool SignDocumentContentUsingCertificate(
288 const css::uno::Reference
<css::frame::XModel
>& xModel
, bool bHasValidDocumentSignature
,
289 const css::uno::Reference
<css::security::XCertificate
>& xCertificate
);
291 // the following two methods must be used and make sense only during saving currently
292 // TODO/LATER: in future the signature state should be controlled by the medium not by the document
293 // in this case the methods will be used generally, and might need to be renamed
294 SAL_DLLPRIVATE SignatureState
GetCachedSignatureState_Impl() const;
295 SAL_DLLPRIVATE
void SetCachedSignatureState_Impl( SignatureState nState
);
297 void SetHasEmbeddedObjects(bool bHasEmbeddedObjects
);
299 static css::uno::Sequence
< css::util::RevisionTag
> GetVersionList(
300 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
301 static OUString
CreateTempCopyWithExt( std::u16string_view aURL
);
302 static bool CallApproveHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
, const css::uno::Any
& rRequest
, bool bAllowAbort
);
304 static bool SetWritableForUserOnly( const OUString
& aURL
);
305 static sal_uInt32
CreatePasswordToModifyHash( std::u16string_view aPasswd
, bool bWriter
);
308 enum class ShowLockResult
{ NoLock
, Succeeded
, Try
};
309 ShowLockResult
ShowLockedDocumentDialog(const LockFileEntry
& aData
,
310 bool bIsLoading
, bool bOwnLock
, bool bHandleSysLocked
);
311 enum class MessageDlg
{ LockFileIgnore
, LockFileCorrupt
};
312 bool ShowLockFileProblemDialog(MessageDlg nWhichDlg
);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */