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: messagelog.cpp 797 2006-05-09 04:42:35Z 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 <QTreeWidget> 00034 #include <QHeaderView> 00035 #include <QShowEvent> 00036 #include <control/logevent.h> 00037 00038 #include "logtreeitem.h" 00039 00040 00041 class LogTreeWidget : public QTreeWidget 00042 { 00043 Q_OBJECT 00044 00045 public: 00046 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 00058 /** Returns a list of all currently selected items. */ 00059 QList<LogTreeItem *> selectedMessages(); 00060 /** Returns a list of all selected items as a formatted string. */ 00061 QString selectedMessagesText(); 00062 /** Returns a list of all items in the tree. */ 00063 QList<LogTreeItem *> allMessages(); 00064 /** Deselects all currently selected items. */ 00065 void deselectAll(); 00066 00067 /** Returns the number of items currently in the tree. */ 00068 int messageCount(); 00069 /** Sets the maximum number of items in the tree. */ 00070 void setMaximumMessageCount(int max); 00071 /** Filters the log according to the specified filter. */ 00072 void filter(uint filter); 00073 00074 /** Adds a log item to the tree. */ 00075 LogTreeItem* log(LogEvent::Severity type, QString message); 00076 00077 /** Searches the log for entries that contain the given text. */ 00078 QList<LogTreeItem *> find(QString text, bool highlight = true); 00079 00080 /** Adjusts the message column, for long messages. */ 00081 void adjustMessageColumn(); 00082 00083 public slots: 00084 /** Clears all contents on the message log and resets the counter. */ 00085 void clearMessages(); 00086 00087 protected: 00088 /** Sets the default, initial column header widths. */ 00089 void showEvent(QShowEvent *event); 00090 00091 private slots: 00092 /** Called when the user moves the vertical scroll bar. */ 00093 void onVerticalScroll(int value); 00094 00095 private: 00096 /** Adds a message log item. */ 00097 void addMessageItem(LogTreeItem *item); 00098 /** Casts a QList of one pointer type to another. */ 00099 QList<LogTreeItem *> qlist_cast(QList<QTreeWidgetItem *> inlist); 00100 /** Sortrs a QList of pointers to tree items. */ 00101 QList<LogTreeItem *> qlist_sort(QList<LogTreeItem *> inlist); 00102 00103 int _maxItemCount; /**< Maximum number of items in the tree. */ 00104 bool _scrollOnNewItem; /**< Set to true if we are to scroll to the new item 00105 after adding a message to the log. */ 00106 }; 00107 00108 #endif 00109