File: kaboutapplicationpersonmodel_p.h

package info (click to toggle)
kde4libs 4%3A4.8.4-4%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,588 kB
  • sloc: cpp: 746,914; xml: 8,370; ansic: 6,295; java: 4,060; perl: 2,930; yacc: 2,462; sh: 1,225; python: 1,081; ruby: 337; lex: 278; makefile: 29
file content (237 lines) | stat: -rw-r--r-- 7,084 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* This file is part of the KDE libraries
   Copyright (C) 2010 Teo Mrnjavac <teo@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KABOUT_APPLICATION_PERSON_MODEL_H
#define KABOUT_APPLICATION_PERSON_MODEL_H

#include "kdeui/icons/kicon.h"
#include "dialogs/kaboutapplicationconfigattica_p.h"

#ifdef HAVE_ATTICA
#include <attica/providermanager.h>
#include <attica/provider.h>
#endif //HAVE_ATTICA

#include <kaboutdata.h>
#include <kurl.h>

#include <QtCore/QAbstractListModel>
#include <QtGui/QPixmap>
#include <QtNetwork/QNetworkReply>

// Forward declarations to make Attica-related members work
namespace Attica {
class BaseJob;
}

namespace KDEPrivate
{

class KAboutApplicationPersonProfile;
class KAboutApplicationPersonIconsJob;

class KAboutApplicationPersonModel : public QAbstractListModel
{
    Q_OBJECT
public:
    KAboutApplicationPersonModel( const QList< KAboutPerson > &personList,
                                  const QString &providerUrl = QString(),
                                  QObject *parent = 0 );

    int rowCount( const QModelIndex &parent = QModelIndex() ) const;
    int columnCount(const QModelIndex &parent = QModelIndex() ) const { Q_UNUSED( parent ) return 1; }
    QVariant data( const QModelIndex &index, int role ) const;

    Qt::ItemFlags flags( const QModelIndex &index ) const;

    bool hasAvatarPixmaps() const { return m_hasAvatarPixmaps; }

    const QString &providerName() const { return m_providerName; }

private Q_SLOTS:
    void onProvidersLoaded();
    void onPersonJobFinished( Attica::BaseJob *job );
    void onAvatarJobFinished( QNetworkReply *reply );
    void onOcsLinksJobFinished( KAboutApplicationPersonIconsJob *job );

private:
    void fetchOcsLinkIcons( int personProfileListIndex );

    QList< KAboutPerson > m_personList;
    QList< KAboutApplicationPersonProfile > m_profileList;

    QMap< int, QString > m_ocsLinkIconUrls;
    QMap< int, QPixmap > m_ocsLinkIcons;

    bool m_hasAvatarPixmaps;

#ifdef HAVE_ATTICA
    Attica::ProviderManager m_providerManager;
    Attica::Provider m_provider;
#endif //HAVE_ATTICA
    QString m_providerUrl;
    QString m_providerName;

    friend class KAboutApplicationPersonIconsJob;
};

//This list must be in sync with the one in KAboutApplicationPersonProfileOcsLink::prettyType()
static const char s_personOcsLinkAtticaTypes[][16] = {
    { "other" },
    { "Blog" },
    { "delicious" },
    { "Digg" },
    { "Facebook" },
    { "Homepage" },
    { "identi.ca" },
    { "libre.fm" },
    { "LinkedIn" },
    { "MySpace" },
    { "Reddit" },
    { "StackOverflow" },
    { "Twitter" },
    { "Wikipedia" },
    { "Xing" },
    { "YouTube" } };

class KAboutApplicationPersonProfileOcsLink
{
public:
    enum Type
    {
        Other = 0,
        Blog,
        Delicious,
        Digg,
        Facebook,
        Homepage,
        Identica,
        LibreFm,
        LinkedIn,
        MySpace,
        Reddit,
        StackOverflow,
        Twitter,
        Wikipedia,
        Xing,
        YouTube,
        NUM_ATTICA_LINK_TYPES
    };

    static Type typeFromAttica( const QString &atticaType );

    KAboutApplicationPersonProfileOcsLink( Type type, const KUrl &url )
        : m_type( type )
        , m_url( url )
    {}

    Type type() const { return m_type; }
    QString prettyType() const;
    void setIcon( const QIcon &icon ) { m_icon = icon; }
    const QIcon &icon() const { return m_icon; }
    const KUrl & url() const { return m_url; }

private:
    Type m_type;
    KUrl m_url;
    QIcon m_icon;
};

class KAboutApplicationPersonProfile
{
public:
    KAboutApplicationPersonProfile()
        : m_name()
        , m_task()
        , m_email()
        , m_ocsUsername() {} //needed for QVariant

    KAboutApplicationPersonProfile( const QString &name,
                                    const QString &task,
                                    const QString &email,
                                    const QString &ocsUsername = QString() )
        : m_name( name )
        , m_task( task )
        , m_email( email )
        , m_ocsUsername( ocsUsername )
    {}

    void setHomepage( const KUrl &url ) { m_homepage = url; }
    void setAvatar( const QPixmap &pixmap ) { m_avatar = pixmap; }
    void setLocation( const QString &location ) { m_location = location; }
    void setOcsProfileUrl( const QString &url ) { m_ocsProfileUrl = url; }
    void addAdditionalString( const QString &string ) { m_additionalStrings << string; }
    void setOcsLinks( const QList< KAboutApplicationPersonProfileOcsLink > &ocsLinks )
        { m_ocsLinks = ocsLinks; }

    const QString & name() const { return m_name; }
    const QString & task() const { return m_task; }
    const QString & email() const { return m_email; }
    const QString & ocsUsername() const { return m_ocsUsername; }
    const QString & ocsProfileUrl() const { return m_ocsProfileUrl; }
    const KUrl & homepage() const { return m_homepage; }
    const QPixmap & avatar() const { return m_avatar; }
    const QString & location() const { return m_location; }
    const QStringList & additionalStrings() const { return m_additionalStrings; }
    const QList< KAboutApplicationPersonProfileOcsLink > & ocsLinks() const { return m_ocsLinks; }

private:
    QString m_name;
    QString m_task;
    QString m_email;
    QString m_ocsUsername;
    QString m_ocsProfileUrl;
    KUrl m_homepage;
    QPixmap m_avatar;
    QString m_location;
    QStringList m_additionalStrings;
    QList< KAboutApplicationPersonProfileOcsLink > m_ocsLinks;
};

class KAboutApplicationPersonIconsJob : public QObject
{
    Q_OBJECT
public:
    KAboutApplicationPersonIconsJob( KAboutApplicationPersonModel *model,
                                    int personProfileListIndex );

    void start();

    int personProfileListIndex() const { return m_personProfileListIndex; }

    const QList< KAboutApplicationPersonProfileOcsLink > & ocsLinks() const { return m_ocsLinks; }

signals:
    void finished( KAboutApplicationPersonIconsJob *job);

private Q_SLOTS:
    void onJobFinished( QNetworkReply *reply );

private:
    void getIcons( int i );

    int m_personProfileListIndex;
    KAboutApplicationPersonModel *m_model;
    QList< KAboutApplicationPersonProfileOcsLink > m_ocsLinks;

    QNetworkAccessManager *m_manager;
};

} //namespace KDEPrivate

Q_DECLARE_METATYPE( KDEPrivate::KAboutApplicationPersonProfile )
#endif // KABOUT_APPLICATION_PERSON_MODEL_H