From e201ec17a9eb1ffba1a8887a76e0a0672d457c18 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Sat, 15 Aug 2009 16:48:11 +0200 Subject: [PATCH] Video error reporting --- src/video.cpp | 12 +++++++++--- src/video.h | 3 ++- src/videoareawidget.cpp | 33 +++++++++++++++++++++++++++------ src/videoareawidget.h | 2 +- src/youtubesearch.cpp | 1 + 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 1ac9871..c4c3575 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -39,7 +39,7 @@ void Video::scrapeStreamUrl() { QRegExp re("^http://www\\.youtube\\.com/watch\\?v=([0-9A-Za-z_-]+)$"); bool match = re.exactMatch(webpage.toString()); if (!match || re.numCaptures() < 1) { - emit errorStreamUrl(); + emit errorStreamUrl(QString("Cannot get video id for %1").arg(webpage.toString())); return; } videoId = re.cap(1); @@ -52,6 +52,7 @@ void Video::scrapeStreamUrl() { QObject *reply = The::http()->get(normalizedUrl); connect(reply, SIGNAL(data(QByteArray)), SLOT(gotVideoInfo(QByteArray))); + connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*))); // see you in gotVideoInfo... } @@ -76,8 +77,9 @@ void Video::gotVideoInfo(QByteArray data) { errorMessage = errorMessage.left(indexOfTag); } if (mainWindow) mainWindow->statusBar()->showMessage(errorMessage); - } - emit errorStreamUrl(); + emit errorStreamUrl(errorMessage); + } else + emit errorStreamUrl("Error parsing video info"); return; } @@ -95,3 +97,7 @@ void Video::gotVideoInfo(QByteArray data) { emit gotStreamUrl(videoUrl); } + +void Video::errorVideoInfo(QNetworkReply *reply) { + emit errorStreamUrl(tr("Network error: %1 for %2").arg(reply->errorString(), reply->url().toString())); +} diff --git a/src/video.h b/src/video.h index f7d9198..974f49b 100644 --- a/src/video.h +++ b/src/video.h @@ -52,10 +52,11 @@ public slots: signals: void gotThumbnail(); void gotStreamUrl(QUrl streamUrl); - void errorStreamUrl(); + void errorStreamUrl(QString message); private slots: void gotVideoInfo(QByteArray); + void errorVideoInfo(QNetworkReply*); private: void scrapeStreamUrl(); diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index 0169148..1e87343 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -2,10 +2,27 @@ #include "videomimedata.h" VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { - stackedLayout = new QStackedLayout(this); - setLayout(stackedLayout); + QBoxLayout *vLayout = new QVBoxLayout(this); + vLayout->setMargin(0); + vLayout->setSpacing(0); + + // hidden message widget + messageLabel = new QLabel(this); + messageLabel->setOpenExternalLinks(true); + messageLabel->setMargin(7); + messageLabel->setBackgroundRole(QPalette::ToolTipBase); + messageLabel->setForegroundRole(QPalette::ToolTipText); + messageLabel->setAutoFillBackground(true); + messageLabel->setWordWrap(true); + messageLabel->hide(); + vLayout->addWidget(messageLabel); + + stackedLayout = new QStackedLayout(); + vLayout->addLayout(stackedLayout); + + setLayout(vLayout); setAcceptDrops(true); - + // mouse autohide setMouseTracking(true); mouseTimer = new QTimer(this); @@ -29,13 +46,17 @@ void VideoAreaWidget::showVideo() { } void VideoAreaWidget::showError(QString message) { - loadingWidget->setError(message); + // loadingWidget->setError(message); + messageLabel->setText(message); + messageLabel->show(); stackedLayout->setCurrentWidget(loadingWidget); } void VideoAreaWidget::showLoading(Video *video) { this->loadingWidget->setVideo(video); stackedLayout->setCurrentWidget(loadingWidget); + messageLabel->hide(); + messageLabel->clear(); } void VideoAreaWidget::mouseDoubleClickEvent(QMouseEvent *event) { @@ -67,10 +88,10 @@ void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) { } void VideoAreaWidget::dropEvent(QDropEvent *event) { - + const VideoMimeData* videoMimeData = dynamic_cast( event->mimeData() ); if(!videoMimeData ) return; - + QList droppedVideos = videoMimeData->videos(); foreach( Video *video, droppedVideos) { int row = listModel->rowForVideo(video); diff --git a/src/videoareawidget.h b/src/videoareawidget.h index 44e5477..34650cc 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -41,7 +41,7 @@ private: QWidget *videoWidget; LoadingWidget *loadingWidget; ListModel *listModel; - + QLabel *messageLabel; QTimer *mouseTimer; }; diff --git a/src/youtubesearch.cpp b/src/youtubesearch.cpp index a182099..78d4375 100644 --- a/src/youtubesearch.cpp +++ b/src/youtubesearch.cpp @@ -17,6 +17,7 @@ void YouTubeSearch::search(SearchParams *searchParams, int max, int skip) { .arg(searchParams->keywords(), QString::number(max), QString::number(skip)); // Useful to test with a local webserver + urlString = QString("http://localhost/oringo/video.xml?q=%1&max-results=%2&start-index=%3") .arg(searchParams->keywords(), QString::number(max), QString::number(skip)); -- 2.39.5