LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
downloadhelpers.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "downloadhelpers.h"
10#include <QFuture>
11#include <QFile>
12#include <QtDebug>
13#include <util/sll/either.h>
14#include <util/sll/visitor.h>
15#include <util/sys/paths.h>
16#include <util/xpc/util.h>
19
20namespace LC::Util
21{
22 std::optional<QFuture<TempResultType_t>> DownloadAsTemporary (IEntityManager *iem,
24 {
25 const auto& path = Util::GetTemporaryName ();
26 auto e = Util::MakeEntity (url,
27 path,
29 Internal |
32 e.Mime_ = std::move (params.Mime_);
33 e.Additional_ = std::move (params.Additional_);
34
35 auto res = iem->DelegateEntity (e);
36 if (!res)
37 {
39 << "delegation failed for"
40 << url;
41 return {};
42 }
43
44 return Util::Sequence (params.Context_, res.DownloadResult_) >>
46 {
49 {
50 QFile file { path };
51 auto removeGuard = Util::MakeScopeGuard ([&file] { file.remove (); });
52 if (!file.open (QIODevice::ReadOnly))
53 {
55 << "unable to open downloaded file"
56 << file.errorString ();
59 "unable to open file"
60 }));
61 }
62
64 }
65 };
66 }
67
68}
Proxy to core entity manager.
static Either Left(const L &l)
Definition either.h:119
static Either Right(R &&r)
Definition either.h:124
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
QString GetTemporaryName(const QString &pattern)
Returns a temporary filename.
Definition paths.cpp:143
std::optional< QFuture< TempResultType_t > > DownloadAsTemporary(IEntityManager *iem, const QUrl &url, DownloadParams params)
detail::ScopeGuard< F > MakeScopeGuard(const F &f)
Returns an object performing passed function on scope exit.
Definition util.h:155
Entity MakeEntity(const QVariant &entity, const QString &location, TaskParameters tp, const QString &mime)
Definition util.cpp:82
@ DoNotSaveInHistory
Definition structures.h:35
@ Internal
Definition structures.h:53
@ DoNotNotifyUser
Definition structures.h:48
@ NotPersistent
Definition structures.h:58