Created
April 5, 2012 20:12
-
-
Save nowrep/2313746 to your computer and use it in GitHub Desktop.
youtuber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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