Changeset 14274 in vbox for trunk/src/VBox/Frontends/VirtualBox4
- Timestamp:
- Nov 18, 2008 1:37:42 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 39449
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 2 added
- 4 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk
r14092 r14274 217 217 # Headers containing definitions of classes that use the Q_OBJECT macro. 218 218 VirtualBox4_QT_MOCHDRS = \ 219 include/QIHttp.h \ 219 220 include/QIWidgetValidator.h \ 220 221 include/QIHotKeyEdit.h \ … … 242 243 include/VBoxProblemReporter.h \ 243 244 include/VBoxDownloaderWgt.h \ 244 include/VBoxNetworkFramework.h \245 245 include/VBoxAboutDlg.h \ 246 246 include/VBoxCloseVMDlg.h \ … … 282 282 VirtualBox4_QT_MOCSRCS = \ 283 283 src/VBoxSelectorWnd.cpp \ 284 src/VBoxConsoleWnd.cpp \ 284 285 src/VBoxMediaManagerDlg.cpp 285 286 ifdef VBOX_WITH_XPCOM … … 318 319 src/VBoxVMListView.cpp \ 319 320 src/VBoxFrameBuffer.cpp \ 320 src/HappyHttp.cpp \321 src/VBoxNetworkFramework.cpp \322 321 src/VBoxAboutDlg.cpp \ 323 322 src/VBoxCloseVMDlg.cpp \ … … 391 390 # The Qt modules we're using. 392 391 # (The include directory and lib/framework for each module will be added by the Qt4 unit.) 393 VirtualBox4_QT_MODULES = Core Gui 392 VirtualBox4_QT_MODULES = Core Gui Network 394 393 395 394 # Import QDesigner UI sources and translations from VBoxUI.pro. … … 412 411 VirtualBox4_QT_TRANSLATIONS_INST = $(INST_BIN)nls/ 413 412 414 415 # Some flag hacks (should go away).416 ifneq ($(KBUILD_TARGET),win)417 VirtualBox4_src/HappyHttp.cpp_CXXFLAGS += -fexceptions418 VirtualBox4_src/VBoxDownloaderWgt.cpp_CXXFLAGS += -fexceptions419 VirtualBox4_src/VBoxNetworkFramework.cpp_CXXFLAGS += -fexceptions420 endif421 VirtualBox4_src/HappyHttp.cpp_CXXFLAGS.linux += -O2422 413 423 414 ## @todo how to detect what tool is used? -
trunk/src/VBox/Frontends/VirtualBox4/VirtualBox.qrc
r13553 r14274 109 109 <file alias="site_disabled_32px.png">images/site_disabled_32px.png</file> 110 110 <file alias="register_16px.png">images/register_16px.png</file> 111 <file alias="register_32px.png">images/register_32px.png</file> 111 112 <file alias="register_disabled_16px.png">images/register_disabled_16px.png</file> 112 113 <file alias="reset_16px.png">images/reset_16px.png</file> -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDownloaderWgt.h
r9729 r14274 24 24 #define __VBoxDownloaderWgt_h__ 25 25 26 #include "HappyHttp.h"27 26 #include "QIWithRetranslateUI.h" 28 27 29 28 /* Qt includes */ 29 #include <QUrl> 30 30 #include <QWidget> 31 #include <QUrl>32 #include <QMutex>33 31 34 class Q StatusBar;35 class Q Action;32 class QIHttp; 33 class QHttpResponseHeader; 36 34 class QProgressBar; 37 35 class QToolButton; 38 class QThread;39 class QTimer;40 typedef happyhttp::Connection HConnect;41 36 42 /** class VBoxDownloaderWgt 37 /** 38 * The VBoxDownloaderWgt class is QWidget class re-implementation which embeds 39 * into the Dialog's status-bar and allows background http downloading. 40 * This class is not supposed to be used itself and made for sub-classing only. 43 41 * 44 * The VBoxDownloaderWgt class is an QWidget class for Guest Additions 45 * http backgroung downloading. This class is also used to display the 46 * Guest Additions download state through the progress dialog integrated 47 * into the VM console status bar. 42 * This class has two parts: 43 * 1. Acknowledging (getting information about target presence and size). 44 * 2. Downloading (starting and handling file downloading process). 45 * Every subclass can determine using or not those two parts and handling 46 * the result of those parts itself. 48 47 */ 49 class VBoxDownloaderWgt : public QIWithRetranslateUI <QWidget>48 class VBoxDownloaderWgt : public QIWithRetranslateUI <QWidget> 50 49 { 51 50 Q_OBJECT; … … 53 52 public: 54 53 55 VBoxDownloaderWgt (QStatusBar *aStatusBar, QAction *aAction, 56 const QString &aUrl, const QString &aTarget); 54 VBoxDownloaderWgt (const QString &aSource, const QString &aTarget); 57 55 56 virtual void start(); 58 57 59 bool isCheckingPresence() { return mIsChecking; } 58 protected slots: 59 60 /* Acknowledging part */ 61 virtual void acknowledgeStart(); 62 virtual void acknowledgeProcess (const QHttpResponseHeader &aResponse); 63 virtual void acknowledgeFinished (bool aError); 64 65 /* Downloading part */ 66 virtual void downloadStart(); 67 virtual void downloadProcess (int aDone, int aTotal); 68 virtual void downloadFinished (bool aError); 69 70 /* Common slots */ 71 virtual void cancelDownloading(); 72 virtual void abortDownload (const QString &aError); 73 virtual void suicide(); 60 74 61 75 protected: 62 76 63 void retranslateUi(); 77 /* In sub-class this function will show the user downloading object size 78 * and ask him about downloading confirmation. Returns user response. */ 79 virtual bool confirmDownload() = 0; 64 80 65 private slots: 81 /* In sub-class this function will show the user which error happens 82 * in context of downloading file and executing his request. */ 83 virtual void warnAboutError (const QString &aError) = 0; 66 84 67 /* This slot is used to control the connection timeout. */ 68 void processTimeout(); 69 70 /* This slot is used to process cancel-button clicking signal. */ 71 void processAbort(); 72 73 /* This slot is used to terminate the downloader, activate the 74 * Install Guest Additions action and removing the downloader's 75 * sub-widgets from the VM Console status-bar. */ 76 void suicide(); 77 78 private: 79 80 /* Used to process all the widget events */ 81 bool event (QEvent *aEvent); 82 83 /* This function is used to make a request to get a file */ 84 void getFile(); 85 86 /* This function is used to ask the user about he wants to download the 87 * founded Guest Additions image or not. It also shows the progress-bar 88 * and Cancel-button widgets. */ 89 void processFile (int aSize); 90 91 /* This wrapper displays an error message box (unless @aReason is 92 * QString::null) with the cause of the download procedure 93 * termination. After the message box is dismissed, the downloader signals 94 * to close itself on the next event loop iteration. */ 95 void abortDownload (const QString &aReason = QString::null); 96 97 void abortConnection(); 98 99 QUrl mUrl; 85 QUrl mSource; 100 86 QString mTarget; 101 QStatusBar *mStatusBar; 102 QAction *mAction; 87 QIHttp *mHttp; 103 88 QProgressBar *mProgressBar; 104 89 QToolButton *mCancelButton; 105 bool mIsChecking;106 bool mSuicide;107 HConnect *mConn;108 QThread *mRequestThread;109 QMutex mMutex;110 QByteArray mDataArray;111 QDataStream mDataStream;112 QTimer *mTimeout;113 90 }; 114 91 115 #endif 92 #endif // __VBoxDownloaderWgt_h__ 116 93 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxRegistrationDlg.h
r11401 r14274 25 25 26 26 #include "QIAbstractWizard.h" 27 #include "VBoxRegistrationDlg.gen.h"28 #include "COMDefs.h"29 27 #include "QIWidgetValidator.h" 30 28 #include "QIWithRetranslateUI.h" 29 #include "VBoxRegistrationDlg.gen.h" 31 30 32 31 /* Qt includes */ 33 32 #include <QUrl> 34 33 35 class VBoxNetworkFramework;34 class QIHttp; 36 35 37 class VBoxRegistrationDlg : public QIWithRetranslateUI 2<QIAbstractWizard>,36 class VBoxRegistrationDlg : public QIWithRetranslateUI <QIAbstractWizard>, 38 37 public Ui::VBoxRegistrationDlg 39 38 { … … 42 41 public: 43 42 44 VBoxRegistrationDlg (VBoxRegistrationDlg **aSelf, QWidget *aParent = 0, 45 Qt::WindowFlags aFlags = 0); 43 static bool hasToBeShown(); 44 45 VBoxRegistrationDlg (VBoxRegistrationDlg **aSelf, QWidget *aParent = 0); 46 46 ~VBoxRegistrationDlg(); 47 48 static bool hasToBeShown();49 47 50 48 protected: … … 56 54 void accept(); 57 55 void reject(); 58 void handshake(); 59 void registration(); 60 void processTimeout(); 61 void onNetBegin (int aStatus); 62 void onNetData (const QByteArray &aData); 63 void onNetEnd (const QByteArray &aData); 64 void onNetError (const QString &aError); 56 57 void handshakeStart(); 58 void handshakeResponse (bool aError); 59 60 void registrationStart(); 61 void registrationResponse (bool aError); 65 62 66 63 void revalidate (QIWidgetValidator *aWval); … … 70 67 private: 71 68 72 void postRequest (const Q String &aHost, const QString &aUrl, const QString &aBody);73 void abortRe gisterRequest (const QString &aReason);69 void postRequest (const QUrl &aUrl); 70 void abortRequest (const QString &aReason); 74 71 void finish(); 75 72 … … 77 74 QIWidgetValidator *mWvalReg; 78 75 QUrl mUrl; 76 QIHttp *mHttp; 79 77 QString mKey; 80 QTimer *mTimeout;81 bool mHandshake;82 bool mSuicide;83 VBoxNetworkFramework *mNetfw;84 78 }; 85 79 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUpdateDlg.h
r11401 r14274 24 24 #define __VBoxUpdateDlg_h__ 25 25 26 /* Common includes */27 26 #include "QIAbstractWizard.h" 27 #include "QIWithRetranslateUI.h" 28 28 #include "VBoxUpdateDlg.gen.h" 29 #include "QIWithRetranslateUI.h"30 29 31 30 /* Qt includes */ … … 33 32 #include <QDate> 34 33 35 class VBoxNetworkFramework;34 class QIHttp; 36 35 37 36 /** … … 84 83 85 84 /* Private variables */ 86 static QList <UpdateDay> mDayList;85 static QList <UpdateDay> mDayList; 87 86 88 87 QString mData; … … 91 90 }; 92 91 93 class VBoxUpdateDlg : public QIWithRetranslateUI 2<QIAbstractWizard>,92 class VBoxUpdateDlg : public QIWithRetranslateUI <QIAbstractWizard>, 94 93 public Ui::VBoxUpdateDlg 95 94 { … … 100 99 static bool isNecessary(); 101 100 102 VBoxUpdateDlg (VBoxUpdateDlg **aSelf, bool aForceRun, 103 QWidget *aParent = 0, Qt::WindowFlags aFlags = 0); 101 VBoxUpdateDlg (VBoxUpdateDlg **aSelf, bool aForceRun, QWidget *aParent = 0); 104 102 ~VBoxUpdateDlg(); 105 103 106 104 public slots: 107 105 108 void accept();109 106 void search(); 110 107 … … 115 112 private slots: 116 113 117 void processTimeout(); 118 119 void onNetBegin (int aStatus); 120 void onNetData (const QByteArray &aData); 121 void onNetEnd (const QByteArray &aData); 122 void onNetError (const QString &aError); 123 114 void accept(); 115 void searchResponse (bool aError); 124 116 void onPageShow(); 125 117 126 118 private: 127 119 128 /* Private functions */ 129 void networkAbort (const QString &aReason); 130 void processResponse (const QString &aResponse); 120 void abortRequest (const QString &aReason); 131 121 132 122 /* Private variables */ 133 123 VBoxUpdateDlg **mSelf; 134 VBoxNetworkFramework *mNetfw; 135 QTimer *mTimeout; 136 QUrl mUrl; 137 bool mForceRun; 138 bool mSuicide; 124 QUrl mUrl; 125 QIHttp *mHttp; 126 bool mForceRun; 139 127 }; 140 128 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp
r13580 r14274 36 36 #include "QIStatusBar.h" 37 37 #include "QIHotKeyEdit.h" 38 #include "QIHttp.h" 38 39 39 40 /* Qt includes */ … … 44 45 #include <QDir> 45 46 #include <QTimer> 47 #include <QProgressBar> 46 48 #ifdef Q_WS_X11 47 49 # include <QX11Info> … … 93 95 class Q3HttpResponseHeader; 94 96 #endif 97 98 class VBoxAdditionsDownloader : public VBoxDownloaderWgt 99 { 100 Q_OBJECT; 101 102 public: 103 104 VBoxAdditionsDownloader (const QString &aSource, const QString &aTarget, QAction *aAction) 105 : VBoxDownloaderWgt (aSource, aTarget) 106 , mAction (aAction) 107 { 108 mAction->setEnabled (false); 109 retranslateUi(); 110 } 111 112 void start() 113 { 114 acknowledgeStart(); 115 } 116 117 protected: 118 119 void retranslateUi() 120 { 121 mCancelButton->setText (tr ("Cancel")); 122 mProgressBar->setToolTip (tr ("Downloading the VirtualBox Guest Additions " 123 "CD image from <nobr><b>%1</b>...</nobr>") 124 .arg (mSource.toString())); 125 mCancelButton->setToolTip (tr ("Cancel the VirtualBox Guest " 126 "Additions CD image download")); 127 } 128 129 private slots: 130 131 void downloadFinished (bool aError) 132 { 133 if (aError) 134 VBoxDownloaderWgt::downloadFinished (aError); 135 else 136 { 137 QByteArray receivedData (mHttp->readAll()); 138 /* Serialize the incoming buffer into the .iso image. */ 139 while (true) 140 { 141 QFile file (mTarget); 142 if (file.open (QIODevice::WriteOnly)) 143 { 144 file.write (receivedData); 145 file.close(); 146 if (vboxProblem().confirmMountAdditions (mSource.toString(), 147 QDir::toNativeSeparators (mTarget))) 148 vboxGlobal().consoleWnd().installGuestAdditionsFrom (mTarget); 149 QTimer::singleShot (0, this, SLOT (suicide())); 150 break; 151 } 152 else 153 { 154 vboxProblem().message (window(), VBoxProblemReporter::Error, 155 tr ("<p>Failed to save the downloaded file as " 156 "<nobr><b>%1</b>.</nobr></p>") 157 .arg (QDir::toNativeSeparators (mTarget))); 158 } 159 160 QString target = vboxGlobal().getExistingDirectory ( 161 QFileInfo (mTarget).absolutePath(), this, 162 tr ("Select folder to save Guest Additions image to"), true); 163 if (target.isNull()) 164 QTimer::singleShot (0, this, SLOT (suicide())); 165 else 166 mTarget = QDir (target).absoluteFilePath (QFileInfo (mTarget).fileName()); 167 } 168 } 169 } 170 171 void suicide() 172 { 173 QStatusBar *sb = qobject_cast <QStatusBar*> (parent()); 174 Assert (sb); 175 sb->removeWidget (this); 176 mAction->setEnabled (true); 177 VBoxDownloaderWgt::suicide(); 178 } 179 180 private: 181 182 bool confirmDownload() 183 { 184 return vboxProblem().confirmDownloadAdditions (mSource.toString(), 185 mHttp->lastResponse().contentLength()); 186 } 187 188 void warnAboutError (const QString &aError) 189 { 190 return vboxProblem().cannotDownloadGuestAdditions (mSource.toString(), aError); 191 } 192 193 QAction *mAction; 194 }; 95 195 96 196 /** \class VBoxConsoleWnd … … 2682 2782 #else 2683 2783 char szAppPrivPath [RTPATH_MAX]; 2684 int rc; 2685 2686 rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath)); 2784 int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath)); 2687 2785 AssertRC (rc); 2688 2786 … … 2691 2789 #endif 2692 2790 2791 /* Check the standard image locations */ 2693 2792 if (QFile::exists (src1)) 2694 installGuestAdditionsFrom (src1);2793 return installGuestAdditionsFrom (src1); 2695 2794 else if (QFile::exists (src2)) 2696 installGuestAdditionsFrom (src2);2697 else 2698 {2699 /* Check for the already registered required image */2700 CVirtualBox vbox = vboxGlobal().virtualBox();2701 QString name = QString ("VBoxGuestAdditions_%1.iso")2702 .arg (vbox.GetVersion().remove ("_OSE")); 2703 2704 CDVDImage2Vector vec = vbox.GetDVDImages();2705 for (CDVDImage2Vector::ConstIterator it = vec.begin();2706 it != vec.end(); ++ it)2707 {2708 QString path = it->GetLocation();2709 /* Compare the name part ignoring the file case */2710 QString fn = QFileInfo (path).fileName();2711 if (RTPathCompare (name.toUtf8().constData(), fn.toUtf8().constData()) == 0)2712 return installGuestAdditionsFrom (path);2713 } 2714 2715 /* Download the required image: */2716 int rc = vboxProblem().cannotFindGuestAdditions (2717 QDir::toNativeSeparators (src1), QDir::toNativeSeparators (src2));2718 if (rc == QIMessageBox::Yes)2719 {2720 QString url = QString ("http://download.virtualbox.org/virtualbox/%1/")2721 .arg (vbox.GetVersion().remove ("_OSE")) + name;2722 QString target = QDir (vboxGlobal().virtualBox().GetHomeFolder())2723 .absoluteFilePath (name); 2724 2725 new VBox DownloaderWgt (statusBar(), devicesInstallGuestToolsAction,2726 url, target);2727 }2795 return installGuestAdditionsFrom (src2); 2796 2797 /* Check for the already registered image */ 2798 CVirtualBox vbox = vboxGlobal().virtualBox(); 2799 QString name = QString ("VBoxGuestAdditions_%1.iso") 2800 .arg (vbox.GetVersion().remove ("_OSE")); 2801 2802 CDVDImage2Vector vec = vbox.GetDVDImages(); 2803 for (CDVDImage2Vector::ConstIterator it = vec.begin(); 2804 it != vec.end(); ++ it) 2805 { 2806 QString path = it->GetLocation(); 2807 /* Compare the name part ignoring the file case */ 2808 QString fn = QFileInfo (path).fileName(); 2809 if (RTPathCompare (name.toUtf8().constData(), fn.toUtf8().constData()) == 0) 2810 return installGuestAdditionsFrom (path); 2811 } 2812 2813 /* Download the required image */ 2814 int result = vboxProblem().cannotFindGuestAdditions ( 2815 QDir::toNativeSeparators (src1), QDir::toNativeSeparators (src2)); 2816 if (result == QIMessageBox::Yes) 2817 { 2818 QString source = QString ("http://download.virtualbox.org/virtualbox/%1/") 2819 .arg (vbox.GetVersion().remove ("_OSE")) + name; 2820 QString target = QDir (vboxGlobal().virtualBox().GetHomeFolder()) 2821 .absoluteFilePath (name); 2822 2823 VBoxAdditionsDownloader *dl = 2824 new VBoxAdditionsDownloader (source, target, devicesInstallGuestToolsAction); 2825 statusBar()->addWidget (dl, 0); 2826 dl->start(); 2728 2827 } 2729 2828 } … … 2745 2844 2746 2845 if (!vbox.isOk()) 2747 { 2748 vboxProblem().cannotOpenMedium (this, vbox, 2749 VBoxDefs::MediaType_DVD, aSource); 2750 return; 2751 } 2846 return vboxProblem().cannotOpenMedium (this, vbox, 2847 VBoxDefs::MediaType_DVD, aSource); 2752 2848 2753 2849 Assert (!uuid.isNull()); 2754 2850 CDVDDrive drv = csession.GetMachine().GetDVDDrive(); 2755 2851 drv.MountImage (uuid); 2756 /// @todo NEWMEDIA use VBoxProblemReporter::cannotMountMedia2757 2852 AssertWrapperOk (drv); 2853 if (drv.isOk()) 2854 { 2855 if (mIsAutoSaveMedia) 2856 { 2857 CMachine m = csession.GetMachine(); 2858 m.SaveSettings(); 2859 if (!m.isOk()) 2860 vboxProblem().cannotSaveMachineSettings (m); 2861 } 2862 } 2758 2863 } 2759 2864 … … 3635 3740 QDialog::showEvent (aEvent); 3636 3741 } 3742 3743 #include "VBoxConsoleWnd.moc" -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDownloaderWgt.cpp
r13580 r14274 21 21 */ 22 22 23 #include "QIHttp.h" 24 #include "VBoxDownloaderWgt.h" 23 25 #include "VBoxGlobal.h" 24 #include "VBoxProblemReporter.h"25 #include "VBoxConsoleWnd.h"26 #include "VBoxDownloaderWgt.h"27 26 28 27 /* Qt includes */ 28 #include <QFile> 29 #include <QHBoxLayout> 30 #include <QHttpResponseHeader> 29 31 #include <QProgressBar> 30 #include <QHBoxLayout>31 #include <QTimer>32 32 #include <QToolButton> 33 #include <QStatusBar>34 #include <QDir>35 #include <QThread>36 33 37 /* These notifications are used to notify the GUI thread about different 38 * downloading events: Downloading Started, Downloading in Progress,39 * Downloading Finished. */40 enum 34 VBoxDownloaderWgt::VBoxDownloaderWgt (const QString &aSource, const QString &aTarget) 35 : mSource (aSource), mTarget (aTarget), mHttp (0) 36 , mProgressBar (new QProgressBar (this)) 37 , mCancelButton (new QToolButton (this)) 41 38 { 42 StartDownloadEventType = QEvent::User + 100, 43 ProcessDownloadEventType, 44 FinishDownloadEventType, 45 ErrorDownloadEventType 46 }; 47 48 class StartDownloadEvent : public QEvent 49 { 50 public: 51 StartDownloadEvent (int aStatus, long aSize) 52 : QEvent ((QEvent::Type) StartDownloadEventType) 53 , mStatus (aStatus), mSize (aSize) {} 54 55 int mStatus; 56 long mSize; 57 }; 58 59 class ProcessDownloadEvent : public QEvent 60 { 61 public: 62 ProcessDownloadEvent (const char *aData, ulong aSize) 63 : QEvent ((QEvent::Type) ProcessDownloadEventType) 64 , mData (aData, aSize) {} 65 66 QByteArray mData; 67 }; 68 69 class FinishDownloadEvent : public QEvent 70 { 71 public: 72 FinishDownloadEvent() 73 : QEvent ((QEvent::Type) FinishDownloadEventType) {} 74 }; 75 76 class ErrorDownloadEvent : public QEvent 77 { 78 public: 79 ErrorDownloadEvent (const QString &aInfo) 80 : QEvent ((QEvent::Type) ErrorDownloadEventType) 81 , mInfo (aInfo) {} 82 83 QString mInfo; 84 }; 85 86 /* This callback is used to handle the file-downloading procedure 87 * beginning. It checks the downloading status for the file 88 * presence verifying purposes. */ 89 void OnBegin (const happyhttp::Response *aResponse, void *aUserdata) 90 { 91 VBoxDownloaderWgt *loader = static_cast<VBoxDownloaderWgt*> (aUserdata); 92 if (loader->isCheckingPresence()) 93 { 94 int status = aResponse->getstatus(); 95 QString contentLength = aResponse->getheader ("Content-length"); 96 97 QApplication::postEvent (loader, 98 new StartDownloadEvent (status, contentLength.toLong())); 99 } 100 } 101 102 /* This callback is used to handle the progress of the file-downloading 103 * procedure. It also checks the downloading status for the file 104 * presence verifying purposes. */ 105 void OnData (const happyhttp::Response*, void *aUserdata, 106 const unsigned char *aData, int aSize) 107 { 108 VBoxDownloaderWgt *loader = static_cast<VBoxDownloaderWgt*> (aUserdata); 109 if (!loader->isCheckingPresence()) 110 { 111 QApplication::postEvent (loader, 112 new ProcessDownloadEvent ((const char*)aData, aSize)); 113 } 114 } 115 116 /* This callback is used to handle the finish signal of every operation's 117 * response. It is used to display the errors occurred during the download 118 * operation and for the received-buffer serialization procedure. */ 119 void OnComplete (const happyhttp::Response*, void *aUserdata) 120 { 121 VBoxDownloaderWgt *loader = static_cast<VBoxDownloaderWgt*> (aUserdata); 122 if (!loader->isCheckingPresence()) 123 QApplication::postEvent (loader, 124 new FinishDownloadEvent()); 125 } 126 127 VBoxDownloaderWgt::VBoxDownloaderWgt (QStatusBar *aStatusBar, QAction *aAction, 128 const QString &aUrl, const QString &aTarget) 129 : QIWithRetranslateUI<QWidget> () 130 , mUrl (aUrl), mTarget (aTarget) 131 , mStatusBar (aStatusBar), mAction (aAction) 132 , mProgressBar (0), mCancelButton (0) 133 , mIsChecking (true), mSuicide (false) 134 , mConn (new HConnect (mUrl.host().toAscii().constData(), 80)) 135 , mRequestThread (0) 136 , mDataStream (&mDataArray, QIODevice::WriteOnly) 137 , mTimeout (new QTimer (this)) 138 { 139 /* Disable the associated action */ 140 mAction->setEnabled (false); 141 mTimeout->setSingleShot (true); 142 connect (mTimeout, SIGNAL (timeout()), 143 this, SLOT (processTimeout())); 144 145 /* Drawing itself */ 146 setFixedHeight (16); 147 148 mProgressBar = new QProgressBar (this); 39 /* Progress Bar setup */ 149 40 mProgressBar->setFixedWidth (100); 150 41 mProgressBar->setFormat ("%p%"); 151 42 mProgressBar->setValue (0); 152 43 153 mCancelButton = new QToolButton (this);44 /* Cancel Button setup */ 154 45 mCancelButton->setAutoRaise (true); 155 46 mCancelButton->setFocusPolicy (Qt::TabFocus); 156 connect (mCancelButton, SIGNAL (clicked()), 157 this, SLOT (processAbort())); 47 connect (mCancelButton, SIGNAL (clicked()), this, SLOT (cancelDownloading())); 158 48 49 /* Downloader setup */ 50 setFixedHeight (16); 159 51 QHBoxLayout *mainLayout = new QHBoxLayout (this); 160 52 mainLayout->setSpacing (0); … … 163 55 mainLayout->addWidget (mCancelButton); 164 56 mainLayout->addStretch (1); 165 166 /* Prepare the connection */167 mConn->setcallbacks (OnBegin, OnData, OnComplete, this);168 169 retranslateUi();170 mStatusBar->addWidget (this, 1);171 172 /* Try to get the required file for the information */173 getFile();174 57 } 175 58 176 void VBoxDownloaderWgt:: retranslateUi()59 void VBoxDownloaderWgt::start() 177 60 { 178 mCancelButton->setText (tr ("Cancel")); 179 /// @todo the below title should be parametrized 180 mProgressBar->setToolTip (tr ("Downloading the VirtualBox Guest Additions " 181 "CD image from <nobr><b>%1</b>...</nobr>") 182 .arg (mUrl.toString())); 183 /// @todo the below title should be parametrized 184 mCancelButton->setToolTip (tr ("Cancel the VirtualBox Guest " 185 "Additions CD image download")); 61 /* By default we are not using acknowledging step, so 62 * making downloading immediately */ 63 downloadStart(); 186 64 } 187 65 188 /* This slot is used to control the connection timeout. */ 189 void VBoxDownloaderWgt::processTimeout() 66 /* This function is used to start acknowledging mechanism: 67 * checking file presence & size */ 68 void VBoxDownloaderWgt::acknowledgeStart() 190 69 { 191 abortDownload (tr ("Connection timed out.")); 70 delete mHttp; 71 mHttp = new QIHttp (this, mSource.host()); 72 connect (mHttp, SIGNAL (responseHeaderReceived (const QHttpResponseHeader &)), 73 this, SLOT (acknowledgeProcess (const QHttpResponseHeader &))); 74 connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (acknowledgeFinished (bool))); 75 mHttp->get (mSource.toEncoded()); 192 76 } 193 77 194 /* This slot is used to process cancel-button clicking signal.*/195 void VBoxDownloaderWgt:: processAbort()78 /* This function is used to store content length */ 79 void VBoxDownloaderWgt::acknowledgeProcess (const QHttpResponseHeader &aResponse) 196 80 { 197 abortDownload (tr ("The download process has been cancelled "198 "by the user."));81 /* Abort connection as we already got all we need */ 82 mHttp->abort(); 199 83 } 200 84 201 /* This slot is used to terminate the downloader, activate the 202 * associated action and removing the downloader's 203 * sub-widgets from the VM Console status-bar. */ 85 /* This function is used to ask the user about if he really want 86 * to download file of proposed size if no error present or 87 * abort download progress if error is present */ 88 void VBoxDownloaderWgt::acknowledgeFinished (bool aError) 89 { 90 AssertMsg (aError, ("Error must be 'true' due to aborting.\n")); 91 92 mHttp->disconnect (this); 93 94 switch (mHttp->errorCode()) 95 { 96 case QIHttp::Aborted: 97 { 98 /* Ask the user if he wish to download it */ 99 if (confirmDownload()) 100 QTimer::singleShot (0, this, SLOT (downloadStart())); 101 else 102 QTimer::singleShot (0, this, SLOT (suicide())); 103 break; 104 } 105 case QIHttp::MovedTemporarilyError: 106 { 107 /* Restart downloading at new location */ 108 mSource = mHttp->lastResponse().value ("location"); 109 QTimer::singleShot (0, this, SLOT (acknowledgeStart())); 110 break; 111 } 112 default: 113 { 114 /* Show error happens during acknowledging */ 115 abortDownload (mHttp->errorString()); 116 break; 117 } 118 } 119 } 120 121 /* This function is used to start downloading mechanism: 122 * downloading and saving the target */ 123 void VBoxDownloaderWgt::downloadStart() 124 { 125 delete mHttp; 126 mHttp = new QIHttp (this, mSource.host()); 127 connect (mHttp, SIGNAL (dataReadProgress (int, int)), 128 this, SLOT (downloadProcess (int, int))); 129 connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (downloadFinished (bool))); 130 mHttp->get (mSource.toEncoded()); 131 } 132 133 /* this function is used to observe the downloading progress through 134 * changing the corresponding qprogressbar value */ 135 void VBoxDownloaderWgt::downloadProcess (int aDone, int aTotal) 136 { 137 mProgressBar->setMaximum (aTotal); 138 mProgressBar->setValue (aDone); 139 } 140 141 /* This function is used to handle the 'downloading finished' issue 142 * through saving the downloaded into the file if there in no error or 143 * notifying the user about error happens */ 144 void VBoxDownloaderWgt::downloadFinished (bool aError) 145 { 146 mHttp->disconnect (this); 147 148 if (aError) 149 { 150 /* Show information about error happens */ 151 if (mHttp->errorCode() == QIHttp::Aborted) 152 abortDownload (tr ("The download process has been cancelled by the user.")); 153 else 154 abortDownload (mHttp->errorString()); 155 } 156 else 157 { 158 /* Trying to serialize the incoming buffer into the target, this is the 159 * default behavior which have to be reimplemented in sub-class */ 160 QFile file (mTarget); 161 if (file.open (QIODevice::WriteOnly)) 162 { 163 file.write (mHttp->readAll()); 164 file.close(); 165 } 166 QTimer::singleShot (0, this, SLOT (suicide())); 167 } 168 } 169 170 /* This slot is used to process cancel-button clicking */ 171 void VBoxDownloaderWgt::cancelDownloading() 172 { 173 QTimer::singleShot (0, this, SLOT (suicide())); 174 } 175 176 /* This function is used to abort download by showing aborting reason 177 * and calling the downloader's delete function */ 178 void VBoxDownloaderWgt::abortDownload (const QString &aError) 179 { 180 warnAboutError (aError); 181 QTimer::singleShot (0, this, SLOT (suicide())); 182 } 183 184 /* This function is used to delete the downloader widget itself, 185 * should be reimplemented to enhanse necessary functionality in sub-class */ 204 186 void VBoxDownloaderWgt::suicide() 205 187 { 206 delete mRequestThread;207 delete mConn;208 209 mAction->setEnabled (true);210 mStatusBar->removeWidget (this);211 188 delete this; 212 189 } 213 190 214 /* Used to process all the widget events */215 bool VBoxDownloaderWgt::event (QEvent *aEvent)216 {217 switch (aEvent->type())218 {219 case StartDownloadEventType:220 {221 StartDownloadEvent *e = static_cast<StartDownloadEvent*> (aEvent);222 223 mTimeout->stop();224 if (e->mStatus == 404)225 abortDownload (tr ("Could not locate the file on "226 "the server (response: %1).").arg (e->mStatus));227 else228 processFile (e->mSize);229 230 return true;231 }232 case ProcessDownloadEventType:233 {234 ProcessDownloadEvent *e = static_cast<ProcessDownloadEvent*> (aEvent);235 236 mTimeout->start (20000);237 mProgressBar->setValue (mProgressBar->value() + e->mData.size());238 mDataStream.writeRawData (e->mData.data(), e->mData.size());239 240 return true;241 }242 case FinishDownloadEventType:243 {244 mTimeout->stop();245 246 /* Serialize the incoming buffer into the .iso image. */247 while (true)248 {249 QFile file (mTarget);250 if (file.open (QIODevice::WriteOnly))251 {252 file.write (mDataArray);253 file.close();254 /// @todo the below action is not part of the generic255 // VBoxDownloaderWgt functionality, so this class should just256 // emit a signal when it is done saving the downloaded file257 // (succeeded or failed).258 if (vboxProblem()259 .confirmMountAdditions (mUrl.toString(),260 QDir::toNativeSeparators (mTarget)))261 vboxGlobal().consoleWnd().installGuestAdditionsFrom (mTarget);262 QTimer::singleShot (0, this, SLOT (suicide()));263 break;264 }265 else266 {267 vboxProblem().message (mStatusBar->window(),268 VBoxProblemReporter::Error,269 tr ("<p>Failed to save the downloaded file as "270 "<nobr><b>%1</b>.</nobr></p>")271 .arg (QDir::toNativeSeparators (mTarget)));272 }273 274 /// @todo read the todo above (probably should just parametrize275 /// the title)276 QString target = vboxGlobal().getExistingDirectory (277 QFileInfo (mTarget).absolutePath(), this,278 tr ("Select folder to save Guest Additions image to"), true);279 if (target.isNull())280 QTimer::singleShot (0, this, SLOT (suicide()));281 else282 mTarget = QDir (target).absoluteFilePath (QFileInfo (mTarget).fileName());283 }284 285 return true;286 }287 case ErrorDownloadEventType:288 {289 ErrorDownloadEvent *e = static_cast<ErrorDownloadEvent*> (aEvent);290 291 abortDownload (e->mInfo);292 293 return true;294 }295 default:296 break;297 }298 299 return QWidget::event (aEvent);300 }301 302 /* This function is used to make a request to get a file */303 void VBoxDownloaderWgt::getFile()304 {305 /* Http request thread class */306 class Thread : public QThread307 {308 public:309 310 Thread (VBoxDownloaderWgt *aParent, HConnect *aConn,311 const QString &aPath, QMutex *aMutex)312 : mParent (aParent), mConn (aConn)313 , mPath (aPath), mMutex (aMutex) {}314 315 virtual void run()316 {317 try318 {319 mConn->request ("GET", mPath.toAscii().constData());320 while (mConn->outstanding())321 {322 QMutexLocker locker (mMutex);323 mConn->pump();324 }325 }326 catch (happyhttp::Wobbly &ex)327 {328 QApplication::postEvent (mParent,329 new ErrorDownloadEvent (ex.what()));330 }331 }332 333 private:334 335 VBoxDownloaderWgt *mParent;336 HConnect *mConn;337 QString mPath;338 QMutex *mMutex;339 };340 341 if (!mRequestThread)342 mRequestThread = new Thread (this, mConn, mUrl.path(), &mMutex);343 mRequestThread->start();344 mTimeout->start (20000);345 }346 347 /* This function is used to ask the user about he wants to download the348 * founded Guest Additions image or not. It also shows the progress-bar349 * and Cancel-button widgets. */350 void VBoxDownloaderWgt::processFile (int aSize)351 {352 abortConnection();353 354 /// @todo the below action is not part of the generic355 // VBoxDownloaderWgt functionality, so this class should just356 // emit a signal when it is done detecting the file size.357 358 /* Ask user about GA image downloading */359 if (vboxProblem().confirmDownloadAdditions (mUrl.toString(), aSize))360 {361 mIsChecking = false;362 mProgressBar->setMaximum (aSize);363 getFile();364 }365 else366 abortDownload();367 }368 369 /* This wrapper displays an error message box (unless aReason is370 * QString::null) with the cause of the download procedure371 * termination. After the message box is dismissed, the downloader signals372 * to close itself on the next event loop iteration. */373 void VBoxDownloaderWgt::abortDownload (const QString &aReason)374 {375 abortConnection();376 377 /* Protect against double kill request. */378 if (mSuicide)379 return;380 mSuicide = true;381 382 /// @todo the below action is not part of the generic383 // VBoxDownloaderWgt functionality, so this class should just emit a384 // signal to display the error message when the download is aborted.385 386 if (!aReason.isNull())387 vboxProblem().cannotDownloadGuestAdditions (mUrl.toString(), aReason);388 389 /* Allows all the queued signals to be processed before quit. */390 QTimer::singleShot (0, this, SLOT (suicide()));391 }392 393 void VBoxDownloaderWgt::abortConnection()394 {395 mMutex.lock();396 mConn->close();397 mMutex.unlock();398 }399 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxProblemReporter.cpp
r14190 r14274 1539 1539 1540 1540 bool VBoxProblemReporter::confirmDownloadAdditions (const QString &aURL, 1541 ulong aSize)1541 ulong aSize) 1542 1542 { 1543 1543 return messageOkCancel (&vboxGlobal().consoleWnd(), Question, … … 1624 1624 message (aParent, Error, 1625 1625 tr ("<p>Failed to connect to the VirtualBox online " 1626 "registration service .</p><p>%1</p>")1626 "registration service due to the following error:</p><p><b>%1</b></p>") 1627 1627 .arg (aReason)); 1628 1628 } … … 1656 1656 const QString &aReason) 1657 1657 { 1658 message (aParent, Info,1658 message (aParent, Error, 1659 1659 tr ("<p>Unable to obtain the new version information " 1660 "due to the following networkerror:</p><p><b>%1</b></p>")1660 "due to the following error:</p><p><b>%1</b></p>") 1661 1661 .arg (aReason)); 1662 1662 } -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxRegistrationDlg.cpp
r11465 r14274 21 21 */ 22 22 23 #include " VBoxRegistrationDlg.h"23 #include "QIHttp.h" 24 24 #include "VBoxGlobal.h" 25 25 #include "VBoxProblemReporter.h" 26 #include "VBox NetworkFramework.h"26 #include "VBoxRegistrationDlg.h" 27 27 28 28 /* Qt includes */ 29 29 #include <QTimer> 30 #include <QProcess>31 32 #include <iprt/err.h>33 #include <iprt/param.h>34 #include <iprt/path.h>35 36 /* Time to auto-disconnect if no network answer received. */37 static const int MaxWaitTime = 20000;38 30 39 31 /** … … 47 39 : mIsValid (false), mIsRegistered (false) 48 40 , mData (aData) 49 , mTriesLeft (3 /* the initial tries value !*/)41 , mTriesLeft (3 /* the initial tries value */) 50 42 { 51 43 decode (aData); … … 53 45 54 46 VBoxRegistrationData (const QString &aName, const QString &aEmail, 55 const QString &a Private)47 const QString &aIsPrivate) 56 48 : mIsValid (true), mIsRegistered (true) 57 , mName (aName), mEmail (aEmail), m Private (aPrivate)49 , mName (aName), mEmail (aEmail), mIsPrivate (aIsPrivate) 58 50 , mTriesLeft (0) 59 51 { 60 encode (aName, aEmail, a Private);52 encode (aName, aEmail, aIsPrivate); 61 53 } 62 54 63 bool isValid() const 64 bool isRegistered() const 65 66 const QString &data() const 67 const QString &name() const 68 const QString &email() const 69 const QString &isPrivate() const { return mPrivate; }70 71 uint triesLeft() const 55 bool isValid() const { return mIsValid; } 56 bool isRegistered() const { return mIsRegistered; } 57 58 const QString &data() const { return mData; } 59 const QString &name() const { return mName; } 60 const QString &email() const { return mEmail; } 61 const QString &isPrivate() const { return mIsPrivate; } 62 63 uint triesLeft() const { return mTriesLeft; } 72 64 73 65 private: … … 117 109 mName = dataList [0]; 118 110 mEmail = dataList [1]; 119 m Private = dataList [2];111 mIsPrivate = dataList [2]; 120 112 121 113 mIsValid = true; … … 189 181 QString mName; 190 182 QString mEmail; 191 QString m Private;183 QString mIsPrivate; 192 184 193 185 uint mTriesLeft; 194 186 }; 195 187 196 VBoxRegistrationDlg::VBoxRegistrationDlg (VBoxRegistrationDlg **aSelf, 197 QWidget *aParent, 198 Qt::WindowFlags aFlags) 199 : QIWithRetranslateUI2<QIAbstractWizard> (aParent, aFlags) 188 /* Static member to check if registration dialog necessary. */ 189 bool VBoxRegistrationDlg::hasToBeShown() 190 { 191 VBoxRegistrationData regData (vboxGlobal().virtualBox(). 192 GetExtraData (VBoxDefs::GUI_RegistrationData)); 193 194 return (!regData.isValid()) || 195 (!regData.isRegistered() && regData.triesLeft() > 0); 196 } 197 198 VBoxRegistrationDlg::VBoxRegistrationDlg (VBoxRegistrationDlg **aSelf, QWidget *aParent) 199 : QIWithRetranslateUI <QIAbstractWizard> (aParent) 200 200 , mSelf (aSelf) 201 201 , mWvalReg (0) 202 202 , mUrl ("http://registration.virtualbox.org/register762.php") 203 , mKey (QString::null) 204 , mTimeout (new QTimer (this)) 205 , mHandshake (true) 206 , mSuicide (false) 207 , mNetfw (0) 208 { 209 /* Store external pointer to this dialog. */ 203 , mHttp (new QIHttp (this, mUrl.host())) 204 { 205 /* Store external pointer to this dialog */ 210 206 *mSelf = this; 211 207 212 208 /* Apply UI decorations */ 213 209 Ui::VBoxRegistrationDlg::setupUi (this); 210 211 /* Apply window icons */ 212 setWindowIcon (vboxGlobal().iconSetFull (QSize (32, 32), QSize (16, 16), 213 ":/register_32px.png", ":/register_16px.png")); 214 214 215 215 /* Initialize wizard hdr */ … … 219 219 QRegExp nameExp ("[\\S\\s]+"); 220 220 /* E-mail address is validated according to RFC2821, RFC2822, 221 * see http://en.wikipedia.org/wiki/E-mail_address .*/221 * see http://en.wikipedia.org/wiki/E-mail_address */ 222 222 QRegExp emailExp ("(([a-zA-Z0-9_\\-\\.!#$%\\*/?|^{}`~&'\\+=]*" 223 223 "[a-zA-Z0-9_\\-!#$%\\*/?|^{}`~&'\\+=])|" … … 234 234 mLeEmail->setMaxLength (50); 235 235 236 /* This is a single shot timer */237 mTimeout->setSingleShot (true);238 239 236 /* Setup other connections */ 240 237 mWvalReg = new QIWidgetValidator (mPageReg, this); … … 243 240 connect (mWvalReg, SIGNAL (isValidRequested (QIWidgetValidator *)), 244 241 this, SLOT (revalidate (QIWidgetValidator *))); 245 connect (mTimeout, SIGNAL (timeout()), this, SLOT (processTimeout()));246 242 247 243 /* Setup initial dialog parameters. */ … … 264 260 VBoxRegistrationDlg::~VBoxRegistrationDlg() 265 261 { 266 /* Delete network framework. */267 delete mNetfw;268 269 262 /* Erase dialog handle in config file. */ 270 263 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationDlgWinID, … … 273 266 /* Erase external pointer to this dialog. */ 274 267 *mSelf = 0; 275 }276 277 /* Static member to check if registration dialog necessary. */278 bool VBoxRegistrationDlg::hasToBeShown()279 {280 VBoxRegistrationData regData (vboxGlobal().virtualBox().281 GetExtraData (VBoxDefs::GUI_RegistrationData));282 283 return !regData.isValid() ||284 (!regData.isRegistered() && regData.triesLeft() > 0);285 268 } 286 269 … … 302 285 303 286 /* Perform connection handshake */ 304 QTimer::singleShot (0, this, SLOT (handshake ()));287 QTimer::singleShot (0, this, SLOT (handshakeStart())); 305 288 } 306 289 … … 325 308 } 326 309 327 void VBoxRegistrationDlg::handshake ()328 { 329 /* Handshake arguments initializing*/330 Q String version = vboxGlobal().virtualBox().GetVersion();331 version = QUrl::toPercentEncoding (version);310 void VBoxRegistrationDlg::handshakeStart() 311 { 312 /* Compose query */ 313 QUrl url (mUrl); 314 url.addQueryItem ("version", vboxGlobal().virtualBox().GetVersion()); 332 315 333 316 /* Handshake */ 334 QString body = QString ("version=%1").arg (version); 335 postRequest (mUrl.host(), mUrl.path(), body); 336 } 337 338 void VBoxRegistrationDlg::registration() 339 { 340 /* Registration arguments initializing */ 341 mHandshake = false; 342 QString version = vboxGlobal().virtualBox().GetVersion(); 343 QString platform = vboxGlobal().platformInfo(); 344 QString name = mLeName->text(); 345 QString email = mLeEmail->text(); 346 QString prvt = mCbUse->isChecked() ? "1" : "0"; 347 version = QUrl::toPercentEncoding (version); 348 platform = QUrl::toPercentEncoding (platform); 349 name = QUrl::toPercentEncoding (name); 350 email = QUrl::toPercentEncoding (email); 317 mHttp->disconnect (this); 318 connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (handshakeResponse (bool))); 319 mHttp->post (url.toEncoded()); 320 } 321 322 void VBoxRegistrationDlg::handshakeResponse (bool aError) 323 { 324 /* Block all the other incoming signals */ 325 mHttp->disconnect (this); 326 327 /* Process error if present */ 328 if (aError) 329 return abortRequest (mHttp->errorString()); 330 331 /* Read received data */ 332 mKey = mHttp->readAll(); 333 334 /* Verifying key correctness */ 335 if (QString (mKey).indexOf (QRegExp ("^[a-zA-Z0-9]{32}$"))) 336 return abortRequest (tr ("Could not perform connection handshake.")); 337 338 /* Perform registration */ 339 QTimer::singleShot (0, this, SLOT (registrationStart())); 340 } 341 342 void VBoxRegistrationDlg::registrationStart() 343 { 344 /* Compose query */ 345 QUrl url (mUrl); 346 url.addQueryItem ("version", vboxGlobal().virtualBox().GetVersion()); 347 url.addQueryItem ("key", mKey); 348 url.addQueryItem ("platform", vboxGlobal().platformInfo()); 349 url.addQueryItem ("name", mLeName->text()); 350 url.addQueryItem ("email", mLeEmail->text()); 351 url.addQueryItem ("private", mCbUse->isChecked() ? "1" : "0"); 351 352 352 353 /* Registration */ 353 QString body; 354 body += QString ("version=%1").arg (version); 355 body += QString ("&key=%1").arg (mKey); 356 body += QString ("&platform=%1").arg (platform); 357 body += QString ("&name=%1").arg (name); 358 body += QString ("&email=%1").arg (email); 359 body += QString ("&private=%1").arg (prvt); 360 361 postRequest (mUrl.host(), mUrl.path(), body); 362 } 363 364 void VBoxRegistrationDlg::processTimeout() 365 { 366 abortRegisterRequest (tr ("Connection timed out.")); 367 } 368 369 /* Handles the network request begining. */ 370 void VBoxRegistrationDlg::onNetBegin (int aStatus) 371 { 372 if (mSuicide) return; 373 374 if (aStatus == 404) 375 abortRegisterRequest (tr ("Could not locate the registration form on " 376 "the server (response: %1).").arg (aStatus)); 377 else 378 mTimeout->start (MaxWaitTime); 379 } 380 381 /* Handles the network request data incoming. */ 382 void VBoxRegistrationDlg::onNetData (const QByteArray&) 383 { 384 if (mSuicide) return; 385 386 mTimeout->start (MaxWaitTime); 387 } 388 389 /* Handles the network request end. */ 390 void VBoxRegistrationDlg::onNetEnd (const QByteArray &aTotalData) 391 { 392 if (mSuicide) return; 393 394 mTimeout->stop(); 395 if (mHandshake) 396 { 397 /* Verifying key correctness */ 398 if (QString (aTotalData).indexOf (QRegExp ("^[a-zA-Z0-9]{32}$"))) 399 { 400 abortRegisterRequest (tr ("Could not perform connection handshake.")); 401 return; 402 } 403 mKey = aTotalData; 404 405 /* Perform registration */ 406 QTimer::singleShot (0, this, SLOT (registration())); 407 } 408 else 409 { 410 /* Show registration result */ 411 QString result (aTotalData); 412 vboxProblem().showRegisterResult (this, result); 413 414 /* Close the dialog */ 415 result == "OK" ? finish() : reject(); 416 } 417 } 418 419 /* Handles the network error. */ 420 void VBoxRegistrationDlg::onNetError (const QString &aError) 421 { 422 abortRegisterRequest (aError); 354 mHttp->disconnect (this); 355 connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (registrationResponse (bool))); 356 mHttp->post (url.toEncoded()); 357 } 358 359 void VBoxRegistrationDlg::registrationResponse (bool aError) 360 { 361 /* Block all the other incoming signals */ 362 mHttp->disconnect (this); 363 364 /* Process error if present */ 365 if (aError) 366 return abortRequest (mHttp->errorString()); 367 368 /* Read received data */ 369 QString data (mHttp->readAll()); 370 371 /* Show registration result */ 372 vboxProblem().showRegisterResult (this, data); 373 374 /* Close the dialog */ 375 data == "OK" ? finish() : reject(); 423 376 } 424 377 … … 441 394 } 442 395 443 void VBoxRegistrationDlg::postRequest (const QString &aHost, 444 const QString &aUrl, 445 const QString &aBody) 446 { 447 delete mNetfw; 448 mNetfw = new VBoxNetworkFramework(); 449 connect (mNetfw, SIGNAL (netBegin (int)), 450 SLOT (onNetBegin (int))); 451 connect (mNetfw, SIGNAL (netData (const QByteArray&)), 452 SLOT (onNetData (const QByteArray&))); 453 connect (mNetfw, SIGNAL (netEnd (const QByteArray&)), 454 SLOT (onNetEnd (const QByteArray&))); 455 connect (mNetfw, SIGNAL (netError (const QString&)), 456 SLOT (onNetError (const QString&))); 457 mTimeout->start (MaxWaitTime); 458 mNetfw->postRequest (aHost, aUrl, aBody); 459 } 460 461 /* This wrapper displays an error message box (unless aReason is 462 * QString::null) with the cause of the request-send procedure 463 * termination. After the message box is dismissed, the downloader signals 464 * to close itself on the next event loop iteration. */ 465 void VBoxRegistrationDlg::abortRegisterRequest (const QString &aReason) 466 { 467 /* Protect against double kill request. */ 468 if (mSuicide) return; 469 mSuicide = true; 470 396 /* This wrapper displays an error message box (unless aReason is QString::null) 397 * with the cause of the request-send procedure termination. After the message 398 * box dismissed, the registration dialog signals to close itself on the next 399 * event loop iteration. */ 400 void VBoxRegistrationDlg::abortRequest (const QString &aReason) 401 { 471 402 if (!aReason.isNull()) 472 403 vboxProblem().cannotConnectRegister (this, mUrl.toString(), aReason); … … 479 410 { 480 411 VBoxRegistrationData regData (mLeName->text(), mLeEmail->text(), 481 mCbUse->isChecked() ? "yes" : "no");412 mCbUse->isChecked() ? "yes" : "no"); 482 413 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_RegistrationData, 483 414 regData.data()); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxUpdateDlg.cpp
r12286 r14274 22 22 23 23 /* Common includes */ 24 #include " VBoxUpdateDlg.h"24 #include "QIHttp.h" 25 25 #include "VBoxGlobal.h" 26 26 #include "VBoxProblemReporter.h" 27 #include "VBox NetworkFramework.h"27 #include "VBoxUpdateDlg.h" 28 28 29 29 /* Qt includes */ 30 30 #include <QTimer> 31 32 /* Time to auto-disconnect if no network answer received. */33 static const int MaxWaitTime = 20000;34 35 31 36 32 /* VBoxVersion stuff */ … … 53 49 bool operator< (const VBoxVersion &aOther) const 54 50 { 55 return x < aOther.x||51 return (x < aOther.x) || 56 52 (x == aOther.x && y < aOther.y) || 57 53 (x == aOther.x && y == aOther.y && z < aOther.z); … … 72 68 73 69 /* VBoxUpdateData stuff */ 74 QList <UpdateDay> VBoxUpdateData::mDayList = QList<UpdateDay>();70 QList <UpdateDay> VBoxUpdateData::mDayList = QList <UpdateDay>(); 75 71 76 72 void VBoxUpdateData::populate() … … 121 117 bool VBoxUpdateData::isNecessary() 122 118 { 123 return mIndex != NeverCheck && 124 QDate::currentDate() >= mDate; 119 return mIndex != NeverCheck && QDate::currentDate() >= mDate; 125 120 } 126 121 … … 215 210 } 216 211 217 VBoxUpdateDlg::VBoxUpdateDlg (VBoxUpdateDlg **aSelf, bool aForceRun, 218 QWidget *aParent, Qt::WindowFlags aFlags) 219 : QIWithRetranslateUI2<QIAbstractWizard> (aParent, aFlags) 212 VBoxUpdateDlg::VBoxUpdateDlg (VBoxUpdateDlg **aSelf, bool aForceRun, QWidget *aParent) 213 : QIWithRetranslateUI <QIAbstractWizard> (aParent) 220 214 , mSelf (aSelf) 221 , mNetfw (0)222 , mTimeout (new QTimer (this))223 215 , mUrl ("http://update.virtualbox.org/query.php") 216 , mHttp (new QIHttp (this, mUrl.host())) 224 217 , mForceRun (aForceRun) 225 , mSuicide (false)226 218 { 227 219 /* Store external pointer to this dialog. */ … … 231 223 Ui::VBoxUpdateDlg::setupUi (this); 232 224 225 /* Apply window icons */ 226 setWindowIcon (vboxGlobal().iconSetFull (QSize (32, 32), QSize (16, 16), 227 ":/refresh_32px.png", ":/refresh_16px.png")); 228 233 229 /* Initialize wizard hdr */ 234 230 initializeWizardHdr(); 235 231 236 /* Network outage - single shot timer */237 mTimeout->setSingleShot (true);238 239 232 /* Setup other connections */ 240 connect (mTimeout, SIGNAL (timeout()), this, SLOT (processTimeout()));241 233 connect (mBtnCheck, SIGNAL (clicked()), this, SLOT (search())); 242 234 … … 245 237 246 238 /* Setup initial condition */ 247 mPbCheck->setMinimumWidth (mLogoUpdate->width() + 248 mLogoUpdate->frameWidth() * 2); 239 mPbCheck->setMinimumWidth (mLogoUpdate->width() + mLogoUpdate->frameWidth() * 2); 249 240 mPbCheck->hide(); 250 251 241 mTextSuccessInfo->hide(); 252 242 mTextFailureInfo->hide(); … … 259 249 VBoxUpdateDlg::~VBoxUpdateDlg() 260 250 { 261 /* Delete network framework. */262 delete mNetfw;263 264 251 /* Erase dialog handle in config file. */ 265 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateDlgWinID, 266 QString::null); 252 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateDlgWinID, QString::null); 267 253 268 254 /* Erase external pointer to this dialog. */ … … 270 256 } 271 257 258 void VBoxUpdateDlg::retranslateUi() 259 { 260 /* Translate uic generated strings */ 261 Ui::VBoxUpdateDlg::retranslateUi (this); 262 263 #if 0 /* All the text constants */ 264 setWindowTitle (tr ("VirtualBox Update Wizard")); 265 266 mPageUpdateHdr->setText (tr ("Check for Updates")); 267 mBtnCheck->setText (tr ("Chec&k")); 268 mBtnCancel->setText (tr ("Cancel")); 269 270 mPageFinishHdr->setText (tr ("Summary")); 271 mBtnFinish->setText (tr ("&Close")); 272 273 mTextUpdateInfo->setText (tr ("<p>This wizard will connect to the VirtualBox " 274 "web-site and check if a newer version of " 275 "VirtualBox is available.</p><p>Use the " 276 "<b>Check</b> button to check for a new version " 277 "now or the <b>Cancel</b> button if you do not " 278 "want to perform this check.</p><p>You can run " 279 "this wizard at any time by choosing <b>Check " 280 "for Updates...</b> from the <b>Help</b> menu.</p>")); 281 282 mTextSuccessInfo->setText (tr ("<p>A new version of VirtualBox has been released! " 283 "Version <b>%1</b> is available at " 284 "<a href=\"http://www.virtualbox.org/\">virtualbox.org</a>.</p>" 285 "<p>You can download this version from this direct link:</p>" 286 "<p><a href=%2>%3</a></p>")); 287 288 mTextFailureInfo->setText (tr ("<p>Unable to obtain the new version information " 289 "due to the following network error:</p><p><b>%1</b></p>")); 290 291 mTextNotFoundInfo->setText (tr ("You have already installed the latest VirtualBox " 292 "version. Please repeat the version check later.")); 293 #endif 294 } 295 272 296 void VBoxUpdateDlg::accept() 273 297 { 274 298 /* Recalculate new update data */ 275 299 VBoxUpdateData oldData (vboxGlobal().virtualBox(). 276 GetExtraData (VBoxDefs::GUI_UpdateDate));300 GetExtraData (VBoxDefs::GUI_UpdateDate)); 277 301 VBoxUpdateData newData (oldData.index()); 278 302 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateDate, … … 284 308 void VBoxUpdateDlg::search() 285 309 { 286 /* Create & setup network framework */ 287 mNetfw = new VBoxNetworkFramework(); 288 connect (mNetfw, SIGNAL (netBegin (int)), 289 SLOT (onNetBegin (int))); 290 connect (mNetfw, SIGNAL (netData (const QByteArray&)), 291 SLOT (onNetData (const QByteArray&))); 292 connect (mNetfw, SIGNAL (netEnd (const QByteArray&)), 293 SLOT (onNetEnd (const QByteArray&))); 294 connect (mNetfw, SIGNAL (netError (const QString&)), 295 SLOT (onNetError (const QString&))); 296 310 /* Calculate the count of checks left */ 311 int count = 1; 312 QString sc = vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_UpdateCheckCount); 313 if (!sc.isEmpty()) 314 { 315 bool ok = false; 316 int c = sc.toLongLong (&ok); 317 if (ok) count = c; 318 } 319 320 /* Compose query */ 321 QUrl url (mUrl); 322 url.addQueryItem ("platform", vboxGlobal().virtualBox().GetPackageType()); 323 url.addQueryItem ("version", QString ("%1_%2").arg (vboxGlobal().virtualBox().GetVersion()) 324 .arg (vboxGlobal().virtualBox().GetRevision())); 325 url.addQueryItem ("count", QString::number (count)); 326 327 QString userAgent (QString ("VirtualBox %1 <%2>") 328 .arg (vboxGlobal().virtualBox().GetVersion()) 329 .arg (vboxGlobal().platformInfo())); 330 331 /* Show progress bar */ 332 mPbCheck->show(); 333 334 /* Send composed information */ 335 QHttpRequestHeader header ("POST", url.toEncoded()); 336 header.setValue ("Host", url.host()); 337 header.setValue ("User-Agent", userAgent); 338 mHttp->disconnect (this); 339 connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (searchResponse (bool))); 340 mHttp->request (header); 341 } 342 343 void VBoxUpdateDlg::searchResponse (bool aError) 344 { 345 /* Block all the other incoming signals */ 346 mHttp->disconnect (this); 347 348 /* Process error if present */ 349 if (aError) 350 return abortRequest (mHttp->errorString()); 351 352 /* Hide progress bar */ 353 mPbCheck->hide(); 354 355 /* Parse incoming data */ 356 QString responseData (mHttp->readAll()); 357 358 if (responseData.indexOf (QRegExp ("^\\d+\\.\\d+\\.\\d+ \\S+$")) == 0) 359 { 360 /* Newer version of necessary package found */ 361 QStringList response = responseData.split (" ", QString::SkipEmptyParts); 362 363 if (isHidden()) 364 { 365 /* For background update */ 366 vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(), 367 response [0], response [1]); 368 QTimer::singleShot (0, this, SLOT (accept())); 369 } 370 else 371 { 372 /* For wizard update */ 373 mTextSuccessInfo->setText (mTextSuccessInfo->text() 374 .arg (response [0], response [1], response [1])); 375 mTextSuccessInfo->show(); 376 mPageStack->setCurrentIndex (1); 377 } 378 } 379 else /* if (responseData == "UPTODATE") */ 380 { 381 /* No newer version of necessary package found */ 382 if (isHidden()) 383 { 384 /* For background update */ 385 if (mForceRun) 386 vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow()); 387 QTimer::singleShot (0, this, SLOT (accept())); 388 } 389 else 390 { 391 /* For wizard update */ 392 mTextNotFoundInfo->show(); 393 mPageStack->setCurrentIndex (1); 394 } 395 } 396 397 /* Save left count of checks */ 297 398 int count = 1; 298 399 bool ok = false; 299 400 QString sc = vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_UpdateCheckCount); 300 401 if (!sc.isEmpty()) 301 { 302 int c = sc.toLongLong(&ok); 303 if (ok) 304 count = c; 305 } 306 QString package = vboxGlobal().virtualBox().GetPackageType(); 307 QString version = vboxGlobal().virtualBox().GetVersion(); 308 QString revision = QString::number (vboxGlobal().virtualBox().GetRevision()); 309 package = QUrl::toPercentEncoding (package); 310 version = QUrl::toPercentEncoding (version); 311 revision = QUrl::toPercentEncoding (revision); 312 QString body; 313 body += QString ("platform=%1").arg (package); 314 body += QString ("&version=%1_%2").arg (version).arg (revision); 315 body += QString ("&count=%1").arg (count); 316 317 QStringList header ("User-Agent"); 318 header << QString ("VirtualBox %1 <%2>") 319 .arg (vboxGlobal().virtualBox().GetVersion()) 320 .arg (vboxGlobal().platformInfo()); 321 322 /* Show progress bar & send composed information */ 323 mPbCheck->show(); 324 mTimeout->start (MaxWaitTime); 325 mNetfw->postRequest (mUrl.host(), mUrl.path(), body, header); 326 } 327 328 void VBoxUpdateDlg::retranslateUi() 329 { 330 /* Translate uic generated strings */ 331 Ui::VBoxUpdateDlg::retranslateUi (this); 332 } 333 334 void VBoxUpdateDlg::processTimeout() 335 { 336 networkAbort (tr ("Connection timed out.")); 337 } 338 339 /* Handles the network request begining. */ 340 void VBoxUpdateDlg::onNetBegin (int aStatus) 341 { 342 if (mSuicide) return; 343 344 if (aStatus == 404) 345 networkAbort (tr ("Could not locate the latest version " 346 "list on the server (response: %1).").arg (aStatus)); 347 else 348 mTimeout->start (MaxWaitTime); 349 } 350 351 /* Handles the network request data incoming. */ 352 void VBoxUpdateDlg::onNetData (const QByteArray&) 353 { 354 if (mSuicide) return; 355 356 mTimeout->start (MaxWaitTime); 357 } 358 359 /* Handles the network request end. */ 360 void VBoxUpdateDlg::onNetEnd (const QByteArray &aTotalData) 361 { 362 if (mSuicide) return; 363 364 mTimeout->stop(); 365 processResponse (aTotalData); 366 } 367 368 /* Handles the network error. */ 369 void VBoxUpdateDlg::onNetError (const QString &aError) 370 { 371 networkAbort (aError); 402 count = sc.toLongLong (&ok); 403 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateCheckCount, 404 QString ("%1").arg ((qulonglong) count + 1)); 372 405 } 373 406 … … 380 413 } 381 414 382 void VBoxUpdateDlg::networkAbort (const QString &aReason) 383 { 384 /* Protect against double kill request. */ 385 if (mSuicide) return; 386 mSuicide = true; 387 415 void VBoxUpdateDlg::abortRequest (const QString &aReason) 416 { 388 417 /* Hide progress bar */ 389 418 mPbCheck->hide(); … … 405 434 } 406 435 407 void VBoxUpdateDlg::processResponse (const QString &aResponse)408 {409 /* Hide progress bar */410 mPbCheck->hide();411 412 if (aResponse.indexOf (QRegExp ("^\\d+\\.\\d+\\.\\d+ \\S+$")) == 0)413 {414 /* Newer version of necessary package found */415 QStringList response = aResponse.split (" ", QString::SkipEmptyParts);416 417 if (isHidden())418 {419 /* For background update */420 vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(),421 response [0], response [1]);422 QTimer::singleShot (0, this, SLOT (accept()));423 }424 else425 {426 /* For wizard update */427 mTextSuccessInfo->setText (mTextSuccessInfo->text()428 .arg (response [0], response [1], response [1]));429 mTextSuccessInfo->show();430 mPageStack->setCurrentIndex (1);431 }432 }433 else /* if (aResponse == "UPTODATE") */434 {435 /* No newer version of necessary package found */436 if (isHidden())437 {438 /* For background update */439 if (mForceRun)440 vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow());441 QTimer::singleShot (0, this, SLOT (accept()));442 }443 else444 {445 /* For wizard update */446 mTextNotFoundInfo->show();447 mPageStack->setCurrentIndex (1);448 }449 }450 451 int count = 1;452 bool ok = false;453 QString sc = vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_UpdateCheckCount);454 if (!sc.isEmpty())455 count = sc.toLongLong(&ok);456 vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_UpdateCheckCount,457 QString ("%1").arg ((qulonglong) count + 1));458 }459 -
trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxRegistrationDlg.ui
r12030 r14274 30 30 <string>VirtualBox Registration Dialog</string> 31 31 </property> 32 <property name="windowIcon" >33 <iconset resource="../VirtualBox.qrc" >:/register_16px.png</iconset>34 </property>35 32 <layout class="QVBoxLayout" > 36 33 <property name="leftMargin" > -
trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxUpdateDlg.ui
r12030 r14274 27 27 </rect> 28 28 </property> 29 <property name="windowTitle" >30 <string>VirtualBox Update Wizard</string>31 </property>32 <property name="windowIcon" >33 <iconset resource="../VirtualBox.qrc" >:/refresh_16px.png</iconset>34 </property>35 29 <layout class="QVBoxLayout" > 36 30 <property name="leftMargin" > … … 63 57 </font> 64 58 </property> 65 <property name="text" >66 <string>Check for Updates</string>67 </property>68 59 </widget> 69 60 </item> … … 112 103 </size> 113 104 </property> 114 <property name="text" >115 <string><p>This wizard will connect to the VirtualBox web-site and check if a newer version of VirtualBox is available.</p>116 <p>Use the <b>Check</b> button to check for a new version now or the <b>Cancel</b> button if you do not want to perform this check.</p>117 <p>You can run this wizard at any time by choosing <b>Check for Updates...</b> from the <b>Help</b> menu.</p></string>118 </property>119 105 <property name="wordWrap" > 120 106 <bool>true</bool> … … 188 174 <item> 189 175 <widget class="QPushButton" name="mBtnCheck" > 190 <property name="text" >191 <string>Chec&k</string>192 </property>193 176 <property name="default" > 194 177 <bool>true</bool> … … 213 196 </item> 214 197 <item> 215 <widget class="QPushButton" name="mBtnCancel" > 216 <property name="text" > 217 <string>Cancel</string> 218 </property> 219 </widget> 198 <widget class="QPushButton" name="mBtnCancel" /> 220 199 </item> 221 200 </layout> … … 235 214 </font> 236 215 </property> 237 <property name="text" >238 <string>Summary</string>239 </property>240 216 </widget> 241 217 </item> … … 288 264 <height>0</height> 289 265 </size> 290 </property>291 <property name="text" >292 <string><p>A new version of VirtualBox has been released! Version <b>%1</b> is available at <a href="http://www.virtualbox.org/">virtualbox.org</a>.</p><p>You can download this version from this direct link:</p><p><a href=%2>%3</a></p></string>293 266 </property> 294 267 <property name="wordWrap" > … … 311 284 </size> 312 285 </property> 313 <property name="text" >314 <string><p>Unable to obtain the new version information due to the following network error:</p><p><b>%1</b></p></string>315 </property>316 286 <property name="wordWrap" > 317 287 <bool>true</bool> … … 333 303 </size> 334 304 </property> 335 <property name="text" >336 <string>You have already installed the latest VirtualBox version. Please repeat the version check later.</string>337 </property>338 305 <property name="wordWrap" > 339 306 <bool>true</bool> … … 387 354 <item> 388 355 <widget class="QPushButton" name="mBtnFinish" > 389 <property name="text" >390 <string>&Close</string>391 </property>392 356 <property name="default" > 393 357 <bool>true</bool>
Note:
See TracChangeset
for help on using the changeset viewer.