예제 #1
0
void MainWindow::createDeclarativeView()
{
    m_tweetListModel = new TweetQmlListModel(m_oauthTwitter);
    //connect user stream to tweet home timeline
    connect(m_userStream, SIGNAL(statusesStream(QTweetStatus)),
            m_tweetListModel, SLOT(onStatusesStream(QTweetStatus)));
    connect(m_userStream, SIGNAL(deleteStatusStream(qint64,qint64)),
            m_tweetListModel, SLOT(onDeleteStatusStream(qint64,qint64)));
    // ### TODO: Test for syncing problems
    connect(m_userStream, SIGNAL(reconnected()),
            m_tweetListModel, SLOT(fetchLastTweets()));
    //try using REST API when streams fails
    connect(m_userStream, SIGNAL(failureConnect()),
            m_tweetListModel, SLOT(fetchLastTweets()));

    m_mentionsListModel = new MentionsQmlListModel(m_oauthTwitter);
    connect(m_userStream, SIGNAL(statusesStream(QTweetStatus)),
            m_mentionsListModel, SLOT(onStatusesStream(QTweetStatus)));
    connect(m_userStream, SIGNAL(deleteStatusStream(qint64,qint64)),
            m_mentionsListModel, SLOT(onDeleteStatusStream(qint64,qint64)));
    connect(m_userStream, SIGNAL(reconnected()),
            m_mentionsListModel, SLOT(fetchLastTweets()));

    m_directMessagesListModel = new DirectMessagesQmlListModel(m_oauthTwitter);
    connect(m_userStream, SIGNAL(directMessageStream(QTweetDMStatus)),
            m_directMessagesListModel, SLOT(onDirectMessageStream(QTweetDMStatus)));

    m_searchListModel = new SearchQmlListModel(m_oauthTwitter);

    m_userInfo = new UserInfo;
    m_userInfo->setOAuthTwitter(m_oauthTwitter);
    connect(m_userStream, SIGNAL(friendsList(QList<qint64>)),
            m_userInfo, SLOT(onUserStreamFriendsList(QList<qint64>)));

    m_userTimelineListModel = new UserTimelineListModel(m_oauthTwitter);

    m_conversationListModel = new ConversationListModel(m_oauthTwitter);

    rootContext()->setContextProperty("hometimelineListModel", m_tweetListModel);
    rootContext()->setContextProperty("mentionsListModel", m_mentionsListModel);
    rootContext()->setContextProperty("directMessagesListModel", m_directMessagesListModel);
    rootContext()->setContextProperty("searchListModel", m_searchListModel);
    rootContext()->setContextProperty("userInfo", m_userInfo);
    rootContext()->setContextProperty("userTimelineListModel", m_userTimelineListModel);
    rootContext()->setContextProperty("conversationListModel", m_conversationListModel);
    rootContext()->setContextProperty("rootWindow", this);

    //setSource(QUrl::fromLocalFile("qml/QTwitdget/Main.qml"));
    setMainQmlFile(QLatin1String("qml/QTwitdget/Main.qml"));
}
예제 #2
0
/**
 *  Called when connection is finished. Reconnects.
 */
void QTweetUserStream::replyFinished()
{
    qDebug() << "User stream closed ";

    m_streamTryingReconnect = true;

    if (!m_reply->error()) { //no error, reconnect
        qDebug() << "No error, reconnect";

        m_reply->deleteLater();
        m_reply = 0;

        startFetching();
    } else {    //error
        qDebug() << "Error: " << m_reply->error() << ", " << m_reply->errorString();

        m_reply->deleteLater();
        m_reply = 0;

        //if (m_backofftimer->interval() < 20001) {
        //  m_backofftimer->start();
        //  return;
        //}

        //increase back off interval
        int nextInterval = 2 * m_backofftimer->interval();

        if (nextInterval > 300000) {
            m_backofftimer->setInterval(300000);
            emit failureConnect();
        }

        m_backofftimer->setInterval(nextInterval);
        m_backofftimer->start();

        qDebug() << "Exp backoff interval: " << nextInterval;
    }
}