summaryrefslogtreecommitdiffstats
path: root/kresources/blogging/API_Blog.cpp
blob: b6ac3752b1a6fb1c39686ba36464445dce47ee9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/***************************************************************************
*   Copyright (C) 2004-05 Reinhold Kainhofer <reinhold@kainhofer.com>     *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
***************************************************************************/
#include "API_Blog.h"
#include <kdebug.h>
#include <tqvariant.h>

using namespace KBlog;

APIBlog::APIBlog( const KURL &url, TQObject *parent, const char *name ) :
    TQObject( parent, name ),
    mServerURL( url ), mAppID( TQString::null ), mDownloadCount( 20 )
{}

APIBlog::~APIBlog()
{}

void APIBlog::dumpBlog( BlogPosting *blog )
{
  kdDebug() << "-----------------------------------" << endl;
  kdDebug() << "Post " << blog->postID() << " by \"" <<
               blog->userID() << "\" on " <<
               blog->dateTime().toString() << endl;
  kdDebug() << "Title: " << blog->title() << endl;
  kdDebug() << blog->content() <<endl;
  kdDebug() << "-----------------------------------" << endl;
}



/*void APIBlog::setTemplateTags( const BlogTemplate& Template )
{
  mTemplate = Template;
}
BlogTemplate APIBlog::templateTags() const
{
  return mTemplate;
}*/

/*void APIBlog::deletePost( const TQString &postID )
{
  BlogPosting *post = new BlogPosting();
  post->setPostID( postID );
  deletePost( post );
  delete post;
}*/

TQValueList<TQVariant> APIBlog::defaultArgs( const TQString &id )
{
  TQValueList<TQVariant> args;
  args << TQVariant( mAppID );
  if ( !id.isNull() ) {
    args << TQVariant( id );
  }
  args << TQVariant( mUsername )
       << TQVariant( mPassword );
  return args;
}


KCal::Journal *APIBlog::journalFromPosting( KBlog::BlogPosting *blog )
{
  if ( !blog ) return 0;
  KCal::Journal *j = new KCal::Journal();
  TQDateTime dt = blog->dateTime();
  TQDateTime creationDt = blog->creationDateTime();
  TQDateTime modificationDt = blog->modificationDateTime();
kdDebug() << "dt            ="<<dt.toString( Qt::ISODate ) << endl;
kdDebug() << "creationDt    ="<<creationDt.toString( Qt::ISODate ) << endl;
kdDebug() << "modificationDt="<<modificationDt.toString( Qt::ISODate ) << endl;
  if ( dt.isValid() && !dt.isNull() ) {
    j->setDtStart( dt );
  } else if ( creationDt.isValid() && !creationDt.isNull() ) {
    j->setDtStart( creationDt );
  } else if ( modificationDt.isValid() && !modificationDt.isNull() ) {
    j->setDtStart( modificationDt );
  }
  
  j->setCreated( blog->creationDateTime() );
  j->setLastModified( blog->modificationDateTime() );
  j->setFloats( false );
  kdDebug() << "Date for blog " << blog->title() << " is "
            << blog->dateTime().toString()<<endl;
  j->setSummary( blog->title() );
  j->setDescription( blog->content() );
  j->setCategories( TQStringList( blog->category() ) );
  j->setOrganizer( blog->userID() );
  j->setCustomProperty( "KCalBloggerRes", "UserID", blog->userID() );
  j->setCustomProperty( "KCalBloggerRes", "BlogID", blog->blogID() );
  j->setCustomProperty( "KCalBloggerRes", "PostID", blog->postID() );

  // TODO: Set the read-only flag in the resource!
//   j->setReadOnly( readOnly() );

  return j;
}

KBlog::BlogPosting *APIBlog::postingFromJournal( KCal::Journal *journal )
{
  KBlog::BlogPosting *item = new KBlog::BlogPosting();
  if ( journal && item ) {
    item->setContent( journal->description() );
    item->setTitle( journal->summary() );
    item->setCategory( journal->categories().first() );
    item->setDateTime( journal->dtStart() );
    item->setModificationDateTime( journal->lastModified() );
    item->setCreationDateTime( journal->created() );
    item->setUserID( journal->customProperty( "KCalBloggerRes", "UserID" ) );
    item->setBlogID( journal->customProperty( "KCalBloggerRes", "BlogID" ) );
    item->setPostID( journal->customProperty( "KCalBloggerRes", "PostID" ) );
  }
  return item;
}


#include "API_Blog.moc"