~ubuntu-branches/ubuntu/saucy/mumble/saucy

« back to all changes in this revision

Viewing changes to .pc/10-use-celt-guard/src/mumble/UserInformation.cpp

  • Committer: Package Import Robot
  • Author(s): Ron Lee
  • Date: 2012-06-04 03:56:35 UTC
  • mfrom: (1.4.9)
  • Revision ID: package-import@ubuntu.com-20120604035635-4m4pqnh80i1i30yw
Tags: 1.2.3-349-g315b5f5-1
* Adopt the package.  Closes: #674719
* Drop the dependency on the celt package.  Closes: #674650
* Add the upstream patch to enable opus support.
* Explicitly disable the bundled libs, don't rely on system lib detection
  doing that as a side-effect.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
 
2
 
 
3
   All rights reserved.
 
4
 
 
5
   Redistribution and use in source and binary forms, with or without
 
6
   modification, are permitted provided that the following conditions
 
7
   are met:
 
8
 
 
9
   - Redistributions of source code must retain the above copyright notice,
 
10
     this list of conditions and the following disclaimer.
 
11
   - Redistributions in binary form must reproduce the above copyright notice,
 
12
     this list of conditions and the following disclaimer in the documentation
 
13
     and/or other materials provided with the distribution.
 
14
   - Neither the name of the Mumble Developers nor the names of its
 
15
     contributors may be used to endorse or promote products derived from this
 
16
     software without specific prior written permission.
 
17
 
 
18
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
 
22
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
25
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
26
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
27
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
28
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
*/
 
30
 
 
31
#include "mumble_pch.hpp"
 
32
 
 
33
#include "UserInformation.h"
 
34
 
 
35
#include "Audio.h"
 
36
#include "Global.h"
 
37
#include "Net.h"
 
38
#include "ServerHandler.h"
 
39
#include "ViewCert.h"
 
40
 
 
41
static QString decode_utf8_qssl_string(const QString &input) {
 
42
        QString i = input;
 
43
        return QUrl::fromPercentEncoding(i.replace(QLatin1String("\\x"), QLatin1String("%")).toLatin1());
 
44
}
 
45
 
 
46
UserInformation::UserInformation(const MumbleProto::UserStats &msg, QWidget *p) : QDialog(p) {
 
47
        setupUi(this);
 
48
 
 
49
        uiSession = msg.session();
 
50
 
 
51
        qtTimer = new QTimer(this);
 
52
        connect(qtTimer, SIGNAL(timeout()), this, SLOT(tick()));
 
53
        qtTimer->start(6000);
 
54
 
 
55
        qgbConnection->setVisible(false);
 
56
 
 
57
        qlOpus->setText(tr("Not Reported"));
 
58
 
 
59
        update(msg);
 
60
        resize(sizeHint());
 
61
 
 
62
        qfCertificateFont = qlCertificate->font();
 
63
}
 
64
 
 
65
unsigned int UserInformation::session() const {
 
66
        return uiSession;
 
67
}
 
68
 
 
69
void UserInformation::tick() {
 
70
        if (bRequested)
 
71
                return;
 
72
 
 
73
        bRequested = true;
 
74
 
 
75
        g.sh->requestUserStats(uiSession, true);
 
76
}
 
77
 
 
78
void UserInformation::on_qpbCertificate_clicked() {
 
79
        ViewCert *vc = new ViewCert(qlCerts, this);
 
80
        vc->setWindowModality(Qt::WindowModal);
 
81
        vc->setAttribute(Qt::WA_DeleteOnClose, true);
 
82
        vc->show();
 
83
}
 
