/***************************************************************************
 *   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 "CaptureOption.h"
#include "../version.h"

CaptureOption::CaptureOption()
{
  m_strSniffingInterface = QString::null;
  m_strSniffingFilename = QString::null;
}


CaptureOption::CaptureOption(const QString& strInterface)
{
  m_strSniffingInterface = strInterface;
  m_showAfter = false;
}


void CaptureOption::setSniffingInterface(const QString& str)
{
  m_strSniffingInterface = str;
  m_strSniffingFilename = QString::null;
}


void CaptureOption::setSniffingFilename( const QString& filename )
{
  m_strSniffingFilename = filename;
  m_strSniffingInterface = QString::null;
}


void CaptureOption::setTmpDir( const QString& str)
{
  m_strDirTmp = str;
}


void CaptureOption::setShowAfter( const bool& display )
{
  m_showAfter = display;
}


void CaptureOption::setTrayBar( const bool& trayBar )
{
  m_trayBar = trayBar;
}


void CaptureOption::setWarning( const bool& warn )
{
  m_warning = warn;
}


void CaptureOption::setPassiveWarn( const bool& passive )
{
  m_passivePopUp = passive;
}


void CaptureOption::setShowSplash( const bool& splash )
{
  m_showSplash = splash;
}


void CaptureOption::setPacketsNumber( const long& number )
{
  m_packetsNumber = number;
}


void CaptureOption::setPacketsSize( const long& packsize )
{
  m_packetsSize = packsize;
}


void CaptureOption::setPacketsTime( const long& packtime )
{
  m_packetsTime = packtime;
}


void CaptureOption::setPacketsInfoSizeUnits( const int& sizeunit )
{
  m_packetsInfoSizeUnits = sizeunit;
}


void CaptureOption::setPacketsInfoTimeUnits( const int& timeunit )
{
  m_packetsInfoTimeUnits = timeunit;
}


void CaptureOption::setSniffingType( const QString& sniffType )
{
  if (sniffType == "manually")
    m_sniffType = 0;
  else if (sniffType == "by packets")
    m_sniffType = 1;
  else if (sniffType == "by size")
    m_sniffType = 2;
  else if (sniffType == "by time")
    m_sniffType = 3;
}


void CaptureOption::setRawFramePosition( const QString& position )
{
  m_rawFramePosition = position;
}


void CaptureOption::setShowProtocolName( const bool& display )
{
  m_showProtocolName = display;
}


QString CaptureOption::sniffingInterface() const
{
  return m_strSniffingInterface;
}


QString CaptureOption::sniffingFilename() const
{
  return m_strSniffingFilename;
}


QString CaptureOption::tmpFilePath() const
{
  QString path = m_strDirTmp;
  if (path[path.length() - 1] != '/')
    path.append( "/" );
  path.append( TEMP_PCAP_FILE_NAME );

  return path;
}


QString CaptureOption::tmpFileConfigPath() const
{
  QString path = m_strDirTmp;
  if (path[path.length() - 1] != '/')
    path.append( "/" );
  path.append( TEMP_SNIFFER_CONFIG_FILE_NAME );

  return path;
}


QString CaptureOption::tmpDir() const
{
  return m_strDirTmp;
}


bool CaptureOption::showAfter() const
{
  return m_showAfter;
}


bool CaptureOption::showTrayBar() const
{
  return m_trayBar;
}


bool CaptureOption::showWarning() const
{
  return m_warning;
}


bool CaptureOption::showPassiveWarn() const
{
  return m_passivePopUp;
}


bool CaptureOption::showSplash() const
{
  return m_showSplash;
}


long CaptureOption::packetsNumber() const
{
  return m_packetsNumber;
}


long CaptureOption::packetsSize() const
{
  return m_packetsSize;
}


long CaptureOption::packetsTime() const
{
  return m_packetsTime;
}


int CaptureOption::packetsInfoSizeUnits() const
{
  return m_packetsInfoSizeUnits;
}


int CaptureOption::packetsInfoTimeUnits() const
{
  return m_packetsInfoTimeUnits;
}


int CaptureOption::sniffType() const
{
  return m_sniffType;
}


QString CaptureOption::sniffingType() const
{
  QString res;

  switch (m_sniffType)
  {
    case 0:
      res = "manually";
      break;
    case 1:
      res = "packets";
      break;
    case 2:
      res = "size";
      break;
    case 3:
      res = "time";
      break;
  }

  return res;
}


QString CaptureOption::rawFramePosition() const
{
  return m_rawFramePosition;
}


bool CaptureOption::showProtocolName() const
{
  return m_showProtocolName;
}
