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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • socialutils
  • serializer
akonadi_serializer_socialfeeditem.cpp
1 /*
2  Social feed serializer
3  Copyright (C) 2012 Martin Klapetek <martin.klapetek@gmail.com>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation; either version 2.1 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "akonadi_serializer_socialfeeditem.h"
22 #include "../socialfeeditem.h"
23 
24 #include "akonadi/config-akonadi.h"
25 #include "akonadi/item.h"
26 
27 #include <QtCore/qplugin.h>
28 
29 #include <qjson/qobjecthelper.h>
30 #include <qjson/parser.h>
31 #include <qjson/serializer.h>
32 
33 using namespace Akonadi;
34 
35 bool SocialFeedItemSerializerPlugin::deserialize( Item &item,
36  const QByteArray &label,
37  QIODevice &data,
38  int version )
39 {
40  Q_UNUSED( version );
41 
42  if ( label != Item::FullPayload ) {
43  return false;
44  }
45 
46  SocialFeedItem feedItem;
47 
48  QJson::Parser parser;
49  QVariantMap map = parser.parse( data.readAll() ).toMap();
50 
51  feedItem.setNetworkString( map.value( QLatin1String( "networkString" ) ).toString() );
52  feedItem.setPostId( map.value( QLatin1String( "postId" ) ).toString() );
53  feedItem.setPostText( map.value( QLatin1String( "postText" ) ).toString() );
54  feedItem.setPostLinkTitle( map.value( QLatin1String( "postLinkTitle" ) ).toString() );
55  feedItem.setPostLink( map.value( QLatin1String( "postLink" ) ).toUrl() );
56  feedItem.setPostImageUrl( map.value( QLatin1String( "postImageUrl" ) ).toUrl() );
57  feedItem.setPostInfo( map.value( QLatin1String( "postInfo" ) ).toString() );
58  feedItem.setUserName( map.value( QLatin1String( "userName" ) ).toString() );
59  feedItem.setUserDisplayName( map.value( QLatin1String( "userDisplayName" ) ).toString() );
60  feedItem.setUserId( map.value( QLatin1String( "userId" ) ).toString() );
61  feedItem.setAvatarUrl( map.value( QLatin1String( "avatarUrl" ) ).toUrl() );
62  feedItem.setPostTime( map.value( QLatin1String( "postTimeString" ) ).toString(),
63  map.value( QLatin1String( "postTimeFormat" ) ).toString() );
64  feedItem.setShared( map.value( QLatin1String( "shared" ) ).toBool() );
65  feedItem.setSharedFrom( map.value( QLatin1String( "sharedFrom" ) ).toString() );
66  feedItem.setSharedFromId( map.value( QLatin1String( "sharedFromId" ) ).toString() );
67  feedItem.setLiked( map.value( QLatin1String( "liked" ) ).toBool() );
68  feedItem.setItemSourceMap( map.value( QLatin1String( "itemSourceMap" ) ).toMap() );
69 
70  if ( map.keys().contains( QLatin1String( "postReplies" ) ) ) {
71  QList<SocialFeedItem> replies;
72  Q_FOREACH ( const QVariant &replyData, map.value( QLatin1String( "postReplies" ) ).toList() ) {
73  QVariantMap reply = replyData.toMap();
74  SocialFeedItem postReply;
75  postReply.setUserId( reply.value( QLatin1String( "userId" ) ).toString() );
76  postReply.setUserName( reply.value( QLatin1String( "userName" ) ).toString() );
77  postReply.setAvatarUrl( reply.value( QLatin1String( "userAvatarUrl" ) ).toString() );
78  postReply.setPostText( reply.value( QLatin1String( "replyText" ) ).toString() );
79 // postReply.setPostTime( reply.value( QLatin1String( "replyTime" ) ).toString();
80  postReply.setPostId( reply.value( QLatin1String( "replyId" ) ).toString() );
81 // postReply.postId = reply.value( QLatin1String( "postId" ) ).toString();
82 
83  replies.append( postReply );
84  }
85 
86  feedItem.setPostReplies( replies );
87  }
88 
89  item.setMimeType( QLatin1String( "text/x-vnd.akonadi.socialfeeditem" ) );
90  item.setPayload<SocialFeedItem>( feedItem );
91 
92  return true;
93 }
94 
95 void SocialFeedItemSerializerPlugin::serialize( const Item &item,
96  const QByteArray &label,
97  QIODevice &data,
98  int &version )
99 {
100  Q_UNUSED( label );
101  Q_UNUSED( version );
102 
103  if ( !item.hasPayload<SocialFeedItem>() ) {
104  return;
105  }
106 
107  SocialFeedItem feedItem = item.payload<SocialFeedItem>();
108 
109  QVariantMap map;
110 
111  map.insert( QLatin1String( "networkString" ), feedItem.networkString() );
112  map.insert( QLatin1String( "postId" ), feedItem.postId() );
113  map.insert( QLatin1String( "postText" ), feedItem.postText() );
114  map.insert( QLatin1String( "postLinkTitle" ), feedItem.postLinkTitle() );
115  map.insert( QLatin1String( "postLink" ), feedItem.postLink() );
116  map.insert( QLatin1String( "postImageUrl" ), feedItem.postImageUrl() );
117  map.insert( QLatin1String( "postInfo" ), feedItem.postInfo() );
118  map.insert( QLatin1String( "userName" ), feedItem.userName() );
119  map.insert( QLatin1String( "userDisplayName" ), feedItem.userDisplayName() );
120  map.insert( QLatin1String( "userId" ), feedItem.userId() );
121  map.insert( QLatin1String( "avatarUrl" ), feedItem.avatarUrl() );
122  map.insert( QLatin1String( "postTimeString" ), feedItem.postTimeString() );
123  map.insert( QLatin1String( "postTimeFormat" ), feedItem.postTimeFormat() );
124  map.insert( QLatin1String( "shared" ), feedItem.isShared() );
125  map.insert( QLatin1String( "sharedFrom" ), feedItem.sharedFrom() );
126  map.insert( QLatin1String( "sharedFromId" ), feedItem.sharedFromId() );
127  map.insert( QLatin1String( "liked" ), feedItem.isLiked() );
128  map.insert( QLatin1String( "itemSourceMap" ), feedItem.itemSourceMap() );
129 
130  if (!feedItem.postReplies().isEmpty() ) {
131  QVariantList replies;
132  Q_FOREACH ( const SocialFeedItem &reply, feedItem.postReplies() ) {
133  QVariantMap replyData;
134  replyData.insert( QLatin1String( "userId" ), reply.userId() );
135  replyData.insert( QLatin1String( "userName" ), reply.userName() );
136  replyData.insert( QLatin1String( "userAvatarUrl" ), reply.avatarUrl() );
137  replyData.insert( QLatin1String( "replyText" ), reply.postText() );
138 // replyData.insert( QLatin1String( "replyTime" ), reply.postTimeString() );
139  replyData.insert( QLatin1String( "replyId" ), reply.postId() );
140 // replyData.insert( QLatin1String( "postId" ), reply.postId );
141  replies.append( replyData );
142  }
143 
144  map.insert( QLatin1String( "postReplies" ), replies );
145  }
146 
147  QJson::Serializer serializer;
148 #if !defined( USE_QJSON_0_8 )
149  data.write( serializer.serialize( map ) );
150 #else
151  data.write( serializer.serialize( map, 0 ) );
152 #endif
153 }
154 
155 QSet<QByteArray> SocialFeedItemSerializerPlugin::parts( const Item &item ) const
156 {
157  // only need to reimplement this when implementing partial serialization
158  // i.e. when using the "label" parameter of the other two methods
159  return ItemSerializerPlugin::parts( item );
160 }
161 
162 Q_EXPORT_PLUGIN2( akonadi_serializer_socialfeeditem, Akonadi::SocialFeedItemSerializerPlugin )
163 
Akonadi::SocialFeedItem::userName
QString userName() const
Definition: socialfeeditem.cpp:153
Akonadi::SocialFeedItem::setPostReplies
void setPostReplies(const QList< SocialFeedItem > &replies)
Sets replies/comments for this post.
Definition: socialfeeditem.cpp:238
Akonadi::SocialFeedItem::sharedFrom
QString sharedFrom() const
Definition: socialfeeditem.cpp:183
Akonadi::SocialFeedItem::postLink
QUrl postLink() const
Definition: socialfeeditem.cpp:80
Akonadi::SocialFeedItem::setUserDisplayName
void setUserDisplayName(const QString &userDisplayName)
Sets the name to be displayed to the user (full name usually)
Definition: socialfeeditem.cpp:168
Akonadi::SocialFeedItem::postId
QString postId() const
Definition: socialfeeditem.cpp:60
Akonadi::SocialFeedItem::setSharedFrom
void setSharedFrom(const QString &sharedFrom)
Sets the display name of the user which was the original author of this post.
Definition: socialfeeditem.cpp:188
Akonadi::SocialFeedItem::userId
QString userId() const
Definition: socialfeeditem.cpp:143
Akonadi::SocialFeedItem::itemSourceMap
QVariantMap itemSourceMap() const
Definition: socialfeeditem.cpp:203
Akonadi::SocialFeedItem::setPostLinkTitle
void setPostLinkTitle(const QString &linkTitle)
Sets the link title the posts links to.
Definition: socialfeeditem.cpp:95
Akonadi::SocialFeedItem::setLiked
void setLiked(bool liked)
Sets if the user has liked/favorited the post or not.
Definition: socialfeeditem.cpp:228
Akonadi::SocialFeedItem::postReplies
QList< SocialFeedItem > postReplies() const
Definition: socialfeeditem.cpp:233
Akonadi::SocialFeedItem::setPostImageUrl
void setPostImageUrl(const QUrl &imageUrl)
Sets the URL of an image associated with this post, it can be an image thumb, link thumb etc...
Definition: socialfeeditem.cpp:105
Akonadi::SocialFeedItem::userDisplayName
QString userDisplayName() const
Definition: socialfeeditem.cpp:163
Akonadi::SocialFeedItem::setNetworkString
void setNetworkString(const QString &networkString)
Sets the network string for this item.
Definition: socialfeeditem.cpp:55
Akonadi::SocialFeedItem::postImageUrl
QUrl postImageUrl() const
Definition: socialfeeditem.cpp:100
Akonadi::SocialFeedItem::setSharedFromId
void setSharedFromId(const QString &sharedFromId)
Sets the user id of the user this was shared from.
Definition: socialfeeditem.cpp:198
Akonadi::ItemSerializerPlugin::parts
virtual QSet< QByteArray > parts(const Item &item) const
Returns a list of available parts for the given item payload.
Definition: itemserializerplugin.cpp:33
Akonadi::SocialFeedItem::setPostLink
void setPostLink(const QUrl &link)
Sets the link the posts links to.
Definition: socialfeeditem.cpp:85
Akonadi::SocialFeedItem::setItemSourceMap
void setItemSourceMap(const QVariantMap &itemSourceMap)
Sets the original data which was received from the network and then mapped to a QVariantMap.
Definition: socialfeeditem.cpp:208
Akonadi::SocialFeedItem::postInfo
QString postInfo() const
Definition: socialfeeditem.cpp:120
Akonadi::SocialFeedItem::isLiked
bool isLiked() const
Definition: socialfeeditem.cpp:223
Akonadi::SocialFeedItem::setPostTime
void setPostTime(const QString &postTimeString, const QString &postTimeFormat)
Sets the time string which was received from the network together with the format which could be rece...
Definition: socialfeeditem.cpp:130
Akonadi::SocialFeedItem::postLinkTitle
QString postLinkTitle() const
Definition: socialfeeditem.cpp:90
Akonadi::SocialFeedItem
Class representing one entry in the social feed.
Definition: socialfeeditem.h:38
Akonadi::SocialFeedItem::setPostId
void setPostId(const QString &postId)
Sets the original post id.
Definition: socialfeeditem.cpp:65
Akonadi::SocialFeedItem::setUserId
void setUserId(const QString &userId)
Sets the network user id associated with this post.
Definition: socialfeeditem.cpp:148
Akonadi::SocialFeedItem::avatarUrl
QUrl avatarUrl() const
Definition: socialfeeditem.cpp:213
Akonadi::SocialFeedItem::postText
QString postText() const
Definition: socialfeeditem.cpp:70
Akonadi::SocialFeedItem::postTimeFormat
QString postTimeFormat() const
Definition: socialfeeditem.cpp:138
Akonadi::SocialFeedItem::postTimeString
QString postTimeString() const
Definition: socialfeeditem.cpp:115
Akonadi::SocialFeedItem::setPostText
void setPostText(const QString &text)
Sets the post text to be displayed in the feed.
Definition: socialfeeditem.cpp:75
Akonadi::SocialFeedItem::networkString
QString networkString() const
This returns the service string such as "on Facebook", "on Twitter" It's used in the feed as the firs...
Definition: socialfeeditem.cpp:50
Akonadi::SocialFeedItem::setShared
void setShared(bool shared)
Sets if this post was shared from other user.
Definition: socialfeeditem.cpp:178
Akonadi::SocialFeedItem::setPostInfo
void setPostInfo(const QString &postInfo)
Sets additional info for the post, like number of comments, likes, retweed from etc.
Definition: socialfeeditem.cpp:125
Akonadi::SocialFeedItem::isShared
bool isShared() const
Definition: socialfeeditem.cpp:173
Akonadi::SocialFeedItem::sharedFromId
QString sharedFromId() const
Definition: socialfeeditem.cpp:193
Akonadi::SocialFeedItem::setUserName
void setUserName(const QString &userName)
Sets the network user name associated with this post.
Definition: socialfeeditem.cpp:158
Akonadi::SocialFeedItem::setAvatarUrl
void setAvatarUrl(const QUrl &url)
Sets the url of the avatar picture to be displayed next to the post in the feed.
Definition: socialfeeditem.cpp:218
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • 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