OSDN Git Service

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