#include "multiselectionfiledialog.h"

#include <QDialogButtonBox>
#include <ukuistylehelper/ukuistylehelper.h>

MultiSelectionFileDialog::MultiSelectionFileDialog(QWidget *parent,
                                                   const QString &caption,
                                                   const QString directory,
                                                   const QString filter)
    : QFileDialog(parent, caption, directory, filter)
{
    kdk::UkuiStyleHelper::self()->removeHeader(this);
    m_oListView = findChild<QListView *>("listView");
    m_oTreeView = findChild<QTreeView *>();
    QDialogButtonBox *btn = findChild<QDialogButtonBox *>("buttonBox");
    if (btn)
    {
        disconnect(btn, SIGNAL(accepted()), this, SLOT(accept()));
        connect(btn, SIGNAL(accepted()), this, SLOT(slotsAccept()));
    }
    m_oFileName = findChild<QLineEdit *>("fileNameEdit");
}

void MultiSelectionFileDialog::setExtendedSelection()
{
    if (m_oListView)
        m_oListView->setSelectionMode(QListView::ExtendedSelection);
    if (m_oTreeView)
        m_oTreeView->setSelectionMode(QTreeView::ExtendedSelection);
}

void MultiSelectionFileDialog::setSingleSelection()
{
    if (m_oListView)
        m_oListView->setSelectionMode(QListView::SingleSelection);
    if (m_oTreeView)
        m_oTreeView->setSelectionMode(QTreeView::SingleSelection);
}

void MultiSelectionFileDialog::reset()
{
    if (m_oListView) m_oListView->clearSelection();
    if (m_oTreeView) m_oTreeView->clearSelection();
    if (m_oFileName) m_oFileName->setText("");
}

void MultiSelectionFileDialog::slotsAccept()
{
    QDialog::accept();
}

MultiSelectionFileDialog::~MultiSelectionFileDialog()
{}
