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: download.hxx,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 ************************************************************************/
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <rtl/ref.hxx>
35 #include <rtl/ustring.hxx>
36 #include <osl/conditn.hxx>
39 struct DownloadInteractionHandler
: public rtl::IReference
41 // called if the destination file already exists, but resume is false
42 virtual bool downloadTargetExists(const rtl::OUString
& rFileName
) = 0;
44 // called when curl reports an error
45 virtual void downloadStalled(const rtl::OUString
& rErrorMessage
) = 0;
48 virtual void downloadProgressAt(sal_Int8 nPercent
) = 0;
50 // called on first progress notification
51 virtual void downloadStarted(const rtl::OUString
& rFileName
, sal_Int64 nFileSize
) = 0;
53 // called when download has been finished
54 virtual void downloadFinished(const rtl::OUString
& rFileName
) = 0;
61 Download(const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& xContext
,
62 const rtl::Reference
< DownloadInteractionHandler
>& rHandler
) : m_xContext(xContext
), m_aHandler(rHandler
) {};
64 // returns true when the content of rURL was successfully written to rLocalFile
65 bool start(const rtl::OUString
& rURL
, const rtl::OUString
& rFile
, const rtl::OUString
& rDestinationDir
);
67 // stops the download after the next write operation
70 // returns true if the stop condition is set
71 bool isStopped() const
72 { return sal_True
== const_cast <Download
*> (this)->m_aCondition
.check(); };
76 // Determines the appropriate proxy settings for the given URL. Returns true if a proxy should be used
77 void getProxyForURL(const rtl::OUString
& rURL
, rtl::OString
& rHost
, sal_Int32
& rPort
) const;
80 osl::Condition m_aCondition
;
81 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& m_xContext
;
82 const rtl::Reference
< DownloadInteractionHandler
> m_aHandler
;