예제 #1
0
void UserStream::statusStream(const QTweetStatus &tweet)
{
    ui->infoTextBrowser->append("New tweet");
    ui->infoTextBrowser->append("id: " + QString::number(tweet.id()));
    ui->infoTextBrowser->append("text: " + tweet.text());
    ui->infoTextBrowser->append("name: " + tweet.user().name());
}
예제 #2
0
/**
 *  Load last 100 tweets mentions from database
 *  @reimp
 */
void MentionsQmlListModel::loadTweetsFromDatabase()
{
    QSqlQuery query;
    query.prepare("SELECT id, text, screenName, profileImageUrl, userId, created "
                  "FROM status "
                  "WHERE mention = 1 "
                  "ORDER BY id DESC "
                  "LIMIT 100 ");
    query.exec();

    //remove/clear all statuses
    beginResetModel();

    m_statuses.clear();
    m_numUnreadTweets = 0;

    endResetModel();

    QList<QTweetStatus> newStatuses;

    while (query.next()) {
        QTweetStatus st;
        st.setId(query.value(0).toLongLong());
        st.setText(query.value(1).toString());

        //Datetime is stored in UTC
        QDateTime tempTime = query.value(5).toDateTime();
        QDateTime utcTime(tempTime.date(), tempTime.time(), Qt::UTC);
        st.setCreatedAt(utcTime);

        QTweetUser userinfo;
        userinfo.setScreenName(query.value(2).toString());
        userinfo.setprofileImageUrl(query.value(3).toString());
        userinfo.setId(query.value(4).toInt());

        st.setUser(userinfo);

        newStatuses.append(st);
    }

    if (newStatuses.count()) {

        beginInsertRows(QModelIndex(), 0, newStatuses.count() - 1);

        m_statuses.append(newStatuses);

        endInsertRows();
    }
}
예제 #3
0
void
TwitterConfigWidget::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
{
    if ( status.id() == 0 )
        QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
    else
        QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") );
}
예제 #4
0
void
TwitterInfoPlugin::postLovedStatusUpdateReply( const QTweetStatus& status )
{
    if ( status.id() == 0 )
        tDebug() << Q_FUNC_INFO << "Failed to post loved status";
    else
        tDebug() << Q_FUNC_INFO << "Successfully posted loved status";
}
예제 #5
0
void MainWindow::statusUpdateFinished(const QTweetStatus &status)
{
    QTweetStatusUpdate *statusUpdate = qobject_cast<QTweetStatusUpdate*>(sender());
    if (statusUpdate) {
        qDebug() << "Sended status with id: " << status.id();

        statusUpdate->deleteLater();
    }
}
예제 #6
0
/**
 * This slot is connected to user stream object.
 * Called when new tweet arrives in the user stream
 */
void MentionsQmlListModel::onStatusesStream(const QTweetStatus &status)
{
    QList<QTweetEntityUserMentions> entityUserMentions = status.userMentionsEntities();

    for (int i = 0; i < entityUserMentions.count(); ++i) {
        if (entityUserMentions.at(i).userid() == userID()) {    //check if is mention
            QSqlQuery query;
            QString text;

            query.prepare("INSERT OR REPLACE INTO status "
                          "(id, text, screenName, profileImageUrl, userId, mention, created, replyToStatusId) "
                          "VALUES "
                          "(:id, :text, :screenName, :profileImageUrl, :userId, :mention, :created, :replyToStatusId);");
            query.bindValue(":id", status.id());
            query.bindValue(":userId", status.user().id());
            query.bindValue(":screenName", status.user().screenName());
            query.bindValue(":profileImageUrl", status.user().profileImageUrl());
            query.bindValue(":mention", 1);
            query.bindValue(":created", status.createdAt());
            query.bindValue(":replyToStatusId", status.inReplyToStatusId());

            if (status.isRetweet()) {
                QString retweetedText = status.retweetedStatus().text();
                text = "RT @" + status.retweetedStatus().user().screenName() + ": " + retweetedText;
            } else {
                text = status.text();
            }

             query.bindValue(":text", text);

            query.exec();

            m_newStatuses.prepend(status);

            m_numNewTweets = m_newStatuses.count();
            emit numNewTweetsChanged();
            break;
        }
    }
}
예제 #7
0
/**
 *  This slot is called when fetching mentions is finished (see fetchLastTweets())
 */
