digiKam
yftalker.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-11-14
7  * Description : a tool to export items to YandexFotki web service
8  *
9  * Copyright (C) 2010 by Roman Tsisyk <roman at tsisyk dot com>
10  * Copyright (C) 2010-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * 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 #ifndef DIGIKAM_YF_TALKER_H
25 #define DIGIKAM_YF_TALKER_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 #include <QString>
31 #include <QDomElement>
32 
33 // Local includes
34 
35 #include "yfphoto.h"
36 #include "yfalbum.h"
37 
38 class QNetworkReply;
39 
40 namespace DigikamGenericYFPlugin
41 {
42 
43 class YFTalker : public QObject
44 {
45  Q_OBJECT
46 
47 public:
48 
49  // We use FSM for async I/O
50 
51  enum State
52  {
53  // FSM states
56  STATE_ERROR = 0x40,
57 
61 /*
62  // for future use
63  STATE_CHECKTOKEN = STATE_UNAUTHENTICATED | 0x4,
64  STATE_CHECKTOKEN_INVALID = STATE_UNAUTHENTICATED | 0x5,
65  STATE_CHECKTOKEN_DONE = STATE_UNAUTHENTICATED | 0x6,
66 */
70 
75 
79 
83 
89 
93  };
94 
95 public:
96 
97  explicit YFTalker(QObject* const parent = nullptr);
98  ~YFTalker() override;
99 
100 public:
101 
102  // Fields
103 
104  State state() const;
105  const QString& sessionKey() const;
106  const QString& sessionId() const;
107  const QString& token() const;
108 
109  const QString& login() const;
110  void setLogin(const QString& login);
111 
112  const QString& password() const;
113  void setPassword(const QString& password);
114 
115  bool isAuthenticated() const;
116  bool isErrorState() const;
117  const QList<YandexFotkiAlbum>& albums() const;
118  const QList<YFPhoto>& photos() const;
119 
120 public:
121 
122  // Actions
123  void getService();
124 /*
125  void checkToken();
126 */
127  void getSession();
128  void getToken();
129 
130  void listAlbums();
131  void listPhotos(const YandexFotkiAlbum& album);
132  void updatePhoto(YFPhoto& photo, const YandexFotkiAlbum& album);
133  void updateAlbum(YandexFotkiAlbum& album);
134 
135  void reset();
136  void cancel();
137 
138 public:
139 
141  static const QString USERPAGE_URL;
142  static const QString USERPAGE_DEFAULT_URL;
143 
144 Q_SIGNALS:
145 
147  void signalError();
151 
156 
157 private Q_SLOTS:
158 
159  void slotFinished(QNetworkReply* reply);
160 
161  void slotParseResponseGetSession();
162 /*
163  void slotParseResponseCheckToken();
164 */
165  void slotParseResponseGetToken();
166  void slotParseResponseGetService();
167  void slotParseResponseListAlbums();
168 
169  void slotParseResponseListPhotos();
170  bool slotParsePhotoXml(const QDomElement& entryElem,
171  YFPhoto& photo);
172 
173  void slotParseResponseUpdatePhotoFile();
174  void slotParseResponseUpdatePhotoInfo();
175  void slotParseResponseUpdateAlbum();
176 
177 private:
178 
180  void updatePhotoFile(YFPhoto& photo);
181  void updatePhotoInfo(YFPhoto& photo);
182 
184  void updateAlbumCreate(YandexFotkiAlbum& album);
185 
187  void setErrorState(State state);
188 
189  void listAlbumsNext();
190 
192  void listPhotosNext();
193 
194 private:
195 
196  class Private;
197  Private* const d;
198 };
199 
200 } // namespace DigikamGenericYFPlugin
201 
202 #endif // DIGIKAM_YF_TALKER_H
Definition: yfphoto.h:38
Definition: yftalker.h:44
void signalError()
emits when we are in a bad state
static const QString USERPAGE_URL
API-related public constants.
Definition: yftalker.h:141
void signalListPhotosDone(const QList< YFPhoto > &)
const QString & token() const
Definition: yftalker.cpp:151
void getToken()
Definition: yftalker.cpp:241
const QString & sessionId() const
Definition: yftalker.cpp:146
const QList< YandexFotkiAlbum > & albums() const
Definition: yftalker.cpp:186
void setPassword(const QString &password)
Definition: yftalker.cpp:171
const QString & sessionKey() const
Definition: yftalker.cpp:141
bool isErrorState() const
Definition: yftalker.cpp:181
State state() const
Definition: yftalker.cpp:136
void signalUpdatePhotoDone(YFPhoto &)
void listPhotos(const YandexFotkiAlbum &album)
Definition: yftalker.cpp:299
const QString & login() const
Definition: yftalker.cpp:156
void updateAlbum(YandexFotkiAlbum &album)
Definition: yftalker.cpp:471
bool isAuthenticated() const
Definition: yftalker.cpp:176
void reset()
Definition: yftalker.cpp:532
void getSession()
Definition: yftalker.cpp:227
const QString & password() const
Definition: yftalker.cpp:166
void setLogin(const QString &login)
Definition: yftalker.cpp:161
void listAlbums()
Definition: yftalker.cpp:270
void getService()
Definition: yftalker.cpp:196
void updatePhoto(YFPhoto &photo, const YandexFotkiAlbum &album)
Definition: yftalker.cpp:327
~YFTalker() override
Definition: yftalker.cpp:130
YFTalker(QObject *const parent=nullptr)
Definition: yftalker.cpp:120
State
Definition: yftalker.h:52
@ STATE_GETSESSION
Definition: yftalker.h:67
@ STATE_GETSERVICE
Definition: yftalker.h:58
@ STATE_UPDATEALBUM
Definition: yftalker.h:90
@ STATE_UPDATEALBUM_DONE
Definition: yftalker.h:92
@ STATE_LISTPHOTOS
Definition: yftalker.h:80
@ STATE_GETTOKEN_DONE
simple alias
Definition: yftalker.h:74
@ STATE_GETSERVICE_ERROR
Definition: yftalker.h:59
@ STATE_GETTOKEN_ERROR
Definition: yftalker.h:73
@ STATE_LISTALBUMS_DONE
Definition: yftalker.h:78
@ STATE_GETSERVICE_DONE
Definition: yftalker.h:60
@ STATE_UNAUTHENTICATED
Definition: yftalker.h:54
@ STATE_UPDATEPHOTO_DONE
Definition: yftalker.h:88
@ STATE_LISTPHOTOS_DONE
Definition: yftalker.h:82
@ STATE_UPDATEPHOTO_INFO_ERROR
Definition: yftalker.h:87
@ STATE_GETSESSION_DONE
Definition: yftalker.h:69
@ STATE_GETTOKEN
Definition: yftalker.h:71
@ STATE_LISTALBUMS
Definition: yftalker.h:76
@ STATE_UPDATEPHOTO_INFO
Definition: yftalker.h:86
@ STATE_UPDATEALBUM_ERROR
Definition: yftalker.h:91
@ STATE_UPDATEPHOTO_FILE
Definition: yftalker.h:84
@ STATE_INVALID_CREDENTIALS
Definition: yftalker.h:72
@ STATE_UPDATEPHOTO_FILE_ERROR
Definition: yftalker.h:85
@ STATE_AUTHENTICATED
Definition: yftalker.h:55
@ STATE_LISTALBUMS_ERROR
Definition: yftalker.h:77
@ STATE_LISTPHOTOS_ERROR
Definition: yftalker.h:81
@ STATE_ERROR
Definition: yftalker.h:56
@ STATE_GETSESSION_ERROR
Definition: yftalker.h:68
static const QString USERPAGE_DEFAULT_URL
Definition: yftalker.h:142
const QList< YFPhoto > & photos() const
Definition: yftalker.cpp:191
void signalListAlbumsDone(const QList< YandexFotkiAlbum > &)
void cancel()
Definition: yftalker.cpp:544
Definition: piwigotalker.h:48
Definition: yfalbum.cpp:27