tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / core / dataaccess / myucp_datasupplier.cxx
blob597933b9db5fe1f11967eb17c5ff91845cf30b52
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 <utility>
21 #include <vector>
23 #include "myucp_datasupplier.hxx"
24 #include <ContentHelper.hxx>
25 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::ucb;
29 using namespace ::com::sun::star::sdbc;
30 using namespace ::com::sun::star::io;
31 using namespace ::com::sun::star::container;
33 using namespace dbaccess;
36 DataSupplier::DataSupplier( const rtl::Reference< ODocumentContainer >& rContent )
37 : m_xContent( rContent )
41 DataSupplier::~DataSupplier()
45 OUString DataSupplier::queryContentIdentifierString( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex )
47 osl::Guard< osl::Mutex > aGuard( m_aMutex );
49 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
51 OUString aId = m_aResults[ nIndex ]->aId;
52 if ( !aId.isEmpty() )
54 // Already cached.
55 return aId;
59 if ( getResult( rResultSetGuard, nIndex ) )
61 OUString aId = m_xContent->getIdentifier()->getContentIdentifier();
63 if ( !aId.isEmpty() )
64 aId += "/";
66 aId += m_aResults[ nIndex ]->rData.aTitle;
68 m_aResults[ nIndex ]->aId = aId;
69 return aId;
71 return OUString();
74 Reference< XContentIdentifier >
75 DataSupplier::queryContentIdentifier( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex )
77 osl::Guard< osl::Mutex > aGuard( m_aMutex );
79 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
81 Reference< XContentIdentifier > xId = m_aResults[ nIndex ]->xId;
82 if ( xId.is() )
84 // Already cached.
85 return xId;
89 OUString aId = queryContentIdentifierString( rResultSetGuard, nIndex );
90 if ( !aId.isEmpty() )
92 Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aId );
93 m_aResults[ nIndex ]->xId = xId;
94 return xId;
96 return Reference< XContentIdentifier >();
99 Reference< XContent >
100 DataSupplier::queryContent( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 _nIndex )
102 osl::Guard< osl::Mutex > aGuard( m_aMutex );
104 if ( static_cast<size_t>(_nIndex) < m_aResults.size() )
106 Reference< XContent > xContent = m_aResults[ _nIndex ]->xContent;
107 if ( xContent.is() )
109 // Already cached.
110 return xContent;
114 Reference< XContentIdentifier > xId = queryContentIdentifier( rResultSetGuard, _nIndex );
115 if ( xId.is() )
119 Reference< XContent > xContent;
120 OUString sName = xId->getContentIdentifier();
121 sName = sName.copy(sName.lastIndexOf('/')+1);
123 m_aResults[ _nIndex ]->xContent = m_xContent->getContent(sName);
125 xContent = m_aResults[ _nIndex ]->xContent.get();
126 return xContent;
129 catch ( IllegalIdentifierException& )
133 return Reference< XContent >();
136 bool DataSupplier::getResult( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex )
138 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
140 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
142 // Result already present.
143 return true;
146 // Result not (yet) present.
148 if ( m_bCountFinal )
149 return false;
151 // Try to obtain result...
153 sal_uInt32 nOldCount = m_aResults.size();
154 bool bFound = false;
156 // @@@ Obtain data and put it into result list...
157 Sequence< OUString> aSeq = m_xContent->getElementNames();
158 if ( nIndex < sal::static_int_cast< sal_uInt32 >( aSeq.getLength() ) )
160 m_aResults.reserve(nIndex + 1);
161 const OUString* pEnd = aSeq.begin() + nIndex + 1;
162 for (const OUString* pIter = aSeq.begin() + nOldCount; pIter != pEnd; ++pIter)
163 m_aResults.emplace_back(
164 new ResultListEntry( m_xContent->getContent(*pIter)->getContentProperties() ) );
166 // Result obtained.
167 bFound = true;
170 if ( !bFound )
171 m_bCountFinal = true;
173 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet();
174 if ( xResultSet.is() )
176 // Callbacks follow!
177 aGuard.clear();
179 if ( static_cast<size_t>(nOldCount) < m_aResults.size() )
180 xResultSet->rowCountChanged( rResultSetGuard, nOldCount, m_aResults.size() );
182 if ( m_bCountFinal )
183 xResultSet->rowCountFinal(rResultSetGuard);
186 return bFound;
189 sal_uInt32 DataSupplier::totalCount(std::unique_lock<std::mutex>& rResultSetGuard)
191 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
193 if ( m_bCountFinal )
194 return m_aResults.size();
196 sal_uInt32 nOldCount = m_aResults.size();
198 // @@@ Obtain data and put it into result list...
199 Sequence< OUString> aSeq = m_xContent->getElementNames();
200 // FIXME: this adds everything from aSeq to m_aResults, unlike similar code in getResult,
201 // which skips nOldCount entries in aSeq - which is correct?
202 for (auto& name : aSeq)
203 m_aResults.emplace_back(
204 new ResultListEntry( m_xContent->getContent(name)->getContentProperties() ) );
206 m_bCountFinal = true;
208 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet();
209 if ( xResultSet.is() )
211 // Callbacks follow!
212 aGuard.clear();
214 if ( static_cast<size_t>(nOldCount) < m_aResults.size() )
215 xResultSet->rowCountChanged( rResultSetGuard, nOldCount, m_aResults.size() );
217 xResultSet->rowCountFinal(rResultSetGuard);
220 return m_aResults.size();
223 sal_uInt32 DataSupplier::currentCount()
225 return m_aResults.size();
228 bool DataSupplier::isCountFinal()
230 return m_bCountFinal;
233 Reference< XRow >
234 DataSupplier::queryPropertyValues( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex )
236 osl::Guard< osl::Mutex > aGuard( m_aMutex );
238 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
240 Reference< XRow > xRow = m_aResults[ nIndex ]->xRow;
241 if ( xRow.is() )
243 // Already cached.
244 return xRow;
248 if ( getResult( rResultSetGuard, nIndex ) )
250 if ( !m_aResults[ nIndex ]->xContent.is() )
251 queryContent(rResultSetGuard, nIndex);
253 Reference< XRow > xRow = m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties());
254 m_aResults[ nIndex ]->xRow = xRow;
255 return xRow;
258 return Reference< XRow >();
261 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
263 osl::Guard< osl::Mutex > aGuard( m_aMutex );
265 if ( static_cast<size_t>(nIndex) < m_aResults.size() )
266 m_aResults[ nIndex ]->xRow.clear();
269 void DataSupplier::close()
273 void DataSupplier::validate()
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */