tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / store / source / stordir.cxx
blobbd4139b96d58e92d6082ec318a87a09cd1b41b22
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 #include "stordir.hxx"
22 #include <sal/types.h>
24 #include <rtl/textcvt.h>
25 #include <rtl/ref.hxx>
26 #include <rtl/ustring.h>
28 #include <osl/mutex.hxx>
30 #include <store/types.h>
32 #include "storbase.hxx"
33 #include "stordata.hxx"
34 #include "storpage.hxx"
36 using namespace store;
38 static sal_Size convertTextToUnicode (
39 rtl_TextToUnicodeConverter hConverter,
40 const char *pSrcBuffer, sal_Size nSrcLength,
41 sal_Unicode *pDstBuffer, sal_Size nDstLength)
43 sal_uInt32 nCvtInfo = 0;
44 sal_Size nCvtBytes = 0;
45 return rtl_convertTextToUnicode (
46 hConverter, nullptr,
47 pSrcBuffer, nSrcLength,
48 pDstBuffer, nDstLength,
49 OSTRING_TO_OUSTRING_CVTFLAGS,
50 &nCvtInfo, &nCvtBytes);
53 const sal_uInt32 OStoreDirectory_Impl::m_nTypeId(0x89191107);
55 OStoreDirectory_Impl::OStoreDirectory_Impl()
56 : m_aDescr (0, 0, 0),
57 m_nPath (0),
58 m_hTextCvt (nullptr)
61 OStoreDirectory_Impl::~OStoreDirectory_Impl()
63 if (m_xManager.is())
65 if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
66 m_xManager->releasePage (m_aDescr);
68 rtl_destroyTextToUnicodeConverter (m_hTextCvt);
71 bool OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
73 return (nTypeId == m_nTypeId);
76 storeError OStoreDirectory_Impl::create (
77 OStorePageManager *pManager,
78 rtl_String const *pPath,
79 rtl_String const *pName,
80 storeAccessMode eMode)
82 rtl::Reference<OStorePageManager> xManager (pManager);
83 if (!xManager.is())
84 return store_E_InvalidAccess;
86 if (!(pPath && pName))
87 return store_E_InvalidParameter;
89 OStoreDirectoryPageObject aPage;
90 storeError eErrCode = xManager->iget (
91 aPage, STORE_ATTRIB_ISDIR,
92 pPath, pName, eMode);
93 if (eErrCode != store_E_None)
94 return eErrCode;
96 if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
97 return store_E_NotDirectory;
99 inode_holder_type xNode (aPage.get());
100 eErrCode = xManager->acquirePage (xNode->m_aDescr, storeAccessMode::ReadOnly);
101 if (eErrCode != store_E_None)
102 return eErrCode;
104 // Evaluate iteration path.
105 m_nPath = aPage.path();
106 m_nPath = rtl_crc32 (m_nPath, "/", 1);
108 // Save page manager, and descriptor.
109 m_xManager = std::move(xManager);
110 m_aDescr = xNode->m_aDescr;
112 return store_E_None;
115 storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
117 if (!m_xManager.is())
118 return store_E_InvalidAccess;
120 storeError eErrCode = store_E_NoMoreFiles;
121 if (!rFindData.m_nReserved)
122 return eErrCode;
124 // Acquire exclusive access.
125 osl::MutexGuard aGuard (*m_xManager);
127 // Check TextConverter.
128 if (m_hTextCvt == nullptr)
129 m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
131 // Setup iteration key.
132 OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
134 // Iterate.
135 for (;;)
137 OStorePageLink aLink;
138 eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
139 if (eErrCode != store_E_None || aKey.m_nHigh != store::htonl(m_nPath))
140 break;
142 if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
144 // Load page.
145 OStoreDirectoryPageObject aPage;
146 eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
147 if (eErrCode == store_E_None)
149 inode_holder_type xNode (aPage.get());
151 // Setup FindData.
152 char *p = xNode->m_aNameBlock.m_pData;
153 sal_Int32 n = rtl_str_getLength (p);
154 sal_Int32 k = rFindData.m_nLength;
156 n = convertTextToUnicode (
157 m_hTextCvt, p, n,
158 rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
159 if (k > n)
161 k = (k - n) * sizeof(sal_Unicode);
162 memset (&rFindData.m_pszName[n], 0, k);
165 rFindData.m_nLength = n;
166 rFindData.m_nAttrib |= aPage.attrib();
168 // Leave.
169 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
170 return store_E_None;
174 if (aKey.m_nLow == 0)
175 break;
176 aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
179 // Finished.
180 memset (&rFindData, 0, sizeof (storeFindData));
181 return store_E_NoMoreFiles;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */