| 1 | /* ============================================================ |
|---|
| 2 | * |
|---|
| 3 | * This file is a part of kipi-plugins project |
|---|
| 4 | * http://www.kipi-plugins.org |
|---|
| 5 | * |
|---|
| 6 | * Date : 2010-01-07 |
|---|
| 7 | * Description : a plugin to export to a remote Piwigo server. |
|---|
| 8 | * |
|---|
| 9 | * Copyright (C) 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com> |
|---|
| 10 | * Copyright (C) 2006 by Colin Guthrie <kde@colin.guthr.ie> |
|---|
| 11 | * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com> |
|---|
| 12 | * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> |
|---|
| 13 | * Copyright (C) 2010 by Frederic Coiffier <frederic dot coiffier at free dot com> |
|---|
| 14 | * |
|---|
| 15 | * This program is free software; you can redistribute it |
|---|
| 16 | * and/or modify it under the terms of the GNU General |
|---|
| 17 | * Public License as published by the Free Software Foundation; |
|---|
| 18 | * either version 2, or (at your option) any later version. |
|---|
| 19 | * |
|---|
| 20 | * This program is distributed in the hope that it will be useful, |
|---|
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | * GNU General Public License for more details. |
|---|
| 24 | * |
|---|
| 25 | * ============================================================ */ |
|---|
| 26 | |
|---|
| 27 | #ifndef PIWIGOTALKER_H |
|---|
| 28 | #define PIWIGOTALKER_H |
|---|
| 29 | |
|---|
| 30 | // Qt includes |
|---|
| 31 | |
|---|
| 32 | #include <QObject> |
|---|
| 33 | #include <QList> |
|---|
| 34 | #include <QDateTime> |
|---|
| 35 | // Debug |
|---|
| 36 | #include <QTextStream> |
|---|
| 37 | #include <QFile> |
|---|
| 38 | |
|---|
| 39 | // KDE includes |
|---|
| 40 | |
|---|
| 41 | #include <KUrl> |
|---|
| 42 | #include <kio/job.h> |
|---|
| 43 | |
|---|
| 44 | namespace KIO |
|---|
| 45 | { |
|---|
| 46 | class Job; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | class KUrl; |
|---|
| 50 | template <class T> class QList; |
|---|
| 51 | |
|---|
| 52 | namespace KIPIPiwigoExportPlugin |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | class GAlbum; |
|---|
| 56 | class GPhoto; |
|---|
| 57 | |
|---|
| 58 | class PiwigoTalker : public QObject |
|---|
| 59 | { |
|---|
| 60 | Q_OBJECT |
|---|
| 61 | |
|---|
| 62 | public: |
|---|
| 63 | |
|---|
| 64 | enum State { |
|---|
| 65 | GE_LOGIN = 0, |
|---|
| 66 | GE_LISTALBUMS, |
|---|
| 67 | GE_LISTPHOTOS, |
|---|
| 68 | GE_CREATEALBUM, |
|---|
| 69 | GE_CHECKPHOTOEXIST, |
|---|
| 70 | GE_ADDPHOTO, |
|---|
| 71 | GE_ADDTHUMB, |
|---|
| 72 | GE_ADDPHOTOSUMMARY |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | public: |
|---|
| 76 | |
|---|
| 77 | PiwigoTalker(QWidget* parent); |
|---|
| 78 | ~PiwigoTalker(); |
|---|
| 79 | |
|---|
| 80 | static QString getAuthToken() { |
|---|
| 81 | return s_authToken; |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | bool loggedIn() const; |
|---|
| 85 | |
|---|
| 86 | void login(const KUrl& url, const QString& name, const QString& passwd); |
|---|
| 87 | void listAlbums(); |
|---|
| 88 | void listPhotos(const QString& albumName); |
|---|
| 89 | |
|---|
| 90 | void createAlbum(const QString& parentAlbumName, |
|---|
| 91 | const QString& albumName, |
|---|
| 92 | const QString& albumTitle, |
|---|
| 93 | const QString& albumCaption); |
|---|
| 94 | |
|---|
| 95 | bool addPhoto(int albumId, |
|---|
| 96 | const QString& photoPath, |
|---|
| 97 | const QString& caption = QString(), |
|---|
| 98 | bool captionIsTitle = true, bool captionIsDescription = false, |
|---|
| 99 | bool rescale = false, int maxDim = 600, int thumbDim = 120); |
|---|
| 100 | |
|---|
| 101 | void cancel(); |
|---|
| 102 | |
|---|
| 103 | Q_SIGNALS: |
|---|
| 104 | |
|---|
| 105 | void signalError(const QString& msg); |
|---|
| 106 | void signalLoginFailed(const QString& msg); |
|---|
| 107 | void signalBusy(bool val); |
|---|
| 108 | void signalAlbums(const QList<GAlbum>& albumList); |
|---|
| 109 | void signalPhotos(const QList<GPhoto>& photoList); |
|---|
| 110 | void signalAddPhotoSucceeded(); |
|---|
| 111 | void signalAddPhotoFailed(const QString& msg); |
|---|
| 112 | |
|---|
| 113 | private: |
|---|
| 114 | |
|---|
| 115 | void parseResponseLogin(const QByteArray& data); |
|---|
| 116 | void parseResponseListAlbums(const QByteArray& data); |
|---|
| 117 | void parseResponseListPhotos(const QByteArray& data); |
|---|
| 118 | void parseResponseCreateAlbum(const QByteArray& data); |
|---|
| 119 | void parseResponseDoesPhotoExist(const QByteArray& data); |
|---|
| 120 | void parseResponseAddPhoto(const QByteArray& data); |
|---|
| 121 | void parseResponseAddThumbnail(const QByteArray& data); |
|---|
| 122 | void parseResponseAddPhotoSummary(const QByteArray& data); |
|---|
| 123 | |
|---|
| 124 | QByteArray computeMD5Sum(const QString &filepath); |
|---|
| 125 | |
|---|
| 126 | private Q_SLOTS: |
|---|
| 127 | |
|---|
| 128 | void slotTalkerData(KIO::Job *job, const QByteArray& data); |
|---|
| 129 | void slotResult(KJob *job); |
|---|
| 130 | |
|---|
| 131 | private: |
|---|
| 132 | |
|---|
| 133 | QWidget* m_parent; |
|---|
| 134 | State m_state; |
|---|
| 135 | QString m_cookie; |
|---|
| 136 | KUrl m_url; |
|---|
| 137 | KIO::TransferJob* m_job; |
|---|
| 138 | bool m_loggedIn; |
|---|
| 139 | QByteArray m_talker_buffer; |
|---|
| 140 | |
|---|
| 141 | QByteArray m_md5sum; |
|---|
| 142 | QString m_path; |
|---|
| 143 | int m_albumId; |
|---|
| 144 | QString m_thumbpath; |
|---|
| 145 | QString m_comment; |
|---|
| 146 | QString m_name; |
|---|
| 147 | QDateTime m_date; |
|---|
| 148 | |
|---|
| 149 | static QString s_authToken; |
|---|
| 150 | }; |
|---|
| 151 | |
|---|
| 152 | } // namespace KIPIPiwigoExportPlugin |
|---|
| 153 | |
|---|
| 154 | #endif /* PIWIGOTALKER_H */ |
|---|