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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include <tqtextcodec.h>
#include <kdebug.h>
#include <kdialogbase.h>
#include <tdeglobal.h>
#include <kcharsets.h>
#include "cdinfoencodingwidget.h"
const char *CDInfoDialogBase::SEPARATOR = " / ";
void CDInfoDialogBase::init()
{
m_categories = KCDDB::Categories();
m_category->insertStringList(m_categories.i18nList());
m_genres = KCDDB::Genres();
m_genre->insertStringList(m_genres.i18nList());
// We want control over the visibility of this column. See artistChanged().
m_trackList->setColumnWidthMode(TRACK_ARTIST, TQListView::Manual);
// Make the user-definable values in-place editable.
m_trackList->setRenameable(TRACK_NUMBER, false);
m_trackList->setRenameable(TRACK_TIME, false);
m_trackList->setRenameable(TRACK_TITLE, true);
m_trackList->setRenameable(TRACK_COMMENT, true);
m_trackList->setRenameable(TRACK_ARTIST, true);
}
void CDInfoDialogBase::destroy()
{
}
void CDInfoDialogBase::slotTrackSelected( TQListViewItem *item )
{
emit play(item->text(0).toUInt()-1);
}
void CDInfoDialogBase::slotNextTrack()
{
if (m_trackList->currentItem())
{
TQListViewItem *item = m_trackList->currentItem()->nextSibling();
m_trackList->setSelected(item, true);
m_trackList->ensureItemVisible(item);
}
}
void CDInfoDialogBase::slotTrackDoubleClicked( TQListViewItem *item, const TQPoint &, int column)
{
m_trackList->rename(item, column);
}
void CDInfoDialogBase::setInfo( const KCDDB::CDInfo &info, KCDDB::TrackOffsetList &trackStartFrames )
{
m_artist->setText(info.artist.stripWhiteSpace());
m_title->setText(info.title.stripWhiteSpace());
m_category->setCurrentText(m_categories.cddb2i18n(info.category));
// Make sure the revision is set before the genre to allow the genreChanged() handler to fire.
m_revision->setText(TQString::number(info.revision));
m_genre->setCurrentText(m_genres.cddb2i18n(info.genre));
m_year->setValue(info.year);
m_comment->setText(info.extd.stripWhiteSpace());
m_id->setText(info.id.stripWhiteSpace());
// Now do the individual tracks.
unsigned tracks = info.trackInfoList.count();
m_length->setText(framesTime(trackStartFrames[tracks + 1] - trackStartFrames[0]));
m_trackList->clear();
for (unsigned i = 0; i < tracks; i++)
{
TQListViewItem *item = new TQListViewItem(m_trackList, 0);
item->setText(TRACK_NUMBER, TQString().sprintf("%02d", i + 1));
item->setText(TRACK_TIME, framesTime(trackStartFrames[i + ((i + 1 < tracks) ? 1 : 2)] - trackStartFrames[i]));
TQString title = info.trackInfoList[i].title;
int separator = title.find(SEPARATOR);
if (info.artist != "Various" || separator == -1 || !m_multiple->isChecked() )
{
item->setText(TRACK_ARTIST, "");
item->setText(TRACK_TITLE, title);
}
else
{
// We seem to have a compilation.
item->setText(TRACK_ARTIST, title.left(separator));
item->setText(TRACK_TITLE, title.mid(separator + 3));
}
item->setText(TRACK_COMMENT, info.trackInfoList[i].extt);
}
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
if (info.artist == "Various" || m_multiple->isChecked()){
m_trackList->adjustColumn(TRACK_ARTIST);
}
}
TQString CDInfoDialogBase::framesTime(unsigned frames)
{
TQTime time;
double ms;
ms = frames * 1000 / 75.0;
time = time.addMSecs((int)ms);
// Use ".zzz" for milliseconds...
TQString temp2;
if (time.hour() > 0)
temp2 = time.toString("hh:mm:ss");
else
temp2 = time.toString("mm:ss");
return temp2;
} // framesTime
KCDDB::CDInfo CDInfoDialogBase::info() const
{
KCDDB::CDInfo info;
KCDDB::TrackInfo track;
info.artist = m_artist->text().stripWhiteSpace();
info.title = m_title->text().stripWhiteSpace();
info.category = m_categories.i18n2cddb(m_category->currentText());
info.genre = m_genres.i18n2cddb(m_genre->currentText());
info.year = m_year->value();
info.extd = m_comment->text().stripWhiteSpace();
info.revision = m_revision->text().stripWhiteSpace().toUInt();
info.id = m_id->text().stripWhiteSpace();
for (TQListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
{
// Combine the track artist if present with the title.
TQString trackArtist = item->text(TRACK_ARTIST).stripWhiteSpace();
track.title = trackArtist;
if (!trackArtist.isEmpty())
{
track.title.append(SEPARATOR);
}
track.title.append(item->text(TRACK_TITLE).stripWhiteSpace());
track.extt = item->text(TRACK_COMMENT).stripWhiteSpace();
info.trackInfoList.append(track);
// FIXME KDE4: handle track lengths here too, once KCDDBInfo::CDInfo is updated.
}
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
return info;
}
void CDInfoDialogBase::artistChanged( const TQString &newArtist )
{
// Enable special handling of compilations.
if (newArtist.stripWhiteSpace().compare("Various")) {
m_multiple->setChecked(false);
} else {
m_multiple->setChecked(true);
}
}
void CDInfoDialogBase::genreChanged( const TQString &newGenre )
{
// Disable changes to category if the version number indicates that a record
// is already in the database, or if the genre is poorly set. The latter
// condition also provides a "back-door" override.
m_category->setEnabled((m_revision->text().stripWhiteSpace().toUInt() < 1) ||
(newGenre.compare("Unknown") == 0));
}
void CDInfoDialogBase::slotMultipleArtists( bool hasMultipleArtist)
{
if(hasMultipleArtist){
for (TQListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
{
TQString title = item->text(TRACK_TITLE);
int separator = title.find(SEPARATOR);
if (separator != -1)
{
// Artists probably entered already
item->setText(TRACK_ARTIST, title.left(separator));
item->setText(TRACK_TITLE, title.mid(separator + 3));
}
}
m_trackList->adjustColumn(TRACK_ARTIST);
m_trackList->adjustColumn(TRACK_TITLE);
}
else{
for (TQListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
{
TQString artist = item->text(TRACK_ARTIST);
if (!artist.isEmpty())
{
item->setText(TRACK_ARTIST, TQString());
item->setText(TRACK_TITLE, artist + SEPARATOR + item->text(TRACK_TITLE));
}
}
m_trackList->hideColumn(TRACK_ARTIST);
m_trackList->adjustColumn(TRACK_TITLE);
}
}
void CDInfoDialogBase::slotChangeEncoding()
{
kdDebug() << k_funcinfo << endl;
KDialogBase* dialog = new KDialogBase(this, 0, true, i18n("Change Encoding"),
KDialogBase::Ok | KDialogBase::Cancel);
TQStringList songTitles;
for (TQListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
{
TQString title = item->text(TRACK_ARTIST).stripWhiteSpace();
if (!title.isEmpty())
title.append(SEPARATOR);
title.append(item->text(TRACK_TITLE).stripWhiteSpace());
songTitles << title;
}
KCDDB::CDInfoEncodingWidget* encWidget = new KCDDB::CDInfoEncodingWidget(
dialog, m_artist->text(),m_title->text(), songTitles);
dialog->setMainWidget(encWidget);
if (dialog->exec())
{
KCharsets* charsets = TDEGlobal::charsets();
TQTextCodec* codec = charsets->codecForName(charsets->encodingForName(encWidget->selectedEncoding()));
m_artist->setText(codec->toUnicode(m_artist->text().latin1()));
m_title->setText(codec->toUnicode(m_title->text().latin1()));
m_genre->setCurrentText(codec->toUnicode(m_genre->currentText().latin1()));
m_comment->setText(codec->toUnicode(m_comment->text().latin1()));
for (TQListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
{
item->setText(TRACK_ARTIST,codec->toUnicode(item->text(TRACK_ARTIST).latin1()));
item->setText(TRACK_TITLE,codec->toUnicode(item->text(TRACK_TITLE).latin1()));
item->setText(TRACK_COMMENT,codec->toUnicode(item->text(TRACK_COMMENT).latin1()));
}
}
}
|