]> git.pld-linux.org Git - packages/libreoffice.git/blob - openoffice-vfs-directory.patch
- DON'T hardcode java paths!
[packages/libreoffice.git] / openoffice-vfs-directory.patch
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
3 @@ -0,0 +1,78 @@
4 +#ifndef _GVFS_UCP_RESULTSET_HXX
5 +#define _GVFS_UCP_RESULTSET_HXX
6 +
7 +#ifndef _RTL_REF_HXX_
8 +#include <rtl/ref.hxx>
9 +#endif
10 +#ifndef _UCBHELPER_RESULTSET_HXX
11 +#include <ucbhelper/resultset.hxx>
12 +#endif
13 +#ifndef _UCBHELPER_RESULTSETHELPER_HXX
14 +#include <ucbhelper/resultsethelper.hxx>
15 +#endif
16 +
17 +#ifndef _GVFS_UCP_CONTENT_HXX
18 +#include "content.hxx"
19 +#endif
20 +
21 +namespace gvfs {
22 +
23 +class DynamicResultSet : public ::ucb::ResultSetImplHelper
24 +{
25 +       rtl::Reference< Content > m_xContent;
26 +       com::sun::star::uno::Reference<
27 +               com::sun::star::ucb::XCommandEnvironment > m_xEnv;
28 +
29 +private:
30 +       virtual void initStatic();
31 +       virtual void initDynamic();
32 +
33 +public:
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 );
40 +};
41 +
42 +
43 +struct gvfs::DataSupplier_Impl;
44 +class DataSupplier : public ucb::ResultSetDataSupplier
45 +{
46 +private:
47 +       gvfs::DataSupplier_Impl *m_pImpl;
48 +       sal_Bool DataSupplier::getData();
49 +
50 +public:
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);
55 +
56 +       virtual ~DataSupplier();
57 +
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 );
64 +
65 +       virtual sal_Bool      getResult( sal_uInt32 nIndex );
66 +
67 +       virtual sal_uInt32    totalCount();
68 +       virtual sal_uInt32    currentCount();
69 +       virtual sal_Bool      isCountFinal();
70 +
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 );
77 +};
78 +
79 +}
80 +
81 +#endif
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
84 @@ -0,0 +1,399 @@
85 +/*
86 + * This file pinched from webdavdatasupplier (etc.)
87 + * cut & paste + new getData impl. & collate ResultSet code.
88 + */
89 +#include <vector>
90 +#ifndef _OSL_DIAGNOSE_H_
91 +#include <osl/diagnose.h>
92 +#endif
93 +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
94 +#include <com/sun/star/ucb/OpenMode.hpp>
95 +#endif
96 +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
97 +#include <ucbhelper/contentidentifier.hxx>
98 +#endif
99 +#ifndef _UCBHELPER_PROVIDERHELPER_HXX
100 +#include <ucbhelper/providerhelper.hxx>
101 +#endif
102 +
103 +#include "directory.hxx"
104 +
105 +#include <libgnomevfs/gnome-vfs-utils.h>
106 +#include <libgnomevfs/gnome-vfs-directory.h>
107 +
108 +using namespace com::sun::star;
109 +using namespace gvfs;
110 +
111 +// DynamicResultSet Implementation.
112 +
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 ),
120 +         m_xEnv( rxEnv )
121 +{
122 +}
123 +void DynamicResultSet::initStatic()
124 +{
125 +       m_xResultSet1
126 +               = new ::ucb::ResultSet( m_xSMgr,
127 +                                       m_aCommand.Properties,
128 +                                       new DataSupplier( m_xSMgr,
129 +                                                         m_xContent,
130 +                                                         m_aCommand.Mode ),
131 +                                       m_xEnv );
132 +}
133 +void DynamicResultSet::initDynamic()
134 +{
135 +       initStatic();
136 +       m_xResultSet2 = m_xResultSet1;
137 +}
138 +
139 +//=========================================================================
140 +
141 +
142 +// DataSupplier Implementation.
143 +
144 +
145 +
146 +struct ResultListEntry
147 +{
148 +       rtl::OUString                                             aId;
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;
153 +
154 +       ResultListEntry( const GnomeVFSFileInfo *fileInfo)
155 +       {
156 +               gnome_vfs_file_info_copy (&aInfo, fileInfo);
157 +       }
158 +
159 +       ~ResultListEntry()
160 +       {
161 +               gnome_vfs_file_info_clear (&aInfo);
162 +       }
163 +};
164 +
165 +//=========================================================================
166 +//
167 +// ResultList.
168 +//
169 +//=========================================================================
170 +
171 +typedef std::vector< ResultListEntry* > ResultList;
172 +
173 +//=========================================================================
174 +//
175 +// struct DataSupplier_Impl.
176 +//
177 +//=========================================================================
178 +
179 +struct gvfs::DataSupplier_Impl
180 +{
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;
187 +
188 +       DataSupplier_Impl(
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()
195 +       {
196 +               ResultList::const_iterator it  = m_aResults.begin();
197 +               ResultList::const_iterator end = m_aResults.end();
198 +
199 +               while ( it != end )
200 +                       {
201 +                               delete (*it);
202 +                               it++;
203 +                       }
204 +       }
205 +};
206 +
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 ) )
212 +{
213 +}
214 +
215 +//=========================================================================
216 +// virtual
217 +DataSupplier::~DataSupplier()
218 +{
219 +       delete m_pImpl;
220 +}
221 +
222 +// virtual
223 +rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
224 +{
225 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
226 +
227 +       if ( nIndex < m_pImpl->m_aResults.size() ) {
228 +               rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
229 +               if ( aId.getLength() ) // cached
230 +                       return aId;
231 +       }
232 +
233 +       if ( getResult( nIndex ) ) {
234 +               rtl::OUString aId = m_pImpl->m_xContent->getOUURI();
235 +
236 +               char *escaped_name;
237 +               escaped_name = gnome_vfs_escape_string( m_pImpl->m_aResults[ nIndex ]->aInfo.name );
238 +
239 +               if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
240 +                       aId += rtl::OUString::createFromAscii( "/" );
241 +
242 +               aId += rtl::OUString::createFromAscii( escaped_name );
243 +               
244 +               g_free( escaped_name );
245 +
246 +               m_pImpl->m_aResults[ nIndex ]->aId = aId;
247 +               return aId;
248 +       }
249 +
250 +       return rtl::OUString();
251 +}
252 +
253 +// virtual
254 +uno::Reference< com::sun::star::ucb::XContentIdentifier >
255 +DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
256 +{
257 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
258 +
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.
263 +                       return xId;
264 +       }
265 +
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;
271 +               return xId;
272 +       }
273 +
274 +       return uno::Reference< com::sun::star::ucb::XContentIdentifier >();
275 +}
276 +
277 +// virtual
278 +uno::Reference< com::sun::star::ucb::XContent >
279 +DataSupplier::queryContent( sal_uInt32 nIndex )
280 +{
281 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
282 +
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.
287 +                       return xContent;
288 +       }
289 +
290 +       uno::Reference< com::sun::star::ucb::XContentIdentifier > xId
291 +               = queryContentIdentifier( nIndex );
292 +       if ( xId.is() ) {
293 +               try
294 +               {
295 +                       // FIXME:
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;
302 +                       return xContent;
303 +                       
304 +               }
305 +               catch ( com::sun::star::ucb::IllegalIdentifierException& ) {
306 +               }
307 +       }
308 +       return uno::Reference< com::sun::star::ucb::XContent >();
309 +}
310 +
311 +// virtual
312 +sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
313 +{
314 +       osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
315 +
316 +       if ( m_pImpl->m_aResults.size() > nIndex ) // Result already present.
317 +               return sal_True;
318 +
319 +       if ( getData() && m_pImpl->m_aResults.size() > nIndex )
320 +               return sal_True;
321 +
322 +       return sal_False;
323 +}
324 +
325 +// virtual
326 +sal_uInt32 DataSupplier::totalCount()
327 +{
328 +       getData();
329 +
330 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
331 +
332 +       return m_pImpl->m_aResults.size();
333 +}
334 +
335 +// virtual
336 +sal_uInt32 DataSupplier::currentCount()
337 +{
338 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
339 +       return m_pImpl->m_aResults.size();
340 +}
341 +
342 +// virtual
343 +sal_Bool DataSupplier::isCountFinal()
344 +{
345 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
346 +       return m_pImpl->m_bCountFinal;
347 +}
348 +
349 +// virtual
350 +uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
351 +{
352 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
353 +
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.
357 +                       return xRow;
358 +       }
359 +
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());
364 +
365 +               uno::Reference< sdbc::XRow > xRow =
366 +                       pContent->getPropertyValues( getResultSet()->getProperties(),
367 +                                                    getResultSet()->getEnvironment() );
368 +
369 +               m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
370 +
371 +               return xRow;
372 +       }
373 +
374 +       return uno::Reference< sdbc::XRow >();
375 +}
376 +
377 +// virtual
378 +void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
379 +{
380 +       osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
381 +
382 +       if ( nIndex < m_pImpl->m_aResults.size() )
383 +               m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
384 +}
385 +
386 +// virtual
387 +void DataSupplier::close()
388 +{
389 +}
390 +
391 +// virtual
392 +void DataSupplier::validate()
393 +    throw( com::sun::star::ucb::ResultSetException )
394 +{
395 +}
396 +
397 +sal_Bool DataSupplier::getData()
398 +{
399 +       osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
400 +
401 +       if ( !m_pImpl->m_bCountFinal ) {
402 +               GnomeVFSResult result;
403 +               GnomeVFSDirectoryHandle *dirHandle = NULL;
404 +
405 +               {
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 );
410 +                       
411 +                       if (result != GNOME_VFS_OK) {
412 +#ifdef DEBUG
413 +                               g_warning ("Failed open of '%s' with '%s'",
414 +                                          uri, gnome_vfs_result_to_string( result ));
415 +#endif
416 +                               g_free( uri );
417 +                               return sal_False;
418 +                       }
419 +
420 +                       g_free( uri );
421 +               }
422 +
423 +
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' ) ) )
429 +                               continue;
430 +
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 )
435 +                                       continue;
436 +                               break;
437 +                               
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 )
441 +                                       continue;
442 +                               break;
443 +                               
444 +                       case com::sun::star::ucb::OpenMode::ALL:
445 +                       default:
446 +                               break;
447 +                       }
448 +                       
449 +                       m_pImpl->m_aResults.push_back( new ResultListEntry( &fileInfo ) );
450 +               }
451 +#ifdef DEBUG
452 +               g_warning ("Got %d directory entries", result);
453 +#endif
454 +
455 +               m_pImpl->m_bCountFinal = sal_True;
456 +
457 +               // Callback possible, because listeners may be informed!
458 +               aGuard.clear();
459 +               getResultSet()->rowCountFinal();
460 +
461 +               if (result != GNOME_VFS_ERROR_EOF) {
462 +#ifdef DEBUG
463 +                       g_warning( "Failed read_next '%s'",
464 +                                  gnome_vfs_result_to_string( result ) );
465 +#endif
466 +                       return sal_False;
467 +               }
468 +
469 +               result = gnome_vfs_directory_close (dirHandle);
470 +               if (result != GNOME_VFS_OK) {
471 +#ifdef DEBUG
472 +                       g_warning( "Failed close '%s'",
473 +                                  gnome_vfs_result_to_string( result ) );
474 +#endif
475 +                       return sal_False;
476 +               }
477 +       }
478 +
479 +       return sal_True;
480 +}
481 +
482 +
483 +
This page took 0.070648 seconds and 3 git commands to generate.