/***************************************************************************
 *   Copyright (C) 2004-2010 by Giovanni Venturi                           *
 *   giovanni@ksniffer.org                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301, USA.          *
 ***************************************************************************/

#include <KLocale>

#include <KDebug>

#include "PacketListModel.h"

PacketListModel::PacketListModel(QObject * parent)
  : QAbstractListModel(parent)
{
  m_list.clear();
}


int PacketListModel::rowCount(const QModelIndex &parent) const
{
  Q_UNUSED(parent);
  return m_list.size();
}


int PacketListModel::columnCount(const QModelIndex& parent) const
{
  Q_UNUSED(parent);
  return 6;
}


Qt::ItemFlags PacketListModel::flags ( const QModelIndex& index ) const
{
  Q_UNUSED(index);
  return Qt::ItemIsEnabled;
}


void PacketListModel::addPacket( PacketDataItem *item )
{
  m_list.append( *item );
  reset();
}


QList<PacketDataItem> *PacketListModel::list()
{
  return &m_list;
}


QVariant PacketListModel::data(const QModelIndex &index, int role) const
{
  QVariant res;

  if (index.isValid())
  {
    if ( role == Qt::DisplayRole )
    {
      if (m_list.size() > 0)
      {
        switch(index.column())
        {
          case 0:
            //res = "zero";// + m_list.at(index.row()).essid() + "   ";
            res = static_cast<PacketDataItem>(m_list.at(index.row())).id();
            break;
          case 1:
            res = "uno";// + m_list.at(index.row()).essid() + "   ";
            break;
          case 2:
            res = "due";// + m_list.at(index.row()).essid() + "   ";
            break;
          case 3:
            res = "tre";// + m_list.at(index.row()).essid() + "   ";
            break;
          case 4:
            res = "tre";// + m_list.at(index.row()).essid() + "   ";
            break;
          case 5:
            res = "tre";// + m_list.at(index.row()).essid() + "   ";
            break;
        }
      }
    }
  }

  return res;
}


QVariant PacketListModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
  QString name;

  if ( role != Qt::DisplayRole )
    return QVariant();

  if (orientation == Qt::Horizontal)
  {
    switch(section)
    {
      case 0:
        name = "Frame n.";
        break;
      case 1:
        name = "Time";
        break;
      case 2:
        name = "Source";
        break;
      case 3:
        name = "Destination";
        break;
      case 4:
        name = "Protocol";
        break;
      case 5:
        name = "Information";
        break;
    }
  }

  return name;
}
