OSDN Git Service

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