Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 688 lines (597 sloc) 22.579 kB
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
96db5e8 @lordmulder Happy new year!
authored
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Dialog_Processing.h"
23
24 #include "Global.h"
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
25 #include "Resource.h"
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
26 #include "Model_FileList.h"
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
27 #include "Model_Progress.h"
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
28 #include "Model_Settings.h"
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
29 #include "Thread_Process.h"
c0ece99 @lordmulder Implemented logging and added a log file view.
authored
30 #include "Dialog_LogView.h"
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
31 #include "Encoder_MP3.h"
32 #include "Encoder_Vorbis.h"
be4ce0d @lordmulder Added AAC encoding support.
authored
33 #include "Encoder_AAC.h"
e6460b9 @lordmulder FLAC encoding support.
authored
34 #include "Encoder_FLAC.h"
e189eb0 @lordmulder Support for Wave (PCM) output.
authored
35 #include "Encoder_Wave.h"
58ded8c @lordmulder Added a normalization filter, based on SoX.
authored
36 #include "Filter_Normalize.h"
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
37 #include "Filter_Resample.h"
38 #include "Filter_ToneAdjust.h"
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
39 #include "WinSevenTaskbar.h"
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
40
41 #include <QApplication>
42 #include <QRect>
43 #include <QDesktopWidget>
44 #include <QMovie>
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
45 #include <QMessageBox>
46 #include <QTimer>
47 #include <QCloseEvent>
48 #include <QDesktopServices>
49 #include <QUrl>
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
50 #include <QUuid>
51 #include <QFileInfo>
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
52 #include <QDir>
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
53 #include <QMenu>
18bed9e @lordmulder Added a system tray icon.
authored
54 #include <QSystemTrayIcon>
b12e524 @lordmulder Add option "Brose Output File Location" to context menu in processing…
authored
55 #include <QProcess>
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
56
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
57 #include <Windows.h>
58
c967a01 @lordmulder Properly map the popup menu position to global coordinates.
authored
59 ////////////////////////////////////////////////////////////
60
d6e5b9e @lordmulder AAC decoding support added.
authored
61 #define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) \
62 { \
63 QPalette palette = WIDGET->palette(); \
64 palette.setColor(QPalette::Background, COLOR); \
65 WIDGET->setPalette(palette); \
66 }
67
18bed9e @lordmulder Added a system tray icon.
authored
68 #define SET_PROGRESS_TEXT(TXT) \
69 { \
70 label_progress->setText(TXT); \
71 m_systemTray->setToolTip(QString().sprintf("LameXP v%d.%02d\n%ls", lamexp_version_major(), lamexp_version_minor(), QString(TXT).utf16())); \
72 }
73
c967a01 @lordmulder Properly map the popup menu position to global coordinates.
authored
74 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
75
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
76 ////////////////////////////////////////////////////////////
77 // Constructor
78 ////////////////////////////////////////////////////////////
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
79
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
80 ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent)
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
81 :
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
82 QDialog(parent),
0534264 @lordmulder WMA decoding support. Limitations in the WMA decoder we cannot do any…
authored
83 m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd_go.png"), this)),
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
84 m_settings(settings),
85 m_metaInfo(metaInfo)
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
86 {
87 //Init the dialog, from the .ui file
88 setupUi(this);
89 setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
092e664 @lordmulder More detailed error output when process failed to create + use UUID's…
authored
90
91 //Setup version info
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
92 label_versionInfo->setText(QString().sprintf("v%d.%02d %s (Build %d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build()));
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
93 label_versionInfo->installEventFilter(this);
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
94
092e664 @lordmulder More detailed error output when process failed to create + use UUID's…
authored
95 //Register meta type
96 qRegisterMetaType<QUuid>("QUuid");
97
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
98 //Center window in screen
99 QRect desktopRect = QApplication::desktop()->screenGeometry();
100 QRect thisRect = this->geometry();
101 move((desktopRect.width() - thisRect.width()) / 2, (desktopRect.height() - thisRect.height()) / 2);
102 setMinimumSize(thisRect.width(), thisRect.height());
103
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
104 //Enable buttons
105 connect(button_AbortProcess, SIGNAL(clicked()), this, SLOT(abortEncoding()));
106
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
107 //Init progress indicator
108 m_progressIndicator = new QMovie(":/images/Working.gif");
109 label_headerWorking->setMovie(m_progressIndicator);
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
110 progressBar->setValue(0);
111
112 //Init progress model
113 m_progressModel = new ProgressModel();
114 view_log->setModel(m_progressModel);
115 view_log->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
116 view_log->verticalHeader()->hide();
117 view_log->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
118 view_log->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
119 connect(m_progressModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
120 connect(m_progressModel, SIGNAL(modelReset()), this, SLOT(progressModelChanged()));
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
121 connect(view_log, SIGNAL(activated(QModelIndex)), this, SLOT(logViewDoubleClicked(QModelIndex)));
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
122
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
123 //Create context menu
124 m_contextMenu = new QMenu();
b12e524 @lordmulder Add option "Brose Output File Location" to context menu in processing…
authored
125 QAction *contextMenuDetailsAction = m_contextMenu->addAction(QIcon(":/icons/zoom.png"), tr("Show details for selected job"));
126 QAction *contextMenuShowFileAction = m_contextMenu->addAction(QIcon(":/icons/folder_go.png"), tr("Browse Output File Location"));
127
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
128 view_log->setContextMenuPolicy(Qt::CustomContextMenu);
129 connect(view_log, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
b12e524 @lordmulder Add option "Brose Output File Location" to context menu in processing…
authored
130 connect(contextMenuDetailsAction, SIGNAL(triggered(bool)), this, SLOT(contextMenuDetailsActionTriggered()));
131 connect(contextMenuShowFileAction, SIGNAL(triggered(bool)), this, SLOT(contextMenuShowFileActionTriggered()));
c967a01 @lordmulder Properly map the popup menu position to global coordinates.
authored
132 SET_FONT_BOLD(contextMenuDetailsAction, true);
133
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
134 //Enque jobs
135 if(fileListModel)
136 {
137 for(int i = 0; i < fileListModel->rowCount(); i++)
138 {
139 m_pendingJobs.append(fileListModel->getFile(fileListModel->index(i,0)));
140 }
141 }
142
5a1ff67 @lordmulder Make more strings translatable.
authored
143 //Translate
144 label_headerStatus->setText(QString("<b>%1</b><br>%2").arg(tr("Encoding Files"), tr("Your files are being encoded, please be patient...")));
145
18bed9e @lordmulder Added a system tray icon.
authored
146 //Enable system tray icon
147 connect(m_systemTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systemTrayActivated(QSystemTrayIcon::ActivationReason)));
148
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
149 //Init other vars
150 m_runningThreads = 0;
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
151 m_currentFile = 0;
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
152 m_allJobs.clear();
153 m_succeededJobs.clear();
154 m_failedJobs.clear();
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
155 m_userAborted = false;
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
156 }
157
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
158 ////////////////////////////////////////////////////////////
159 // Destructor
160 ////////////////////////////////////////////////////////////
161
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
162 ProcessingDialog::~ProcessingDialog(void)
163 {
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
164 view_log->setModel(NULL);
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
165 if(m_progressIndicator) m_progressIndicator->stop();
166 LAMEXP_DELETE(m_progressIndicator);
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
167 LAMEXP_DELETE(m_progressModel);
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
168 LAMEXP_DELETE(m_contextMenu);
18bed9e @lordmulder Added a system tray icon.
authored
169 LAMEXP_DELETE(m_systemTray);
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
170
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
171 WinSevenTaskbar::setOverlayIcon(this, NULL);
172 WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState);
173
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
174 while(!m_threadList.isEmpty())
175 {
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
176 ProcessThread *thread = m_threadList.takeFirst();
177 thread->terminate();
178 thread->wait(15000);
179 delete thread;
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
180 }
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
181 }
182
183 ////////////////////////////////////////////////////////////
184 // EVENTS
185 ////////////////////////////////////////////////////////////
186
187 void ProcessingDialog::showEvent(QShowEvent *event)
188 {
189 setCloseButtonEnabled(false);
190 button_closeDialog->setEnabled(false);
191 button_AbortProcess->setEnabled(false);
18bed9e @lordmulder Added a system tray icon.
authored
192 m_systemTray->setVisible(true);
193
9947e9c @lordmulder Detect the entry points for some of the Win32 API functions on Runtim…
authored
194 if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
195 {
196 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
197 }
198
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
199 QTimer::singleShot(1000, this, SLOT(initEncoding()));
200 }
201
202 void ProcessingDialog::closeEvent(QCloseEvent *event)
203 {
18bed9e @lordmulder Added a system tray icon.
authored
204 if(!button_closeDialog->isEnabled())
205 {
206 event->ignore();
207 }
208 else
209 {
210 m_systemTray->setVisible(false);
211 }
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
212 }
213
214 bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
215 {
216 static QColor defaultColor = QColor();
217
218 if(obj == label_versionInfo)
219 {
220 if(event->type() == QEvent::Enter)
221 {
222 QPalette palette = label_versionInfo->palette();
223 defaultColor = palette.color(QPalette::Normal, QPalette::WindowText);
224 palette.setColor(QPalette::Normal, QPalette::WindowText, Qt::red);
225 label_versionInfo->setPalette(palette);
226 }
227 else if(event->type() == QEvent::Leave)
228 {
229 QPalette palette = label_versionInfo->palette();
230 palette.setColor(QPalette::Normal, QPalette::WindowText, defaultColor);
231 label_versionInfo->setPalette(palette);
232 }
233 else if(event->type() == QEvent::MouseButtonPress)
234 {
235 QUrl url("http://mulder.dummwiedeutsch.de/");
236 QDesktopServices::openUrl(url);
237 }
238 }
239
240 return false;
241 }
242
243 ////////////////////////////////////////////////////////////
244 // SLOTS
245 ////////////////////////////////////////////////////////////
246
247 void ProcessingDialog::initEncoding(void)
248 {
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
249 m_runningThreads = 0;
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
250 m_currentFile = 0;
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
251 m_allJobs.clear();
252 m_succeededJobs.clear();
253 m_failedJobs.clear();
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
254 m_userAborted = false;
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
255 m_playList.clear();
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
256
d6e5b9e @lordmulder AAC decoding support added.
authored
257 CHANGE_BACKGROUND_COLOR(frame_header, QColor(Qt::white));
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
258 SET_PROGRESS_TEXT(tr("Encoding files, please wait..."));
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
259 m_progressIndicator->start();
260
261 button_closeDialog->setEnabled(false);
262 button_AbortProcess->setEnabled(true);
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
263 progressBar->setRange(0, m_pendingJobs.count());
264
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
265 WinSevenTaskbar::initTaskbar();
266 WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
267 WinSevenTaskbar::setTaskbarProgress(this, 0, m_pendingJobs.count());
268 WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/control_play_blue.png"));
269
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
270 lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
d9e775b @lordmulder Show notification in progress window, if multi-threading is activated.
authored
271 int parallelThreadCount = max(min(min(cpuFeatures.count, m_pendingJobs.count()), 4), 1);
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
272
d9e775b @lordmulder Show notification in progress window, if multi-threading is activated.
authored
273 if(parallelThreadCount > 1)
274 {
275 m_progressModel->addSystemMessage(tr("Multi-threading enabled: Running %1 instances in parallel!").arg(QString::number(parallelThreadCount)));
276 }
277
278 for(int i = 0; i < parallelThreadCount; i++)
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
279 {
280 startNextJob();
281 }
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
282 }
283
284 void ProcessingDialog::abortEncoding(void)
285 {
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
286 m_userAborted = true;
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
287 button_AbortProcess->setEnabled(false);
288
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
289 SET_PROGRESS_TEXT(tr("Aborted! Waiting for running jobs to terminate..."));
d6e5b9e @lordmulder AAC decoding support added.
authored
290
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
291 for(int i = 0; i < m_threadList.count(); i++)
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
292 {
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
293 m_threadList.at(i)->abort();
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
294 }
295 }
296
297 void ProcessingDialog::doneEncoding(void)
298 {
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
299 m_runningThreads--;
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
300 progressBar->setValue(progressBar->value() + 1);
d6e5b9e @lordmulder AAC decoding support added.
authored
301
302 if(!m_userAborted)
303 {
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
304 SET_PROGRESS_TEXT(tr("Encoding: %1 files of %2 completed so far, please wait...").arg(QString::number(progressBar->value()), QString::number(progressBar->maximum())));
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
305 WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
d6e5b9e @lordmulder AAC decoding support added.
authored
306 }
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
307
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
308 int index = m_threadList.indexOf(dynamic_cast<ProcessThread*>(QWidget::sender()));
309 if(index >= 0)
310 {
311 m_threadList.takeAt(index)->deleteLater();
312 }
313
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
314 if(!m_pendingJobs.isEmpty() && !m_userAborted)
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
315 {
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
316 startNextJob();
317 qDebug("Running jobs: %u", m_runningThreads);
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
318 return;
319 }
320
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
321 if(m_runningThreads > 0)
322 {
323 qDebug("Running jobs: %u", m_runningThreads);
324 return;
325 }
326
4fd8ec0 @lordmulder Addded context menu to "source file" view + make the "output folder" …
authored
327 QApplication::setOverrideCursor(Qt::WaitCursor);
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
328 qDebug("Running jobs: %u", m_runningThreads);
329
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
330 if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir())
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
331 {
c4e0415 @lordmulder Fix to more typos.
authored
332 SET_PROGRESS_TEXT(tr("Creating the playlist file, please wait..."));
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
333 QApplication::processEvents();
334 writePlayList();
335 }
336
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
337 if(m_userAborted)
338 {
d6e5b9e @lordmulder AAC decoding support added.
authored
339 CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA"));
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
340 WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
341 WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/error.png"));
f6465c7 @lordmulder Make 5 more strings translatable.
authored
342 SET_PROGRESS_TEXT((m_succeededJobs.count() > 0) ? tr("Process was aborted by the user after %1 file(s)!").arg(QString::number(m_succeededJobs.count())) : tr("Process was aborted prematurely by the user!"));
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
343 m_systemTray->showMessage(tr("LameXP - Aborted"), tr("Process was aborted by the user."), QSystemTrayIcon::Warning);
0534264 @lordmulder WMA decoding support. Limitations in the WMA decoder we cannot do any…
authored
344 m_systemTray->setIcon(QIcon(":/icons/cd_delete.png"));
09bac5a @lordmulder Add more SFX for the user's pleasure.
authored
345 QApplication::processEvents();
53a1bf6 @lordmulder Implement update reminder + added options to disable the update remin…
authored
346 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
347 }
348 else
349 {
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
350 if(m_failedJobs.count() > 0)
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
351 {
d6e5b9e @lordmulder AAC decoding support added.
authored
352 CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFBABA"));
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
353 WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
354 WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/exclamation.png"));
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
355 SET_PROGRESS_TEXT(tr("Error: %1 of %2 files failed. Double-click failed items for detailed information!").arg(QString::number(m_failedJobs.count()), QString::number(m_failedJobs.count() + m_succeededJobs.count())));
356 m_systemTray->showMessage(tr("LameXP - Error"), tr("At least one file has failed!"), QSystemTrayIcon::Critical);
0534264 @lordmulder WMA decoding support. Limitations in the WMA decoder we cannot do any…
authored
357 m_systemTray->setIcon(QIcon(":/icons/cd_delete.png"));
09bac5a @lordmulder Add more SFX for the user's pleasure.
authored
358 QApplication::processEvents();
53a1bf6 @lordmulder Implement update reminder + added options to disable the update remin…
authored
359 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
360 }
361 else
362 {
fc148e5 @lordmulder Implement filter framework + currently only the "downmix" filter is i…
authored
363 CHANGE_BACKGROUND_COLOR(frame_header, QColor("#E0FFE2"));
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
364 WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
365 WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/accept.png"));
979205e @lordmulder Fixed one typo.
authored
366 SET_PROGRESS_TEXT(tr("All files completed successfully."));
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
367 m_systemTray->showMessage(tr("LameXP - Done"), tr("All files completed successfully."), QSystemTrayIcon::Information);
0534264 @lordmulder WMA decoding support. Limitations in the WMA decoder we cannot do any…
authored
368 m_systemTray->setIcon(QIcon(":/icons/cd_add.png"));
09bac5a @lordmulder Add more SFX for the user's pleasure.
authored
369 QApplication::processEvents();
53a1bf6 @lordmulder Implement update reminder + added options to disable the update remin…
authored
370 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_SUCCESS), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
371 }
372 }
373
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
374 setCloseButtonEnabled(true);
375 button_closeDialog->setEnabled(true);
376 button_AbortProcess->setEnabled(false);
377
a29780e @lordmulder Don't try to encode from source files that aren't supported by the en…
authored
378 view_log->scrollToBottom();
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
379 m_progressIndicator->stop();
c2f1320 @lordmulder Added support for Windows 7 taskbar features (progress and overlay ic…
authored
380 progressBar->setValue(progressBar->maximum());
381 WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
4fd8ec0 @lordmulder Addded context menu to "source file" view + make the "output folder" …
authored
382
383 QApplication::restoreOverrideCursor();
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
384 }
385
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
386 void ProcessingDialog::processFinished(const QUuid &jobId, const QString &outFileName, bool success)
387 {
388 if(success)
389 {
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
390 m_playList.insert(jobId, outFileName);
391 m_succeededJobs.append(jobId);
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
392 }
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
393 else
394 {
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
395 m_failedJobs.append(jobId);
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
396 }
397 }
398
399 void ProcessingDialog::progressModelChanged(void)
400 {
401 view_log->scrollToBottom();
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
402 }
403
c0ece99 @lordmulder Implemented logging and added a log file view.
authored
404 void ProcessingDialog::logViewDoubleClicked(const QModelIndex &index)
405 {
406 if(m_runningThreads == 0)
407 {
408 const QStringList &logFile = m_progressModel->getLogFile(index);
d9e775b @lordmulder Show notification in progress window, if multi-threading is activated.
authored
409
410 if(!logFile.isEmpty())
411 {
412 LogViewDialog *logView = new LogViewDialog(this);
413 logView->setWindowTitle(QString("LameXP - [%1]").arg(m_progressModel->data(index, Qt::DisplayRole).toString()));
414 logView->exec(logFile);
415 LAMEXP_DELETE(logView);
416 }
417 else
418 {
419 MessageBeep(MB_ICONWARNING);
420 }
c0ece99 @lordmulder Implemented logging and added a log file view.
authored
421 }
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
422 else
423 {
424 MessageBeep(MB_ICONWARNING);
425 }
426 }
427
428 void ProcessingDialog::contextMenuTriggered(const QPoint &pos)
429 {
c967a01 @lordmulder Properly map the popup menu position to global coordinates.
authored
430 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
431 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
432
433 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
38d60fe @lordmulder Fix context menu in progress dialog.
authored
434 {
c967a01 @lordmulder Properly map the popup menu position to global coordinates.
authored
435 m_contextMenu->popup(sender->mapToGlobal(pos));
38d60fe @lordmulder Fix context menu in progress dialog.
authored
436 }
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
437 }
438
b12e524 @lordmulder Add option "Brose Output File Location" to context menu in processing…
authored
439 void ProcessingDialog::contextMenuDetailsActionTriggered(void)
571df62 @lordmulder Implement support for Job Objects + improve log view.
authored
440 {
441 QModelIndex index = view_log->indexAt(view_log->mapFromGlobal(m_contextMenu->pos()));
442 logViewDoubleClicked(index.isValid() ? index : view_log->currentIndex());
c0ece99 @lordmulder Implemented logging and added a log file view.
authored
443 }
444
b12e524 @lordmulder Add option "Brose Output File Location" to context menu in processing…
authored
445 void ProcessingDialog::contextMenuShowFileActionTriggered(void)
446 {
447 QModelIndex index = view_log->indexAt(view_log->mapFromGlobal(m_contextMenu->pos()));
448 const QUuid &jobId = m_progressModel->getJobId(index.isValid() ? index : view_log->currentIndex());
449 QString filePath = m_playList.value(jobId, QString());
450
451 if(filePath.isEmpty())
452 {
453 MessageBeep(MB_ICONWARNING);
454 return;
455 }
456
457 if(QFileInfo(filePath).exists())
458 {
459 QString systemRootPath;
460
461 QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
462 if(systemRoot.exists() && systemRoot.cdUp())
463 {
464 systemRootPath = systemRoot.canonicalPath();
465 }
466
467 if(!systemRootPath.isEmpty())
468 {
469 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
470 if(explorer.exists() && explorer.isFile())
471 {
472 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(QFileInfo(filePath).canonicalFilePath()));
473 return;
474 }
475 }
476 else
477 {
478 qWarning("SystemRoot directory could not be detected!");
479 }
480 }
481 else
482 {
483 qWarning("File not found: %s", filePath.toLatin1().constData());
484 MessageBeep(MB_ICONERROR);
485 }
486 }
487
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
488 ////////////////////////////////////////////////////////////
489 // Private Functions
490 ////////////////////////////////////////////////////////////
491
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
492 void ProcessingDialog::startNextJob(void)
493 {
494 if(m_pendingJobs.isEmpty())
495 {
496 return;
497 }
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
498
499 m_currentFile++;
500 AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst());
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
501 AbstractEncoder *encoder = NULL;
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
502 bool nativeResampling = false;
e6460b9 @lordmulder FLAC encoding support.
authored
503
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
504 switch(m_settings->compressionEncoder())
505 {
506 case SettingsModel::MP3Encoder:
507 {
508 MP3Encoder *mp3Encoder = new MP3Encoder();
509 mp3Encoder->setBitrate(m_settings->compressionBitrate());
510 mp3Encoder->setRCMode(m_settings->compressionRCMode());
476edeb @lordmulder Initial support for advanced options. Only "LAME Algorithm Quality" s…
authored
511 mp3Encoder->setAlgoQuality(m_settings->lameAlgoQuality());
3f0796d @lordmulder Added support for bitrate management to LAME and OggEnc2 encoders.
authored
512 if(m_settings->bitrateManagementEnabled())
513 {
514 mp3Encoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate());
515 }
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
516 if(m_settings->samplingRate() > 0)
517 {
518 mp3Encoder->setSamplingRate(SettingsModel::samplingRates[m_settings->samplingRate()]);
519 nativeResampling = true;
520 }
7e44c69 @lordmulder Actually make the Nero AAC Profile/2-Pass options work. Also make the…
authored
521 mp3Encoder->setChannelMode(m_settings->lameChannelMode());
cfb20fe @lordmulder Added support for custom encoder parameters.
authored
522 mp3Encoder->setCustomParams(m_settings->customParametersLAME());
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
523 encoder = mp3Encoder;
524 }
525 break;
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
526 case SettingsModel::VorbisEncoder:
527 {
528 VorbisEncoder *vorbisEncoder = new VorbisEncoder();
529 vorbisEncoder->setBitrate(m_settings->compressionBitrate());
530 vorbisEncoder->setRCMode(m_settings->compressionRCMode());
3f0796d @lordmulder Added support for bitrate management to LAME and OggEnc2 encoders.
authored
531 if(m_settings->bitrateManagementEnabled())
532 {
533 vorbisEncoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate());
534 }
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
535 if(m_settings->samplingRate() > 0)
536 {
537 vorbisEncoder->setSamplingRate(SettingsModel::samplingRates[m_settings->samplingRate()]);
538 nativeResampling = true;
539 }
cfb20fe @lordmulder Added support for custom encoder parameters.
authored
540 vorbisEncoder->setCustomParams(m_settings->customParametersOggEnc());
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
541 encoder = vorbisEncoder;
542 }
543 break;
be4ce0d @lordmulder Added AAC encoding support.
authored
544 case SettingsModel::AACEncoder:
545 {
546 AACEncoder *aacEncoder = new AACEncoder();
547 aacEncoder->setBitrate(m_settings->compressionBitrate());
548 aacEncoder->setRCMode(m_settings->compressionRCMode());
7e44c69 @lordmulder Actually make the Nero AAC Profile/2-Pass options work. Also make the…
authored
549 aacEncoder->setEnable2Pass(m_settings->neroAACEnable2Pass());
550 aacEncoder->setProfile(m_settings->neroAACProfile());
cfb20fe @lordmulder Added support for custom encoder parameters.
authored
551 aacEncoder->setCustomParams(m_settings->customParametersNeroAAC());
be4ce0d @lordmulder Added AAC encoding support.
authored
552 encoder = aacEncoder;
553 }
554 break;
e6460b9 @lordmulder FLAC encoding support.
authored
555 case SettingsModel::FLACEncoder:
556 {
557 FLACEncoder *flacEncoder = new FLACEncoder();
558 flacEncoder->setBitrate(m_settings->compressionBitrate());
559 flacEncoder->setRCMode(m_settings->compressionRCMode());
cfb20fe @lordmulder Added support for custom encoder parameters.
authored
560 flacEncoder->setCustomParams(m_settings->customParametersFLAC());
e6460b9 @lordmulder FLAC encoding support.
authored
561 encoder = flacEncoder;
562 }
563 break;
e189eb0 @lordmulder Support for Wave (PCM) output.
authored
564 case SettingsModel::PCMEncoder:
565 {
566 WaveEncoder *waveEncoder = new WaveEncoder();
567 waveEncoder->setBitrate(m_settings->compressionBitrate());
568 waveEncoder->setRCMode(m_settings->compressionRCMode());
569 encoder = waveEncoder;
570 }
571 break;
1633489 @lordmulder Actually use selected encoder in progress dialog + forward output dir.
authored
572 default:
573 throw "Unsupported encoder!";
574 }
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
575
063c530 @lordmulder Added an option to prepend the source file's relative path to the out…
authored
576 ProcessThread *thread = new ProcessThread
577 (
578 currentFile,
579 (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath(): m_settings->outputDir()),
580 encoder,
581 m_settings->prependRelativeSourcePath()
582 );
58ded8c @lordmulder Added a normalization filter, based on SoX.
authored
583
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
584 if((m_settings->samplingRate() > 0) && !nativeResampling)
585 {
c1cde1a @lordmulder Invoke the "resampling" filter only if the target sampling rate is re…
authored
586 if(SettingsModel::samplingRates[m_settings->samplingRate()] != currentFile.formatAudioSamplerate() || currentFile.formatAudioSamplerate() == 0)
587 {
588 thread->addFilter(new ResampleFilter(SettingsModel::samplingRates[m_settings->samplingRate()]));
589 }
d13050c @lordmulder Added "Resample" filter, based on SoX. Used for encoders that don't s…
authored
590 }
591 if((m_settings->toneAdjustBass() != 0) || (m_settings->toneAdjustTreble() != 0))
592 {
593 thread->addFilter(new ToneAdjustFilter(m_settings->toneAdjustBass(), m_settings->toneAdjustTreble()));
594 }
58ded8c @lordmulder Added a normalization filter, based on SoX.
authored
595 if(m_settings->normalizationFilterEnabled())
596 {
597 thread->addFilter(new NormalizeFilter(m_settings->normalizationFilterMaxVolume()));
598 }
599
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
600 m_threadList.append(thread);
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
601 m_allJobs.append(thread->getId());
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
602
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
603 connect(thread, SIGNAL(finished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
604 connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel, SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
605 connect(thread, SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel, SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection);
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
606 connect(thread, SIGNAL(processStateFinished(QUuid,QString,bool)), this, SLOT(processFinished(QUuid,QString,bool)), Qt::QueuedConnection);
c0ece99 @lordmulder Implemented logging and added a log file view.
authored
607 connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel, SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection);
11f57ae @lordmulder Ogg Vorbis encoding support.
authored
608
28a926b @lordmulder Implement multi-theaded processing in progress dialog.
authored
609 m_runningThreads++;
610 thread->start();
611 }
612
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
613 void ProcessingDialog::writePlayList(void)
614 {
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
615 if(m_succeededJobs.count() <= 0 || m_allJobs.count() <= 0)
616 {
617 qWarning("WritePlayList: Nothing to do!");
618 return;
619 }
620
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
621 QString playListName = (m_metaInfo->fileAlbum().isEmpty() ? "Playlist" : m_metaInfo->fileAlbum());
622
623 const static char *invalidChars = "\\/:*?\"<>|";
624 for(int i = 0; invalidChars[i]; i++)
625 {
626 playListName.replace(invalidChars[i], ' ');
627 playListName = playListName.simplified();
628 }
629
630 QString playListFile = QString("%1/%2.m3u").arg(m_settings->outputDir(), playListName);
631
632 int counter = 1;
633 while(QFileInfo(playListFile).exists())
634 {
635 playListFile = QString("%1/%2 (%3).m3u").arg(m_settings->outputDir(), playListName, QString::number(++counter));
636 }
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
637
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
638 QFile playList(playListFile);
639 if(playList.open(QIODevice::WriteOnly))
640 {
641 playList.write("#EXTM3U\r\n");
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
642 for(int i = 0; i < m_allJobs.count(); i++)
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
643 {
6491965 @lordmulder Add items to the playlist in the order the jobs are created, rather t…
authored
644
645 if(!m_succeededJobs.contains(m_allJobs.at(i))) continue;
063c530 @lordmulder Added an option to prepend the source file's relative path to the out…
authored
646 playList.write(QDir::toNativeSeparators(QDir(m_settings->outputDir()).relativeFilePath(m_playList.value(m_allJobs.at(i), "N/A"))).toUtf8().constData());
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
647 playList.write("\r\n");
648 }
649 playList.close();
650 }
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
651 else
652 {
8c0fa11 @lordmulder make more strings translatable + try to load a default translation th…
authored
653 QMessageBox::warning(this, tr("Playlist creation failed"), QString("%1<br><nobr>%2</nobr>").arg(tr("The playlist file could not be created:"), playListFile));
47a6c2f @lordmulder Make "Save output files to the same location where the input file is …
authored
654 }
970f2cd @lordmulder Create playlist file + serialize filename generation, just to be sure.
authored
655 }
656
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
657 AudioFileModel ProcessingDialog::updateMetaInfo(const AudioFileModel &audioFile)
658 {
659 if(!m_settings->writeMetaTags())
660 {
0fd4b56 @lordmulder Refactor audio file model.
authored
661 return AudioFileModel(audioFile, false);
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
662 }
663
664 AudioFileModel result = audioFile;
0fd4b56 @lordmulder Refactor audio file model.
authored
665 result.updateMetaInfo(*m_metaInfo);
666
667 if(m_metaInfo->filePosition() == UINT_MAX)
668 {
669 result.setFilePosition(m_currentFile);
670 }
cffa6a2 @lordmulder Correctly forward meta info to MP3 encoder and apply.
authored
671
672 return result;
673 }
674
3170f35 @lordmulder Implement processing thread and connect to processing dialog.
authored
675 void ProcessingDialog::setCloseButtonEnabled(bool enabled)
676 {
677 HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
678 EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED));
7a79c47 @lordmulder Implemented processing dialog, no functionality yet.
authored
679 }
18bed9e @lordmulder Added a system tray icon.
authored
680
681 void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason reason)
682 {
683 if(reason == QSystemTrayIcon::DoubleClick)
684 {
685 SetForegroundWindow(this->winId());
686 }
687 }
Something went wrong with that request. Please try again.