1 /*
2  * Copyright (C) 2011, 2015  Alexander Potashev <aspotashev@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) version 3, or any
8  * later version accepted by the membership of KDE e.V. (or its
9  * successor approved by the membership of KDE e.V.), which shall
10  * act as a proxy defined in Section 6 of version 3 of the license.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "editalbumjob.h"
22 
23 #include <KLocalizedString>
24 
25 #include <QtCore/QDebug>
26 #include <QtCore/QJsonValue>
27 
28 namespace Vkontakte
29 {
30 
EditAlbumJob(const QString & accessToken,int aid,const QString & title,const QString & description,int privacy,int comment_privacy)31 EditAlbumJob::EditAlbumJob(const QString &accessToken,
32                            int aid, const QString &title, const QString &description,
33                            int privacy, int comment_privacy)
34     : VkontakteJob(accessToken, QStringLiteral("photos.editAlbum"), true)
35     , d(0)
36 {
37     addQueryItem(QStringLiteral("aid"), QString::number(aid));
38     addQueryItem(QStringLiteral("title"), title);
39     if (!description.isEmpty())
40         addQueryItem(QStringLiteral("description"), description);
41     if (privacy != AlbumInfo::PRIVACY_UNKNOWN)
42         addQueryItem(QStringLiteral("privacy"), QString::number(privacy));
43     if (comment_privacy != AlbumInfo::PRIVACY_UNKNOWN)
44         addQueryItem(QStringLiteral("comment_privacy"), QString::number(comment_privacy));
45 }
46 
handleData(const QJsonValue & data)47 void EditAlbumJob::handleData(const QJsonValue &data)
48 {
49     if (data.toInt(-1) != 1)
50     {
51         setError(1);
52         setErrorText(i18n("Failed to edit album"));
53         qWarning() << "Failed to edit album";
54     }
55 }
56 
57 } /* namespace Vkontakte */
58