main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2009 Girish Ramakrishnan (girish@forwardbias.in)
  4. ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
  5. **
  6. ** Use, modification and distribution is allowed without limitation,
  7. ** warranty, liability or support of any kind.
  8. **
  9. ****************************************************************************/
  10. #include <QtGui>
  11. #include "npnimpl.h"
  12. //#define PLUGIN_PATH "/home/girish/.mozilla/plugins/libmymozplug"
  13. //#define PLUGIN_PATH "/home/girish/.mozilla/plugins/libdiamondx"
  14. //#define PLUGIN_PATH "/home/girish/.mozilla/plugins/libgrapher"
  15. //#define PLUGIN_PATH "/home/girish/.mozilla/plugins/libtrivial"
  16. //#define PLUGIN_PATH "/usr/lib/adobe-flashplugin/libflashplayer.so"
  17. //#define PLUGIN_PATH "/usr/lib/flashplugin-installer/libflashplayer.so"
  18. #ifdef Q_WS_MAEMO_5
  19. #define PLUGIN_PATH "/usr/lib/browser/plugins/libflashplayer.so"
  20. #else
  21. #define PLUGIN_PATH "/var/lib/flashplugin-installer/npwrapper.libflashplayer.so"
  22. #endif
  23. #define PLUGIN_MIMETYPE "application/x-shockwave-flash"
  24. #define PLUGIN_SRC "frog.swf"
  25. class MainWindow : public QMainWindow
  26. {
  27. Q_OBJECT
  28. public:
  29. MainWindow(QWidget *parent = 0) : QMainWindow(parent)
  30. {
  31. statusBar()->hide();
  32. QMenu *fileMenu = menuBar()->addMenu("&File");
  33. fileMenu->addAction("Snapshot", this, SLOT(snapshot()));
  34. fileMenu->addAction("Exit", qApp, SLOT(quit()));
  35. }
  36. public slots:
  37. void snapshot()
  38. {
  39. QPixmap pixmap = QPixmap::grabWidget(centralWidget());
  40. QLabel *label = new QLabel;
  41. label->setWindowTitle("Snapshot");
  42. label->setPixmap(pixmap);
  43. label->setAttribute(Qt::WA_DeleteOnClose);
  44. label->show();
  45. }
  46. };
  47. int main(int argc, char *argv[])
  48. {
  49. QApplication app(argc, argv);
  50. Plugin plugin(PLUGIN_PATH);
  51. if (!plugin.load()) {
  52. qWarning() << "Failed to load plugin";
  53. return false;
  54. }
  55. const char *keys[] = { "url", "type", "wmode" };
  56. const char *values[] = { PLUGIN_SRC, PLUGIN_MIMETYPE, "opaque" };
  57. int16_t count = sizeof(keys)/sizeof(const char *) - !app.arguments().contains("-windowless");
  58. Instance *instance = plugin.newInstance(PLUGIN_SRC, PLUGIN_MIMETYPE, keys, values, count);
  59. if (!instance) {
  60. qWarning() << "Failed to create instance";
  61. return 0;
  62. }
  63. instance->printInfo();
  64. MainWindow *mainWindow = new MainWindow;
  65. QWidget *browser = new QWidget;
  66. instance->setWindow(browser);
  67. QGridLayout *layout = new QGridLayout(browser);
  68. for (int i = 0; i < 5; i++) {
  69. for (int j = 0; j < 5; j++) {
  70. QPushButton *button = new QPushButton;
  71. button->setText(QString("%1, %2").arg(i).arg(j));
  72. layout->addWidget(button, i, j);
  73. }
  74. }
  75. QWidget *container = instance->container();
  76. container->setGeometry(50, 50, 300, 150);
  77. browser->setFixedSize(50+250, 50+250); // make the plugin align with bottom edge
  78. mainWindow->setCentralWidget(browser);
  79. mainWindow->show();
  80. app.exec();
  81. plugin.destroyInstance(instance);
  82. plugin.unload();
  83. return 0;
  84. }
  85. #include "main.moc"