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 ** \version $Id: BridgeUsageDialog.cpp 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Displays a summary of bridge usage information, including client
00015 ** geographic location history.
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   /* Set the header with the TimeStarted value converted to local time */
00056   ui.lblClientSummary->setText(tr("Clients from the following countries have "
00057                                   "used your relay since %1")
00058                                   .arg(timeStarted.toLocalTime().toString()));
00059 
00060   /* Populate the table of client country statistics */
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 
Generated on Mon Aug 30 22:58:54 2010 for Vidalia by  doxygen 1.6.3