Displays activity and notification messages in the list view.

Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
Camila San 2018-03-26 17:13:54 +02:00 committed by Roeland Jago Douma
parent 908870ccde
commit 75c2613b1b
No known key found for this signature in database
GPG key ID: F941078878347C0C
5 changed files with 35 additions and 32 deletions

View file

@ -79,9 +79,9 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
QIcon actionIcon = qvariant_cast<QIcon>(index.data(ActionIconRole));
QIcon userIcon = qvariant_cast<QIcon>(index.data(UserIconRole));
QString actionText = qvariant_cast<QString>(index.data(ActionTextRole));
QString pathText = qvariant_cast<QString>(index.data(PathRole));
QString remoteLink = qvariant_cast<QString>(index.data(LinkRole));
QString messageText = qvariant_cast<QString>(index.data(MessageRole));
// QString pathText = qvariant_cast<QString>(index.data(PathRole));
// QString remoteLink = qvariant_cast<QString>(index.data(LinkRole));
QString timeText = qvariant_cast<QString>(index.data(PointInTimeRole));
QString accountRole = qvariant_cast<QString>(index.data(AccountRole));
bool accountOnline = qvariant_cast<bool>(index.data(AccountConnectedRole));
@ -110,9 +110,14 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
timeBox.setWidth(timeBoxWidth);
timeBox.setHeight(fm.height());
// text rect
QRect messageTextBox = timeBox;\
messageTextBox.setRight(timeBox.left() - margin);
messageTextBox.setLeft(messageTextBox.right() - timeBoxWidth);
QRect actionTextBox = timeBox;
actionTextBox.setLeft(userIconRect.right() + margin);
actionTextBox.setRight(timeBox.left() - margin);
actionTextBox.setRight(messageTextBox.left() - margin);
/* === start drawing === */
QPixmap pm = actionIcon.pixmap(iconWidth, iconHeight, QIcon::Normal);
@ -135,6 +140,10 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
const QString elidedAction = fm.elidedText(actionText, Qt::ElideRight, actionTextBox.width());
painter->drawText(actionTextBox, elidedAction);
const QString elidedMessage = fm.elidedText(messageText, Qt::ElideRight, messageTextBox.width());
painter->drawText(messageTextBox, elidedMessage);
int atPos = accountRole.indexOf(QLatin1Char('@'));
if (atPos > -1) {
accountRole.remove(0, atPos + 1);

View file

@ -30,6 +30,7 @@ public:
UserIconRole,
AccountRole,
ActionTextRole,
MessageRole,
PathRole,
LinkRole,
PointInTimeRole,

View file

@ -46,8 +46,6 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
return QVariant();
a = _finalList.at(index.row());
qDebug() << "Adding activity/notification: " << a._subject;
qDebug() << "Adding activity/notification: " << a._message;
AccountStatePtr ast = AccountManager::instance()->account(a._accName);
if (!ast)
return QVariant();
@ -78,6 +76,9 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
case ActivityItemDelegate::ActionTextRole:
return a._subject;
break;
case ActivityItemDelegate::MessageRole:
return a._message;
break;
case ActivityItemDelegate::LinkRole:
return a._link;
break;
@ -176,34 +177,23 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st
}
void ActivityListModel::addToActivityList(AccountState *ast, ActivityList list) {
_activityLists[ast].append(list);
//endInsertRows();
ActivityList resultList;
foreach (ActivityList list, _activityLists.values()) {
resultList.append(list);
}
std::sort(resultList.begin(), resultList.end());
beginResetModel();
_finalList.clear();
endResetModel();
beginInsertRows(QModelIndex(), 0, resultList.count());
_finalList = resultList;
endInsertRows();
_notificationLists[ast].append(list);
combineActivityLists();
}
void ActivityListModel::combineActivityLists()
{
ActivityList resultList;
foreach (ActivityList list, _notificationLists.values()) {
resultList.append(list);
}
foreach (ActivityList list, _activityLists.values()) {
resultList.append(list);
}
std::sort(resultList.begin(), resultList.end());
//std::sort(resultList.begin(), resultList.end());
beginResetModel();
_finalList.clear();

View file

@ -64,6 +64,7 @@ private:
void combineActivityLists();
QMap<AccountState *, ActivityList> _activityLists;
QMap<AccountState *, ActivityList> _notificationLists;
ActivityList _finalList;
QSet<AccountState *> _currentlyFetching;
};

View file

@ -174,6 +174,7 @@ void ActivityWidget::storeActivityList(QTextStream &ts)
ActivityList activities = _model->activityList();
foreach (Activity activity, activities) {
QString message = activity._message.isEmpty()? "Message!" : activity._message;
ts << right
// account name
<< qSetFieldWidth(30)
@ -199,12 +200,15 @@ void ActivityWidget::storeActivityList(QTextStream &ts)
// separator
<< qSetFieldWidth(0) << ","
// message (mostly empty)
<< qSetFieldWidth(55)
<< activity._message
//
<< qSetFieldWidth(0)
<< endl;
// message
<< qSetFieldWidth(55)
<< message
// separator
<< qSetFieldWidth(0) << ","
//
<< qSetFieldWidth(0)
<< endl;
}
}
@ -316,9 +320,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList &list)
}
_newNotifications.append(activity);
}
i++;
}
//_model->addToActivityList(AccountManager::instance()->account(listAccountName).data(), _newNotifications);
_model->addToActivityList(AccountManager::instance()->account(listAccountName).data(), list);
// check if there are widgets that have no corresponding activity from