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

KBlog Client Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kblog
blogpost.cpp
1 /*
2  This file is part of the kblog library.
3 
4  Copyright (c) 2006-2007 Christian Weilbach <christian_weilbach@web.de>
5  Copyright (c) 2007 Mike McQuaid <mike@mikemcquaid.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "blogpost.h"
24 #include "blogpost_p.h"
25 
26 #include "blog.h"
27 
28 #include <KDateTime>
29 #include <KUrl>
30 #include <kcal/journal.h>
31 
32 #include <QStringList>
33 
34 namespace KBlog {
35 
36 BlogPost::BlogPost( const KBlog::BlogPost &post )
37  : d_ptr( new BlogPostPrivate )
38 {
39  d_ptr->q_ptr = this;
40  d_ptr->mPrivate = post.isPrivate();
41  d_ptr->mPostId = post.postId();
42  d_ptr->mTitle = post.title();
43  d_ptr->mContent = post.content();
44  d_ptr->mAdditionalContent = post.additionalContent();
45  d_ptr->mWpSlug = post.slug();
46  d_ptr->mCategories = post.categories();
47  d_ptr->mTags = post.tags();
48  d_ptr->mMood = post.mood();
49  d_ptr->mPermaLink = post.permaLink();
50  d_ptr->mSummary = post.summary();
51  d_ptr->mLink = post.link();
52  d_ptr->mMusic = post.music();
53  d_ptr->mTrackBackAllowed = post.isTrackBackAllowed();
54  d_ptr->mCommentAllowed = post.isCommentAllowed();
55  d_ptr->mError = post.error();
56  d_ptr->mJournalId = post.journalId();
57  d_ptr->mStatus = post.status();
58  d_ptr->mCreationDateTime = post.creationDateTime();
59  d_ptr->mModificationDateTime = post.modificationDateTime();
60 }
61 
62 BlogPost::BlogPost( const QString &postId )
63  : d_ptr( new BlogPostPrivate )
64 {
65  d_ptr->q_ptr = this;
66  d_ptr->mPrivate = false;
67  d_ptr->mPostId = postId;
68  d_ptr->mStatus = New;
69 }
70 
71 BlogPost::BlogPost( const KCal::Journal &journal )
72  : d_ptr( new BlogPostPrivate )
73 {
74  d_ptr->q_ptr = this;
75  d_ptr->mPrivate = false;
76  d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
77  d_ptr->mJournalId = journal.uid();
78  d_ptr->mStatus = New;
79  d_ptr->mTitle = journal.summary();
80  if ( journal.descriptionIsRich() ) {
81  d_ptr->mContent = d_ptr->cleanRichText( journal.description() );
82  } else {
83  d_ptr->mContent = journal.description();
84  }
85  d_ptr->mCategories = journal.categories();
86  d_ptr->mCreationDateTime = journal.dtStart();
87 }
88 
89 // BlogPost::BlogPost( const KCal::Journal &journal, BlogPostPrivate &dd )
90 // : d_ptr( &dd )
91 // {
92 // d_ptr->q_ptr = this;
93 // d_ptr->mPrivate = false;
94 // d_ptr->mPostId = journal.customProperty( "KBLOG", "ID" );
95 // d_ptr->mJournalId = journal.uid();
96 // d_ptr->mStatus = New;
97 // d_ptr->mTitle = journal.summary();
98 // d_ptr->mContent = journal.description();
99 // d_ptr->mCategories = journal.categories();
100 // d_ptr->mCreationDateTime = journal.dtStart();
101 // }
102 
103 BlogPost::~BlogPost()
104 {
105  delete d_ptr;
106 }
107 
108 KCal::Journal *BlogPost::journal( const Blog &blog ) const
109 {
110  QString url = blog.url().url();
111  QString username = blog.username();
112  QString blogId = blog.blogId();
113  // Generate unique ID. Should be unique enough...
114  QString id = QLatin1String("kblog-") + url + QLatin1Char('-') + blogId + QLatin1Char('-') + username +
115  QLatin1Char('-') + d_ptr->mPostId;
116  KCal::Journal *journal = new KCal::Journal();
117  journal->setUid( id );
118  journal->setSummary( d_ptr->mTitle );
119  journal->setCategories( d_ptr->mCategories );
120  journal->setDescription( d_ptr->mContent, true );
121  journal->setDtStart( d_ptr->mCreationDateTime );
122  journal->setCustomProperty( "KBLOG", "URL", url );
123  journal->setCustomProperty( "KBLOG", "USER", blog.username() );
124  journal->setCustomProperty( "KBLOG", "BLOG", blogId );
125  journal->setCustomProperty( "KBLOG", "ID", d_ptr->mPostId );
126  return journal;
127 }
128 
129 QString BlogPost::journalId() const
130 {
131  return d_ptr->mJournalId;
132 }
133 
134 bool BlogPost::isPrivate() const
135 {
136  return d_ptr->mPrivate;
137 }
138 
139 void BlogPost::setPrivate( bool privatePost )
140 {
141  d_ptr->mPrivate = privatePost;
142 }
143 
144 QString BlogPost::postId() const
145 {
146  return d_ptr->mPostId;
147 }
148 
149 void BlogPost::setPostId( const QString &postId )
150 {
151  d_ptr->mPostId = postId;
152 }
153 
154 QString BlogPost::title() const
155 {
156  return d_ptr->mTitle;
157 }
158 
159 void BlogPost::setTitle( const QString &title )
160 {
161  d_ptr->mTitle = title;
162 }
163 
164 QString BlogPost::content() const
165 {
166  return d_ptr->mContent;
167 }
168 
169 void BlogPost::setContent( const QString &content )
170 {
171  d_ptr->mContent = content;
172 }
173 
174 // QString BlogPost::abbreviatedContent() const
175 // {
176 // //TODO
177 // return 0;
178 // }
179 //
180 // void BlogPost::setAbbreviatedContent( const QString &abbreviatedContent )
181 // {
182 // Q_UNUSED( abbreviatedContent );
183 // //TODO
184 // }
185 
186 QString BlogPost::additionalContent() const
187 {
188  return d_ptr->mAdditionalContent;
189 }
190 
191 void BlogPost::setAdditionalContent( const QString &additionalContent )
192 {
193  d_ptr->mAdditionalContent = additionalContent;
194 }
195 
196 QString BlogPost::slug() const
197 {
198  return d_ptr->mWpSlug;
199 }
200 
201 void BlogPost::setSlug( const QString &slug )
202 {
203  d_ptr->mWpSlug = slug;
204 }
205 
206 KUrl BlogPost::link() const
207 {
208  return d_ptr->mLink;
209 }
210 
211 void BlogPost::setLink( const KUrl &link ) const
212 {
213  d_ptr->mLink = link;
214 }
215 
216 KUrl BlogPost::permaLink() const
217 {
218  return d_ptr->mPermaLink;
219 }
220 
221 void BlogPost::setPermaLink( const KUrl &permalink ) const
222 {
223  d_ptr->mPermaLink = permalink;
224 }
225 
226 bool BlogPost::isCommentAllowed() const
227 {
228  return d_ptr->mCommentAllowed;
229 }
230 
231 void BlogPost::setCommentAllowed( bool commentAllowed )
232 {
233  d_ptr->mCommentAllowed = commentAllowed;
234 }
235 
236 bool BlogPost::isTrackBackAllowed() const
237 {
238  return d_ptr->mCommentAllowed;
239 }
240 
241 void BlogPost::setTrackBackAllowed ( bool allowTrackBacks )
242 {
243  d_ptr->mTrackBackAllowed = allowTrackBacks;
244 }
245 
246 QString BlogPost::summary() const
247 {
248  return d_ptr->mSummary;
249 }
250 
251 void BlogPost::setSummary( const QString &summary )
252 {
253  d_ptr->mSummary = summary;
254 }
255 
256 QStringList BlogPost::tags() const
257 {
258  return d_ptr->mTags;
259 }
260 
261 void BlogPost::setTags( const QStringList &tags )
262 {
263  d_ptr->mTags = tags;
264 }
265 
266 // QList<KUrl> BlogPost::trackBackUrls() const
267 // {
268 // //TODO
269 // return QList<KUrl>();
270 // }
271 //
272 // void BlogPost::setTrackBackUrls( const QList<KUrl> &trackBackUrls )
273 // {
274 // Q_UNUSED( trackBackUrls );
275 // //TODO
276 // }
277 
278 QString BlogPost::mood() const
279 {
280  return d_ptr->mMood;
281 }
282 
283 void BlogPost::setMood( const QString &mood )
284 {
285  d_ptr->mMood = mood;
286 }
287 
288 QString BlogPost::music() const
289 {
290  return d_ptr->mMusic;
291 }
292 
293 void BlogPost::setMusic( const QString &music )
294 {
295  d_ptr->mMusic = music;
296 }
297 
298 QStringList BlogPost::categories() const
299 {
300  return d_ptr->mCategories;
301 }
302 
303 void BlogPost::setCategories( const QStringList &categories )
304 {
305  d_ptr->mCategories = categories;
306 }
307 
308 KDateTime BlogPost::creationDateTime() const
309 {
310  return d_ptr->mCreationDateTime;
311 }
312 
313 void BlogPost::setCreationDateTime( const KDateTime &datetime )
314 {
315  d_ptr->mCreationDateTime = datetime;
316 }
317 
318 KDateTime BlogPost::modificationDateTime() const
319 {
320  return d_ptr->mModificationDateTime;
321 }
322 
323 void BlogPost::setModificationDateTime( const KDateTime &datetime )
324 {
325  d_ptr->mModificationDateTime = datetime;
326 }
327 
328 BlogPost::Status BlogPost::status() const
329 {
330  return d_ptr->mStatus;
331 }
332 
333 void BlogPost::setStatus( BlogPost::Status status )
334 {
335  d_ptr->mStatus = status;
336 }
337 
338 QString BlogPost::error() const
339 {
340  return d_ptr->mError;
341 }
342 
343 void BlogPost::setError( const QString &error )
344 {
345  d_ptr->mError = error;
346 }
347 
348 BlogPost &BlogPost::operator=( const BlogPost &other )
349 {
350  BlogPost copy( other );
351  swap( copy );
352  return *this;
353 }
354 
355 QString BlogPostPrivate::cleanRichText( QString richText ) const
356 {
357  QRegExp getBodyContents( QLatin1String("<body[^>]*>(.*)</body>") );
358  if ( getBodyContents.indexIn( richText ) ) {
359  // Get anything inside but excluding the body tags
360  richText = getBodyContents.cap( 1 );
361  // Get rid of any whitespace
362  richText.remove( QRegExp( QLatin1String("^\\s+") ) );
363  }
364  // Get rid of styled paragraphs
365  richText.replace( QRegExp( QLatin1String("<p style=\"[^\"]*\">" )), QLatin1String("<p>") );
366 
367  // If we're left with empty content then return a clean empty string
368  if ( richText == QLatin1String("<p></p>") ) {
369  richText.clear();
370  }
371 
372  return richText;
373 }
374 
375 } // namespace KBlog
KBlog::BlogPost::title
QString title() const
Returns the title.
Definition: blogpost.cpp:154
KBlog::BlogPost::creationDateTime
KDateTime creationDateTime() const
Returns the creation date time.
Definition: blogpost.cpp:308
KBlog::BlogPost::setLink
void setLink(const KUrl &link) const
Set the link path.
Definition: blogpost.cpp:211
KBlog::BlogPost::link
KUrl link() const
Returns the link path.
Definition: blogpost.cpp:206
KBlog::BlogPost::tags
QStringList tags() const
Returns the tags list as a QStringList.
Definition: blogpost.cpp:256
KBlog::BlogPost::operator=
BlogPost & operator=(const BlogPost &post)
The overloaed = operator.
Definition: blogpost.cpp:348
KBlog::BlogPost::~BlogPost
virtual ~BlogPost()
Virtual default destructor.
Definition: blogpost.cpp:103
KBlog::BlogPost::mood
QString mood() const
Returns the mood.
Definition: blogpost.cpp:278
KBlog::BlogPost::isCommentAllowed
bool isCommentAllowed() const
Returns whether comments should be allowed.
Definition: blogpost.cpp:226
KBlog::BlogPost::Status
Status
The enumartion of the different post status, reflecting the status changes on the server...
Definition: blogpost.h:393
KBlog::BlogPost::isTrackBackAllowed
bool isTrackBackAllowed() const
Returns whether track back should be allowed.
Definition: blogpost.cpp:236
KBlog::BlogPost::summary
QString summary() const
Returns the summary.
Definition: blogpost.cpp:246
KBlog::BlogPost::setTitle
void setTitle(const QString &title)
Sets the title.
Definition: blogpost.cpp:159
KBlog::BlogPost::setPostId
void setPostId(const QString &postId)
Sets the post id value.
Definition: blogpost.cpp:149
KBlog::BlogPost::setMood
void setMood(const QString &mood)
Set the mood list.
Definition: blogpost.cpp:283
KBlog::Blog::username
QString username() const
Returns the username used in blog authentication.
Definition: blog.cpp:91
KBlog::BlogPost::setCreationDateTime
void setCreationDateTime(const KDateTime &datetime)
Sets the creation time.
Definition: blogpost.cpp:313
KBlog::BlogPost::setMusic
void setMusic(const QString &music)
Set the music.
Definition: blogpost.cpp:293
KBlog::BlogPost::status
Status status() const
Returns the status on the server.
Definition: blogpost.cpp:328
KBlog::BlogPost::additionalContent
QString additionalContent() const
Returns the additional content, (mt_text_more of MovableType API)
Definition: blogpost.cpp:186
KBlog::BlogPost::setAdditionalContent
void setAdditionalContent(const QString &additionalContent)
Sets the additional content, (mt_text_more of MovableType API)
Definition: blogpost.cpp:191
KBlog::BlogPost::setContent
void setContent(const QString &content)
Sets the content.
Definition: blogpost.cpp:169
KBlog::BlogPost::error
QString error() const
Returns the last error.
Definition: blogpost.cpp:338
KBlog::BlogPost::modificationDateTime
KDateTime modificationDateTime() const
Returns the modification date time.
Definition: blogpost.cpp:318
KBlog::BlogPost::setModificationDateTime
void setModificationDateTime(const KDateTime &datetime)
Sets the modification time.
Definition: blogpost.cpp:323
KBlog::Blog::blogId
QString blogId() const
Returns the unique ID for the specific blog on the server.
Definition: blog.cpp:109
KBlog::BlogPost::setStatus
void setStatus(Status status)
Sets the status.
Definition: blogpost.cpp:333
KBlog::Blog::url
KUrl url() const
Get the URL for the blog's XML-RPC interface.
Definition: blog.cpp:121
KBlog::BlogPost::setTrackBackAllowed
void setTrackBackAllowed(bool allowTrackBacks)
Set whether track back should be allowed.
Definition: blogpost.cpp:241
KBlog::BlogPost::setSlug
void setSlug(const QString &slug)
Sets the Wordpress slug property! (will use to set post's permalink) Currently just wordpress support...
Definition: blogpost.cpp:201
KBlog::BlogPost::slug
QString slug() const
Returns the Wordpress posts Slug (or permalink will use for post) Currently just wordpress supports t...
Definition: blogpost.cpp:196
KBlog::BlogPost::setCommentAllowed
void setCommentAllowed(bool commentAllowed)
Set whether comments should be allowed.
Definition: blogpost.cpp:231
KBlog::BlogPost::setPrivate
void setPrivate(bool privatePost)
Sets the post to private viewings only.
Definition: blogpost.cpp:139
KBlog::BlogPost::content
QString content() const
Returns the content.
Definition: blogpost.cpp:164
KBlog::BlogPost::permaLink
KUrl permaLink() const
Returns the perma link path.
Definition: blogpost.cpp:216
KBlog::BlogPost::setPermaLink
void setPermaLink(const KUrl &permalink) const
Set the perma link path.
Definition: blogpost.cpp:221
KBlog::BlogPost::BlogPost
BlogPost(const KBlog::BlogPost &post)
Constructor.
Definition: blogpost.cpp:36
KBlog::BlogPost
A class that represents a blog post on the server.
Definition: blogpost.h:68
KBlog::BlogPost::setCategories
void setCategories(const QStringList &categories)
Sets the categories.
Definition: blogpost.cpp:303
KBlog::BlogPost::journal
KCal::Journal * journal(const Blog &blog) const
Returns a KCal journal from the blog post owned by the caller.
Definition: blogpost.cpp:108
KBlog::BlogPost::music
QString music() const
Returns the music.
Definition: blogpost.cpp:288
KBlog::BlogPost::New
Status of a freshly constructed post on the client.
Definition: blogpost.h:395
KBlog::BlogPost::setSummary
void setSummary(const QString &summary)
Set the summary.
Definition: blogpost.cpp:251
KBlog::BlogPost::journalId
QString journalId() const
Returns the ID used by the journal in creation, if created from a journal.
Definition: blogpost.cpp:129
KBlog::BlogPost::categories
QStringList categories() const
Returns the categories.
Definition: blogpost.cpp:298
KBlog::BlogPost::setTags
void setTags(const QStringList &tags)
Set the tags list.
Definition: blogpost.cpp:261
KBlog::Blog
A class that provides methods to call functions on a supported blog web application.
Definition: blog.h:71
blog.h
This is the main interface for blogging APIs.
KBlog::BlogPost::swap
void swap(BlogPost &other)
The swap operator.
Definition: blogpost.h:453
KBlog::BlogPost::isPrivate
bool isPrivate() const
Returns if the post is published or not.
Definition: blogpost.cpp:134
KBlog::BlogPost::postId
QString postId() const
Returns the postId.
Definition: blogpost.cpp:144
KBlog::BlogPost::setError
void setError(const QString &error)
Sets the error.
Definition: blogpost.cpp:343
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:55 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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