Commit 7ae502c7 authored by Justin Hipple's avatar Justin Hipple
Browse files

MessageLog now is mostly functional, with Select All, Max Log Size, and Clear...

MessageLog now is mostly functional, with Select All, Max Log Size, and Clear working correctly. Message filtering is also working, but there is no way to change the types filtered just yet. It is set at the default level.

svn:r121
parent 68af9e59
Loading
Loading
Loading
Loading
+7 −5
Changes for src/gui/mainwindow.cpp: 7 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include "mainwindow.h"
#include "../util/compat.h"
#include "../config/messagetypes.h"

/* On Mac, we need to put the 128x128 icon in the dock */
#if defined(Q_WS_MAC)
@@ -49,11 +50,12 @@ MainWindow::MainWindow()
  /* Create a new MessageLog object so messages can be logged when not shown */
  _messageLog = new MessageLog(this);
  _messageLog->write(MSG_VIDERR, "This is a critical Vidalia error");
  _messageLog->write(MSG_INFO, "This is an info message");
  _messageLog->write(MSG_WARN, "This is a warning");
  _messageLog->write(MSG_TORERR, "This is a critical Tor error");
  _messageLog->write(MSG_DEBUG, "This is a debug message");
  _messageLog->write(MSG_NOTE, "This is a note");
  _messageLog->write(MSG_VIDSTAT, "This is a Vidalia status message");
  _messageLog->write(MSG_TORINFO, "This is a tor info message");
  _messageLog->write(MSG_TORWARN, "This is a tor warning");
  _messageLog->write(MSG_TORERR, "This is a critical tor error");
  _messageLog->write(MSG_TORDEBUG, "This is a tor debug message");
  _messageLog->write(MSG_TORNOTE, "This is a note");

  /* Create a new TorControl object, used to communicate with and manipulate Tor */
  _torControl = new TorControl();
+55 −3
Changes for src/gui/messagelog.cpp: 55 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -28,24 +28,70 @@ MessageLog::MessageLog(QWidget *parent, Qt::WFlags flags)
{
  ui.setupUi(this);
 
  _settings = new VidaliaSettings();
  _clock = new QDateTime(QDateTime::currentDateTime());
  
  _maxCount = _settings->getMaxMsgCount();

  _createActions();
}

/*
 Binds events to actions 
*/
void
MessageLog::_createActions()
{
  connect(ui.actionHistory_Size, SIGNAL(triggered()), 
      this, SLOT(setMaxCount()));
}

/*
 Creates a dialog that allows changing of the maxiumum
 number of message to display in the message history log.
*/
void
MessageLog::setMaxCount()
{
  bool ok_clicked = false;
  int value = 0;
  
  value = QInputDialog::getInteger(this, tr("Enter Max History Size"),
      tr("(1 - 99,999 items)"), _maxCount, 1, 99999, 1, &ok_clicked);
  
  if (ok_clicked) {
    /* if new max is smaller than number of columns then remove some */
    while (value < ui.lstMessages->topLevelItemCount()) {
      ui.lstMessages->takeTopLevelItem(0);
    }
    _settings->setMaxMsgCount(value);
    _maxCount = value;
  }
}

/*
 Writes a message to the Message History and tags it with
 the proper date, time and type.
*/
void MessageLog::write(const char* type, const char* message)
void 
MessageLog::write(const char* type, const char* message)
{
  QTreeWidgetItem *newMessage = new QTreeWidgetItem(ui.lstMessages);
  QTreeWidgetItem *newMessage = new QTreeWidgetItem();
 
  /* Remove top message if message log is at maximum setting */
  if (ui.lstMessages->topLevelItemCount() == _maxCount) {
    ui.lstMessages->takeTopLevelItem(0);
  }
  
  /* Change row color and text for serious warnings and errors */
  if (!qstrcmp(type, MSG_VIDERR) or !qstrcmp(type, MSG_TORERR)) {
    /* Critical messages are red with white text */
    for (int i=0; i < ui.lstMessages->columnCount(); i++) {
      newMessage->setBackgroundColor(i, Qt::red);
      newMessage->setTextColor(i, Qt::white);
    }
  } else if (!qstrcmp(type, MSG_WARN)) {
  } else if (!qstrcmp(type, MSG_TORWARN)) {
    /* Warning messages are yellow with black text */
    for (int i=0; i < ui.lstMessages->columnCount(); i++) {
      newMessage->setBackgroundColor(i, Qt::yellow);
    }
@@ -60,4 +106,10 @@ void MessageLog::write(const char* type, const char* message)

  /* Set Message Body */
  newMessage->setText(2, tr(message));

  /* Add the message to the bottom of the list */
  ui.lstMessages->addTopLevelItem(newMessage);

  /* Hide the message if necessary */
  ui.lstMessages->setItemHidden(newMessage, !_settings->getShowMsg(type));
}
+10 −8
Changes for src/gui/messagelog.h: 10 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -27,17 +27,11 @@
#include <QMainWindow>
#include <QTreeWidgetItem>
#include <QDateTime>
#include <QInputDialog>

#include "ui_messagelog.h"
#include "../config/vidaliasettings.h"

#define MSG_TORERR    "Tor Error"
#define MSG_WARN      "Warn"
#define MSG_NOTE      "Notice"
#define MSG_INFO      "Info"
#define MSG_DEBUG     "Debug"
#define MSG_VIDERR    "Vidalia Error"
#define MSG_VIDSTAT   "Vidalia Status"
#include "../config/messagetypes.h"

class MessageLog : public QMainWindow
{
@@ -48,9 +42,17 @@ public:
 
  void write(const char* type, const char* message);

private slots:
  void setMaxCount();

private:
  void _createActions();

  int _maxCount;
  QDateTime* _clock;

  VidaliaSettings* _settings;
    
  Ui::MessageLog ui;
};

+41 −9
Changes for src/gui/messagelog.ui: 41 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -131,6 +131,15 @@
     <height>19</height>
    </rect>
   </property>
   <widget class="QMenu" name="menu_File" >
    <property name="title" >
     <string>&amp;File</string>
    </property>
    <addaction name="actionSave_All" />
    <addaction name="actionSave_Selected" />
    <addaction name="separator" />
    <addaction name="actionClose" />
   </widget>
   <widget class="QMenu" name="menu_View" >
    <property name="title" >
     <string>&amp;View</string>
@@ -151,15 +160,6 @@
    <addaction name="actionMessage_Filters" />
    <addaction name="actionHistory_Size" />
   </widget>
   <widget class="QMenu" name="menu_File" >
    <property name="title" >
     <string>&amp;File</string>
    </property>
    <addaction name="actionSave_All" />
    <addaction name="actionSave_Selected" />
    <addaction name="separator" />
    <addaction name="actionClose" />
   </widget>
   <addaction name="menu_File" />
   <addaction name="menu_Edit" />
   <addaction name="menu_View" />
@@ -337,5 +337,37 @@
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>actionClear</sender>
   <signal>triggered()</signal>
   <receiver>lstMessages</receiver>
   <slot>clear()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>-1</x>
     <y>-1</y>
    </hint>
    <hint type="destinationlabel" >
     <x>407</x>
     <y>393</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>actionSelect_All</sender>
   <signal>triggered()</signal>
   <receiver>lstMessages</receiver>
   <slot>selectAll()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>-1</x>
     <y>-1</y>
    </hint>
    <hint type="destinationlabel" >
     <x>407</x>
     <y>393</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>