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

KBlog Client Library

  • 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
34namespace KBlog {
35
36BlogPost::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
62BlogPost::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
71BlogPost::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
103BlogPost::~BlogPost()
104{
105 delete d_ptr;
106}
107
108KCal::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
129QString BlogPost::journalId() const
130{
131 return d_ptr->mJournalId;
132}
133
134bool BlogPost::isPrivate() const
135{
136 return d_ptr->mPrivate;
137}
138
139void BlogPost::setPrivate( bool privatePost )
140{
141 d_ptr->mPrivate = privatePost;
142}
143
144QString BlogPost::postId() const
145{
146 return d_ptr->mPostId;
147}
148
149void BlogPost::setPostId( const QString &postId )
150{
151 d_ptr->mPostId = postId;
152}
153
154QString BlogPost::title() const
155{
156 return d_ptr->mTitle;
157}
158
159void BlogPost::setTitle( const QString &title )
160{
161 d_ptr->mTitle = title;
162}
163
164QString BlogPost::content() const
165{
166 return d_ptr->mContent;
167}
168
169void 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
186QString BlogPost::additionalContent() const
187{
188 return d_ptr->mAdditionalContent;
189}
190
191void BlogPost::setAdditionalContent( const QString &additionalContent )
192{
193 d_ptr->mAdditionalContent = additionalContent;
194}
195
196QString BlogPost::slug() const
197{
198 return d_ptr->mWpSlug;
199}
200
201void BlogPost::setSlug( const QString &slug )
202{
203 d_ptr->mWpSlug = slug;
204}
205
206KUrl BlogPost::link() const
207{
208 return d_ptr->mLink;
209}
210
211void BlogPost::setLink( const KUrl &link ) const
212{
213 d_ptr->mLink = link;
214}
215
216KUrl BlogPost::permaLink() const
217{
218 return d_ptr->mPermaLink;
219}
220
221void BlogPost::setPermaLink( const KUrl &permalink ) const
222{
223 d_ptr->mPermaLink = permalink;
224}
225
226bool BlogPost::isCommentAllowed() const
227{
228 return d_ptr->mCommentAllowed;
229}
230
231void BlogPost::setCommentAllowed( bool commentAllowed )
232{
233 d_ptr->mCommentAllowed = commentAllowed;
234}
235
236bool BlogPost::isTrackBackAllowed() const
237{
238 return d_ptr->mCommentAllowed;
239}
240
241void BlogPost::setTrackBackAllowed ( bool allowTrackBacks )
242{
243 d_ptr->mTrackBackAllowed = allowTrackBacks;
244}
245
246QString BlogPost::summary() const
247{
248 return d_ptr->mSummary;
249}
250
251void BlogPost::setSummary( const QString &summary )
252{
253 d_ptr->mSummary = summary;
254}
255
256QStringList BlogPost::tags() const
257{
258 return d_ptr->mTags;
259}
260
261void 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
278QString BlogPost::mood() const
279{
280 return d_ptr->mMood;
281}
282
283void BlogPost::setMood( const QString &mood )
284{
285 d_ptr->mMood = mood;
286}
287
288QString BlogPost::music() const
289{
290 return d_ptr->mMusic;
291}
292
293void BlogPost::setMusic( const QString &music )
294{
295 d_ptr->mMusic = music;
296}
297
298QStringList BlogPost::categories() const
299{
300 return d_ptr->mCategories;
301}
302
303void BlogPost::setCategories( const QStringList &categories )
304{
305 d_ptr->mCategories = categories;
306}
307
308KDateTime BlogPost::creationDateTime() const
309{
310 return d_ptr->mCreationDateTime;
311}
312
313void BlogPost::setCreationDateTime( const KDateTime &datetime )
314{
315 d_ptr->mCreationDateTime = datetime;
316}
317
318KDateTime BlogPost::modificationDateTime() const
319{
320 return d_ptr->mModificationDateTime;
321}
322
323void BlogPost::setModificationDateTime( const KDateTime &datetime )
324{
325 d_ptr->mModificationDateTime = datetime;
326}
327
328BlogPost::Status BlogPost::status() const
329{
330 return d_ptr->mStatus;
331}
332
333void BlogPost::setStatus( BlogPost::Status status )
334{
335 d_ptr->mStatus = status;
336}
337
338QString BlogPost::error() const
339{
340 return d_ptr->mError;
341}
342
343void BlogPost::setError( const QString &error )
344{
345 d_ptr->mError = error;
346}
347
348BlogPost &BlogPost::operator=( const BlogPost &other )
349{
350 BlogPost copy( other );
351 swap( copy );
352 return *this;
353}
354
355QString 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
blog.h
This is the main interface for blogging APIs.
KBlog::BlogPost
A class that represents a blog post on the server.
Definition: blogpost.h:69
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::permaLink
KUrl permaLink() const
Returns the perma link path.
Definition: blogpost.cpp:216
KBlog::BlogPost::creationDateTime
KDateTime creationDateTime() const
Returns the creation date time.
Definition: blogpost.cpp:308
KBlog::BlogPost::summary
QString summary() const
Returns the summary.
Definition: blogpost.cpp:246
KBlog::BlogPost::isPrivate
bool isPrivate() const
Returns if the post is published or not.
Definition: blogpost.cpp:134
KBlog::BlogPost::setPostId
void setPostId(const QString &postId)
Sets the post id value.
Definition: blogpost.cpp:149
KBlog::BlogPost::mood
QString mood() const
Returns the mood.
Definition: blogpost.cpp:278
KBlog::BlogPost::setCategories
void setCategories(const QStringList &categories)
Sets the categories.
Definition: blogpost.cpp:303
KBlog::BlogPost::setPermaLink
void setPermaLink(const KUrl &permalink) const
Set the perma link path.
Definition: blogpost.cpp:221
KBlog::BlogPost::setTrackBackAllowed
void setTrackBackAllowed(bool allowTrackBacks)
Set whether track back should be allowed.
Definition: blogpost.cpp:241
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::setStatus
void setStatus(Status status)
Sets the status.
Definition: blogpost.cpp:333
KBlog::BlogPost::setCreationDateTime
void setCreationDateTime(const KDateTime &datetime)
Sets the creation time.
Definition: blogpost.cpp:313
KBlog::BlogPost::setContent
void setContent(const QString &content)
Sets the content.
Definition: blogpost.cpp:169
KBlog::BlogPost::isCommentAllowed
bool isCommentAllowed() const
Returns whether comments should be allowed.
Definition: blogpost.cpp:226
KBlog::BlogPost::swap
void swap(BlogPost &other)
The swap operator.
Definition: blogpost.h:453
KBlog::BlogPost::content
QString content() const
Returns the content.
Definition: blogpost.cpp:164
KBlog::BlogPost::setSummary
void setSummary(const QString &summary)
Set the summary.
Definition: blogpost.cpp:251
KBlog::BlogPost::~BlogPost
virtual ~BlogPost()
Virtual default destructor.
Definition: blogpost.cpp:103
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::setLink
void setLink(const KUrl &link) const
Set the link path.
Definition: blogpost.cpp:211
KBlog::BlogPost::tags
QStringList tags() const
Returns the tags list as a QStringList.
Definition: blogpost.cpp:256
KBlog::BlogPost::setMusic
void setMusic(const QString &music)
Set the music.
Definition: blogpost.cpp:293
KBlog::BlogPost::link
KUrl link() const
Returns the link path.
Definition: blogpost.cpp:206
KBlog::BlogPost::music
QString music() const
Returns the music.
Definition: blogpost.cpp:288
KBlog::BlogPost::BlogPost
BlogPost(const KBlog::BlogPost &post)
Constructor.
Definition: blogpost.cpp:36
KBlog::BlogPost::modificationDateTime
KDateTime modificationDateTime() const
Returns the modification date time.
Definition: blogpost.cpp:318
KBlog::BlogPost::title
QString title() const
Returns the title.
Definition: blogpost.cpp:154
KBlog::BlogPost::setError
void setError(const QString &error)
Sets the error.
Definition: blogpost.cpp:343
KBlog::BlogPost::categories
QStringList categories() const
Returns the categories.
Definition: blogpost.cpp:298
KBlog::BlogPost::setCommentAllowed
void setCommentAllowed(bool commentAllowed)
Set whether comments should be allowed.
Definition: blogpost.cpp:231
KBlog::BlogPost::setTags
void setTags(const QStringList &tags)
Set the tags list.
Definition: blogpost.cpp:261
KBlog::BlogPost::setMood
void setMood(const QString &mood)
Set the mood list.
Definition: blogpost.cpp:283
KBlog::BlogPost::additionalContent
QString additionalContent() const
Returns the additional content, (mt_text_more of MovableType API)
Definition: blogpost.cpp:186
KBlog::BlogPost::postId
QString postId() const
Returns the postId.
Definition: blogpost.cpp:144
KBlog::BlogPost::operator=
BlogPost & operator=(const BlogPost &post)
The overloaed = operator.
Definition: blogpost.cpp:348
KBlog::BlogPost::setAdditionalContent
void setAdditionalContent(const QString &additionalContent)
Sets the additional content, (mt_text_more of MovableType API)
Definition: blogpost.cpp:191
KBlog::BlogPost::Status
Status
The enumartion of the different post status, reflecting the status changes on the server.
Definition: blogpost.h:393
KBlog::BlogPost::New
@ New
Status of a freshly constructed post on the client.
Definition: blogpost.h:395
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::isTrackBackAllowed
bool isTrackBackAllowed() const
Returns whether track back should be allowed.
Definition: blogpost.cpp:236
KBlog::BlogPost::error
QString error() const
Returns the last error.
Definition: blogpost.cpp:338
KBlog::BlogPost::setTitle
void setTitle(const QString &title)
Sets the title.
Definition: blogpost.cpp:159
KBlog::BlogPost::setPrivate
void setPrivate(bool privatePost)
Sets the post to private viewings only.
Definition: blogpost.cpp:139
KBlog::BlogPost::setModificationDateTime
void setModificationDateTime(const KDateTime &datetime)
Sets the modification time.
Definition: blogpost.cpp:323
KBlog::BlogPost::status
Status status() const
Returns the status on the server.
Definition: blogpost.cpp:328
KBlog::Blog
A class that provides methods to call functions on a supported blog web application.
Definition: blog.h:72
KBlog::Blog::username
QString username() const
Returns the username used in blog authentication.
Definition: blog.cpp:91
KBlog::Blog::blogId
QString blogId() const
Returns the unique ID for the specific blog on the server.
Definition: blog.cpp:109
KBlog::Blog::url
KUrl url() const
Get the URL for the blog's XML-RPC interface.
Definition: blog.cpp:121
KBlog
Namespace for blog related classes.
Definition: blog.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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