/src/libreoffice/include/sot/storage.hxx
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 | | #ifndef INCLUDED_SOT_STORAGE_HXX |
21 | | #define INCLUDED_SOT_STORAGE_HXX |
22 | | |
23 | | #include <sot/object.hxx> |
24 | | #include <tools/stream.hxx> |
25 | | #include <comphelper/errcode.hxx> |
26 | | #include <sot/storinfo.hxx> |
27 | | #include <sot/sotdllapi.h> |
28 | | |
29 | | namespace com::sun::star::embed { class XStorage; } |
30 | | namespace com::sun::star::uno { class Any; } |
31 | | namespace com::sun::star::uno { template <typename > class Reference; } |
32 | | namespace rtl { template <class reference_type> class Reference; } |
33 | | |
34 | | enum class SotClipboardFormatId : sal_uInt32; |
35 | | |
36 | | class BaseStorageStream; |
37 | | class SvGlobalName; |
38 | | |
39 | | namespace SotTempStream |
40 | | { |
41 | | SOT_DLLPUBLIC std::unique_ptr<SvStream> Create(OUString const & rString, StreamMode = StreamMode::STD_READWRITE); |
42 | | }; |
43 | | |
44 | | class SOT_DLLPUBLIC SotStorageStream final : virtual public SotObject, public SvStream |
45 | | { |
46 | | friend class SotStorage; |
47 | | BaseStorageStream * pOwnStm; // pointer to the own stream |
48 | | |
49 | | virtual std::size_t GetData(void* pData, std::size_t nSize) override; |
50 | | virtual std::size_t PutData(const void* pData, std::size_t nSize) override; |
51 | | virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override; |
52 | | virtual void FlushData() override; |
53 | | |
54 | | virtual ~SotStorageStream() override; |
55 | | public: |
56 | | SotStorageStream(BaseStorageStream *pBaseStream); |
57 | | |
58 | | virtual void ResetError() override; |
59 | | |
60 | | virtual void SetSize(sal_uInt64 nNewSize) override; |
61 | | sal_uInt32 GetSize() const; |
62 | | void Commit(); |
63 | | bool SetProperty(OUString const & rName, css::uno::Any const & rValue); |
64 | | virtual sal_uInt64 TellEnd() override; |
65 | | }; |
66 | | |
67 | | class BaseStorage; |
68 | | class SOT_DLLPUBLIC SotStorage final : virtual public SotObject |
69 | | { |
70 | | friend class SotStorageStream; |
71 | | |
72 | | BaseStorage* m_pOwnStg; // target storage |
73 | | SvStream* m_pStorStm; // only for SDSTORAGES |
74 | | ErrCode m_nError; |
75 | | OUString m_aName;// name of the storage |
76 | | bool m_bIsRoot; // e.g.: File Storage |
77 | | bool m_bDelStm; |
78 | | OString m_aKey; // aKey.Len != 0 -> encryption |
79 | | sal_Int32 m_nVersion; |
80 | | |
81 | | virtual ~SotStorage() override; |
82 | | void CreateStorage(bool bUCBStorage, StreamMode); |
83 | | public: |
84 | | SotStorage(OUString const & rString, StreamMode eMode = StreamMode::STD_READWRITE); |
85 | | SotStorage(bool bUCBStorage, const OUString & rString, |
86 | | StreamMode = StreamMode::STD_READWRITE); |
87 | | SotStorage(BaseStorage * pStorage); |
88 | | SotStorage(SvStream & rStream); |
89 | | SotStorage(bool bUCBStorage, SvStream & rStream); |
90 | | SotStorage(SvStream * rStream, bool bDelete); |
91 | | |
92 | | std::unique_ptr<SvMemoryStream> CreateMemoryStream(); |
93 | | |
94 | | static bool IsStorageFile(OUString const & rFileName); |
95 | | static bool IsStorageFile(SvStream* pStream); |
96 | | |
97 | | const OUString& GetName() const; |
98 | | |
99 | | bool Validate(); |
100 | | |
101 | 10.8k | const OString& GetKey() const { return m_aKey;} |
102 | | |
103 | | void SetVersion(sal_Int32 nVersion) |
104 | 0 | { |
105 | 0 | m_nVersion = nVersion; |
106 | 0 | } |
107 | | sal_Int32 GetVersion() const |
108 | 10.8k | { |
109 | 10.8k | return m_nVersion; |
110 | 10.8k | } |
111 | | |
112 | | ErrCode GetError() const |
113 | 36.1k | { |
114 | 36.1k | return m_nError.IgnoreWarning(); |
115 | 36.1k | } |
116 | | void SetError(ErrCode nErrorCode) |
117 | 218k | { |
118 | 218k | if (m_nError == ERRCODE_NONE) |
119 | 215k | m_nError = nErrorCode; |
120 | 218k | } |
121 | | |
122 | 109k | void SignAsRoot(bool bRoot) { m_bIsRoot = bRoot; } |
123 | | |
124 | | // own data sector |
125 | | void SetClass(const SvGlobalName & rClass, |
126 | | SotClipboardFormatId bOriginalClipFormat, |
127 | | const OUString & rUserTypeName); |
128 | | |
129 | | SvGlobalName GetClassName(); // type of data in the storage |
130 | | SotClipboardFormatId GetFormat(); |
131 | | OUString GetUserName(); |
132 | | |
133 | | // list of all elements |
134 | | void FillInfoList(SvStorageInfoList *) const; |
135 | | bool CopyTo(SotStorage * pDestStg); |
136 | | bool Commit(); |
137 | | |
138 | | // create stream with connection to Storage, |
139 | | // more or less a Parent-Child relationship |
140 | | rtl::Reference<SotStorageStream> OpenSotStream(const OUString & rEleName, |
141 | | StreamMode = StreamMode::STD_READWRITE); |
142 | | rtl::Reference<SotStorage> OpenSotStorage(const OUString & rEleName, |
143 | | StreamMode = StreamMode::STD_READWRITE, |
144 | | bool transacted = true); |
145 | | |
146 | | // query whether Storage or Stream |
147 | | bool IsStream( const OUString & rEleName ) const; |
148 | | bool IsStorage( const OUString & rEleName ) const; |
149 | | bool IsContained( const OUString & rEleName ) const; |
150 | | // remove element |
151 | | bool Remove(const OUString & rEleName); |
152 | | bool CopyTo(const OUString & rEleName, SotStorage* pDest, |
153 | | const OUString & rNewName); |
154 | | |
155 | | bool IsOLEStorage() const; |
156 | | static bool IsOLEStorage(const OUString & rFileName); |
157 | | static bool IsOLEStorage(SvStream* pStream); |
158 | | |
159 | | static rtl::Reference<SotStorage> OpenOLEStorage(css::uno::Reference<css::embed::XStorage> const & xStorage, |
160 | | OUString const & rEleName, StreamMode = StreamMode::STD_READWRITE); |
161 | | static SotClipboardFormatId GetFormatID(css::uno::Reference<css::embed::XStorage> const & xStorage); |
162 | | static sal_Int32 GetVersion(css::uno::Reference<css::embed::XStorage> const & xStorage); |
163 | | }; |
164 | | |
165 | | #endif // INCLUDED_SOT_STORAGE_HXX |
166 | | |
167 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |