WIP enable scripting in Kexi.
ClosedPublic

Authored by piggz on May 30 2017, 10:15 PM.

Details

Summary

No Kexi wrappers are built yet, but module and global scripts are
available to reports

Test Plan

generate report with scripts

run 'executable' scripts within kexi. Scripts such as Kexi.openItem("report", "report_name"); works as expected

Example working script (providing database exists):

var db = new KDb();
console.log(db.driverNames());

var driver = db.driver("org.kde.kdb.sqlite");
console.log(driver.fileDBDriverMimeTypes());

var conn_data = db.createConnectionData();
conn_data.setDatabaseName("/home/piggz/Documents/Database/POI.kexi")

var conn = driver.createConnection(conn_data);

if (!conn.connect()) {
    console.log("Error connecting to database", conn.lastError());
}

if (!conn.useDatabase("")) {
    console.log("Error using database", conn.lastError());
}

console.log(conn.currentDatabase(), conn.isConnected());
console.log(conn.tableNames());

var cursor = conn.executeQueryString("select * from " + conn.tableNames()[0]);

cursor.open();
var fieldcount = cursor.fieldCount();
while (!cursor.eof()) {
    for (var i = 0; i < fieldcount; ++i) {
        console.log(cursor.value(i));
    }
    cursor.moveNext();
}

Diff Detail

Repository
R71 Kexi
Branch
kexi_scripting
Lint
No Linters Available
Unit
No Unit Test Coverage
There are a very large number of changes, so older changes are hidden. Show Older Changes
staniek added inline comments.Jul 13 2017, 10:45 PM
src/plugins/reports/kexireportpart.cpp
218

