Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
db0a7798
Commit
db0a7798
authored
Nov 26, 2014
by
Gavin Bisesi
Browse files
Merge pull request #456 from ctrlaltca/gamesmodel_qt
Port #436 to QDateTime
parents
f71cfb12
c8aeff0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/gamesmodel.cpp
View file @
db0a7798
...
@@ -2,8 +2,7 @@
...
@@ -2,8 +2,7 @@
#include
"pb/serverinfo_game.pb.h"
#include
"pb/serverinfo_game.pb.h"
#include
<QDebug>
#include
<QDebug>
#include
<QStringList>
#include
<QStringList>
#include
<sstream>
#include
<QDateTime>
#include
<time.h>
namespace
{
namespace
{
const
unsigned
SECS_PER_MIN
=
60
;
const
unsigned
SECS_PER_MIN
=
60
;
...
@@ -21,7 +20,7 @@ namespace {
...
@@ -21,7 +20,7 @@ namespace {
* 91-300 minutes will return "Xhr ago"
* 91-300 minutes will return "Xhr ago"
* 300+ minutes will return "5+ hr ago"
* 300+ minutes will return "5+ hr ago"
*/
*/
QString
prettyPrintSecsAgo
(
u
int32_
t
secs
)
{
QString
prettyPrintSecsAgo
(
u
nsigned
in
t
secs
)
{
if
(
secs
<
SECS_PER_MIN
)
{
if
(
secs
<
SECS_PER_MIN
)
{
return
QObject
::
tr
(
"<1m ago"
);
return
QObject
::
tr
(
"<1m ago"
);
}
}
...
@@ -29,7 +28,7 @@ namespace {
...
@@ -29,7 +28,7 @@ namespace {
return
QObject
::
tr
(
"<5m ago"
);
return
QObject
::
tr
(
"<5m ago"
);
}
}
if
(
secs
<
SECS_PER_HOUR
)
{
if
(
secs
<
SECS_PER_HOUR
)
{
u
int32_
t
mins
=
secs
/
SECS_PER_MIN
;
u
nsigned
in
t
mins
=
secs
/
SECS_PER_MIN
;
if
(
secs
%
SECS_PER_MIN
>=
30
)
if
(
secs
%
SECS_PER_MIN
>=
30
)
mins
++
;
mins
++
;
//: This will have a number prepended, like "10m ago"
//: This will have a number prepended, like "10m ago"
...
@@ -44,7 +43,7 @@ namespace {
...
@@ -44,7 +43,7 @@ namespace {
//
//
// Personally, I prefer to keep the code cleaner, and allow these.
// Personally, I prefer to keep the code cleaner, and allow these.
if
(
secs
<
SECS_PER_MIN
*
90
)
{
if
(
secs
<
SECS_PER_MIN
*
90
)
{
u
int32_
t
mins
=
secs
/
SECS_PER_MIN
-
60
;
u
nsigned
in
t
mins
=
secs
/
SECS_PER_MIN
-
60
;
if
(
secs
%
SECS_PER_MIN
>=
30
)
if
(
secs
%
SECS_PER_MIN
>=
30
)
mins
++
;
mins
++
;
return
QObject
::
tr
(
"1hr "
)
return
QObject
::
tr
(
"1hr "
)
...
@@ -53,7 +52,7 @@ namespace {
...
@@ -53,7 +52,7 @@ namespace {
.
append
(
QObject
::
tr
(
"m ago"
));
.
append
(
QObject
::
tr
(
"m ago"
));
}
}
if
(
secs
<
SECS_PER_HOUR
*
5
)
{
if
(
secs
<
SECS_PER_HOUR
*
5
)
{
u
int32_
t
hours
=
secs
/
SECS_PER_HOUR
;
u
nsigned
in
t
hours
=
secs
/
SECS_PER_HOUR
;
if
(
secs
%
SECS_PER_HOUR
>=
SECS_PER_MIN
*
30
)
if
(
secs
%
SECS_PER_HOUR
>=
SECS_PER_MIN
*
30
)
hours
++
;
hours
++
;
//: This will have a number prepended, like "2h ago"
//: This will have a number prepended, like "2h ago"
...
@@ -83,9 +82,9 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
...
@@ -83,9 +82,9 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
switch
(
index
.
column
())
{
switch
(
index
.
column
())
{
case
0
:
return
rooms
.
value
(
g
.
room_id
());
case
0
:
return
rooms
.
value
(
g
.
room_id
());
case
1
:
{
case
1
:
{
uint32_t
now
=
time
(
NULL
)
;
QDateTime
then
;
uint32_t
then
=
g
.
start_time
();
then
.
setTime_t
(
g
.
start_time
()
)
;
int
secs
=
now
-
then
;
unsigned
int
secs
=
then
.
secsTo
(
QDateTime
::
currentDateTime
())
;
switch
(
role
)
{
switch
(
role
)
{
case
Qt
::
DisplayRole
:
return
prettyPrintSecsAgo
(
secs
);
case
Qt
::
DisplayRole
:
return
prettyPrintSecsAgo
(
secs
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment