Commit 87895494 authored by Matt Edman's avatar Matt Edman
Browse files

Start cleaning up messagelog.cpp. More work remains, but it's late and I want

to check this stuff in and go home.


svn:r811
parent 9eaef37a
Loading
Loading
Loading
Loading
+9 −2
Changes for src/gui/log/log.pri: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@

FORMS += $$PWD/messagelog.ui

HEADERS += $$PWD/messagelog.h
HEADERS += $$PWD/messagelog.h \
           $$PWD/logheaderview.h \
           $$PWD/logtreewidget.h \
           $$PWD/logtreeitem.h

SOURCES += $$PWD/messagelog.cpp \
           $$PWD/logheaderview.cpp \
           $$PWD/logtreewidget.cpp \
           $$PWD/logtreeitem.cpp
SOURCES += $$PWD/messagelog.cpp
+48 −0
Changes for src/gui/log/logheaderview.cpp: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
/****************************************************************
 *  Vidalia is distributed under the following license:
 *
 *  Copyright (C) 2006,  Matt Edman, Justin Hipple
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 *  Boston, MA  02110-1301, USA.
 ****************************************************************/

/** 
 * \file logheaderview.cpp
 * \version $Id: messagelog.cpp 797 2006-05-09 04:42:35Z edmanm $ 
 */

#include "logheaderview.h"
#include "logtreewidget.h"

/* Column indices */
#define COL_TIME  LogTreeWidget::TimeColumn
#define COL_TYPE  LogTreeWidget::TypeColumn

/* Default column widths */
#define COL_TIME_WIDTH    135
#define COL_TYPE_WIDTH    70


/** Default constructor. */
LogHeaderView::LogHeaderView(QWidget *parent)
: QHeaderView(Qt::Horizontal, parent)
{
  resizeSection(COL_TIME, COL_TIME_WIDTH);
  resizeSection(COL_TYPE, COL_TYPE_WIDTH);

  setStretchLastSection(true);
}
+41 −0
Changes for src/gui/log/logheaderview.h: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
/****************************************************************
 *  Vidalia is distributed under the following license:
 *
 *  Copyright (C) 2006,  Matt Edman, Justin Hipple
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 *  Boston, MA  02110-1301, USA.
 ****************************************************************/

/** 
 * \file logheaderview.h
 * \version $Id: messagelog.cpp 797 2006-05-09 04:42:35Z edmanm $ 
 */

#ifndef _LOGHEADERVIEW_H
#define _LOGHEADERVIEW_H

#include <QHeaderView>


class LogHeaderView : public QHeaderView
{
public:
  /** Default constructor. */
  LogHeaderView(QWidget *parent);
};

#endif
+128 −0
Changes for src/gui/log/logtreeitem.cpp: 128 added lines, 0 removed lines.
Original line number Diff line number Diff line
/****************************************************************
 *  Vidalia is distributed under the following license:
 *
 *  Copyright (C) 2006,  Matt Edman, Justin Hipple
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 *  Boston, MA  02110-1301, USA.
 ****************************************************************/

/** 
 * \file logtreeitem.cpp
 * \version $Id: messagelog.cpp 797 2006-05-09 04:42:35Z edmanm $ 
 */

#include "logtreeitem.h"
#include "logtreewidget.h"

/** Defines the format used for displaying the date and time of a log message.*/
#define DATETIME_FMT  "MMM dd hh:mm:ss:zzz"

/* Column index values */
#define COL_TIME    LogTreeWidget::TimeColumn
#define COL_TYPE    LogTreeWidget::TypeColumn
#define COL_MESG    LogTreeWidget::MessageColumn
#define ROLE_TYPE   Qt::UserRole


/** Default constructor. */
LogTreeItem::LogTreeItem(LogEvent::Severity type, QString message, 
                         QDateTime timestamp)
{
  /* Set the item's log time */
  setTimestamp(timestamp);

  /* Set the item's severity and appropriate color. */
  setSeverity(type);

  /* Set the item's message text. */
  setMessage(message);
}

