Skip to content

Instantly share code, notes, and snippets.

@nowrep
Created April 5, 2012 20:12
Show Gist options
  • Save nowrep/2313746 to your computer and use it in GitHub Desktop.
Save nowrep/2313746 to your computer and use it in GitHub Desktop.
youtuber
void YouTuber_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
{
// Why are you storing pointer to webview? (And even as guarded pointer :-D )
m_view = view;
QRegExp rx("v=([^&]+)|youtu.be/([^&]+)");
rx.indexIn(r.linkUrl().toString());
QString videoId = rx.cap(1).isEmpty() ? rx.cap(2) : rx.cap(1);
if(videoId.isEmpty()) {
rx.indexIn(view->url().toString());
videoId = rx.cap(1).isEmpty() ? rx.cap(2) : rx.cap(1);
}
if (!videoId.isEmpty()) {
menu->addAction(QIcon(":/youtuber/data/youtube.png"), tr("View via YouTuber"), this, SLOT(startExternalHandler()))->setData(videoId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment