$END_LICENSE */
#include "channelmodel.h"
-#include "ytuser.h"
+#include "ytchannel.h"
static const int channelOffset = 2;
case ChannelModel::DataObjectRole:
if (typeForIndex(index) == ChannelModel::ItemChannel)
- return QVariant::fromValue(QPointer<YTUser>(userForIndex(index)));
+ return QVariant::fromValue(QPointer<YTChannel>(channelForIndex(index)));
break;
case ChannelModel::HoveredItemRole:
case Qt::StatusTipRole:
if (typeForIndex(index) == ChannelModel::ItemChannel)
- return userForIndex(index)->getDescription();
+ return channelForIndex(index)->getDescription();
}
return QVariant();
}
-YTUser* ChannelModel::userForIndex(const QModelIndex &index) const {
+YTChannel* ChannelModel::channelForIndex(const QModelIndex &index) const {
const int row = index.row();
if (row < channelOffset) return 0;
return channels.at(index.row() - channelOffset);
qWarning() << q.lastQuery() << q.lastError().text();
sqlError = q.lastError();
}
+ channels.reserve(q.size());
while (q.next()) {
- YTUser *user = YTUser::forId(q.value(0).toString());
- connect(user, SIGNAL(thumbnailLoaded()), SLOT(updateSender()), Qt::UniqueConnection);
- connect(user, SIGNAL(notifyCountChanged()), SLOT(updateSender()), Qt::UniqueConnection);
- connect(user, SIGNAL(destroyed(QObject *)), SLOT(removeChannel(QObject *)), Qt::UniqueConnection);
- channels << user;
+ YTChannel *channel = YTChannel::forId(q.value(0).toString());
+ connect(channel, SIGNAL(thumbnailLoaded()), SLOT(updateSender()), Qt::UniqueConnection);
+ connect(channel, SIGNAL(notifyCountChanged()), SLOT(updateSender()), Qt::UniqueConnection);
+ connect(channel, SIGNAL(destroyed(QObject *)), SLOT(removeChannel(QObject *)), Qt::UniqueConnection);
+ channels << channel;
}
+ channels.squeeze();
endResetModel();
}
}
void ChannelModel::updateSender() {
- YTUser *user = static_cast<YTUser*>(sender());
- if (!user) {
+ YTChannel *channel = static_cast<YTChannel*>(sender());
+ if (!channel) {
qWarning() << "Cannot get sender" << __PRETTY_FUNCTION__;
return;
}
- updateChannel(user);
+ updateChannel(channel);
}
-void ChannelModel::updateChannel(YTUser *user) {
- int row = channels.indexOf(user);
+void ChannelModel::updateChannel(YTChannel *channel) {
+ int row = channels.indexOf(channel);
if (row == -1) return;
row += channelOffset;
QModelIndex i = createIndex(row, 0);
}
void ChannelModel::removeChannel(QObject *obj) {
- YTUser *user = static_cast<YTUser*>(obj);
- qWarning() << "user is" << user << obj << obj->metaObject()->className();
- if (!user) return;
+ YTChannel *channel = static_cast<YTChannel*>(obj);
+ // qWarning() << "channel" << channel << obj << obj->metaObject()->className();
+ if (!channel) return;
- int row = channels.indexOf(user);
+ int row = channels.indexOf(channel);
if (row == -1) return;
int position = row + channelOffset;