OSDN Git Service

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