/src/sip/twitter/twitter.h

http://github.com/tomahawk-player/tomahawk · C Header · 166 lines · 123 code · 24 blank · 19 comment · 0 complexity · c50e41176f0bdcddc084b0ad141ab438 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef TWITTER_H
  19. #define TWITTER_H
  20. #include "twitterconfigwidget.h"
  21. #include <QTimer>
  22. #include <QWeakPointer>
  23. #include <QSet>
  24. #include <QTweetLib/qtweetuser.h>
  25. #include <QTweetLib/qtweetnetbase.h>
  26. #include <QTweetLib/qtweetfriendstimeline.h>
  27. #include <QTweetLib/qtweetdirectmessages.h>
  28. #include <QTweetLib/qtweetdirectmessagenew.h>
  29. #include <QTweetLib/qtweetdirectmessagedestroy.h>
  30. #include <QTweetLib/qtweetmentions.h>
  31. #include <QTweetLib/qtweetdmstatus.h>
  32. #include "../sipdllmacro.h"
  33. #include "sip/SipPlugin.h"
  34. #include "tomahawkoauthtwitter.h"
  35. #define MYNAME "SIPTWITTER"
  36. class SIPDLLEXPORT TwitterFactory : public SipPluginFactory
  37. {
  38. Q_OBJECT
  39. Q_INTERFACES( SipPluginFactory )
  40. public:
  41. TwitterFactory() {}
  42. virtual ~TwitterFactory() {}
  43. virtual QString prettyName() const { return "Twitter"; }
  44. virtual QString factoryId() const { return "siptwitter"; }
  45. virtual QIcon icon() const;
  46. virtual SipPlugin* createPlugin( const QString& pluginId = QString() );
  47. };
  48. class SIPDLLEXPORT TwitterPlugin : public SipPlugin
  49. {
  50. Q_OBJECT
  51. public:
  52. TwitterPlugin( const QString& pluginId );
  53. virtual ~TwitterPlugin() {}
  54. virtual bool isValid() const;
  55. virtual const QString name() const;
  56. virtual const QString accountName() const;
  57. virtual const QString friendlyName() const;
  58. virtual ConnectionState connectionState() const;
  59. virtual QIcon icon() const;
  60. virtual QWidget* configWidget();
  61. public slots:
  62. virtual bool connectPlugin( bool startup );
  63. void disconnectPlugin();
  64. void checkSettings();
  65. void refreshProxy();
  66. void deletePlugin();
  67. void sendMsg( const QString& to, const QString& msg )
  68. {
  69. Q_UNUSED( to );
  70. Q_UNUSED( msg );
  71. }
  72. void broadcastMsg( const QString &msg )
  73. {
  74. Q_UNUSED( msg );
  75. }
  76. void addContact( const QString &jid, const QString& msg = QString() )
  77. {
  78. Q_UNUSED( jid );
  79. Q_UNUSED( msg );
  80. }
  81. private slots:
  82. void configDialogAuthedSignalSlot( bool authed );
  83. void connectAuthVerifyReply( const QTweetUser &user );
  84. void checkTimerFired();
  85. void connectTimerFired();
  86. void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
  87. void mentionsStatuses( const QList< QTweetStatus > &statuses );
  88. void pollDirectMessages();
  89. void directMessages( const QList< QTweetDMStatus > &messages );
  90. void directMessagePosted( const QTweetDMStatus &message );
  91. void directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message );
  92. void directMessageDestroyed( const QTweetDMStatus &message );
  93. void registerOffers( const QStringList &peerList );
  94. void registerOffer( const QString &screenName, const QVariantHash &peerdata );
  95. void sendOffer( const QString &screenName, const QVariantHash &peerdata );
  96. void makeConnection( const QString &screenName, const QVariantHash &peerdata );
  97. void fetchAvatar( const QString &screenName );
  98. void avatarUserDataSlot( const QTweetUser &user );
  99. void profilePicReply();
  100. private:
  101. inline void syncConfig() { setTwitterCachedPeers( m_cachedPeers ); }
  102. bool refreshTwitterAuth();
  103. void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text );
  104. // handle per-plugin config
  105. QString twitterSavedDbid() const;
  106. void setTwitterSavedDbid( const QString& dbid );
  107. QString twitterScreenName() const;
  108. void setTwitterScreenName( const QString& screenName );
  109. QString twitterOAuthToken() const;
  110. void setTwitterOAuthToken( const QString& oauthtoken );
  111. QString twitterOAuthTokenSecret() const;
  112. void setTwitterOAuthTokenSecret( const QString& oauthtokensecret );
  113. qint64 twitterCachedFriendsSinceId() const;
  114. void setTwitterCachedFriendsSinceId( qint64 sinceid );
  115. qint64 twitterCachedMentionsSinceId() const;
  116. void setTwitterCachedMentionsSinceId( qint64 sinceid );
  117. qint64 twitterCachedDirectMessagesSinceId() const;
  118. void setTwitterCachedDirectMessagesSinceId( qint64 sinceid );
  119. QVariantHash twitterCachedPeers() const;
  120. void setTwitterCachedPeers( const QVariantHash &cachedPeers );
  121. QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
  122. QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
  123. QWeakPointer< QTweetMentions > m_mentions;
  124. QWeakPointer< QTweetDirectMessages > m_directMessages;
  125. QWeakPointer< QTweetDirectMessageNew > m_directMessageNew;
  126. QWeakPointer< QTweetDirectMessageDestroy > m_directMessageDestroy;
  127. bool m_isAuthed;
  128. QTimer m_checkTimer;
  129. QTimer m_connectTimer;
  130. QTimer m_dmPollTimer;
  131. qint64 m_cachedFriendsSinceId;
  132. qint64 m_cachedMentionsSinceId;
  133. qint64 m_cachedDirectMessagesSinceId;
  134. QVariantHash m_cachedPeers;
  135. QHash< QString, QPixmap > m_cachedAvatars;
  136. QSet<QString> m_keyCache;
  137. ConnectionState m_state;
  138. QWeakPointer<TwitterConfigWidget > m_configWidget;
  139. // for settings access
  140. friend class TwitterConfigWidget;
  141. };
  142. #endif