VirtualBox

Changeset 10855 in vbox


Ignore:
Timestamp:
Jul 24, 2008 2:33:58 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33669
Message:

Fe/Qt4: Porting of VBoxProgressDialog to qt4.
This have to fix issues related to any actions which directly or indirectly uses progress dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxProblemReporter.cpp

    r10772 r10855  
    7373                           Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint)
    7474        , mProgress (aProgress)
    75         , mCalcelEnabled (true)
     75        , mEventLoop (new QEventLoop (this))
     76        , mCalcelEnabled (false)
    7677        , mOpCount (mProgress.GetOperationCount())
    7778        , mCurOp (mProgress.GetOperation() + 1)
    78         , mLoopLevel (-1)
    7979        , mEnded (false)
    8080    {
     
    9292                    .arg (aTitle, mProgress.GetDescription()));
    9393        setMinimumDuration (aMinDuration);
    94         setCancelEnabled (false);
    9594        setValue (0);
    9695    }
    9796
    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; }
    102121
    103122protected:
    104123
    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)
    110169    {
    111170        if (mCalcelEnabled)
    112             QProgressDialog::closeEvent (e);
     171            QProgressDialog::closeEvent (aEvent);
    113172        else
    114             e->ignore();
     173            aEvent->ignore();
    115174    }
    116175
     
    118177
    119178    CProgress &mProgress;
     179    QEventLoop *mEventLoop;
    120180    bool mCalcelEnabled;
    121181    const ulong mOpCount;
    122182    ulong mCurOp;
    123     int mLoopLevel;
    124183    bool mEnded;
    125184
     
    127186};
    128187
    129 //static
    130188const char *VBoxProgressDialog::sOpDescTpl = "%1... (%2/%3)";
    131 
    132 int VBoxProgressDialog::run (int aRefreshInterval)
    133 {
    134     if (mProgress.isOk())
    135     {
    136 //#warning port me
    137         /* 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 //virtual
    155 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         else
    170             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 me
    182 //            /* 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 //            else
    189 //            {
    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         else
    197             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 }
    212189
    213190
Note: See TracChangeset for help on using the changeset viewer.

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