OSDN Git Service

Updated TTA decoder multiplatform library to v2.1 (2011-03-11), compiled with MSVC...
[lamexp/LameXP.git] / src / Dialog_About.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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 //Qt includes
29 #include <QDate>
30 #include <QApplication>
31 #include <QIcon>
32 #include <QPushButton>
33 #include <QDesktopServices>
34 #include <QUrl>
35 #include <QTimer>
36 #include <QFileInfo>
37 #include <QDir>
38
39 //Win32 includes
40 #include <Windows.h>
41
42 //Helper macros
43 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(URL)
44
45 //Constants
46 const char *AboutDialog::neroAacUrl = "http://www.nero.com/eng/technologies-aac-codec.html";
47
48 //Contributors
49 static const struct 
50 {
51         char *pcFlag;
52         wchar_t *pcLanguage;
53         wchar_t *pcName;
54         char *pcMail;
55 }
56 g_lamexp_contributors[] =
57 {
58         {"en", L"Englisch",   L"LoRd_MuldeR",         "MuldeR2@GMX.de"       },
59         {"de", L"Deutsch",    L"LoRd_MuldeR",         "MuldeR2@GMX.de"       },
60         {"",   L"",           L"Bodo Thevissen",      "Bodo@thevissen.de"    },
61         {"fr", L"Française",  L"Dodich Informatique", "Dodich@live.fr"       },
62         {"it", L"Italiano",   L"Roberto",             "Gulliver_69@libero.it"},
63         {"es", L"Español",    L"Rub3nCT",             "Rub3nCT@gmail.com"    },
64         {"ru", L"Русский",    L"Neonailol",           "Neonailol@gmail.com"  },
65         {"uk", L"Українська", L"Arestarh",            "Arestarh@ukr.net"     },
66         {NULL, NULL, NULL, NULL}
67 };
68
69 ////////////////////////////////////////////////////////////
70 // Constructor
71 ////////////////////////////////////////////////////////////
72
73 AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstStart)
74 :
75         QMessageBox(parent),
76         m_settings(settings)
77 {
78         QString aboutText;
79
80         aboutText += QString("<h2>%1</h2>").arg(tr("LameXP &minus; Audio Encoder Front-end"));
81         aboutText += QString("<b>Copyright (C) 2004-%1 LoRd_MuldeR &lt;MuldeR2@GMX.de&gt;. Some rights reserved.</b><br>").arg(max(lamexp_version_date().year(),QDate::currentDate().year()));
82         aboutText += QString().sprintf("<b>Version %d.%02d %s, Build %d [%s]</b><br><br>", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData());
83         aboutText += QString("<nobr>%1</nobr><br>").arg(tr("Please visit %1 for news and updates!").arg(LINK(lamexp_website_url())));
84         aboutText += "<hr><br>";
85         aboutText += "<nobr><tt>This program is free software; you can redistribute it and/or<br>";
86         aboutText += "modify it under the terms of the GNU General Public License<br>";
87         aboutText += "as published by the Free Software Foundation; either version 2<br>";
88         aboutText += "of the License, or (at your option) any later version.<br><br>";
89         aboutText += "This program is distributed in the hope that it will be useful,<br>";
90         aboutText += "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>";
91         aboutText += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>";
92         aboutText += "GNU General Public License for more details.<br><br>";
93         aboutText += "You should have received a copy of the GNU General Public License<br>";
94         aboutText += "along with this program; if not, write to the Free Software<br>";
95         aboutText += "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</tt></nobr><br>";
96         aboutText += "<hr><table><tr>";
97         aboutText += "<td valign=\"middle\"><img src=\":/icons/error_big.png\"</td><td>&nbsp;</td>";
98         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 !!!"));
99         aboutText += "</tr></table><hr><br>";
100         aboutText += QString("%1<br>").arg(tr("Special thanks go out to \"John33\" from %1 for his continuous support.").arg(LINK("http://www.rarewares.org/")));
101         
102         setText(aboutText);
103         setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
104         setWindowTitle(tr("About LameXP"));
105         
106         if(firstStart)
107         {
108                 QPushButton *firstButton = addButton(tr("Show License Text"), QMessageBox::AcceptRole);
109                 firstButton->setIcon(QIcon(":/icons/script.png"));
110                 firstButton->setIconSize(QSize(16, 16));
111                 firstButton->setMinimumWidth(135);
112                 firstButton->disconnect();
113                 connect(firstButton, SIGNAL(clicked()), this, SLOT(openLicenseText()));
114
115                 QPushButton *secondButton = addButton(tr("Accept License"), QMessageBox::AcceptRole);
116                 secondButton->setIcon(QIcon(":/icons/accept.png"));
117                 secondButton->setIconSize(QSize(16, 16));
118                 secondButton->setMinimumWidth(120);
119
120                 QPushButton *thirdButton = addButton(tr("Decline License"), QMessageBox::AcceptRole);
121                 thirdButton->setIcon(QIcon(":/icons/delete.png"));
122                 thirdButton->setIconSize(QSize(16, 16));
123                 thirdButton->setMinimumWidth(120);
124                 thirdButton->setEnabled(false);
125         }
126         else
127         {
128                 QPushButton *firstButton = addButton(tr("3rd Party S/W"), QMessageBox::AcceptRole);
129                 firstButton->setIcon(QIcon(":/icons/page_white_cplusplus.png"));
130                 firstButton->setIconSize(QSize(16, 16));
131                 firstButton->setMinimumWidth(120);
132                 firstButton->disconnect();
133                 connect(firstButton, SIGNAL(clicked()), this, SLOT(showMoreAbout()));
134
135                 QPushButton *secondButton = addButton(tr("Contributors"), QMessageBox::AcceptRole);
136                 secondButton->setIcon(QIcon(":icons/user_suit.png"));
137                 secondButton->setIconSize(QSize(16, 16));
138                 secondButton->setMinimumWidth(120);
139                 secondButton->disconnect();
140                 connect(secondButton, SIGNAL(clicked()), this, SLOT(showAboutContributors()));
141
142                 QPushButton *thirdButton = addButton(tr("About Qt4"), QMessageBox::AcceptRole);
143                 thirdButton->setIcon(QIcon(":/images/Qt.svg"));
144                 thirdButton->setIconSize(QSize(16, 16));
145                 thirdButton->setMinimumWidth(120);
146                 thirdButton->disconnect();
147                 connect(thirdButton, SIGNAL(clicked()), this, SLOT(showAboutQt()));
148
149                 QPushButton *fourthButton = addButton(tr("Discard"), QMessageBox::AcceptRole);
150                 fourthButton->setIcon(QIcon(":/icons/cross.png"));
151                 fourthButton->setIconSize(QSize(16, 16));
152                 fourthButton->setMinimumWidth(90);
153         }
154
155         m_firstShow = firstStart;
156 }
157
158 AboutDialog::~AboutDialog(void)
159 {
160 }
161
162 ////////////////////////////////////////////////////////////
163 // Public Functions
164 ////////////////////////////////////////////////////////////
165
166 int AboutDialog::exec()
167 {
168         if(m_settings->soundsEnabled())
169         {
170                 if(m_firstShow)
171                 {
172                         if(!playResoureSound("imageres.dll", 5080, true))
173                         {
174                                 PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS | SND_ASYNC);
175                         }
176                 }
177                 else
178                 {
179                         PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
180                 }
181         }
182         
183         switch(QMessageBox::exec())
184         {
185         case 1:
186                 return 1;
187                 break;
188         case 2:
189                 return -1;
190                 break;
191         default:
192                 return 0;
193                 break;
194         }
195 }
196
197 ////////////////////////////////////////////////////////////
198 // Slots
199 ////////////////////////////////////////////////////////////
200
201 void AboutDialog::enableButtons(void)
202 {
203         const QList<QAbstractButton*> buttonList = buttons();
204         
205         for(int i = 0; i < buttonList.count(); i++)
206         {
207                 buttonList.at(i)->setEnabled(true);
208         }
209
210         setCursor(QCursor(Qt::ArrowCursor));
211 }
212
213 void AboutDialog::openLicenseText(void)
214 {
215         QDesktopServices::openUrl(QUrl("http://www.gnu.org/licenses/gpl-2.0.txt"));
216 }
217
218 void AboutDialog::showAboutQt(void)
219 {
220         QMessageBox::aboutQt(this);
221 }
222
223 void AboutDialog::showAboutContributors(void)
224 {
225         QString contributorsAboutText;
226
227         contributorsAboutText += QString("<h3><nobr>%1</nobr></h3>").arg(tr("The following people have contributed to LameXP:"));
228         contributorsAboutText += QString("<b>%1</b>").arg(tr("Translators:"));
229         contributorsAboutText += "<table style=\"margin-top:5px\">";
230         for(int i = 0; g_lamexp_contributors[i].pcName; i++)
231         {
232                 QString flagIcon = (strlen(g_lamexp_contributors[i].pcFlag) > 0) ? QString("<img src=\":/flags/%1.png\">").arg(g_lamexp_contributors[i].pcFlag) : QString();
233                 contributorsAboutText += QString("<tr><td valign=\"middle\">%1</td><td>&nbsp;&nbsp;</td>").arg(flagIcon);
234                 contributorsAboutText += QString("<td valign=\"middle\">%2</td><td>&nbsp;&nbsp;</td>").arg(WCHAR2QSTR(g_lamexp_contributors[i].pcLanguage));
235                 contributorsAboutText += QString("<td valign=\"middle\">%3</td><td>&nbsp;&nbsp;</td><td>&lt;%4&gt;</td></tr>").arg(WCHAR2QSTR(g_lamexp_contributors[i].pcName), g_lamexp_contributors[i].pcMail);
236         }
237         contributorsAboutText += "</table>";
238         contributorsAboutText += "<br><br>";
239         contributorsAboutText += QString("<nobr><i>%1</i></nobr><br>").arg(tr("If you are willing to contribute a LameXP translation, feel free to contact us!"));
240
241         QMessageBox *contributorsAboutBox = new QMessageBox(this);
242         contributorsAboutBox->setText(contributorsAboutText);
243         contributorsAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
244
245         QPushButton *closeButton = contributorsAboutBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
246         closeButton->setIcon(QIcon(":/icons/cross.png"));
247         closeButton->setMinimumWidth(90);
248
249         contributorsAboutBox->setWindowTitle(tr("About Contributors"));
250         contributorsAboutBox->setIconPixmap(QIcon(":/images/Logo_Contributors.png").pixmap(QSize(64,74)));
251         contributorsAboutBox->setWindowIcon(QIcon(":/icons/user_suit.png"));
252         contributorsAboutBox->exec();
253                                 
254         LAMEXP_DELETE(contributorsAboutBox);
255 }
256
257 void AboutDialog::showMoreAbout(void)
258 {
259         QString moreAboutText;
260
261         moreAboutText += QString("<h3>%1</h3>").arg(tr("The following third-party software is used in LameXP:"));
262         moreAboutText += "<div style=\"margin-left:-25px;font-size:8pt;white-space:nowrap\"><table><tr><td><ul>";
263         
264         moreAboutText += makeToolText
265         (
266                 tr("LAME &minus; OpenSource mp3 Encoder"),
267                 "lame.exe", "v?.??, Alpha-??",
268                 tr("Released under the terms of the GNU Lesser General Public License."),
269                 "http://lame.sourceforge.net/"
270         );
271         moreAboutText += makeToolText
272         (
273                 tr("OggEnc &minus; Ogg Vorbis Encoder"),
274                 "oggenc2_i386.exe", "v?.??, aoTuV Beta-?.??",
275                 tr("Completely open and patent-free audio encoding technology."),
276                 "http://www.vorbis.com/"
277         );
278         moreAboutText += makeToolText
279         (
280                 tr("Nero AAC Reference MPEG-4 Encoder"),
281                 "neroAacEnc.exe", "v?.?.?.?",
282                 tr("Freeware state-of-the-art HE-AAC encoder with 2-Pass support."),
283                 neroAacUrl,
284                 tr("Available from vendor web-site as free download:")
285         );
286         moreAboutText += makeToolText
287         (
288                 tr("FLAC &minus; Free Lossless Audio Codec"),
289                 "flac.exe", "v?.?.?",
290                 tr("Open and patent-free lossless audio compression technology."),
291                 "http://flac.sourceforge.net/"
292         );
293         moreAboutText += makeToolText
294         (
295                 tr("mpg123 &minus; Fast Console MPEG Audio Player/Decoder"),
296                 "mpg123.exe", "v?.??.?",
297                 tr("Released under the terms of the GNU Lesser General Public License."),
298                 "http://www.mpg123.de/"
299         );
300         moreAboutText += makeToolText
301         (
302                 tr("FAAD &minus; OpenSource MPEG-4 and MPEG-2 AAC Decoder"),
303                 "faad.exe", "v?.?",
304                 tr("Released under the terms of the GNU General Public License."),
305                 "http://www.audiocoding.com/"
306         );
307         moreAboutText += makeToolText
308         (
309                 tr("AC3Filter Tools &minus; AC3/DTS Decoder"),
310                 "valdec.exe", "v?.??",
311                 tr("Released under the terms of the GNU Lesser General Public License."),
312                 "http://www.ac3filter.net/projects/tools"
313         );
314         moreAboutText += makeToolText
315                 (
316                 tr("WavPack &minus; Hybrid Lossless Compression"),
317                 "wvunpack.exe", "v?.??.?",
318                 tr("Completely open audio compression format."),
319                 "http://www.wavpack.com/"
320         );
321         moreAboutText += makeToolText
322                 (
323                 tr("Musepack &minus; Living Audio Compression"),
324                 "mpcdec.exe", "r???",
325                 tr("Released under the terms of the GNU Lesser General Public License."),
326                 "http://www.musepack.net/"
327         );
328         moreAboutText += QString
329         (
330                 "</ul></td><td><ul>"
331         );
332         moreAboutText += makeToolText
333         (
334                 tr("Monkey's Audio &minus; Lossless Audio Compressor"),
335                 "mac.exe", "v?.??",
336                 tr("Freely available source code, simple SDK and non-restrictive licensing."),
337                 "http://www.monkeysaudio.com/"
338         );
339         moreAboutText += makeToolText
340         (
341                 tr("Shorten &minus; Lossless Audio Compressor"),
342                 "shorten.exe", "v?.?.?",
343                 tr("Released under the terms of the GNU Lesser General Public License."),
344                 "http://etree.org/shnutils/shorten/"
345         );
346         moreAboutText += makeToolText
347         (
348                 tr("Speex &minus; Free Codec For Free Speech"),
349                 "speexdec.exe", "v?.?",
350                 tr("Open Source patent-free audio format designed for speech."),
351                 "http://www.speex.org/"
352         );
353         moreAboutText += makeToolText
354         (
355                 tr("The True Audio &minus; Lossless Audio Codec"),
356                 "tta.exe", "v?.?",
357                 tr("Released under the terms of the GNU Lesser General Public License."),
358                 "http://tta.sourceforge.net/"
359         );
360         moreAboutText += makeToolText
361         (
362                 tr("MediaInfo &minus; Media File Analysis Tool"),
363                 "mediainfo_i386.exe", "v?.?.??",
364                 tr("Released under the terms of the GNU Lesser General Public License."),
365                 "http://mediainfo.sourceforge.net/"
366         );
367         moreAboutText += makeToolText
368         (
369                 tr("SoX &minus; Sound eXchange"),
370                 "sox.exe", "v??.?.?",
371                 tr("Released under the terms of the GNU Lesser General Public License."),
372                 "http://sox.sourceforge.net/"
373         );
374         moreAboutText += makeToolText
375         (
376                 tr("GnuPG &minus; The GNU Privacy Guard"),
377                 "gpgv.exe", "v?.?.??",
378                 tr("Released under the terms of the GNU Lesser General Public License."),
379                 "http://www.gnupg.org/"
380         );
381
382
383         moreAboutText += makeToolText
384         (
385                 tr("GNU Wget &minus; Software for retrieving files using HTTP"),
386                 "wget.exe", "v?.??.?",
387                 tr("Released under the terms of the GNU Lesser General Public License."),
388                 "http://www.gnu.org/software/wget/"
389         );
390
391
392         moreAboutText += makeToolText
393         (
394                 tr("Silk Icons &minus; Over 700  icons in PNG format"),
395                 QString(), "v1.3",
396                 tr("By Mark James, released under the Creative Commons 'by' License."),
397                 "http://www.famfamfam.com/lab/icons/silk/"
398         );
399         moreAboutText += QString("</ul></td><td>&nbsp;</td></tr></table></div><i>%1</i><br>").arg
400         (
401                 tr("LameXP as a whole is copyrighted by LoRd_MuldeR. The copyright of thrird-party software used in LameXP belongs to the individual authors.")
402         );
403
404         QMessageBox *moreAboutBox = new QMessageBox(this);
405         moreAboutBox->setText(moreAboutText);
406         moreAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
407
408         QPushButton *closeButton = moreAboutBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
409         closeButton->setIcon(QIcon(":/icons/cross.png"));
410         closeButton->setMinimumWidth(90);
411
412         moreAboutBox->setWindowTitle(tr("About Third-party Software"));
413         moreAboutBox->setIconPixmap(QIcon(":/images/Logo_Software.png").pixmap(QSize(64,71)));
414         moreAboutBox->setWindowIcon(QIcon(":/icons/page_white_cplusplus.png"));
415         moreAboutBox->exec();
416                                 
417         LAMEXP_DELETE(moreAboutBox);
418 }
419
420 ////////////////////////////////////////////////////////////
421 // Protected Functions
422 ////////////////////////////////////////////////////////////
423
424 void AboutDialog::showEvent(QShowEvent *e)
425 {
426         QDialog::showEvent(e);
427         if(m_firstShow)
428         {
429                 const QList<QAbstractButton*> buttonList = buttons();
430
431                 for(int i = 1; i < buttonList.count(); i++)
432                 {
433                         buttonList.at(i)->setEnabled(false);
434                 }
435
436                 QTimer::singleShot(5000, this, SLOT(enableButtons()));
437                 setCursor(QCursor(Qt::WaitCursor));
438         }
439 }
440
441 ////////////////////////////////////////////////////////////
442 // Private Functions
443 ////////////////////////////////////////////////////////////
444
445 QString AboutDialog::makeToolText(const QString &toolName, const QString &toolBin, const QString &toolVerFmt, const QString &toolLicense, const QString &toolWebsite, const QString &extraInfo)
446 {
447         QString toolText, verStr(toolVerFmt);
448
449         if(!toolBin.isEmpty())
450         {
451                 verStr = lamexp_version2string(toolVerFmt, lamexp_tool_version(toolBin), tr("n/a"));
452         }
453
454         toolText += QString("<li><nobr><b>%1 (%2)</b></nobr><br>").arg(toolName, verStr);
455         toolText += QString("<nobr>%1</nobr><br>").arg(toolLicense);
456         if(!extraInfo.isEmpty()) toolText += QString("<nobr><i>%1</i></nobr><br>").arg(extraInfo);
457         toolText += QString("<a href=\"%1\">%1</a>").arg(toolWebsite);
458         toolText += QString("<div style=\"font-size:1pt\"><br></div>");
459
460         return toolText;
461 }
462
463
464 bool AboutDialog::playResoureSound(const QString &library, const unsigned long soundId, const bool async)
465 {
466         HMODULE module = 0;
467         DWORD flags = SND_RESOURCE;
468         bool result = false;
469
470         QFileInfo libraryFile(library);
471         if(!libraryFile.isAbsolute())
472         {
473                 unsigned int buffSize = GetSystemDirectoryW(NULL, NULL) + 1;
474                 wchar_t *buffer = (wchar_t*) _malloca(buffSize * sizeof(wchar_t));
475                 unsigned int result = GetSystemDirectory(buffer, buffSize);
476                 if(result > 0 && result < buffSize)
477                 {
478                         libraryFile.setFile(QString("%1/%2").arg(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast<const unsigned short*>(buffer))), library));
479                 }
480                 _freea(buffer);
481         }
482
483         if(async)
484         {
485                 flags |= SND_ASYNC;
486         }
487         else
488         {
489                 flags |= SND_SYNC;
490         }
491
492         module = LoadLibraryW(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(libraryFile.absoluteFilePath()).utf16()));
493
494         if(module)
495         {
496                 result = PlaySound((LPCTSTR) soundId, module, flags);
497                 FreeLibrary(module);
498         }
499
500         return result;
501 }