1 --- ucb/source/ucp/gvfs/directory.hxx 2003-04-24 16:24:35.000000000 +0100
2 +++ ucb/source/ucp/gvfs/directory.hxx 2003-04-24 16:24:35.000000000 +0100
4 +#ifndef _GVFS_UCP_RESULTSET_HXX
5 +#define _GVFS_UCP_RESULTSET_HXX
8 +#include <rtl/ref.hxx>
10 +#ifndef _UCBHELPER_RESULTSET_HXX
11 +#include <ucbhelper/resultset.hxx>
13 +#ifndef _UCBHELPER_RESULTSETHELPER_HXX
14 +#include <ucbhelper/resultsethelper.hxx>
17 +#ifndef _GVFS_UCP_CONTENT_HXX
18 +#include "content.hxx"
23 +class DynamicResultSet : public ::ucb::ResultSetImplHelper
25 + rtl::Reference< Content > m_xContent;
26 + com::sun::star::uno::Reference<
27 + com::sun::star::ucb::XCommandEnvironment > m_xEnv;
30 + virtual void initStatic();
31 + virtual void initDynamic();
34 + DynamicResultSet( const com::sun::star::uno::Reference<
35 + com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
36 + const rtl::Reference< Content >& rxContent,
37 + const com::sun::star::ucb::OpenCommandArgument2& rCommand,
38 + const com::sun::star::uno::Reference<
39 + com::sun::star::ucb::XCommandEnvironment >& rxEnv );
43 +struct gvfs::DataSupplier_Impl;
44 +class DataSupplier : public ucb::ResultSetDataSupplier
47 + gvfs::DataSupplier_Impl *m_pImpl;
48 + sal_Bool DataSupplier::getData();
51 + DataSupplier( const com::sun::star::uno::Reference<
52 + com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
53 + const rtl::Reference< Content >& rContent,
54 + sal_Int32 nOpenMode);
56 + virtual ~DataSupplier();
58 + virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex );
59 + virtual com::sun::star::uno::Reference<
60 + com::sun::star::ucb::XContentIdentifier >
61 + queryContentIdentifier( sal_uInt32 nIndex );
62 + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent >
63 + queryContent( sal_uInt32 nIndex );
65 + virtual sal_Bool getResult( sal_uInt32 nIndex );
67 + virtual sal_uInt32 totalCount();
68 + virtual sal_uInt32 currentCount();
69 + virtual sal_Bool isCountFinal();
71 + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow >
72 + queryPropertyValues( sal_uInt32 nIndex );
73 + virtual void releasePropertyValues( sal_uInt32 nIndex );
74 + virtual void close();
75 + virtual void validate()
76 + throw( com::sun::star::ucb::ResultSetException );
82 --- ucb/source/ucp/gvfs/directory.cxx 2003-04-24 17:03:31.000000000 +0100
83 +++ ucb/source/ucp/gvfs/directory.cxx 2003-04-24 17:03:31.000000000 +0100
86 + * This file pinched from webdavdatasupplier (etc.)
87 + * cut & paste + new getData impl. & collate ResultSet code.
90 +#ifndef _OSL_DIAGNOSE_H_
91 +#include <osl/diagnose.h>
93 +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
94 +#include <com/sun/star/ucb/OpenMode.hpp>
96 +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
97 +#include <ucbhelper/contentidentifier.hxx>
99 +#ifndef _UCBHELPER_PROVIDERHELPER_HXX
100 +#include <ucbhelper/providerhelper.hxx>
103 +#include "directory.hxx"
105 +#include <libgnomevfs/gnome-vfs-utils.h>
106 +#include <libgnomevfs/gnome-vfs-directory.h>
108 +using namespace com::sun::star;
109 +using namespace gvfs;
111 +// DynamicResultSet Implementation.
113 +DynamicResultSet::DynamicResultSet(
114 + const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
115 + const rtl::Reference< Content >& rxContent,
116 + const com::sun::star::ucb::OpenCommandArgument2& rCommand,
117 + const uno::Reference<com::sun::star::ucb::XCommandEnvironment >& rxEnv )
118 + : ResultSetImplHelper( rxSMgr, rCommand ),
119 + m_xContent( rxContent ),
123 +void DynamicResultSet::initStatic()
126 + = new ::ucb::ResultSet( m_xSMgr,
127 + m_aCommand.Properties,
128 + new DataSupplier( m_xSMgr,
133 +void DynamicResultSet::initDynamic()
136 + m_xResultSet2 = m_xResultSet1;
139 +//=========================================================================
142 +// DataSupplier Implementation.
146 +struct ResultListEntry
149 + uno::Reference< com::sun::star::ucb::XContentIdentifier > xId;
150 + uno::Reference< com::sun::star::ucb::XContent > xContent;
151 + uno::Reference< sdbc::XRow > xRow;
152 + GnomeVFSFileInfo aInfo;
154 + ResultListEntry( const GnomeVFSFileInfo *fileInfo)
156 + gnome_vfs_file_info_copy (&aInfo, fileInfo);
161 + gnome_vfs_file_info_clear (&aInfo);
165 +//=========================================================================
169 +//=========================================================================
171 +typedef std::vector< ResultListEntry* > ResultList;
173 +//=========================================================================
175 +// struct DataSupplier_Impl.
177 +//=========================================================================
179 +struct gvfs::DataSupplier_Impl
181 + osl::Mutex m_aMutex;
182 + ResultList m_aResults;
183 + rtl::Reference< Content > m_xContent;
184 + uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
185 + sal_Int32 m_nOpenMode;
186 + sal_Bool m_bCountFinal;
189 + const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
190 + const rtl::Reference< Content >& rContent,
191 + sal_Int32 nOpenMode )
192 + : m_xContent( rContent ), m_xSMgr( rxSMgr ),
193 + m_nOpenMode( nOpenMode ), m_bCountFinal( sal_False ) {}
194 + ~DataSupplier_Impl()
196 + ResultList::const_iterator it = m_aResults.begin();
197 + ResultList::const_iterator end = m_aResults.end();
199 + while ( it != end )
207 +DataSupplier::DataSupplier(
208 + const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
209 + const rtl::Reference< Content >& rContent,
210 + sal_Int32 nOpenMode )
211 +: m_pImpl( new DataSupplier_Impl( rxSMgr, rContent, nOpenMode ) )
215 +//=========================================================================
217 +DataSupplier::~DataSupplier()
223 +rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
225 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
227 + if ( nIndex < m_pImpl->m_aResults.size() ) {
228 + rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
229 + if ( aId.getLength() ) // cached
233 + if ( getResult( nIndex ) ) {
234 + rtl::OUString aId = m_pImpl->m_xContent->getOUURI();
236 + char *escaped_name;
237 + escaped_name = gnome_vfs_escape_string( m_pImpl->m_aResults[ nIndex ]->aInfo.name );
239 + if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
240 + aId += rtl::OUString::createFromAscii( "/" );
242 + aId += rtl::OUString::createFromAscii( escaped_name );
244 + g_free( escaped_name );
246 + m_pImpl->m_aResults[ nIndex ]->aId = aId;
250 + return rtl::OUString();
254 +uno::Reference< com::sun::star::ucb::XContentIdentifier >
255 +DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
257 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
259 + if ( nIndex < m_pImpl->m_aResults.size() ) {
260 + uno::Reference< com::sun::star::ucb::XContentIdentifier > xId
261 + = m_pImpl->m_aResults[ nIndex ]->xId;
262 + if ( xId.is() ) // Already cached.
266 + rtl::OUString aId = queryContentIdentifierString( nIndex );
267 + if ( aId.getLength() ) {
268 + uno::Reference< com::sun::star::ucb::XContentIdentifier > xId
269 + = new ::ucb::ContentIdentifier( aId );
270 + m_pImpl->m_aResults[ nIndex ]->xId = xId;
274 + return uno::Reference< com::sun::star::ucb::XContentIdentifier >();
278 +uno::Reference< com::sun::star::ucb::XContent >
279 +DataSupplier::queryContent( sal_uInt32 nIndex )
281 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
283 + if ( nIndex < m_pImpl->m_aResults.size() ) {
284 + uno::Reference< com::sun::star::ucb::XContent > xContent
285 + = m_pImpl->m_aResults[ nIndex ]->xContent;
286 + if ( xContent.is() ) // Already cached.
290 + uno::Reference< com::sun::star::ucb::XContentIdentifier > xId
291 + = queryContentIdentifier( nIndex );
296 + // It would be really nice to propagate this information
297 + // to the Content, but we can't then register it with the
298 + // ContentProvider, and the ucbhelper hinders here.
299 + uno::Reference< com::sun::star::ucb::XContent > xContent
300 + = m_pImpl->m_xContent->getProvider()->queryContent( xId );
301 + m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
305 + catch ( com::sun::star::ucb::IllegalIdentifierException& ) {
308 + return uno::Reference< com::sun::star::ucb::XContent >();
312 +sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
314 + osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
316 + if ( m_pImpl->m_aResults.size() > nIndex ) // Result already present.
319 + if ( getData() && m_pImpl->m_aResults.size() > nIndex )
326 +sal_uInt32 DataSupplier::totalCount()
330 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
332 + return m_pImpl->m_aResults.size();
336 +sal_uInt32 DataSupplier::currentCount()
338 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
339 + return m_pImpl->m_aResults.size();
343 +sal_Bool DataSupplier::isCountFinal()
345 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
346 + return m_pImpl->m_bCountFinal;
350 +uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
352 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
354 + if ( nIndex < m_pImpl->m_aResults.size() ) {
355 + uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
356 + if ( xRow.is() ) // Already cached.
360 + if ( getResult( nIndex ) ) {
361 + // Inefficient - but we can't create xContent's sensibly
362 + // nor can we do the property code sensibly cleanly staticaly.
363 + Content *pContent = static_cast< ::gvfs::Content * >(queryContent( nIndex ).get());
365 + uno::Reference< sdbc::XRow > xRow =
366 + pContent->getPropertyValues( getResultSet()->getProperties(),
367 + getResultSet()->getEnvironment() );
369 + m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
374 + return uno::Reference< sdbc::XRow >();
378 +void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
380 + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
382 + if ( nIndex < m_pImpl->m_aResults.size() )
383 + m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
387 +void DataSupplier::close()
392 +void DataSupplier::validate()
393 + throw( com::sun::star::ucb::ResultSetException )
397 +sal_Bool DataSupplier::getData()
399 + osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
401 + if ( !m_pImpl->m_bCountFinal ) {
402 + GnomeVFSResult result;
403 + GnomeVFSDirectoryHandle *dirHandle = NULL;
406 + Authentication aAuth( getResultSet()->getEnvironment() );
407 + char *uri = m_pImpl->m_xContent->getURI();
408 + result = gnome_vfs_directory_open
409 + ( &dirHandle, uri, GNOME_VFS_FILE_INFO_DEFAULT );
411 + if (result != GNOME_VFS_OK) {
413 + g_warning ("Failed open of '%s' with '%s'",
414 + uri, gnome_vfs_result_to_string( result ));
424 + GnomeVFSFileInfo fileInfo = { 0 };
425 + while ((result = gnome_vfs_directory_read_next (dirHandle, &fileInfo)) == GNOME_VFS_OK) {
426 + if( fileInfo.name && fileInfo.name[0] == '.' &&
427 + ( fileInfo.name[1] == '\0' ||
428 + ( fileInfo.name[1] == '.' && fileInfo.name[2] == '\0' ) ) )
431 + switch ( m_pImpl->m_nOpenMode ) {
432 + case com::sun::star::ucb::OpenMode::FOLDERS:
433 + if ( !(fileInfo.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ||
434 + fileInfo.type != GNOME_VFS_FILE_TYPE_DIRECTORY )
438 + case com::sun::star::ucb::OpenMode::DOCUMENTS:
439 + if ( !(fileInfo.valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ||
440 + fileInfo.type != GNOME_VFS_FILE_TYPE_REGULAR )
444 + case com::sun::star::ucb::OpenMode::ALL:
449 + m_pImpl->m_aResults.push_back( new ResultListEntry( &fileInfo ) );
452 + g_warning ("Got %d directory entries", result);
455 + m_pImpl->m_bCountFinal = sal_True;
457 + // Callback possible, because listeners may be informed!
459 + getResultSet()->rowCountFinal();
461 + if (result != GNOME_VFS_ERROR_EOF) {
463 + g_warning( "Failed read_next '%s'",
464 + gnome_vfs_result_to_string( result ) );
469 + result = gnome_vfs_directory_close (dirHandle);
470 + if (result != GNOME_VFS_OK) {
472 + g_warning( "Failed close '%s'",
473 + gnome_vfs_result_to_string( result ) );