summaryrefslogtreecommitdiffstats
path: root/amarok/src/trackpickerdialog.cpp
blob: 7b3bf4b950bdd0c8105e636a492f5a6d5fe44783 (plain)
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
/***************************************************************************
    begin                : Sat Sep 6 2003
    copyright            : (C) 2003 - 2004 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <config.h>

#if HAVE_TUNEPIMP

#include <tqlabel.h>

#include <tdeapplication.h>
#include <tdelistview.h>
#include <tdelocale.h>

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

#define NUMBER(x) (x == 0 ? TQString() : TQString::number(x))

class TrackPickerItem : public TDEListViewItem
{
public:
    TrackPickerItem(TDEListView *parent, const KTRMResult &result) :
        TDEListViewItem(parent, parent->lastChild(),
                      result.title(), result.artist(), result.album(),
                      NUMBER(result.track()), NUMBER(result.year())),
                      m_result(result) {
//TQString year;
//if(result.year() == TQString::empty()) year = "xx";
//else year = result.year();
//setText(5,"xx");
}
    KTRMResult result() const { return m_result; }

private:
    KTRMResult m_result;
};

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

TrackPickerDialog::TrackPickerDialog(const TQString &name, const KTRMResultList &results, TQWidget *parent)
        : KDialogBase(parent, name.latin1(), true, TQString(), Ok | Cancel, Ok, true)
{
    kapp->setTopWidget( this );
    setCaption( kapp->makeStdCaption( i18n("MusicBrainz Results") ) );

    m_base = new TrackPickerDialogBase(this);
    setMainWidget(m_base);
    //setSorting with a column that doesn't exist means manual sorting only
    m_base->trackList->setSorting( 5 );

#if HAVE_TUNEPIMP >= 5
    //remove year column, there won't be any results anyway
    m_base->trackList->removeColumn( 4 );
#endif

    m_base->fileLabel->setText(name);
    KTRMResultList::ConstIterator end( results.end() );
    for(KTRMResultList::ConstIterator it = results.begin(); it != end; ++it)
        new TrackPickerItem(m_base->trackList, *it);
//     for( int j = 0; j < 5; j++ ) {
//             m_base->trackList->adjustColumn( j );
//         //resultTable->setColumnStretchable(j,true);
//     }
    m_base->trackList->setSelected(m_base->trackList->firstChild(), true);
  //  m_base->trackList->triggerUpdate();
    setMinimumWidth(kMax(300, width()));
    connect(this, TQT_SIGNAL( sigSelectionMade( KTRMResult ) ), parent, TQT_SLOT( fillSelected( KTRMResult ) ) );

}


KTRMResult
TrackPickerDialog::result() const
{
    if(m_base->trackList->selectedItem())
        return static_cast<TrackPickerItem *>(m_base->trackList->selectedItem())->result();
    else
        return KTRMResult();
}


void
TrackPickerDialog::accept()
{
    emit sigSelectionMade( result() );
    KDialog::accept();
}


#include "trackpickerdialog.moc"

#endif // HAVE_TUNEPIMP