bool QtScriptEngine::runScript(const QString& script, const QString& name, RunMode mode)
    {
        MyQScriptEngine engine(this);

        map<ADM_dynMuxer*, Muxer*> muxers;
        map<ADM_videoEncoder6*, VideoEncoder*> videoEncoders;

#ifdef QT_SCRIPTTOOLS
        QScriptEngineDebugger debugger;

        if (mode == IScriptEngine::Debug || mode == IScriptEngine::DebugOnError)
        {
            debugger.attachTo(&engine);
            debugger.standardWindow()->setWindowTitle(QT_TR_NOOP("Avidemux Script Debugger"));
            debugger.standardWindow()->setWindowModality(Qt::ApplicationModal);

            if (mode == IScriptEngine::Debug)
            {
                debugger.action(QScriptEngineDebugger::InterruptAction)->trigger();
            }
        }

#endif

        this->registerAudioEncoderPlugins(&engine);
        this->registerMuxerPlugins(&engine, &muxers);
        this->registerVideoEncoderPlugins(&engine, &videoEncoders);
        this->registerVideoFilterPlugins(&engine);
		this->registerDialogClasses(&engine);
        this->registerScriptClasses(&engine, &muxers, &videoEncoders);

        QScriptValue result = engine.evaluate(script, name);
        bool success = false;

        if (engine.hasUncaughtException())
        {
            QString errorDetails = (QString("Unable to process script.\n\nLine number: %1\n").arg(
                                        engine.uncaughtExceptionLineNumber()) + result.toString());

            this->callEventHandlers(IScriptEngine::Error, NULL, -1, (QString("Script error ") + errorDetails).toUtf8().constData());
            success = false;
        }
        else
        {
            this->callEventHandlers(IScriptEngine::Information, NULL, -1, (QString("Result: ") + result.toString()).toUtf8().constData());
            success = true;
        }

        return success;
    }
void tst_QScriptEngineDebugger::standardObjects()
{
#if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600
    QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll);
#endif

    QScriptEngine engine;
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);

    QMainWindow *win = debugger.standardWindow();
    QCOMPARE(static_cast<QWidget *>(win->parent()), (QWidget*)0);

    QMenu *menu = debugger.createStandardMenu();
    QCOMPARE(static_cast<QWidget *>(menu->parent()), (QWidget*)0);
    QToolBar *toolBar = debugger.createStandardToolBar();
    QCOMPARE(static_cast<QWidget *>(toolBar->parent()), (QWidget*)0);

    QMenu *menu2 = debugger.createStandardMenu(win);
    QCOMPARE(static_cast<QWidget *>(menu2->parent()), (QWidget*)win);
    QVERIFY(menu2 != menu);
    QToolBar *toolBar2 = debugger.createStandardToolBar(win);
    QCOMPARE(static_cast<QWidget *>(toolBar2->parent()), (QWidget*)win);
    QVERIFY(toolBar2 != toolBar);

    delete menu;
    delete toolBar;
}
MapleManager::MapleManager(Server* server, QWidget *widget) :
    QObject(server),
    m_status(ConnectionStatus::WAITIGN),
    m_launch_status(LaunchStatus::LAUNCHIGN),
    m_socket(0),
    m_relaunch(true),
    r_mode(MapleManager::RESIZE_MODE::AUTO)
{
    m_server = server;
    m_widget = new ManagerWidget(widget);
    m_widget->installEventFilter(this);
    connect(m_widget,SIGNAL(save()),this,SLOT(saveSettings()));
    connect(m_widget,SIGNAL(load()),this,SLOT(loadSettings()));
    connect(m_widget,SIGNAL(showDBG(bool)),this,SLOT(showDBG(bool)));
    connect(m_widget,SIGNAL(relaunch(bool)),this,SLOT(setRelaunch(bool)));
    connect(m_widget,SIGNAL(s_changeTabName(QString)),this,SLOT(changeTabName(QString)));

    m_engine = new QScriptEngine(this);

    QScriptEngineDebugger *dbg = new QScriptEngineDebugger(this);
    dbg->attachTo(m_engine);
    m_widget->regiterDebugger((QWidget*)dbg->standardWindow());

    ScriptFunctions::registerFuncions(m_engine);
    m_engine->globalObject().setProperty(API::Path,qApp->applicationDirPath());
    m_engine->globalObject().setProperty(API::GUI,m_engine->newQObject(m_widget));
    m_engine->globalObject().setProperty(API::Socket,m_engine->newQObject(this));
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(tetrix);

//! [1]
    QApplication app(argc, argv);
    QScriptEngine engine;

    QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get());
    Qt.setProperty("App", engine.newQObject(&app));
    engine.globalObject().setProperty("Qt", Qt);
