First semi-working implementation in c++ of remote Danbooru calls

This commit is contained in:
Luca Beltrame 2013-02-24 18:28:37 +01:00
parent c0cf369b92
commit fc691a9301
9 changed files with 1341 additions and 0 deletions

105
src/libdanbooru/utils.cpp Normal file
View file

@ -0,0 +1,105 @@
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Luca Beltrame <lbeltrame@kde.org>
*
* 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; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "utils.h"
namespace Danbooru {
KUrl requestUrl(KUrl& url, const QString& path,
const QString& username, const QString& password,
const dictMap& parameters, const QStringList& tags)
{
KUrl danbooruUrl = KUrl(url);
danbooruUrl.addPath(path);
// If we have parameters, add them
if (!parameters.isEmpty()) {
QMap<QString, QString>::const_iterator iter;
for (iter = parameters.constBegin(); iter!= parameters.constEnd();
++iter) {
danbooruUrl.addQueryItem(iter.key(), iter.value());
}
}
// Now, let's add tags should we have them
if (!tags.isEmpty()) {
QByteArray encoded_tags = QUrl::toPercentEncoding(tags.join(" "));
danbooruUrl.addEncodedQueryItem("tags", encoded_tags);
}
if (!username.isEmpty() && !password.isEmpty()) {
danbooruUrl.setUserName(username);
danbooruUrl.setPassword(password);
}
return danbooruUrl;
}
KUrl requestUrl(KUrl& url, const QString& path, const QString& username,
const QString& password, const dictMap& parameters)
{
KUrl danbooruUrl = KUrl(url);
danbooruUrl.addPath(path);
// If we have parameters, add them
if (!parameters.isEmpty()) {
QMap<QString, QString>::const_iterator iter;
for (iter = parameters.constBegin(); iter!= parameters.constEnd();
++iter) {
danbooruUrl.addQueryItem(iter.key(), iter.value());
}
}
if (!username.isEmpty() && !password.isEmpty()) {
danbooruUrl.setUserName(username);
danbooruUrl.setPassword(password);
}
return danbooruUrl;
}
KUrl requestUrl(KUrl& url, const QString& path, const QString& username,
const QString& password)
{
KUrl danbooruUrl = KUrl(url);
danbooruUrl.addPath(path);
if (!username.isEmpty() && !password.isEmpty()) {
danbooruUrl.setUserName(username);
danbooruUrl.setPassword(password);
}
return danbooruUrl;
}
} // namespace Danbooru