OSDN Git Service

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