logview.h

00001
00002 /***************************************************************************
00003  *  logview.h - Fawkes log view widget
00004  *
00005  *  Created: Mon Nov 02 13:08:29 2008
00006  *  Copyright  2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __LIBS_GUI_UTILS_LOGVIEW_H_
00025 #define __LIBS_GUI_UTILS_LOGVIEW_H_
00026 
00027 #include <gtkmm.h>
00028 #include <libglademm/xml.h>
00029
00030 #include <utils/logging/logger.h>
00031
00032 namespace fawkes {
00033 #if 0 /* just to make Emacs auto-indent happy */
00034 }
00035 #endif
00036 
00037 class FawkesNetworkClient;
00038 class FawkesNetworkMessage;
00039 class ConnectionDispatcher;
00040
00041 class LogView
00042   : public Gtk::TreeView
00043 {
00044  public:
00045   LogView();
00046   LogView(const char *hostname, unsigned short int port);
00047   LogView(BaseObjectType* cobject,
00048           const Glib::RefPtr<Gnome::Glade::Xml>& ref_glade);
00049   ~LogView();
00050
00051   void set_client(FawkesNetworkClient *client);
00052   FawkesNetworkClient *  get_client();
00053
00054   void append_message(Logger::LogLevel log_level, struct timeval t,
00055                       const char *component, bool is_exception,
00056                       const char *message);
00057
00058   void clear();
00059
00060   ConnectionDispatcher *  get_connection_dispatcher() const;
00061
00062  private:
00063   virtual void on_row_inserted(const Gtk::TreeModel::Path& path,
00064                                const Gtk::TreeModel::iterator& iter);
00065   virtual void on_message_received(FawkesNetworkMessage *msg);
00066   virtual void on_client_connected();
00067   virtual void on_client_disconnected();
00068   virtual void on_expose_notify(GdkEventExpose *event);
00069
00070   void ctor(const char *hostname = NULL, unsigned short int port = 0);
00071
00072  private:
00073   class LogRecord : public Gtk::TreeModelColumnRecord
00074   {
00075    public:
00076     LogRecord();
00077     Gtk::TreeModelColumn<Glib::ustring> loglevel;
00078     Gtk::TreeModelColumn<Glib::ustring> time;
00079     Gtk::TreeModelColumn<Glib::ustring> component;
00080     Gtk::TreeModelColumn<Glib::ustring> message;
00081     Gtk::TreeModelColumn<Gdk::Color>    foreground;
00082     Gtk::TreeModelColumn<Gdk::Color>    background;
00083   };
00084
00085   LogRecord __record;
00086
00087   Glib::RefPtr<Gtk::ListStore> __list;
00088
00089   ConnectionDispatcher *__connection_dispatcher;
00090   FawkesNetworkClient  *__client;
00091
00092   bool                  __have_recently_added_path;
00093   Gtk::TreeModel::Path  __recently_added_path;
00094 };
00095
00096 } // end namespace fawkes
00097
00098
00099 #endif