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
|
#include "replaygainscanner.h"
#include "logger.h"
#include "combobutton.h"
#include "config.h"
#include "dirdialog.h"
#include <qlayout.h>
#include <qstringlist.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qtooltip.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kfiledialog.h>
#include <kpushbutton.h>
#include <kprogress.h>
// FIXME file name encoding !!!
ReplayGainScanner::ReplayGainScanner( TagEngine* _tagEngine, Config* _config, Logger* _logger, QWidget *parent, const char *name, bool modal, WFlags f )
: KDialog( parent, name, modal, f )
{
tagEngine = _tagEngine;
config = _config;
logger = _logger;
// create an icon loader object for loading icons
KIconLoader* iconLoader = new KIconLoader();
setCaption( i18n("Replay Gain Tool") );
resize( 600, 400 );
setIcon( iconLoader->loadIcon("soundkonverter_replaygain",KIcon::Small) );
QGridLayout* grid = new QGridLayout( this, 4, 1, 11, 6 );
QHBoxLayout* filterBox = new QHBoxLayout();
grid->addLayout( filterBox, 0, 0 );
cAdd = new ComboButton( this, "cAdd" );
cAdd->insertItem( iconLoader->loadIcon("folder",KIcon::Small),i18n("Add Folder ...") );
cAdd->insertItem( iconLoader->loadIcon("sound",KIcon::Small),i18n("Add Files ...") );
filterBox->addWidget( cAdd );
connect( cAdd, SIGNAL(clicked(int)),
this, SLOT(addClicked(int))
);
filterBox->addStretch();
cForce = new QCheckBox( i18n("Force recalculation"), this, "cForce" );
QToolTip::add( cForce, i18n("Recalculate Replay Gain tag for files that already have a Replay Gain tag set.") );
filterBox->addWidget( cForce );
/*QLabel *lFilter=new QLabel(i18n("Show:"),this,"lFilter");
filterBox->addWidget(lFilter);
cFilter=new QComboBox(this,"cFilter");
cFilter->insertItem(i18n("All"));
cFilter->insertItem(i18n("With Replay Gain"));
cFilter->insertItem(i18n("Without Replay Gain"));
cFilter->insertItem(i18n("Unknown"));
filterBox->addWidget(cFilter);*/
lList = new ReplayGainFileList( tagEngine, config, logger, this, "lList" );
grid->addWidget( lList, 1, 0 );
connect( this, SIGNAL(addFile(const QString&)),
lList, SLOT(addFile(const QString&))
);
connect( this, SIGNAL(addDir(const QString&,const QStringList&,bool)),
lList, SLOT(addDir(const QString&,const QStringList&,bool))
);
connect( this, SIGNAL(calcAllReplayGain(bool)),
lList, SLOT(calcAllReplayGain(bool))
);
connect( this, SIGNAL(removeAllReplayGain()),
lList, SLOT(removeAllReplayGain())
);
connect( this, SIGNAL(cancelProcess()),
lList, SLOT(cancelProcess())
);
connect( lList, SIGNAL(processStarted()),
this, SLOT(processStarted())
);
connect( lList, SIGNAL(processStopped()),
this, SLOT(processStopped())
);
connect( lList, SIGNAL(updateProgress(int,int)),
this, SLOT(updateProgress(int,int))
);
QHBoxLayout* progressBox = new QHBoxLayout();
grid->addLayout( progressBox, 2, 0 );
pProgressBar = new KProgress( this, "pProgressBar" );
progressBox->addWidget( pProgressBar );
QHBoxLayout* buttonBox = new QHBoxLayout();
grid->addLayout( buttonBox, 3, 0 );
pTagVisible = new KPushButton( iconLoader->loadIcon("apply",KIcon::Small), i18n("Tag untagged"), this, "pTagVisible" );
QToolTip::add( pTagVisible, i18n("Calculate Replay Gain tag for all files in the file list without Replay Gain tag.") );
buttonBox->addWidget( pTagVisible );
connect( pTagVisible, SIGNAL(clicked()),
this, SLOT(calcReplayGainClicked())
);
pRemoveTag = new KPushButton( iconLoader->loadIcon("cancel",KIcon::Small), i18n("Untag tagged"), this, "pRemoveTag" );
QToolTip::add( pRemoveTag, i18n("Remove the Replay Gain tag from all files in the file list.") );
buttonBox->addWidget( pRemoveTag );
connect( pRemoveTag, SIGNAL(clicked()),
this, SLOT(removeReplayGainClicked())
);
pCancel = new KPushButton( iconLoader->loadIcon("cancel",KIcon::Small),i18n("Cancel"), this, "pCancel" );
pCancel->hide();
buttonBox->addWidget( pCancel );
connect( pCancel, SIGNAL(clicked()),
this, SLOT(cancelClicked())
);
buttonBox->addStretch();
pOk = new KPushButton( iconLoader->loadIcon("exit",KIcon::Small), i18n("Close"), this, "pOk" );
pOk->setFocus();
buttonBox->addWidget( pOk );
connect( pOk, SIGNAL(clicked()),
this, SLOT(accept())
);
// delete the icon loader object
delete iconLoader;
}
ReplayGainScanner::~ReplayGainScanner()
{}
void ReplayGainScanner::addClicked( int index )
{
if( index == 1 ) {
showFileDialog();
}
else {
showDirDialog();
}
}
void ReplayGainScanner::showFileDialog()
{
KFileDialog* dialog = new KFileDialog( ":file_open", config->replayGainFilter(), this, i18n("Choose files!"), true );
dialog->setMode ( KFile::Files | KFile::ExistingOnly );
if( dialog->exec() == KDialog::Accepted ) {
QStringList urls = dialog->selectedURLs().toStringList();
for( QStringList::Iterator it = urls.begin(); it != urls.end(); ++it ) {
emit addFile( *it );
}
}
}
void ReplayGainScanner::showDirDialog()
{
// QString directory = KFileDialog::getExistingDirectory( ":file_open", this, i18n("Choose a directory!") );
// if( directory != NULL )
// {
// emit addDir( directory );
// }
DirDialog *dialog = new DirDialog( config, DirDialog::ReplayGain, this, "DirDialog" );
Q_CHECK_PTR( dialog );
if( dialog->exec() ) {
emit addDir( dialog->directory, dialog->selectedFileTypes, dialog->recursive );
}
delete dialog;
}
void ReplayGainScanner::addFiles( QStringList files )
{
for( QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
emit addFile( *it );
}
}
void ReplayGainScanner::calcReplayGainClicked()
{
emit calcAllReplayGain( cForce->isChecked() );
}
void ReplayGainScanner::removeReplayGainClicked()
{
emit removeAllReplayGain();
}
void ReplayGainScanner::cancelClicked()
{
emit cancelProcess();
}
void ReplayGainScanner::processStarted()
{
pTagVisible->hide();
pRemoveTag->hide();
pCancel->show();
}
void ReplayGainScanner::processStopped()
{
pTagVisible->show();
pRemoveTag->show();
pCancel->hide();
pProgressBar->setProgress( 100 );
pProgressBar->setTotalSteps( 100 );
setCaption( i18n("Finished") + " - " + i18n("Replay Gain Tool") );
}
void ReplayGainScanner::updateProgress( int progress, int totalSteps )
{
/* pProgressBar->setProgress( int(processedTime) + percent * int(timeCount) / 100 );
pProgressBar->setTotalSteps( int(time) );*/
pProgressBar->setProgress( progress );
pProgressBar->setTotalSteps( totalSteps );
float fPercent;
if( pProgressBar->totalSteps() > 0 ) fPercent = pProgressBar->progress() * 100 / pProgressBar->totalSteps();
else fPercent = 0;
QString percent;
percent.sprintf( "%i%%", (int)fPercent );
setCaption( percent + " - " + i18n("Replay Gain Tool") );
}
|