MainPage.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import ConnectivityPlugin 1.0
  7. import "qrc:/common"
  8. Page {
  9. id: root
  10. ListHeading {
  11. id: pageHeading
  12. anchors {
  13. top: parent.top
  14. left: parent.left
  15. right: parent.right
  16. }
  17. z: 2
  18. ListItemText {
  19. anchors.fill: pageHeading.paddingItem
  20. role: "Heading"
  21. text: "Connectivity Plug-in Example"
  22. }
  23. }
  24. Rectangle {
  25. id: mainContainer
  26. height: 300
  27. anchors {
  28. top: pageHeading.bottom
  29. left: parent.left
  30. right: parent.right
  31. }
  32. z: 1
  33. color: "black"
  34. Column {
  35. id: columnContainer
  36. anchors {
  37. fill: parent
  38. margins: 10
  39. }
  40. // Connection type selector
  41. SelectionListItem {
  42. x: -10
  43. title: qsTr("Connection type");
  44. subTitle: {
  45. var retval = "Undefined";
  46. switch (connectionManager.connectionType) {
  47. case ConnectionManager.Bluetooth:
  48. retval = "Bluetooth";
  49. break;
  50. case ConnectionManager.LAN:
  51. retval = "LAN";
  52. break;
  53. }
  54. return retval;
  55. }
  56. onClicked: connTypeSelectionDialog.open();
  57. SelectionDialog {
  58. id: connTypeSelectionDialog
  59. titleText: qsTr("Select connection type");
  60. selectedIndex: -1
  61. model: ListModel {
  62. ListElement { name: "Bluetooth"; }
  63. ListElement { name: "LAN"; }
  64. }
  65. onSelectedIndexChanged: {
  66. console.debug("connTypeSelectionDialog: onSelectedIndexChanged: " + connTypeSelectionDialog.selectedIndex);
  67. connectionManager.connectionType = connTypeSelectionDialog.selectedIndex;
  68. //Here we check if if there are too many ListElement in our ListModel depending on the type of connection.
  69. //Lan connections get the extra Don't Care option.
  70. if (connectionManager.isBluetooth && connAsModel.count > 2) {
  71. if (connAsSelectionDialog.selectedIndex >= 2) {
  72. --connAsSelectionDialog.selectedIndex;
  73. }
  74. connAsModel.remove(connAsModel.count - 1);
  75. } else if (connectionManager.isLAN && connAsModel.count < 3) {
  76. connAsModel.append({name: "Don't care"});
  77. }
  78. }
  79. }
  80. }
  81. // Connect as (client/server) selector
  82. SelectionListItem {
  83. x: -10
  84. title: qsTr("Connect as");
  85. subTitle: {
  86. var retval = "Undefined";
  87. switch (connectionManager.connectAs) {
  88. case ConnectionManager.Client:
  89. retval = "Client";
  90. break;
  91. case ConnectionManager.Server:
  92. retval = "Server";
  93. break;
  94. case ConnectionManager.DontCare:
  95. retval = "Don't care";
  96. }
  97. return retval;
  98. }
  99. onClicked: {
  100. if (connectionManager.isBluetooth &&
  101. connAsModel.count > 2)
  102. {
  103. connAsModel.remove(connAsModel.count - 1);
  104. }
  105. if (connectionManager.isLAN &&
  106. connAsModel.count === 3 &&
  107. connAsModel.get(2).name === "")
  108. {
  109. connAsModel.get(2).name = "Don't care"
  110. }
  111. connAsSelectionDialog.open();
  112. }
  113. SelectionDialog {
  114. id: connAsSelectionDialog
  115. titleText: qsTr("Connect as");
  116. selectedIndex: -1
  117. //On some symbian devices SelectionDialog doesn't resize properly
  118. //so we create enough space for all 3 options.
  119. //This makes the selection dialog look a little silly with
  120. //2 options on some devices but atleast 3rd option is visible.
  121. model: ListModel {
  122. id: connAsModel
  123. ListElement { name: "Client"; }
  124. ListElement { name: "Server"; }
  125. ListElement { name: ""; }
  126. }
  127. onSelectedIndexChanged: {
  128. console.debug("connAsSelectionDialog: onSelectedIndexChanged: " + connAsSelectionDialog.selectedIndex);
  129. connectionManager.connectAs = connAsSelectionDialog.selectedIndex;
  130. }
  131. }
  132. }
  133. // Spacer
  134. Item {
  135. width: parent.width
  136. height: 10
  137. }
  138. Button {
  139. x: (parent.width - width) / 2
  140. width: 250
  141. text: connectionManager.status == ConnectionManager.NotConnected ?
  142. qsTr("Connect") : qsTr("Disconnect");
  143. onClicked: {
  144. if (connectionManager.status == ConnectionManager.NotConnected) {
  145. connectionManager.connect();
  146. }
  147. else {
  148. connectionManager.disconnect();
  149. }
  150. }
  151. }
  152. }
  153. }
  154. StatusInfo {
  155. anchors {
  156. top: mainContainer.bottom
  157. left: parent.left
  158. right: parent.right
  159. bottom: parent.bottom
  160. }
  161. }
  162. CommonDialog {
  163. id: aboutDialog
  164. titleText: "About"
  165. privateCloseIcon: true
  166. onClickedOutside: aboutDialog.close()
  167. content: Item {
  168. height: root.height / 2
  169. width: parent.width
  170. About {
  171. id: cabout
  172. fontSize: 25
  173. anchors.fill: parent
  174. }
  175. ScrollDecorator {
  176. flickableItem: cabout
  177. }
  178. }
  179. }
  180. tools: ToolBarLayout {
  181. ToolButton {
  182. iconSource: "toolbar-back"
  183. onClicked: Qt.quit();
  184. }
  185. ToolButton {
  186. iconSource: Qt.resolvedUrl("start_chat.svg")
  187. opacity: connectionManager.isConnected ? 1.0 : 0.5
  188. enabled: connectionManager.isConnected
  189. onClicked: {
  190. pageStack.push(Qt.resolvedUrl("ChatPage.qml"))
  191. }
  192. }
  193. ToolButton {
  194. iconSource: Qt.resolvedUrl("info.svg")
  195. onClicked: {
  196. aboutDialog.open()
  197. }
  198. }
  199. }
  200. }