LibreOffice Module extensions (master) 1
download.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25
26#include <com/sun/star/uno/XComponentContext.hpp>
27
28#include <rtl/ref.hxx>
29#include <rtl/ustring.hxx>
30#include <osl/conditn.hxx>
32
34{
35 virtual bool checkDownloadDestination(const OUString& rFileName) = 0;
36
37 // called if the destination file already exists, but resume is false
38 virtual bool downloadTargetExists(const OUString& rFileName) = 0;
39
40 // called when curl reports an error
41 virtual void downloadStalled(const OUString& rErrorMessage) = 0;
42
43 // progress handler
44 virtual void downloadProgressAt(sal_Int8 nPercent) = 0;
45
46 // called on first progress notification
47 virtual void downloadStarted(const OUString& rFileName, sal_Int64 nFileSize) = 0;
48
49 // called when download has been finished
50 virtual void downloadFinished(const OUString& rFileName) = 0;
51
52protected:
53 virtual ~DownloadInteractionHandler() override {}
54};
55
57{
58public:
59 Download(const css::uno::Reference<css::uno::XComponentContext>& xContext,
61 : m_xContext(xContext)
62 , m_aHandler(rHandler){};
63
64 // returns true when the content of rURL was successfully written to rLocalFile
65 bool start(const OUString& rURL, const OUString& rFile, const OUString& rDestinationDir);
66
67 // stops the download after the next write operation
68 void stop();
69
70protected:
71 // Determines the appropriate proxy settings for the given URL. Returns true if a proxy should be used
72 void getProxyForURL(std::u16string_view rURL, OString& rHost, sal_Int32& rPort) const;
73
74private:
75 osl::Condition m_aCondition;
76 const css::uno::Reference<css::uno::XComponentContext>& m_xContext;
78};
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool start(const OUString &rURL, const OUString &rFile, const OUString &rDestinationDir)
Definition: download.cxx:335
void getProxyForURL(std::u16string_view rURL, OString &rHost, sal_Int32 &rPort) const
Definition: download.cxx:172
Download(const css::uno::Reference< css::uno::XComponentContext > &xContext, const rtl::Reference< DownloadInteractionHandler > &rHandler)
Definition: download.hxx:59
const rtl::Reference< DownloadInteractionHandler > m_aHandler
Definition: download.hxx:77
const css::uno::Reference< css::uno::XComponentContext > & m_xContext
Definition: download.hxx:76
osl::Condition m_aCondition
Definition: download.hxx:75
void stop()
Definition: download.cxx:422
virtual bool downloadTargetExists(const OUString &rFileName)=0
virtual ~DownloadInteractionHandler() override
Definition: download.hxx:53
virtual bool checkDownloadDestination(const OUString &rFileName)=0
virtual void downloadFinished(const OUString &rFileName)=0
virtual void downloadStarted(const OUString &rFileName, sal_Int64 nFileSize)=0
virtual void downloadStalled(const OUString &rErrorMessage)=0
virtual void downloadProgressAt(sal_Int8 nPercent)=0
signed char sal_Int8