/** Returns a printable string representing the fields of this item. */
QString
LogTreeItem::toString()
{
  return QString("%1 [%2] %3\n").arg(text(COL_TIME))
                                .arg(text(COL_TYPE))
                                .arg(text(COL_MESG).trimmed());
}

/** Sets the item's log time. */
void
LogTreeItem::setTimestamp(QDateTime timestamp)
{
  setText(COL_TIME, timestamp.toString(DATETIME_FMT));
}

/** Sets the item's severity and the appropriate background color. */
void
LogTreeItem::setSeverity(LogEvent::Severity type)
{
  /* Change row and text color for serious warnings and errors. */
  if (type == LogEvent::TorError) {
    /* Critical messages are red with white text. */
    for (int i = 0; i < 3; i++) {
      setBackgroundColor(i, Qt::red);
      setTextColor(i, Qt::white);
    }
  } else if (type == LogEvent::TorWarn) {
    /* Warning messages are yellow with black text. */
    for (int i = 0; i < 3; i++) {
      setBackgroundColor(i, Qt::yellow);
    }
  }
  
  setTextAlignment(COL_TYPE, Qt::AlignCenter);
  setText(COL_TYPE, LogEvent::severityToString(type));
  setData(COL_TYPE, ROLE_TYPE, (uint)type);
}

/** Sets the item's message text. */
void
LogTreeItem::setMessage(QString message)
{
  setText(COL_MESG, message);
}

/** Returns the severity associated with this log item. */
LogEvent::Severity
LogTreeItem::severity()
{
  return (LogEvent::Severity)data(COL_TYPE, ROLE_TYPE).toUInt();
}

/** Returns the timestamp for this log message. */
QDateTime
LogTreeItem::timestamp() const
{
  return QDateTime::fromString(text(COL_TIME), DATETIME_FMT);
}

/** Returns the message for this log item. */
QString
LogTreeItem::message()
{
  return text(COL_MESG);
}

/** Overloaded comparison operator. */
bool
LogTreeItem::operator<(const LogTreeItem &other) const
{
  /* Comparison is based on the message timestamps. */
  return (timestamp() < other.timestamp());
}
+65 −0
Changes for src/gui/log/logtreeitem.h: 65 added lines, 0 removed lines.
Original line number Diff line number Diff line
/****************************************************************
 *  Vidalia is distributed under the following license:
 *
 *  Copyright (C) 2006,  Matt Edman, Justin Hipple
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 *  Boston, MA  02110-1301, USA.
 ****************************************************************/

/** 
 * \file logtreeitem.h
 * \version $Id: messagelog.cpp 797 2006-05-09 04:42:35Z edmanm $ 
 */

#ifndef _LOGTREEITEM_H
#define _LOGTREEITEM_H

#include <QTreeWidgetItem>
#include <QDateTime>
#include <QString>
#include <control/logevent.h>


class LogTreeItem : public QTreeWidgetItem
{
public:
  /** Default constructor. */
  LogTreeItem(LogEvent::Severity type, QString message, 
              QDateTime timestamp = QDateTime::currentDateTime());

  /** Sets the item's log time. */
  void setTimestamp(QDateTime timestamp);
  /** Sets the item's severity and appropriate background color. */
  void setSeverity(LogEvent::Severity type);
  /** Sets the item's message text. */
  void setMessage(QString message);

  /** Returns the timestamp for this log message. */
  QDateTime timestamp() const;
  /** Returns the severity associated with this log item. */
  LogEvent::Severity severity();
  /** Returns the message associated with this log item. */
  QString message();

  /** Overloaded comparison operator. */
  virtual bool operator<(const LogTreeItem &other) const;
  
  /** Returns a printable string representation of the item's contents.*/
  QString toString();
};

#endif
Loading