mirror of
https://gitlab.com/comunic/comunicmessages
synced 2025-06-21 17:35:16 +00:00
Display the list of conversations.
This commit is contained in:
31
widgets/conversationitemwidget.cpp
Normal file
31
widgets/conversationitemwidget.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "conversationitemwidget.h"
|
||||
#include "ui_conversationitemwidget.h"
|
||||
#include "../helpers/conversationslisthelper.h"
|
||||
#include "../utils/timeutils.h"
|
||||
|
||||
ConversationItemWidget::ConversationItemWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ConversationItemWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
ConversationItemWidget::~ConversationItemWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ConversationItemWidget::setConversation(const Conversation &conv, const UsersList &list)
|
||||
{
|
||||
ui->nameLabel->setText(ConversationsListHelper::getConversationDisplayName(conv, list));
|
||||
QFont font = ui->nameLabel->font();
|
||||
font.setBold(!conv.sawLastMessage());
|
||||
ui->nameLabel->setFont(font);
|
||||
|
||||
if(conv.members().size() == 1)
|
||||
ui->numberMembersLabel->setText(tr("1 member"));
|
||||
else
|
||||
ui->numberMembersLabel->setText(tr("%1 members").arg(conv.members().size()));
|
||||
|
||||
ui->lastActivityLabel->setText(TimeUtils::TimeDiffToString(conv.lastActive()));
|
||||
}
|
41
widgets/conversationitemwidget.h
Normal file
41
widgets/conversationitemwidget.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Conversation item widget
|
||||
*
|
||||
* Contains information about a single conversation
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
#ifndef CONVERSATIONITEMWIDGET_H
|
||||
#define CONVERSATIONITEMWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class ConversationItemWidget;
|
||||
}
|
||||
|
||||
class Conversation;
|
||||
class User;
|
||||
class UsersList;
|
||||
|
||||
class ConversationItemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConversationItemWidget(QWidget *parent = nullptr);
|
||||
~ConversationItemWidget();
|
||||
|
||||
/**
|
||||
* Apply a conversation to the widget
|
||||
*
|
||||
* @param conv Information about the conversation to apply
|
||||
* @param list Information about potential users of the conversation
|
||||
*/
|
||||
void setConversation(const Conversation &conv, const UsersList &list);
|
||||
|
||||
private:
|
||||
Ui::ConversationItemWidget *ui;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONITEMWIDGET_H
|
129
widgets/conversationitemwidget.ui
Normal file
129
widgets/conversationitemwidget.ui
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ConversationItemWidget</class>
|
||||
<widget class="QWidget" name="ConversationItemWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>138</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>14</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../res/ressources.qrc">:/baseline_people_black_48dp.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="numberMembersLabel">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../res/ressources.qrc">:/baseline_access_time_black_48dp.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lastActivityLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../res/ressources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,9 +1,12 @@
|
||||
#include <QMessageBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "conversationslistwidget.h"
|
||||
#include "conversationitemwidget.h"
|
||||
#include "../helpers/conversationslisthelper.h"
|
||||
#include "../helpers/usershelper.h"
|
||||
#include "../data/conversationslist.h"
|
||||
#include "../utils/uiutils.h"
|
||||
|
||||
ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
@ -15,6 +18,9 @@ ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
|
||||
//Create users helper
|
||||
mUsersHelper = new UsersHelper(this);
|
||||
connect(mUsersHelper, &UsersHelper::onGotUsersInfo, this, &ConversationsListWidget::onGotUsersInfo);
|
||||
|
||||
//Set conversations list layout
|
||||
new QVBoxLayout(this);
|
||||
}
|
||||
|
||||
ConversationsListWidget::~ConversationsListWidget()
|
||||
@ -38,15 +44,28 @@ void ConversationsListWidget::onGotConversationsList(bool success, const Convers
|
||||
|
||||
//Get the list of users
|
||||
mUsersHelper->getList(list.getAllMembersId());
|
||||
|
||||
//Save the list of conversations
|
||||
mCurrList = list;
|
||||
}
|
||||
|
||||
void ConversationsListWidget::onGotUsersInfo(bool success, const QList<User> &users)
|
||||
void ConversationsListWidget::onGotUsersInfo(bool success, const UsersList &users)
|
||||
{
|
||||
if(!success){
|
||||
QMessageBox::warning(this, tr("Error"), tr("Could not get information about the members of the conversations!"));
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug("Got the list of members of the conversations.");
|
||||
//TODO : use ConversationItemWidget
|
||||
//Save members information
|
||||
mCurrList.setMembersInformation(users);
|
||||
|
||||
//First, remove any present convversation
|
||||
UiUtils::emptyLayout(layout());
|
||||
|
||||
//Append the list of conversations
|
||||
for(Conversation conv : mCurrList){
|
||||
ConversationItemWidget *item = new ConversationItemWidget;
|
||||
item->setConversation(conv, users);
|
||||
layout()->addWidget(item);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include "../data/conversationslist.h"
|
||||
#include "../data/userslist.h"
|
||||
#include "../data/user.h"
|
||||
|
||||
class ConversationsListHelper;
|
||||
@ -38,7 +39,7 @@ private slots:
|
||||
* @param success TRUE in case of success / FALSE else
|
||||
* @param users The list of suers (empty list in case of failure)
|
||||
*/
|
||||
void onGotUsersInfo(bool success, const QList<User> &users);
|
||||
void onGotUsersInfo(bool success, const UsersList &users);
|
||||
|
||||
private:
|
||||
ConversationsListHelper *mConversationsList;
|
||||
|
Reference in New Issue
Block a user