25 #include "metaweblog_p.h"
27 #include "blogmedia.h"
29 #include <kxmlrpcclient/client.h>
31 #include <KLocalizedString>
33 #include <kstandarddirs.h>
35 #include <QtCore/QFile>
36 #include <QtCore/QDataStream>
38 using namespace KBlog;
41 :
Blogger1( server, *new MetaWeblogPrivate, parent )
65 kDebug() <<
"Fetching List of Categories...";
67 d->mXmlRpcClient->call(
77 kError() <<
"MetaWeblog::createMedia: media is a null pointer";
78 emit
error (
Other, i18n(
"Media is a null pointer." ) );
81 unsigned int i = d->mCallMediaCounter++;
82 d->mCallMediaMap[ i ] = media;
83 kDebug() <<
"MetaWeblog::createMedia: name=" << media->
name();
90 d->mXmlRpcClient->call(
98 MetaWeblogPrivate::MetaWeblogPrivate()
105 MetaWeblogPrivate::~MetaWeblogPrivate()
114 if ( !
id.isEmpty() ) {
122 void MetaWeblogPrivate::loadCategories()
131 if ( mUrl.isEmpty() || mBlogId.isEmpty() || mUsername.isEmpty() ) {
132 kDebug() <<
"We need at least url, blogId and the username to create a unique filename.";
137 filename = KStandardDirs::locateLocal(
"data", filename,
true );
139 QFile file( filename );
140 if ( !file.open( QIODevice::ReadOnly ) ) {
141 kDebug() <<
"Cannot open cached categories file: " << filename;
146 stream >> mCategoriesList;
150 void MetaWeblogPrivate::saveCategories()
153 if ( mUrl.isEmpty() || mBlogId.isEmpty() || mUsername.isEmpty() ) {
154 kDebug() <<
"We need at least url, blogId and the username to create a unique filename.";
159 filename = KStandardDirs::locateLocal(
"data", filename,
true );
161 QFile file( filename );
162 if ( !file.open( QIODevice::WriteOnly ) ) {
163 kDebug() <<
"Cannot open cached categories file: " << filename;
168 stream << mCategoriesList;
172 void MetaWeblogPrivate::slotListCategories(
const QList<QVariant> &result,
178 kDebug() <<
"MetaWeblogPrivate::slotListCategories";
179 kDebug() <<
"TOP:" << result[0].typeName();
180 if ( result[0].type() != QVariant::Map &&
181 result[0].type() != QVariant::List ) {
184 kError() <<
"Could not list categories out of the result from the server.";
186 i18n(
"Could not list categories out of the result "
187 "from the server." ) );
189 if ( result[0].type() == QVariant::Map ) {
195 for ( ; it != end; ++it ) {
196 kDebug() <<
"MIDDLE:" << ( *it );
205 mCategoriesList.append( category );
207 kDebug() <<
"Emitting listedCategories";
208 emit q->listedCategories( mCategoriesList );
211 if ( result[0].type() == QVariant::List ) {
217 for ( ; it != end; ++it ) {
218 kDebug() <<
"MIDDLE:" << ( *it ).typeName();
227 mCategoriesList.append( category );
229 kDebug() <<
"Emitting listedCategories()";
230 emit q->listedCategories( mCategoriesList );
235 void MetaWeblogPrivate::slotCreateMedia(
const QList<QVariant> &result,
241 mCallMediaMap.remove(
id.toInt() );
243 kDebug() <<
"MetaWeblogPrivate::slotCreateMedia, no error!";
244 kDebug() <<
"TOP:" << result[0].typeName();
245 if ( result[0].type() != 8 ) {
246 kError() <<
"Could not read the result, not a map.";
248 i18n(
"Could not read the result, not a map." ),
254 kDebug() <<
"MetaWeblog::slotCreateMedia url=" << url;
257 media->
setUrl( KUrl( url ) );
259 kDebug() <<
"Emitting createdMedia( url=" << url <<
");";
260 emit q->createdMedia( media );
264 bool MetaWeblogPrivate::readPostFromMap(
BlogPost *post,
268 kDebug() <<
"readPostFromMap()";
277 KDateTime( postInfo[
QLatin1String(
"dateCreated")].toDateTime(), KDateTime::UTC );
278 if ( dt.isValid() && !dt.isNull() ) {
283 KDateTime( postInfo[
QLatin1String(
"lastModified")].toDateTime(), KDateTime::UTC );
284 if ( dt.isValid() && !dt.isNull() ) {
297 if ( !categories.isEmpty() ) {
298 kDebug() <<
"Categories:" << categories;
320 QString MetaWeblogPrivate::getCallFromFunction( FunctionToCall type )
323 case GetRecentPosts:
return QLatin1String(
"metaWeblog.getRecentPosts");
325 case ModifyPost:
return QLatin1String(
"metaWeblog.editPost");
330 #include "moc_metaweblog.cpp"
QString title() const
Returns the title.
MetaWeblog(const KUrl &server, QObject *parent=0)
Create an object for MetaWeblog.
QString interfaceName() const
Returns the of the inherited object.
void error(KBlog::Blog::ErrorType type, const QString &errorMessage)
This signal is emitted when an error occurs with XML parsing or a structural problem.
KDateTime creationDateTime() const
Returns the creation date time.
virtual void listCategories()
List the categories of the blog.
A class that represents a media object on the server.
void setStatus(Status status)
Set the status.
QString join(const QString &separator) const
A class that can be used for access to MetaWeblog blogs.
QString mimetype() const
Returns the mimetype.
void setTitle(const QString &title)
Sets the title.
virtual void createMedia(KBlog::BlogMedia *media)
Create a new media object, e.g.
void setPostId(const QString &postId)
Sets the post id value.
QList< Key > keys() const
void setCreationDateTime(const KDateTime &datetime)
Sets the creation time.
void setUrl(const KUrl &url)
Sets the url of the server side object.
void setContent(const QString &content)
Sets the content.
KDateTime modificationDateTime() const
Returns the modification date time.
void setModificationDateTime(const KDateTime &datetime)
Sets the modification time.
QString blogId() const
Returns the unique ID for the specific blog on the server.
QFuture< void > map(Sequence &sequence, MapFunction function)
This file is part of the for accessing Blog Servers and defines the MetaWeblog class.
QString content() const
Returns the content.
char * toString(const T &value)
virtual ~MetaWeblog()
Destroy the object.
A class that represents a blog post on the server.
A class that can be used for access to Blogger 1.0 blogs.
Status of a media object successfully created on the server.
void setCategories(const QStringList &categories)
Sets the categories.
QString name() const
Returns the wished name.
QStringList categories() const
Returns the categories.
QByteArray data() const
Returns the data of the file.
bool isPrivate() const
Returns if the post is published or not.
Any other miscellaneous error.