}
YTUser* ChannelModel::userForIndex(const QModelIndex &index) const {
+ const int row = index.row();
+ if (row < channelOffset) return 0;
return channels.at(index.row() - channelOffset);
}
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;
}
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;
setMouseTracking(true);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
+ SLOT(showContextMenu(const QPoint &)));
+
connect(this, SIGNAL(clicked(const QModelIndex &)),
SLOT(itemActivated(const QModelIndex &)));
connect(this, SIGNAL(entered(const QModelIndex &)),
void ChannelView::setupActions() {
QSettings settings;
- markAsWatchedAction = new QAction(
- Utils::icon("mark-watched"), tr("Mark all as watched"), this);
- markAsWatchedAction->setEnabled(false);
- markAsWatchedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
- connect(markAsWatchedAction, SIGNAL(triggered()), SLOT(markAllAsWatched()));
- statusActions << markAsWatchedAction;
-
- showUpdated = settings.value(showUpdatedKey, false).toBool();
- QAction *showUpdatedAction = new QAction(
- Utils::icon("show-updated"), tr("Show Updated"), this);
- showUpdatedAction->setCheckable(true);
- showUpdatedAction->setChecked(showUpdated);
- showUpdatedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
- connect(showUpdatedAction, SIGNAL(toggled(bool)), SLOT(toggleShowUpdated(bool)));
- statusActions << showUpdatedAction;
-
SortBy sortBy = static_cast<SortBy>(settings.value(sortByKey, SortByName).toInt());
QMenu *sortMenu = new QMenu(this);
widgetAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
statusActions << widgetAction;
+ markAsWatchedAction = new QAction(
+ Utils::icon("mark-watched"), tr("Mark all as watched"), this);
+ markAsWatchedAction->setEnabled(false);
+ markAsWatchedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
+ connect(markAsWatchedAction, SIGNAL(triggered()), SLOT(markAllAsWatched()));
+ statusActions << markAsWatchedAction;
+
+ showUpdated = settings.value(showUpdatedKey, false).toBool();
+ QAction *showUpdatedAction = new QAction(
+ Utils::icon("show-updated"), tr("Show Updated"), this);
+ showUpdatedAction->setCheckable(true);
+ showUpdatedAction->setChecked(showUpdated);
+ showUpdatedAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
+ connect(showUpdatedAction, SIGNAL(toggled(bool)), SLOT(toggleShowUpdated(bool)));
+ statusActions << showUpdatedAction;
+
foreach (QAction *action, statusActions) {
window()->addAction(action);
Utils::setupAction(action);
}
}
+void ChannelView::showContextMenu(const QPoint &point) {
+ const QModelIndex index = indexAt(point);
+ if (!index.isValid()) return;
+
+ YTUser *user = channelsModel->userForIndex(index);
+ if (!user) return;
+
+ unsetCursor();
+
+ QMenu menu;
+
+ QAction *markAsWatchedAction = menu.addAction(tr("Mark as Watched"), user, SLOT(updateWatched()));
+ connect(markAsWatchedAction, SIGNAL(triggered()),
+ ChannelAggregator::instance(), SLOT(updateUnwatchedCount()));
+
+ menu.addSeparator();
+
+ /*
+ // TODO
+ QAction *notificationsAction = menu.addAction(tr("Receive Notifications"), user, SLOT(unsubscribe()));
+ notificationsAction->setCheckable(true);
+ notificationsAction->setChecked(true);
+ */
+
+ QAction *unsubscribeAction = menu.addAction(tr("Unsubscribe"), user, SLOT(unsubscribe()));
+ connect(unsubscribeAction, SIGNAL(triggered()),
+ ChannelAggregator::instance(), SLOT(updateUnwatchedCount()));
+
+ menu.exec(mapToGlobal(point));
+}
+
void ChannelView::paintEvent(QPaintEvent *event) {
if (model()->rowCount() < 3) {
QString msg;