void MentionsQmlListModel::finishedFetchTweets(const QList<QTweetStatus> &statuses)
{
    QTweetMentions *mentions = qobject_cast<QTweetMentions*>(sender());

    if (mentions) {
        if (!statuses.isEmpty()) {
            qDebug() << "Fetch mentions: " << statuses.count();

            QSqlQuery query;

            query.exec("BEGIN;");
            query.prepare("INSERT OR REPLACE INTO status "
                          "(id, text, screenName, profileImageUrl, userId, mention, created, replyToStatusId) "
                          "VALUES "
                          "(:id, :text, :screenName, :profileImageUrl, :userId, :mention, :created, :replyToStatusId);");

            QListIterator<QTweetStatus> i(statuses);
            i.toBack();
            while (i.hasPrevious()) {
                QString text;
                QTweetStatus s = i.previous();
                query.bindValue(":id", s.id());
                query.bindValue(":replyToStatusId", s.inReplyToStatusId());
                query.bindValue(":userId", s.user().id());
                query.bindValue(":screenName", s.user().screenName());
                query.bindValue(":profileImageUrl", s.user().profileImageUrl());
                query.bindValue(":mention", 1);
                query.bindValue(":created", s.createdAt());

                if (s.isRetweet()) {
                    QString retweetedText = s.retweetedStatus().text();
                    text = "RT @" + s.retweetedStatus().user().screenName() + ": " + retweetedText;
                } else {
                    text = s.text();
                }

                query.bindValue(":text", text);

                query.exec();

                m_newStatuses.prepend(s);
            }
            query.exec("COMMIT;");

            m_numNewTweets = m_newStatuses.count();
            emit numNewTweetsChanged();
        }
        mentions->deleteLater();
    }
}
예제 #8
0
QTweetStatus QTweetConvert::jsonObjectToStatus(const QJsonObject& json)
{
    QTweetStatus status;

    status.setCreatedAt(json["created_at"].toString());
    status.setText(json["text"].toString());
    status.setId(static_cast<qint64>(json["id"].toDouble()));
    status.setInReplyToUserId(static_cast<qint64>(json["in_reply_to_user_id"].toDouble()));
    status.setInReplyToScreenName(json["in_reply_to_screen_name"].toString());
    status.setFavorited(json["favorited"].toBool());

    QJsonObject userObject = json["user"].toObject();
    QTweetUser user = jsonObjectToUser(userObject);
    status.setUser(user);

    status.setSource(json["source"].toString());
    status.setInReplyToStatusId(static_cast<qint64>(json["in_reply_to_status_id"].toDouble()));

    //check if contains native retweet
    if (json.contains("retweeted_status")) {
        QJsonObject retweetObject = json["retweeted_status"].toObject();

        QTweetStatus rtStatus = jsonObjectToStatus(retweetObject);

        status.setRetweetedStatus(rtStatus);
    }

    //parse place id if it's not null
    QJsonValue placeValue = json["place"];
    if (!placeValue.isNull()) {
        QTweetPlace place = jsonObjectToPlace(placeValue.toObject());
        status.setPlace(place);
    }

    //check if contains entities
    if (json.contains("entities")) {
        QJsonObject entitiesObject = json["entities"].toObject();

        //url entities
        QJsonArray urlEntitiesList = entitiesObject["urls"].toArray();

        for (int i = 0; i < urlEntitiesList.size(); ++i) {
            QTweetEntityUrl urlEntity = jsonObjectToEntityUrl(urlEntitiesList[i].toObject());

            status.addUrlEntity(urlEntity);
        }

        //hashtag entities
        QJsonArray hashtagEntitiesList = entitiesObject["hashtags"].toArray();

        for (int i = 0; i < hashtagEntitiesList.size(); ++i) {
            QTweetEntityHashtag hashtagEntity = jsonObjectToEntityHashtag(hashtagEntitiesList[i].toObject());

            status.addHashtagEntity(hashtagEntity);
        }

        //user mentions
        QJsonArray userMentionsEntitiesList = entitiesObject["user_mentions"].toArray();

        for (int i = 0; i < userMentionsEntitiesList.count(); ++i) {
            QTweetEntityUserMentions userMentionsEntity = jsonObjectToEntityUserMentions(userMentionsEntitiesList[i].toObject());

            status.addUserMentionsEntity(userMentionsEntity);
        }

        //media
        QJsonArray mediaEntitiesList = entitiesObject["media"].toArray();

        for (int i = 0; i < mediaEntitiesList.count(); ++i) {
            QTweetEntityMedia mediaEntity = jsonObjectToEntityMedia(mediaEntitiesList[i].toObject());

            status.addMediaEntity(mediaEntity);
        }
    }

    return status;
}