libQuotient
A Qt library for building matrix clients
avatar.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017 Kitsune Ral <kitsune-ral@users.sf.net>
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 
4 #pragma once
5 
6 #include "util.h"
7 
8 #include <QtCore/QFuture>
9 #include <QtCore/QUrl>
10 #include <QtGui/QIcon>
11 
12 #include <functional>
13 
14 namespace Quotient {
15 class Connection;
16 
17 class QUOTIENT_API Avatar {
18 public:
19  explicit Avatar(Connection* parent, const QUrl& url = {});
20 
21 #ifdef __cpp_lib_move_only_function // AppleClang 15 doesn't have it
22  using get_callback_t = std::move_only_function<void()>;
23  using upload_callback_t = std::move_only_function<void(QUrl)>;
24 #else
25  using get_callback_t = std::function<void()>;
26  using upload_callback_t = std::function<void(QUrl)>;
27 #endif
28 
29 
30  QImage get(int dimension, get_callback_t callback) const;
31  QImage get(int width, int height, get_callback_t callback) const;
32 
33  [[deprecated("Use the QFuture-returning overload instead")]]
34  bool upload(const QString& fileName, upload_callback_t callback) const;
35  [[deprecated("Use the QFuture-returning overload instead")]]
36  bool upload(QIODevice* source, upload_callback_t callback) const;
37  QFuture<QUrl> upload(const QString& fileName) const;
38  QFuture<QUrl> upload(QIODevice* source) const;
39 
40  bool isEmpty() const;
41  QString mediaId() const;
42  QUrl url() const;
43  bool updateUrl(const QUrl& newUrl);
44 
45  static bool isUrlValid(const QUrl& u);
46 
47 private:
48  class Private;
49  ImplPtr<Private> d;
50 };
51 } // namespace Quotient