Vidalia  0.3.1
RouterInfoDialog.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 RouterInfoDialog.cpp
13 ** \brief Displays detailed information about a particular router
14 */
15 
16 #include "RouterInfoDialog.h"
17 
18 #include "stringutil.h"
19 
20 
22  : QDialog(parent)
23 {
24  ui.setupUi(this);
25 }
26 
27 quint64
28 RouterInfoDialog::adjustUptime(quint64 uptime, const QDateTime &published)
29 {
30  QDateTime now = QDateTime::currentDateTime().toUTC();
31 
32  if (now < published)
33  return uptime;
34 
35  return (uptime + (now.toTime_t() - published.toTime_t()));
36 }
37 
38 void
39 RouterInfoDialog::setRouterInfo(const QStringList &desc,
40  const RouterStatus &status)
41 {
42  RouterDescriptor rd(desc);
43 
44  ui.lblName->setText(rd.name());
45  ui.lblIPAddress->setText(rd.ip().toString());
46  ui.lblPlatform->setText(rd.platform());
47  ui.lblBandwidth->setText(string_format_bandwidth(rd.observedBandwidth()));
48  ui.lblLastUpdated->setText(string_format_datetime(rd.published()) + " GMT");
49  ui.lblUptime->setText(string_format_uptime(adjustUptime(rd.uptime(),
50  rd.published())));
51 
52  if (rd.hibernating()) {
53  ui.lblStatus->setText(tr("Hibernating"));
54  } else if (status.isValid()) {
55  if (status.flags() & RouterStatus::Running)
56  ui.lblStatus->setText(tr("Online"));
57  else
58  ui.lblStatus->setText(tr("Offline"));
59  } else {
60  ui.lblStatus->setText(tr("Unknown"));
61  }
62 
63  if (! rd.contact().isEmpty()) {
64  ui.lblContact->setText(rd.contact());
65  } else {
66  ui.lblContact->setVisible(false);
67  ui.lblContactLabel->setVisible(false);
68  }
69 
70  ui.textDescriptor->setPlainText(desc.join("\n"));
71 }
72 
73 void
74 RouterInfoDialog::setLocation(const QString &location)
75 {
76  ui.lblLocation->setText(location);
77 }
78