/***************************************************************************
 *   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 "PacketListView.h"

#include "PacketListModel.h"

#include <QtCore/QStringList>
#include <QtGui/QMouseEvent>

#include <KLocale>

#include <KMessageBox>
#include <KMenu>
#include <KAction>
#include <KDebug>

PacketListView::PacketListView(QWidget *parent)
 : QTreeView(parent)
{
  m_model = new PacketListModel(parent);
  setSortingEnabled( false );
  setRootIsDecorated( false );
  setModel(m_model);
/*  if (list != 0)
  {
    if (list->size() > 0)
    {
      m_model->addLine(list);
      setToolTip(i18n("Click on the wanted wireless network to connect"));
    }
    else
      setToolTip(i18n("<p>Sorry, but no wireless network detected.</p>")); \
                      "<p>Try to click on <b>Rescan</b> button to repeat "\
                      "the wireless network scanning."));
  }
  else
    setToolTip(i18n("<p>Sorry, but no wireless network detected.</p>")); \
                    "<p>Try to click on <b>Rescan</b> button to repeat "\
                    "the wireless network scanning."));
*/
  resizeColumnToContents(0);
  resizeColumnToContents(1);
  resizeColumnToContents(2);
  resizeColumnToContents(3);
}


void PacketListView::setData()
{
static long index = 1;
  /*
  if (list != NULL)
  {
    if (list->size() == 0)
      setToolTip(i18n("<p>Sorry, but no wireless network detected.</p>")); \
                      "<p>Try to click on <b>Rescan</b> button to repeat "\
                      "the wireless network scanning."));
    else
      setToolTip(i18n("Click on the wanted wireless network to connect"));
    */
    for (int i = 0; i < 25000; i++)
    {
    PacketDataItem *d = new PacketDataItem(QString("%1").arg(index++), "1", "2", "3");
    m_model->addPacket( d );
    }
    resizeColumnToContents(0);
    resizeColumnToContents(1);
    resizeColumnToContents(2);
    resizeColumnToContents(3);
//  }
}


/*
void WirelessNetworkView::mouseDoubleClickEvent(QMouseEvent *event)
{
  if (event->button() == Qt::LeftButton)
  {
    if (indexAt(event->pos()).isValid())
      KMessageBox::sorry(0, QString("<p>Trying to connect to the<br><b>%1</b><br>wireless network.").
        arg(m_model->list()->at(indexAt(event->pos()).row()).essid()),
        i18n("Connecting..."));
    {
      kDebug() << "I'm going to connect to" << m_model->list()->at(indexAt(event->pos()).row()).essid() << "via" << m_interface;
      m_netManager.connectToWireless( m_interface, m_model->list()->at(indexAt(event->pos()).row()) );
    }
  }
}


void WirelessNetworkView::mousePressEvent(QMouseEvent *event)
{
  if (event->button() == Qt::LeftButton)
  {
    if (indexAt(event->pos()).isValid())
      m_selectedWirelessNetwork = m_model->list()->at(indexAt(event->pos()).row());
  }
  else if (event->button() == Qt::RightButton)
  {
    if (indexAt(event->pos()).isValid())
    {
      m_selectedWirelessNetwork = m_model->list()->at(indexAt(event->pos()).row());
      m_actConnect->setStatusTip( i18n(("Connect to \"%1\" wireless network"),
        m_selectedWirelessNetwork.essid()) );

      m_actConfigure->setStatusTip( i18n(("Configure or reconfigure \"%1\" wireless network"),
        m_model->list()->at(indexAt(event->pos()).row()).essid()) );

      KMenu *menu = new KMenu;
      menu->addAction( m_actConnect );
      menu->addAction( m_actConfigure );
      menu->popup( event->globalPos() );
    }
  }
}
*/

void PacketListView::clear()
{
}
