PageRenderTime 137ms CodeModel.GetById 52ms app.highlight 14ms RepoModel.GetById 49ms app.codeStats 0ms

/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
 19#ifndef TWITTER_H
 20#define TWITTER_H
 21
 22#include "twitterconfigwidget.h"
 23
 24#include <QTimer>
 25#include <QWeakPointer>
 26#include <QSet>
 27
 28#include <QTweetLib/qtweetuser.h>
 29#include <QTweetLib/qtweetnetbase.h>
 30#include <QTweetLib/qtweetfriendstimeline.h>
 31#include <QTweetLib/qtweetdirectmessages.h>
 32#include <QTweetLib/qtweetdirectmessagenew.h>
 33#include <QTweetLib/qtweetdirectmessagedestroy.h>
 34#include <QTweetLib/qtweetmentions.h>
 35#include <QTweetLib/qtweetdmstatus.h>
 36
 37#include "../sipdllmacro.h"
 38#include "sip/SipPlugin.h"
 39#include "tomahawkoauthtwitter.h"
 40
 41#define MYNAME "SIPTWITTER"
 42
 43class SIPDLLEXPORT TwitterFactory : public SipPluginFactory
 44{
 45    Q_OBJECT
 46    Q_INTERFACES( SipPluginFactory )
 47
 48public:
 49    TwitterFactory() {}
 50    virtual ~TwitterFactory() {}
 51
 52    virtual QString prettyName() const { return "Twitter"; }
 53    virtual QString factoryId() const { return "siptwitter"; }
 54    virtual QIcon icon() const;
 55    virtual SipPlugin* createPlugin( const QString& pluginId = QString() );
 56};
 57
 58class SIPDLLEXPORT TwitterPlugin : public SipPlugin
 59{
 60    Q_OBJECT
 61
 62public:
 63    TwitterPlugin( const QString& pluginId );
 64
 65    virtual ~TwitterPlugin() {}
 66
 67    virtual bool isValid() const;
 68    virtual const QString name() const;
 69    virtual const QString accountName() const;
 70    virtual const QString friendlyName() const;
 71    virtual ConnectionState connectionState() const;
 72    virtual QIcon icon() const;
 73    virtual QWidget* configWidget();
 74
 75public slots:
 76    virtual bool connectPlugin( bool startup );
 77    void disconnectPlugin();
 78    void checkSettings();
 79    void refreshProxy();
 80    void deletePlugin();
 81
 82    void sendMsg( const QString& to, const QString& msg )
 83    {
 84        Q_UNUSED( to );
 85        Q_UNUSED( msg );
 86    }
 87
 88    void broadcastMsg( const QString &msg )
 89    {
 90        Q_UNUSED( msg );
 91    }
 92
 93    void addContact( const QString &jid, const QString& msg = QString() )
 94    {
 95        Q_UNUSED( jid );
 96        Q_UNUSED( msg );
 97    }
 98
 99private slots:
100    void configDialogAuthedSignalSlot( bool authed );
101    void connectAuthVerifyReply( const QTweetUser &user );
102    void checkTimerFired();
103    void connectTimerFired();
104    void friendsTimelineStatuses( const QList< QTweetStatus > &statuses );
105    void mentionsStatuses( const QList< QTweetStatus > &statuses );
106    void pollDirectMessages();
107    void directMessages( const QList< QTweetDMStatus > &messages );
108    void directMessagePosted( const QTweetDMStatus &message );
109    void directMessagePostError( QTweetNetBase::ErrorCode errorCode, const QString &message );
110    void directMessageDestroyed( const QTweetDMStatus &message );
111    void registerOffers( const QStringList &peerList );
112    void registerOffer( const QString &screenName, const QVariantHash &peerdata );
113    void sendOffer( const QString &screenName, const QVariantHash &peerdata );
114    void makeConnection( const QString &screenName, const QVariantHash &peerdata );
115    void fetchAvatar( const QString &screenName );
116    void avatarUserDataSlot( const QTweetUser &user );
117    void profilePicReply();
118
119private:
120    inline void syncConfig() { setTwitterCachedPeers( m_cachedPeers ); }
121    bool refreshTwitterAuth();
122    void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text );
123    // handle per-plugin config
124    QString twitterSavedDbid() const;
125    void setTwitterSavedDbid( const QString& dbid );
126    QString twitterScreenName() const;
127    void setTwitterScreenName( const QString& screenName );
128    QString twitterOAuthToken() const;
129    void setTwitterOAuthToken( const QString& oauthtoken );
130    QString twitterOAuthTokenSecret() const;
131    void setTwitterOAuthTokenSecret( const QString& oauthtokensecret );
132    qint64 twitterCachedFriendsSinceId() const;
133    void setTwitterCachedFriendsSinceId( qint64 sinceid );
134    qint64 twitterCachedMentionsSinceId() const;
135    void setTwitterCachedMentionsSinceId( qint64 sinceid );
136    qint64 twitterCachedDirectMessagesSinceId() const;
137    void setTwitterCachedDirectMessagesSinceId( qint64 sinceid );
138    QVariantHash twitterCachedPeers() const;
139    void setTwitterCachedPeers( const QVariantHash &cachedPeers );
140
141    QWeakPointer< TomahawkOAuthTwitter > m_twitterAuth;
142    QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
143    QWeakPointer< QTweetMentions > m_mentions;
144    QWeakPointer< QTweetDirectMessages > m_directMessages;
145    QWeakPointer< QTweetDirectMessageNew > m_directMessageNew;
146    QWeakPointer< QTweetDirectMessageDestroy > m_directMessageDestroy;
147
148    bool m_isAuthed;
149    QTimer m_checkTimer;
150    QTimer m_connectTimer;
151    QTimer m_dmPollTimer;
152    qint64 m_cachedFriendsSinceId;
153    qint64 m_cachedMentionsSinceId;
154    qint64 m_cachedDirectMessagesSinceId;
155    QVariantHash m_cachedPeers;
156    QHash< QString, QPixmap > m_cachedAvatars;
157    QSet<QString> m_keyCache;
158    ConnectionState m_state;
159
160    QWeakPointer<TwitterConfigWidget > m_configWidget;
161
162    // for settings access
163    friend class TwitterConfigWidget;
164};
165
166#endif