Moving libkfacebook to extragear

Kevin Krammer krammer at kde.org
Mon Oct 29 14:14:46 GMT 2012


On Sunday, 2012-10-28, Kevin Krammer wrote:
> On Sunday, 2012-10-28, Martin Klapetek wrote:
> > On Sat, Oct 27, 2012 at 6:05 PM, Kevin Krammer <krammer at kde.org> wrote:

> > > - the *Info classes seem to be normal data classes, IMHO they don't
> > > need to be
> > > QObjects but rather "value types"
> > 
> > This is for the parsing purposes - the library uses QJson parser/mapper,
> > which automagically maps the received json data to qobjects, otherwise
> > there would have to be manual parsing everywhere (and the facebook jsons
> > are huge), which means more code, more error possibilities, more
> > maintaining requirement and worse readability (compared to two lines
> > QJson mapper). So I'd like to leave this one as is.
> 
> I haven't had a look at the QJson library internals (yet), but from its
> usage it looks like that it is only using instances of those QObject
> classes to provide a convenient mapper of map keys to conversion functions
> (the property setters).

I've checked QJson and its QObjectHelper indeed only uses the passed object as 
a setter/getter interface.

Those "info" classes can therefore easily be made non-public/non-exported and 
a single instance of each class to operate on respective instance of a proper 
value-type data class.

E.g.
// appinfo.h
class LIBKFACEBOOK_EXPORT AppInfo
{
public:
  // if applications do not need to set this, AppInfoParser could also be
  // a friend, etc
  void setId( const QString &id );
  QString id() const;

  // ...

private:
  class Private;
  QSharedDataPointer<Private> d;
};

// appinfoparser_p.h
class AppInfoParser : public QObject
{
  Q_OBJECT
  Q_PROPERTY( QString, id READ id WRITE setId )

public:
  void setData( const AppInfo &appInfo ) { m_appInfo = appInfo; }
  AppInfo data() const { return m_appInfo; }

  void setId( const QString &id ) { m_appInfo.setId( id ); }
  QString id() const { return m_appInfo.id() }

private:
  AppInfo m_appInfo;
};

Usage e.g. in PostInfo::setApplication(

void PostInfo::setApplication( const QVariantMap &application )
{
  AppInfoParser parser; // could be also be a member, etc
  QJSon::QObjectHelper::qvariant2qobject( application, &parser );

  m_application = parser.data();
}

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20121029/dc41c614/attachment.sig>


More information about the kde-core-devel mailing list