]> git.sur5r.net Git - minitube/blobdiff - src/channelmodel.cpp
Imported Upstream version 2.2
[minitube] / src / channelmodel.cpp
index 2aa6c43d351454cd05af4a9739f0960e9f698c2b..fb8cbdb577736e3c516b7b1a4e2968381b3ce3c0 100644 (file)
@@ -56,6 +56,8 @@ QVariant ChannelModel::data(const QModelIndex &index, int role) const {
 }
 
 YTUser* ChannelModel::userForIndex(const QModelIndex &index) const {
+    const int row = index.row();
+    if (row < channelOffset) return 0;
     return channels.at(index.row() - channelOffset);
 }
 
@@ -84,6 +86,8 @@ void ChannelModel::setQuery(const QString &query, const QSqlDatabase &db) {
     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;
     }
 
@@ -116,6 +120,20 @@ void ChannelModel::updateUnwatched() {
     emit dataChanged(i, i);
 }
 
+void ChannelModel::removeChannel(QObject *obj) {
+    YTUser *user = static_cast<YTUser*>(obj);
+    qWarning() << "user is" << user << obj << obj->metaObject()->className();
+    if (!user) return;
+
+    int row = channels.indexOf(user);
+    if (row == -1) return;
+
+    int position = row + channelOffset;
+    beginRemoveRows(QModelIndex(), position, position+1);
+    channels.removeAt(row);
+    endRemoveRows();
+}
+
 void ChannelModel::setHoveredRow(int row) {
     int oldRow = hoveredRow;
     hoveredRow = row;