/***************************************************************************
                          mycatalogdlg.cpp  -  description
                             -------------------
    begin                : Wed Feb 4 2004
    copyright            : (C) 2004 by Harald Krippel
    email                : neuro.harald@surfeu.at
 ***************************************************************************/

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

#include <iostream>

#include <qvariant.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qdir.h>
#include <qcombobox.h>
#include <qiconview.h>
#include <qfiledialog.h>

MyCatalogEditDlg::MyCatalogEditDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
    : CatalogEditDlg( parent, name, modal, fl )
{

     tmppath = tmpdir.homeDirPath () + "/cat3d/";
     tmpdir.setPath(tmppath);
     catpath->setText(tmppath);
     fillcombo();
     fillicon();
//     path->setText( tmppath ) ;
     state=0;
}

/*
 *  Destroys the object and frees any allocated resources
 */
MyCatalogEditDlg::~MyCatalogEditDlg()
{
    // no need to delete child widgets, Qt does it all for us
}

void MyCatalogEditDlg::slotGetData(FolderListItem *i)
{

    qWarning( "MyCatalogEditDlg::slotGetData(): Geht !" );
}

void MyCatalogEditDlg::slotEditData()
{

     qWarning( "MyCatalogEditDlg::slotEditData(): Geht !" );
     accept();
}

void MyCatalogEditDlg::slotGetCatPath()
{
//    KURL url=KFileDialog::getExistingURL();
    QString url=QFileDialog::getExistingDirectory();
    if(!url.isEmpty())
    {
//      tmppath =  url.directory() + '/' + url.fileName() + '/' ;
      tmppath =  url + '/'  ;
      tmpdir.setPath(tmppath);
      catpath->setText( tmppath) ;
      fillcombo();
    }
    qWarning( "MyCatalogEditDlg::slotGetCatPath(): Geht !" );

}
void MyCatalogEditDlg::slotGetCombo()
{
    fillicon();
    qWarning( "MyCatalogEditDlg::slotGetCombo(): Geht !" );
}

void MyCatalogEditDlg::fillicon()
{
     QDir icondir;
     QStringList catlist;
     icondir.setPath( tmpdir.path() + "/" + comboBox1->currentText());
     path =  icondir.path() + "/";
     icondir.setFilter(QDir::Dirs);
     catlist = icondir.entryList();
     icon->clear();
     for ( uint i = 0; i < icondir.count(); i++ )
     {
       if (icondir[i] != "." && icondir[i] != "..")
        (void) new QIconViewItem( icon, icondir[i], QPixmap( icondir.path() + icondir[i] ) );
     }
     icon->setCurrentItem(icon->firstItem());
/*
    QIconView *iv = new QIconView( this );
    QDir dir( path, "*.xpm" );
    for ( uint i = 0; i < dir.count(); i++ ) {
        (void) new QIconViewItem( iv, dir[i], QPixmap( path + dir[i] ) );
    }
*/
}
void MyCatalogEditDlg::fillcombo()
{
     QStringList catlist;
     tmpdir.setFilter(QDir::Dirs);
     catlist = tmpdir.entryList();
     comboBox1->clear();
     for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it )
     {
       if (*it != "." && *it != "..")
       comboBox1->insertItem( *it );
     }
}


QString MyCatalogEditDlg::getfile()
{
     file = (icon->currentItem())->text();
     return file;
}

QString MyCatalogEditDlg::getpath()
{
     return path;
}
