build fix
[LibreOffice.git] / include / sfx2 / docfile.hxx
blob6df519c2c625c870a9e190dc40bfcf4c97a6f6c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <com/sun/star/io/XSeekable.hpp>
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 <com/sun/star/util/RevisionTag.hpp>
30 #include <com/sun/star/util/DateTime.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/ucb/XContent.hpp>
36 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
37 #include <com/sun/star/task/XInteractionHandler.hpp>
38 #include <com/sun/star/embed/XStorage.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <cppuhelper/weak.hxx>
41 #include <rtl/ustring.hxx>
42 #include <svl/lstner.hxx>
43 #include <tools/link.hxx>
44 #include <tools/stream.hxx>
45 #include <ucbhelper/content.hxx>
47 class SvKeyValueIterator;
48 class SfxObjectFactory;
49 class SfxFilter;
50 class SfxMedium_Impl;
51 class INetURLObject;
52 class SfxObjectShell;
53 class SfxFrame;
54 class Timer;
55 class SfxItemSet;
56 class DateTime;
58 class SFX2_DLLPUBLIC SfxMedium : public SvRefBase
60 std::unique_ptr< SfxMedium_Impl > pImpl;
62 SAL_DLLPRIVATE void SetIsRemote_Impl();
63 SAL_DLLPRIVATE void CloseInStream_Impl();
64 SAL_DLLPRIVATE void CloseOutStream_Impl();
65 SAL_DLLPRIVATE void CloseStreams_Impl();
67 SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl();
69 public:
71 SfxMedium();
72 /**
73 * @param pSet Takes ownership
75 SfxMedium( const OUString &rName,
76 StreamMode nOpenMode,
77 std::shared_ptr<const SfxFilter> pFilter = nullptr,
78 SfxItemSet *pSet = nullptr );
79 /**
80 * @param pSet Takes ownership
82 SfxMedium( const OUString &rName,
83 const OUString &rReferer,
84 StreamMode nOpenMode,
85 std::shared_ptr<const SfxFilter> pFilter = nullptr,
86 SfxItemSet *pSet = nullptr );
88 /**
89 * @param pSet does NOT take ownership
91 SfxMedium( const css::uno::Reference< css::embed::XStorage >& xStorage,
92 const OUString& rBaseURL,
93 const SfxItemSet* pSet=nullptr );
94 /**
95 * @param pSet does NOT take ownership
97 SfxMedium( const css::uno::Reference< css::embed::XStorage >& xStorage,
98 const OUString& rBaseURL,
99 const OUString& rTypeName,
100 const SfxItemSet* pSet=nullptr );
101 SfxMedium( const css::uno::Sequence< css::beans::PropertyValue >& aArgs );
103 virtual ~SfxMedium() override;
105 void UseInteractionHandler( bool );
106 css::uno::Reference< css::task::XInteractionHandler >
107 GetInteractionHandler( bool bGetAlways = false );
109 void setStreamToLoadFrom(
110 const css::uno::Reference<css::io::XInputStream>& xInputStream,
111 bool bIsReadOnly);
113 void SetLoadTargetFrame(SfxFrame* pFrame );
114 SfxFrame* GetLoadTargetFrame() const;
117 * Does not take ownership of pFlt but pFlt needs to be around as long as the SfxMedium instance.
119 void SetFilter(const std::shared_ptr<const SfxFilter>& pFilter);
120 const std::shared_ptr<const SfxFilter>& GetFilter() const;
121 std::shared_ptr<const SfxFilter> const & GetOrigFilter() const;
122 const OUString& GetOrigURL() const;
124 SfxItemSet * GetItemSet() const;
125 void Close();
126 void CloseAndRelease();
127 void ReOpen();
128 void CompleteReOpen();
129 const OUString& GetName() const;
130 const INetURLObject& GetURLObject() const;
132 void CheckFileDate( const css::util::DateTime& aInitDate );
133 SAL_WARN_UNUSED_RESULT bool DocNeedsFileDateCheck() const;
134 css::util::DateTime GetInitFileDate( bool bIgnoreOldValue );
136 css::uno::Reference< css::ucb::XContent > GetContent() const;
137 const OUString& GetPhysicalName() const;
138 SAL_WARN_UNUSED_RESULT bool IsRemote() const;
139 SAL_WARN_UNUSED_RESULT bool IsOpen() const; // { return aStorage.Is() || pInStream; }
140 void Download( const Link<void*,void>& aLink = Link<void*,void>());
141 void SetDoneLink( const Link<void*,void>& rLink );
143 sal_uInt32 GetErrorCode() const;
144 sal_uInt32 GetError() const
145 { return ERRCODE_TOERROR(GetErrorCode()); }
146 sal_uInt32 GetLastStorageCreationState();
148 void SetError( sal_uInt32 nError, const OUString& aLogMessage );
150 void AddLog( const OUString& aMessage );
152 void CloseInStream();
153 bool CloseOutStream();
155 void CloseStorage();
157 StreamMode GetOpenMode() const;
158 void SetOpenMode( StreamMode nStorOpen, bool bDontClose = false );
160 SvStream* GetInStream();
161 SvStream* GetOutStream();
163 bool Commit();
164 bool IsStorage();
166 enum class LockFileResult
168 Failed,
169 FailedLockFile, // there was only lock file that prevented success - no syslock or IO error
170 Succeeded,
172 LockFileResult LockOrigFileOnDemand( bool bLoading, bool bNoUI, bool bTryIgnoreLockFile = false );
173 void DisableUnlockWebDAV( bool bDisableUnlockWebDAV = true );
174 void UnlockFile( bool bReleaseLockStream );
175 /// Lets Transfer_Impl() not fsync the output file.
176 void DisableFileSync(bool bDisableFileSync);
178 css::uno::Reference< css::embed::XStorage > GetStorage( bool bCreateTempIfNo = true );
179 css::uno::Reference< css::embed::XStorage > GetOutputStorage();
180 void ResetError();
181 SAL_WARN_UNUSED_RESULT bool IsExpired() const;
182 void SetName( const OUString& rName, bool bSetOrigURL = false );
184 const css::uno::Sequence < css::util::RevisionTag >&
185 GetVersionList( bool _bNoReload = false );
186 SAL_WARN_UNUSED_RESULT bool IsReadOnly() const;
188 // Whether the medium had originally been opened r/o (either because it is
189 // "physically" r/o, or because it was requested to be opended r/o,
190 // independent of later changes via SetOpenMode; used to keep track of the
191 // "true" state of the medium across toggles via SID_EDITDOC (which do
192 // change SetOpenMode):
193 SAL_WARN_UNUSED_RESULT bool IsOriginallyReadOnly() const;
195 // Whether the medium had originally been requested to be opened r/o,
196 // independent of later changes via SetOpenMode; used for SID_RELOAD:
197 SAL_WARN_UNUSED_RESULT bool IsOriginallyLoadedReadOnly() const;
199 css::uno::Reference< css::io::XInputStream > GetInputStream();
201 void CreateTempFile( bool bReplace = true );
202 void CreateTempFileNoCopy();
203 OUString SwitchDocumentToTempFile();
204 bool SwitchDocumentToFile( const OUString& aURL );
206 OUString GetBaseURL( bool bForSaving=false );
207 void SetInCheckIn( bool bInCheckIn );
208 bool IsInCheckIn( );
209 bool IsSkipImages( );
211 SAL_DLLPRIVATE bool HasStorage_Impl() const;
213 SAL_DLLPRIVATE void StorageBackup_Impl();
214 SAL_DLLPRIVATE OUString GetBackup_Impl();
216 SAL_DLLPRIVATE css::uno::Reference< css::embed::XStorage > GetZipStorageToSign_Impl( bool bReadOnly = true );
217 SAL_DLLPRIVATE void CloseZipStorage_Impl();
219 // the storage that will be returned by the medium on GetStorage request
220 SAL_DLLPRIVATE void SetStorage_Impl( const css::uno::Reference< css::embed::XStorage >& xNewStorage );
222 SAL_DLLPRIVATE void CloseAndReleaseStreams_Impl();
223 SAL_DLLPRIVATE void AddVersion_Impl( css::util::RevisionTag& rVersion );
224 SAL_DLLPRIVATE bool TransferVersionList_Impl( SfxMedium& rMedium );
225 SAL_DLLPRIVATE void SaveVersionList_Impl();
226 SAL_DLLPRIVATE void RemoveVersion_Impl( const OUString& rVersion );
228 SAL_DLLPRIVATE void SetExpired_Impl( const DateTime& rDateTime );
229 SAL_DLLPRIVATE SvKeyValueIterator* GetHeaderAttributes_Impl();
231 SAL_DLLPRIVATE void Init_Impl();
233 SAL_DLLPRIVATE void GetLockingStream_Impl();
234 SAL_DLLPRIVATE void GetMedium_Impl();
235 SAL_DLLPRIVATE bool TryDirectTransfer( const OUString& aURL, SfxItemSet& aTargetSet );
236 SAL_DLLPRIVATE void Transfer_Impl();
237 SAL_DLLPRIVATE void CreateFileStream();
238 SAL_DLLPRIVATE void SetUpdatePickList(bool);
239 SAL_DLLPRIVATE bool IsUpdatePickList() const;
241 SAL_DLLPRIVATE void SetLongName(const OUString &rName);
242 SAL_DLLPRIVATE const OUString & GetLongName() const;
243 SAL_DLLPRIVATE bool IsPreview_Impl();
244 SAL_DLLPRIVATE void ClearBackup_Impl();
245 SAL_DLLPRIVATE void SetPhysicalName_Impl(const OUString& rName);
246 SAL_DLLPRIVATE void CanDisposeStorage_Impl( bool bDisposeStorage );
247 SAL_DLLPRIVATE bool WillDisposeStorageOnClose_Impl();
249 SAL_DLLPRIVATE void DoBackup_Impl();
250 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent );
251 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent,
252 const OUString& aPrefix,
253 const OUString& aExtension,
254 const OUString& aDestDir );
256 SAL_DLLPRIVATE bool UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent,
257 const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
259 SAL_DLLPRIVATE bool StorageCommit_Impl();
261 SAL_DLLPRIVATE void TransactedTransferForFS_Impl( const INetURLObject& aSource,
262 const INetURLObject& aDest,
263 const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
265 SAL_DLLPRIVATE bool SignContents_Impl( bool bScriptingContent, const OUString& aODFVersion, bool bHasValidDocumentSignature );
267 // the following two methods must be used and make sense only during saving currently
268 // TODO/LATER: in future the signature state should be controlled by the medium not by the document
269 // in this case the methods will be used generally, and might need to be renamed
270 SAL_DLLPRIVATE SignatureState GetCachedSignatureState_Impl();
271 SAL_DLLPRIVATE void SetCachedSignatureState_Impl( SignatureState nState );
273 static css::uno::Sequence < css::util::RevisionTag > GetVersionList(
274 const css::uno::Reference< css::embed::XStorage >& xStorage );
275 static OUString CreateTempCopyWithExt( const OUString& aURL );
276 static bool CallApproveHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler, const css::uno::Any& rRequest, bool bAllowAbort);
278 static bool SetWritableForUserOnly( const OUString& aURL );
279 static sal_uInt32 CreatePasswordToModifyHash( const OUString& aPasswd, bool bWriter );
281 private:
282 enum class ShowLockResult { NoLock, Succeeded, Try };
283 ShowLockResult ShowLockedDocumentDialog(const LockFileEntry& aData, bool bIsLoading, bool bOwnLock, bool bHandleSysLocked);
284 enum class MessageDlg { LockFileIgnore, LockFileCorrupt };
285 bool ShowLockFileProblemDialog(MessageDlg nWhichDlg);
289 #endif
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */