1
/****************************************************************************
2
** ui.h extension file, included from the uic-generated form implementation.
4
** If you wish to add, delete or rename functions or slots use
5
** Qt Designer which will update this file, preserving your code. Create an
6
** init() function in place of a constructor, and a destroy() function in
7
** place of a destructor.
8
*****************************************************************************/
9
const char *CDInfoDialogBase::SEPARATOR = " / ";
11
void CDInfoDialogBase::init()
13
m_categories = KCDDB::Categories();
14
m_category->insertStringList(m_categories.i18nList());
15
m_genres = KCDDB::Genres();
16
m_genre->insertStringList(m_genres.i18nList());
18
// We want control over the visibility of this column. See artistChanged().
19
m_trackList->setColumnWidthMode(TRACK_ARTIST, QListView::Manual);
21
// Make the user-definable values in-place editable.
22
m_trackList->setRenameable(TRACK_NUMBER, false);
23
m_trackList->setRenameable(TRACK_TIME, false);
24
m_trackList->setRenameable(TRACK_TITLE, true);
25
m_trackList->setRenameable(TRACK_COMMENT, true);
26
m_trackList->setRenameable(TRACK_ARTIST, true);
29
void CDInfoDialogBase::destroy()
33
void CDInfoDialogBase::slotTrackSelected( QListViewItem *item )
35
emit play(item->text(0).toUInt()-1);
38
void CDInfoDialogBase::slotNextTrack()
40
if (m_trackList->currentItem())
42
QListViewItem *item = m_trackList->currentItem()->nextSibling();
43
m_trackList->setSelected(item, true);
44
m_trackList->ensureItemVisible(item);
48
void CDInfoDialogBase::slotTrackDoubleClicked( QListViewItem *item, const QPoint &, int column)
50
m_trackList->rename(item, column);
54
void CDInfoDialogBase::setInfo( const KCDDB::CDInfo &info, KCDDB::TrackOffsetList &trackStartFrames )
56
m_artist->setText(info.artist.stripWhiteSpace());
57
m_title->setText(info.title.stripWhiteSpace());
58
m_category->setCurrentText(m_categories.cddb2i18n(info.category));
60
// Make sure the revision is set before the genre to allow the genreChanged() handler to fire.
61
m_revision->setText(QString::number(info.revision));
62
m_genre->setCurrentText(m_genres.cddb2i18n(info.genre));
63
m_year->setValue(info.year);
64
m_comment->setText(info.extd.stripWhiteSpace());
65
m_id->setText(info.id.stripWhiteSpace());
67
// Now do the individual tracks.
68
unsigned tracks = info.trackInfoList.count();
69
m_length->setText(framesTime(trackStartFrames[tracks + 1] - trackStartFrames[0]));
71
for (unsigned i = 0; i < tracks; i++)
73
QListViewItem *item = new QListViewItem(m_trackList, 0);
75
item->setText(TRACK_NUMBER, QString().sprintf("%02d", i + 1));
76
item->setText(TRACK_TIME, framesTime(trackStartFrames[i + ((i + 1 < tracks) ? 1 : 2)] - trackStartFrames[i]));
77
QString title = info.trackInfoList[i].title;
78
int separator = title.find(SEPARATOR);
79
if (info.artist != "Various" || separator == -1)
81
item->setText(TRACK_ARTIST, "");
82
item->setText(TRACK_TITLE, title);
86
// We seem to have a compilation.
87
item->setText(TRACK_ARTIST, title.left(separator));
88
item->setText(TRACK_TITLE, title.mid(separator + 3));
90
item->setText(TRACK_COMMENT, info.trackInfoList[i].extt);
92
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
94
if (info.artist == "Various")
95
m_trackList->adjustColumn(TRACK_ARTIST);
98
QString CDInfoDialogBase::framesTime(unsigned frames)
103
ms = frames * 1000 / 75.0;
104
time = time.addMSecs((int)ms);
106
// Use ".zzz" for milliseconds...
109
temp2 = time.toString("hh:mm:ss");
111
temp2 = time.toString("mm:ss");
115
KCDDB::CDInfo CDInfoDialogBase::info() const
118
KCDDB::TrackInfo track;
120
info.artist = m_artist->text().stripWhiteSpace();
121
info.title = m_title->text().stripWhiteSpace();
122
info.category = m_categories.i18n2cddb(m_category->currentText());
123
info.genre = m_genres.i18n2cddb(m_genre->currentText());
124
info.year = m_year->value();
125
info.extd = m_comment->text().stripWhiteSpace();
126
info.revision = m_revision->text().stripWhiteSpace().toUInt();
127
info.id = m_id->text().stripWhiteSpace();
128
for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
130
// Combine the track artist if present with the title.
131
QString trackArtist = item->text(TRACK_ARTIST).stripWhiteSpace();
132
track.title = trackArtist;
133
if (!trackArtist.isEmpty())
135
track.title.append(SEPARATOR);
137
track.title.append(item->text(TRACK_TITLE).stripWhiteSpace());
138
track.extt = item->text(TRACK_COMMENT).stripWhiteSpace();
139
info.trackInfoList.append(track);
140
// FIXME KDE4: handle track lengths here too, once KCDDBInfo::CDInfo is updated.
142
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
147
void CDInfoDialogBase::artistChanged( const QString &newArtist )
149
// Enable special handling of compilations.
150
if (newArtist.stripWhiteSpace().compare("Various") == 0)
152
for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
154
QString title = item->text(TRACK_TITLE);
155
int separator = title.find(SEPARATOR);
158
// Artists probably entered already
159
item->setText(TRACK_ARTIST, title.left(separator));
160
item->setText(TRACK_TITLE, title.mid(separator + 3));
163
m_trackList->adjustColumn(TRACK_ARTIST);
164
m_trackList->adjustColumn(TRACK_TITLE);
168
for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
170
QString artist = item->text(TRACK_ARTIST);
171
if (!artist.isEmpty())
173
item->setText(TRACK_ARTIST, QString::null);
174
item->setText(TRACK_TITLE, artist + SEPARATOR + item->text(TRACK_TITLE));
177
m_trackList->hideColumn(TRACK_ARTIST);
178
m_trackList->adjustColumn(TRACK_TITLE);
182
void CDInfoDialogBase::genreChanged( const QString &newGenre )
184
// Disable changes to category if the version number indicates that a record
185
// is already in the database, or if the genre is poorly set. The latter
186
// condition also provides a "back-door" override.
187
m_category->setEnabled((m_revision->text().stripWhiteSpace().toUInt() < 1) ||
188
(newGenre.compare("Unknown") == 0));