trackpickerdialog.cpp 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2003-2004 Scott Wheeler <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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16

17
#include <config-juk.h>
18 19 20

#include "trackpickerdialog.h"

21
#if HAVE_TUNEPIMP
22

23

Laurent Montel's avatar
Laurent Montel committed
24
#include <k3listview.h>
25 26
#include <klocale.h>

27
#define NUMBER(x) (x == 0 ? QString::null : QString::number(x))	//krazy:exclude=nullstrassign for old broken gcc
28

Laurent Montel's avatar
Laurent Montel committed
29
class TrackPickerItem : public K3ListViewItem
30 31
{
public:
Laurent Montel's avatar
Laurent Montel committed
32 33
    TrackPickerItem(K3ListView *parent, const KTRMResult &result) :
        K3ListViewItem(parent, parent->lastChild(),
34 35
                      result.title(), result.artist(), result.album(),
                      NUMBER(result.track()), NUMBER(result.year())),
36 37 38 39 40 41
        m_result(result) {}
    KTRMResult result() const { return m_result; }

private:
    KTRMResult m_result;
};
42 43 44 45 46

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

47 48 49
TrackPickerDialog::TrackPickerDialog(const QString &name,
                                     const KTRMResultList &results,
                                     QWidget *parent) :
50
    KDialog(parent)
51
{
Dirk Mueller's avatar
Dirk Mueller committed
52
    setObjectName(name.toAscii());
53 54 55
    setModal(true);
    setCaption(i18n("Internet Tag Guesser"));
    setButtons(Ok | Cancel);
Laurent Montel's avatar
Laurent Montel committed
56
    showButtonSeparator(true);
57

58 59 60
    m_base = new TrackPickerDialogBase(this);
    setMainWidget(m_base);

61 62
    m_base->fileLabel->setText(name);
    m_base->trackList->setSorting(-1);
63

64
    for(KTRMResultList::ConstIterator it = results.begin(); it != results.end(); ++it)
Stephan Kulow's avatar
Stephan Kulow committed
65
        new TrackPickerItem(m_base->trackList, *it);
66 67

    m_base->trackList->setSelected(m_base->trackList->firstChild(), true);
68

Laurent Montel's avatar
Laurent Montel committed
69
    connect(m_base->trackList, SIGNAL(doubleClicked(Q3ListViewItem*,QPoint,int)),
70 71
            this, SLOT(accept()));

72
    setMinimumWidth(qMax(400, width()));
73 74 75 76 77 78 79
}

TrackPickerDialog::~TrackPickerDialog()
{

}

80
KTRMResult TrackPickerDialog::result() const
81 82
{
    if(m_base->trackList->selectedItem())
Stephan Kulow's avatar
Stephan Kulow committed
83
        return static_cast<TrackPickerItem *>(m_base->trackList->selectedItem())->result();
84
    else
85
        return KTRMResult();
86 87 88 89 90 91 92 93
}

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

int TrackPickerDialog::exec()
{
94
    int dialogCode = KDialog::exec();
95 96 97 98 99 100 101 102 103

    // Only return true if an item was selected.

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

104
#endif // HAVE_TUNEPIMP
105 106

// vim: set et sw=4 tw=0 sta: