BridgeUsageDialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "BridgeUsageDialog.h"
00019 #include "CountryInfo.h"
00020
00021 #include <QHeaderView>
00022 #include <QTreeWidgetItem>
00023 #include <QPixmap>
00024
00025
00026 BridgeUsageDialog::BridgeUsageDialog(QWidget *parent)
00027 : QDialog(parent)
00028 {
00029 ui.setupUi(this);
00030 ui.treeClientSummary->setHeaderLabels(QStringList() << QString("")
00031 << tr("Country")
00032 << tr("# Clients"));
00033 }
00034
00035 void
00036 BridgeUsageDialog::showEvent(QShowEvent *e)
00037 {
00038 QHeaderView *header = ui.treeClientSummary->header();
00039 header->setResizeMode(0, QHeaderView::ResizeToContents);
00040 header->resizeSection(1, 220);
00041 header->setResizeMode(2, QHeaderView::ResizeToContents);
00042
00043 QDialog::showEvent(e);
00044 }
00045
00046 void
00047 BridgeUsageDialog::update(const QDateTime &timeStarted,
00048 const QHash<QString,int> &countrySummary)
00049 {
00050 QTreeWidgetItem *item;
00051 int minClients, maxClients;
00052 QString countryName;
00053 QPixmap flag;
00054
00055
00056 ui.lblClientSummary->setText(tr("Clients from the following countries have "
00057 "used your relay since %1")
00058 .arg(timeStarted.toLocalTime().toString()));
00059
00060
00061 foreach (QString countryCode, countrySummary.keys()) {
00062 maxClients = countrySummary.value(countryCode);
00063 minClients = maxClients-7;
00064
00065 flag = QPixmap(":/images/flags/" + countryCode.toLower() + ".png");
00066 if (flag.isNull())
00067 flag = QPixmap(":/images/flags/unknown.png");
00068
00069 countryName = CountryInfo::countryName(countryCode);
00070 if (countryName.isEmpty())
00071 countryName = countryCode;
00072
00073 item = new QTreeWidgetItem();
00074 item->setIcon(0, QIcon(flag));
00075 item->setText(1, countryName);
00076 item->setText(2, QString("%1-%2").arg(minClients).arg(maxClients));
00077 ui.treeClientSummary->addTopLevelItem(item);
00078 }
00079 ui.treeClientSummary->sortItems(2, Qt::DescendingOrder);
00080 }
00081