VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxRegistrationDlg.ui.h@ 7285

Last change on this file since 7285 was 7220, checked in by vboxsync, 17 years ago

Compile VirtualBox with qt4 on linux.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 17.6 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxRegistrationDlg UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19/****************************************************************************
20** ui.h extension file, included from the uic-generated form implementation.
21**
22** If you want to add, delete, or rename functions or slots, use
23** Qt Designer to update this file, preserving your code.
24**
25** You should not define a constructor or destructor in this file.
26** Instead, write your code in functions called init() and destroy().
27** These will automatically be called by the form's constructor and
28** destructor.
29*****************************************************************************/
30
31#include <iprt/assert.h>
32#include <iprt/err.h>
33#include <iprt/param.h>
34#include <iprt/path.h>
35//Added by qt3to4:
36#include <QShowEvent>
37
38/**
39 * This class is used to encode/decode the registration data.
40 */
41class VBoxRegistrationData
42{
43public:
44
45 VBoxRegistrationData (const QString &aData)
46 : mIsValid (false), mIsRegistered (false)
47 , mData (aData)
48 , mTriesLeft (3 /* the initial tries value! */)
49 {
50 decode (aData);
51 }
52
53 VBoxRegistrationData (const QString &aName, const QString &aEmail,
54 const QString &aPrivate)
55 : mIsValid (true), mIsRegistered (true)
56 , mName (aName), mEmail (aEmail), mPrivate (aPrivate)
57 , mTriesLeft (0)
58 {
59 encode (aName, aEmail, aPrivate);
60 }
61
62 bool isValid() const { return mIsValid; }
63 bool isRegistered() const { return mIsRegistered; }
64
65 const QString &data() const { return mData; }
66 const QString &name() const { return mName; }
67 const QString &email() const { return mEmail; }
68 const QString &isPrivate() const { return mPrivate; }
69
70 uint triesLeft() const { return mTriesLeft; }
71
72private:
73
74 void decode (const QString &aData)
75 {
76 mIsValid = mIsRegistered = false;
77
78 if (aData.isEmpty())
79 return;
80
81 if (aData.startsWith ("triesLeft="))
82 {
83 bool ok = false;
84 uint triesLeft = aData.section ('=', 1, 1).toUInt (&ok);
85 if (!ok)
86 return;
87 mTriesLeft = triesLeft;
88 mIsValid = true;
89 return;
90 }
91
92 /* Decoding CRC32 */
93 QString data = aData;
94 QString crcData = data.right (2 * sizeof (ulong));
95 ulong crcNeed = 0;
96 for (ulong i = 0; i < crcData.length(); i += 2)
97 {
98 crcNeed <<= 8;
99 uchar curByte = (uchar) crcData.mid (i, 2).toUShort (0, 16);
100 crcNeed += curByte;
101 }
102 data.truncate (data.length() - 2 * sizeof (ulong));
103
104 /* Decoding data */
105 QString result;
106 for (ulong i = 0; i < data.length(); i += 4)
107 result += QChar (data.mid (i, 4).toUShort (0, 16));
108 ulong crcNow = crc32 ((uchar*)result.ascii(), result.length());
109
110 /* Check the CRC32 */
111 if (crcNeed != crcNow)
112 return;
113
114 /* Initialize values */
115 QStringList dataList = QStringList::split ("|", result);
116 mName = dataList [0];
117 mEmail = dataList [1];
118 mPrivate = dataList [2];
119
120 mIsValid = true;
121 mIsRegistered = true;
122 }
123
124 void encode (const QString &aName, const QString &aEmail,
125 const QString &aPrivate)
126 {
127 /* Encoding data */
128 QString data = QString ("%1|%2|%3")
129 .arg (aName).arg (aEmail).arg (aPrivate);
130 mData = QString::null;
131 for (ulong i = 0; i < data.length(); ++ i)
132 {
133 QString curPair = QString::number (data.at (i).unicode(), 16);
134 while (curPair.length() < 4)
135 curPair.prepend ('0');
136 mData += curPair;
137 }
138
139 /* Enconding CRC32 */
140 ulong crcNow = crc32 ((uchar*)data.ascii(), data.length());
141 QString crcData;
142 for (ulong i = 0; i < sizeof (ulong); ++ i)
143 {
144 ushort curByte = crcNow & 0xFF;
145 QString curPair = QString::number (curByte, 16);
146 if (curPair.length() == 1)
147 curPair.prepend ("0");
148 crcData = curPair + crcData;
149 crcNow >>= 8;
150 }
151
152 mData += crcData;
153 }
154
155 ulong crc32 (unsigned char *aBufer, int aSize)
156 {
157 /* Filling CRC32 table */
158 ulong crc32;
159 ulong crc_table [256];
160 ulong temp;
161 for (int i = 0; i < 256; ++ i)
162 {
163 temp = i;
164 for (int j = 8; j > 0; -- j)
165 {
166 if (temp & 1)
167 temp = (temp >> 1) ^ 0xedb88320;
168 else
169 temp >>= 1;
170 };
171 crc_table [i] = temp;
172 }
173
174 /* CRC32 calculation */
175 crc32 = 0xffffffff;
176 for (int i = 0; i < aSize; ++ i)
177 {
178 crc32 = crc_table [(crc32 ^ (*aBufer ++)) & 0xff] ^ (crc32 >> 8);
179 }
180 crc32 = crc32 ^ 0xffffffff;
181 return crc32;
182 };
183
184 bool mIsValid : 1;
185 bool mIsRegistered : 1;
186
187 QString mData;
188 QString mName;
189 QString mEmail;
190 QString mPrivate;
191
192 uint mTriesLeft;
193};
194
195/* static */
196bool VBoxRegistrationDlg::hasToBeShown()
197{
198 VBoxRegistrationData regData (vboxGlobal().virtualBox().
199 GetExtraData (VBoxDefs::GUI_RegistrationData));
200
201 return !regData.isValid() ||
202 (!regData.isRegistered() && regData.triesLeft() > 0);
203}
204
205/* Default constructor initialization. */
206void VBoxRegistrationDlg::init()
207{
208 /* Hide unnecessary buttons */
209 helpButton()->setShown (false);
210 cancelButton()->setShown (false);
211 backButton()->setShown (false);
212
213 /* Confirm button initially disabled */
214 finishButton()->setEnabled (false);
215 finishButton()->setAutoDefault (true);
216 finishButton()->setDefault (true);
217
218 /* Setup the label colors for nice scaling */
219 VBoxGlobal::adoptLabelPixmap (pictureLabel);
220
221 /* Adjust text label size */
222#warning port me
223// mTextLabel->setMinimumWidth (widthSpacer->minimumSize().width());
224
225 /* Setup validations and maximum text-edit text length */
226 QRegExp nameExp ("[\\S\\s]+");
227 /* E-mail address is validated according to RFC2821, RFC2822,
228 * see http://en.wikipedia.org/wiki/E-mail_address. */
229 QRegExp emailExp ("(([a-zA-Z0-9_\\-\\.!#$%\\*/?|^{}`~&'\\+=]*"
230 "[a-zA-Z0-9_\\-!#$%\\*/?|^{}`~&'\\+=])|"
231 "(\"([\\x0001-\\x0008,\\x000B,\\x000C,\\x000E-\\x0019,\\x007F,"
232 "\\x0021,\\x0023-\\x005B,\\x005D-\\x007E,"
233 "\\x0009,\\x0020]|"
234 "(\\\\[\\x0001-\\x0009,\\x000B,\\x000C,"
235 "\\x000E-\\x007F]))*\"))"
236 "@"
237 "[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)*");
238 mNameEdit->setValidator (new QRegExpValidator (nameExp, this));
239 mEmailEdit->setValidator (new QRegExpValidator (emailExp, this));
240 mNameEdit->setMaxLength (50);
241 mEmailEdit->setMaxLength (50);
242
243 /* Create connection-timeout timer */
244 mTimeout = new QTimer (this);
245
246 /* Load language constraints */
247 languageChangeImp();
248
249 /* Set required boolean flags */
250 mSuicide = false;
251 mHandshake = true;
252
253 /* Network framework */
254 mNetfw = 0;
255
256 /* Setup connections */
257 disconnect (finishButton(), SIGNAL (clicked()), 0, 0);
258 connect (finishButton(), SIGNAL (clicked()), SLOT (registration()));
259 connect (mTimeout, SIGNAL (timeout()), this, SLOT (processTimeout()));
260 connect (mNameEdit, SIGNAL (textChanged (const QString&)), this, SLOT (validate()));
261 connect (mEmailEdit, SIGNAL (textChanged (const QString&)), this, SLOT (validate()));
262 connect (mTextLabel, SIGNAL (clickedOnLink (const QString &)),
263 &vboxGlobal(), SLOT (openURL (const QString &)));
264
265 /* Resize the dialog initially to minimum size */
266 resize (minimumSize());
267}
268
269/* Default destructor cleanup. */
270void VBoxRegistrationDlg::destroy()
271{
272 delete mNetfw;
273 *mSelf = 0;
274}
275
276/* Setup necessary dialog parameters. */
277void VBoxRegistrationDlg::setup (VBoxRegistrationDlg **aSelf)
278{
279 mSelf = aSelf;
280 *mSelf = this;
281 mUrl = "http://www.innotek.de/register762.php";
282
283 VBoxRegistrationData regData (vboxGlobal().virtualBox().
284 GetExtraData (VBoxDefs::GUI_RegistrationData));
285
286 mNameEdit->setText (regData.name());
287 mEmailEdit->setText (regData.email());
288 mUseCheckBox->setChecked (regData.isPrivate() == "yes");
289}
290
291/* String constants initializer. */
292void VBoxRegistrationDlg::languageChangeImp()
293{
294 finishButton()->setText (tr ("&Confirm"));
295}
296
297void VBoxRegistrationDlg::postRequest (const QString &aHost,
298 const QString &aUrl)
299{
300 delete mNetfw;
301 mNetfw = new VBoxNetworkFramework();
302 connect (mNetfw, SIGNAL (netBegin (int)),
303 SLOT (onNetBegin (int)));
304 connect (mNetfw, SIGNAL (netData (const QByteArray&)),
305 SLOT (onNetData (const QByteArray&)));
306 connect (mNetfw, SIGNAL (netEnd (const QByteArray&)),
307 SLOT (onNetEnd (const QByteArray&)));
308 connect (mNetfw, SIGNAL (netError (const QString&)),
309 SLOT (onNetError (const QString&)));
310
311 mNetfw->postRequest (aHost, aUrl);
312}
313
314
315/* Post the handshake request into the innotek register site. */
316void VBoxRegistrationDlg::registration()
317{
318 /* Disable control elements */
319 mNameEdit->setEnabled (false);
320 mEmailEdit->setEnabled (false);
321 mUseCheckBox->setEnabled (false);
322 finishButton()->setEnabled (false);
323
324 /* Handshake arguments initializing */
325 QString version = vboxGlobal().virtualBox().GetVersion();
326 Q3Url::encode (version);
327
328 /* Handshake */
329 QString argument = QString ("?version=%1").arg (version);
330 mTimeout->start (20000, true);
331 postRequest (mUrl.host(), mUrl.path() + argument);
332}
333
334/* This slot is used to control the connection timeout. */
335void VBoxRegistrationDlg::processTimeout()
336{
337 abortRegisterRequest (tr ("Connection timed out."));
338}
339
340/* Handles the network request begining. */
341void VBoxRegistrationDlg::onNetBegin (int aStatus)
342{
343 if (aStatus == 404)
344 abortRegisterRequest (tr ("Could not locate the registration form on "
345 "the server (response: %1).").arg (aStatus));
346 else
347 mTimeout->start (20000, true);
348}
349
350/* Handles the network request data incoming. */
351void VBoxRegistrationDlg::onNetData (const QByteArray&)
352{
353 if (!mSuicide)
354 mTimeout->start (20000, true);
355}
356
357/* Handles the network request end. */
358void VBoxRegistrationDlg::onNetEnd (const QByteArray &aTotalData)
359{
360 if (mSuicide)
361 return;
362
363 mTimeout->stop();
364 if (mHandshake)
365 {
366 /* Verifying key correctness */
367 if (QString (aTotalData).find (QRegExp ("^[a-zA-Z0-9]{32}$")))
368 {
369 abortRegisterRequest (tr ("Could not perform connection handshake."));
370 return;
371 }
372
373 /* Registration arguments initializing */
374 QString version = vboxGlobal().virtualBox().GetVersion();
375 QString key (aTotalData);
376 QString platform = getPlatform();
377 QString name = mNameEdit->text();
378 QString email = mEmailEdit->text();
379 QString prvt = mUseCheckBox->isChecked() ? "1" : "0";
380 Q3Url::encode (version);
381 Q3Url::encode (platform);
382 Q3Url::encode (name);
383 Q3Url::encode (email);
384
385 /* Registration */
386 QString argument;
387 argument += QString ("?version=%1").arg (version);
388 argument += QString ("&key=%1").arg (key);
389 argument += QString ("&platform=%1").arg (platform);
390 argument += QString ("&name=%1").arg (name);
391 argument += QString ("&email=%1").arg (email);
392 argument += QString ("&private=%1").arg (prvt);
393
394 mHandshake = false;
395 mTimeout->start (20000, true);
396 postRequest (mUrl.host(), mUrl.path() + argument);
397 }
398 else
399 {
400 /* Show registration result */
401 QString result (aTotalData);
402 vboxProblem().showRegisterResult (this, result);
403
404 /* Close the dialog */
405 result == "OK" ? accept() : reject();
406 }
407}
408
409void VBoxRegistrationDlg::onNetError (const QString &aError)
410{
411 abortRegisterRequest (aError);
412}
413
414/* SLOT: QDialog accept slot reimplementation. */
415void VBoxRegistrationDlg::accept()
416{
417 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationDlgWinID,
418 QString::null);
419
420 VBoxRegistrationData regData (mNameEdit->text(), mEmailEdit->text(),
421 mUseCheckBox->isChecked() ? "yes" : "no");
422 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationData,
423 regData.data());
424
425 QDialog::accept();
426}
427
428/* SLOT: QDialog reject slot reimplementation. */
429void VBoxRegistrationDlg::reject()
430{
431 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationDlgWinID,
432 QString::null);
433
434 /* Decrement the triesLeft. */
435 VBoxRegistrationData regData (vboxGlobal().virtualBox().
436 GetExtraData (VBoxDefs::GUI_RegistrationData));
437 if (!regData.isValid() || !regData.isRegistered())
438 {
439 uint triesLeft = regData.triesLeft();
440 if (triesLeft)
441 {
442 -- triesLeft;
443 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationData,
444 QString ("triesLeft=%1")
445 .arg (triesLeft));
446 }
447 }
448
449 QDialog::reject();
450}
451
452void VBoxRegistrationDlg::validate()
453{
454 int pos = 0;
455 QString name = mNameEdit->text();
456 QString email = mEmailEdit->text();
457 finishButton()->setEnabled (
458 mNameEdit->validator()->validate (name, pos) == QValidator::Acceptable &&
459 mEmailEdit->validator()->validate (email, pos) == QValidator::Acceptable);
460}
461
462QString VBoxRegistrationDlg::getPlatform()
463{
464 QString platform;
465
466#if defined (Q_OS_WIN)
467 platform = "win";
468#elif defined (Q_OS_LINUX)
469 platform = "linux";
470#elif defined (Q_OS_MACX)
471 platform = "macosx";
472#elif defined (Q_OS_OS2)
473 platform = "os2";
474#elif defined (Q_OS_FREEBSD)
475 platform = "freebsd";
476#elif defined (Q_OS_SOLARIS)
477 platform = "solaris";
478#else
479 platform = "unknown";
480#endif
481
482 /* the format is <system>.<bitness> */
483 platform += QString (".%1").arg (ARCH_BITS);
484
485 /* add more system information */
486#if defined (Q_OS_WIN)
487 OSVERSIONINFO versionInfo;
488 ZeroMemory (&versionInfo, sizeof (OSVERSIONINFO));
489 versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
490 GetVersionEx (&versionInfo);
491 int major = versionInfo.dwMajorVersion;
492 int minor = versionInfo.dwMinorVersion;
493 int build = versionInfo.dwBuildNumber;
494 QString sp = QString::fromUcs2 ((ushort*)versionInfo.szCSDVersion);
495
496 QString distrib;
497 if (major == 6)
498 distrib = QString ("Windows Vista %1");
499 else if (major == 5)
500 {
501 if (minor == 2)
502 distrib = QString ("Windows Server 2003 %1");
503 else if (minor == 1)
504 distrib = QString ("Windows XP %1");
505 else if (minor == 0)
506 distrib = QString ("Windows 2000 %1");
507 else
508 distrib = QString ("Unknown %1");
509 }
510 else if (major == 4)
511 {
512 if (minor == 90)
513 distrib = QString ("Windows Me %1");
514 else if (minor == 10)
515 distrib = QString ("Windows 98 %1");
516 else if (minor == 0)
517 distrib = QString ("Windows 95 %1");
518 else
519 distrib = QString ("Unknown %1");
520 }
521 else
522 distrib = QString ("Unknown %1");
523 distrib = distrib.arg (sp);
524 QString version = QString ("%1.%2").arg (major).arg (minor);
525 QString kernel = QString ("%1").arg (build);
526 platform += QString (" [Distribution: %1 | Version: %2 | Build: %3]")
527 .arg (distrib).arg (version).arg (kernel);
528#elif defined (Q_OS_OS2)
529 // TODO: add sys info for os2 if any...
530#elif defined (Q_OS_LINUX) || defined (Q_OS_MACX) || defined (Q_OS_FREEBSD) || defined (Q_OS_SOLARIS)
531 char szAppPrivPath [RTPATH_MAX];
532 int rc;
533
534 rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath));
535 Assert (RT_SUCCESS (rc));
536 Q3Process infoScript (QString ("./VBoxSysInfo.sh"), this, "infoScript");
537 infoScript.setWorkingDirectory (QString (szAppPrivPath));
538 if (infoScript.start())
539 {
540 while (infoScript.isRunning()) {}
541 if (infoScript.normalExit())
542 platform += QString (" [%1]").arg (QString(infoScript.readStdout()));
543 }
544#endif
545
546 return platform;
547}
548
549/* This wrapper displays an error message box (unless aReason is
550 * QString::null) with the cause of the request-send procedure
551 * termination. After the message box is dismissed, the downloader signals
552 * to close itself on the next event loop iteration. */
553void VBoxRegistrationDlg::abortRegisterRequest (const QString &aReason)
554{
555 /* Protect against double kill request. */
556 if (mSuicide)
557 return;
558 mSuicide = true;
559
560 if (!aReason.isNull())
561 vboxProblem().cannotConnectRegister (this, mUrl.toString(), aReason);
562
563 /* Allows all the queued signals to be processed before quit. */
564 QTimer::singleShot (0, this, SLOT (reject()));
565}
566
567void VBoxRegistrationDlg::showEvent (QShowEvent *aEvent)
568{
569 validate();
570 Q3Wizard::showEvent (aEvent);
571}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette