From 9b1068416ce67bea774a3eb299dc188718235388 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Sat, 15 Aug 2009 16:48:52 +0200 Subject: [PATCH] Better error handling --- src/MediaView.cpp | 34 ++++++++++++++++++++++++++++++---- src/MediaView.h | 4 ++++ 2 files changed, 34 insertions(+), 4 deletions(-) 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__ -- 2.39.5