fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / gio / gio_seekable.cxx
blob509eb29e7bedbe8ddbec5eb82dc6cc518838b0ba
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 <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
21 #include <ucbhelper/cancelcommandexecution.hxx>
22 #include <string.h>
24 #include "gio_seekable.hxx"
25 #include "gio_content.hxx"
27 using namespace com::sun::star;
29 namespace gio
32 Seekable::Seekable(GSeekable *pStream) : mpStream(pStream)
34 if (!mpStream)
35 throw io::NotConnectedException();
38 Seekable::~Seekable()
42 void SAL_CALL Seekable::truncate()
43 throw( io::IOException, uno::RuntimeException, std::exception )
45 if (!mpStream)
46 throw io::NotConnectedException();
48 if (!g_seekable_can_truncate(mpStream))
49 throw io::IOException("Truncate unsupported",
50 static_cast< cppu::OWeakObject * >(this));
52 GError *pError=NULL;
53 if (!g_seekable_truncate(mpStream, 0, NULL, &pError))
54 convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
57 void SAL_CALL Seekable::seek( sal_Int64 location )
58 throw( lang::IllegalArgumentException, io::IOException, uno::RuntimeException, std::exception )
60 if (!mpStream)
61 throw io::NotConnectedException();
63 if (!g_seekable_can_seek(mpStream))
64 throw io::IOException("Seek unsupported",
65 static_cast< cppu::OWeakObject * >(this));
67 GError *pError=NULL;
68 if (!g_seekable_seek(mpStream, location, G_SEEK_SET, NULL, &pError))
69 convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
72 sal_Int64 SAL_CALL Seekable::getPosition() throw( io::IOException, uno::RuntimeException, std::exception )
74 if (!mpStream)
75 throw io::NotConnectedException();
77 return g_seekable_tell(mpStream);
80 sal_Int64 SAL_CALL Seekable::getLength() throw( io::IOException, uno::RuntimeException, std::exception )
82 if (!mpStream)
83 throw io::NotConnectedException();
85 bool bOk = false;
86 sal_uInt64 nSize = 0;
88 GFileInfo* pInfo = G_IS_FILE_INPUT_STREAM(mpStream)
89 ? g_file_input_stream_query_info(G_FILE_INPUT_STREAM(mpStream), G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, NULL)
90 : g_file_output_stream_query_info(G_FILE_OUTPUT_STREAM(mpStream), G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, NULL);
92 if (pInfo)
94 if (g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE))
96 nSize = g_file_info_get_size(pInfo);
97 bOk = true;
99 g_object_unref(pInfo);
102 if (!bOk)
104 GError *pError=NULL;
105 sal_Int64 nCurr = getPosition();
106 if (!g_seekable_seek(mpStream, 0, G_SEEK_END, NULL, &pError))
107 convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
108 nSize = getPosition();
109 seek(nCurr);
110 bOk = true;
113 return nSize;
116 uno::Any Seekable::queryInterface( const uno::Type &type ) throw( uno::RuntimeException, std::exception )
118 uno::Any aRet = ::cppu::queryInterface ( type,
119 static_cast< XSeekable * >( this ) );
121 if (!aRet.hasValue() && g_seekable_can_truncate(mpStream))
122 aRet = ::cppu::queryInterface ( type, static_cast< XTruncate * >( this ) );
124 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( type );
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */