fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / gio / gio_datasupplier.cxx
blob02c1e11df61eabd5f8f2f0723f0b3390bb45df9f
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 <vector>
22 #include <ucbhelper/contentidentifier.hxx>
23 #include <ucbhelper/providerhelper.hxx>
25 #include <com/sun/star/ucb/OpenMode.hpp>
27 #include "gio_datasupplier.hxx"
28 #include "gio_content.hxx"
29 #include "gio_provider.hxx"
31 using namespace com::sun::star;
33 using namespace gio;
35 namespace gio
38 typedef std::vector< ResultListEntry* > ResultList;
40 DataSupplier::DataSupplier( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
41 const uno::Reference< ::gio::Content >& rContent, sal_Int32 nOpenMode )
42 : mxContent(rContent), m_xSMgr(rxSMgr), mnOpenMode(nOpenMode), mbCountFinal(false)
46 bool DataSupplier::getData()
48 if (mbCountFinal)
49 return true;
51 GFile *pFile = mxContent->getGFile();
53 GFileEnumerator* pEnumerator = g_file_enumerate_children(pFile, "*",
54 G_FILE_QUERY_INFO_NONE, NULL, NULL);
56 if (!pEnumerator)
57 return false;
59 GFileInfo *pInfo = NULL;
60 while ((pInfo = g_file_enumerator_next_file (pEnumerator, NULL, NULL)))
62 switch ( mnOpenMode )
64 case ucb::OpenMode::FOLDERS:
65 if (g_file_info_get_file_type(pInfo) != G_FILE_TYPE_DIRECTORY)
66 continue;
67 break;
68 case ucb::OpenMode::DOCUMENTS:
69 if (g_file_info_get_file_type(pInfo) != G_FILE_TYPE_REGULAR)
70 continue;
71 break;
72 case ucb::OpenMode::ALL:
73 default:
74 break;
77 maResults.push_back( new ResultListEntry( pInfo ) );
78 g_object_unref(pInfo);
81 mbCountFinal = true;
83 g_file_enumerator_close(pEnumerator, NULL, NULL);
84 return true;
87 DataSupplier::~DataSupplier()
89 ResultList::const_iterator it = maResults.begin();
90 ResultList::const_iterator end = maResults.end();
92 while ( it != end )
94 delete (*it);
95 ++it;
99 OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
101 if ( nIndex < maResults.size() )
103 OUString aId = maResults[ nIndex ]->aId;
104 if ( aId.getLength() )
106 // Already cached.
107 return aId;
111 if ( getResult( nIndex ) )
113 GFile *pFile = mxContent->getGFile();
114 char* parent = g_file_get_uri(pFile);
115 OUString aId = OUString::createFromAscii( parent );
116 g_free(parent);
118 char *escaped_name =
119 g_uri_escape_string( g_file_info_get_name(maResults[ nIndex ]->pInfo) , NULL, false);
121 if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
122 aId += "/";
124 aId += OUString::createFromAscii( escaped_name );
126 g_free( escaped_name );
128 maResults[ nIndex ]->aId = aId;
129 return aId;
132 return OUString();
135 uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
137 if ( nIndex < maResults.size() )
139 uno::Reference< ucb::XContentIdentifier > xId = maResults[ nIndex ]->xId;
140 if ( xId.is() )
142 // Already cached.
143 return xId;
147 OUString aId = queryContentIdentifierString( nIndex );
148 if ( aId.getLength() )
150 uno::Reference< ucb::XContentIdentifier > xId = new ucbhelper::ContentIdentifier( aId );
151 maResults[ nIndex ]->xId = xId;
152 return xId;
155 return uno::Reference< ucb::XContentIdentifier >();
158 uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex )
160 if ( nIndex < maResults.size() )
162 uno::Reference< ucb::XContent > xContent = maResults[ nIndex ]->xContent;
163 if ( xContent.is() )
165 // Already cached.
166 return xContent;
170 uno::Reference< ucb::XContentIdentifier > xId = queryContentIdentifier( nIndex );
171 if ( xId.is() )
175 uno::Reference< ucb::XContent > xContent = mxContent->getProvider()->queryContent( xId );
176 maResults[ nIndex ]->xContent = xContent;
177 return xContent;
179 catch ( ucb::IllegalIdentifierException& )
183 return uno::Reference< ucb::XContent >();
186 bool DataSupplier::getResult( sal_uInt32 nIndex )
188 if ( maResults.size() > nIndex ) // Result already present.
189 return true;
191 if ( getData() && maResults.size() > nIndex )
192 return true;
194 return false;
197 sal_uInt32 DataSupplier::totalCount()
199 getData();
200 return maResults.size();
203 sal_uInt32 DataSupplier::currentCount()
205 return maResults.size();
208 bool DataSupplier::isCountFinal()
210 return mbCountFinal;
213 uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
215 if ( nIndex < maResults.size() )
217 uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ]->xRow;
218 if ( xRow.is() )
220 // Already cached.
221 return xRow;
225 if ( getResult( nIndex ) )
227 uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) );
228 if ( xContent.is() )
232 uno::Reference< ucb::XCommandProcessor > xCmdProc(
233 xContent, uno::UNO_QUERY_THROW );
234 sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() );
235 ucb::Command aCmd;
236 aCmd.Name = "getPropertyValues";
237 aCmd.Handle = -1;
238 aCmd.Argument <<= getResultSet()->getProperties();
239 uno::Any aResult( xCmdProc->execute(
240 aCmd, nCmdId, getResultSet()->getEnvironment() ) );
241 uno::Reference< sdbc::XRow > xRow;
242 if ( aResult >>= xRow )
244 maResults[ nIndex ]->xRow = xRow;
245 return xRow;
248 catch ( uno::Exception const & )
253 return uno::Reference< sdbc::XRow >();
256 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
258 if ( nIndex < maResults.size() )
259 maResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
262 void DataSupplier::close()
266 void DataSupplier::validate() throw( ucb::ResultSetException )
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */