Vidalia
0.2.17
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file CircuitItem.cpp 00013 ** \brief Item representing a Tor circuit and its status 00014 */ 00015 00016 #include "CircuitItem.h" 00017 #include "CircuitListWidget.h" 00018 00019 00020 /** Constructor */ 00021 CircuitItem::CircuitItem(const Circuit &circuit) 00022 { 00023 /* Update the displayed text */ 00024 update(circuit); 00025 } 00026 00027 /** Updates the status and path of this circuit item. */ 00028 void 00029 CircuitItem::update(const Circuit &circuit) 00030 { 00031 QString displayedPath; 00032 00033 /* Save the Circuit object */ 00034 _circuit = circuit; 00035 00036 /* Use a semi-meaningful value if the path is empty */ 00037 displayedPath = circuit.length() > 0 ? circuit.routerNames().join(",") 00038 : tr("<Path Empty>"); 00039 00040 /* Update the column fields */ 00041 setText(CircuitListWidget::ConnectionColumn, displayedPath); 00042 setToolTip(CircuitListWidget::ConnectionColumn, displayedPath); 00043 setText(CircuitListWidget::StatusColumn, circuit.statusString()); 00044 setToolTip(CircuitListWidget::StatusColumn, circuit.statusString()); 00045 } 00046 00047 /** Adds a stream as a child of this circuit. */ 00048 void 00049 CircuitItem::addStream(StreamItem *stream) 00050 { 00051 addChild(stream); 00052 } 00053 00054 /** Removes the stream item from this circuit and frees its memory */ 00055 void 00056 CircuitItem::removeStream(StreamItem *stream) 00057 { 00058 int index = indexOfChild(stream); 00059 if (index > -1) { 00060 delete takeChild(index); 00061 } 00062 } 00063 00064 /** Returns a list of all stream items on this circuit. */ 00065 QList<StreamItem *> 00066 CircuitItem::streams() const 00067 { 00068 QList<StreamItem *> streams; 00069 int n = childCount(); 00070 for (int i = 0; i < n; i++) { 00071 streams << (StreamItem *)child(i); 00072 } 00073 return streams; 00074 } 00075