main.qml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import meegim 1.0
  4. import "main.js" as Engine
  5. PageStackWindow {
  6. id: main
  7. showStatusBar: false
  8. showToolBar: false
  9. property string loadPage: "RosterPage.qml"
  10. property variant mainViewItem
  11. //property string chatAvatar: "" //аватар для которого открыто окно чата
  12. /* окно редактирование аккаунта */
  13. property string accJid: ""
  14. property string accPass: ""
  15. property string accResource: ""
  16. property string accHost: ""
  17. property string accPort: ""
  18. property bool accManualHostPort: false
  19. property bool accDefault: false
  20. signal statusChanged
  21. property string statStatusText: xmppClient.statusText
  22. signal statusTextChanged
  23. property int orPortrait: PageOrientation.LockPortrait
  24. property int orAuto: PageOrientation.Automatic
  25. property int appOrientation: PageOrientation.LockPortrait
  26. property bool requestMyVCard: false // используется для запроса своей vCard
  27. MyTheme { id: mytheme }
  28. initialPage: MainView {
  29. }
  30. XmppClient {
  31. id: xmppClient
  32. onMessageReceived: {
  33. //console.log("==> QML: a message received: " + bareJidLastMsg)
  34. //при открывании и закрытии окна чата сообщения будут сбрасываться
  35. if( (main.loadPage.indexOf("RosterPage.qml")+1) && (settings.notifyMessage == true) ) {
  36. createInfoPanel( "qrc:/qml/images/msg_recv.png", "Message from \n" + bareJidLastMsg, 3000, "lightblue" )
  37. }
  38. //FIXME: лажа со звуковыми оповещениями
  39. //if( (bareJidLastMsg != xmppClient.myBareJid) && (!(main.loadPage.indexOf("MucPage.qml")+1)) ) {
  40. //console.log("*** "+bareJidLastMsg + "|" + xmppClient.myBareJid + "|" + toBareJid + "|" + fromBareJid )
  41. //if( (xmppClient.myBareJid == toBareJid) && (!(fromBareJid.indexOf("conference")+1)) ) {
  42. if( (xmppClient.myBareJid == toBareJid) && (muc.jidRoom != fromBareJid) )
  43. {
  44. if( !(fromBareJid.indexOf("conference")+1) )
  45. {
  46. notify.notifyMessageRecv()
  47. //console.log("***<<< MESSAGE RECEIVED >>>***")
  48. /*meventfeed.icon = ""
  49. meventfeed.title = "MeegIM"
  50. meventfeed.body = "You have received a message from " + fromBareJid
  51. meventfeed.pushEvent()*/
  52. }
  53. }
  54. }
  55. onTypingChanged: {
  56. //console.log("==> QML: ["+ bareJid +"] is typing: [" + isTyping + "]" )
  57. if( (main.loadPage.indexOf("RosterPage.qml")+1) && (settings.notifyTyping == true) ) {
  58. if( isTyping ) {
  59. createInfoPanel( "qrc:/qml/images/bar_edit.png", bareJid + "\nis typing", 2000, "lightblue" )
  60. } else {
  61. createInfoPanel( "qrc:/qml/images/bar_edit.png", bareJid + "\nhas stopped typing", 2000, "lightblue" )
  62. }
  63. }
  64. }
  65. onConnectingChanged: {
  66. if( (stateConnect == XmppClient.Connecting) && (settings.notifyConnection == true) ) {
  67. createInfoPanel( "qrc:/qml/images/presence-unknown.png", "Connecting...", 1000, "lightblue" )
  68. } else if( (stateConnect == XmppClient.Connected) && (settings.notifyOnline == true) ) {
  69. createInfoPanel( "qrc:/qml/images/presence-online.png", "Online", 3000, "lightgreen" )
  70. } else if( (stateConnect == XmppClient.Disconnected) && (settings.notifyOffline == true) ) {
  71. createInfoPanel( "qrc:/qml/images/presence-offline.png", "Offline", 3000, "gray" )
  72. }
  73. }
  74. onStatusTextChanged: {
  75. console.log( "XmppClient::onStatusTextChanged:" + statusText )
  76. main.statusTextChanged()
  77. }
  78. onStatusChanged: {
  79. console.log( "XmppClient::onStatusChanged:" + status )
  80. main.statusChanged()
  81. }
  82. onVCardChanged: {
  83. xmppVCard.vcard = xmppClient.vcard //это действие перенесено в VCardPage.qml
  84. }
  85. onErrorHappened: {
  86. console.log("QML: Error: " + errorString )
  87. createInfoPanel( "qrc:/qml/images/presence-unknown.png", "Error: "+errorString, 5000, "red" )
  88. }
  89. onPresenceJidChanged:
  90. {
  91. //TODO: Сюда вставлять извещения
  92. if( presenceBareJid != xmppClient.myBareJid ) {
  93. if( presenceTextStatus == "Offline" ) {
  94. notify.notifyBuddyLogsOut()
  95. } else {
  96. notify.notifyBuddyLogsIn()
  97. }
  98. }
  99. //console.log( "QML: XmppClient::onPresenceJidChanged: " +presenceBareJid + " / " + presenceTextStatus + " / " + presencePicStatus )
  100. }
  101. onSubscriptionReceived: {
  102. //console.log( "XmppClient::onSubscriptionReceived: [" + subscriptionJids + "]" )
  103. //createInfoPanel( "", "Subscription received \n from "+bareJid, 5000, "lightblue" )
  104. }
  105. } //XmppClient
  106. MeegIMSettings {
  107. id: settings
  108. }
  109. XmppVCard {
  110. id: xmppVCard
  111. }
  112. MSmiles {
  113. id: mainSmiles
  114. file: settings.smilesTheme
  115. onSmilesModelChanged: {
  116. console.log("QML: MSiles::onSmilesModelChanged: The model was changed.")
  117. }
  118. }
  119. /*------------( Multi user chats )------------*/
  120. property string invRoomJid: ""
  121. property string invInviterJid: ""
  122. property string invMyNickName:""
  123. XmppMuc {
  124. id: muc
  125. mucManager: xmppClient.mucManager
  126. nickName: xmppClient.myBareJid.substring( 0, xmppClient.myBareJid.indexOf('@') )
  127. onInvitationMucReceived: {
  128. invRoomJid = roomJid
  129. invInviterJid = inviterJid
  130. invMyNickName = nickName
  131. notify.notifyMessageRecv()
  132. } //onInvitationMucReceived
  133. onSubjectRoomChanged: {
  134. xmppClient.setMucSubject( muc.jidRoom, subject )
  135. }
  136. onMessageReceived: {
  137. var pos = textMessage.indexOf(":");
  138. if( pos > 0 ) {
  139. var pehapsNickName = textMessage.substring( 0, pos )
  140. if( pehapsNickName == muc.nickName ) {
  141. notify.notifyChatSomeoneSaysMyName()
  142. return
  143. }
  144. }
  145. if( nickName != muc.nickName ) {
  146. notify.notifyChatOthersTalk()
  147. }
  148. }
  149. }
  150. /*------------ ------------*/
  151. Component.onCompleted: {
  152. initAccount()
  153. Engine.clearInfoStack() //очистка стека инфо сообщений
  154. }
  155. property bool _existDefaultAccount: false
  156. function initAccount()
  157. {
  158. _existDefaultAccount = false
  159. for( var j=0; j<settings.accounts.count(); j++ )
  160. {
  161. if( settings.accIsDefault( j ) )
  162. {
  163. _existDefaultAccount = true
  164. xmppClient.myBareJid = settings.accGetJid( j );
  165. xmppClient.myPassword = settings.accGetPassword( j );
  166. xmppClient.resource = settings.accGetResource( j );
  167. if( settings.accIsManuallyHostPort( j ) ) {
  168. xmppClient.host = settings.accGetHost( j );
  169. } else {
  170. xmppClient.host = "";
  171. }
  172. if( settings.accIsManuallyHostPort( j ) ) {
  173. xmppClient.port = settings.accGetPort( j );
  174. } else {
  175. xmppClient.port = 0;
  176. }
  177. console.log("QML: main::initAccount():" + xmppClient.myBareJid + "/" + xmppClient.resource);
  178. break;
  179. }
  180. }
  181. }
  182. /**************( info panels )*************/
  183. Component {
  184. id: infoPanelComponent
  185. TopInfoPanel {
  186. id: infoPanel
  187. onClosed: {
  188. Engine.removeInfoPanel( infoPanel )
  189. }
  190. }
  191. }
  192. function createInfoPanel( icon, message, time_ms, color )
  193. {
  194. Engine.infoMessage( infoPanelComponent, icon, message, time_ms, color )
  195. }
  196. //-----------
  197. /*Component {
  198. id: infoPanelSubcrRecvComponent
  199. TopInfoPanel {
  200. id: subscrRecvPanel
  201. onClicked: {
  202. }
  203. }
  204. }*/
  205. /**************(* notify *)**************/
  206. //property variant notify
  207. Notify {
  208. id: notify
  209. }
  210. /*MEventFeed {
  211. id: meventfeed
  212. }*/
  213. }