• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

KBlog Client Library

blogpost.cpp
00001 /*
00002   This file is part of the kblog library.
00003 
00004   Copyright (c) 2006-2007 Christian Weilbach <christian_weilbach@web.de>
00005   Copyright (c) 2007 Mike McQuaid <mike@mikemcquaid.com>
00006 
00007   This library is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU Library General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This library is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   Library General Public License for more details.
00016 
00017   You should have received a copy of the GNU Library General Public License
00018   along with this library; see the file COPYING.LIB.  If not, write to
00019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020   Boston, MA 02110-1301, USA.
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->mAdditionalContent = post.additionalContent();
00045   d_ptr->mWpSlug = post.slug();
00046   d_ptr->mCategories = post.categories();
00047   d_ptr->mTags = post.tags();
00048   d_ptr->mMood = post.mood();
00049   d_ptr->mPermaLink = post.permaLink();
00050   d_ptr->mSummary = post.summary();
00051   d_ptr->mLink = post.link();
00052   d_ptr->mMusic = post.music();
00053   d_ptr->mTrackBackAllowed = post.isTrackBackAllowed();
00054   d_ptr->mCommentAllowed = post.isCommentAllowed();
00055   d_ptr->mError = post.error();
00056   d_ptr->mJournalId = post.journalId();
00057   d_ptr->mStatus = post.status();
00058   d_ptr->mCreationDateTime = post.creationDateTime();
00059   d_ptr->mModificationDateTime = post.modificationDateTime();
00060 }
00061 
00062 BlogPost::BlogPost( const QString &postId )
00063   : d_ptr( new BlogPostPrivate )
00064 {
00065   d_ptr->q_ptr = this;
00066   d_ptr->mPrivate = false;
00067   d_ptr->mPostId = postId;
00068   d_ptr->mStatus = New;
00069 }
00070 
00071 BlogPost::BlogPost( const KCal::Journal &journal )
00072   : d_ptr( new BlogPostPrivate )
00073 {
00074   d_ptr->q_ptr = this;
00075   d_ptr->mPrivate = false;
00076   d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
00077   d_ptr->mJournalId = journal.uid();
00078   d_ptr->mStatus = New;
00079   d_ptr->mTitle = journal.summary();
00080   if ( journal.descriptionIsRich() ) {
00081     d_ptr->mContent = d_ptr->cleanRichText( journal.description() );
00082   } else {
00083     d_ptr->mContent = journal.description();
00084   }
00085   d_ptr->mCategories = journal.categories();
00086   d_ptr->mCreationDateTime = journal.dtStart();
00087 }
00088 
00089 // BlogPost::BlogPost( const KCal::Journal &journal, BlogPostPrivate &dd )
00090 //   : d_ptr( &dd )
00091 // {
00092 //   d_ptr->q_ptr = this;
00093 //   d_ptr->mPrivate = false;
00094 //   d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
00095 //   d_ptr->mJournalId = journal.uid();
00096 //   d_ptr->mStatus = New;
00097 //   d_ptr->mTitle = journal.summary();
00098 //   d_ptr->mContent = journal.description();
00099 //   d_ptr->mCategories = journal.categories();
00100 //   d_ptr->mCreationDateTime = journal.dtStart();
00101 // }
00102 
00103 BlogPost::~BlogPost()
00104 {
00105   delete d_ptr;
00106 }
00107 
00108 KCal::Journal *BlogPost::journal( const Blog &blog ) const
00109 {
00110   QString url = blog.url().url();
00111   QString username = blog.username();
00112   QString blogId = blog.blogId();
00113   // Generate unique ID. Should be unique enough...
00114   QString id = "kblog-" + url + '-' + blogId  + '-' + username +
00115       '-' + d_ptr->mPostId;
00116   KCal::Journal *journal = new KCal::Journal();
00117   journal->setUid( id );
00118   journal->setSummary( d_ptr->mTitle );
00119   journal->setCategories( d_ptr->mCategories );
00120   journal->setDescription( d_ptr->mContent, true );
00121   journal->setDtStart( d_ptr->mCreationDateTime );
00122   journal->setCustomProperty( "KBLOG", "URL", url );
00123   journal->setCustomProperty( "KBLOG", "USER", blog.username() );
00124   journal->setCustomProperty( "KBLOG", "BLOG", blogId );
00125   journal->setCustomProperty( "KBLOG", "ID", d_ptr->mPostId );
00126   return journal;
00127 }
00128 
00129 QString BlogPost::journalId() const
00130 {
00131   return d_ptr->mJournalId;
00132 }
00133 
00134 bool BlogPost::isPrivate() const
00135 {
00136   return d_ptr->mPrivate;
00137 }
00138 
00139 void BlogPost::setPrivate( bool privatePost )
00140 {
00141   d_ptr->mPrivate = privatePost;
00142 }
00143 
00144 QString BlogPost::postId() const
00145 {
00146   return d_ptr->mPostId;
00147 }
00148 
00149 void BlogPost::setPostId( const QString &postId )
00150 {
00151   d_ptr->mPostId = postId;
00152 }
00153 
00154 QString BlogPost::title() const
00155 {
00156   return d_ptr->mTitle;
00157 }
00158 
00159 void BlogPost::setTitle( const QString &title )
00160 {
00161   d_ptr->mTitle = title;
00162 }
00163 
00164 QString BlogPost::content() const
00165 {
00166   return d_ptr->mContent;
00167 }
00168 
00169 void BlogPost::setContent( const QString &content )
00170 {
00171   d_ptr->mContent = content;
00172 }
00173 
00174 // QString BlogPost::abbreviatedContent() const
00175 // {
00176 //   //TODO
00177 //   return 0;
00178 // }
00179 //
00180 // void BlogPost::setAbbreviatedContent( const QString &abbreviatedContent )
00181 // {
00182 //   Q_UNUSED( abbreviatedContent );
00183 //   //TODO
00184 // }
00185 
00186 QString BlogPost::additionalContent() const
00187 {
00188     return d_ptr->mAdditionalContent;
00189 }
00190 
00191 void BlogPost::setAdditionalContent( const QString &additionalContent )
00192 {
00193   d_ptr->mAdditionalContent = additionalContent;
00194 }
00195 
00196 QString BlogPost::slug() const
00197 {
00198     return d_ptr->mWpSlug;
00199 }
00200 
00201 void BlogPost::setSlug( const QString &slug )
00202 {
00203     d_ptr->mWpSlug = slug;
00204 }
00205 
00206 KUrl BlogPost::link() const
00207 {
00208   return d_ptr->mLink;
00209 }
00210 
00211 void BlogPost::setLink( const KUrl &link ) const
00212 {
00213   d_ptr->mLink = link;
00214 }
00215 
00216 KUrl BlogPost::permaLink() const
00217 {
00218   return d_ptr->mPermaLink;
00219 }
00220 
00221 void BlogPost::setPermaLink( const KUrl &permalink ) const
00222 {
00223   d_ptr->mPermaLink = permalink;
00224 }
00225 
00226 bool BlogPost::isCommentAllowed() const
00227 {
00228   return d_ptr->mCommentAllowed;
00229 }
00230 
00231 void BlogPost::setCommentAllowed( bool commentAllowed )
00232 {
00233   d_ptr->mCommentAllowed = commentAllowed;
00234 }
00235 
00236 bool BlogPost::isTrackBackAllowed() const
00237 {
00238   return d_ptr->mCommentAllowed;
00239 }
00240 
00241 void BlogPost::setTrackBackAllowed ( bool allowTrackBacks )
00242 {
00243   d_ptr->mTrackBackAllowed = allowTrackBacks;
00244 }
00245 
00246 QString BlogPost::summary() const
00247 {
00248   return d_ptr->mSummary;
00249 }
00250 
00251 void BlogPost::setSummary( const QString &summary )
00252 {
00253   d_ptr->mSummary = summary;
00254 }
00255 
00256 QStringList BlogPost::tags() const
00257 {
00258   return d_ptr->mTags;
00259 }
00260 
00261 void BlogPost::setTags( const QStringList &tags )
00262 {
00263   d_ptr->mTags = tags;
00264 }
00265 
00266 // QList<KUrl> BlogPost::trackBackUrls() const
00267 // {
00268 //   //TODO
00269 //   return QList<KUrl>();
00270 // }
00271 //
00272 // void BlogPost::setTrackBackUrls( const QList<KUrl> &trackBackUrls )
00273 // {
00274 //   Q_UNUSED( trackBackUrls );
00275 //   //TODO
00276 // }
00277 
00278 QString BlogPost::mood() const
00279 {
00280   return d_ptr->mMood;
00281 }
00282 
00283 void BlogPost::setMood( const QString &mood )
00284 {
00285   d_ptr->mMood = mood;
00286 }
00287 
00288 QString BlogPost::music() const
00289 {
00290   return d_ptr->mMusic;
00291 }
00292 
00293 void BlogPost::setMusic( const QString &music )
00294 {
00295   d_ptr->mMusic = music;
00296 }
00297 
00298 QStringList BlogPost::categories() const
00299 {
00300   return d_ptr->mCategories;
00301 }
00302 
00303 void BlogPost::setCategories( const QStringList &categories )
00304 {
00305   d_ptr->mCategories = categories;
00306 }
00307 
00308 KDateTime BlogPost::creationDateTime() const
00309 {
00310   return d_ptr->mCreationDateTime;
00311 }
00312 
00313 void BlogPost::setCreationDateTime( const KDateTime &datetime )
00314 {
00315   d_ptr->mCreationDateTime = datetime;
00316 }
00317 
00318 KDateTime BlogPost::modificationDateTime() const
00319 {
00320   return d_ptr->mModificationDateTime;
00321 }
00322 
00323 void BlogPost::setModificationDateTime( const KDateTime &datetime )
00324 {
00325   d_ptr->mModificationDateTime = datetime;
00326 }
00327 
00328 BlogPost::Status BlogPost::status() const
00329 {
00330   return d_ptr->mStatus;
00331 }
00332 
00333 void BlogPost::setStatus( BlogPost::Status status )
00334 {
00335   d_ptr->mStatus = status;
00336 }
00337 
00338 QString BlogPost::error() const
00339 {
00340   return d_ptr->mError;
00341 }
00342 
00343 void BlogPost::setError( const QString &error )
00344 {
00345   d_ptr->mError = error;
00346 }
00347 
00348 BlogPost &BlogPost::operator=( const BlogPost &other )
00349 {
00350   BlogPost copy( other );
00351   swap( copy );
00352   return *this;
00353 }
00354 
00355 QString BlogPostPrivate::cleanRichText( QString richText ) const
00356 {
00357   QRegExp getBodyContents( "<body[^>]*>(.*)</body>" );
00358   if ( getBodyContents.indexIn( richText ) ) {
00359     // Get anything inside but excluding the body tags
00360     richText = getBodyContents.cap( 1 );
00361     // Get rid of any whitespace
00362     richText.remove( QRegExp( "^\\s+" ) );
00363   }
00364   // Get rid of styled paragraphs
00365   richText.replace( QRegExp( "<p style=\"[^\"]*\">" ), "<p>" );
00366 
00367   // If we're left with empty content then return a clean empty string
00368   if ( richText == "<p></p>" ) {
00369     richText.clear();
00370   }
00371 
00372   return richText;
00373 }
00374 
00375 } // namespace KBlog
00376 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:18 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KBlog Client Library

Skip menu "KBlog Client Library"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal