Changeset 10855 in vbox
- Timestamp:
- Jul 24, 2008 2:33:58 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33669
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxProblemReporter.cpp
r10772 r10855 73 73 Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint) 74 74 , mProgress (aProgress) 75 , mCalcelEnabled (true) 75 , mEventLoop (new QEventLoop (this)) 76 , mCalcelEnabled (false) 76 77 , mOpCount (mProgress.GetOperationCount()) 77 78 , mCurOp (mProgress.GetOperation() + 1) 78 , mLoopLevel (-1)79 79 , mEnded (false) 80 80 { … … 92 92 .arg (aTitle, mProgress.GetDescription())); 93 93 setMinimumDuration (aMinDuration); 94 setCancelEnabled (false);95 94 setValue (0); 96 95 } 97 96 98 int run (int aRefreshInterval); 99 100 bool cancelEnabled() const { return mCalcelEnabled; } 101 void setCancelEnabled (bool aEnabled) { mCalcelEnabled = aEnabled; } 97 int run (int aRefreshInterval) 98 { 99 if (mProgress.isOk()) 100 { 101 /* Start refresh timer */ 102 int id = startTimer (aRefreshInterval); 103 104 /* Show the progress dialog */ 105 show(); 106 107 /* Enter the modal loop */ 108 mEventLoop->exec(); 109 110 /* Kill refresh timer */ 111 killTimer (id); 112 113 return result(); 114 } 115 return Rejected; 116 } 117 118 /* These methods disabled for now as not used anywhere */ 119 // bool cancelEnabled() const { return mCalcelEnabled; } 120 // void setCancelEnabled (bool aEnabled) { mCalcelEnabled = aEnabled; } 102 121 103 122 protected: 104 123 105 virtual void timerEvent (QTimerEvent *e); 106 107 virtual void reject() { if (mCalcelEnabled) QProgressDialog::reject(); }; 108 109 virtual void closeEvent (QCloseEvent *e) 124 virtual void timerEvent (QTimerEvent * /* aEvent */) 125 { 126 if (!mEnded && (!mProgress.isOk() || mProgress.GetCompleted())) 127 { 128 /* Progress finished */ 129 if (mProgress.isOk()) 130 { 131 setValue (100); 132 setResult (Accepted); 133 } 134 /* Progress is not valid */ 135 else 136 setResult (Rejected); 137 138 /* Request to exit loop */ 139 mEnded = true; 140 141 /* The progress will be finalized 142 * on next timer iteration. */ 143 return; 144 } 145 146 if (mEnded) 147 { 148 /* Exit loop if it is running */ 149 if (mEventLoop->isRunning()) 150 mEventLoop->quit(); 151 return; 152 } 153 154 /* Update the progress dialog */ 155 ulong newOp = mProgress.GetOperation() + 1; 156 if (newOp != mCurOp) 157 { 158 mCurOp = newOp; 159 setLabelText (QString (sOpDescTpl) 160 .arg (mProgress.GetOperationDescription()) 161 .arg (mCurOp).arg (mOpCount)); 162 } 163 setValue (mProgress.GetPercent()); 164 } 165 166 virtual void reject() { if (mCalcelEnabled) QProgressDialog::reject(); } 167 168 virtual void closeEvent (QCloseEvent *aEvent) 110 169 { 111 170 if (mCalcelEnabled) 112 QProgressDialog::closeEvent ( e);171 QProgressDialog::closeEvent (aEvent); 113 172 else 114 e->ignore();173 aEvent->ignore(); 115 174 } 116 175 … … 118 177 119 178 CProgress &mProgress; 179 QEventLoop *mEventLoop; 120 180 bool mCalcelEnabled; 121 181 const ulong mOpCount; 122 182 ulong mCurOp; 123 int mLoopLevel;124 183 bool mEnded; 125 184 … … 127 186 }; 128 187 129 //static130 188 const char *VBoxProgressDialog::sOpDescTpl = "%1... (%2/%3)"; 131 132 int VBoxProgressDialog::run (int aRefreshInterval)133 {134 if (mProgress.isOk())135 {136 //#warning port me137 /* start a refresh timer */138 startTimer (aRefreshInterval);139 // todo: Ok here I have no clue what this mean.140 // I never saw someone calling the eventloop directly.141 // Very inconventient. I will investigate this later.142 // For now it seems to working correctly.143 // mLoopLevel = qApp->eventLoop()->loopLevel();144 // /* enter the modal loop */145 // qApp->eventLoop()->enterLoop();146 // killTimers();147 // mLoopLevel = -1;148 // mEnded = false;149 return exec();150 }151 return Rejected;152 }153 154 //virtual155 void VBoxProgressDialog::timerEvent (QTimerEvent *e)156 {157 bool justEnded = false;158 159 if (!mEnded && (!mProgress.isOk() || mProgress.GetCompleted()))160 {161 /* dismiss the dialog -- the progress is no more valid */162 killTimer (e->timerId());163 if (mProgress.isOk())164 {165 setValue (100);166 accepted();167 // setResult (Accepted);168 }169 else170 rejected();171 // setResult (Rejected);172 //173 // mEnded = justEnded = true;174 return;175 }176 177 if (mEnded)178 {179 if (mLoopLevel != -1)180 {181 //#warning port me182 // /* we've entered the loop in run() */183 // if (mLoopLevel + 1 == qApp->eventLoop()->loopLevel())184 // {185 // /* it's our loop, exit it */186 // qApp->eventLoop()->exitLoop();187 // }188 // else189 // {190 // Assert (mLoopLevel + 1 < qApp->eventLoop()->loopLevel());191 // /* restart the timer to watch for the loop level to drop */192 // if (justEnded)193 // startTimer (50);194 // }195 }196 else197 Assert (justEnded);198 return;199 }200 201 /* update the progress dialog */202 ulong newOp = mProgress.GetOperation() + 1;203 if (newOp != mCurOp)204 {205 mCurOp = newOp;206 setLabelText (QString (sOpDescTpl)207 .arg (mProgress.GetOperationDescription())208 .arg (mCurOp).arg (mOpCount));209 }210 setValue (mProgress.GetPercent());211 }212 189 213 190
Note:
See TracChangeset
for help on using the changeset viewer.