Ticket #341: busy.patch
File busy.patch, 7.2 KB (added by , 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.
1520 1520 progress->setBackgroundOrigin(ParentOrigin); 1521 1521 progress->setProgress(0); 1522 1522 1523 m_totalSteps = totalSteps; 1524 steps = totalSteps / 1000; 1525 if (steps == 0) 1526 steps = 1; 1523 setTotalSteps (totalSteps); 1527 1524 1528 1525 if (class LCD * lcddev = LCD::Get()) 1529 1526 { … … 1588 1585 MythDialog::keyPressEvent(e); 1589 1586 } 1590 1587 1588 void MythProgressDialog::setTotalSteps (int totalSteps) { 1589 m_totalSteps = totalSteps; 1590 steps = totalSteps / 1000; 1591 if (steps == 0) 1592 steps = 1; 1593 } 1594 1595 MythBusyDialog::MythBusyDialog (const QString &title) : 1596 MythProgressDialog (title, 0), 1597 timer (NULL) 1598 { 1599 } 1600 1601 MythBusyDialog::~MythBusyDialog () { 1602 if (timer) 1603 delete timer; 1604 } 1605 1606 void 1607 MythBusyDialog::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 1615 void 1616 MythBusyDialog::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 1626 void 1627 MythBusyDialog::setProgress () { 1628 progress->setProgress (progress->progress () + 10); 1629 qApp->processEvents (); 1630 if (LCD *lcddev = LCD::Get()) 1631 lcddev->setGenericBusy (); 1632 } 1633 1634 void 1635 MythBusyDialog::timeout () { 1636 setProgress (); 1637 } 1638 1591 1639 MythThemedDialog::MythThemedDialog(MythMainWindow *parent, QString window_name, 1592 1640 QString theme_filename, const char* name, 1593 1641 bool setsize) -
mythtv/libs/libmyth/mythdialogs.h
11 11 #include <qevent.h> 12 12 #include <qvaluevector.h> 13 13 #include <qscrollview.h> 14 #include <qthread.h> 14 15 15 16 #include <vector> 16 17 using namespace std; … … 229 230 bool arrowAccel; 230 231 }; 231 232 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 */ 232 246 class MythProgressDialog: public MythDialog 233 247 { 234 248 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 */ 235 254 MythProgressDialog(const QString& message, int totalSteps); 236 255 256 /* \brief Close the dialog. 257 This will close the dialog and return the LCD to the Time screen 258 */ 237 259 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 */ 238 268 void setProgress(int curprogress); 269 239 270 void keyPressEvent(QKeyEvent *); 240 271 272 protected: 273 QProgressBar *progress; 274 241 275 private: 242 QProgressBar *progress; 276 void setTotalSteps (int totalSteps); 243 277 int steps; 244 278 int m_totalSteps; 245 279 QPtrList<class LCDTextItem> * textItems; 280 }; 246 281 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 */ 288 class 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; 248 322 }; 249 323 250 324 class MythThemedDialog : public MythDialog -
mythplugins/mythmusic/mythmusic/main.cpp
102 102 QFileInfoListIterator it(*list); 103 103 QFileInfo *fi; 104 104 105 /* Recursively traverse directory, calling 106 QApplication::processEvents every now and then to ensure the UI 107 updates */ 108 int update_interval = 0; 105 109 while ((fi = it.current()) != 0) 106 110 { 107 111 ++it; 108 112 if (fi->fileName() == "." || fi->fileName() == "..") 109 113 continue; 110 114 QString filename = fi->absFilePath(); 111 if (fi->isDir()) 115 if (fi->isDir()) { 112 116 BuildFileList(filename, music_files); 113 else 117 qApp->processEvents (); 118 } else { 119 if (++update_interval > 100) { 120 qApp->processEvents (); 121 update_interval = 0; 122 } 114 123 music_files[filename] = kFileSystem; 124 } 115 125 } 116 126 } 117 127 … … 177 187 MusicLoadedMap music_files; 178 188 MusicLoadedMap::Iterator iter; 179 189 190 MythBusyDialog *busy = new MythBusyDialog (QObject::tr("Searching for music files")); 191 busy->start (); 180 192 BuildFileList(directory, music_files); 193 busy->Close (); 194 delete busy; 181 195 182 196 MSqlQuery query(MSqlQuery::InitCon()); 183 197 query.exec("SELECT filename FROM musicmetadata " … … 186 200 int counter = 0; 187 201 188 202 MythProgressDialog *file_checking; 189 file_checking = new MythProgressDialog(QObject::tr("S earching formusic files"),203 file_checking = new MythProgressDialog(QObject::tr("Scanning music files"), 190 204 query.numRowsAffected()); 191 205 192 206 if (query.isActive() && query.size() > 0)