ImportWordPage.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import "Logic.js" as Logic
  4. Page {
  5. id: pageImportWords
  6. property int selectedCategoryId: 0
  7. property string xmlfile: ""
  8. //property QtObject _txtTF
  9. tools: ToolBarLayout {
  10. id: tool_only_back
  11. opacity: userTheme.opacityToolbar
  12. ToolIcon {
  13. id: toolIconBack
  14. //iconId: "toolbar-back"
  15. iconSource: "images/toolbar/back.png"
  16. onClicked: {
  17. pageStack.pop();
  18. }
  19. }
  20. } //ToolBarLayout
  21. QNMTitle {
  22. id: titlePage
  23. text: qsTr("Import of words")
  24. image: "images/import.png"
  25. busy: false
  26. }
  27. BackgroundPage { }
  28. Flickable {
  29. id: flickArea
  30. anchors {
  31. top: titlePage.bottom
  32. bottom: parent.bottom
  33. left: parent.left
  34. right: parent.right
  35. topMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 5 : 15
  36. leftMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 40 : 20
  37. rightMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 40 : 20
  38. bottomMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 5 : 15
  39. }
  40. flickableDirection: Flickable.VerticalFlick
  41. width: parent.width
  42. height: parent.height
  43. contentWidth: contentFlickArea.width
  44. contentHeight: contentFlickArea.height
  45. clip: true
  46. Column {
  47. id: contentFlickArea
  48. width: parent.width
  49. spacing: 20
  50. Text {
  51. text: qsTr("Category")
  52. font.pixelSize: 30
  53. }
  54. MyButton {
  55. id: categorySelectButton
  56. iconSource: "images/categories_icon.png"
  57. text: qsTr("List of categories")
  58. fontSize: 24
  59. height: 100
  60. width: flickArea.width
  61. onClicked: {
  62. dlgSelectCategory.open()
  63. }
  64. }
  65. Item {
  66. height: (screen.orientationString == "Portrait") || (screen.orientationString == "PortraitInverted") ? 20 : 5
  67. width:flickArea.width
  68. }
  69. Text {
  70. text: qsTr("XML file")
  71. font.pixelSize: 30
  72. }
  73. Row {
  74. TextField {
  75. id: tfXmlFile
  76. text: pageImportWords.xmlfile
  77. height: 70
  78. width: flickArea.width - btBrowse.width
  79. anchors.verticalCenter: parent.verticalCenter
  80. onTextChanged: {
  81. pageImportWords.xmlfile = tfXmlFile.text
  82. var res = cppMeeWords.checkFile( tfXmlFile.text )
  83. if (res) {
  84. btImport.enabled = true
  85. } else {
  86. btImport.enabled = false
  87. }
  88. }
  89. /*Component.onCompleted: {
  90. _txtTF = tfXmlFile
  91. }*/
  92. }
  93. MyButton {
  94. id: btBrowse
  95. width: 80
  96. height: 70
  97. anchors.verticalCenter: parent.verticalCenter
  98. iconSource: "images/folder_docs.png"
  99. indicator: false
  100. isGlow: false
  101. onClicked: {
  102. Logic.openFile("FileListView.qml")
  103. }
  104. }
  105. }
  106. Item {
  107. height: (screen.orientationString == "Portrait") || (screen.orientationString == "PortraitInverted") ? 20 : 5
  108. width:flickArea.width
  109. }
  110. MyButton {
  111. id: btImport
  112. height: 100
  113. width: flickArea.width
  114. text: qsTr("Start the import")
  115. iconSource: "images/import.png"
  116. onClicked: {
  117. createImport()
  118. }
  119. enabled: false
  120. }
  121. MyButton {
  122. id: btHelp
  123. height: 100
  124. width: flickArea.width
  125. text: qsTr("Help")
  126. //iconSource: "image://theme/icon-l-user-guide"
  127. iconSource: "images/info.png"
  128. onClicked: {
  129. Logic.openFile("ImportHelp.qml")
  130. }
  131. }
  132. }
  133. } //Flickable
  134. /*******************************************************************************/
  135. function createImport() {
  136. var component = Qt.createComponent( "ImportWords.qml" );
  137. if ( component.status == Component.Ready ) {
  138. finishCreation( component );
  139. } else {
  140. component.statusChanged.connect( finishCreation );
  141. }
  142. }
  143. function finishCreation( component ) {
  144. if (component.status == Component.Ready) {
  145. var sprite = component.createObject(pageImportWords, { });
  146. if (sprite == null) {
  147. // Error Handling
  148. console.log("Error creating object");
  149. }
  150. } else if (component.status == Component.Error) {
  151. // Error Handling
  152. console.log("Error loading component:", component.errorString());
  153. }
  154. }
  155. function getAllCategories () {
  156. titlePage.busy = false
  157. categorySelectButton.enabled = false
  158. var db = Logic.getDatabase()
  159. listModelCategory.clear()
  160. db.transaction( function(tx) {
  161. var res = tx.executeSql( "SELECT id,category FROM categories" )
  162. for(var i = 0; i<=res.rows.length-1; i++) {
  163. categorySelectButton.enabled = true
  164. var _id = res.rows.item(i).id;
  165. var nameCategory = res.rows.item(i).category;
  166. //var descrCategory = res.rows.item(i).description;
  167. listModelCategory.append( { name: nameCategory, category_id: _id } );
  168. }
  169. }
  170. )
  171. /* установка значение для первого элемента */
  172. titlePage.busy = false
  173. }
  174. /*******************************************************************************/
  175. ListModel {
  176. id: listModelCategory
  177. Component.onCompleted: {
  178. getAllCategories()
  179. }
  180. }
  181. SelectionDialog {
  182. id: dlgSelectCategory
  183. titleText: qsTr("Select category")
  184. model: listModelCategory
  185. onSelectedIndexChanged: {
  186. var j = selectedIndex
  187. pageImportWords.selectedCategoryId = listModelCategory.get(j).category_id
  188. var nc = listModelCategory.get(j).name
  189. categorySelectButton.text = nc
  190. }
  191. }
  192. }