Commit 02e3e21f authored by Matt Edman's avatar Matt Edman
Browse files

Add methods to Circuit and Stream, to turn a status value into a more

user-friendly status string.


svn:r869
parent dbb27bf6
Loading
Loading
Loading
Loading
+16 −0
Changes for src/control/circuit.cpp: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -91,6 +91,22 @@ Circuit::toStatus(QString strStatus)
  return status;
}

/** Returns a string representation of the circuit's status. */
QString
Circuit::statusString()
{
  QString status;
  switch (_status) {
    case Launched:    status = tr("New"); break;
    case Built:       status = tr("Open"); break;
    case Extended:    status = tr("Building"); break;
    case Failed:      status = tr("Failed");  break;
    case Closed:      status = tr("Closed"); break;
    default:          status = tr("Unknown"); break;
  }
  return status;
}

/** Returns true if all fields in this Circuit object are empty. */
bool
Circuit::isEmpty()
+5 −0
Changes for src/control/circuit.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -27,11 +27,14 @@
#ifndef _CIRCUIT_H
#define _CIRCUIT_H

#include <QCoreApplication>
#include <QString>


class Circuit
{
  Q_DECLARE_TR_FUNCTIONS(Circuit)

public:
  /** Circuit status events */
  enum Status {
@@ -60,6 +63,8 @@ public:
  quint64 id() { return _circId; }
  /** Returns the status of this circuit */
  Status status() { return _status; }
  /** Returns a string representation of the status of this circuit. */
  QString statusString();
  /** Returns the path chosen for this circuit */
  QString path() { return _path; }
  
+20 −0
Changes for src/control/stream.cpp: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -99,6 +99,26 @@ Stream::toStatus(QString strStatus)
  return status;
}

/** Returns a human-understandable string representation of this 
 * stream's status. */
QString
Stream::statusString()
{
  QString status;
  switch (_status) {
    case New:           status = tr("New"); break;
    case NewResolve:    
    case SentResolve:   status = tr("Resolving"); break;
    case SentConnect:   status = tr("Connecting"); break;
    case Succeeded:     status = tr("Open"); break;
    case Failed:        status = tr("Failed"); break;
    case Closed:        status = tr("Closed"); break;
    case Detached:      status = tr("Detached"); break;
    default:            status = tr("Unknown"); break;
  }
  return status;
}

/** Returns true if all fields in this Stream object are empty. */
bool
Stream::isEmpty()
+10 −5
Changes for src/control/stream.h: 10 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -27,11 +27,14 @@
#ifndef _STREAM_H
#define _STREAM_H

#include <QCoreApplication>
#include <QString>

#include <QObject>

class Stream
{
  Q_DECLARE_TR_FUNCTIONS(Stream)

public:
  /** Stream status values */
  enum Status {
@@ -59,13 +62,15 @@ public:
  /** Returns true if the Stream object's fields are all empty. */
  bool isEmpty();
  
  /** Returns the ID for this stream */
  /** Returns the ID for this stream. */
  quint64 id() { return _streamId; }
  /** Returns the status for this stream */
  /** Returns the status for this stream. */
  Status status() { return _status; }
  /** Returns the ID of the circuit to which this stream is assigned */
  /** Returns a string representation of this stream's status. */
  QString statusString();
  /** Returns the ID of the circuit to which this stream is assigned. */
  quint64 circuitId() { return _circuitId; }
  /** Returns the target for this stream */
  /** Returns the target for this stream. */
  QString target() { return _target; }
  
private: