1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gio_datasupplier.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <ucbhelper/contentidentifier.hxx>
34 #include <ucbhelper/providerhelper.hxx>
36 #include <com/sun/star/ucb/OpenMode.hpp>
38 #include "gio_datasupplier.hxx"
39 #include "gio_content.hxx"
40 #include "gio_provider.hxx"
44 using namespace com::sun::star
;
51 typedef std::vector
< ResultListEntry
* > ResultList
;
53 DataSupplier::DataSupplier( const uno::Reference
< lang::XMultiServiceFactory
>& rxSMgr
,
54 const uno::Reference
< ::gio::Content
>& rContent
, sal_Int32 nOpenMode
)
55 : mxContent(rContent
), m_xSMgr(rxSMgr
), mnOpenMode(nOpenMode
), mbCountFinal(false)
59 bool DataSupplier::getData()
64 GFile
*pFile
= mxContent
->getGFile();
66 GFileEnumerator
* pEnumerator
= g_file_enumerate_children(pFile
, "*",
67 G_FILE_QUERY_INFO_NONE
, NULL
, NULL
);
72 GFileInfo
*pInfo
= NULL
;
73 while ((pInfo
= g_file_enumerator_next_file (pEnumerator
, NULL
, NULL
)))
77 case ucb::OpenMode::FOLDERS
:
78 if (g_file_info_get_file_type(pInfo
) != G_FILE_TYPE_DIRECTORY
)
81 case ucb::OpenMode::DOCUMENTS
:
82 if (g_file_info_get_file_type(pInfo
) != G_FILE_TYPE_REGULAR
)
85 case ucb::OpenMode::ALL
:
90 maResults
.push_back( new ResultListEntry( pInfo
) );
91 g_object_unref(pInfo
);
94 mbCountFinal
= sal_True
;
96 g_file_enumerator_close(pEnumerator
, NULL
, NULL
);
100 DataSupplier::~DataSupplier()
102 ResultList::const_iterator it
= maResults
.begin();
103 ResultList::const_iterator end
= maResults
.end();
112 ::rtl::OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
114 if ( nIndex
< maResults
.size() )
116 ::rtl::OUString aId
= maResults
[ nIndex
]->aId
;
117 if ( aId
.getLength() )
124 if ( getResult( nIndex
) )
126 GFile
*pFile
= mxContent
->getGFile();
127 char* parent
= g_file_get_uri(pFile
);
128 rtl::OUString aId
= rtl::OUString::createFromAscii( parent
);
132 g_uri_escape_string( g_file_info_get_name(maResults
[ nIndex
]->pInfo
) , NULL
, false);
134 if ( ( aId
.lastIndexOf( '/' ) + 1 ) != aId
.getLength() )
135 aId
+= rtl::OUString::createFromAscii( "/" );
137 aId
+= rtl::OUString::createFromAscii( escaped_name
);
139 g_free( escaped_name
);
141 maResults
[ nIndex
]->aId
= aId
;
147 return ::rtl::OUString();
150 uno::Reference
< ucb::XContentIdentifier
> DataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
152 if ( nIndex
< maResults
.size() )
154 uno::Reference
< ucb::XContentIdentifier
> xId
= maResults
[ nIndex
]->xId
;
162 ::rtl::OUString aId
= queryContentIdentifierString( nIndex
);
163 if ( aId
.getLength() )
165 uno::Reference
< ucb::XContentIdentifier
> xId
= new ucbhelper::ContentIdentifier( aId
);
166 maResults
[ nIndex
]->xId
= xId
;
170 return uno::Reference
< ucb::XContentIdentifier
>();
173 uno::Reference
< ucb::XContent
> DataSupplier::queryContent( sal_uInt32 nIndex
)
175 if ( nIndex
< maResults
.size() )
177 uno::Reference
< ucb::XContent
> xContent
= maResults
[ nIndex
]->xContent
;
185 uno::Reference
< ucb::XContentIdentifier
> xId
= queryContentIdentifier( nIndex
);
190 uno::Reference
< ucb::XContent
> xContent
= mxContent
->getProvider()->queryContent( xId
);
191 maResults
[ nIndex
]->xContent
= xContent
;
194 catch ( ucb::IllegalIdentifierException
& )
198 return uno::Reference
< ucb::XContent
>();
201 sal_Bool
DataSupplier::getResult( sal_uInt32 nIndex
)
203 if ( maResults
.size() > nIndex
) // Result already present.
206 if ( getData() && maResults
.size() > nIndex
)
212 sal_uInt32
DataSupplier::totalCount()
215 return maResults
.size();
218 sal_uInt32
DataSupplier::currentCount()
220 return maResults
.size();
223 sal_Bool
DataSupplier::isCountFinal()
228 uno::Reference
< sdbc::XRow
> DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
230 if ( nIndex
< maResults
.size() )
232 uno::Reference
< sdbc::XRow
> xRow
= maResults
[ nIndex
]->xRow
;
240 if ( getResult( nIndex
) )
242 uno::Reference
< sdbc::XRow
> xRow
= Content::getPropertyValuesFromGFileInfo(
243 maResults
[ nIndex
]->pInfo
, m_xSMgr
, getResultSet()->getProperties());
245 maResults
[ nIndex
]->xRow
= xRow
;
248 return uno::Reference
< sdbc::XRow
>();
251 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
253 if ( nIndex
< maResults
.size() )
254 maResults
[ nIndex
]->xRow
= uno::Reference
< sdbc::XRow
>();
257 void DataSupplier::close()
261 void DataSupplier::validate() throw( ucb::ResultSetException
)