Vidalia 0.2.12

BridgeUsageDialog.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file BridgeUsageDialog.cpp
00013 ** \brief Displays a summary of bridge usage information, including client
00014 ** geographic location history.
00015 */
00016 
00017 #include "BridgeUsageDialog.h"
00018 #include "CountryInfo.h"
00019 
00020 #include <QHeaderView>
00021 #include <QTreeWidgetItem>
00022 #include <QPixmap>
00023 
00024 
00025 BridgeUsageDialog::BridgeUsageDialog(QWidget *parent)
00026   : QDialog(parent)
00027 {
00028   ui.setupUi(this);
00029   ui.treeClientSummary->setHeaderLabels(QStringList() << QString("")
00030                                                       << tr("Country")
00031                                                       << tr("# Clients"));
00032 }
00033 
00034 void
00035 BridgeUsageDialog::showEvent(QShowEvent *e)
00036 {
00037   QHeaderView *header = ui.treeClientSummary->header();
00038   header->setResizeMode(0, QHeaderView::ResizeToContents);
00039   header->resizeSection(1, 220);
00040   header->setResizeMode(2, QHeaderView::ResizeToContents);
00041 
00042   QDialog::showEvent(e);
00043 }
00044 
00045 void
00046 BridgeUsageDialog::update(const QDateTime &timeStarted,
00047                           const QHash<QString,int> &countrySummary)
00048 {
00049   QTreeWidgetItem *item;
00050   int minClients, maxClients;
00051   QString countryName;
00052   QPixmap flag;
00053 
00054   /* Set the header with the TimeStarted value converted to local time */
00055   ui.lblClientSummary->setText(tr("Clients from the following countries have "
00056                                   "used your relay since %1")
00057                                   .arg(timeStarted.toLocalTime().toString()));
00058 
00059   /* Populate the table of client country statistics */
00060   foreach (QString countryCode, countrySummary.keys()) {
00061     maxClients = countrySummary.value(countryCode);
00062     minClients = maxClients-7;
00063 
00064     flag = QPixmap(":/images/flags/" + countryCode.toLower() + ".png");
00065     if (flag.isNull())
00066       flag = QPixmap(":/images/flags/unknown.png");
00067 
00068     countryName = CountryInfo::countryName(countryCode);
00069     if (countryName.isEmpty())
00070       countryName = countryCode;
00071 
00072     item = new QTreeWidgetItem();
00073     item->setIcon(0, QIcon(flag));
00074     item->setText(1, countryName);
00075     item->setText(2, QString("%1-%2").arg(minClients).arg(maxClients));
00076     ui.treeClientSummary->addTopLevelItem(item);
00077   }
00078   ui.treeClientSummary->sortItems(2, Qt::DescendingOrder);
00079 }
00080