LibreOffice Module sfx2 (master) 1
docfile.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_SFX2_DOCFILE_HXX
21#define INCLUDED_SFX2_DOCFILE_HXX
22
23#include <memory>
24#include <sal/config.h>
25#include <sfx2/dllapi.h>
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>
33#include <mutex>
34
35namespace com::sun::star::beans { struct PropertyValue; }
36namespace com::sun::star::embed { class XStorage; }
37namespace com::sun::star::graphic { class XGraphic; }
38namespace com::sun::star::io { class XInputStream; }
39namespace com::sun::star::security { class XCertificate; }
41namespace com::sun::star::ucb { class XCommandEnvironment; }
42namespace com::sun::star::ucb { class XContent; }
43namespace com::sun::star::util { struct DateTime; }
44namespace com::sun::star::util { struct RevisionTag; }
46{
47class XModel;
48}
49namespace ucbhelper { class Content; }
50
52class SfxFilter;
53class SfxMedium_Impl;
54class INetURLObject;
55class SfxFrame;
56class DateTime;
57struct ImplSVEvent;
58
59namespace weld
60{
61 class Window;
62}
63
65{
66 std::unique_ptr< SfxMedium_Impl > pImpl;
67
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);
72
73 SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl();
74
75public:
76
77 SfxMedium();
78 SfxMedium( const OUString &rName,
79 StreamMode nOpenMode,
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,
84 StreamMode nOpenMode,
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 );
95
96 virtual ~SfxMedium() override;
97
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);
106
107 void UseInteractionHandler( bool );
108 css::uno::Reference< css::task::XInteractionHandler >
109 GetInteractionHandler( bool bGetAlways = false );
110
111 void setStreamToLoadFrom(
112 const css::uno::Reference<css::io::XInputStream>& xInputStream,
113 bool bIsReadOnly);
114
115 void SetLoadTargetFrame(SfxFrame* pFrame );
116 SfxFrame* GetLoadTargetFrame() const;
117
121 void SetFilter(const std::shared_ptr<const SfxFilter>& pFilter);
122 const std::shared_ptr<const SfxFilter>& GetFilter() const;
123 const OUString& GetOrigURL() const;
124
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();
130 void ReOpen();
131 void CompleteReOpen();
132 const OUString& GetName() const;
133 const INetURLObject& GetURLObject() const;
134
135 void CheckFileDate( const css::util::DateTime& aInitDate );
136 [[nodiscard]] bool DocNeedsFileDateCheck() const;
137 css::util::DateTime const & GetInitFileDate( bool bIgnoreOldValue );
138
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 );
145
146 ErrCode GetErrorCode() const;
148 { return GetErrorCode().IgnoreWarning(); }
149 ErrCode GetWarningError() const;
150 ErrCode const & GetLastStorageCreationState() const;
151
152 void SetError(ErrCode nError);
153 void SetWarningError(ErrCode nWarningError);
154
155 void CloseInStream();
156 void CloseOutStream();
157
158 void CloseStorage();
159
160 StreamMode GetOpenMode() const;
161 void SetOpenMode( StreamMode nStorOpen, bool bDontClose = false );
162
163 SvStream* GetInStream();
164 SvStream* GetOutStream();
165
166 bool Commit();
167 bool IsStorage();
168
169 enum class LockFileResult
170 {
171 Failed,
172 FailedLockFile, // there was only lock file that prevented success - no syslock or IO error
173 Succeeded,
174 };
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 );
180 void DisableFileSync(bool bDisableFileSync);
181
182 css::uno::Reference< css::embed::XStorage > GetStorage( bool bCreateTempFile = true );
183 css::uno::Reference< css::embed::XStorage > GetOutputStorage();
184 void ResetError();
185 [[nodiscard]] bool IsExpired() const;
186 void SetName( const OUString& rName, bool bSetOrigURL = false );
187
188 const css::uno::Sequence < css::util::RevisionTag >&
189 GetVersionList( bool _bNoReload = false );
190 [[nodiscard]] bool IsReadOnly() const;
191
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;
198
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;
202
203 css::uno::Reference< css::io::XInputStream > const & GetInputStream();
204
205 void CreateTempFile( bool bReplace = true );
206 void CreateTempFileNoCopy();
207 OUString SwitchDocumentToTempFile();
208 bool SwitchDocumentToFile( const OUString& aURL );
209
210 OUString GetBaseURL( bool bForSaving=false );
211 void SetInCheckIn( bool bInCheckIn );
212 bool IsInCheckIn( ) const;
213 bool IsSkipImages( ) const;
214
215 SAL_DLLPRIVATE bool HasStorage_Impl() const;
216
217 SAL_DLLPRIVATE void StorageBackup_Impl();
218 SAL_DLLPRIVATE OUString const & GetBackup_Impl();
219
220 SAL_DLLPRIVATE css::uno::Reference< css::embed::XStorage > const & GetZipStorageToSign_Impl( bool bReadOnly = true );
221 SAL_DLLPRIVATE void CloseZipStorage_Impl();
222
223 // the storage that will be returned by the medium on GetStorage request
224 SAL_DLLPRIVATE void SetStorage_Impl( const css::uno::Reference< css::embed::XStorage >& xNewStorage );
225
226 SAL_DLLPRIVATE void CloseAndReleaseStreams_Impl();
227 SAL_DLLPRIVATE void AddVersion_Impl( css::util::RevisionTag& rVersion );
228 SAL_DLLPRIVATE bool TransferVersionList_Impl( SfxMedium const & rMedium );
229 SAL_DLLPRIVATE void SaveVersionList_Impl();
230 SAL_DLLPRIVATE void RemoveVersion_Impl( const OUString& rVersion );
231
232 SAL_DLLPRIVATE void SetExpired_Impl( const DateTime& rDateTime );
233 SAL_DLLPRIVATE SvKeyValueIterator* GetHeaderAttributes_Impl();
234
235 SAL_DLLPRIVATE void Init_Impl();
236
237 SAL_DLLPRIVATE void GetLockingStream_Impl();
238 SAL_DLLPRIVATE void GetMedium_Impl();
239 SAL_DLLPRIVATE bool TryDirectTransfer( const OUString& aURL, SfxItemSet const & aTargetSet );
240 SAL_DLLPRIVATE void Transfer_Impl();
241 SAL_DLLPRIVATE void CreateFileStream();
242 SAL_DLLPRIVATE void SetUpdatePickList(bool);
243 SAL_DLLPRIVATE bool IsUpdatePickList() const;
244
245 SAL_DLLPRIVATE void SetLongName(const OUString &rName);
246 SAL_DLLPRIVATE const OUString & GetLongName() const;
247 SAL_DLLPRIVATE bool IsPreview_Impl() const;
248 SAL_DLLPRIVATE void ClearBackup_Impl();
249 SAL_DLLPRIVATE void SetPhysicalName_Impl(const OUString& rName);
250 SAL_DLLPRIVATE void CanDisposeStorage_Impl( bool bDisposeStorage );
251 SAL_DLLPRIVATE bool WillDisposeStorageOnClose_Impl();
252
253 SAL_DLLPRIVATE void DoBackup_Impl(bool bForceUsingBackupPath);
254 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent );
255 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent,
256 std::u16string_view aPrefix,
257 std::u16string_view aExtension,
258 const OUString& aDestDir );
259
260 SAL_DLLPRIVATE bool UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent,
261 const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
262
263 SAL_DLLPRIVATE bool StorageCommit_Impl();
264
265 SAL_DLLPRIVATE void TransactedTransferForFS_Impl( const INetURLObject& aSource,
266 const INetURLObject& aDest,
267 const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
268
269 SAL_DLLPRIVATE bool
270 SignContents_Impl(weld::Window* pDialogParent,
271 bool bSignScriptingContent, bool bHasValidDocumentSignature,
272 const OUString& aSignatureLineId = OUString(),
273 const css::uno::Reference<css::security::XCertificate>& xCert
274 = css::uno::Reference<css::security::XCertificate>(),
275 const css::uno::Reference<css::graphic::XGraphic>& xValidGraphic
276 = css::uno::Reference<css::graphic::XGraphic>(),
277 const css::uno::Reference<css::graphic::XGraphic>& xInvalidGraphic
278 = css::uno::Reference<css::graphic::XGraphic>(),
279 const OUString& aComment = OUString());
280
281 SAL_DLLPRIVATE bool SignDocumentContentUsingCertificate(
282 const css::uno::Reference<css::frame::XModel>& xModel, bool bHasValidDocumentSignature,
283 const css::uno::Reference<css::security::XCertificate>& xCertificate);
284
285 // the following two methods must be used and make sense only during saving currently
286 // TODO/LATER: in future the signature state should be controlled by the medium not by the document
287 // in this case the methods will be used generally, and might need to be renamed
288 SAL_DLLPRIVATE SignatureState GetCachedSignatureState_Impl() const;
289 SAL_DLLPRIVATE void SetCachedSignatureState_Impl( SignatureState nState );
290
291 void SetHasEmbeddedObjects(bool bHasEmbeddedObjects);
292
293 static css::uno::Sequence < css::util::RevisionTag > GetVersionList(
294 const css::uno::Reference< css::embed::XStorage >& xStorage );
295 static OUString CreateTempCopyWithExt( std::u16string_view aURL );
296 static bool CallApproveHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler, const css::uno::Any& rRequest, bool bAllowAbort);
297
298 static bool SetWritableForUserOnly( const OUString& aURL );
299 static sal_uInt32 CreatePasswordToModifyHash( std::u16string_view aPasswd, bool bWriter );
300
301private:
302 enum class ShowLockResult { NoLock, Succeeded, Try };
304 bool bIsLoading, bool bOwnLock, bool bHandleSysLocked);
305 enum class MessageDlg { LockFileIgnore, LockFileCorrupt };
307};
308
309#endif
310
311/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ErrCode IgnoreWarning() const
SfxMedium(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &rBaseURL, const std::shared_ptr< SfxItemSet > &pSet=nullptr)
bool ShowLockFileProblemDialog(MessageDlg nWhichDlg)
ErrCode GetError() const
Definition: docfile.hxx:147
std::unique_ptr< SfxMedium_Impl > pImpl
Definition: docfile.hxx:66
static css::uno::Sequence< css::util::RevisionTag > GetVersionList(const css::uno::Reference< css::embed::XStorage > &xStorage)
SfxMedium(const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
SfxMedium(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &rBaseURL, const OUString &rTypeName, const std::shared_ptr< SfxItemSet > &pSet=nullptr)
ShowLockResult ShowLockedDocumentDialog(const LockFileEntry &aData, bool bIsLoading, bool bOwnLock, bool bHandleSysLocked)
DECL_DLLPRIVATE_STATIC_LINK(SfxMedium, ShowReloadEditableDialog, void *, void)
virtual OUString GetName() const override
#define SFX2_DLLPUBLIC
Definition: dllapi.h:29
constexpr OUStringLiteral IsRemote(u"IsRemote")
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
DdeData aData
Definition: lnkbase2.cxx:82
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Implementation of the interface com.sun.star.rdf.XDocumentMetadataAccess.
Close
SignatureState
StreamMode
int SetError()