Vidalia 0.3.1
BridgeUsageDialog.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file BridgeUsageDialog.cpp
13** \brief Displays a summary of bridge usage information, including client
14** geographic location history.
15*/
16
17#include "BridgeUsageDialog.h"
18#include "CountryInfo.h"
19
20#include <QHeaderView>
21#include <QTreeWidgetItem>
22#include <QPixmap>
23
24
26 : QDialog(parent)
27{
28 ui.setupUi(this);
29 ui.treeClientSummary->setHeaderLabels(QStringList() << QString("")
30 << tr("Country")
31 << tr("# Clients"));
32}
33
34void
36{
37 QHeaderView *header = ui.treeClientSummary->header();
38 header->setResizeMode(0, QHeaderView::ResizeToContents);
39 header->resizeSection(1, 220);
40 header->setResizeMode(2, QHeaderView::ResizeToContents);
41
42 QDialog::showEvent(e);
43}
44
45void
46BridgeUsageDialog::update(const QDateTime &timeStarted,
47 const QHash<QString,int> &countrySummary)
48{
49 QTreeWidgetItem *item;
50 int minClients, maxClients;
51 QString countryName;
52 QPixmap flag;
53
54 /* Set the header with the TimeStarted value converted to local time */
55 ui.lblClientSummary->setText(tr("Clients from the following countries have "
56 "used your relay since %1")
57 .arg(timeStarted.toLocalTime().toString()));
58
59 /* Populate the table of client country statistics */
60 foreach (QString countryCode, countrySummary.keys()) {
61 maxClients = countrySummary.value(countryCode);
62 minClients = maxClients-7;
63
64 flag = QPixmap(":/images/flags/" + countryCode.toLower() + ".png");
65 if (flag.isNull())
66 flag = QPixmap(":/images/flags/unknown.png");
67
68 countryName = CountryInfo::countryName(countryCode);
69 if (countryName.isEmpty())
70 countryName = countryCode;
71
72 item = new QTreeWidgetItem();
73 item->setIcon(0, QIcon(flag));
74 item->setText(1, countryName);
75 item->setText(2, QString("%1-%2").arg(minClients).arg(maxClients));
76 ui.treeClientSummary->addTopLevelItem(item);
77 }
78 ui.treeClientSummary->sortItems(2, Qt::DescendingOrder);
79}
80
Ui::BridgeUsageDialog ui
void update(const QDateTime &timeStarted, const QHash< QString, int > &countrySummary)
void showEvent(QShowEvent *e)
BridgeUsageDialog(QWidget *parent=0)
static QString countryName(const QString &countryCode)
Definition: CountryInfo.cpp:34