OSDN Git Service

Refactor some global structs.
[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         char *pcLanguage;
53         char *pcName;
54         char *pcMail;
55 }
56 g_lamexp_contributors[] =
57 {
58         {"en", "Englisch",  "LoRd_MuldeR",         "MuldeR2@GMX.de"       },
59         {"de", "Deutsch",   "LoRd_MuldeR",         "MuldeR2@GMX.de"       },
60         {"fr", "Française", "Dodich Informatique", "Dodich@live.fr"       },
61         {"it", "Italiano",  "Roberto",             "Gulliver_69@libero.it"},
62         {"es", "Español",   "Rub3nCT",             "Rub3nCT@gmail.com"    },
63         {NULL, NULL, NULL, NULL}
64 };
65
66 ////////////////////////////////////////////////////////////
67 // Constructor
68 ////////////////////////////////////////////////////////////
69
70 AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstStart)
71 :
72         QMessageBox(parent),
73         m_settings(settings)
74 {
75         QString aboutText;
76
77         aboutText += QString("<h2>%1</h2>").arg(tr("LameXP - Audio Encoder Front-end"));
78         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()));
79         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());
80         aboutText += QString("<nobr>%1</nobr><br>").arg(tr("Please visit %1 for news and updates!").arg(LINK("http://forum.doom9.org/showthread.php?t=157726")));
81         aboutText += "<hr><br>";
82         aboutText += "<nobr><tt>This program is free software; you can redistribute it and/or<br>";
83         aboutText += "modify it under the terms of the GNU General Public License<br>";
84         aboutText += "as published by the Free Software Foundation; either version 2<br>";
85         aboutText += "of the License, or (at your option) any later version.<br><br>";
86         aboutText += "This program is distributed in the hope that it will be useful,<br>";
87         aboutText += "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>";
88         aboutText += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>";
89         aboutText += "GNU General Public License for more details.<br><br>";
90         aboutText += "You should have received a copy of the GNU General Public License<br>";
91         aboutText += "along with this program; if not, write to the Free Software<br>";
92         aboutText += "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</tt></nobr><br>";
93         aboutText += "<hr><table><tr>";
94         aboutText += "<td valign=\"middle\"><img src=\":/icons/error_big.png\"</td><td>&nbsp;</td>";
95         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 !!!"));
96         aboutText += "</tr></table><hr><br>";
97         aboutText += QString("%1<br>").arg(tr("Special thanks go out to \"John33\" from %1 for his continuous support.").arg(LINK("http://www.rarewares.org/")));
98         
99         setText(aboutText);
100         setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
101         setWindowTitle(tr("About LameXP"));
102         
103         if(firstStart)
104         {
105                 QPushButton *firstButton = addButton(tr("Show License Text"), QMessageBox::AcceptRole);
106                 firstButton->setIcon(QIcon(":/icons/script.png"));
107                 firstButton->setMinimumWidth(135);
108                 firstButton->disconnect();
109                 connect(firstButton, SIGNAL(clicked()), this, SLOT(openLicenseText()));
110
111                 QPushButton *secondButton = addButton(tr("Accept License"), QMessageBox::AcceptRole);
112                 secondButton->setIcon(QIcon(":/icons/accept.png"));
113                 secondButton->setMinimumWidth(120);
114
115                 QPushButton *thirdButton = addButton(tr("Decline License"), QMessageBox::AcceptRole);
116                 thirdButton->setIcon(QIcon(":/icons/delete.png"));
117                 thirdButton->setMinimumWidth(120);
118                 thirdButton->setEnabled(false);
119         }
120         else
121         {
122                 QPushButton *firstButton = addButton(tr("3rd Party S/W"), QMessageBox::AcceptRole);
123                 firstButton->setIcon(QIcon(":/icons/page_white_cplusplus.png"));
124                 firstButton->setMinimumWidth(120);
125                 firstButton->disconnect();
126                 connect(firstButton, SIGNAL(clicked()), this, SLOT(showMoreAbout()));
127
128                 QPushButton *secondButton = addButton(tr("Contributors"), QMessageBox::AcceptRole);
129                 secondButton->setIcon(QIcon(":icons/user_suit.png"));
130                 secondButton->setMinimumWidth(120);
131                 secondButton->disconnect();
132                 connect(secondButton, SIGNAL(clicked()), this, SLOT(showAboutContributors()));
133
134                 QPushButton *thirdButton = addButton(tr("About Qt4"), QMessageBox::AcceptRole);
135                 thirdButton->setIcon(QIcon(":/images/Qt.svg"));
136                 thirdButton->setMinimumWidth(120);
137                 thirdButton->disconnect();
138                 connect(thirdButton, SIGNAL(clicked()), this, SLOT(showAboutQt()));
139
140                 QPushButton *fourthButton = addButton(tr("Discard"), QMessageBox::AcceptRole);
141                 fourthButton->setIcon(QIcon(":/icons/cross.png"));
142                 fourthButton->setMinimumWidth(90);
143         }
144
145         m_firstShow = firstStart;
146 }
147
148 AboutDialog::~AboutDialog(void)
149 {
150 }
151
152 ////////////////////////////////////////////////////////////
153 // Public Functions
154 ////////////////////////////////////////////////////////////
155
156 int AboutDialog::exec()
157 {
158         if(m_settings->soundsEnabled())
159         {
160                 if(!m_firstShow || !playResoureSound("imageres.dll", 5080, true))
161                 {
162                         PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
163                 }
164         }
165         
166         switch(QMessageBox::exec())
167         {
168         case 1:
169                 return 1;
170                 break;
171         case 2:
172                 return -1;
173                 break;
174         default:
175                 return 0;
176                 break;
177         }
178 }
179
180 ////////////////////////////////////////////////////////////
181 // Slots
182 ////////////////////////////////////////////////////////////
183
184 void AboutDialog::enableButtons(void)
185 {
186         const QList<QAbstractButton*> buttonList = buttons();
187         
188         for(int i = 0; i < buttonList.count(); i++)
189         {
190                 buttonList.at(i)->setEnabled(true);
191         }
192
193         setCursor(QCursor(Qt::ArrowCursor));
194 }
195
196 void AboutDialog::openLicenseText(void)
197 {
198         QDesktopServices::openUrl(QUrl("http://www.gnu.org/licenses/gpl-2.0.txt"));
199 }
200
201 void AboutDialog::showAboutQt(void)
202 {
203         QMessageBox::aboutQt(this);
204 }
205
206 void AboutDialog::showAboutContributors(void)
207 {
208         QString contributorsAboutText;
209
210         contributorsAboutText += QString("<h3><nobr>%1</nobr></h3>").arg(tr("The following people have contributed to LameXP:"));
211         contributorsAboutText += QString("<b>%1</b>").arg(tr("Translators:"));
212         contributorsAboutText += "<table style=\"margin-top:5px\">";
213         for(int i = 0; g_lamexp_contributors[i].pcName; i++)
214         {
215                 contributorsAboutText += QString("<tr><td valign=\"middle\"><img src=\":/flags/%1.png\"></td><td>&nbsp;&nbsp;</td>").arg(g_lamexp_contributors[i].pcFlag);
216                 contributorsAboutText += QString("<td valign=\"middle\">%2</td><td>&nbsp;&nbsp;</td>").arg(g_lamexp_contributors[i].pcLanguage);
217                 contributorsAboutText += QString("<td valign=\"middle\">%3</td><td>&nbsp;&nbsp;</td><td>&lt;%4&gt;</td></tr>").arg(g_lamexp_contributors[i].pcName, g_lamexp_contributors[i].pcMail);
218         }
219         contributorsAboutText += "</table>";
220         contributorsAboutText += "<br><br>";
221         contributorsAboutText += QString("<nobr><i>%1</i></nobr><br>").arg(tr("If you are willing to contribute a LameXP translation, feel free to contact us!"));
222
223         QMessageBox *contributorsAboutBox = new QMessageBox(this);
224         contributorsAboutBox->setText(contributorsAboutText);
225         contributorsAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
226
227         QPushButton *closeButton = contributorsAboutBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
228         closeButton->setIcon(QIcon(":/icons/cross.png"));
229         closeButton->setMinimumWidth(90);
230
231         contributorsAboutBox->setWindowTitle(tr("About Contributors"));
232         contributorsAboutBox->setIconPixmap(QIcon(":/images/Logo_Contributors.png").pixmap(QSize(64,74)));
233         contributorsAboutBox->setWindowIcon(QIcon(":/icons/user_suit.png"));
234         contributorsAboutBox->exec();
235                                 
236         LAMEXP_DELETE(contributorsAboutBox);
237 }
238
239 void AboutDialog::showMoreAbout(void)
240 {
241         QString moreAboutText;
242
243         moreAboutText += QString("<h3>%1</h3>").arg(tr("The following third-party software is used in LameXP:"));
244         moreAboutText += "<div style=\"margin-left:-25px;font-size:8pt\"><ul>";
245         
246         moreAboutText += makeToolText
247         (
248                 tr("LAME - OpenSource mp3 Encoder"),
249                 "lame.exe", "v?.?? a??",
250                 tr("Released under the terms of the GNU Lesser General Public License."),
251                 "http://lame.sourceforge.net/"
252         );
253         moreAboutText += makeToolText
254         (
255                 tr("OggEnc - Ogg Vorbis Encoder"),
256                 "oggenc2_i386.exe", "v?.??",
257                 tr("Completely open and patent-free audio encoding technology."),
258                 "http://www.vorbis.com/"
259         );
260         moreAboutText += makeToolText
261         (
262                 tr("Nero AAC reference MPEG-4 Encoder"),
263                 "neroAacEnc.exe", "v?.?.?.?",
264                 tr("Freeware state-of-the-art HE-AAC encoder with 2-Pass support."),
265                 neroAacUrl,
266                 tr("Available from vendor web-site as free download:")
267         );
268         moreAboutText += makeToolText
269         (
270                 tr("FLAC - Free Lossless Audio Codec"),
271                 "flac.exe", "v?.?.?",
272                 tr("Open and patent-free lossless audio compression technology."),
273                 "http://flac.sourceforge.net/"
274         );
275         moreAboutText += makeToolText
276         (
277                 tr("AC3Filter Tools - AC3/DTS Decoder"),
278                 "valdec.exe", "v?.??",
279                 tr("Released under the terms of the GNU Lesser General Public License."),
280                 "http://www.ac3filter.net/projects/tools"
281         );
282         moreAboutText += makeToolText
283                 (
284                 tr("WavPack - Hybrid Lossless Compression"),
285                 "wvunpack.exe", "v?.??.?",
286                 tr("Completely open audio compression format."),
287                 "http://www.wavpack.com/"
288         );
289         moreAboutText += makeToolText
290         (
291                 tr("Monkey's Audio - Lossless Audio Compressor"),
292                 "mac.exe", "v?.??",
293                 tr("Freely available source code, simple SDK and non-restrictive licensing."),
294                 "http://www.monkeysaudio.com/"
295         );
296         moreAboutText += makeToolText
297         (
298                 tr("The True Audio - Lossless Audio Codec"),
299                 "ttaenc.exe", "v?.?.?",
300                 tr("Released under the terms of the GNU Lesser General Public License."),
301                 "http://tta.sourceforge.net/"
302         );
303         moreAboutText += makeToolText
304         (
305                 tr("MediaInfo - Media File Analysis Tool"),
306                 "mediainfo_i386.exe", "v?.?.??",
307                 tr("Released under the terms of the GNU Lesser General Public License."),
308                 "http://mediainfo.sourceforge.net/"
309         );
310         moreAboutText += makeToolText
311         (
312                 tr("SoX - Sound eXchange"),
313                 "sox.exe", "v??.?.?",
314                 tr("Released under the terms of the GNU Lesser General Public License."),
315                 "http://sox.sourceforge.net/"
316         );
317         moreAboutText += makeToolText
318         (
319                 tr("GnuPG - The GNU Privacy Guard"),
320                 "gpgv.exe", "v?.?.??",
321                 tr("Released under the terms of the GNU Lesser General Public License."),
322                 "http://www.gnupg.org/"
323         );
324         moreAboutText += makeToolText
325         (
326                 tr("Silk Icons - Over 700  icons in PNG format"),
327                 QString(), "v1.3",
328                 tr("By Mark James, released under the Creative Commons 'by' License."),
329                 "http://www.famfamfam.com/lab/icons/silk/"
330         );
331
332         QMessageBox *moreAboutBox = new QMessageBox(this);
333         moreAboutBox->setText(moreAboutText);
334         moreAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
335
336         QPushButton *closeButton = moreAboutBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
337         closeButton->setIcon(QIcon(":/icons/cross.png"));
338         closeButton->setMinimumWidth(90);
339
340         moreAboutBox->setWindowTitle(tr("About Third-party Software"));
341         moreAboutBox->setIconPixmap(QIcon(":/images/Logo_Software.png").pixmap(QSize(64,71)));
342         moreAboutBox->setWindowIcon(QIcon(":/icons/page_white_cplusplus.png"));
343         moreAboutBox->exec();
344                                 
345         LAMEXP_DELETE(moreAboutBox);
346 }
347
348 ////////////////////////////////////////////////////////////
349 // Protected Functions
350 ////////////////////////////////////////////////////////////
351
352 void AboutDialog::showEvent(QShowEvent *e)
353 {
354         QDialog::showEvent(e);
355         if(m_firstShow)
356         {
357                 const QList<QAbstractButton*> buttonList = buttons();
358
359                 for(int i = 1; i < buttonList.count(); i++)
360                 {
361                         buttonList.at(i)->setEnabled(false);
362                 }
363
364                 QTimer::singleShot(5000, this, SLOT(enableButtons()));
365                 setCursor(QCursor(Qt::WaitCursor));
366         }
367 }
368
369 ////////////////////////////////////////////////////////////
370 // Private Functions
371 ////////////////////////////////////////////////////////////
372
373 QString AboutDialog::makeToolText(const QString &toolName, const QString &toolBin, const QString &toolVerFmt, const QString &toolLicense, const QString &toolWebsite, const QString &extraInfo)
374 {
375         QString toolText, verStr(toolVerFmt);
376
377         if(!toolBin.isEmpty())
378         {
379                 verStr = lamexp_version2string(toolVerFmt, lamexp_tool_version(toolBin), tr("n/a"));
380         }
381
382         toolText += QString("<li><b>%1 (%2)</b><br>").arg(toolName, verStr);
383         toolText += QString("<nobr>%1</nobr><br>").arg(toolLicense);
384         if(!extraInfo.isEmpty()) toolText += QString("<nobr><i>%1</i></nobr><br>").arg(extraInfo);
385         toolText += QString("<a href=\"%1\">%1</a>").arg(toolWebsite);
386         toolText += QString("<div style=\"font-size:1pt\"><br></div>");
387
388         return toolText;
389 }
390
391
392 bool AboutDialog::playResoureSound(const QString &library, const unsigned long soundId, const bool async)
393 {
394         HMODULE module = 0;
395         DWORD flags = SND_RESOURCE;
396         bool result = false;
397
398         QFileInfo libraryFile(library);
399         if(!libraryFile.isAbsolute())
400         {
401                 unsigned int buffSize = GetSystemDirectoryW(NULL, NULL) + 1;
402                 wchar_t *buffer = (wchar_t*) _malloca(buffSize * sizeof(wchar_t));
403                 unsigned int result = GetSystemDirectory(buffer, buffSize);
404                 if(result > 0 && result < buffSize)
405                 {
406                         libraryFile.setFile(QString("%1/%2").arg(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast<const unsigned short*>(buffer))), library));
407                 }
408                 _freea(buffer);
409         }
410
411         if(async)
412         {
413                 flags |= SND_ASYNC;
414         }
415         else
416         {
417                 flags |= SND_SYNC;
418         }
419
420         module = LoadLibraryW(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(libraryFile.absoluteFilePath()).utf16()));
421
422         if(module)
423         {
424                 result = PlaySound((LPCTSTR) soundId, module, flags);
425                 FreeLibrary(module);
426         }
427
428         return result;
429 }