236 lines
9.0 KiB
QML
236 lines
9.0 KiB
QML
import QtQuick 2.6
|
|
import Sailfish.Silica 1.0
|
|
import io.thp.pyotherside 1.5
|
|
import QtQuick.LocalStorage 2.0
|
|
|
|
Page {
|
|
id: page
|
|
property string apikey
|
|
onApikeyChanged: {
|
|
console.log("api key changed")
|
|
python.call('languagedownloader.getAPItoken', [], function(output){
|
|
console.log(output)});
|
|
python.call('languagedownloader.setAPItoken', [apikey], function(output1){
|
|
console.log(output1)
|
|
console.log(apikey)
|
|
});
|
|
python.call('languagedownloader.getAPItoken', [], function(output){
|
|
console.log(output)});
|
|
if (apikey) {
|
|
python.call('languagedownloader.populateSourceLangDB',
|
|
[], function(result) {
|
|
});
|
|
python.call('languagedownloader.populateTargetLangDB',
|
|
[], function(result) {
|
|
});
|
|
python.call('languagedownloader.sourceLangFromDB', [], function(output){
|
|
repeaterSource.model = output
|
|
});
|
|
python.call('languagedownloader.targetLangFromDB', [], function(output){
|
|
repeaterDestination.model = output
|
|
});
|
|
}
|
|
}
|
|
|
|
function swapLanguage(){
|
|
python.call('languagedownloader.swapLanguages', [], function(){});
|
|
python.call('languagedownloader.sourceLangFromDB', [], function(output){
|
|
repeaterSource.model = output
|
|
});
|
|
python.call('languagedownloader.targetLangFromDB', [], function(output){
|
|
repeaterDestination.model = output
|
|
});
|
|
}
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentWidth: parent.width
|
|
|
|
PullDownMenu {
|
|
id: pullDownMenu
|
|
|
|
MenuItem {
|
|
text: qsTr("Settings")
|
|
onClicked: {
|
|
var text1
|
|
var dialog = pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
|
dialog.accepted.connect(function() {
|
|
console.log(dialog.apikey)
|
|
page.apikey = dialog.apikey
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Column {
|
|
id: column1
|
|
width: parent.width
|
|
|
|
PageHeader {
|
|
title: qsTr("Text Translation")
|
|
}
|
|
|
|
Row {
|
|
id: row
|
|
width : parent.width
|
|
ComboBox {
|
|
id: comboBoxSource
|
|
width: parent.width / 2
|
|
|
|
menu : ContextMenu {
|
|
id: contextMenuSource
|
|
Repeater {
|
|
id: repeaterSource
|
|
Component.onCompleted: {
|
|
model: {
|
|
python.call('languagedownloader.sourceLangFromDB', [], function(output){
|
|
model = output
|
|
});
|
|
}
|
|
}
|
|
MenuItem {
|
|
id: menuItemSource
|
|
text: "%0".arg(modelData[1])
|
|
|
|
onClicked: {
|
|
python.call('languagedownloader.setLastLangDB', [modelData[0]], function(){
|
|
});
|
|
|
|
python.call('languagedownloader.sourceLangFromDB', [], function(output){
|
|
repeaterSource.model = output
|
|
});
|
|
}
|
|
Component.onCompleted: {
|
|
comboBoxSource.value = repeaterSource.itemAt(0).text
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
IconButton {
|
|
id: swapLang
|
|
width: icon.width
|
|
icon.source: "image://theme/icon-s-retweet"
|
|
onClicked: {
|
|
swapLanguage()
|
|
}
|
|
}
|
|
|
|
ComboBox {
|
|
id: comboBoxDestination
|
|
width: parent.width / 2
|
|
|
|
menu : ContextMenu {
|
|
id: contextMenuDestination
|
|
Repeater {
|
|
id: repeaterDestination
|
|
Component.onCompleted: {
|
|
model: {
|
|
python.call('languagedownloader.targetLangFromDB', [], function(output){
|
|
model = output
|
|
});
|
|
}
|
|
}
|
|
MenuItem {
|
|
id: menuItemDestination
|
|
text: "%0".arg(modelData[1])
|
|
onClicked: {
|
|
python.call('languagedownloader.setLastTargetLangDB', [modelData[0]], function(){
|
|
});
|
|
python.call('languagedownloader.targetLangFromDB', [], function(output){
|
|
repeaterDestination.model = output
|
|
});
|
|
}
|
|
Component.onCompleted: {
|
|
comboBoxDestination.value = repeaterDestination.itemAt(0).text
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
TextArea {
|
|
id: textAreaInput
|
|
height: Screen.height / 4
|
|
placeholderText: qsTr("Text")
|
|
onTextChanged: {
|
|
if (text.charAt(cursorPosition-1) == " "){
|
|
python.startDownload(textAreaInput.text)
|
|
}
|
|
}
|
|
EnterKey.enabled: text.length > 0
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: {
|
|
focus = false
|
|
python.startDownload(textAreaInput.text)
|
|
}
|
|
|
|
leftItem: IconButton {
|
|
onClicked: {
|
|
textAreaInput.text = ""
|
|
textAreaOutput.text = ""
|
|
focus = textAreaInput
|
|
}
|
|
width: icon.width
|
|
height: icon.height
|
|
icon.source: "image://theme/icon-splus-clear"
|
|
opacity: textAreaInput.text.length > 0 ? 1.0 : 0.0
|
|
Behavior on opacity { FadeAnimation {} }
|
|
}
|
|
}
|
|
|
|
TextArea {
|
|
id: textAreaOutput
|
|
height: Screen.height / 4
|
|
text: ""
|
|
|
|
leftItem: IconButton {
|
|
width: icon.width
|
|
height: icon.height
|
|
icon.source: "image://theme/icon-s-clipboard"
|
|
opacity: textAreaOutput.text.length > 0 ? 1.0 : 0.0
|
|
onClicked: {
|
|
Clipboard.text = textAreaOutput.text;
|
|
Notices.show(qsTr("Copied"), Notice.Short, Notice.Center);
|
|
}
|
|
}
|
|
}
|
|
|
|
Python {
|
|
id: python
|
|
|
|
Component.onCompleted: {
|
|
addImportPath(Qt.resolvedUrl('.'));
|
|
|
|
importModule('languagedownloader', function() {});
|
|
|
|
call('languagedownloader.populateSourceLangDB',
|
|
[], function(result) {
|
|
});
|
|
|
|
call('languagedownloader.populateTargetLangDB',
|
|
[], function(result) {
|
|
});
|
|
|
|
setHandler('finished', function(translatedText){
|
|
if (translatedText) textAreaOutput.text = translatedText
|
|
else console.log(translatedText)
|
|
});
|
|
|
|
setHandler('status', function (status){
|
|
});
|
|
}
|
|
|
|
function startDownload(textAreaInput) {
|
|
call('languagedownloader.translate_text',[textAreaInput],
|
|
function() {})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|