Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "youtuber.h"
- void YouTuber::init(QString sPath)
- {
- settingsPath = sPath;
- //This function is called right after plugin is loaded
- qDebug() << __FUNCTION__ << "called";
- }
- bool YouTuber::testPlugin()
- {
- //This function is called right after init()
- //There should be some testing if plugin is loaded correctly
- //If this function returns false, plugin is automatically unloaded
- return true;
- }
- QTranslator* YouTuber::getTranslator(QString locale)
- {
- QTranslator* translator = new QTranslator();
- translator->load(":/" + locale);
- return translator;
- }
- void YouTuber::showSettings()
- {
- QWidget* widget = new QWidget();
- new QLabel("YouTuber v0.1", widget);
- widget->resize(200, 200);
- widget->setAttribute(Qt::WA_DeleteOnClose);
- widget->setWindowModality(Qt::WindowModal); //As the preferences window is modal too
- widget->setWindowTitle(tr("Settings"));
- widget->setWindowIcon(pluginIcon());
- widget->show();
- }
- void YouTuber::populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestResult r)
- {
- Q_UNUSED(view)
- if (!r.linkUrl().isEmpty()) {
- QRegExp rx("v=([^&]+)");
- bool matched = rx.indexIn(r.linkUrl().toString()) != -1;
- if (matched) {
- menu->addAction(QIcon(pluginIcon()), tr("View via YouTuber"), this, SLOT(startExternalHandler()))->setData(r.linkUrl());
- }
- }
- }
- void YouTuber::startExternalHandler(l)
- {
- const QUrl &url = qobject_cast<QAction*>(sender())->data()->toUrl();
- // Will be used to pass arguments of external program, not needed for now
- QString extArg = "";
- // Will be used to pass path to the external program, using my script for now
- QString extBin = "/home/mladen/Radna/opera-youtube-viewer.sh";
- QStringList arguments = extArg.split(" ");
- arguments << url.toString();
- bool success = QProcess::startDetached(extBin, arguments);
- if (!success) {
- QString info = "<ul><li><b>" + tr("Executable: ") + "</b>" + extBin + "</li><li><b>" + tr("Arguments: ") + "</b>" + arguments.join(" ") + "</li></ul>";
- QMessageBox::critical(0, tr("Cannot start external viewer"), tr("Cannot start external viewer! %1").arg(info));
- }
- }
- //Export plugin macro
- Q_EXPORT_PLUGIN2(YouTuber, YouTuber)
Add Comment
Please, Sign In to add comment