1*46dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*46dbaceeSAndrew Rist * distributed with this work for additional information 6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 10*46dbaceeSAndrew Rist * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*46dbaceeSAndrew Rist * 13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an 15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 17*46dbaceeSAndrew Rist * specific language governing permissions and limitations 18*46dbaceeSAndrew Rist * under the License. 19*46dbaceeSAndrew Rist * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <rtl/ref.hxx> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <osl/conditn.hxx> 30cdf0e10cSrcweir #include <osl/file.h> 31cdf0e10cSrcweir 32cdf0e10cSrcweir struct DownloadInteractionHandler : public rtl::IReference 33cdf0e10cSrcweir { 34cdf0e10cSrcweir virtual bool checkDownloadDestination(const rtl::OUString& rFileName) = 0; 35cdf0e10cSrcweir 36cdf0e10cSrcweir // called if the destination file already exists, but resume is false 37cdf0e10cSrcweir virtual bool downloadTargetExists(const rtl::OUString& rFileName) = 0; 38cdf0e10cSrcweir 39cdf0e10cSrcweir // called when curl reports an error 40cdf0e10cSrcweir virtual void downloadStalled(const rtl::OUString& rErrorMessage) = 0; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // progress handler 43cdf0e10cSrcweir virtual void downloadProgressAt(sal_Int8 nPercent) = 0; 44cdf0e10cSrcweir 45cdf0e10cSrcweir // called on first progress notification 46cdf0e10cSrcweir virtual void downloadStarted(const rtl::OUString& rFileName, sal_Int64 nFileSize) = 0; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // called when download has been finished 49cdf0e10cSrcweir virtual void downloadFinished(const rtl::OUString& rFileName) = 0; 50cdf0e10cSrcweir }; 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweir class Download 54cdf0e10cSrcweir { 55cdf0e10cSrcweir public: Download(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & xContext,const rtl::Reference<DownloadInteractionHandler> & rHandler)56cdf0e10cSrcweir Download(const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& xContext, 57cdf0e10cSrcweir const rtl::Reference< DownloadInteractionHandler >& rHandler) : m_xContext(xContext), m_aHandler(rHandler) {}; 58cdf0e10cSrcweir 59cdf0e10cSrcweir // returns true when the content of rURL was successfully written to rLocalFile 60cdf0e10cSrcweir bool start(const rtl::OUString& rURL, const rtl::OUString& rFile, const rtl::OUString& rDestinationDir); 61cdf0e10cSrcweir 62cdf0e10cSrcweir // stops the download after the next write operation 63cdf0e10cSrcweir void stop(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir // returns true if the stop condition is set isStopped() const66cdf0e10cSrcweir bool isStopped() const 67cdf0e10cSrcweir { return sal_True == const_cast <Download *> (this)->m_aCondition.check(); }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir protected: 70cdf0e10cSrcweir 71cdf0e10cSrcweir // Determines the appropriate proxy settings for the given URL. Returns true if a proxy should be used 72cdf0e10cSrcweir void getProxyForURL(const rtl::OUString& rURL, rtl::OString& rHost, sal_Int32& rPort) const; 73cdf0e10cSrcweir 74cdf0e10cSrcweir private: 75cdf0e10cSrcweir osl::Condition m_aCondition; 76cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& m_xContext; 77cdf0e10cSrcweir const rtl::Reference< DownloadInteractionHandler > m_aHandler; 78cdf0e10cSrcweir }; 79cdf0e10cSrcweir 80cdf0e10cSrcweir 81