/***************************************************************************
                          fileviewimpl.cpp  -  description
                             -------------------
    begin                : Wed Mar 7 2001
    copyright            : (C) 2001 by Olaf Lueg
    email                : olaf.lueg@t-online.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "fileviewimpl.h"

// qt includes
#include <qlistview.h>
#include <qbutton.h>


// kde includes
#include <kfiledialog.h>
#include <klocale.h>

FileViewImpl::FileViewImpl(QWidget *parent, const char *name ) : FileView(parent,name) {
	itemList.setAutoDelete(false);
	ListView1->setColumnWidth(0,ListView1->width()-4);
}
FileViewImpl::~FileViewImpl(){
}
/** No descriptions */
void FileViewImpl::slotAddFiles(){
	QStringList currentFile = KFileDialog::getOpenFileNames("/",
		    i18n("*.*|All files"), this, i18n("Add file..."));
	if(currentFile.count() != 0){
		for ( QStringList::Iterator it = currentFile.begin(); it != currentFile.end(); ++it ) {
    	insertFile((*it).latin1());
    }
  }

}
void FileViewImpl::insertFile(QString file){
	QListViewItem *item;
  item = new QListViewItem(ListView1,file);
}


void FileViewImpl::slotRemoveFiles(){
	getSelectedItems();
	debug("count %i",itemList.count());
	if(itemList.count() !=0){
	for(QListViewItem *item = itemList.first();item != 0;item=itemList.first()){
		itemList.remove(item);
		delete item;
	}
	ListView1->update();
		     }
}

void FileViewImpl::slotCreateSpec(){
	emit createSpec();
}

void FileViewImpl::slotExecuteRpm(){
	emit executeRpm();
}

void FileViewImpl::getSelectedItems(){

  if(ListView1->childCount() !=0){
  QListViewItem *item = ListView1->firstChild();
  debug(item->text(0));
  	for(int i =1;i <=ListView1->childCount() ; i++){
  		if(item->isSelected()){
  		debug(item->text(0));
  		itemList.append(item);
  		}
  		item = item->itemBelow();
  		}
  }
}

QStringList FileViewImpl::getFiles(){
	QStringList list;
  if(ListView1->childCount() !=0){
  QListViewItem *item = ListView1->firstChild();
  for(int i =1;i <=ListView1->childCount() ; i++){
  	list.append(item->text(0));
  	item = item->itemBelow();
  }
  }
  return list;
}

void FileViewImpl::resizeEvent(QResizeEvent){
	ListView1->setColumnWidth(0,ListView1->width()-2);
}
