summaryrefslogtreecommitdiffstats
path: root/tderesources/blogging/API_Blog.h
blob: 9425bd5e6a3b7085419bca0830c51afe6f3e4af8 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**************************************************************************
*   Copyright (C) 2004 by 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.                                   *
***************************************************************************/
#ifndef API_BLOG_H
#define API_BLOG_H

#include <kurl.h>
#include <kio/job.h>
#include <libkcal/journal.h>

#include <tqobject.h>
#include <tqstring.h>
#include <tqvaluelist.h>
#include <tqdatetime.h>

/**
This is the main interface for blog backends
@author ian reinhart geiser, Reinhold Kainhofer
*/

namespace KBlog {

class BlogPosting
{
public:
  BlogPosting() {}
  virtual ~BlogPosting() {}

  TQString userID() const { return mUserID; }
  void setUserID( const TQString &userID ) { mUserID = userID; }

  TQString blogID() const { return mBlogID; }
  void setBlogID( const TQString &blogID ) { mBlogID = blogID; }

  TQString postID() const { return mPostID; }
  void setPostID( const TQString &postID ) { assignPostID( postID ); mPostID = postID; }

  TQString title() const { return mTitle; }
  void setTitle( const TQString &title ) { mTitle = title; }

  TQString content() const { return mContent; }
  void setContent( const TQString &content ) { mContent = content; }

  TQString category() const { return mCategory; }
  void setCategory( const TQString &category ) { mCategory = category; }

  TQString fingerprint() const { return mFingerprint; }
  void setFingerprint( const TQString &fp ) { mFingerprint = fp; }

  TQDateTime dateTime() const { return mDateTime; }
  void setDateTime( const TQDateTime &datetime ) { mDateTime = datetime; }

  TQDateTime creationDateTime() const { return mCreationDateTime; }
  void setCreationDateTime( const TQDateTime &datetime ) { mCreationDateTime = datetime; }

  TQDateTime modificationDateTime() const { return mModificationDateTime; }
  void setModificationDateTime( const TQDateTime &datetime ) { mModificationDateTime = datetime; }

  virtual void wasDeleted( bool ) {}
  virtual void wasUploaded( bool ) {}
  virtual void error( int /*code*/, const TQString &/*error*/ ) {}

protected:
  // Override this method to detect the new postID assigned when adding a new post
  virtual void assignPostID( const TQString &/*postID*/ ) {}
  TQString mUserID;
  TQString mBlogID;
  TQString mPostID;
  TQString mTitle;
  TQString mContent;
  TQString mCategory;
  TQString mFingerprint;
  TQDateTime mDateTime;
  TQDateTime mCreationDateTime;
  TQDateTime mModificationDateTime;
};


class APIBlog : public TQObject
{
    Q_OBJECT
  
  public:
    APIBlog( const KURL &server, TQObject *parent = 0L, const char *name = 0L );
    virtual ~APIBlog();
    virtual TQString interfaceName() const = 0;

    void setAppID( const TQString &appID ) { mAppID = appID; }
    TQString appID() const { return mAppID; }

    void setPassword( const TQString &pass ) { mPassword = pass; }
    TQString password() const { return mPassword; }

    void setUsername( const TQString &uname ) { mUsername = uname; }
    TQString username() const { return mUsername; }

    void setURL( const KURL& url ) { mServerURL = url; }
    KURL url() const { return mServerURL; }

    void setDownloadCount( int nr ) { mDownloadCount = nr; }
    int downloadCount() const { return mDownloadCount; }

    static void dumpBlog( BlogPosting *blog );


    enum blogFunctions {
      bloggerGetUserInfo,
      bloggerGetUsersBlogs,
      bloggerGetRecentPosts,
      bloggerNewPost,
      bloggerEditPost,
      bloggerDeletePost,
      bloggerGetPost,
      bloggerGetTemplate,
      bloggerSetTemplate
    };

    virtual TQString getFunctionName( blogFunctions type ) = 0;
    virtual TQValueList<TQVariant> defaultArgs( const TQString &id = TQString() );

    virtual TDEIO::Job *createUserInfoJob() = 0;
    virtual TDEIO::Job *createListFoldersJob() = 0;
    virtual TDEIO::TransferJob *createListItemsJob( const KURL &url ) = 0;
    virtual TDEIO::TransferJob *createDownloadJob( const KURL &url ) = 0;
    virtual TDEIO::TransferJob *createUploadJob( const KURL &url, KBlog::BlogPosting *posting ) = 0;
    virtual TDEIO::TransferJob *createUploadNewJob( KBlog::BlogPosting *posting ) = 0;
    virtual TDEIO::Job *createRemoveJob( const KURL &url, const TQString &postid ) = 0;

    virtual bool interpretUserInfoJob( TDEIO::Job *job ) = 0;
    virtual void interpretListFoldersJob( TDEIO::Job *job ) = 0;
    virtual bool interpretListItemsJob( TDEIO::Job *job ) = 0;
    virtual bool interpretDownloadItemsJob( TDEIO::Job *job ) = 0;
    
    static KCal::Journal *journalFromPosting( KBlog::BlogPosting *post );
    static KBlog::BlogPosting *postingFromJournal( KCal::Journal *journal );

  signals:
    // TODO: Connect these
    void userInfoRetrieved( const TQString &nickname, const TQString &userid, const TQString &email );
    void folderInfoRetrieved( const TQString &id, const TQString &name );

    void itemOnServer( const KURL &remoteURL );
    void itemDownloaded( KCal::Incidence *j, const TQString &localID,
                         const KURL &remoteURL, const TQString &fingerprint,
                         const TQString &storageLocation );
    

  protected:

    KURL mServerURL;
    TQString mPassword;
    TQString mUsername;
    TQString mAppID;
    int mDownloadCount;
};

}
#endif