if (win

src/plugins/scripting/kexidb/kexidbconnection.cpp
27 ↗(On Diff #16671)

Can we set include paths and have just #include "kexiscriptingdebug.h" ?

src/plugins/scripting/kexidb/kexidbfieldlist.cpp
62 ↗(On Diff #15438)

Yep, massive change for all these const is OK.

src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp
391

BTW
Can we have have check for Qt version in CMake and if < 5.8 then disable scritping. I am OK with having 5.8 a dependency of scripting.

src/plugins/scripting/kexiscripting/kexiscriptpart.cpp
100

Better: xi18n("Error executing script at line %1:\n%2")

142

I see. KexiPart::Part::loadSchemaObject() can be still useful if implemented, right?

This revision now requires changes to proceed.Jul 13 2017, 10:45 PM
piggz updated this revision to Diff 16760.Jul 15 2017, 10:04 PM
piggz edited edge metadata.
piggz marked 4 inline comments as done.
  • Move execute from the view to the part
  • Address comments
  • Initialise
staniek requested changes to this revision.Jul 17 2017, 8:57 PM

Looks nice, good job, some comments.

CMakeLists.txt
109

instead how about:

if(KEXI_SCRIPTS_SUPPORT)
    find_package(Qt5 5.8.0 COMPONENTS Qml)
    set_package_properties(Qt5Qml PROPERTIES
                        DESCRIPTION "A framework for developing applications and libraries with the QML and JavaScript language."
                        URL "http://qt.io"
                        TYPE REQUIRED PURPOSE "Required by Kexi scripting (JavaScript)"
    )
endif()

This way: KEXI_SCRIPTS_SUPPORT is fully controlled by the user, if right version of Qml is missing -> proper error with explanation why Qml is needed

src/plugins/scripting/kexidb/kexidbconnection.cpp
89 ↗(On Diff #16760)

there's m_connection->options()->isReadOnly()

182 ↗(On Diff #16760)

KDbConnection::CreateTableOption::Default not needed

src/plugins/scripting/kexidb/kexidbdriver.cpp
55 ↗(On Diff #16760)

m_driver->metaData()->mimeTypes()?

src/plugins/scripting/kexidb/kexidbmodule.cpp
91 ↗(On Diff #16760)

Remove const from return type

93 ↗(On Diff #16760)

check is the list is not empty

101 ↗(On Diff #16760)

probably QUrl::fromLocalFile is better if we assume local files, otherwise only true URLs will work

117 ↗(On Diff #16760)

Like above

src/plugins/scripting/kexidb/kexidbparser.h
68 ↗(On Diff #16760)

missing const?

Do we need it as slot?

71 ↗(On Diff #16760)

Do we need it as slot?

73 ↗(On Diff #16760)

Do we need it as slot?

75 ↗(On Diff #16760)

Do we need it as slot?

77 ↗(On Diff #16760)

missing const?

Do we need it as slot?

80 ↗(On Diff #16760)

missing const?

Do we need it as slot?

82 ↗(On Diff #16760)

missing const?

Do we need it as slot?

84 ↗(On Diff #16760)

missing const?

Do we need it as slot?

src/plugins/scripting/kexidb/kexidbschema.cpp
133 ↗(On Diff #16760)

Not needed line?

138 ↗(On Diff #16760)

QRegularExpression is the current API, can we use it?

src/plugins/scripting/kexidb/kexidbschema.h
67 ↗(On Diff #16760)

Do getters need to be slots?

src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp
391

Sorry for confusion wrt disabling scripting.

src/plugins/scripting/kexiscripting/kexiscripteditor.cpp
30

not needed ;

46

isEmpty() is safer

83

KexiEditor::text() is already QString()

This revision now requires changes to proceed.Jul 17 2017, 8:57 PM
piggz marked 22 inline comments as done.Jul 19 2017, 2:34 PM
piggz added inline comments.
src/plugins/scripting/kexidb/kexidbparser.h
84 ↗(On Diff #16760)

They dont need to be slots, but they do have to be Q_INVOKABLE to be accessible to the JS engine

src/plugins/scripting/kexidb/kexidbschema.cpp
138 ↗(On Diff #16760)

Ok, ive moved this to the new API, but I dont know if ive done it correct,y. Please check thoroughly. I suspect a test case would be good here! (infact, some test scripts to check the whole KDb wrapper would be very handy)

piggz updated this revision to Diff 16915.Jul 19 2017, 2:51 PM
piggz edited edge metadata.
piggz marked 2 inline comments as done.
  • Address comments
piggz updated this revision to Diff 16924.Jul 19 2017, 7:32 PM
  • Fixes
piggz edited the test plan for this revision. (Show Details)Jul 19 2017, 7:32 PM

Thanks for the update Adam.
Only one thing today. Unsure about the var db = new KDb(); construct (the meaning). There's in fact one KDb, having multiple KDbs won't bring multiple driver managers or or multiple SQLite drivers.

Regarding side question "what's the purpose of the operator new for us?", how about t = new Table(), t.addField(), ... , then conn.createTable(t)? And similar constructs.

Eventually 'r = new Report' then "setup design of r dynamically" then r.print(), then forget r. See the difference? r is not stored in the design, it's fully dynamic :)

Just quick thoughts to admit: expressiveness of the operator-new looks promising.

piggz added a comment.Jul 21 2017, 9:00 AM

What is best, if you are happy with the engine port, do we push and work on the API separately? Do you want API changes for 3.1 or 4?

In D6037#127117, @piggz wrote:

What is best, if you are happy with the engine port, do we push and work on the API separately? Do you want API changes for 3.1 or 4?

The patch for kexi is OFF by default (what marks it as experimental) so it's safe to have it in 3.1 after the review and officially marked as experimental. Then it can be all further developed in master.
Further rework would move db-related scripting code to KDb, leaving only Kexi-related part in kexi.git. Moving to KDb makes major changes to KDb so KDb version would be up to 4. Scripting does not need to be public API/feature of KDb anytime soon but it shall be there in KDb if we assume probability of accessing KDb internals.

staniek edited the test plan for this revision. (Show Details)Jul 21 2017, 11:24 PM
staniek updated this revision to Diff 16992.Jul 21 2017, 11:51 PM
staniek edited the test plan for this revision. (Show Details)
  • avoid conflict of macros KDE_DEFAULT_DEBUG_AREA
  • Scripts have text mode only
  • Missing include for kproperty master
src/plugins/CMakeLists.txt
1

This line needs to be commented to avoid double definition

(previous is in src/plugins/scripting/kexiscripting/CMakeLists.txt)

src/plugins/scripting/kexiscripting/kexi_scriptplugin.desktop
56

I am not sure Kexi/Viewer fits here. "Open" does not work. Only Kexi/Editor.

By the way please change Kexi::DesignViewMode occurences to TextViewMode.

69–70

Similarly, no Kexi/Viewer here

staniek requested changes to this revision.Jul 21 2017, 11:55 PM

Fixed all 3 my notes.

Now question, your test code probably works for me but I see no debug log in the output pane.

This revision now requires changes to proceed.Jul 21 2017, 11:55 PM

BTW I do not request changes to the javascript API. That would be different task after we get things designed.

piggz updated this revision to Diff 17063.Jul 23 2017, 3:24 PM
piggz edited edge metadata.
piggz marked 9 inline comments as done.
  • Enable the kexiadaptor object
  • Enable KexiScriptAdaptor in the design view
  • Start porting the kexidb module
  • If it builds, relese it!
  • Plug together the kdb wrappers
  • Address comments
  • Address comments
  • Add KexiScriptingDebug
  • No need to have an adaptor instance if they can be created at runtime
  • Move execute from the view to the part
  • Address comments
  • Initialise
  • Address comments
  • Fixes
  • Add stdout redirection to print JS output in the script designer
piggz updated this revision to Diff 17067.Jul 23 2017, 3:48 PM
  • Only filter out JS category messages, send others to stderr

Almost there!
Big thanks Adam. Minor fixes proposed.

src/plugins/reports/kexireportpart.cpp
242

-> qWarning

245

-> qWarning

276

-> qWarning

282

-> qWarning

296

-> qWarning

src/plugins/scripting/kexidb/kexidbconnection.cpp
132 ↗(On Diff #17067)

-> KexiScriptingWarning, remove QString()

144 ↗(On Diff #17067)

-> KexiScriptingWarning, remove QString()

148 ↗(On Diff #17067)

-> KexiScriptingWarning, remove QString()

src/plugins/scripting/kexidb/kexidbmodule.cpp
135 ↗(On Diff #17067)

-> KexiScriptingWarning

174 ↗(On Diff #17067)

-> KexiScriptingWarning

src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp
328

-> KexiScriptingWarning

334

-> KexiScriptingWarning

src/plugins/scripting/kexiscripting/kexiscriptingdebug.h
1 ↗(On Diff #17067)

CamelCase recommended for new files

--> KexiScriptingDebug.h

27 ↗(On Diff #17067)

Add KexiScriptingWarning too

src/plugins/scripting/kexiscripting/kexiscriptpart.cpp
158

-> KexiScriptingWarning

164

-> KexiScriptingWarning

staniek requested changes to this revision.Jul 24 2017, 10:04 AM
This revision now requires changes to proceed.Jul 24 2017, 10:04 AM
piggz updated this revision to Diff 17141.Jul 24 2017, 7:59 PM
piggz edited edge metadata.
piggz marked 16 inline comments as done.
  • Add KexiScriptingWarning
staniek accepted this revision.Jul 24 2017, 8:09 PM

Good job!

This revision is now accepted and ready to land.Jul 24 2017, 8:09 PM
This revision was automatically updated to reflect the committed changes.