AuthenticationSheet.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Róbert Márki
  4. **
  5. ** This file is part of Web Feeds.
  6. **
  7. ** Web Feeds is free software: you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation, either version 3 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** Web Feeds is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with Web Feeds. If not, see <http://www.gnu.org/licenses/>.
  19. ****************************************************************************/
  20. import QtQuick 1.1
  21. import com.nokia.meego 1.0
  22. import com.nokia.extras 1.1
  23. import WebFeeds 1.0
  24. import GoogleReader 1.0
  25. import "../../../../shared/qml" as Shared
  26. import "../../../../shared/qml/UIConstants.js" as UIConstants
  27. Shared.CommonSheet {
  28. id: root
  29. property variant service
  30. property bool authenticationDataValid: false
  31. acceptButtonText: qsTr("Sign in")
  32. rejectButtonText: qsTr("Cancel")
  33. title: root.service ? root.service.serviceName() : "";
  34. busyText: qsTr("Checking")
  35. iconSource: root.service ? root.service.serviceImageUrl() : "";
  36. Connections {
  37. target: root.service
  38. onAccountVerificationComplete: root.onAccountVerificationComplete(result)
  39. }
  40. function updateAcceptButtonStatus() {
  41. if(root.service) {
  42. root.acceptButton.enabled
  43. = ((userNameField.text.length > 0) && (passwordField.text.length > 0));
  44. }
  45. }
  46. function onAccountVerificationComplete(result) {
  47. if(result == GoogleReaderEnum.ErrNoError) {
  48. root.authenticationDataValid = true;
  49. root.close();
  50. return;
  51. } else if(result == GoogleReaderEnum.ErrAborted) {
  52. root.close();
  53. return;
  54. }
  55. root.busy = false;
  56. if(result == GoogleReaderEnum.ErrInvalidAccount) {
  57. root.showMessage(qsTr("Wrong username or password"));
  58. }
  59. else if(result == GoogleReaderEnum.ErrAborted) {
  60. root.close();
  61. }
  62. else if(result == GoogleReaderEnum.ErrNetworkError) {
  63. root.showMessage(qsTr("Network error"));
  64. }
  65. }
  66. onAccepted: {
  67. root.busy = true;
  68. root.open();
  69. root.service.verifyAuthenticationData(userNameField.text, passwordField.text);
  70. }
  71. onRejected: {
  72. if(root.busy)
  73. {
  74. root.open();
  75. root.service.abortVerification();
  76. }
  77. }
  78. onStatusChanged: {
  79. if((root.status == DialogStatus.Closed)
  80. && root.authenticationDataValid)
  81. root.service.setAuthenticationData(userNameField.text, passwordField.text);
  82. }
  83. contentItem: Column {
  84. id: dataEntryItem
  85. anchors.fill: parent
  86. anchors.leftMargin: UIConstants.DEFAULT_MARGIN
  87. anchors.rightMargin: UIConstants.DEFAULT_MARGIN
  88. spacing: UIConstants.DEFAULT_HALF_MARGIN
  89. Column {
  90. width: parent.width
  91. Label {
  92. text: qsTr("Username")
  93. font.family: UIConstants.FONT_FAMILY_LIGHT
  94. }
  95. Shared.TextField {
  96. id: userNameField
  97. width: parent.width
  98. inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase | Qt.ImhEmailCharactersOnly
  99. onTextChanged: {
  100. root.updateAcceptButtonStatus();
  101. }
  102. platformSipAttributes: SipAttributes {
  103. actionKeyEnabled: root.acceptButton.enabled
  104. actionKeyLabel: root.acceptButtonText
  105. actionKeyHighlighted: true
  106. }
  107. Keys.onReturnPressed: {
  108. if(root.acceptButton.enabled)
  109. root.accept();
  110. }
  111. }
  112. }
  113. Column {
  114. width: parent.width
  115. Label {
  116. text: qsTr("Password")
  117. font.family: UIConstants.FONT_FAMILY_LIGHT
  118. }
  119. Shared.TextField {
  120. id: passwordField
  121. width: parent.width
  122. echoMode: TextInput.Password
  123. inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
  124. onTextChanged: {
  125. root.updateAcceptButtonStatus();
  126. }
  127. platformSipAttributes: SipAttributes {
  128. actionKeyEnabled: root.acceptButton.enabled
  129. actionKeyLabel: root.acceptButtonText
  130. actionKeyHighlighted: true
  131. }
  132. Keys.onReturnPressed: {
  133. if(root.acceptButton.enabled)
  134. root.accept();
  135. }
  136. }
  137. }
  138. Column {
  139. width: parent.width
  140. spacing: UIConstants.DEFAULT_MARGIN
  141. Label {
  142. anchors.horizontalCenter: parent.horizontalCenter
  143. text: qsTr("Don't have an account yet?")
  144. }
  145. Label {
  146. anchors.horizontalCenter: parent.horizontalCenter
  147. text: '<a href="https://accounts.google.com/NewAccount?service=reader">Get new account here</a>'
  148. font.bold: true
  149. onLinkActivated: Qt.openUrlExternally(link)
  150. }
  151. }
  152. Connections {
  153. target: root
  154. onStatusChanged: {
  155. if(root.status == DialogStatus.Open) {
  156. userNameField.forceActiveFocus();
  157. userNameField.platformOpenSoftwareInputPanel();
  158. }
  159. }
  160. }
  161. }
  162. }