Ticket #341: busy.patch

File busy.patch, 7.2 KB (added by eskil <myth@…>, 19 years ago)
  • mythtv/libs/libmyth/mythdialogs.cpp

    Patch mythdialogs to add a busy-spinner style progress bar. Also
    changed mythmusic to use this spinner while searching for music, since
    ie. scanning big nfs mounted directories can take >10 secs.
    
    This patch requires the lcd-busy-520 patch.
    
    1) add a MythBusyDialog, inherited from MythProgressDialog, which
    essentially just displays the QProgressBar as a busy-spinner instead
    of a normal progress bar. It sets up a timer, so the used just has to
    periodically call qApp->processEvents to make the spinner spin. It
    also updates the LCD.
    
    2) Change mythmusic, so searching for music files displays a busy
    spinner.
    
     
    15201520    progress->setBackgroundOrigin(ParentOrigin);
    15211521    progress->setProgress(0);
    15221522
    1523     m_totalSteps = totalSteps;
    1524     steps = totalSteps / 1000;
    1525     if (steps == 0)
    1526         steps = 1;
     1523    setTotalSteps (totalSteps);
    15271524
    15281525    if (class LCD * lcddev = LCD::Get())
    15291526    {
     
    15881585        MythDialog::keyPressEvent(e);
    15891586}
    15901587
     1588void MythProgressDialog::setTotalSteps (int totalSteps) {
     1589    m_totalSteps = totalSteps;
     1590    steps = totalSteps / 1000;
     1591    if (steps == 0)
     1592        steps = 1;
     1593}
     1594
     1595MythBusyDialog::MythBusyDialog (const QString &title) :
     1596    MythProgressDialog (title, 0),
     1597    timer (NULL)
     1598{
     1599}
     1600
     1601MythBusyDialog::~MythBusyDialog () {
     1602    if (timer)
     1603        delete timer;
     1604}
     1605
     1606void
     1607MythBusyDialog::start (int interval) {
     1608    if (timer == NULL) {
     1609        timer = new QTimer (this);
     1610    }
     1611    connect (timer, SIGNAL (timeout ()), SLOT (timeout ()));
     1612    timer->start (interval);
     1613}
     1614
     1615void
     1616MythBusyDialog::Close () {
     1617    if (timer) {
     1618        disconnect (timer, SIGNAL (timeout ()), this, SLOT (timeout ()));
     1619        delete timer;
     1620        timer = 0;
     1621    }
     1622
     1623    MythProgressDialog::Close ();
     1624}
     1625
     1626void
     1627MythBusyDialog::setProgress ()  {
     1628    progress->setProgress (progress->progress () + 10);
     1629    qApp->processEvents ();
     1630    if (LCD *lcddev = LCD::Get())
     1631        lcddev->setGenericBusy ();
     1632}
     1633
     1634void
     1635MythBusyDialog::timeout ()  {
     1636    setProgress ();
     1637}
     1638
    15911639MythThemedDialog::MythThemedDialog(MythMainWindow *parent, QString window_name,
    15921640                                   QString theme_filename, const char* name,
    15931641                                   bool setsize)
  • mythtv/libs/libmyth/mythdialogs.h

     
    1111#include <qevent.h>
    1212#include <qvaluevector.h>
    1313#include <qscrollview.h>
     14#include <qthread.h>
    1415
    1516#include <vector>
    1617using namespace std;
     
    229230    bool arrowAccel;
    230231};
    231232
     233/** The MythTV progress bar dialog.
     234
     235    This dialog is responsible for displaying a progress bar box on
     236    the screen. This is used when you have a known set of steps to
     237    perform and the possibility of calling the \p setProgress call at
     238    the end of each step.
     239
     240        If you do not know the number of steps, use \p MythBusyDialog
     241        instead.
     242
     243    The dialog widget also updates the LCD display if present.
     244
     245*/
    232246class MythProgressDialog: public MythDialog
    233247{
    234248  public:
     249    /** Create a progress bar dialog.
     250       
     251        \param message the title string to appear in the progress dialog.
     252        \param totalSteps the total number of steps
     253     */
    235254    MythProgressDialog(const QString& message, int totalSteps);
    236255
     256        /* \brief Close the dialog.
     257           This will close the dialog and return the LCD to the Time screen
     258        */
    237259    void Close(void);
     260        /* \brief Update thr progress bar. 
     261
     262            This will move the progress bar the percentage-completed as
     263            determined by \p curprogress and the totalsteps as set by the
     264            call to the constructor.
     265
     266                The LCD is updated as well.
     267         */
    238268    void setProgress(int curprogress);
     269
    239270    void keyPressEvent(QKeyEvent *);
    240271
     272  protected:
     273    QProgressBar *progress;
     274
    241275  private:
    242     QProgressBar *progress;
     276        void setTotalSteps (int totalSteps);   
    243277    int steps;
    244 
     278    int m_totalSteps;
    245279    QPtrList<class LCDTextItem> * textItems;
     280};
    246281
    247     int m_totalSteps;
     282/** MythDialog box that displays a busy spinner-style dialog box to
     283    indicate the program is busy, but that the number of steps needed
     284    is unknown.
     285
     286    Ie. used by MythMusic when scanning the filesystem for musicfiles.
     287 */
     288class MythBusyDialog : public MythProgressDialog {
     289    Q_OBJECT
     290  public:
     291    /** \brief Create the busy indicator. 
     292
     293        Creates the dialog widget and sets up the timer that causes
     294        the widget to indicate progress every 100msec;
     295
     296        \param title the title to appear in the progress bar dialog
     297    */
     298    MythBusyDialog (const QString &title);
     299
     300    ~MythBusyDialog ();
     301
     302    /** \brief Setup a timer to 'move' the spinner
     303
     304        This will create a \p QTimer object that will update the
     305        spinner ever \p interval msecs.
     306
     307        \param interval msecs between movement, default is 100
     308    */
     309    void start (int interval = 100);
     310
     311    /** \brief Close the dialog.
     312        This will close the dialog and stop the timer.         
     313    */
     314    void Close ();
     315
     316  protected slots:
     317    void setProgress();
     318    void timeout ();
     319
     320  private:
     321    QTimer *timer;
    248322};
    249323
    250324class MythThemedDialog : public MythDialog
  • mythplugins/mythmusic/mythmusic/main.cpp

     
    102102    QFileInfoListIterator it(*list);
    103103    QFileInfo *fi;
    104104
     105    /* Recursively traverse directory, calling
     106       QApplication::processEvents every now and then to ensure the UI
     107       updates */
     108    int update_interval = 0;
    105109    while ((fi = it.current()) != 0)
    106110    {
    107111        ++it;
    108112        if (fi->fileName() == "." || fi->fileName() == "..")
    109113            continue;
    110114        QString filename = fi->absFilePath();
    111         if (fi->isDir())
     115        if (fi->isDir()) {
    112116            BuildFileList(filename, music_files);
    113         else
     117            qApp->processEvents ();
     118        } else {
     119            if (++update_interval > 100) {
     120                qApp->processEvents ();
     121                update_interval = 0;
     122            }
    114123            music_files[filename] = kFileSystem;
     124        }
    115125    }
    116126}
    117127
     
    177187    MusicLoadedMap music_files;
    178188    MusicLoadedMap::Iterator iter;
    179189
     190    MythBusyDialog *busy = new MythBusyDialog (QObject::tr("Searching for music files"));
     191    busy->start ();
    180192    BuildFileList(directory, music_files);
     193    busy->Close ();
     194    delete busy;
    181195
    182196    MSqlQuery query(MSqlQuery::InitCon());
    183197    query.exec("SELECT filename FROM musicmetadata "
     
    186200    int counter = 0;
    187201
    188202    MythProgressDialog *file_checking;
    189     file_checking = new MythProgressDialog(QObject::tr("Searching for music files"),
     203    file_checking = new MythProgressDialog(QObject::tr("Scanning music files"),
    190204                                           query.numRowsAffected());
    191205
    192206    if (query.isActive() && query.size() > 0)