1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/**
* 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/>.
*/
#include <config-juk.h>
#include "trackpickerdialog.h"
#if HAVE_TUNEPIMP
#include <k3listview.h>
#include <klocale.h>
#define NUMBER(x) (x == 0 ? QString::null : QString::number(x)) //krazy:exclude=nullstrassign for old broken gcc
class TrackPickerItem : public K3ListViewItem
{
public:
TrackPickerItem(K3ListView *parent, const KTRMResult &result) :
K3ListViewItem(parent, parent->lastChild(),
result.title(), result.artist(), result.album(),
NUMBER(result.track()), NUMBER(result.year())),
m_result(result) {}
KTRMResult result() const { return m_result; }
private:
KTRMResult m_result;
};
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
TrackPickerDialog::TrackPickerDialog(const QString &name,
const KTRMResultList &results,
QWidget *parent) :
KDialog(parent)
{
setObjectName(name.toAscii());
setModal(true);
setCaption(i18n("Internet Tag Guesser"));
setButtons(Ok | Cancel);
showButtonSeparator(true);
m_base = new TrackPickerDialogBase(this);
setMainWidget(m_base);
m_base->fileLabel->setText(name);
m_base->trackList->setSorting(-1);
for(KTRMResultList::ConstIterator it = results.begin(); it != results.end(); ++it)
new TrackPickerItem(m_base->trackList, *it);
m_base->trackList->setSelected(m_base->trackList->firstChild(), true);
connect(m_base->trackList, SIGNAL(doubleClicked(Q3ListViewItem*,QPoint,int)),
this, SLOT(accept()));
setMinimumWidth(qMax(400, width()));
}
TrackPickerDialog::~TrackPickerDialog()
{
}
KTRMResult TrackPickerDialog::result() const
{
if(m_base->trackList->selectedItem())
return static_cast<TrackPickerItem *>(m_base->trackList->selectedItem())->result();
else
return KTRMResult();
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
int TrackPickerDialog::exec()
{
int dialogCode = KDialog::exec();
// Only return true if an item was selected.
if(m_base->trackList->selectedItem())
return dialogCode;
else
return Rejected;
}
#include "trackpickerdialog.moc"
#endif // HAVE_TUNEPIMP
// vim: set et sw=4 tw=0 sta:
|