return ItemTypeShowMore;
case Qt::DisplayRole:
case Qt::StatusTipRole:
+ if (!errorMessage.isEmpty()) return errorMessage;
if (searching) return tr("Searching...");
if (canSearchMore) return tr("Show %1 More").arg(MAX_ITEMS);
if (videos.isEmpty()) return tr("No videos");
case Qt::TextAlignmentRole:
return QVariant(int(Qt::AlignHCenter | Qt::AlignVCenter));
case Qt::ForegroundRole:
- return palette.color(QPalette::Dark);
+ if (!errorMessage.isEmpty())
+ return palette.color(QPalette::ToolTipText);
+ else
+ return palette.color(QPalette::Dark);
+ case Qt::BackgroundColorRole:
+ if (!errorMessage.isEmpty())
+ return palette.color(QPalette::ToolTipBase);
+ else
+ return QVariant();
case Qt::FontRole:
return boldFont;
default:
m_activeVideo = 0;
m_activeRow = -1;
skip = 1;
+ errorMessage.clear();
reset();
// (re)initialize the YouTubeSearch
youtubeSearch = new YouTubeSearch();
connect(youtubeSearch, SIGNAL(gotVideo(Video*)), this, SLOT(addVideo(Video*)));
connect(youtubeSearch, SIGNAL(finished(int)), this, SLOT(searchFinished(int)));
+ connect(youtubeSearch, SIGNAL(error(QString)), this, SLOT(searchError(QString)));
this->searchParams = searchParams;
searching = true;
void ListModel::searchMore(int max) {
if (searching) return;
searching = true;
+ errorMessage.clear();
youtubeSearch->search(searchParams, max, skip);
skip += max;
}
emit dataChanged( createIndex( MAX_ITEMS, 0 ), createIndex( MAX_ITEMS, columnCount() - 1 ) );
}
+void ListModel::searchError(QString message) {
+ errorMessage = message;
+ // update the message item
+ emit dataChanged( createIndex( MAX_ITEMS, 0 ), createIndex( MAX_ITEMS, columnCount() - 1 ) );
+}
+
void ListModel::addVideo(Video* video) {
connect(video, SIGNAL(gotThumbnail()), this, SLOT(updateThumbnail()));
void searchNeeded();
void addVideo(Video* video);
void searchFinished(int total);
+ void searchError(QString message);
void updateThumbnail();
signals:
int m_activeRow;
Video *m_activeVideo;
+ QString errorMessage;
};
#endif
// progressBar->hide();
}
+void LoadingWidget::setError(QString message) {
+ titleLabel->setText(tr("Error"));
+ descriptionLabel->setText(message);
+ // progressBar->hide();
+}
+
void LoadingWidget::bufferStatus(int percent) {
/*
qDebug() << percent;
public:
LoadingWidget(QWidget *parent);
void setVideo(Video *video);
+ void setError(QString message);
void clear();
public slots:
// get the HTTP response body
QByteArray bytes = networkReply->readAll();
-
emit data(bytes);
// bye bye my reply
networkReply->deleteLater();
}
+void NetworkReply::requestError(QNetworkReply::NetworkError code) {
+ emit error(networkReply);
+}
+
/* --- NetworkAccess --- */
NetworkAccess::NetworkAccess( QObject* parent) : QObject( parent ) {}
connect(networkReply, SIGNAL(metaDataChanged()),
reply, SLOT(metaDataChanged()), Qt::QueuedConnection);
+ // error signal
+ connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)),
+ reply, SLOT(requestError(QNetworkReply::NetworkError)));
+
// when the request is finished we'll invoke the target method
connect(networkReply, SIGNAL(finished()), reply, SLOT(finished()), Qt::QueuedConnection);
// report the error in the status bar
QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(qApp->topLevelWidgets().first());
- if (mainWindow) mainWindow->statusBar()->showMessage(networkReply->errorString());
+ if (mainWindow) mainWindow->statusBar()->showMessage(
+ tr("Network error: %1").arg(networkReply->errorString()));
+
+ qDebug() << "Network error:" << networkReply->errorString() << code;
- qDebug() << "Network error" << networkReply->errorString() << code;
networkReply->deleteLater();
}
public slots:
void finished();
void metaDataChanged();
+ void requestError(QNetworkReply::NetworkError);
signals:
void data(QByteArray);
+ void error(QNetworkReply*);
void finished(QNetworkReply*);
private:
stackedLayout->setCurrentWidget(videoWidget);
}
+void VideoAreaWidget::showError(QString message) {
+ loadingWidget->setError(message);
+ stackedLayout->setCurrentWidget(loadingWidget);
+}
+
void VideoAreaWidget::showLoading(Video *video) {
this->loadingWidget->setVideo(video);
stackedLayout->setCurrentWidget(loadingWidget);
void setLoadingWidget(LoadingWidget *loadingWidget);
void showLoading(Video* video);
void showVideo();
+ void showError(QString message);
void setListModel(ListModel *listModel) {
this->listModel = listModel;
}
"http://gdata.youtube.com/feeds/api/videos?q=%1&max-results=%2&start-index=%3")
.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));
+
switch (searchParams->sortBy()) {
case SearchParams::SortByNewest:
urlString.append("&orderby=published");
break;
}
- // QString urlString = QString("http://localhost/oringo/video.xml?q=%1&max-results=%2&start-index=%3")
- // .arg(query, QString::number(max), QString::number(skip));
-
QUrl url(urlString);
QObject *reply = The::http()->get(url);
- // connect(reply, SIGNAL(ready(QNetworkReply*)), SLOT(searchReady(QNetworkReply*)));
connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
+ connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(error(QNetworkReply*)));
+
+}
+void YouTubeSearch::error(QNetworkReply *reply) {
+ emit error(reply->errorString());
}
void YouTubeSearch::parseResults(QByteArray data) {
signals:
void gotVideo(Video*);
void finished(int total);
+ void error(QString message);
private slots:
void parseResults(QByteArray data);
+ void error(QNetworkReply *reply);
private: