OSDN Git Service

Updated VS2012 project file.
[lamexp/LameXP.git] / src / Dialog_About.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
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_About.h"
23
24 #include "Global.h"
25 #include "Resource.h"
26 #include "Model_Settings.h"
27
28 #include <QDate>
29 #include <QApplication>
30 #include <QIcon>
31 #include <QPushButton>
32 #include <QDesktopServices>
33 #include <QUrl>
34 #include <QTimer>
35 #include <QFileInfo>
36 #include <QDir>
37 #include <QDesktopWidget>
38 #include <QLabel>
39 #include <QMessageBox>
40 #include <QTextStream>
41 #include <QScrollBar>
42 #include <QCloseEvent>
43 #include <QWindowsVistaStyle>
44 #include <QWindowsXPStyle>
45
46 #include <ShellAPI.h>
47 #include <MMSystem.h>
48 #include <math.h>
49
50 //Helper macros
51 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "&minus;"))
52 #define TRIM_RIGHT(STR) do { while(STR.endsWith(QChar(' ')) || STR.endsWith(QChar('\t')) || STR.endsWith(QChar('\r')) || STR.endsWith(QChar('\n'))) STR.chop(1); } while(0)
53 #define MAKE_TRANSPARENT(WIDGET) do { QPalette _p = (WIDGET)->palette(); _p.setColor(QPalette::Background, Qt::transparent); (WIDGET)->setPalette(_p); } while(0)
54
55
56 //Constants
57 const char *AboutDialog::neroAacUrl = "http://www.nero.com/eng/technologies-aac-codec.html";
58 const char *AboutDialog::disqueUrl =  "http://mulder.brhack.net/?player_url=38X-MXOB014"; //http://mulder.brhack.net/?player_url=yF6W-w0iAMM; http://www.youtube.com/watch_popup?v=yF6W-w0iAMM&vq=large
59
60 //Contributors
61 static const struct 
62 {
63         char *pcFlag;
64         wchar_t *pcLanguage;
65         wchar_t *pcName;
66         char *pcMail;
67 }
68 g_lamexp_translators[] =
69 {
70         {"en", L"Englisch",   L"LoRd_MuldeR",         "MuldeR2@GMX.de"        },
71         {"de", L"Deutsch",    L"LoRd_MuldeR",         "MuldeR2@GMX.de"        },
72         {"",   L"",           L"Bodo Thevissen",      "Bodo@thevissen.de"     },
73         {"es", L"Español",    L"Rub3nCT",             "Rub3nCT@gmail.com"     },
74         {"fr", L"Française",  L"Dodich Informatique", "Dodich@live.fr"        },
75         {"it", L"Italiano",   L"Roberto",             "Gulliver_69@libero.it" },
76         {"kr", L"한국어",        L"JaeHyung Lee",        "Kolanp@gmail.com"      },
77         {"pl", L"Polski",     L"Sir Daniel K",        "Sir.Daniel.K@gmail.com"},
78         {"ru", L"Русский",    L"Neonailol",           "Neonailol@gmail.com"   },
79         {"",   L"",           L"Иван Митин",          "bardak@inbox.ru"       },
80         {"sv", L"Svenska",    L"Åke Engelbrektson",   "eson57@gmail.com"      },
81         {"tw", L"繁体中文",       L"456Vv",               "123@456vv.com"         },
82         {"uk", L"Українська", L"Arestarh",            "Arestarh@ukr.net"      },
83         {"zh", L"简体中文",       L"456Vv",               "123@456vv.com"         },
84         {NULL, NULL, NULL, NULL}
85 };
86
87 ////////////////////////////////////////////////////////////
88 // Constructor
89 ////////////////////////////////////////////////////////////
90
91 AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstStart)
92 :
93         QDialog(parent),
94         m_settings(settings),
95         m_initFlags(new QMap<QWidget*,bool>),
96         m_disque(NULL),
97         m_disqueTimer(NULL),
98         m_rotateNext(false),
99         m_disqueDelay(_I64_MAX),
100         m_lastTab(0)
101 {
102         //Init the dialog, from the .ui file
103         setupUi(this);
104         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
105         resize(this->minimumSize());
106         
107         //Disable "X" button
108         if(firstStart)
109         {
110                 if(HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE))
111                 {
112                         EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
113                 }
114         }
115
116         //Init images
117         for(int i = 0; i < 4; i++)
118         {
119                 m_cartoon[i] = NULL;
120         }
121
122         //Init tab widget
123         connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
124
125         //Make transparent
126         QStyle *style = qApp->style();
127         if((dynamic_cast<QWindowsVistaStyle*>(style)) || (dynamic_cast<QWindowsXPStyle*>(style)))
128         {
129                 MAKE_TRANSPARENT(infoScrollArea);
130                 MAKE_TRANSPARENT(contributorsScrollArea);
131                 MAKE_TRANSPARENT(softwareScrollArea);
132                 MAKE_TRANSPARENT(licenseScrollArea);
133         }
134
135         //Show about dialog for the first time?
136         if(!firstStart)
137         {
138                 lamexp_seed_rand();
139
140                 acceptButton->hide();
141                 declineButton->hide();
142                 aboutQtButton->show();
143                 closeButton->show();
144
145                 QPixmap disque(":/images/Disque.png");
146                 QRect screenGeometry = QApplication::desktop()->availableGeometry();
147                 m_disque = new QLabel(this, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
148                 m_disque->installEventFilter(this);
149                 m_disque->setStyleSheet("background:transparent;");
150                 m_disque->setAttribute(Qt::WA_TranslucentBackground);
151                 m_disque->setGeometry(static_cast<int>(lamexp_rand() % static_cast<unsigned int>(screenGeometry.width() - disque.width())), static_cast<int>(lamexp_rand() % static_cast<unsigned int>(screenGeometry.height() - disque.height())), disque.width(), disque.height());
152                 m_disque->setPixmap(disque);
153                 m_disque->setWindowOpacity(0.01);
154                 m_disque->show();
155                 m_disqueFlags[0] = (lamexp_rand() > (UINT_MAX/2));
156                 m_disqueFlags[1] = (lamexp_rand() > (UINT_MAX/2));
157                 m_disqueTimer = new QTimer;
158                 connect(m_disqueTimer, SIGNAL(timeout()), this, SLOT(moveDisque()));
159                 m_disqueTimer->setInterval(10);
160                 m_disqueTimer->start();
161
162                 connect(aboutQtButton, SIGNAL(clicked()), this, SLOT(showAboutQt()));
163         }
164         else
165         {
166                 acceptButton->show();
167                 declineButton->show();
168                 aboutQtButton->hide();
169                 closeButton->hide();
170         }
171
172         //Activate "show license" button
173         showLicenseButton->show();
174         connect(showLicenseButton, SIGNAL(clicked()), this, SLOT(gotoLicenseTab()));
175
176         m_firstShow = firstStart;
177 }
178
179 AboutDialog::~AboutDialog(void)
180 {
181         if(m_disque)
182         {
183                 m_disque->close();
184                 LAMEXP_DELETE(m_disque);
185         }
186         if(m_disqueTimer)
187         {
188                 m_disqueTimer->stop();
189                 LAMEXP_DELETE(m_disqueTimer);
190         }
191         for(int i = 0; i < 4; i++)
192         {
193                 LAMEXP_DELETE(m_cartoon[i]);
194         }
195         LAMEXP_DELETE(m_initFlags);
196 }
197
198 ////////////////////////////////////////////////////////////
199 // Public Functions
200 ////////////////////////////////////////////////////////////
201
202 int AboutDialog::exec()
203 {
204         if(m_settings->soundsEnabled())
205         {
206                 if(m_firstShow)
207                 {
208                         if(!playResoureSound("imageres.dll", 5080, true))
209                         {
210                                 PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS | SND_ASYNC);
211                         }
212                 }
213                 else
214                 {
215                         PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
216                 }
217         }
218         
219         switch(QDialog::exec())
220         {
221         case 1:
222                 return 1;
223                 break;
224         case 2:
225                 return -1;
226                 break;
227         default:
228                 return 0;
229                 break;
230         }
231 }
232
233 ////////////////////////////////////////////////////////////
234 // Slots
235 ////////////////////////////////////////////////////////////
236
237 #define TEMP_HIDE_DISQUE(CMD) \
238 if(m_disque) { bool _tmp = m_disque->isVisible(); if(_tmp) m_disque->hide(); {CMD}; if(_tmp) { m_disque->show(); m_disque->setWindowOpacity(0.01); } } else {CMD}
239
240 void AboutDialog::tabChanged(int index)
241 {
242         bool bInitialized = m_initFlags->value(tabWidget->widget(index), false);
243
244         if(!bInitialized)
245         {
246                 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
247
248                 if(QWidget *tab = tabWidget->widget(index))
249                 {
250                         bool ok = false;
251
252                         if(tab == infoTab) { initInformationTab(); ok = true; }
253                         if(tab == contributorsTab) { initContributorsTab(); ok = true; }
254                         if(tab == softwareTab) { initSoftwareTab(); ok = true; }
255                         if(tab == licenseTab) { initLicenseTab(); ok = true; }
256
257                         if(ok)
258                         {
259                                 m_initFlags->insert(tab, true);
260                         }
261                         else
262                         {
263                                 qWarning("Unknown tab %p encountered, cannot initialize !!!", tab);
264                         }
265                         
266                 }
267
268                 tabWidget->widget(index)->update();
269                 qApp->processEvents();
270                 qApp->restoreOverrideCursor();
271         }
272
273         //Scroll to the top
274         if(QWidget *tab = tabWidget->widget(index))
275         {
276                 if(tab == infoTab) infoScrollArea->verticalScrollBar()->setSliderPosition(0);
277                 if(tab == contributorsTab) contributorsScrollArea->verticalScrollBar()->setSliderPosition(0);
278                 if(tab == softwareTab) softwareScrollArea->verticalScrollBar()->setSliderPosition(0);
279                 if(tab == licenseTab) licenseScrollArea->verticalScrollBar()->setSliderPosition(0);
280         }
281
282         //Update license button
283         showLicenseButton->setChecked(tabWidget->widget(index) == licenseTab);
284         if(tabWidget->widget(index) != licenseTab) m_lastTab = index;
285 }
286
287 void AboutDialog::enableButtons(void)
288 {
289         acceptButton->setEnabled(true);
290         declineButton->setEnabled(true);
291         setCursor(QCursor(Qt::ArrowCursor));
292 }
293
294 void AboutDialog::openURL(const QString &url)
295 {
296         if(!QDesktopServices::openUrl(QUrl(url)))
297         {
298                 ShellExecuteW(this->winId(), L"open", QWCHAR(url), NULL, NULL, SW_SHOW);
299         }
300 }
301
302 void AboutDialog::showAboutQt(void)
303 {
304         TEMP_HIDE_DISQUE
305         (
306                 QMessageBox::aboutQt(this);
307         );
308 }
309
310 void AboutDialog::gotoLicenseTab(void)
311 {
312         tabWidget->setCurrentIndex(tabWidget->indexOf(showLicenseButton->isChecked() ? licenseTab : tabWidget->widget(m_lastTab)));
313 }
314
315 void AboutDialog::moveDisque(void)
316 {
317         int delta = 2;
318         LARGE_INTEGER perfCount, perfFrequ;
319
320         if(QueryPerformanceFrequency(&perfFrequ) &&     QueryPerformanceCounter(&perfCount))
321         {
322                 if(m_disqueDelay != _I64_MAX)
323                 {
324                         const double delay = static_cast<double>(perfCount.QuadPart) - static_cast<double>(m_disqueDelay);
325                         delta = qMax(1, qMin(128, static_cast<int>(ceil(delay / static_cast<double>(perfFrequ.QuadPart) / 0.00512))));
326                 }
327                 m_disqueDelay = perfCount.QuadPart;
328         }
329
330         if(m_disque)
331         {
332                 QRect screenGeometry = QApplication::desktop()->availableGeometry();
333                 const int minX = screenGeometry.left();
334                 const int maxX = screenGeometry.width() - m_disque->width() + screenGeometry.left();
335                 const int minY = screenGeometry.top();
336                 const int maxY = screenGeometry.height() - m_disque->height() + screenGeometry.top();
337                 
338                 QPoint pos = m_disque->pos();
339                 pos.setX(m_disqueFlags[0] ? pos.x() + delta : pos.x() - delta);
340                 pos.setY(m_disqueFlags[1] ? pos.y() + delta : pos.y() - delta);
341
342                 if(pos.x() <= minX)
343                 {
344                         m_disqueFlags[0] = true;
345                         pos.setX(minX);
346                         m_rotateNext = true;
347                 }
348                 else if(pos.x() >= maxX)
349                 {
350                         m_disqueFlags[0] = false;
351                         pos.setX(maxX);
352                         m_rotateNext = true;
353                 }
354                 if(pos.y() <= minY)
355                 {
356                         m_disqueFlags[1] = true;
357                         pos.setY(minY);
358                         m_rotateNext = true;
359                 }
360                 else if(pos.y() >= maxY)
361                 {
362                         m_disqueFlags[1] = false;
363                         pos.setY(maxY);
364                         m_rotateNext = true;
365                 }
366
367                 m_disque->move(pos);
368
369                 if(m_rotateNext)
370                 {
371                         QPixmap *cartoon = NULL;
372                         if(m_disqueFlags[0] == true && m_disqueFlags[1] != true) cartoon = m_cartoon[0];
373                         if(m_disqueFlags[0] == true && m_disqueFlags[1] == true) cartoon = m_cartoon[1];
374                         if(m_disqueFlags[0] != true && m_disqueFlags[1] == true) cartoon = m_cartoon[2];
375                         if(m_disqueFlags[0] != true && m_disqueFlags[1] != true) cartoon = m_cartoon[3];
376                         if(cartoon)
377                         {
378                                 m_disque->setPixmap(*cartoon);
379                                 m_disque->resize(cartoon->size());
380                         }
381                         m_rotateNext = false;
382                 }
383
384                 if(m_disque->windowOpacity() < 0.9)
385                 {
386                         m_disque->setWindowOpacity(m_disque->windowOpacity() + 0.01);
387                 }
388         }
389 }
390
391 void AboutDialog::adjustSize(void)
392 {
393         int maximumHeight = QApplication::desktop()->availableGeometry().height();
394
395         int delta = infoScrollArea->widget()->height() - infoScrollArea->viewport()->height();
396         if(delta > 0)
397         {
398                 this->resize(this->width(), qMin(this->height() + delta, maximumHeight));
399                 this->move(this->x(), this->y() - (delta/2));
400                 this->setMinimumHeight(qMax(this->minimumHeight(), this->height()));
401         }
402 }
403
404 ////////////////////////////////////////////////////////////
405 // Protected Functions
406 ////////////////////////////////////////////////////////////
407
408 void AboutDialog::showEvent(QShowEvent *e)
409 {
410         QDialog::showEvent(e);
411         
412         tabWidget->setCurrentIndex(tabWidget->indexOf(infoTab));
413         tabChanged(m_lastTab = tabWidget->currentIndex());
414         
415         if(m_firstShow)
416         {
417                 acceptButton->setEnabled(false);
418                 declineButton->setEnabled(false);
419                 QTimer::singleShot(5000, this, SLOT(enableButtons()));
420                 setCursor(QCursor(Qt::WaitCursor));
421         }
422
423         QTimer::singleShot(0, this, SLOT(adjustSize()));
424 }
425
426 void AboutDialog::closeEvent(QCloseEvent *e)
427 {
428         if(m_firstShow) e->ignore();
429 }
430
431 bool AboutDialog::eventFilter(QObject *obj, QEvent *event)
432 {
433         if((obj == m_disque) && (event->type() == QEvent::MouseButtonPress))
434         {
435                 QPixmap cartoon(":/images/Cartoon.png");
436                 for(int i = 0; i < 4; i++)
437                 {
438                         if(!m_cartoon[i])
439                         {
440                                 m_cartoon[i] = new QPixmap(cartoon.transformed(QMatrix().rotate(static_cast<double>(i*90) + 45.0), Qt::SmoothTransformation));
441                                 m_rotateNext = true;
442                         }
443                 }
444                 QDesktopServices::openUrl(QUrl(disqueUrl));
445         }
446
447         return false;
448 }
449
450 ////////////////////////////////////////////////////////////
451 // Private Functions
452 ////////////////////////////////////////////////////////////
453
454 void AboutDialog::initInformationTab(void)
455 {
456         const QString versionStr = QString().sprintf
457         (
458                 "Version %d.%02d %s, Build %d [%s], %s %s, Qt v%s",
459                 lamexp_version_major(),
460                 lamexp_version_minor(),
461                 lamexp_version_release(),
462                 lamexp_version_build(),
463                 lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(),
464                 lamexp_version_compiler(),
465                 lamexp_version_arch(),
466                 qVersion()
467         );
468
469         const QString copyrightStr = QString().sprintf
470         (
471                 "Copyright (C) 2004-%04d LoRd_MuldeR &lt;MuldeR2@GMX.de&gt;. Some rights reserved.",
472                 qMax(lamexp_version_date().year(), QDate::currentDate().year())
473         );
474
475         QString aboutText;
476
477         aboutText += QString("<h2>%1</h2>").arg(NOBR(tr("LameXP - Audio Encoder Front-end")));
478         aboutText += QString("<b>%1</b><br>").arg(NOBR(copyrightStr));
479         aboutText += QString("<b>%1</b><br><br>").arg(NOBR(versionStr));
480         aboutText += QString("%1<br>").arg(NOBR(tr("Please visit %1 for news and updates!").arg(LINK(lamexp_website_url()))));
481
482 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
483         if(LAMEXP_DEBUG)
484         {
485                 int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0);
486                 aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(QString("!!! --- DEBUG BUILD --- Expires at: %1 &middot; Days left: %2 --- DEBUG BUILD --- !!!").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
487         }
488         else if(lamexp_version_demo())
489         {
490                 int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0);
491                 aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(tr("Note: This demo (pre-release) version of LameXP will expire at %1. Still %2 days left.").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
492         }
493 #else
494         if(LAMEXP_DEBUG)
495         {
496                 int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0i64);
497                 aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(QString("!!! --- DEBUG BUILD --- Expires at: %1 &middot; Days left: %2 --- DEBUG BUILD --- !!!").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
498         }
499         else if(lamexp_version_demo())
500         {
501                 int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0i64);
502                 aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(tr("Note: This demo (pre-release) version of LameXP will expire at %1. Still %2 days left.").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
503         }
504 #endif
505
506         aboutText += "<hr><br>";
507         aboutText += "<nobr><tt>This program is free software; you can redistribute it and/or<br>";
508         aboutText += "modify it under the terms of the GNU General Public License<br>";
509         aboutText += "as published by the Free Software Foundation; either version 2<br>";
510         aboutText += "of the License, or (at your option) any later version.<br><br>";
511         aboutText += "This program is distributed in the hope that it will be useful,<br>";
512         aboutText += "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>";
513         aboutText += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>";
514         aboutText += "GNU General Public License for more details.<br><br>";
515         aboutText += "You should have received a copy of the GNU General Public License<br>";
516         aboutText += "along with this program; if not, write to the Free Software<br>";
517         aboutText += "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110&minus;1301, USA.</tt></nobr><br>";
518         aboutText += "<hr><table style=\"margin-top:4px\"><tr>";
519         aboutText += "<td valign=\"middle\"><img src=\":/icons/error_big.png\"</td><td>&nbsp;</td>";
520         aboutText += QString("<td><font color=\"darkred\">%1</font></td>").arg(tr("Note: LameXP is free software. Do <b>not</b> pay money to obtain or use LameXP! If some third-party website tries to make you pay for downloading LameXP, you should <b>not</b> respond to the offer !!!"));
521         aboutText += "</tr></table>";
522         //aboutText += QString("%1<br>").arg(NOBR(tr("Special thanks go out to \"John33\" from %1 for his continuous support.")).arg(LINK("http://www.rarewares.org/")));
523
524         infoLabel->setText(aboutText);
525         infoIcon->setPixmap(lamexp_app_icon().pixmap(QSize(72,72)));
526         connect(infoLabel, SIGNAL(linkActivated(QString)), this, SLOT(openURL(QString)));
527 }
528
529 void AboutDialog::initContributorsTab(void)
530 {
531         const QString spaces("&nbsp;&nbsp;&nbsp;&nbsp;");
532         const QString extraVSpace("<font style=\"font-size:7px\"><br>&nbsp;</font>");
533         
534         QString contributorsAboutText;
535         contributorsAboutText += QString("<h3>%1</h3>").arg(NOBR(tr("The following people have contributed to LameXP:")));
536         contributorsAboutText += "<table style=\"margin-top:12px;white-space:nowrap\">";
537         
538         contributorsAboutText += QString("<tr><td colspan=\"7\"><b>%1</b>%2</td></tr>").arg(tr("Programmers:"), extraVSpace);
539         QString icon = QString("<img src=\":/icons/%1.png\">").arg("user_gray");
540         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(icon, spaces);
541         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td>").arg(tr("Project Leader"), spaces);
542         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td><a href=\"mailto:%2\">&lt;%3&gt;</a></td></tr>").arg("LoRd_MuldeR", spaces, "MuldeR2@GMX.de");
543         contributorsAboutText += QString("<tr><td colspan=\"7\"><b>&nbsp;</b></td></tr>");
544
545         contributorsAboutText += QString("<tr><td colspan=\"7\"><b>%1</b>%2</td></tr>").arg(tr("Translators:"), extraVSpace);
546         for(int i = 0; g_lamexp_translators[i].pcName; i++)
547         {
548                 QString flagIcon = (strlen(g_lamexp_translators[i].pcFlag) > 0) ? QString("<img src=\":/flags/%1.png\">").arg(g_lamexp_translators[i].pcFlag) : QString();
549                 contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(flagIcon, spaces);
550                 contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td>").arg(WCHAR2QSTR(g_lamexp_translators[i].pcLanguage), spaces);
551                 contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td><a href=\"mailto:%2\">&lt;%3&gt;</a></td></tr>").arg(WCHAR2QSTR(g_lamexp_translators[i].pcName), spaces, g_lamexp_translators[i].pcMail);
552         }
553
554         contributorsAboutText += QString("<tr><td colspan=\"7\"><b>&nbsp;</b></td></tr>");
555         contributorsAboutText += QString("<tr><td colspan=\"7\"><b>%1</b>%2</td></tr>").arg(tr("Special thanks to:"), extraVSpace);
556
557         QString webIcon = QString("<img src=\":/icons/%1.png\">").arg("world");
558         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
559         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("Doom9's Forum"), spaces, "http://forum.doom9.org/");
560         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
561         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("Gleitz | German Doom9"), spaces, "http://forum.gleitz.info/");
562         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
563         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("Hydrogenaudio Forums"), spaces, "http://www.hydrogenaudio.org/");
564         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
565         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("RareWares"), spaces, "http://www.rarewares.org/");
566         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
567         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("GitHub"), spaces, "http://github.com/");
568         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
569         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("SourceForge"), spaces, "http://sourceforge.net/");
570         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
571         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("Qt Developer Network"), spaces, "http://qt-project.org/");
572         contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>%2</td>").arg(webIcon, spaces);
573         contributorsAboutText += QString("<td valign=\"middle\">%1</td><td>%2</td><td valign=\"middle\" colspan=\"3\"><a href=\"%3\">%3</td></tr>").arg(tr("Marius Hudea"), spaces, "http://savedonthe.net/");
574
575         contributorsAboutText += "</table><br><br><br>";
576         contributorsAboutText += QString("<i>%1</i><br>").arg(NOBR(tr("If you are willing to contribute a LameXP translation, feel free to contact us!")));
577
578         contributorsLabel->setText(contributorsAboutText);
579         contributorsIcon->setPixmap(QIcon(":/images/Logo_Contributors.png").pixmap(QSize(72,84)));
580         connect(contributorsLabel, SIGNAL(linkActivated(QString)), this, SLOT(openURL(QString)));
581 }
582
583 void AboutDialog::initSoftwareTab(void)
584 {
585         QString moreAboutText;
586
587         moreAboutText += QString("<h3>%1</h3>").arg(tr("The following third-party software is used in LameXP:"));
588         moreAboutText += "<div style=\"margin-left:-25px;white-space:nowrap\"><table><tr><td><ul>"; //;font-size:7pt
589         
590         moreAboutText += makeToolText
591         (
592                 tr("LAME - OpenSource mp3 Encoder"),
593                 "lame.exe", "v?.??, Final-?",
594                 tr("Released under the terms of the GNU Lesser General Public License."),
595                 "http://lame.sourceforge.net/"
596         );
597         moreAboutText += makeToolText
598         (
599                 tr("OggEnc - Ogg Vorbis Encoder"),
600                 "oggenc2.exe", "v?.??, aoTuV Beta-?.??",
601                 tr("Completely open and patent-free audio encoding technology."),
602                 "http://www.vorbis.com/"
603         );
604         moreAboutText += makeToolText
605         (
606                 tr("Nero AAC Reference MPEG-4 Encoder"),
607                 "neroAacEnc.exe", "v?.?.?.?",
608                 tr("Freeware state-of-the-art HE-AAC encoder with 2-Pass support."),
609                 neroAacUrl,
610                 tr("Available from vendor web-site as free download:")
611         );
612         moreAboutText += makeToolText
613         (
614                 tr("Aften - A/52 audio encoder"),
615                 "aften.exe", "v?.?.?",
616                 tr("Released under the terms of the GNU Lesser General Public License."),
617                 "http://aften.sourceforge.net/"
618         );
619         moreAboutText += makeToolText
620         (
621                 tr("FLAC - Free Lossless Audio Codec"),
622                 "flac.exe", "v?.?.?",
623                 tr("Open and patent-free lossless audio compression technology."),
624                 "http://flac.sourceforge.net/"
625         );
626         moreAboutText += makeToolText
627         (
628                 tr("Opus Audio Codec"),
629                 "opusenc_std.exe", "????-??-??",
630                 tr("Totally open, royalty-free, highly versatile audio codec."),
631                 "http://www.opus-codec.org/"
632         );
633         moreAboutText += makeToolText
634         (
635                 tr("mpg123 - Fast Console MPEG Audio Player/Decoder"),
636                 "mpg123.exe", "v?.??.?",
637                 tr("Released under the terms of the GNU Lesser General Public License."),
638                 "http://www.mpg123.de/"
639         );
640         moreAboutText += makeToolText
641         (
642                 tr("FAAD - OpenSource MPEG-4 and MPEG-2 AAC Decoder"),
643                 "faad.exe", "v?.?",
644                 tr("Released under the terms of the GNU General Public License."),
645                 "http://www.audiocoding.com/"
646         );
647         moreAboutText += makeToolText
648         (
649                 tr("AC3Filter Tools - AC3/DTS Decoder"),
650                 "valdec.exe", "v?.??",
651                 tr("Released under the terms of the GNU Lesser General Public License."),
652                 "http://www.ac3filter.net/projects/tools"
653         );
654         moreAboutText += makeToolText
655                 (
656                 tr("WavPack - Hybrid Lossless Compression"),
657                 "wvunpack.exe", "v?.??.?",
658                 tr("Completely open audio compression format."),
659                 "http://www.wavpack.com/"
660         );
661         moreAboutText += makeToolText
662                 (
663                 tr("Musepack - Living Audio Compression"),
664                 "mpcdec.exe", "r???",
665                 tr("Released under the terms of the GNU Lesser General Public License."),
666                 "http://www.musepack.net/"
667         );
668         moreAboutText += makeToolText
669         (
670                 tr("Monkey's Audio - Lossless Audio Compressor"),
671                 "mac.exe", "v?.??",
672                 tr("Freely available source code, simple SDK and non-restrictive licensing."),
673                 "http://www.monkeysaudio.com/"
674         );
675         moreAboutText += makeToolText
676         (
677                 tr("Shorten - Lossless Audio Compressor"),
678                 "shorten.exe", "v?.?.?",
679                 tr("Released under the terms of the GNU Lesser General Public License."),
680                 "http://etree.org/shnutils/shorten/"
681         );
682         moreAboutText += makeToolText
683         (
684                 tr("Speex - Free Codec For Free Speech"),
685                 "speexdec.exe", "v?.?",
686                 tr("Open Source patent-free audio format designed for speech."),
687                 "http://www.speex.org/"
688         );
689         moreAboutText += makeToolText
690         (
691                 tr("The True Audio - Lossless Audio Codec"),
692                 "tta.exe", "v?.?",
693                 tr("Released under the terms of the GNU Lesser General Public License."),
694                 "http://tta.sourceforge.net/"
695         );
696         //moreAboutText += makeToolText
697         //(
698         //      tr("ALAC Decoder"),
699         //      "alac.exe", "v?.?.?",
700         //      tr("Copyright (c) 2004 David Hammerton. Contributions by Cody Brocious."),
701         //      "http://craz.net/programs/itunes/alac.html"
702         //);
703         moreAboutText += makeToolText
704         (
705                 tr("refalac - Win32 command line ALAC encoder/decoder"),
706                 "refalac.exe", "v?.??",
707                 tr("The ALAC reference implementation by Apple is available under the Apache license."),
708                 "http://alac.macosforge.org/"
709         );
710         moreAboutText += makeToolText
711         (
712                 tr("wma2wav - Dump WMA files to Wave Audio"),
713                 "wma2wav.exe", "????-??-??",
714                 tr("Copyright (c) 2011 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved."),
715                 "http://forum.doom9.org/showthread.php?t=140273"
716         );
717         moreAboutText += makeToolText
718         (
719                 tr("avs2wav - Avisynth to Wave Audio converter"),
720                 "avs2wav.exe", "v?.?",
721                 tr("By Jory Stone <jcsston@toughguy.net> and LoRd_MuldeR <mulder2@gmx.de>."),
722                 "http://forum.doom9.org/showthread.php?t=70882"
723         );
724         moreAboutText += makeToolText
725         (
726                 tr("dcaenc"),
727                 "dcaenc.exe", "????-??-??",
728                 tr("Copyright (c) 2008-2011 Alexander E. Patrakov. Distributed under the LGPL."),
729                 "http://gitorious.org/dtsenc/dtsenc/trees/master"
730         );
731         moreAboutText += makeToolText
732         (
733                 tr("MediaInfo - Media File Analysis Tool"),
734                 "mediainfo.exe", "v?.?.??",
735                 tr("Released under the terms of the GNU Lesser General Public License."),
736                 "http://mediainfo.sourceforge.net/"
737         );
738         moreAboutText += makeToolText
739         (
740                 tr("SoX - Sound eXchange"),
741                 "sox.exe", "v??.?.?",
742                 tr("Released under the terms of the GNU Lesser General Public License."),
743                 "http://sox.sourceforge.net/"
744         );
745         moreAboutText += makeToolText
746         (
747                 tr("GnuPG - The GNU Privacy Guard"),
748                 "gpgv.exe", "v?.?.??",
749                 tr("Released under the terms of the GNU Lesser General Public License."),
750                 "http://www.gnupg.org/"
751         );
752         moreAboutText += makeToolText
753         (
754                 tr("GNU Wget - Software for retrieving files using HTTP"),
755                 "wget.exe", "v?.??.?",
756                 tr("Released under the terms of the GNU Lesser General Public License."),
757                 "http://www.gnu.org/software/wget/"
758         );
759         moreAboutText += makeToolText
760         (
761                 tr("UPX - The Ultimate Packer for eXecutables"),
762                 QString(), "v3.08",
763                 tr("Released under the terms of the GNU Lesser General Public License."),
764                 "http://upx.sourceforge.net/"
765         );
766         moreAboutText += makeToolText
767         (
768                 tr("Silk Icons - Over 700  icons in PNG format"),
769                 QString(), "v1.3",
770                 tr("By Mark James, released under the Creative Commons 'by' License."),
771                 "http://www.famfamfam.com/lab/icons/silk/"
772         );
773         moreAboutText += QString("</ul></td><td>&nbsp;</td></tr></table></div><br><i>%1</i><br>").arg
774         (
775                 tr("The copyright of LameXP as a whole belongs to LoRd_MuldeR. The copyright of third-party software used in LameXP belongs to the individual authors.")
776         );
777
778         softwareLabel->setText(moreAboutText);
779         softwareIcon->setPixmap(QIcon(":/images/Logo_Software.png").pixmap(QSize(72,65)));
780         connect(softwareLabel, SIGNAL(linkActivated(QString)), this, SLOT(openURL(QString)));
781 }
782
783 void AboutDialog::initLicenseTab(void)
784 {
785         QString licenseText;
786         licenseText += ("<tt>");
787
788         QFile file(":/License.txt");
789         if(file.open(QIODevice::ReadOnly))
790         {
791                 QTextStream stream(&file);
792                 unsigned int counter = 0;
793                 while((!stream.atEnd()) && (stream.status() == QTextStream::Ok))
794                 {
795                         QString line = stream.readLine();
796                         const bool bIsBlank = line.trimmed().isEmpty();
797                         line.replace('<', "&lt;").replace('>', "&gt;");
798
799                         switch(counter)
800                         {
801                         case 0:
802                                 if(!bIsBlank) licenseText += QString("<font size=\"+2\">%1</font><br>").arg(line.simplified());
803                                 break;
804                         case 1:
805                                 if(!bIsBlank) licenseText += QString("<font size=\"+1\">%1 &minus; %2</font><br>").arg(line.simplified(), LINK("http://www.gnu.org/licenses/gpl-2.0.html"));
806                                 break;
807                         default:
808                                 TRIM_RIGHT(line);
809                                 licenseText += QString("<nobr>%1</nobr><br>").arg(line.replace(' ', "&nbsp;"));
810                                 break;
811                         }
812
813                         if(!bIsBlank) counter++;
814                 }
815                 licenseText += QString("<br>");
816                 stream.device()->close();
817         }
818         else
819         {
820                 licenseText += QString("<font color=\"darkred\">Oups, failed to load license text. Please refer to:</font><br>");
821                 licenseText += LINK("http://www.gnu.org/licenses/gpl-2.0.html");
822         }
823
824         licenseText += ("</tt>");
825
826         licenseLabel->setText(licenseText);
827         licenseIcon->setPixmap(QIcon(":/images/Logo_GNU.png").pixmap(QSize(72,65)));
828         connect(licenseLabel, SIGNAL(linkActivated(QString)), this, SLOT(openURL(QString)));
829 }
830
831
832 QString AboutDialog::makeToolText(const QString &toolName, const QString &toolBin, const QString &toolVerFmt, const QString &toolLicense, const QString &toolWebsite, const QString &extraInfo)
833 {
834         QString toolText, verStr(toolVerFmt);
835
836         if(!toolBin.isEmpty())
837         {
838                 verStr = lamexp_version2string(toolVerFmt, lamexp_tool_version(toolBin), tr("n/a"));
839         }
840
841         toolText += QString("<li>%1<br>").arg(NOBR(QString("<b>%1 (%2)</b>").arg(toolName, verStr)));
842         toolText += QString("%1<br>").arg(NOBR(toolLicense));
843         if(!extraInfo.isEmpty()) toolText += QString("<i>%1</i><br>").arg(NOBR(extraInfo));
844         toolText += QString("<nobr>%1</nobr>").arg(LINK(toolWebsite));
845         toolText += QString("<font style=\"font-size:9px\"><br>&nbsp;</font>");
846
847         return toolText;
848 }
849
850
851 bool AboutDialog::playResoureSound(const QString &library, const unsigned long soundId, const bool async)
852 {
853         HMODULE module = 0;
854         DWORD flags = SND_RESOURCE;
855         bool result = false;
856
857         QFileInfo libraryFile(library);
858         if(!libraryFile.isAbsolute())
859         {
860                 unsigned int buffSize = GetSystemDirectoryW(NULL, NULL) + 1;
861                 wchar_t *buffer = (wchar_t*) _malloca(buffSize * sizeof(wchar_t));
862                 unsigned int result = GetSystemDirectory(buffer, buffSize);
863                 if(result > 0 && result < buffSize)
864                 {
865                         libraryFile.setFile(QString("%1/%2").arg(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast<const unsigned short*>(buffer))), library));
866                 }
867                 _freea(buffer);
868         }
869
870         if(async)
871         {
872                 flags |= SND_ASYNC;
873         }
874         else
875         {
876                 flags |= SND_SYNC;
877         }
878
879         module = LoadLibraryW(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(libraryFile.absoluteFilePath()).utf16()));
880
881         if(module)
882         {
883                 result = PlaySound((LPCTSTR) soundId, module, flags);
884                 FreeLibrary(module);
885         }
886
887         return result;
888 }