File indexing completed on 2024-04-14 14:29:57

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2010 Teo Mrnjavac <teo@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #ifndef KABOUT_APPLICATION_PERSON_MODEL_H
0009 #define KABOUT_APPLICATION_PERSON_MODEL_H
0010 
0011 #include <KAboutData>
0012 
0013 #include <QAbstractListModel>
0014 #include <QIcon>
0015 #include <QNetworkReply>
0016 #include <QPixmap>
0017 #include <QUrl>
0018 
0019 namespace KDEPrivate
0020 {
0021 enum {
0022     AVATAR_HEIGHT = 50,
0023     AVATAR_WIDTH = 50,
0024     MAIN_LINKS_HEIGHT = 32,
0025     SOCIAL_LINKS_HEIGHT = 26,
0026     MAX_SOCIAL_LINKS = 9,
0027 };
0028 class KAboutApplicationPersonProfile;
0029 
0030 class KAboutApplicationPersonModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033     Q_PROPERTY(bool hasAnyAvatars READ hasAnyAvatars NOTIFY hasAnyAvatarsChanged)
0034     Q_PROPERTY(bool showRemoteAvatars READ showRemoteAvatars WRITE setShowRemoteAvatars NOTIFY showRemoteAvatarsChanged)
0035 public:
0036     explicit KAboutApplicationPersonModel(const QList<KAboutPerson> &personList, QObject *parent = nullptr);
0037 
0038     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0039     int columnCount(const QModelIndex &parent = QModelIndex()) const override
0040     {
0041         Q_UNUSED(parent)
0042         return 1;
0043     }
0044     QVariant data(const QModelIndex &index, int role) const override;
0045 
0046     Qt::ItemFlags flags(const QModelIndex &index) const override;
0047 
0048     bool hasAvatarPixmaps() const
0049     {
0050         return m_hasAvatarPixmaps;
0051     }
0052     bool hasAnyAvatars() const
0053     {
0054         return m_hasAnyAvatars;
0055     }
0056     Q_SIGNAL void hasAnyAvatarsChanged();
0057 
0058     const QString &providerName() const
0059     {
0060         return m_providerName;
0061     }
0062 
0063     bool showRemoteAvatars() const
0064     {
0065         return m_showRemoteAvatars;
0066     }
0067     void setShowRemoteAvatars(bool value)
0068     {
0069         if (m_showRemoteAvatars != value) {
0070             m_showRemoteAvatars = value;
0071             Q_EMIT showRemoteAvatarsChanged();
0072         }
0073     }
0074     Q_SIGNAL void showRemoteAvatarsChanged();
0075 private Q_SLOTS:
0076     void onAvatarJobFinished();
0077 
0078 private:
0079     const QList<KAboutPerson> m_personList;
0080     QList<KAboutApplicationPersonProfile> m_profileList;
0081 
0082     bool m_hasAnyAvatars = false;
0083     bool m_hasAvatarPixmaps = false;
0084     bool m_showRemoteAvatars = false;
0085 
0086     QString m_providerName;
0087 
0088     QList<QNetworkReply *> m_ongoingAvatarFetches;
0089 };
0090 
0091 class KAboutApplicationPersonProfile
0092 {
0093 public:
0094     KAboutApplicationPersonProfile()
0095         : m_name()
0096         , m_task()
0097         , m_email()
0098         , m_ocsUsername()
0099     {
0100     } // needed for QVariant
0101 
0102     KAboutApplicationPersonProfile(const QString &name, const QString &task, const QString &email, const QString &ocsUsername = QString())
0103         : m_name(name)
0104         , m_task(task)
0105         , m_email(email)
0106         , m_ocsUsername(ocsUsername)
0107     {
0108     }
0109 
0110     void setHomepage(const QUrl &url)
0111     {
0112         m_homepage = url;
0113     }
0114     void setAvatar(const QPixmap &pixmap)
0115     {
0116         m_avatar = pixmap;
0117     }
0118     void setLocation(const QString &location)
0119     {
0120         m_location = location;
0121     }
0122     void setOcsProfileUrl(const QString &url)
0123     {
0124         m_ocsProfileUrl = url;
0125     }
0126 
0127     const QString &name() const
0128     {
0129         return m_name;
0130     }
0131     const QString &task() const
0132     {
0133         return m_task;
0134     }
0135     const QString &email() const
0136     {
0137         return m_email;
0138     }
0139     const QString &ocsUsername() const
0140     {
0141         return m_ocsUsername;
0142     }
0143     const QString &ocsProfileUrl() const
0144     {
0145         return m_ocsProfileUrl;
0146     }
0147     const QUrl &homepage() const
0148     {
0149         return m_homepage;
0150     }
0151     const QPixmap &avatar() const
0152     {
0153         return m_avatar;
0154     }
0155     const QString &location() const
0156     {
0157         return m_location;
0158     }
0159 
0160 private:
0161     QString m_name;
0162     QString m_task;
0163     QString m_email;
0164     QString m_ocsUsername;
0165     QString m_ocsProfileUrl;
0166     QUrl m_homepage;
0167     QPixmap m_avatar;
0168     QString m_location;
0169 };
0170 
0171 } // namespace KDEPrivate
0172 
0173 Q_DECLARE_METATYPE(KDEPrivate::KAboutApplicationPersonProfile)
0174 #endif // KABOUT_APPLICATION_PERSON_MODEL_H