// update the message item
emit dataChanged( createIndex( MAX_ITEMS, 0 ), createIndex( MAX_ITEMS, columnCount() - 1 ) );
+
+ if (!youtubeSearch->getSuggestions().isEmpty()) {
+ emit haveSuggestions(youtubeSearch->getSuggestions());
+ }
}
void ListModel::searchError(QString message) {
signals:
void activeRowChanged(int);
void needSelectionFor(QList<Video*>);
+ void haveSuggestions(const QStringList &suggestions);
private:
void searchMore(int max);
void restore();
void messageReceived(const QString &message);
void quit();
+ void startToolbarSearch(QString query);
protected:
void changeEvent(QEvent *);
void downloadsFinished();
void toggleDownloads(bool show);
- void startToolbarSearch(QString query);
void floatOnTop(bool);
void showActionInStatusBar(QAction*, bool show);
void showStopAfterThisInStatusBar(bool show);
sidebar->setPlaylist(listView);
connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
SLOT(searchAgain()));
+ connect(listModel, SIGNAL(haveSuggestions(const QStringList &)),
+ sidebar, SLOT(showSuggestions(const QStringList &)));
+ connect(sidebar, SIGNAL(suggestionAccepted(QString)),
+ MainWindow::instance(), SLOT(startToolbarSearch(QString)));
splitter->addWidget(sidebar);
videoAreaWidget = new VideoAreaWidget(this);
}
sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
+ sidebar->hideSuggestions();
}
void MediaView::searchAgain() {
playlist = 0;
QBoxLayout *layout = new QVBoxLayout(this);
+ layout->setSpacing(1);
layout->setMargin(0);
+ // hidden message widget
+ messageLabel = new QLabel(this);
+ messageLabel->setMargin(10);
+ messageLabel->setBackgroundRole(QPalette::ToolTipBase);
+ messageLabel->setForegroundRole(QPalette::ToolTipText);
+ messageLabel->setAutoFillBackground(true);
+ messageLabel->setWordWrap(true);
+ messageLabel->setTextFormat(Qt::RichText);
+ messageLabel->setTextInteractionFlags(
+ Qt::LinksAccessibleByKeyboard |
+ Qt::LinksAccessibleByMouse);
+ connect(messageLabel, SIGNAL(linkActivated(QString)),
+ SIGNAL(suggestionAccepted(QString)));
+ messageLabel->hide();
+ layout->addWidget(messageLabel);
+
stackedWidget = new QStackedWidget(this);
layout->addWidget(stackedWidget);
height() - refineSearchButton->minimumHeight());
refineSearchButton->show();
}
+
+void SidebarWidget::showSuggestions(const QStringList &suggestions) {
+ QString message = tr("Did you mean: %1");
+
+ QString suggestionLinks;
+ foreach (QString suggestion, suggestions) {
+ suggestionLinks += "<a href='" + suggestion + "'>" + suggestion + "</a> ";
+ }
+ message = message.arg(suggestionLinks);
+
+ QString html =
+ "<html>"
+ "<style>"
+ "a { color: palette(text); text-decoration: none; font-weight: bold }"
+ "</style>"
+ "<body>%1</body>"
+ "</html>";
+ html = html.arg(message);
+ messageLabel->setText(html);
+ messageLabel->show();
+}
+
+void SidebarWidget::hideSuggestions() {
+ messageLabel->hide();
+ messageLabel->clear();
+}
void setPlaylist(QListView *playlist);
void showPlaylist();
RefineSearchWidget* getRefineSearchWidget() { return refineSearchWidget; }
+ void hideSuggestions();
public slots:
void showRefineSearchWidget();
void hideRefineSearchWidget();
void toggleRefineSearch(bool show = false);
+ void showSuggestions(const QStringList &suggestions);
+
+signals:
+ void suggestionAccepted(QString);
protected:
void resizeEvent(QResizeEvent *);
QListView *playlist;
RefineSearchWidget *refineSearchWidget;
QTimer *mouseTimer;
+ QLabel *messageLabel;
};
qDebug() << "Error parsing XML";
}
videos = reader.getVideos();
+ suggestions = reader.getSuggestions();
foreach (Video *video, videos) {
// send it to the model
return videos;
}
+const QStringList & YouTubeSearch::getSuggestions() const {
+ return suggestions;
+}
+
void YouTubeSearch::abort() {
this->abortFlag = true;
}
void search(SearchParams *searchParams, int max, int skip);
void abort();
QList<Video*> getResults();
+ const QStringList & getSuggestions() const;
static QString videoIdFromUrl(QString url);
signals:
private:
QList<Video*> videos;
+ QStringList suggestions;
bool abortFlag;
readNext();
if (isStartElement() && name() == "entry") {
readEntry();
+ } else if (name() == "link"
+ && attributes().value("rel").toString()
+ == "http://schemas.google.com/g/2006#spellcorrection") {
+ suggestions << attributes().value("title").toString();
}
}
}
webpage.remove("&feature=youtube_gdata");
// qDebug() << "Webpage: " << webpage;
video->setWebpage(QUrl(webpage));
+
} else if (name() == "author") {
readNext();
if (name() == "name") {
QList<Video*> YouTubeStreamReader::getVideos() {
return videos;
}
+
+const QStringList & YouTubeStreamReader::getSuggestions() const {
+ return suggestions;
+}
YouTubeStreamReader();
bool read(QByteArray data);
QList<Video*> getVideos();
+ const QStringList & getSuggestions() const;
private:
void readMediaGroup();
void readEntry();
QList<Video*> videos;
+ QStringList suggestions;
};
#endif // YOUTUBESTREAMREADER_H