KBlog Client Library
blogpost.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "blogpost.h"
00024 #include "blogpost_p.h"
00025
00026 #include "blog.h"
00027
00028 #include <KDateTime>
00029 #include <KUrl>
00030 #include <kcal/journal.h>
00031
00032 #include <QStringList>
00033
00034 namespace KBlog {
00035
00036 BlogPost::BlogPost( const KBlog::BlogPost &post )
00037 : d_ptr( new BlogPostPrivate )
00038 {
00039 d_ptr->q_ptr = this;
00040 d_ptr->mPrivate = post.isPrivate();
00041 d_ptr->mPostId = post.postId();
00042 d_ptr->mTitle = post.title();
00043 d_ptr->mContent = post.content();
00044 d_ptr->mCategories = post.categories();
00045 d_ptr->mError = post.error();
00046 d_ptr->mJournalId = post.journalId();
00047 d_ptr->mStatus = post.status();
00048 d_ptr->mCreationDateTime = post.creationDateTime();
00049 d_ptr->mModificationDateTime = post.modificationDateTime();
00050 }
00051
00052 BlogPost::BlogPost( const QString &postId )
00053 : d_ptr( new BlogPostPrivate )
00054 {
00055 d_ptr->q_ptr = this;
00056 d_ptr->mPrivate = false;
00057 d_ptr->mPostId = postId;
00058 d_ptr->mStatus = New;
00059 }
00060
00061 BlogPost::BlogPost( const KCal::Journal &journal )
00062 : d_ptr( new BlogPostPrivate )
00063 {
00064 d_ptr->q_ptr = this;
00065 d_ptr->mPrivate = false;
00066 d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
00067 d_ptr->mJournalId = journal.uid();
00068 d_ptr->mStatus = New;
00069 d_ptr->mTitle = journal.summary();
00070 if (journal.descriptionIsRich()) {
00071 d_ptr->mContent = d_ptr->cleanRichText(journal.description());
00072 }
00073 else {
00074 d_ptr->mContent = journal.description();
00075 }
00076 d_ptr->mCategories = journal.categories();
00077 d_ptr->mCreationDateTime = journal.dtStart();
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 BlogPost::~BlogPost()
00095 {
00096 delete d_ptr;
00097 }
00098
00099 KCal::Journal *BlogPost::journal( const Blog &blog ) const
00100 {
00101 QString url = blog.url().url();
00102 QString username = blog.username();
00103 QString blogId = blog.blogId();
00104
00105 QString id = "kblog-" + url + '-' + blogId + '-' + username +
00106 '-' + d_ptr->mPostId;
00107 KCal::Journal *journal = new KCal::Journal();
00108 journal->setUid( id );
00109 journal->setSummary( d_ptr->mTitle );
00110 journal->setCategories( d_ptr->mCategories );
00111 journal->setDescription( d_ptr->mContent, true );
00112 journal->setDtStart( d_ptr->mCreationDateTime );
00113 journal->setCustomProperty( "KBLOG", "URL", url );
00114 journal->setCustomProperty( "KBLOG", "USER", blog.username() );
00115 journal->setCustomProperty( "KBLOG", "BLOG", blogId );
00116 journal->setCustomProperty( "KBLOG", "ID", d_ptr->mPostId );
00117 return journal;
00118 }
00119
00120 QString BlogPost::journalId() const
00121 {
00122 return d_ptr->mJournalId;
00123 }
00124
00125 bool BlogPost::isPrivate() const
00126 {
00127 return d_ptr->mPrivate;
00128 }
00129
00130 void BlogPost::setPrivate( bool privatePost )
00131 {
00132 d_ptr->mPrivate = privatePost;
00133 }
00134
00135 QString BlogPost::postId() const
00136 {
00137 return d_ptr->mPostId;
00138 }
00139
00140 void BlogPost::setPostId( const QString &postId )
00141 {
00142 d_ptr->mPostId = postId;
00143 }
00144
00145 QString BlogPost::title() const
00146 {
00147 return d_ptr->mTitle;
00148 }
00149
00150 void BlogPost::setTitle( const QString &title )
00151 {
00152 d_ptr->mTitle = title;
00153 }
00154
00155 QString BlogPost::content() const
00156 {
00157 return d_ptr->mContent;
00158 }
00159
00160 void BlogPost::setContent( const QString &content )
00161 {
00162 d_ptr->mContent = content;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 KUrl BlogPost::link() const
00178 {
00179 return d_ptr->mLink;
00180 }
00181
00182 void BlogPost::setLink( const KUrl &link ) const
00183 {
00184 d_ptr->mLink = link;
00185 }
00186
00187 KUrl BlogPost::permaLink() const
00188 {
00189 return d_ptr->mPermaLink;
00190 }
00191
00192 void BlogPost::setPermaLink( const KUrl &permalink ) const
00193 {
00194 d_ptr->mPermaLink = permalink;
00195 }
00196
00197 bool BlogPost::isCommentAllowed() const
00198 {
00199 return d_ptr->mCommentAllowed;
00200 }
00201
00202 void BlogPost::setCommentAllowed( bool commentAllowed )
00203 {
00204 d_ptr->mCommentAllowed = commentAllowed;
00205 }
00206
00207 bool BlogPost::isTrackBackAllowed() const
00208 {
00209 return d_ptr->mCommentAllowed;
00210 }
00211
00212 void BlogPost::setTrackBackAllowed ( bool allowTrackBacks )
00213 {
00214 d_ptr->mTrackBackAllowed = allowTrackBacks;
00215 }
00216
00217 QString BlogPost::summary() const
00218 {
00219 return d_ptr->mSummary;
00220 }
00221
00222 void BlogPost::setSummary( const QString &summary )
00223 {
00224 d_ptr->mSummary = summary;
00225 }
00226
00227 QStringList BlogPost::tags() const
00228 {
00229 return d_ptr->mTags;
00230 }
00231
00232 void BlogPost::setTags( const QStringList &tags )
00233 {
00234 d_ptr->mTags = tags;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 QString BlogPost::mood() const
00250 {
00251 return d_ptr->mMood;
00252 }
00253
00254 void BlogPost::setMood( const QString &mood )
00255 {
00256 d_ptr->mMood = mood;
00257 }
00258
00259 QString BlogPost::music() const
00260 {
00261 return d_ptr->mMusic;
00262 }
00263
00264 void BlogPost::setMusic( const QString &music )
00265 {
00266 d_ptr->mMusic = music;
00267 }
00268
00269 QStringList BlogPost::categories() const
00270 {
00271 return d_ptr->mCategories;
00272 }
00273
00274 void BlogPost::setCategories( const QStringList &categories )
00275 {
00276 d_ptr->mCategories = categories;
00277 }
00278
00279 KDateTime BlogPost::creationDateTime() const
00280 {
00281 return d_ptr->mCreationDateTime;
00282 }
00283
00284 void BlogPost::setCreationDateTime( const KDateTime &datetime )
00285 {
00286 d_ptr->mCreationDateTime = datetime;
00287 }
00288
00289 KDateTime BlogPost::modificationDateTime() const
00290 {
00291 return d_ptr->mModificationDateTime;
00292 }
00293
00294 void BlogPost::setModificationDateTime( const KDateTime &datetime )
00295 {
00296 d_ptr->mModificationDateTime = datetime;
00297 }
00298
00299 BlogPost::Status BlogPost::status() const
00300 {
00301 return d_ptr->mStatus;
00302 }
00303
00304 void BlogPost::setStatus( BlogPost::Status status )
00305 {
00306 d_ptr->mStatus = status;
00307 }
00308
00309 QString BlogPost::error() const
00310 {
00311 return d_ptr->mError;
00312 }
00313
00314 void BlogPost::setError( const QString &error )
00315 {
00316 d_ptr->mError = error;
00317 }
00318
00319 BlogPost &BlogPost::operator=( const BlogPost &other )
00320 {
00321 BlogPost copy( other );
00322 swap( copy );
00323 return *this;
00324 }
00325
00326 QString BlogPostPrivate::cleanRichText( QString richText ) const
00327 {
00328 QRegExp getBodyContents("<body[^>]*>(.*)</body>");
00329 if ( getBodyContents.indexIn( richText ) )
00330 {
00331
00332 richText = getBodyContents.cap(1);
00333
00334 richText.replace(QRegExp("^\\s+"),"");
00335 }
00336
00337 richText.replace(QRegExp("<p style=\"[^\"]*\">"),"<p>");
00338
00339
00340 if ( richText == "<p></p>" ) {
00341 richText = QString();
00342 }
00343
00344 return richText;
00345 }
00346
00347 }
00348