1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2010 Teo Mrnjavac <teo@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-or-later |
6 | */ |
7 | |
8 | #ifndef KABOUT_APPLICATION_PERSON_MODEL_H |
9 | #define KABOUT_APPLICATION_PERSON_MODEL_H |
10 | |
11 | #include <KAboutData> |
12 | |
13 | #include <QAbstractListModel> |
14 | #include <QIcon> |
15 | #include <QNetworkReply> |
16 | #include <QPixmap> |
17 | #include <QUrl> |
18 | |
19 | namespace KDEPrivate |
20 | { |
21 | enum { |
22 | AVATAR_HEIGHT = 50, |
23 | AVATAR_WIDTH = 50, |
24 | MAIN_LINKS_HEIGHT = 32, |
25 | SOCIAL_LINKS_HEIGHT = 26, |
26 | MAX_SOCIAL_LINKS = 9, |
27 | }; |
28 | class KAboutApplicationPersonProfile; |
29 | |
30 | class KAboutApplicationPersonModel : public QAbstractListModel |
31 | { |
32 | Q_OBJECT |
33 | Q_PROPERTY(bool hasAnyAvatars READ hasAnyAvatars NOTIFY hasAnyAvatarsChanged) |
34 | Q_PROPERTY(bool showRemoteAvatars READ showRemoteAvatars WRITE setShowRemoteAvatars NOTIFY showRemoteAvatarsChanged) |
35 | public: |
36 | explicit KAboutApplicationPersonModel(const QList<KAboutPerson> &personList, QObject *parent = nullptr); |
37 | |
38 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
39 | int columnCount(const QModelIndex &parent = QModelIndex()) const override |
40 | { |
41 | Q_UNUSED(parent) |
42 | return 1; |
43 | } |
44 | QVariant data(const QModelIndex &index, int role) const override; |
45 | |
46 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
47 | |
48 | bool hasAvatarPixmaps() const |
49 | { |
50 | return m_hasAvatarPixmaps; |
51 | } |
52 | bool hasAnyAvatars() const |
53 | { |
54 | return m_hasAnyAvatars; |
55 | } |
56 | Q_SIGNAL void hasAnyAvatarsChanged(); |
57 | |
58 | const QString &providerName() const |
59 | { |
60 | return m_providerName; |
61 | } |
62 | |
63 | bool showRemoteAvatars() const |
64 | { |
65 | return m_showRemoteAvatars; |
66 | } |
67 | void setShowRemoteAvatars(bool value) |
68 | { |
69 | if (m_showRemoteAvatars != value) { |
70 | m_showRemoteAvatars = value; |
71 | Q_EMIT showRemoteAvatarsChanged(); |
72 | } |
73 | } |
74 | Q_SIGNAL void showRemoteAvatarsChanged(); |
75 | private Q_SLOTS: |
76 | void onAvatarJobFinished(); |
77 | |
78 | private: |
79 | const QList<KAboutPerson> m_personList; |
80 | QList<KAboutApplicationPersonProfile> m_profileList; |
81 | |
82 | bool m_hasAnyAvatars = false; |
83 | bool m_hasAvatarPixmaps = false; |
84 | bool m_showRemoteAvatars = false; |
85 | |
86 | QString m_providerName; |
87 | |
88 | QList<QNetworkReply *> m_ongoingAvatarFetches; |
89 | }; |
90 | |
91 | class KAboutApplicationPersonProfile |
92 | { |
93 | public: |
94 | KAboutApplicationPersonProfile() |
95 | : m_name() |
96 | , m_task() |
97 | , m_email() |
98 | , m_avatarUrl() |
99 | { |
100 | } // needed for QVariant |
101 | |
102 | KAboutApplicationPersonProfile(const QString &name, const QString &task, const QString &email, const QUrl &ocsUsername = QUrl()) |
103 | : m_name(name) |
104 | , m_task(task) |
105 | , m_email(email) |
106 | , m_avatarUrl(ocsUsername) |
107 | { |
108 | } |
109 | |
110 | void setHomepage(const QUrl &url) |
111 | { |
112 | m_homepage = url; |
113 | } |
114 | void setAvatar(const QPixmap &pixmap) |
115 | { |
116 | m_avatar = pixmap; |
117 | } |
118 | void setLocation(const QString &location) |
119 | { |
120 | m_location = location; |
121 | } |
122 | |
123 | const QString &name() const |
124 | { |
125 | return m_name; |
126 | } |
127 | const QString &task() const |
128 | { |
129 | return m_task; |
130 | } |
131 | const QString &email() const |
132 | { |
133 | return m_email; |
134 | } |
135 | const QUrl &avatarUrl() const |
136 | { |
137 | return m_avatarUrl; |
138 | } |
139 | const QUrl &homepage() const |
140 | { |
141 | return m_homepage; |
142 | } |
143 | const QPixmap &avatar() const |
144 | { |
145 | return m_avatar; |
146 | } |
147 | const QString &location() const |
148 | { |
149 | return m_location; |
150 | } |
151 | |
152 | private: |
153 | QString m_name; |
154 | QString m_task; |
155 | QString m_email; |
156 | QUrl m_avatarUrl; |
157 | QUrl m_homepage; |
158 | QPixmap m_avatar; |
159 | QString m_location; |
160 | }; |
161 | |
162 | } // namespace KDEPrivate |
163 | |
164 | Q_DECLARE_METATYPE(KDEPrivate::KAboutApplicationPersonProfile) |
165 | #endif // KABOUT_APPLICATION_PERSON_MODEL_H |
166 | |