25 #include "movabletype_p.h" 28 #include <kxmlrpcclient/client.h> 31 #include "kblog_debug.h" 32 #include <KLocalizedString> 34 #include <QStringList> 36 using namespace KBlog;
39 :
MetaWeblog(server, *new MovableTypePrivate, parent)
58 return QStringLiteral(
"Movable Type");
67 d->mXmlRpcClient->call(
68 QStringLiteral(
"metaWeblog.getRecentPosts"), args,
70 this, SLOT(slotError(
int,
QString,QVariant)),
80 unsigned int i = d->mCallCounter++;
81 d->mCallMap[ i ] = post;
82 d->mXmlRpcClient->call(
83 QStringLiteral(
"mt.getTrackbackPings"), args,
94 if (d->mCategoriesList.isEmpty() &&
96 d->mFetchPostCache << post;
97 if (d->mFetchPostCache.count()) {
104 this, SLOT(slotTriggerFetchPost()));
121 if (d->mCategoriesList.isEmpty() &&
123 qCDebug(KBLOG_LOG) <<
"No categories in the cache yet. Have to fetch them first.";
124 d->mCreatePostCache << post;
126 this, SLOT(slotTriggerCreatePost()));
133 if (d->mSilentCreationList.contains(post)) {
134 qCDebug(KBLOG_LOG) <<
"Post already in mSilentCreationList, this *should* never happen!";
136 d->mSilentCreationList << post;
156 if (d->mCategoriesList.isEmpty() &&
158 qCDebug(KBLOG_LOG) <<
"No categories in the cache yet. Have to fetch them first.";
159 d->mModifyPostCache << post;
161 this, SLOT(slotTriggerModifyPost()));
168 void MovableTypePrivate::slotTriggerCreatePost()
174 q, SLOT(slotTriggerCreatePost()));
178 for (; it != end; it++) {
181 mCreatePostCache.clear();
184 void MovableTypePrivate::slotTriggerModifyPost()
190 q, SLOT(slotTriggerModifyPost()));
194 for (; it != end; it++) {
197 mModifyPostCache.clear();
200 void MovableTypePrivate::slotTriggerFetchPost()
206 q, SLOT(slotTriggerFetchPost()));
209 for (; it != end; it++) {
212 mFetchPostCache.clear();
215 MovableTypePrivate::MovableTypePrivate()
220 MovableTypePrivate::~MovableTypePrivate()
231 mCallMap.remove(
id.toInt());
236 qCDebug(KBLOG_LOG) <<
"TOP:" << result[0].typeName();
237 if (result[0].type() != QVariant::String &&
238 result[0].type() != QVariant::Int) {
239 qCritical() <<
"Could not read the postId, not a string or an integer.";
241 i18n(
"Could not read the postId, not a string or an integer."),
246 if (result[0].type() == QVariant::String) {
247 serverID = result[0].toString();
249 if (result[0].type() == QVariant::Int) {
250 serverID = QStringLiteral(
"%1").
arg(result[0].toInt());
253 if (mSilentCreationList.contains(post)) {
255 setPostCategories(post, !post->
isPrivate());
257 qCDebug(KBLOG_LOG) <<
"emitting createdPost()" 258 <<
"for title: \"" << post->
title()
259 <<
"\" server id: " << serverID;
261 emit q->createdPost(post);
271 mCallMap.remove(
id.toInt());
275 qCDebug(KBLOG_LOG) <<
"TOP:" << result[0].typeName();
276 if (result[0].type() == QVariant::Map &&
277 readPostFromMap(post, result[0].toMap())) {
279 qCritical() <<
"Could not fetch post out of the result from the server.";
280 post->
setError(
i18n(
"Could not fetch post out of the result from the server."));
283 i18n(
"Could not fetch post out of the result from the server."), post);
287 unsigned int i = mCallCounter++;
288 mCallMap[ i ] = post;
290 QStringLiteral(
"mt.getPostCategories"), args,
295 qCDebug(KBLOG_LOG) <<
"Emitting fetchedPost()";
297 emit q->fetchedPost(post);
307 mCallMap.remove(
id.toInt());
311 qCDebug(KBLOG_LOG) <<
"TOP:" << result[0].typeName();
312 if (result[0].type() != QVariant::Bool &&
313 result[0].type() != QVariant::Int) {
314 qCritical() <<
"Could not read the result, not a boolean.";
316 i18n(
"Could not read the result, not a boolean."),
320 if (mSilentCreationList.contains(post)) {
322 mSilentCreationList.removeOne(post);
323 emit q->createdPost(post);
326 setPostCategories(post,
false);
331 void MovableTypePrivate::setPostCategories(
BlogPost *post,
bool publishAfterCategories)
336 unsigned int i = mCallCounter++;
337 mCallMap[ i ] = post;
338 mPublishAfterCategories[ i ] = publishAfterCategories;
344 for (
int j = 0; j < categories.
count(); j++) {
345 for (
int k = 0; k < mCategoriesList.count(); k++) {
346 if (mCategoriesList[k][QStringLiteral(
"name")] == categories[j]) {
347 qCDebug(KBLOG_LOG) <<
"Matched category with name: " << categories[ j ] <<
" and id: " << mCategoriesList[ k ][ QStringLiteral(
"categoryId") ];
351 category[QStringLiteral(
"categoryId")] = mCategoriesList[k][QStringLiteral(
"categoryId")].toInt();
355 if (k == mCategoriesList.count()) {
356 qCDebug(KBLOG_LOG) <<
"Couldn't find categoryId for: " << categories[j];
363 QStringLiteral(
"mt.setPostCategories"), args,
365 q, SLOT(slotError(
int,
QString,QVariant)),
378 if (result[ 0 ].type() != QVariant::List) {
379 qCritical() <<
"Could not read the result, not a list. Category fetching failed! We will still emit fetched post now.";
381 i18n(
"Could not read the result - is not a list. Category fetching failed."), post);
384 emit q->fetchedPost(post);
391 for (; it != end; it++) {
392 newCatList << (*it).toMap()[ QStringLiteral(
"categoryName") ].toString();
394 qCDebug(KBLOG_LOG) <<
"categories list: " << newCatList;
397 emit q->fetchedPost(post);
408 bool publish = mPublishAfterCategories[ i ];
410 mPublishAfterCategories.remove(i);
412 if (result[0].type() != QVariant::Bool) {
413 qCritical() <<
"Could not read the result, not a boolean. Category setting failed! We will still publish if now if necessary. ";
415 i18n(
"Could not read the result - is not a boolean value. Category setting failed. Will still publish now if necessary."),
427 if (mSilentCreationList.contains(post)) {
428 qCDebug(KBLOG_LOG) <<
"emitting createdPost() for title: \"" 429 << post->
title() <<
"\"";
431 mSilentCreationList.removeOne(post);
432 emit q->createdPost(post);
434 qCDebug(KBLOG_LOG) <<
"emitting modifiedPost() for title: \"" 435 << post->
title() <<
"\"";
437 emit q->modifiedPost(post);
458 qCDebug(KBLOG_LOG) <<
"readPostFromMap()";
464 qCDebug(KBLOG_LOG) << endl;
466 QDateTime dt = postInfo[QStringLiteral(
"dateCreated")].toDateTime();
471 dt = postInfo[QStringLiteral(
"lastModified")].toDateTime();
476 post->
setPostId(postInfo[QStringLiteral(
"postid")].toString().isEmpty() ? postInfo[QStringLiteral(
"postId")].toString() :
477 postInfo[QStringLiteral(
"postid")].toString());
479 QString title(postInfo[QStringLiteral(
"title")].toString());
480 QString description(postInfo[QStringLiteral(
"description")].toString());
481 QStringList categoryIdList = postInfo[QStringLiteral(
"categories")].toStringList();
485 for (
int i = 0; i < categoryIdList.
count(); i++) {
486 for (
int k = 0; k < mCategoriesList.count(); k++) {
487 if (mCategoriesList[ k ][ QStringLiteral(
"name") ] == categoryIdList[ i ]) {
488 categories << mCategoriesList[ k ][ QStringLiteral(
"name") ];
489 }
else if (mCategoriesList[ k ][ QStringLiteral(
"categoryId") ] == categoryIdList[ i ]) {
490 categories << mCategoriesList[ k ][ QStringLiteral(
"name") ];
497 post->
setSlug(postInfo[QStringLiteral(
"wp_slug")].toString());
501 post->
setCommentAllowed((
bool)postInfo[QStringLiteral(
"mt_allow_comments")].toInt());
503 post->
setSummary(postInfo[QStringLiteral(
"mt_excerpt")].toString());
504 post->
setTags(postInfo[QStringLiteral(
"mt_keywords")].toStringList());
505 post->
setLink(
QUrl(postInfo[QStringLiteral(
"link")].toString()));
507 QString postStatus = postInfo[QStringLiteral(
"post_status")].toString();
518 qCDebug(KBLOG_LOG) <<
"Categories:" << categories;
524 void MovableTypePrivate::slotListTrackBackPings(
528 qCDebug(KBLOG_LOG) <<
"slotTrackbackPings()";
529 BlogPost *post = mCallMap[
id.toInt() ];
530 mCallMap.remove(
id.toInt());
532 if (result[0].type() != QVariant::List) {
533 qCritical() <<
"Could not fetch list of trackback pings out of the" 534 <<
"result from the server.";
536 i18n(
"Could not fetch list of trackback pings out of the " 537 "result from the server."));
543 for (; it != end; ++it) {
545 qCDebug(KBLOG_LOG) <<
"MIDDLE:" << (*it).typeName();
547 tping[ QStringLiteral(
"title") ] = trackBackInfo[ QStringLiteral(
"pingTitle")].toString();
548 tping[ QStringLiteral(
"url") ] = trackBackInfo[ QStringLiteral(
"pingURL")].toString();
549 tping[ QStringLiteral(
"ip") ] = trackBackInfo[ QStringLiteral(
"pingIP")].toString();
550 trackBackList << tping;
552 qCDebug(KBLOG_LOG) <<
"Emitting listedTrackBackPings()";
553 emit q->listedTrackBackPings(post, trackBackList);
565 map[QStringLiteral(
"categories")] = post.
categories();
566 map[QStringLiteral(
"description")] = post.
content();
570 map[QStringLiteral(
"title")] = post.
title();
574 map[QStringLiteral(
"mt_excerpt")] = post.
summary();
582 #include "moc_movabletype.cpp" QString title() const
Returns the title.
void fetchPost(KBlog::BlogPost *post) override
Fetch a post from the server.
void setCreationDateTime(const QDateTime &datetime)
Sets the creation time.
virtual void listCategories()
List the categories of the blog.
Status of a successfully fetched post.
void setLink(const QUrl &link) const
Set the link path.
QStringList tags() const
Returns the tags list as a QStringList.
virtual void listTrackBackPings(KBlog::BlogPost *post)
Get the list of trackback pings from the server.
Status of a successfully created post.
void modifyPost(KBlog::BlogPost *post) override
Modify a post on server.
virtual ~MovableType()
Destroy the object.
void modifyPost(KBlog::BlogPost *post) override
Modify a post on server.
QString join(const QString &separator) const
bool isCommentAllowed() const
Returns whether comments should be allowed.
void fetchPost(KBlog::BlogPost *post) override
Fetch a post from the server.
bool isTrackBackAllowed() const
Returns whether track back should be allowed.
A class that can be used for access to MetaWeblog blogs.
QString summary() const
Returns the summary.
QDateTime creationDateTime() const
Returns the creation date time.
void setTitle(const QString &title)
Sets the title.
void setPostId(const QString &postId)
Sets the post id value.
QList< Key > keys() const
int count(const T &value) const
QString additionalContent() const
Returns the additional content, (mt_text_more of MovableType API)
void createPost(KBlog::BlogPost *post) override
Create a new post on server.
void setAdditionalContent(const QString &additionalContent)
Sets the additional content, (mt_text_more of MovableType API)
This file is part of the for accessing Blog Servers and defines the MovableType class.
void setContent(const QString &content)
Sets the content.
Status when an error on the server side occurred.
QString blogId() const
Returns the unique ID for the specific blog on the server.
void setStatus(Status status)
Sets the status.
Status of a successfully modified post.
void setTrackBackAllowed(bool allowTrackBacks)
Set whether track back should be allowed.
void setSlug(const QString &slug)
Sets the Wordpress slug property! (will use to set post's permalink) Currently just wordpress support...
MovableType(const QUrl &server, QObject *parent=nullptr)
Create an object for Movable Type.
QString interfaceName() const override
Returns the of the inherited object.
A class that can be used for access to Movable Type blogs.
void setCommentAllowed(bool commentAllowed)
Set whether comments should be allowed.
void setPrivate(bool privatePost)
Sets the post to private viewings only.
QString content() const
Returns the content.
QString i18n(const char *text, const TYPE &arg...)
Namespace for blog related classes.
void setPermaLink(const QUrl &permalink) const
Set the perma link path.
A class that represents a blog post on the server.
void setCategories(const QStringList &categories)
Sets the categories.
void createPost(KBlog::BlogPost *post) override
Create a new post on server.
void setSummary(const QString &summary)
Set the summary.
QStringList categories() const
Returns the categories.
QDateTime toLocalTime() const
void setTags(const QStringList &tags)
Set the tags list.
void setModificationDateTime(const QDateTime &datetime)
Sets the modification time.
const_iterator constEnd() const
const_iterator constBegin() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void listRecentPosts(int number) override
List recent posts on the server.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
bool isPrivate() const
Returns if the post is published or not.
void listedCategories(const QList< QMap< QString, QString > > &categories)
This signal is emitted when the last category of the listCategories() job has been fetched...
QString postId() const
Returns the postId.
void setError(const QString &error)
Sets the error.