/****************************************************************************
** assignmenuaudio.cpp
**
**   Created : May 4 2008
**        by : Varol Okan using Kate
** Copyright : (c) Varol Okan
**   License : GPL v 2.0
**
*****************************************************************************/

#include <qfileinfo.h>
#include <qlistview.h>
#include <qcombobox.h>
#include <qpushbutton.h>

//#include "utils.h"    //ooo
#include "qdvdauthor/utils.h"   //xxx
//#include "global.h"   //ooo
#include "qdvdauthor/global.h"  //xxx
//#include "qdvdauthor.h"   //ooo
#include "qdvdauthor/qdvdauthor.h"  //xxx
#include "assignmenuaudio.h"
//#include "filepreviewdialog.h"    //ooo
#include "qdvdauthor/filepreviewdialog.h"   //xxx

namespace Input
{

//AssignMenuAudio::AssignMenuAudio ( QWidget* parent, const char* name, bool modal, WFlags fl ) //ooo
AssignMenuAudio::AssignMenuAudio ( QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl )  //xxx   
  //: uiAssignMenuAudio ( parent, name, modal, fl ) //ooo
  : QDialog ( parent )
{
  setupUi(this);	//xxx  
    
  connect ( m_pButtonAdd,    SIGNAL ( clicked ( ) ), this, SLOT ( slotAdd    ( ) ) );
  connect ( m_pButtonDelete, SIGNAL ( clicked ( ) ), this, SLOT ( slotDelete ( ) ) );
  connect ( m_pButtonCancel, SIGNAL ( clicked ( ) ), this, SLOT ( reject     ( ) ) );
  connect ( m_pButtonOkay,   SIGNAL ( clicked ( ) ), this, SLOT ( accept     ( ) ) );

  QString qsText, qsCode;
  QString qsLang = "something";
  Utils theUtils;
  int t = 0;

  while ( ! qsLang.isEmpty ( ) ) {
    qsLang = theUtils.iso639 ( qsText, false, t++ );
    //m_pComboLanguage->insertItem ( qsLang );  //ooo
    m_pComboLanguage->addItem ( qsLang );   //xxx
  }
  m_pComboLanguage->setCurrentText ( "English" );

}

/*
 *  Destroys the object and frees any allocated resources
 */
AssignMenuAudio::~AssignMenuAudio ( )
{
}

void AssignMenuAudio::slotAdd ( )
{
  QStringList listFileNames;
  QString   qsFilter       = Global::pApp->getSoundFilter ( );
  QString   qsDialogFilter = tr ("Sound Files (") + qsFilter + QString(")");

  listFileNames = FilePreviewDialog::getOpenFileNames ( Global::qsCurrentPath, QString::null, NULL, "SoundFilesDialog", tr( "Select sound files" ), &qsDialogFilter );

  if ( listFileNames.count ( ) < 1)
    return;

  QFileInfo fileInfo;
  QStringList::iterator it = listFileNames.begin ( );
  while ( it != listFileNames.end ( ) )  {
    fileInfo.setFile ( *it++ );

    //QListViewItem *pItem = 
    //new QListViewItem ( m_pListAudio, fileInfo.extension ( FALSE ).lower ( ), "yes", fileInfo.filePath ( ) ); //ooo
    QTreeWidgetItem *pItem = new QTreeWidgetItem ( m_pListAudio );    //xxx
    pItem->setText ( 0, fileInfo.suffix  ( ).toLower ( ));   //xxx
    pItem->setText ( 1, "yes");   //xxx
    pItem->setText ( 2, fileInfo.filePath ( ));   //xxx
  }
}

void AssignMenuAudio::slotDelete ( )
{
  //QListViewItem *pItem, *pNextItem;   //ooo
  QTreeWidgetItem *pItem, *pNextItem;   //xxx
  //pItem = m_pListAudio->firstChild ( );   //ooo
  pItem = m_pListAudio->topLevelItem ( 0 ); //xxx
  while ( pItem )  {
    //pNextItem = pItem->nextSibling ( );   //ooo
    pNextItem = pItem->treeWidget()->itemBelow(pItem);  //xxx  
    if  ( pItem->isSelected ( ) )
      delete pItem;
    pItem = pNextItem;
  }
}

}; // end of namespace Input
