/**
 *  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();
    }
}
Beispiel #2
0
QTweetUser QTweetConvert::jsonObjectToUser(const QJsonObject &jsonObject)
{
    QTweetUser userInfo;

    userInfo.setId(static_cast<qint64>(jsonObject.value("id_str").toString().toLong()));

    if (jsonObject.contains("name")) {
        userInfo.setName(jsonObject.value("name").toString());
        userInfo.setLocation(jsonObject.value("location").toString());
        userInfo.setprofileImageUrl(jsonObject.value("profile_image_url").toString());
        userInfo.setCreatedAt(jsonObject.value("created_at").toString());
        userInfo.setFavouritesCount(static_cast<int>(jsonObject.value("favourites_count").toDouble()));
        userInfo.setUrl(jsonObject.value("url").toString());
        userInfo.setUtcOffset(static_cast<int>(jsonObject.value("utc_offset").toDouble()));
        userInfo.setProtected(jsonObject.value("protected").toBool());
        userInfo.setFollowersCount(static_cast<int>(jsonObject.value("followers_count").toDouble()));
        userInfo.setVerified(jsonObject.value("verified").toBool());
        userInfo.setGeoEnabled(jsonObject.value("geo_enabled").toBool());
        userInfo.setDescription(jsonObject.value("description").toString());
        userInfo.setTimezone(jsonObject.value("time_zone").toString());
        userInfo.setStatusesCount(static_cast<int>(jsonObject.value("statuses_count").toDouble()));
        userInfo.setScreenName(jsonObject.value("screen_name").toString());
        userInfo.setContributorsEnabled(jsonObject.value("contributors_enabled").toBool());
        userInfo.setListedCount(static_cast<int>(jsonObject.value("listed_count").toDouble()));
        userInfo.setLang(jsonObject.value("lang").toString());
	userInfo.setFollowing(jsonObject.value("following").toBool());

        if (jsonObject.contains("status")) {
            QJsonObject jsonStatusObject = jsonObject.value("status").toObject();

            QTweetStatus status = jsonObjectToStatus(jsonStatusObject);
            userInfo.setStatus(status);
        }
    }

    return userInfo;
}