fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchydatasupplier.cxx
blob38bd19ac55fb918b38beac3b93f3dda629d33e2c
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
27 #include <vector>
28 #include <ucbhelper/contentidentifier.hxx>
29 #include "hierarchydatasupplier.hxx"
30 #include "hierarchyprovider.hxx"
31 #include "hierarchycontent.hxx"
33 using namespace com::sun::star;
34 using namespace hierarchy_ucp;
36 namespace hierarchy_ucp
41 // struct ResultListEntry.
45 struct ResultListEntry
47 OUString aId;
48 uno::Reference< ucb::XContentIdentifier > xId;
49 uno::Reference< ucb::XContent > xContent;
50 uno::Reference< sdbc::XRow > xRow;
51 HierarchyEntryData aData;
53 ResultListEntry( const HierarchyEntryData& rEntry ) : aData( rEntry ) {}
58 // ResultList.
62 typedef std::vector< ResultListEntry* > ResultList;
66 // struct DataSupplier_Impl.
70 struct DataSupplier_Impl
72 osl::Mutex m_aMutex;
73 ResultList m_aResults;
74 rtl::Reference< HierarchyContent > m_xContent;
75 uno::Reference< uno::XComponentContext > m_xContext;
76 HierarchyEntry m_aFolder;
77 HierarchyEntry::iterator m_aIterator;
78 sal_Int32 m_nOpenMode;
79 bool m_bCountFinal;
81 DataSupplier_Impl(
82 const uno::Reference< uno::XComponentContext >& rxContext,
83 const rtl::Reference< HierarchyContent >& rContent,
84 sal_Int32 nOpenMode )
85 : m_xContent( rContent ), m_xContext( rxContext ),
86 m_aFolder( rxContext,
87 static_cast< HierarchyContentProvider * >(
88 rContent->getProvider().get() ),
89 rContent->getIdentifier()->getContentIdentifier() ),
90 m_nOpenMode( nOpenMode ), m_bCountFinal( false ) {}
91 ~DataSupplier_Impl();
95 DataSupplier_Impl::~DataSupplier_Impl()
97 ResultList::const_iterator it = m_aResults.begin();
98 ResultList::const_iterator end = m_aResults.end();
100 while ( it != end )
102 delete (*it);
103 ++it;
112 // HierarchyResultSetDataSupplier Implementation.
117 HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
118 const uno::Reference< uno::XComponentContext >& rxContext,
119 const rtl::Reference< HierarchyContent >& rContent,
120 sal_Int32 nOpenMode )
121 : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
126 // virtual
127 HierarchyResultSetDataSupplier::~HierarchyResultSetDataSupplier()
129 delete m_pImpl;
133 // virtual
134 OUString HierarchyResultSetDataSupplier::queryContentIdentifierString(
135 sal_uInt32 nIndex )
137 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
139 if ( nIndex < m_pImpl->m_aResults.size() )
141 OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
142 if ( !aId.isEmpty() )
144 // Already cached.
145 return aId;
149 if ( getResult( nIndex ) )
151 OUString aId
152 = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
154 if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
155 aId += "/";
157 aId += m_pImpl->m_aResults[ nIndex ]->aData.getName();
159 m_pImpl->m_aResults[ nIndex ]->aId = aId;
160 return aId;
162 return OUString();
166 // virtual
167 uno::Reference< ucb::XContentIdentifier >
168 HierarchyResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
170 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
172 if ( nIndex < m_pImpl->m_aResults.size() )
174 uno::Reference< ucb::XContentIdentifier > xId
175 = m_pImpl->m_aResults[ nIndex ]->xId;
176 if ( xId.is() )
178 // Already cached.
179 return xId;
183 OUString aId = queryContentIdentifierString( nIndex );
184 if ( !aId.isEmpty() )
186 uno::Reference< ucb::XContentIdentifier > xId
187 = new ::ucbhelper::ContentIdentifier( aId );
188 m_pImpl->m_aResults[ nIndex ]->xId = xId;
189 return xId;
191 return uno::Reference< ucb::XContentIdentifier >();
195 // virtual
196 uno::Reference< ucb::XContent >
197 HierarchyResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
199 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
201 if ( nIndex < m_pImpl->m_aResults.size() )
203 uno::Reference< ucb::XContent > xContent
204 = m_pImpl->m_aResults[ nIndex ]->xContent;
205 if ( xContent.is() )
207 // Already cached.
208 return xContent;
212 uno::Reference< ucb::XContentIdentifier > xId
213 = queryContentIdentifier( nIndex );
214 if ( xId.is() )
218 uno::Reference< ucb::XContent > xContent
219 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
220 m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
221 return xContent;
224 catch ( ucb::IllegalIdentifierException const & )
228 return uno::Reference< ucb::XContent >();
232 // virtual
233 bool HierarchyResultSetDataSupplier::getResult( sal_uInt32 nIndex )
235 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
237 if ( m_pImpl->m_aResults.size() > nIndex )
239 // Result already present.
240 return true;
243 // Result not (yet) present.
245 if ( m_pImpl->m_bCountFinal )
246 return false;
248 // Try to obtain result...
250 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
251 bool bFound = false;
252 sal_uInt32 nPos = nOldCount;
254 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
256 const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
257 if ( checkResult( rResult ) )
259 m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) );
261 if ( nPos == nIndex )
263 // Result obtained.
264 bFound = true;
265 break;
268 nPos++;
271 if ( !bFound )
272 m_pImpl->m_bCountFinal = true;
274 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
275 if ( xResultSet.is() )
277 // Callbacks follow!
278 aGuard.clear();
280 if ( nOldCount < m_pImpl->m_aResults.size() )
281 xResultSet->rowCountChanged(
282 nOldCount, m_pImpl->m_aResults.size() );
284 if ( m_pImpl->m_bCountFinal )
285 xResultSet->rowCountFinal();
288 return bFound;
292 // virtual
293 sal_uInt32 HierarchyResultSetDataSupplier::totalCount()
295 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
297 if ( m_pImpl->m_bCountFinal )
298 return m_pImpl->m_aResults.size();
300 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
302 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
304 const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
305 if ( checkResult( rResult ) )
306 m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) );
309 m_pImpl->m_bCountFinal = true;
311 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
312 if ( xResultSet.is() )
314 // Callbacks follow!
315 aGuard.clear();
317 if ( nOldCount < m_pImpl->m_aResults.size() )
318 xResultSet->rowCountChanged(
319 nOldCount, m_pImpl->m_aResults.size() );
321 xResultSet->rowCountFinal();
324 return m_pImpl->m_aResults.size();
328 // virtual
329 sal_uInt32 HierarchyResultSetDataSupplier::currentCount()
331 return m_pImpl->m_aResults.size();
335 // virtual
336 bool HierarchyResultSetDataSupplier::isCountFinal()
338 return m_pImpl->m_bCountFinal;
342 // virtual
343 uno::Reference< sdbc::XRow >
344 HierarchyResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex )
346 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
348 if ( nIndex < m_pImpl->m_aResults.size() )
350 uno::Reference< sdbc::XRow > xRow
351 = m_pImpl->m_aResults[ nIndex ]->xRow;
352 if ( xRow.is() )
354 // Already cached.
355 return xRow;
359 if ( getResult( nIndex ) )
361 HierarchyContentProperties aData(
362 m_pImpl->m_aResults[ nIndex ]->aData );
364 uno::Reference< sdbc::XRow > xRow
365 = HierarchyContent::getPropertyValues(
366 m_pImpl->m_xContext,
367 getResultSet()->getProperties(),
368 aData,
369 static_cast< HierarchyContentProvider * >(
370 m_pImpl->m_xContent->getProvider().get() ),
371 queryContentIdentifierString( nIndex ) );
372 m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
373 return xRow;
376 return uno::Reference< sdbc::XRow >();
380 // virtual
381 void HierarchyResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
383 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
385 if ( nIndex < m_pImpl->m_aResults.size() )
386 m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
390 // virtual
391 void HierarchyResultSetDataSupplier::close()
396 // virtual
397 void HierarchyResultSetDataSupplier::validate()
398 throw( ucb::ResultSetException )
403 bool HierarchyResultSetDataSupplier::checkResult(
404 const HierarchyEntryData& rResult )
406 switch ( m_pImpl->m_nOpenMode )
408 case ucb::OpenMode::FOLDERS:
409 if ( rResult.getType() == HierarchyEntryData::LINK )
411 // Entry is a link.
412 return false;
414 break;
416 case ucb::OpenMode::DOCUMENTS:
417 if ( rResult.getType() == HierarchyEntryData::FOLDER )
419 // Entry is a folder.
420 return false;
422 break;
424 case ucb::OpenMode::ALL:
425 default:
426 break;
429 return true;
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */