1/*
2 This file is part of the kblog library.
3
4 Copyright (c) 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#ifndef KBLOG_BLOGPOSTING_H
24#define KBLOG_BLOGPOSTING_H
25
26#include <kblog/kblog_export.h>
27
28#include <kurl.h>
29
30#include <QtCore/QtAlgorithms>
31
32class QStringList;
33
34class KDateTime;
35class KUrl;
36
37namespace KCal {
38 class Journal;
39}
40
41namespace KBlog {
42 class Blog;
43 class BlogPostPrivate;
44
45/**
46 @brief
47 A class that represents a blog post on the server.
48
49 @code
50 KBlog::BlogPost *post = new BlogPost();
51 post->setTitle( "This is the title." );
52 post->setContent( "Here is some the content..." );
53 post->setPrivate( true ); // false on default
54 connect( backend, createdPost( KBlog::BlogPost* ),
55 this, createdPost( KBlog::BlogPost* );
56 backend->createPost( post );
57 ...
58 void createdPost( KBlog::BlogPost* post )
59 {
60 setMyFancyGUIPostId( post->postId() );
61 setMyFancyGUIPermaLink( post->permaLink() );
62 }
63 @endcode
64
65 @author Christian Weilbach \<christian_weilbach\@web.de\>
66*/
67
68class KBLOG_EXPORT BlogPost
69{
70
71public:
72
73 /**
74 Constructor.
75 */
76 BlogPost( const KBlog::BlogPost &post );
77
78 /**
79 Constructor.
80 @param postId The ID of the post on the server.
81 */
82 explicit BlogPost( const QString &postId = QString() );
83
84 /** Constructor to create a blog post from a KCal Journal.
85 @param journal The journal to use to create the post
86 */
87 explicit BlogPost( const KCal::Journal &journal );
88
89 /**
90 Virtual default destructor.
91 */
92 virtual ~BlogPost();
93
94 /**
95 Returns a KCal journal from the blog post owned by the caller.
96 @param blog The blog object to convert.
97 @return journal
98 */
99 KCal::Journal *journal( const Blog &blog ) const;
100
101 /**
102 Returns the ID used by the journal in creation, if created from a journal.
103 @return journal ID
104 */
105 QString journalId() const;
106
107 /**
108 Returns if the post is published or not.
109 @return bool
110
111 @see setPrivate()
112 */
113 bool isPrivate() const;
114
115 /**
116 Sets the post to private viewings only.
117 @param privatePost set this to false, if you don't want to publish
118 the blog post immediately.
119
120 @see isPrivate()
121 */
122 void setPrivate( bool privatePost );
123
124 /**
125 Returns the postId. This is for fetched posts.
126 @return postId
127
128 @see setPostId()
129 */
130 QString postId() const;
131
132 /**
133 Sets the post id value. This is important for modifying posts.
134 @param postId set this to the post id on the server.
135
136 @see postId()
137 */
138 void setPostId( const QString &postId );
139
140 /**
141 Returns the title.
142 @return title
143
144 @see setTitle()
145 */
146 QString title() const;
147
148 /**
149 Sets the title.
150 @param title set the title.
151
152 @see title()
153 */
154 void setTitle( const QString &title );
155
156 /**
157 Returns the content.
158 @return content
159
160 @see setContent()
161 */
162 QString content() const;
163
164 /**
165 Sets the content.
166 @param content set the content.
167
168 @see content()
169 */
170 void setContent( const QString &content );
171
172// QString abbreviatedContent() const; // TODO check if necessary
173// void setAbbreviatedContent( const QString &abbreviatedContent );
174
175 /**
176 Returns the additional content, (mt_text_more of MovableType API)
177 @return additional content
178
179 @see setAdditionalContent()
180 */
181 QString additionalContent() const;
182
183 /**
184 Sets the additional content, (mt_text_more of MovableType API)
185 @param additionalContent set the additional content
186
187 @see additionalContent()
188 */
189 void setAdditionalContent( const QString &additionalContent );
190
191 /**
192 Returns the Wordpress posts Slug (or permalink will use for post)
193 Currently just wordpress supports this!
194 @return wordpress slug
195
196 @see setSlug()
197 */
198 QString slug() const;
199
200 /**
201 Sets the Wordpress slug property! (will use to set post's permalink)
202 Currently just wordpress supports this!
203 @param slug wordpress slug
204
205 @see slug()
206 */
207 void setSlug( const QString &slug );
208 /**
209 Returns the link path.
210 @return link
211
212 @see setLink()
213 */
214 KUrl link() const;
215
216 /**
217 Set the link path.
218 @param link The path to set.
219
220 @see link()
221 */
222 void setLink( const KUrl &link ) const;
223
224 /**
225 Returns the perma link path.
226 @return permaLink
227
228 @see setPermaLink()
229 */
230 KUrl permaLink() const;
231
232 /**
233 Set the perma link path.
234 @param permalink The path to set.
235
236 @see permaLink()
237 */
238 void setPermaLink( const KUrl &permalink ) const;
239
240 /**
241 Returns whether comments should be allowed.
242 @return commentAllowed
243
244 @see setCommentAllowed()
245 */
246 bool isCommentAllowed() const;
247
248 /**
249 Set whether comments should be allowed.
250 @param commentAllowed
251
252 @see isCommentAllowed()
253 */
254 void setCommentAllowed( bool commentAllowed );
255
256 /**
257 Returns whether track back should be allowed.
258 @return trackBackAllowed
259
260 @see setTrackBackAllowed()
261 */
262 bool isTrackBackAllowed() const; // pings in Movable Type
263
264 /**
265 Set whether track back should be allowed.
266 @param allowTrackBacks
267
268 @see isTrackBackAllowed()
269 */
270 void setTrackBackAllowed ( bool allowTrackBacks );
271
272 /**
273 Returns the summary.
274 @return summary
275
276 @see setSummary()
277 */
278 QString summary() const; // excerpts in Movable Type
279
280 /**
281 Set the summary.
282 @param summary
283
284 @see summary()
285 */
286 void setSummary( const QString &summary );
287
288 /**
289 Returns the tags list as a QStringList.
290 @return tags list
291
292 @see setTags()
293 */
294 QStringList tags() const; // keywords in Movable Type
295
296 /**
297 Set the tags list.
298 @param tags The tags list.
299
300 @see tags()
301 */
302 void setTags( const QStringList &tags );
303
304// QList<KUrl> trackBackUrls() const; // TODO check if necessary
305// void setTrackBackUrls( const QList<KUrl> &trackBackUrls );
306
307 /**
308 Returns the mood.
309 @return mood
310
311 @see setMood()
312 */
313 QString mood() const;
314
315 /**
316 Set the mood list.
317 @param mood The mood.
318
319 @see mood()
320 */
321 void setMood( const QString &mood );
322
323 /**
324 Returns the music.
325 @return music
326
327 @see setMusic()
328 */
329 QString music() const;
330
331 /**
332 Set the music.
333 @param music The music.
334
335 @see music()
336 */
337 void setMusic( const QString &music );
338
339 /**
340 Returns the categories.
341 @return categories
342
343 @see setCategories()
344 */
345 QStringList categories() const;
346
347 /**
348 Sets the categories. The first one is used as the primary
349 category if possible.
350 @param categories set the categories.
351
352 @see categories()
353 */
354 void setCategories( const QStringList &categories );
355
356 /**
357 Returns the creation date time.
358 @return creationdatetime
359
360 @see setCreationDateTime()
361 */
362 KDateTime creationDateTime() const;
363
364 /**
365 Sets the creation time. This is used by most Blogs and is generally
366 the shown date. Set it if you want to change the shown date.
367 @param datetime set the time the post has been created.
368
369 @see creationTime()
370 */
371 void setCreationDateTime( const KDateTime &datetime );
372
373 /**
374 Returns the modification date time.
375 @return modificationdatetime
376
377 @see setModificationDateTime(), creationDateTime()
378 */
379 KDateTime modificationDateTime() const;
380
381 /**
382 Sets the modification time.
383 @param datetime set the time the post has been modified.
384
385 @see modificationTime(), setCreationDateTime()
386 */
387 void setModificationDateTime( const KDateTime &datetime );
388
389 /**
390 The enumartion of the different post status, reflecting the status changes
391 on the server.
392 */
393 enum Status {
394 /** Status of a freshly constructed post on the client. */
395 New,
396 /** Status of a successfully fetched post.
397 @see Blog::fetchPost( KBlog::BlogPost* ) */
398 Fetched,
399 /** Status of a successfully created post.
400 @see Blog::createPost( KBlog::BlogPost* ) */
401 Created,
402 /** Status of a successfully modified post.
403 @see Blog::modifyPost( KBlog::BlogPost* ) */
404 Modified,
405 /** Status of a successfully removed post.
406 @see Blog::removePost( KBlog::BlogPost* ) */
407 Removed,
408 /** Status when an error on the server side occurred.
409 @see error() */
410 Error
411 };
412
413 /**
414 Returns the status on the server.
415 @return status
416
417 @see setStatus(), Status
418 */
419 Status status() const;
420
421 /**
422 Sets the status.
423 @param status The status on the server.
424
425 @see status(), Status
426 */
427 void setStatus( Status status );
428
429 /**
430 Returns the last error.
431 @returns error
432
433 @see setError(), Error
434 */
435 QString error() const;
436
437 /**
438 Sets the error.
439 @param error The error string.
440
441 @see error(), Error
442 */
443 void setError( const QString &error );
444
445 /**
446 The overloaed = operator.
447 */
448 BlogPost &operator=( const BlogPost &post );
449
450 /**
451 The swap operator.
452 */
453 void swap( BlogPost &other ) {
454 qSwap( this->d_ptr, other.d_ptr );
455 }
456
457 private:
458 BlogPostPrivate *d_ptr; //krazy:exclude=dpointer can't constify due to bic and swap being declared inline
459};
460
461} //namespace KBlog
462
463#endif
464