Merge pull request #534 from poixen/accountage
Added account age to user info window
This commit is contained in:
commit
69e6aa355f
4 changed files with 72 additions and 37 deletions
|
@ -2,43 +2,40 @@
|
||||||
#include "pixmapgenerator.h"
|
#include "pixmapgenerator.h"
|
||||||
#include "abstractclient.h"
|
#include "abstractclient.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
|
||||||
|
|
||||||
#include "pending_command.h"
|
#include "pending_command.h"
|
||||||
#include "pb/session_commands.pb.h"
|
#include "pb/session_commands.pb.h"
|
||||||
#include "pb/response_get_user_info.pb.h"
|
#include "pb/response_get_user_info.pb.h"
|
||||||
|
|
||||||
|
const qint64 SIXTY = 60;
|
||||||
|
const qint64 HOURS_IN_A_DAY = 24;
|
||||||
|
const qint64 DAYS_IN_A_YEAR = 365;
|
||||||
|
|
||||||
UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags)
|
UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags)
|
||||||
: QWidget(parent, flags), client(_client), fullInfo(_fullInfo)
|
: QWidget(parent, flags), client(_client), fullInfo(_fullInfo)
|
||||||
{
|
{
|
||||||
avatarLabel = new QLabel;
|
QFont nameFont = nameLabel.font();
|
||||||
nameLabel = new QLabel;
|
|
||||||
QFont nameFont = nameLabel->font();
|
|
||||||
nameFont.setBold(true);
|
nameFont.setBold(true);
|
||||||
nameFont.setPointSize(nameFont.pointSize() * 1.5);
|
nameFont.setPointSize(nameFont.pointSize() * 1.5);
|
||||||
nameLabel->setFont(nameFont);
|
nameLabel.setFont(nameFont);
|
||||||
realNameLabel1 = new QLabel;
|
|
||||||
realNameLabel2 = new QLabel;
|
|
||||||
genderLabel1 = new QLabel;
|
|
||||||
genderLabel2 = new QLabel;
|
|
||||||
countryLabel1 = new QLabel;
|
|
||||||
countryLabel2 = new QLabel;
|
|
||||||
userLevelLabel1 = new QLabel;
|
|
||||||
userLevelLabel2 = new QLabel;
|
|
||||||
userLevelLabel3 = new QLabel;
|
|
||||||
|
|
||||||
QGridLayout *mainLayout = new QGridLayout;
|
QGridLayout *mainLayout = new QGridLayout;
|
||||||
mainLayout->addWidget(avatarLabel, 0, 0, 1, 3, Qt::AlignCenter);
|
mainLayout->addWidget(&avatarLabel, 0, 0, 1, 3, Qt::AlignCenter);
|
||||||
mainLayout->addWidget(nameLabel, 1, 0, 1, 3);
|
mainLayout->addWidget(&nameLabel, 1, 0, 1, 3);
|
||||||
mainLayout->addWidget(realNameLabel1, 2, 0, 1, 1);
|
mainLayout->addWidget(&realNameLabel1, 2, 0, 1, 1);
|
||||||
mainLayout->addWidget(realNameLabel2, 2, 1, 1, 2);
|
mainLayout->addWidget(&realNameLabel2, 2, 1, 1, 2);
|
||||||
mainLayout->addWidget(genderLabel1, 3, 0, 1, 1);
|
mainLayout->addWidget(&genderLabel1, 3, 0, 1, 1);
|
||||||
mainLayout->addWidget(genderLabel2, 3, 1, 1, 2);
|
mainLayout->addWidget(&genderLabel2, 3, 1, 1, 2);
|
||||||
mainLayout->addWidget(countryLabel1, 4, 0, 1, 1);
|
mainLayout->addWidget(&countryLabel1, 4, 0, 1, 1);
|
||||||
mainLayout->addWidget(countryLabel2, 4, 1, 1, 2);
|
mainLayout->addWidget(&countryLabel2, 4, 1, 1, 2);
|
||||||
mainLayout->addWidget(userLevelLabel1, 5, 0, 1, 1);
|
mainLayout->addWidget(&userLevelLabel1, 5, 0, 1, 1);
|
||||||
mainLayout->addWidget(userLevelLabel2, 5, 1, 1, 1);
|
mainLayout->addWidget(&userLevelLabel2, 5, 1, 1, 1);
|
||||||
mainLayout->addWidget(userLevelLabel3, 5, 2, 1, 1);
|
mainLayout->addWidget(&userLevelLabel3, 5, 2, 1, 1);
|
||||||
|
mainLayout->addWidget(&accountAgeLebel1, 6, 0, 1, 1);
|
||||||
|
mainLayout->addWidget(&accountAgeLabel2, 6, 2, 1, 1);
|
||||||
mainLayout->setColumnStretch(2, 10);
|
mainLayout->setColumnStretch(2, 10);
|
||||||
|
|
||||||
setWindowTitle(tr("User information"));
|
setWindowTitle(tr("User information"));
|
||||||
|
@ -48,10 +45,11 @@ UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *paren
|
||||||
|
|
||||||
void UserInfoBox::retranslateUi()
|
void UserInfoBox::retranslateUi()
|
||||||
{
|
{
|
||||||
realNameLabel1->setText(tr("Real name:"));
|
realNameLabel1.setText(tr("Real name:"));
|
||||||
genderLabel1->setText(tr("Gender:"));
|
genderLabel1.setText(tr("Gender:"));
|
||||||
countryLabel1->setText(tr("Location:"));
|
countryLabel1.setText(tr("Location:"));
|
||||||
userLevelLabel1->setText(tr("User level:"));
|
userLevelLabel1.setText(tr("User level:"));
|
||||||
|
accountAgeLebel1.setText(tr("Account Age:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
|
@ -62,13 +60,13 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
const std::string bmp = user.avatar_bmp();
|
const std::string bmp = user.avatar_bmp();
|
||||||
if (!avatarPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
|
if (!avatarPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
|
||||||
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel);
|
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel);
|
||||||
avatarLabel->setPixmap(avatarPixmap);
|
avatarLabel.setPixmap(avatarPixmap);
|
||||||
|
|
||||||
nameLabel->setText(QString::fromStdString(user.name()));
|
nameLabel.setText(QString::fromStdString(user.name()));
|
||||||
realNameLabel2->setText(QString::fromStdString(user.real_name()));
|
realNameLabel2.setText(QString::fromStdString(user.real_name()));
|
||||||
genderLabel2->setPixmap(GenderPixmapGenerator::generatePixmap(15, user.gender()));
|
genderLabel2.setPixmap(GenderPixmapGenerator::generatePixmap(15, user.gender()));
|
||||||
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, QString::fromStdString(user.country())));
|
countryLabel2.setPixmap(CountryPixmapGenerator::generatePixmap(15, QString::fromStdString(user.country())));
|
||||||
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
userLevelLabel2.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
||||||
QString userLevelText;
|
QString userLevelText;
|
||||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||||
userLevelText = tr("Administrator");
|
userLevelText = tr("Administrator");
|
||||||
|
@ -78,7 +76,34 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
userLevelText = tr("Registered user");
|
userLevelText = tr("Registered user");
|
||||||
else
|
else
|
||||||
userLevelText = tr("Unregistered user");
|
userLevelText = tr("Unregistered user");
|
||||||
userLevelLabel3->setText(userLevelText);
|
userLevelLabel3.setText(userLevelText);
|
||||||
|
|
||||||
|
QString accountAgeString = tr("Unregistered user");
|
||||||
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin) || userLevel.testFlag(ServerInfo_User::IsModerator) || userLevel.testFlag(ServerInfo_User::IsRegistered)) {
|
||||||
|
if (user.accountage_secs() == 0)
|
||||||
|
accountAgeString = tr("Unknown");
|
||||||
|
else {
|
||||||
|
qint64 seconds = user.accountage_secs();
|
||||||
|
qint64 minutes = seconds / SIXTY;
|
||||||
|
qint64 hours = minutes / SIXTY;
|
||||||
|
qint64 days = hours / HOURS_IN_A_DAY;
|
||||||
|
qint64 years = days / DAYS_IN_A_YEAR;
|
||||||
|
qint64 daysMinusYears = days - (years * DAYS_IN_A_YEAR);
|
||||||
|
|
||||||
|
accountAgeString = "";
|
||||||
|
if (years >= 1) {
|
||||||
|
accountAgeString = QString::number(years);
|
||||||
|
accountAgeString.append(" ");
|
||||||
|
accountAgeString.append(years == 1 ? tr("Year") : tr("Years"));
|
||||||
|
accountAgeString.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
accountAgeString.append(QString::number(daysMinusYears));
|
||||||
|
accountAgeString.append(" ");
|
||||||
|
accountAgeString.append(days == 1 ? tr("Day") : tr("Days"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
accountAgeLabel2.setText(accountAgeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInfoBox::updateInfo(const QString &userName)
|
void UserInfoBox::updateInfo(const QString &userName)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define USERINFOBOX_H
|
#define USERINFOBOX_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
|
@ -13,7 +14,8 @@ class UserInfoBox : public QWidget {
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
bool fullInfo;
|
bool fullInfo;
|
||||||
QLabel *avatarLabel, *nameLabel, *realNameLabel1, *realNameLabel2, *genderLabel1, *genderLabel2, *countryLabel1, *countryLabel2, *userLevelLabel1, *userLevelLabel2, *userLevelLabel3;
|
QLabel avatarLabel, nameLabel, realNameLabel1, realNameLabel2, genderLabel1, genderLabel2, countryLabel1,
|
||||||
|
countryLabel2, userLevelLabel1, userLevelLabel2, userLevelLabel3, accountAgeLebel1, accountAgeLabel2;
|
||||||
public:
|
public:
|
||||||
UserInfoBox(AbstractClient *_client, bool fullInfo, QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
UserInfoBox(AbstractClient *_client, bool fullInfo, QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
|
@ -21,4 +21,5 @@ message ServerInfo_User {
|
||||||
optional sint32 id = 8 [default = -1];
|
optional sint32 id = 8 [default = -1];
|
||||||
optional sint32 server_id = 9 [default = -1];
|
optional sint32 server_id = 9 [default = -1];
|
||||||
optional uint64 session_id = 10;
|
optional uint64 session_id = 10;
|
||||||
|
optional uint64 accountage_secs = 11;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
Servatrice_DatabaseInterface::Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server)
|
Servatrice_DatabaseInterface::Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server)
|
||||||
: instanceId(_instanceId),
|
: instanceId(_instanceId),
|
||||||
|
@ -283,6 +284,12 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer
|
||||||
const QString realName = query.value(3).toString();
|
const QString realName = query.value(3).toString();
|
||||||
if (!realName.isEmpty())
|
if (!realName.isEmpty())
|
||||||
result.set_real_name(realName.toStdString());
|
result.set_real_name(realName.toStdString());
|
||||||
|
|
||||||
|
const QDateTime regDate = query.value(7).toDateTime();
|
||||||
|
if(!regDate.toString(Qt::ISODate).isEmpty()) {
|
||||||
|
qint64 accountAgeInSeconds = regDate.secsTo(QDateTime::currentDateTime());
|
||||||
|
result.set_accountage_secs(accountAgeInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -298,7 +305,7 @@ ServerInfo_User Servatrice_DatabaseInterface::getUserData(const QString &name, b
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
QSqlQuery query(sqlDatabase);
|
QSqlQuery query(sqlDatabase);
|
||||||
query.prepare("select id, name, admin, realname, gender, country, avatar_bmp from " + server->getDbPrefix() + "_users where name = :name and active = 1");
|
query.prepare("select id, name, admin, realname, gender, country, avatar_bmp, registrationDate from " + server->getDbPrefix() + "_users where name = :name and active = 1");
|
||||||
query.bindValue(":name", name);
|
query.bindValue(":name", name);
|
||||||
if (!execSqlQuery(query))
|
if (!execSqlQuery(query))
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue