flickrtalker.h 4.58 KB
Newer Older
1
/* ============================================================
2
3
 *
 * This file is a part of kipi-plugins project
4
 * http://www.digikam.org
5
6
7
8
 *
 * Date        : 2005-07-07
 * Description : a kipi plugin to export images to Flickr web service
 *
Andi Clemens's avatar
Andi Clemens committed
9
10
 * Copyright (C) 2005-2009 by Vardhman Jain <vardhman at gmail dot com>
 * Copyright (C) 2009      by Gilles Caulier <caulier dot gilles at gmail dot com>
11
12
13
14
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
15
 * either version 2, or (at your option) any later version.
16
17
18
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU General Public License for more details.
21
 *
22
23
24
25
26
 * ============================================================ */

#ifndef FLICKRTALKER_H
#define FLICKRTALKER_H

27
// Qt includes
28

Gilles Caulier's avatar
Gilles Caulier committed
29
30
31
#include <QList>
#include <QString>
#include <QObject>
32

33
// KDE includes
34

35
#include <kurl.h>
Gilles Caulier's avatar
polish    
Gilles Caulier committed
36
#include <kio/job.h>
37

Andi Clemens's avatar
Andi Clemens committed
38
// Local includes
39
40
41

#include "flickritem.h"

42
class QProgressDialog;
43
44
45
46
47
48
49

namespace KIPIFlickrExportPlugin
{

class GAlbum;
class GPhoto;
class FPhotoInfo;
50
class FPhotoSet;
51

52
53
54
55
56
57
class FlickrTalker : public QObject
{
    Q_OBJECT

public:

Andi Clemens's avatar
Andi Clemens committed
58
    enum State
59
    {
60
        FE_LOGIN = 0,
61
        FE_LISTPHOTOSETS,
62
63
64
65
66
67
        FE_LISTPHOTOS,
        FE_GETPHOTOPROPERTY,
        FE_ADDPHOTO,
        FE_GETFROB,
        FE_CHECKTOKEN,
        FE_GETTOKEN,
68
69
70
        FE_GETAUTHORIZED,
        FE_CREATEPHOTOSET,
        FE_ADDPHOTOTOPHOTOSET
71
72
    };

73
74
public:

Gilles Caulier's avatar
Gilles Caulier committed
75
    FlickrTalker(QWidget* const parent, const QString& serviceName);
76
77
    ~FlickrTalker();

Laurent Montel's avatar
Laurent Montel committed
78
79
    QString getUserName() const;
    QString getUserId() const;
Gilles Caulier's avatar
fix API    
Gilles Caulier committed
80
81
82
    void    getFrob();
    void    getToken();
    void    checkToken(const QString& token);
83
    void    getPhotoProperty(const QString& method, const QStringList& argList);
Gilles Caulier's avatar
polish    
Gilles Caulier committed
84
    void    cancel();
Gilles Caulier's avatar
polish    
Gilles Caulier committed
85

Gilles Caulier's avatar
polish    
Gilles Caulier committed
86
87
    void    listPhotoSets();
    void    listPhotos(const QString& albumName);
88
89
90
91
    void    createPhotoSet(const QString& name,
                           const QString& title,
                           const QString& desc,
                           const QString& primaryPhotoId);
92

Gilles Caulier's avatar
polish    
Gilles Caulier committed
93
    void    addPhotoToPhotoSet(const QString& photoId, const QString& photoSetId);
Gilles Caulier's avatar
polish    
Gilles Caulier committed
94
    bool    addPhoto(const QString& photoPath, const FPhotoInfo& info,
95
                     bool sendOriginal = false, bool rescale=false, int maxDim=600, int imageQuality=85);
96
97

public:
Gilles Caulier's avatar
polish    
Gilles Caulier committed
98

Gilles Caulier's avatar
polish    
Gilles Caulier committed
99
    QProgressDialog*         m_authProgressDlg;
100
    QLinkedList <FPhotoSet>* m_photoSetsList;
Gilles Caulier's avatar
polish    
Gilles Caulier committed
101
    FPhotoSet                m_selectedPhotoSet;
102

103
Q_SIGNALS:
104

Gilles Caulier's avatar
fix API    
Gilles Caulier committed
105
    void signalError(const QString& msg);
Andi Clemens's avatar
Andi Clemens committed
106
    //  void signalLoginFailed( const QString& msg );
Gilles Caulier's avatar
fix API    
Gilles Caulier committed
107
    void signalBusy(bool val);
Gilles Caulier's avatar
Gilles Caulier committed
108
109
    void signalAlbums(const QList<GAlbum>& albumList);
    void signalPhotos(const QList<GPhoto>& photoList);
Gilles Caulier's avatar
fix API    
Gilles Caulier committed
110
    void signalAddPhotoSucceeded();
111
    void signalAddPhotoSetSucceeded();
112
113
    void signalListPhotoSetsSucceeded();
    void signalListPhotoSetsFailed(QString& msg);
Gilles Caulier's avatar
fix API    
Gilles Caulier committed
114
115
116
    void signalAddPhotoFailed(const QString& msg);
    void signalListPhotoSetsFailed(const QString& msg);
    void signalAuthenticate();
117
118
    void signalTokenObtained(const QString& token);

119
120
private:

Andi Clemens's avatar
Andi Clemens committed
121
    //  void parseResponseLogin(const QByteArray& data);
Gilles Caulier's avatar
polish    
Gilles Caulier committed
122
123
124
125
126
127
128
129
    void parseResponseListPhotoSets(const QByteArray& data);
    void parseResponseListPhotos(const QByteArray& data);
    void parseResponseCreateAlbum(const QByteArray& data);
    void parseResponseAddPhoto(const QByteArray& data);
    void parseResponseGetFrob(const QByteArray& data);
    void parseResponseGetToken(const QByteArray& data);
    void parseResponseCheckToken(const QByteArray& data);
    void parseResponsePhotoProperty(const QByteArray& data);
130
131
    void parseResponseCreatePhotoSet(const QByteArray& data);
    void parseResponseAddPhotoToPhotoSet(const QByteArray& data);
Gilles Caulier's avatar
polish    
Gilles Caulier committed
132

133
    QString getApiSig(const QString& secret, const KUrl& url);
134

135
private Q_SLOTS:
136

Gilles Caulier's avatar
fix API    
Gilles Caulier committed
137
    void slotError(const QString& msg);
Gilles Caulier's avatar
polish    
Gilles Caulier committed
138
    void slotAuthenticate();
Andi Clemens's avatar
Andi Clemens committed
139
140
    void data(KIO::Job* job, const QByteArray& data);
    void slotResult(KJob* job);
141
142
143
144

private:

    QWidget*   m_parent;
Andi Clemens's avatar
Andi Clemens committed
145
    //  QString    m_cookie;
146
147
    QByteArray m_buffer;

148
149
150
151
    QString    m_serviceName;
    QString    m_apiUrl;
    QString    m_authUrl;
    QString    m_uploadUrl;
152
153
154
155
156
157
    QString    m_apikey;
    QString    m_secret;
    QString    m_frob;
    QString    m_token;
    QString    m_username;
    QString    m_userId;
Gilles Caulier's avatar
Gilles Caulier committed
158

159
160
161
    KIO::Job*  m_job;

    State      m_state;
162
163
};

164
} // namespace KIPIFlickrExportPlugin
165
166

#endif /* FLICKRTALKER_H */