Beispiel #1
0
/** Setup the list content
  *
  * \sa serverList
  *
  */
void RainbruRPG::Core::gsServerList::setupServerList(){

  // Should now use OgerGui

  feedList();

}
void OcFeedsModelNew::feedsRequested(const QList<int> &updated, const QList<int> &newFeeds, const QList<int> &deleted)
{
    if (updated.isEmpty() && newFeeds.isEmpty() && deleted.isEmpty())
        return;

    QSqlQuery query;

    if (!updated.isEmpty()) {

        QLOG_INFO() << "Feeds model: updating changed feeds";

        for (int i = 0; i < updated.size(); ++i)
        {
            int idx = findIndex(updated.at(i), 0);

            if (!query.exec(QString("SELECT title, iconSource, iconWidth, iconHeight, folderId, localUnreadCount, FROM feeds WHERE id = %1").arg(updated.at(i)))) {
                QLOG_ERROR() << "Feeds model: failed to select data for changed feeds from database: " << query.lastError().text();
            }

            query.next();

            int fId = query.value(4).toInt();

            // check if updated feed is still child of these folder
            if ((idx != -999) && (fId == folderId())) {

                QLOG_DEBUG() << "Feeds model: updating feed at index " << idx;

                m_items.at(i)->title = query.value(0).toString();
                m_items.at(i)->iconSource = query.value(1).toString();
                m_items.at(i)->iconWidth = query.value(2).toInt();
                m_items.at(i)->iconHeight = query.value(3).toInt();

                QVector<int> roles(1, TitleRole);
                roles.append(IconSourceRole);
                roles.append(IconWidthRole);
                roles.append(IconHeightRole);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
                emit dataChanged(index(idx), index(idx), roles);
#else
                emit dataChanged(index(idx), index(idx));
#endif
            } else if ((idx != -999) && (fId != folderId())) {

                // the updated feed is no longer child of these folder

                QLOG_DEBUG() << "Feeds model: removing feed at index " << idx << " because it is no longer child of this folder";

                beginRemoveRows(QModelIndex(), idx, idx);

                delete m_items.takeAt(i);

                endRemoveRows();
            } else if ((idx == -999) && (fId == folderId())) {

                // the feed has been moved to this folder

                QLOG_DEBUG() << "Feeds model: adding feed that has been moved to this folder";

                beginInsertRows(QModelIndex(), rowCount(), rowCount());

                OcFeedObject *fobj = new OcFeedObject(updated.at(i),
                                                      0,
                                                      query.value(0).toString(),
                                                      query.value(5).toInt(),
                                                      query.value(1).toString(),
                                                      query.value(2).toInt(),
                                                      query.value(3).toInt());
                m_items.append(fobj);

                endInsertRows();
            }
        }
    }


    if (!newFeeds.isEmpty()) {

        QString feedList("(");
        for (int i = 0; i < newFeeds.size(); ++i) {
            feedList.append(QString::number(newFeeds.at(i)));
            feedList.append(", ");
        }
        feedList.chop(2);
        feedList.append(")");

        int length = 0;

        if (!query.exec(QString("SELECT COUNT(id) FROM feeds WHERE folderId = %1 AND id IN %2").arg(folderId()).arg(feedList))) {
            QLOG_ERROR() << "Feeds model: failed to select count of new feeds in this folder from database: " << query.lastError().text();
        }

        query.next();

        length = query.value(0).toInt();

        if (length > 0) {

            QLOG_INFO() << "Feeds model: adding new feeds";

            if (!query.exec(QString("SELECT id, title, localUnreadCount, iconSource, iconWidth, iconHeight WHERE folderId = %1 AND id IN %2").arg(folderId()).arg(feedList))) {
                QLOG_ERROR() << "Feeds model: failed to select data for newly added feeds from database: " << query.lastError().text();
            }

            beginInsertRows(QModelIndex(), rowCount(), (rowCount() + length - 1));

            while(query.next()) {

                OcFeedObject *fobj = new OcFeedObject(query.value(0).toInt(),
                                                      0,
                                                      query.value(1).toString(),
                                                      query.value(2).toInt(),
                                                      query.value(3).toString(),
                                                      query.value(4).toInt(),
                                                      query.value(5).toInt());
                m_items.append(fobj);
            }

            endInsertRows();

            endInsertRows();
        }
    }


    if (!deleted.isEmpty()) {

        for (int i = 0; i < deleted.size(); ++i) {

            int idx = findIndex(deleted.at(i), 0);

            if (idx != -999) {

                QLOG_INFO() << "Feeds model: removing deleted feed at index " << idx;

                beginRemoveRows(QModelIndex(), idx, idx);

                delete m_items.takeAt(idx);

                endRemoveRows();
            }
        }
    }

    queryAndSetTotalUnread();
}