/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef SQ_HAVE_KREGEXP
#include <kregexpeditorinterface.h>
#include <tdeparts/componentfactory.h>
#include <ktrader.h>
#endif

void SQ_SelectDeselectGroup::init()
{
    SQ_Config::instance()->setGroup("Fileview");
    comboMask->insertStringList(SQ_Config::instance()->readListEntry("selectdeselecthistory"));

#ifdef SQ_HAVE_KREGEXP
    // not installed
    if(TDETrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty())
	pushEdit->setEnabled(false);
#else
    pushEdit->setEnabled(false);
#endif
}

int SQ_SelectDeselectGroup::exec(TQString &mask)
{
    int result = TQDialog::exec();

    if(result == TQDialog::Accepted)
    {
        TQStringList list;
        int cc = comboMask->count();

        for(int i = 0;i < cc;i++)
            list.append(comboMask->text(i));

        // save history
        SQ_Config::instance()->setGroup("Fileview");
        SQ_Config::instance()->writeEntry("selectdeselecthistory", list);

        // save mask
        mask = comboMask->currentText();
    }

    return mask.isEmpty() ? TQDialog::Rejected : result;
}

void SQ_SelectDeselectGroup::slotEdit()
{
#ifdef SQ_HAVE_KREGEXP
    TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>("KRegExpEditor/KRegExpEditor");

    if(editorDialog)
    {
	KRegExpEditorInterface *editor = static_cast<KRegExpEditorInterface *>(editorDialog->tqt_cast("KRegExpEditorInterface"));

	Q_ASSERT(editor);
	editor->setRegExp(comboMask->currentText());

	if(editorDialog->exec())
        {
	    comboMask->insertItem(editor->regExp());
            comboMask->setCurrentText(editor->regExp());
        }
    }
#endif
}
