00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file logtreewidget.h 00024 * \version $Id: logtreewidget.h 1563 2006-12-26 06:06:04Z edmanm $ 00025 * \brief Contains a collection of log messages as LogTreeItems 00026 */ 00027 00028 #ifndef _LOGTREEWIDGET_H 00029 #define _LOGTREEWIDGET_H 00030 00031 #include <QList> 00032 #include <QString> 00033 #include <QStringList> 00034 #include <QTreeWidget> 00035 #include <QHeaderView> 00036 #include <QShowEvent> 00037 #include <control/logevent.h> 00038 00039 #include "logtreeitem.h" 00040 00041 00042 class LogTreeWidget : public QTreeWidget 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 /** Log tree column indices. */ 00048 enum LogColumns { 00049 TimeColumn = 0, /**< Timestamp column. */ 00050 TypeColumn = 1, /**< Message severity type column. */ 00051 MessageColumn = 2 /**< Message text column. */ 00052 }; 00053 00054 /** Default constructor. */ 00055 LogTreeWidget(QWidget *parent = 0); 00056 00057 /** Returns a list of all currently selected messages. */ 00058 QStringList selectedMessages(); 00059 /** Returns a list of all messages in the tree. */ 00060 QStringList allMessages(); 00061 /** Deselects all currently selected messages. */ 00062 void deselectAll(); 00063 00064 /** Returns the number of items currently in the tree. */ 00065 int messageCount(); 00066 /** Sets the maximum number of items in the tree. */ 00067 void setMaximumMessageCount(int max); 00068 /** Filters the log according to the specified filter. */ 00069 void filter(uint filter); 00070 00071 /** Adds a log item to the tree. */ 00072 LogTreeItem* log(LogEvent::Severity type, QString message); 00073 00074 /** Searches the log for entries that contain the given text. */ 00075 QList<LogTreeItem *> find(QString text, bool highlight = true); 00076 00077 /** Adjusts the message column, for long messages. */ 00078 void adjustMessageColumn(); 00079 00080 public slots: 00081 /** Clears all contents on the message log and resets the counter. */ 00082 void clearMessages(); 00083 00084 protected: 00085 /** Sets the default, initial column header widths. */ 00086 void showEvent(QShowEvent *event); 00087 00088 private slots: 00089 /** Called when the user moves the vertical scroll bar. */ 00090 void onVerticalScroll(int value); 00091 00092 private: 00093 /** Adds a message log item. */ 00094 void addMessageItem(LogTreeItem *item); 00095 /** Casts a QList of one pointer type to another. */ 00096 QList<LogTreeItem *> qlist_cast(QList<QTreeWidgetItem *> inlist); 00097 /** Sortrs a QList of pointers to tree items. */ 00098 QList<LogTreeItem *> qlist_sort(QList<LogTreeItem *> inlist); 00099 00100 int _maxItemCount; /**< Maximum number of items in the tree. */ 00101 bool _scrollOnNewItem; /**< Set to true if we are to scroll to the new item 00102 after adding a message to the log. */ 00103 }; 00104 00105 #endif 00106