Fawkes API  Fawkes Development Version
logview.h
1 
2 /***************************************************************************
3  * logview.h - Fawkes log view widget
4  *
5  * Created: Mon Nov 02 13:08:29 2008
6  * Copyright 2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __LIBS_GUI_UTILS_LOGVIEW_H_
25 #define __LIBS_GUI_UTILS_LOGVIEW_H_
26 
27 #include <gtkmm.h>
28 
29 #include <logging/logger.h>
30 
31 namespace fawkes {
32 #if 0 /* just to make Emacs auto-indent happy */
33 }
34 #endif
35 
36 class FawkesNetworkClient;
37 class FawkesNetworkMessage;
38 class ConnectionDispatcher;
39 
40 class LogView
41  : public Gtk::TreeView
42 {
43  public:
44  LogView();
45  LogView(const char *hostname, unsigned short int port);
46  LogView(BaseObjectType* cobject,
47  const Glib::RefPtr<Gtk::Builder> &builder);
48  ~LogView();
49 
50  void set_client(FawkesNetworkClient *client);
52 
53  void append_message(Logger::LogLevel log_level, struct timeval t,
54  const char *component, bool is_exception,
55  const char *message);
56 
57  void clear();
58 
60 
61  private:
62  virtual void on_row_inserted(const Gtk::TreeModel::Path& path,
63  const Gtk::TreeModel::iterator& iter);
64  virtual void on_message_received(FawkesNetworkMessage *msg);
65  virtual void on_client_connected();
66  virtual void on_client_disconnected();
67 #if GTK_VERSION_GE(3,0)
68  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr);
69 #else
70  virtual void on_expose_notify(GdkEventExpose *event);
71 #endif
72 
73  void ctor(const char *hostname = NULL, unsigned short int port = 0);
74 
75  private:
76  class LogRecord : public Gtk::TreeModelColumnRecord
77  {
78  public:
79  LogRecord();
80 
81  /// @cond INTERNALS
82  Gtk::TreeModelColumn<Glib::ustring> loglevel;
83  Gtk::TreeModelColumn<Glib::ustring> time;
84  Gtk::TreeModelColumn<Glib::ustring> component;
85  Gtk::TreeModelColumn<Glib::ustring> message;
86  Gtk::TreeModelColumn<Gdk::Color> foreground;
87  Gtk::TreeModelColumn<Gdk::Color> background;
88  /// @endcond
89  };
90 
91  LogRecord __record;
92 
93  Glib::RefPtr<Gtk::ListStore> __list;
94 
95  ConnectionDispatcher *__connection_dispatcher;
96 
97  bool __have_recently_added_path;
98  Gtk::TreeModel::Path __recently_added_path;
99 };
100 
101 } // end namespace fawkes
102 
103 
104 #endif
LogLevel
Log level.
Definition: logger.h:45
Log View widget.
Definition: logview.h:40
~LogView()
Destructor.
Definition: logview.cpp:76
ConnectionDispatcher * get_connection_dispatcher() const
Get ConnectionDispatcher instance that is used internally.
Definition: logview.cpp:192
Simple Fawkes network client.
Definition: client.h:52
void clear()
Clear all records.
Definition: logview.cpp:200
FawkesNetworkClient * get_client()
Get the used FawkesNetworkClient.
Definition: logview.cpp:182
Fawkes library namespace.
LogView()
Constructor.
Definition: logview.cpp:46
Representation of a message that is sent over the network.
Definition: message.h:75
void append_message(Logger::LogLevel log_level, struct timeval t, const char *component, bool is_exception, const char *message)
Append a single message.
Definition: logview.cpp:279
void set_client(FawkesNetworkClient *client)
Set FawkesNetworkClient instance.
Definition: logview.cpp:161
Watches network client events and dispatches them as signals.