84
 
 
85
QString UserInformation::secsToString(unsigned int secs) {
 
86
        QStringList qsl;
 
87
 
 
88
        int weeks = secs / (60 * 60 * 24 * 7);
 
89
        secs = secs % (60 * 60 * 24 * 7);
 
90
        int days = secs / (60 * 60 * 24);
 
91
        secs = secs % (60 * 60 * 24);
 
92
        int hours = secs / (60 * 60);
 
93
        secs = secs % (60 * 60);
 
94
        int minutes = secs / 60;
 
95
        int seconds = secs % 60;
 
96
 
 
97
        if (weeks)
 
98
                qsl << tr("%1w").arg(weeks);
 
99
        if (days)
 
100
                qsl << tr("%1d").arg(days);
 
101
        if (hours)
 
102
                qsl << tr("%1h").arg(hours);
 
103
        if (minutes || hours)
 
104
                qsl << tr("%1m").arg(minutes);
 
105
        qsl << tr("%1s").arg(seconds);
 
106
 
 
107
        return qsl.join(QLatin1String(" "));
 
108
}
 
109
 
 
110
void UserInformation::update(const MumbleProto::UserStats &msg) {
 
111
        bRequested = false;
 
112
 
 
113
        bool showcon = false;
 
114
 
 
115
        ClientUser *cu = ClientUser::get(uiSession);
 
116
        if (cu)
 
117
                setWindowTitle(cu->qsName);
 
118
 
 
119
        if (msg.certificates_size() > 0) {
 
120
                showcon = true;
 
121
                qlCerts.clear();
 
122
                for (int i=0;i<msg.certificates_size(); ++i) {
 
123
                        const std::string &s = msg.certificates(i);
 
124
                        QList<QSslCertificate> certs = QSslCertificate::fromData(QByteArray(s.data(), s.length()), QSsl::Der);
 
125
                        qlCerts <<certs;
 
126
                }
 
127
                if (! qlCerts.isEmpty()) {
 
128
                        qpbCertificate->setEnabled(true);
 
129
 
 
130
                        const QSslCertificate &cert = qlCerts.last();
 
131
                        const QMultiMap<QSsl::AlternateNameEntryType, QString> &alts = cert.alternateSubjectNames();
 
132
 
 
133
                        if (alts.contains(QSsl::EmailEntry))
 
134
                                qlCertificate->setText(QStringList(alts.values(QSsl::EmailEntry)).join(tr(", ")));
 
135
                        else
 
136
                                qlCertificate->setText(decode_utf8_qssl_string(cert.subjectInfo(QSslCertificate::CommonName)));
 
137
 
 
138
                        if (msg.strong_certificate()) {
 
139
                                QFont f = qfCertificateFont;
 
140
                                f.setBold(true);
 
141
                                qlCertificate->setFont(f);
 
142
                        } else {
 
143
                                qlCertificate->setFont(qfCertificateFont);
 
144
                        }
 
145
                } else {
 
146
                        qpbCertificate->setEnabled(false);
 
147
                        qlCertificate->setText(QString());
 
148
                }
 
149
        }
 
150
        if (msg.has_address()) {
 
151
                showcon = true;
 
152
                HostAddress ha(msg.address());
 
153
                qlAddress->setText(ha.toString());
 
154
        }
 
155
        if (msg.has_version()) {
 
156
                showcon = true;
 
157
 
 
158
                const MumbleProto::Version &mpv = msg.version();
 
159
 
 
160
                qlVersion->setText(tr("%1 (%2)").arg(MumbleVersion::toString(mpv.version())).arg(u8(mpv.release())));
 
161
                qlOS->setText(tr("%1 (%2)").arg(u8(mpv.os())).arg(u8(mpv.os_version())));
 
162
        }
 
163
        if (msg.celt_versions_size() > 0) {
 
164
                QStringList qsl;
 
165
                for (int i=0;i<msg.celt_versions_size(); ++i) {
 
166
                        int v = msg.celt_versions(i);
 
167
                        CELTCodec *cc = g.qmCodecs.value(v);
 
168
                        if (cc)
 
169
                                qsl << cc->version();
 
170
                        else
 
171
                                qsl << QString::number(v, 16);
 
172
                }
 
173
                qlCELT->setText(qsl.join(tr(", ")));
 
174
        }
 
175
        if (msg.has_opus()) {
 
176
                qlOpus->setText(msg.opus() ? tr("Supported") : tr("Not Supported"));
 
177
        }
 
178
        if (showcon)
 
179
                qgbConnection->setVisible(true);
 
180
 
 
181
        qlTCPCount->setText(QString::number(msg.tcp_packets()));
 
182
        qlUDPCount->setText(QString::number(msg.udp_packets()));
 
183
 
 
184
        qlTCPAvg->setText(QString::number(msg.tcp_ping_avg(), 'f', 2));
 
185
        qlUDPAvg->setText(QString::number(msg.udp_ping_avg(), 'f', 2));
 
186
 
 
187
        qlTCPVar->setText(QString::number(msg.tcp_ping_var() > 0.0f ? sqrtf(msg.tcp_ping_var()) : 0.0f, 'f', 2));
 
188
        qlUDPVar->setText(QString::number(msg.udp_ping_var() > 0.0f ? sqrtf(msg.udp_ping_var()) : 0.0f, 'f', 2));
 
189
 
 
190
        if (msg.has_from_client() && msg.has_from_server()) {
 
191
                qgbUDP->setVisible(true);
 
192
                const MumbleProto::UserStats_Stats &from = msg.from_client();
 
193
                qlFromGood->setText(QString::number(from.good()));
 
194
                qlFromLate->setText(QString::number(from.late()));
 
195
                qlFromLost->setText(QString::number(from.lost()));
 
196
                qlFromResync->setText(QString::number(from.resync()));
 
197
 
 
198
                const MumbleProto::UserStats_Stats &to = msg.from_server();
 
199
                qlToGood->setText(QString::number(to.good()));
 
200
                qlToLate->setText(QString::number(to.late()));
 
201
                qlToLost->setText(QString::number(to.lost()));
 
202
                qlToResync->setText(QString::number(to.resync()));
 
203
 
 
204
                quint32 allFromPackets = from.good() + from.late() + from.lost();
 
205
                qlFromLatePercent->setText(QString::number(allFromPackets > 0 ? from.late() * 100.0f / allFromPackets : 0.f, 'f', 2));
 
206
                qlFromLostPercent->setText(QString::number(allFromPackets > 0 ? from.lost() * 100.0f / allFromPackets : 0.f, 'f', 2));
 
207
 
 
208
                quint32 allToPackets = to.good() + to.late() + to.lost();
 
209
                qlToLatePercent->setText(QString::number(allToPackets > 0 ? to.late() * 100.0f / allToPackets : 0.f, 'f', 2));
 
210
                qlToLostPercent->setText(QString::number(allToPackets > 0 ? to.lost() * 100.0f / allToPackets : 0.f, 'f', 2));
 
211
        } else {
 
212
                qgbUDP->setVisible(false);
 
213
        }
 
214
 
 
215
        if (msg.has_onlinesecs()) {
 
216
                if (msg.has_idlesecs())
 
217
                        qlTime->setText(tr("%1 online (%2 idle)").arg(secsToString(msg.onlinesecs()), secsToString(msg.idlesecs())));
 
218
                else
 
219
                        qlTime->setText(tr("%1 online").arg(secsToString(msg.onlinesecs())));
 
220
        }
 
221
        if (msg.has_bandwidth()) {
 
222
                qlBandwidth->setVisible(true);
 
223
                qliBandwidth->setVisible(true);
 
224
                qlBandwidth->setText(tr("%1 kbit/s").arg(msg.bandwidth() / 125.0f, 0, 'f', 1));
 
225
        } else {
 
226
                qlBandwidth->setVisible(false);
 
227
                qliBandwidth->setVisible(false);
 
228
                qlBandwidth->setText(QString());
 
229
        }
 
230
}