trackpickerdialog.cpp 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/***************************************************************************
                          trackpickerdialog.h
                             -------------------
    begin                : Sat Sep 6 2003
    copyright            : (C) 2003 by Scott Wheeler
    email                : wheeler@kde.org
***************************************************************************/

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

18 19 20 21
#include <config.h>

#if HAVE_MUSICBRAINZ

22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <qlabel.h>

#include <klocale.h>

#include "trackpickerdialog.h"
#include "trackpickerdialogbase.h"
#include "musicbrainzitem.h"

////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////

TrackPickerDialog::TrackPickerDialog(const QString &fileName,
                                     const MusicBrainzQuery::TrackList &tracks,
36
                                     QWidget *parent,
37
                                     const char *name) :
38
    KDialogBase(parent, name, true, i18n("Internet Tag Guesser"), Ok | Cancel, Ok, true)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
{
    m_base = new TrackPickerDialogBase(this);
    setMainWidget(m_base);

    m_base->fileLabel->setText(fileName);

    MusicBrainzQuery::TrackList::ConstIterator it = tracks.begin();
    for(; it != tracks.end(); ++it)
        new MusicBrainzItem(m_base->trackList, *it, (*it).name, (*it).artist, (*it).album);


    m_base->trackList->setSelected(m_base->trackList->firstChild(), true);
    setMinimumWidth(QMAX(400, width()));

}

TrackPickerDialog::~TrackPickerDialog()
{

}

MusicBrainzQuery::Track TrackPickerDialog::selectedTrack() const
{
    if(m_base->trackList->selectedItem())
        return static_cast<MusicBrainzItem *>(m_base->trackList->selectedItem())->track();
    else
        return MusicBrainzQuery::Track();
}

////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////

int TrackPickerDialog::exec()
{
    int dialogCode = KDialogBase::exec();

    // Only return true if an item was selected.

    if(m_base->trackList->selectedItem())
        return dialogCode;
    else
        return Rejected;
}

#include "trackpickerdialog.moc"
85 86

#endif // HAVE_MUSICBRAINZ