1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2010 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "statsdlg.h"
21 
22 #include "config.h"
23 
24 #include <QDateTime>
25 #include <QDialogButtonBox>
26 #include <QLabel>
27 #include <QPushButton>
28 #include <QVBoxLayout>
29 
30 #include <licq/statistics.h>
31 #include <licq/contactlist/usermanager.h>
32 
33 #include "core/messagebox.h"
34 
35 #include "helpers/support.h"
36 
37 using namespace LicqQtGui;
38 /* TRANSLATOR LicqQtGui::StatsDlg */
39 
StatsDlg(QWidget * parent)40 StatsDlg::StatsDlg(QWidget* parent)
41   : QDialog(parent)
42 {
43   Support::setWidgetProps(this, "StatisticsDialog");
44   setAttribute(Qt::WA_DeleteOnClose, true);
45   setWindowTitle(tr("Licq - Statistics"));
46 
47   QVBoxLayout* lay = new QVBoxLayout(this);
48 
49   stats = new QLabel();
50 
51   lay->addWidget(stats);
52 
53   lay->addSpacing(20);
54 
55   QDialogButtonBox* buttons = new QDialogButtonBox(
56       QDialogButtonBox::Ok | QDialogButtonBox::Reset);
57   connect(buttons, SIGNAL(accepted()), SLOT(close()));
58   connect(buttons->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(reset()));
59   lay->addWidget(buttons);
60   buttons->button(QDialogButtonBox::Ok)->setFocus();
61 
62   prepare();
63 
64   show();
65 }
66 
prepare()67 void StatsDlg::prepare()
68 {
69   QDateTime utime, reset;
70   utime.setTime_t(Licq::gStatistics.startTime());
71   reset.setTime_t(Licq::gStatistics.resetTime());
72 
73   QString text = QString(
74       "<table width=100%>"
75       "<tr><th colspan=2>%1</th></tr>"
76       "<tr><td>%2</td><td align=right>%3</td></tr>"
77       "<tr><td>%4</td><td align=right>%5</td></tr>"
78       "<tr><td>%6</td><td align=right>%7</td></tr>"
79       "</table>"
80       "<hr>"
81       "<table width=100%>"
82       "<tr><th colspan=4>%8</th></tr>"
83       "<tr><td></td><td align=right><small>%9</small></td>"
84       "<td align=center>/</td><td><small>%10</small></td></tr>")
85     .arg(tr("Daemon Statistics"))
86     .arg(tr("Up since"))
87     .arg(utime.toString())
88     .arg(tr("Last reset"))
89     .arg(reset.toString())
90     .arg(tr("Number of users"))
91     .arg(Licq::gUserManager.NumUsers())
92     .arg(tr("Event Statistics"))
93     .arg(tr("Today"))
94     .arg(tr("Total"));
95 
96   for (int i = 0; i < Licq::Statistics::NumCounters; ++i)
97   {
98     text += QString(
99         "<tr>"
100         "<td>%1</td>"
101         "<td align=right>%2</td>"
102         "<td align=center>/</td>"
103         "<td align=left>%3</td>"
104         "</tr>")
105       .arg(Licq::gStatistics.name(i).c_str())
106       .arg(Licq::gStatistics.get(i, true))
107       .arg(Licq::gStatistics.get(i, false));
108   }
109 
110   text += "</table>";
111 
112   stats->setText(text);
113 }
114 
reset()115 void StatsDlg::reset()
116 {
117   if (QueryYesNo(this, tr("Do you really want to\nreset your statistics?")))
118   {
119     Licq::gStatistics.reset();
120     prepare();
121   }
122 }
123