linphone-desktop/tests/ui/scripts/utils.js
2016-09-26 15:59:07 +02:00

78 lines
2.2 KiB
JavaScript

// ===================================================================
// Contains many common helpers.
// ===================================================================
// Load by default a window in the ui/views folder.
// If options.isString is equals to true, a marshalling component can
// be used.
//
// Supported options: isString, exitHandler.
//
// If exitHandler is used, window must implement exitStatus signal.
function openWindow (window, parent, options) {
var object
if (options && options.isString) {
object = Qt.createQmlObject(window, parent)
} else {
var component = Qt.createComponent(
'qrc:/ui/Views/' + window + '.qml'
)
if (component.status !== Component.Ready) {
console.debug('Window not ready.')
if(component.status === Component.Error) {
console.debug('Error:' + component.errorString())
}
return // Error.
}
object = component.createObject(parent)
}
console.debug('Open window.')
object.closing.connect(function () {
console.debug('Destroy window.')
object.destroy()
})
object.exitStatus.connect(function (status) {
console.debug('Exit status: ' + status)
})
if (options && options.exitHandler) {
object.exitStatus.connect(
// Bind to access parent properties.
options.exitHandler.bind(parent)
)
}
object.show()
}
// -------------------------------------------------------------------
// Display a simple ConfirmDialog component.
// Wrap the openWindow function.
function openConfirmDialog (parent, options) {
openWindow(
'import QtQuick 2.7;' +
'import \'qrc:/ui/Linphone/Dialog\';' +
'ConfirmDialog {' +
'descriptionText: \'' + options.descriptionText + '\';' +
'title: \'' + options.title + '\'' +
'}',
parent, {
isString: true,
exitHandler: options.exitHandler
}
)
}
// -------------------------------------------------------------------
function snakeToCamel (s) {
return s.replace(/(\_\w)/g, function (matches) {
return matches[1].toUpperCase()
})
}