//! [1]

#ifndef QT_NO_SCRIPTTOOLS
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    QMainWindow *debugWindow = debugger.standardWindow();
    debugWindow->resize(1024, 640);
#endif

//! [2]
    evaluateFile(engine, ":/tetrixpiece.js");
    evaluateFile(engine, ":/tetrixboard.js");
    evaluateFile(engine, ":/tetrixwindow.js");
//! [2]

//! [3]
    TetrixUiLoader loader;
    QFile uiFile(":/tetrixwindow.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();

    QScriptValue ctor = engine.evaluate("TetrixWindow");
    QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
    QScriptValue tetrix = ctor.construct(QScriptValueList() << scriptUi);
//! [3]

    QPushButton *debugButton = qFindChild<QPushButton*>(ui, "debugButton");
#ifndef QT_NO_SCRIPTTOOLS
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugger.action(QScriptEngineDebugger::InterruptAction),
                     SIGNAL(triggered()));
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugWindow, SLOT(show()));
#else
    debugButton->hide();
#endif

//! [4]
    ui->resize(550, 370);
    ui->show();

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    return app.exec();
//! [4]
}
Beispiel #5
0
int main(int argc, char **argv)
{
    Q_INIT_RESOURCE(calculator);

    QApplication app(argc, argv);
//! [0a]
    QScriptEngine engine;
//! [0a]

#if !defined(QT_NO_SCRIPTTOOLS)
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    QMainWindow *debugWindow = debugger.standardWindow();
    debugWindow->resize(1024, 640);
#endif

//! [0b]
    QString scriptFileName(":/calculator.js");
    QFile scriptFile(scriptFileName);
    scriptFile.open(QIODevice::ReadOnly);
    engine.evaluate(scriptFile.readAll(), scriptFileName);
    scriptFile.close();
//! [0b]

//! [1]
    QUiLoader loader;
    QFile uiFile(":/calculator.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();
//! [1]

//! [2]
    QScriptValue ctor = engine.evaluate("Calculator");
    QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
    QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi);
//! [2]

#if !defined(QT_NO_SCRIPTTOOLS)
    QLineEdit *display = qFindChild<QLineEdit*>(ui, "display");
    QObject::connect(display, SIGNAL(returnPressed()),
                     debugWindow, SLOT(show()));
#endif
//! [3]
    ui->show();
    return app.exec();
//! [3]
}
Beispiel #6
0
void SmsScriptsManager::init()
{
#if SMS_USE_DEBUGGER
 	QScriptEngineDebugger *debugger = new QScriptEngineDebugger(this);
 	debugger->attachTo(Engine);
 	debugger->standardWindow()->show();
#endif

	QString scriptPath = Application::instance()->pathsProvider()->profilePath() + QLatin1String("plugins/data/sms/scripts/gateway.js");
	if (QFile::exists(scriptPath))
		loadScript(scriptPath);
	else
	{
		scriptPath = Application::instance()->pathsProvider()->dataPath() + QLatin1String("plugins/data/sms/scripts/gateway.js");
		if (QFile::exists(scriptPath))
			loadScript(scriptPath);
		// TODO: maybe we should return here if no gateway.js was found?
	}

	// scripts from profile path can replace the ones from data path if the file name is the same
	loadScripts(QDir(Application::instance()->pathsProvider()->profilePath() + QLatin1String("plugins/data/sms/scripts")));
	loadScripts(QDir(Application::instance()->pathsProvider()->dataPath() + QLatin1String("plugins/data/sms/scripts")));
}