/* 
 * © 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _GRT_MESSAGE_LIST_H_
#define _GRT_MESSAGE_LIST_H_

#include "tree_model.h"
#include "refresh_ui.h"

namespace bec {

  class GRTManager;
  
  //! Backend for message's tab in Output window. To clear run popup and feed
  //! menu item's name to activate_node_popup_item.
  class WBPUBLICBACKEND_PUBLIC_FUNC MessageListBE : public ListModel, public RefreshUI
  {
  public:
    enum Column {
      Time,
      Message,
      Detail
    };

    MessageListBE(GRTManager *grtm);

    void clear();
    virtual bool get_field(const NodeId &node, int column, std::string &value);
    virtual void refresh() {}
    virtual IconId get_field_icon(const NodeId &node, int column, IconSize size);
    virtual int count();
    virtual MenuItemList get_popup_items_for_nodes(const std::vector<NodeId> &nodes);
    virtual bool activate_popup_item_for_nodes(const std::string &name, const std::vector<NodeId> &nodes);
    
    sigc::signal<void> signal_show() { return _list_show; }
    sigc::signal<void> signal_changed() { return _list_changed; }

    void handle_message(const grt::Message &msg);

  private:
    GRTManager *_grtm;
    struct MessageEntry {
      IconId icon;
      time_t timestamp;
      std::string message;
      std::string detail;
    };

    IconId _error_icon;
    IconId _warning_icon;
    IconId _info_icon;

    std::vector<MessageEntry> _entries;
    sigc::signal<void> _list_changed;
    sigc::signal<void> _list_show;

    bool _notified;
  };

};


#endif
