• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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 Arthur <mike@mikearthur.co.uk>
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->mCategories = post.categories();
00045   d_ptr->mTags = post.tags();
00046   d_ptr->mMood = post.mood();
00047   d_ptr->mPermaLink = post.permaLink();
00048   d_ptr->mSummary = post.summary();
00049   d_ptr->mLink = post.link();
00050   d_ptr->mMusic = post.music();
00051   d_ptr->mTrackBackAllowed = post.isTrackBackAllowed();
00052   d_ptr->mCommentAllowed = post.isCommentAllowed();
00053   d_ptr->mError = post.error();
00054   d_ptr->mJournalId = post.journalId();
00055   d_ptr->mStatus = post.status();
00056   d_ptr->mCreationDateTime = post.creationDateTime();
00057   d_ptr->mModificationDateTime = post.modificationDateTime();
00058 }
00059 
00060 BlogPost::BlogPost( const QString &postId )
00061   : d_ptr( new BlogPostPrivate )
00062 {
00063   d_ptr->q_ptr = this;
00064   d_ptr->mPrivate = false;
00065   d_ptr->mPostId = postId;
00066   d_ptr->mStatus = New;
00067 }
00068 
00069 BlogPost::BlogPost( const KCal::Journal &journal )
00070   : d_ptr( new BlogPostPrivate )
00071 {
00072   d_ptr->q_ptr = this;
00073   d_ptr->mPrivate = false;
00074   d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
00075   d_ptr->mJournalId = journal.uid();
00076   d_ptr->mStatus = New;
00077   d_ptr->mTitle = journal.summary();
00078   if ( journal.descriptionIsRich() ) {
00079     d_ptr->mContent = d_ptr->cleanRichText( journal.description() );
00080   } else {
00081     d_ptr->mContent = journal.description();
00082   }
00083   d_ptr->mCategories = journal.categories();
00084   d_ptr->mCreationDateTime = journal.dtStart();
00085 }
00086 
00087 // BlogPost::BlogPost( const KCal::Journal &journal, BlogPostPrivate &dd )
00088 //   : d_ptr( &dd )
00089 // {
00090 //   d_ptr->q_ptr = this;
00091 //   d_ptr->mPrivate = false;
00092 //   d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
00093 //   d_ptr->mJournalId = journal.uid();
00094 //   d_ptr->mStatus = New;
00095 //   d_ptr->mTitle = journal.summary();
00096 //   d_ptr->mContent = journal.description();
00097 //   d_ptr->mCategories = journal.categories();
00098 //   d_ptr->mCreationDateTime = journal.dtStart();
00099 // }
00100 
00101 BlogPost::~BlogPost()
00102 {
00103   delete d_ptr;
00104 }
00105 
00106 KCal::Journal *BlogPost::journal( const Blog &blog ) const
00107 {
00108   QString url = blog.url().url();
00109   QString username = blog.username();
00110   QString blogId = blog.blogId();
00111   // Generate unique ID. Should be unique enough...
00112   QString id = "kblog-" + url + '-' + blogId  + '-' + username +
00113       '-' + d_ptr->mPostId;
00114   KCal::Journal *journal = new KCal::Journal();
00115   journal->setUid( id );
00116   journal->setSummary( d_ptr->mTitle );
00117   journal->setCategories( d_ptr->mCategories );
00118   journal->setDescription( d_ptr->mContent, true );
00119   journal->setDtStart( d_ptr->mCreationDateTime );
00120   journal->setCustomProperty( "KBLOG", "URL", url );
00121   journal->setCustomProperty( "KBLOG", "USER", blog.username() );
00122   journal->setCustomProperty( "KBLOG", "BLOG", blogId );
00123   journal->setCustomProperty( "KBLOG", "ID", d_ptr->mPostId );
00124   return journal;
00125 }
00126 
00127 QString BlogPost::journalId() const
00128 {
00129   return d_ptr->mJournalId;
00130 }
00131 
00132 bool BlogPost::isPrivate() const
00133 {
00134   return d_ptr->mPrivate;
00135 }
00136 
00137 void BlogPost::setPrivate( bool privatePost )
00138 {
00139   d_ptr->mPrivate = privatePost;
00140 }
00141 
00142 QString BlogPost::postId() const
00143 {
00144   return d_ptr->mPostId;
00145 }
00146 
00147 void BlogPost::setPostId( const QString &postId )
00148 {
00149   d_ptr->mPostId = postId;
00150 }
00151 
00152 QString BlogPost::title() const
00153 {
00154   return d_ptr->mTitle;
00155 }
00156 
00157 void BlogPost::setTitle( const QString &title )
00158 {
00159   d_ptr->mTitle = title;
00160 }
00161 
00162 QString BlogPost::content() const
00163 {
00164   return d_ptr->mContent;
00165 }
00166 
00167 void BlogPost::setContent( const QString &content )
00168 {
00169   d_ptr->mContent = content;
00170 }
00171 
00172 // QString BlogPost::abbreviatedContent() const
00173 // {
00174 //   //TODO
00175 //   return 0;
00176 // }
00177 //
00178 // void BlogPost::setAbbreviatedContent( const QString &abbreviatedContent )
00179 // {
00180 //   Q_UNUSED( abbreviatedContent );
00181 //   //TODO
00182 // }
00183 
00184 KUrl BlogPost::link() const
00185 {
00186   return d_ptr->mLink;
00187 }
00188 
00189 void BlogPost::setLink( const KUrl &link ) const
00190 {
00191   d_ptr->mLink = link;
00192 }
00193 
00194 KUrl BlogPost::permaLink() const
00195 {
00196   return d_ptr->mPermaLink;
00197 }
00198 
00199 void BlogPost::setPermaLink( const KUrl &permalink ) const
00200 {
00201   d_ptr->mPermaLink = permalink;
00202 }
00203 
00204 bool BlogPost::isCommentAllowed() const
00205 {
00206   return d_ptr->mCommentAllowed;
00207 }
00208 
00209 void BlogPost::setCommentAllowed( bool commentAllowed )
00210 {
00211   d_ptr->mCommentAllowed = commentAllowed;
00212 }
00213 
00214 bool BlogPost::isTrackBackAllowed() const
00215 {
00216   return d_ptr->mCommentAllowed;
00217 }
00218 
00219 void BlogPost::setTrackBackAllowed ( bool allowTrackBacks )
00220 {
00221   d_ptr->mTrackBackAllowed = allowTrackBacks;
00222 }
00223 
00224 QString BlogPost::summary() const
00225 {
00226   return d_ptr->mSummary;
00227 }
00228 
00229 void BlogPost::setSummary( const QString &summary )
00230 {
00231   d_ptr->mSummary = summary;
00232 }
00233 
00234 QStringList BlogPost::tags() const
00235 {
00236   return d_ptr->mTags;
00237 }
00238 
00239 void BlogPost::setTags( const QStringList &tags )
00240 {
00241   d_ptr->mTags = tags;
00242 }
00243 
00244 // QList<KUrl> BlogPost::trackBackUrls() const
00245 // {
00246 //   //TODO
00247 //   return QList<KUrl>();
00248 // }
00249 //
00250 // void BlogPost::setTrackBackUrls( const QList<KUrl> &trackBackUrls )
00251 // {
00252 //   Q_UNUSED( trackBackUrls );
00253 //   //TODO
00254 // }
00255 
00256 QString BlogPost::mood() const
00257 {
00258   return d_ptr->mMood;
00259 }
00260 
00261 void BlogPost::setMood( const QString &mood )
00262 {
00263   d_ptr->mMood = mood;
00264 }
00265 
00266 QString BlogPost::music() const
00267 {
00268   return d_ptr->mMusic;
00269 }
00270 
00271 void BlogPost::setMusic( const QString &music )
00272 {
00273   d_ptr->mMusic = music;
00274 }
00275 
00276 QStringList BlogPost::categories() const
00277 {
00278   return d_ptr->mCategories;
00279 }
00280 
00281 void BlogPost::setCategories( const QStringList &categories )
00282 {
00283   d_ptr->mCategories = categories;
00284 }
00285 
00286 KDateTime BlogPost::creationDateTime() const
00287 {
00288   return d_ptr->mCreationDateTime;
00289 }
00290 
00291 void BlogPost::setCreationDateTime( const KDateTime &datetime )
00292 {
00293   d_ptr->mCreationDateTime = datetime;
00294 }
00295 
00296 KDateTime BlogPost::modificationDateTime() const
00297 {
00298   return d_ptr->mModificationDateTime;
00299 }
00300 
00301 void BlogPost::setModificationDateTime( const KDateTime &datetime )
00302 {
00303   d_ptr->mModificationDateTime = datetime;
00304 }
00305 
00306 BlogPost::Status BlogPost::status() const
00307 {
00308   return d_ptr->mStatus;
00309 }
00310 
00311 void BlogPost::setStatus( BlogPost::Status status )
00312 {
00313   d_ptr->mStatus = status;
00314 }
00315 
00316 QString BlogPost::error() const
00317 {
00318   return d_ptr->mError;
00319 }
00320 
00321 void BlogPost::setError( const QString &error )
00322 {
00323   d_ptr->mError = error;
00324 }
00325 
00326 BlogPost &BlogPost::operator=( const BlogPost &other )
00327 {
00328   BlogPost copy( other );
00329   swap( copy );
00330   return *this;
00331 }
00332 
00333 QString BlogPostPrivate::cleanRichText( QString richText ) const
00334 {
00335   QRegExp getBodyContents( "<body[^>]*>(.*)</body>" );
00336   if ( getBodyContents.indexIn( richText ) ) {
00337     // Get anything inside but excluding the body tags
00338     richText = getBodyContents.cap( 1 );
00339     // Get rid of any whitespace
00340     richText.remove( QRegExp( "^\\s+" ) );
00341   }
00342   // Get rid of styled paragraphs
00343   richText.replace( QRegExp( "<p style=\"[^\"]*\">" ), "<p>" );
00344 
00345   // If we're left with empty content then return a clean empty string
00346   if ( richText == "<p></p>" ) {
00347     richText.clear();
00348   }
00349 
00350   return richText;
00351 }
00352 
00353 } // namespace KBlog
00354 

KBlog Client Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal