ImportWords.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import "Logic.js" as Logic
  4. Rectangle {
  5. id: importWords
  6. anchors.fill: parent
  7. color: "black"
  8. opacity: 0.8
  9. property int cntWord: 0
  10. property bool isOk: false
  11. Item {
  12. id: wrapperImg
  13. height: 140
  14. width: 140
  15. anchors.bottom: textWait.top
  16. anchors.bottomMargin: 10
  17. anchors.horizontalCenter: parent.horizontalCenter
  18. Image {
  19. id: imgImport
  20. anchors.centerIn: parent
  21. source: "images/import.png"
  22. }
  23. }
  24. Text {
  25. id: textWait
  26. property int progresValue: 0
  27. anchors.centerIn: parent
  28. font.pixelSize: 30
  29. color: "white"
  30. text: qsTr("Please wait...")
  31. }
  32. ProgressBar {
  33. id: pbImport
  34. indeterminate: true
  35. anchors.top: textWait.bottom
  36. anchors.horizontalCenter: parent.horizontalCenter
  37. width: 0.7*parent.width
  38. visible: ma.enabled === false ? true : false
  39. }
  40. MouseArea {
  41. id: ma
  42. anchors.fill: parent
  43. enabled: true
  44. onClicked: {
  45. importWords.visible = false
  46. }
  47. }
  48. property int importCategoryId: pageImportWords.selectedCategoryId
  49. /************************************************************************/
  50. /************************************************************************/
  51. XmlListModel {
  52. id: xmlWords
  53. source: pageImportWords.xmlfile
  54. query: "/meewords/words"
  55. XmlRole { name: "wrd"; query: "word/string()" }
  56. XmlRole { name: "trans"; query: "translation/string()" }
  57. }
  58. Repeater {
  59. id: repImport
  60. model: xmlWords
  61. delegate: Item {
  62. Component.onCompleted: {
  63. if( (pageImportWords.selectedCategoryId > 0) && (pageImportWords.xmlfile !== "") ) {
  64. //console.log( "*" + pageImportWords.xmlfile)
  65. ma.enabled = false
  66. if( (wrd !== "") && (trans !== "") )
  67. var id = Logic.addWord( wrd, trans, pageImportWords.selectedCategoryId )
  68. cntWord += 1
  69. textWait.progresValue += 1
  70. if ( cntWord == repImport.count ) {
  71. importWords.visible = false
  72. ma.enabled = true
  73. if( cntWord > 0) {
  74. showDlgImport() //показываем диалог окончания импорта
  75. cntWord = -10 //сбрасываем счетчик
  76. }
  77. }
  78. //console.log("word: id="+id)
  79. //console.log("textWait.progresValue="+textWait.progresValue)
  80. } else if( pageImportWords.xmlfile === "" ) {
  81. textWait.text = qsTr("Please, selected xml file for import")
  82. ma.enabled = true
  83. } else if( pageImportWords.selectedCategoryId <= 0 ) {
  84. textWait.text = qsTr("Please, selected category")
  85. ma.enabled = true
  86. } else {
  87. textWait.text = qsTr("Sorry, internal error")
  88. ma.enabled = true
  89. }
  90. }
  91. }
  92. } //Repeater
  93. QueryDialog {
  94. id: dlgExport
  95. titleText: qsTr("Import")
  96. icon: "images/import.png"
  97. message: qsTr( "Import completed successfully" )
  98. onRejected: {
  99. pageStack.pop()
  100. }
  101. }
  102. function showDlgImport() {
  103. dlgExport.open()
  104. //_txtTF.text = ""
  105. }
  106. }