From: Flavio Tordini Date: Sat, 15 Aug 2009 14:48:52 +0000 (+0200) Subject: Better error handling X-Git-Tag: 0.6~50 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9b1068416ce67bea774a3eb299dc188718235388;p=minitube Better error handling --- diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 1016065..ae90525 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -83,6 +83,10 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { layout->addWidget(splitter); setLayout(layout); + errorTimer = new QTimer(this); + errorTimer->setSingleShot(true); + errorTimer->setInterval(3000); + connect(errorTimer, SIGNAL(timeout()), SLOT(skipVideo())); } MediaView::~MediaView() { @@ -126,6 +130,13 @@ void MediaView::disappear() { timerPlayFlag = true; } +void MediaView::handleError(QString message) { + videoAreaWidget->showError(message); + skippedVideo = listModel->activeVideo(); + // recover from errors by skipping to the next video + errorTimer->start(2000); +} + void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) { @@ -135,9 +146,7 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) case Phonon::ErrorState: qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType(); - videoAreaWidget->showError(mediaObject->errorString()); - // recover from errors by skipping to the next video - skip(); + handleError(mediaObject->errorString()); break; case Phonon::PlayingState: @@ -204,7 +213,7 @@ void MediaView::activeRowChanged(int row) { connect(video, SIGNAL(gotStreamUrl(QUrl)), SLOT(gotStreamUrl(QUrl))); // TODO handle signal in a proper slot and impl item error status - connect(video, SIGNAL(errorStreamUrl()), SLOT(skip())); + connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString))); video->loadStreamUrl(); // reset the timer flag @@ -258,6 +267,23 @@ void MediaView::currentSourceChanged(const Phonon::MediaSource source) { qDebug() << "Source changed:" << source.url(); } + +void MediaView::skipVideo() { + // skippedVideo is useful for DELAYED skip operations + // in order to be sure that we're skipping the video we wanted + // and not another one + if (skippedVideo) { + if (listModel->activeVideo() != skippedVideo) { + qDebug() << "Skip of video canceled"; + return; + } + int nextRow = listModel->rowForVideo(skippedVideo); + nextRow++; + if (nextRow == -1) return; + listModel->setActiveRow(nextRow); + } +} + void MediaView::skip() { int nextRow = listModel->nextRow(); if (nextRow == -1) return; diff --git a/src/MediaView.h b/src/MediaView.h index 3ef1bf8..a536402 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -40,6 +40,7 @@ public slots: void pause(); void stop(); void skip(); + void skipVideo(); void openWebPage(); void removeSelected(); void moveUpSelected(); @@ -53,6 +54,7 @@ private slots: void activeRowChanged(int); void selectVideos(QList videos); void gotStreamUrl(QUrl streamUrl); + void handleError(QString message); // phonon void stateChanged(Phonon::State newState, Phonon::State oldState); void aboutToFinish(); @@ -91,6 +93,8 @@ private: bool timerPlayFlag; + QTimer *errorTimer; + Video *skippedVideo; }; #endif // __MEDIAVIEW_H__