Guest User

Untitled

a guest
Jun 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include "youtuber.h"
  2.  
  3. void YouTuber::init(QString sPath)
  4. {
  5.     settingsPath = sPath;
  6.     //This function is called right after plugin is loaded
  7.     qDebug() << __FUNCTION__ << "called";
  8. }
  9.  
  10. bool YouTuber::testPlugin()
  11. {
  12.     //This function is called right after init()
  13.     //There should be some testing if plugin is loaded correctly
  14.     //If this function returns false, plugin is automatically unloaded
  15.  
  16.     return true;
  17. }
  18.  
  19. QTranslator* YouTuber::getTranslator(QString locale)
  20. {
  21.     QTranslator* translator = new QTranslator();
  22.     translator->load(":/" + locale);
  23.     return translator;
  24. }
  25.  
  26. void YouTuber::showSettings()
  27. {
  28.     QWidget* widget = new QWidget();
  29.     new QLabel("YouTuber v0.1", widget);
  30.     widget->resize(200, 200);
  31.     widget->setAttribute(Qt::WA_DeleteOnClose);
  32.     widget->setWindowModality(Qt::WindowModal); //As the preferences window is modal too
  33.     widget->setWindowTitle(tr("Settings"));
  34.     widget->setWindowIcon(pluginIcon());
  35.     widget->show();
  36. }
  37.  
  38. void YouTuber::populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestResult r)
  39. {
  40.     Q_UNUSED(view)
  41.     if (!r.linkUrl().isEmpty()) {
  42.       QRegExp rx("v=([^&]+)");
  43.       bool matched = rx.indexIn(r.linkUrl().toString()) != -1;
  44.       if (matched) {
  45.         menu->addAction(QIcon(pluginIcon()), tr("View via YouTuber"), this, SLOT(startExternalHandler()))->setData(r.linkUrl());
  46.       }
  47.      }
  48. }
  49.  
  50. void YouTuber::startExternalHandler(l)
  51. {
  52. const QUrl &url = qobject_cast<QAction*>(sender())->data()->toUrl();
  53. //     Will be used to pass arguments of external program, not needed for now
  54.     QString extArg = "";
  55. //     Will be used to pass path to the external program, using my script for now
  56.     QString extBin = "/home/mladen/Radna/opera-youtube-viewer.sh";
  57.    
  58.     QStringList arguments = extArg.split(" ");
  59.     arguments << url.toString();
  60.  
  61.     bool success = QProcess::startDetached(extBin, arguments);
  62.  
  63.     if (!success) {
  64.         QString info = "<ul><li><b>" + tr("Executable: ") + "</b>" + extBin + "</li><li><b>" + tr("Arguments: ") + "</b>" + arguments.join(" ") + "</li></ul>";
  65.         QMessageBox::critical(0, tr("Cannot start external viewer"), tr("Cannot start external viewer! %1").arg(info));
  66.     }
  67. }
  68.  
  69. //Export plugin macro
  70. Q_EXPORT_PLUGIN2(YouTuber, YouTuber)
Add Comment
Please, Sign In to add comment