Can get which is the currently selected user.

This commit is contained in:
Pierre HUBERT 2019-01-15 09:39:38 +01:00
parent 3a1cc0f211
commit 4fda88d735
7 changed files with 169 additions and 3 deletions

View File

@ -43,7 +43,8 @@ SOURCES += \
helpers/imageloadhelper.cpp \ helpers/imageloadhelper.cpp \
utils/filesutils.cpp \ utils/filesutils.cpp \
widgets/remoteimagemanager.cpp \ widgets/remoteimagemanager.cpp \
widgets/clickablelabel.cpp widgets/clickablelabel.cpp \
widgets/currentuserinformationwidget.cpp
HEADERS += \ HEADERS += \
helpers/accounthelper.h \ helpers/accounthelper.h \
@ -81,7 +82,8 @@ HEADERS += \
utils/filesutils.h \ utils/filesutils.h \
data/qlabelholder.h \ data/qlabelholder.h \
widgets/remoteimagemanager.h \ widgets/remoteimagemanager.h \
widgets/clickablelabel.h widgets/clickablelabel.h \
widgets/currentuserinformationwidget.h
FORMS += \ FORMS += \
widgets/loginwidget.ui \ widgets/loginwidget.ui \
@ -89,7 +91,8 @@ FORMS += \
widgets/aboutthisappdialog.ui \ widgets/aboutthisappdialog.ui \
widgets/conversationitemwidget.ui \ widgets/conversationitemwidget.ui \
widgets/conversationwidget.ui \ widgets/conversationwidget.ui \
widgets/conversationmessagewidget.ui widgets/conversationmessagewidget.ui \
widgets/currentuserinformationwidget.ui
RESOURCES += \ RESOURCES += \
res/ressources.qrc res/ressources.qrc

View File

@ -0,0 +1,42 @@
#include <QMessageBox>
#include "currentuserinformationwidget.h"
#include "ui_currentuserinformationwidget.h"
#include "../helpers/accounthelper.h"
#include "../helpers/usershelper.h"
#include "../helpers/imageloadhelper.h"
#include "../data/user.h"
CurrentUserInformationWidget::CurrentUserInformationWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CurrentUserInformationWidget)
{
ui->setupUi(this);
mUsersHelper = new UsersHelper(this);
connect(mUsersHelper, &UsersHelper::onGotUsersInfo, this, &CurrentUserInformationWidget::onGotUsersInfo);
//Get information about the current user
QList<int> mUsersToGet;
mUsersToGet << AccountHelper().getUserID();
mUsersHelper->getList(mUsersToGet);
}
CurrentUserInformationWidget::~CurrentUserInformationWidget()
{
delete ui;
}
void CurrentUserInformationWidget::onGotUsersInfo(bool success, const UsersList &list)
{
if(!success || list.size() == 0){
QMessageBox::warning(this, tr("Error"), tr("Could not get current user information!"));
return;
}
User user = list.at(0);
//Apply user information
ImageLoadHelper::Load(ui->image_label, user.accountImage());
ui->name_label->setText(user.displayName());
}

View File

@ -0,0 +1,43 @@
/**
* Current user information widget
*
* @author Pierre HUBERT
*/
#ifndef CURRENTUSERINFORMATIONWIDGET_H
#define CURRENTUSERINFORMATIONWIDGET_H
#include <QWidget>
namespace Ui {
class CurrentUserInformationWidget;
}
class UsersHelper;
class UsersList;
class CurrentUserInformationWidget : public QWidget
{
Q_OBJECT
public:
explicit CurrentUserInformationWidget(QWidget *parent = nullptr);
~CurrentUserInformationWidget();
private slots:
/**
* Slot called once we have got user information
*
* @param success Depends of the success of the operation
* @param list
*/
void onGotUsersInfo(bool success, const UsersList &list);
private:
Ui::CurrentUserInformationWidget *ui;
UsersHelper *mUsersHelper;
};
#endif // CURRENTUSERINFORMATIONWIDGET_H

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CurrentUserInformationWidget</class>
<widget class="QWidget" name="CurrentUserInformationWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Current User</string>
</property>
<property name="windowIcon">
<iconset resource="../res/ressources.qrc">
<normaloff>:/baseline_person_black_48dp.png</normaloff>:/baseline_person_black_48dp.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="image_label">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1000</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../res/ressources.qrc">:/baseline_person_black_48dp.png</pixmap>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="name_label">
<property name="font">
<font>
<pointsize>19</pointsize>
</font>
</property>
<property name="text">
<string>User name</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../res/ressources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -7,6 +7,7 @@
#include "loginwidget.h" #include "loginwidget.h"
#include "conversationslistwidget.h" #include "conversationslistwidget.h"
#include "conversationwidget.h" #include "conversationwidget.h"
#include "currentuserinformationwidget.h"
#include "../utils/uiutils.h" #include "../utils/uiutils.h"
#include "../helpers/accounthelper.h" #include "../helpers/accounthelper.h"
@ -65,3 +66,8 @@ void MainWindow::on_actionExit_triggered()
{ {
QCoreApplication::exit(0); QCoreApplication::exit(0);
} }
void MainWindow::on_actionInformation_triggered()
{
(new CurrentUserInformationWidget())->show();
}

View File

@ -46,6 +46,8 @@ private slots:
void on_actionExit_triggered(); void on_actionExit_triggered();
void on_actionInformation_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ConversationsListWidget *mConversationsListWidget; ConversationsListWidget *mConversationsListWidget;

View File

@ -54,6 +54,7 @@
<property name="title"> <property name="title">
<string>Account</string> <string>Account</string>
</property> </property>
<addaction name="actionInformation"/>
<addaction name="actionLogout"/> <addaction name="actionLogout"/>
</widget> </widget>
<widget class="QMenu" name="menuHelp"> <widget class="QMenu" name="menuHelp">
@ -94,6 +95,11 @@
<string>Exit</string> <string>Exit</string>
</property> </property>
</action> </action>
<action name="actionInformation">
<property name="text">
<string>Information</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="../res/ressources.qrc"/> <include location="../res/ressources.qrc"/>