From 4fda88d735c79a3945c1c97c32020678fa2ba996 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 15 Jan 2019 09:39:38 +0100 Subject: [PATCH] Can get which is the currently selected user. --- src/ComunicMessages.pro | 9 ++- src/widgets/currentuserinformationwidget.cpp | 42 +++++++++++++ src/widgets/currentuserinformationwidget.h | 43 +++++++++++++ src/widgets/currentuserinformationwidget.ui | 64 ++++++++++++++++++++ src/widgets/mainwindow.cpp | 6 ++ src/widgets/mainwindow.h | 2 + src/widgets/mainwindow.ui | 6 ++ 7 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 src/widgets/currentuserinformationwidget.cpp create mode 100644 src/widgets/currentuserinformationwidget.h create mode 100644 src/widgets/currentuserinformationwidget.ui diff --git a/src/ComunicMessages.pro b/src/ComunicMessages.pro index 268dd3d..29d249c 100644 --- a/src/ComunicMessages.pro +++ b/src/ComunicMessages.pro @@ -43,7 +43,8 @@ SOURCES += \ helpers/imageloadhelper.cpp \ utils/filesutils.cpp \ widgets/remoteimagemanager.cpp \ - widgets/clickablelabel.cpp + widgets/clickablelabel.cpp \ + widgets/currentuserinformationwidget.cpp HEADERS += \ helpers/accounthelper.h \ @@ -81,7 +82,8 @@ HEADERS += \ utils/filesutils.h \ data/qlabelholder.h \ widgets/remoteimagemanager.h \ - widgets/clickablelabel.h + widgets/clickablelabel.h \ + widgets/currentuserinformationwidget.h FORMS += \ widgets/loginwidget.ui \ @@ -89,7 +91,8 @@ FORMS += \ widgets/aboutthisappdialog.ui \ widgets/conversationitemwidget.ui \ widgets/conversationwidget.ui \ - widgets/conversationmessagewidget.ui + widgets/conversationmessagewidget.ui \ + widgets/currentuserinformationwidget.ui RESOURCES += \ res/ressources.qrc diff --git a/src/widgets/currentuserinformationwidget.cpp b/src/widgets/currentuserinformationwidget.cpp new file mode 100644 index 0000000..4aa1560 --- /dev/null +++ b/src/widgets/currentuserinformationwidget.cpp @@ -0,0 +1,42 @@ +#include + +#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 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()); +} diff --git a/src/widgets/currentuserinformationwidget.h b/src/widgets/currentuserinformationwidget.h new file mode 100644 index 0000000..8935de8 --- /dev/null +++ b/src/widgets/currentuserinformationwidget.h @@ -0,0 +1,43 @@ +/** + * Current user information widget + * + * @author Pierre HUBERT + */ + +#ifndef CURRENTUSERINFORMATIONWIDGET_H +#define CURRENTUSERINFORMATIONWIDGET_H + +#include + +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 diff --git a/src/widgets/currentuserinformationwidget.ui b/src/widgets/currentuserinformationwidget.ui new file mode 100644 index 0000000..4c13f70 --- /dev/null +++ b/src/widgets/currentuserinformationwidget.ui @@ -0,0 +1,64 @@ + + + CurrentUserInformationWidget + + + + 0 + 0 + 400 + 300 + + + + Current User + + + + :/baseline_person_black_48dp.png:/baseline_person_black_48dp.png + + + + + + + 16777215 + 1000 + + + + + + + :/baseline_person_black_48dp.png + + + false + + + Qt::AlignCenter + + + + + + + + 19 + + + + User name + + + Qt::AlignCenter + + + + + + + + + + diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 1290856..fda7697 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -7,6 +7,7 @@ #include "loginwidget.h" #include "conversationslistwidget.h" #include "conversationwidget.h" +#include "currentuserinformationwidget.h" #include "../utils/uiutils.h" #include "../helpers/accounthelper.h" @@ -65,3 +66,8 @@ void MainWindow::on_actionExit_triggered() { QCoreApplication::exit(0); } + +void MainWindow::on_actionInformation_triggered() +{ + (new CurrentUserInformationWidget())->show(); +} diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index 5039f4a..6734c72 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -46,6 +46,8 @@ private slots: void on_actionExit_triggered(); + void on_actionInformation_triggered(); + private: Ui::MainWindow *ui; ConversationsListWidget *mConversationsListWidget; diff --git a/src/widgets/mainwindow.ui b/src/widgets/mainwindow.ui index cb6de54..ec9c49a 100644 --- a/src/widgets/mainwindow.ui +++ b/src/widgets/mainwindow.ui @@ -54,6 +54,7 @@ Account + @@ -94,6 +95,11 @@ Exit + + + Information + +