OSDN Git Service

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