meegimsettings.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #include "meegimsettings.h"
  2. #include "MyXmppClient.h"
  3. MeegIMSettings::MeegIMSettings() : MySettings(0)
  4. {
  5. jid_indx0 = "";
  6. pass_indx0 = "";
  7. dflt_indx0 = "";
  8. alm = new AccountsListModel( this );
  9. this->initListOfAccounts();
  10. }
  11. QXmppConfiguration MeegIMSettings::getDefaultAccount()
  12. {
  13. QXmppConfiguration xmppConfig;
  14. //QString passwd("");
  15. QStringList listAcc = getListAccounts();
  16. QStringList::const_iterator itr = listAcc.begin();
  17. while ( itr != listAcc.end() )
  18. {
  19. QString jid = *itr;
  20. itr++;
  21. QString passwd = getPasswd( jid );
  22. QString host = getHost( jid );
  23. int port = getPort( jid );
  24. QString resource = getResource( jid );
  25. bool isDefault = isAccDefault( jid );
  26. if( isDefault ) {
  27. //MyXmppClient::myPass = passwd;
  28. //MyXmppClient::myJid = jid;
  29. xmppConfig.setJid( jid );
  30. xmppConfig.setPassword( passwd );
  31. if( !resource.isEmpty() ) {
  32. xmppConfig.setResource( resource );
  33. }
  34. if( !host.isEmpty() ) {
  35. xmppConfig.setHost( host );
  36. }
  37. if( port > 0 ) {
  38. xmppConfig.setPort( port );
  39. }
  40. return xmppConfig;
  41. }
  42. }
  43. return xmppConfig;
  44. }
  45. void MeegIMSettings::initListOfAccounts() //Q_INVOKABLE
  46. {
  47. QStringList listAcc = getListAccounts();
  48. alm->removeRows( 0, alm->count() );
  49. QStringList::const_iterator itr = listAcc.begin();
  50. int i = 0;
  51. while ( itr != listAcc.end() )
  52. {
  53. QString jid = *itr;
  54. itr++;
  55. QString passwd = getPasswd( jid );
  56. QString icon = "qrc:/qml/images/accXMPP.png";
  57. bool isDefault = isAccDefault( jid );
  58. QString type = "xmpp";
  59. QString host = getHost( jid );
  60. int port = getPort( jid );
  61. QString resource = getResource( jid );
  62. bool isManuallyHostPort = isHostPortManually( jid );
  63. AccountsItemModel *aim = new AccountsItemModel( jid, passwd, icon, type, resource, host, port, isDefault, isManuallyHostPort, this );
  64. alm->append(aim);
  65. if(i==0) {
  66. jid_indx0 = jid;
  67. pass_indx0 = passwd;
  68. dflt_indx0 = isDefault;
  69. }
  70. i++;
  71. }
  72. emit accountsListChanged();
  73. }
  74. void MeegIMSettings::setAccount(
  75. QString _jid,
  76. QString _pass,
  77. bool _isDflt,
  78. QString _resource,
  79. QString _host,
  80. QString _port,
  81. bool manuallyHostPort) //Q_INVOKABLE
  82. {
  83. this->addAccount( _jid );
  84. this->setPasswd( _jid, _pass );
  85. this->setAccDefault( _jid, _isDflt );
  86. this->setResource( _jid, _resource );
  87. this->setHost( _jid, _host );
  88. this->setHostPortManually( _jid, manuallyHostPort );
  89. bool ok = false;
  90. int p = _port.toInt(&ok);
  91. if( ok ) {
  92. this->setPort( _jid, p );
  93. }
  94. this->getDefaultAccount();
  95. }
  96. void MeegIMSettings::removeAccount( QString _jid ) //Q_INVOKABLE
  97. {
  98. this->remAccount( _jid );
  99. this->remove( _jid );
  100. }
  101. bool MeegIMSettings::accIsDefault(int index)
  102. {
  103. bool val = false;
  104. if( (index>=0) and (index<alm->count()) ) {
  105. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  106. val = aim->isDefault();
  107. }
  108. return val;
  109. }
  110. QString MeegIMSettings::accGetJid(int index)
  111. {
  112. QString val = "";
  113. if( (index>=0) and (index<alm->count()) ) {
  114. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  115. val = aim->jid();
  116. }
  117. return val;
  118. }
  119. QString MeegIMSettings::accGetPassword(int index)
  120. {
  121. QString val = "";
  122. if( (index>=0) and (index<alm->count()) ) {
  123. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  124. val = aim->passwd();
  125. }
  126. return val;
  127. }
  128. QString MeegIMSettings::accGetResource(int index)
  129. {
  130. QString val = "";
  131. if( (index>=0) and (index<alm->count()) ) {
  132. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  133. val = aim->resource();
  134. }
  135. return val;
  136. }
  137. QString MeegIMSettings::accGetHost(int index)
  138. {
  139. QString val = "";
  140. if( (index>=0) and (index<alm->count()) ) {
  141. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  142. val = aim->host();
  143. }
  144. return val;
  145. }
  146. int MeegIMSettings::accGetPort(int index)
  147. {
  148. int val = 0;
  149. if( (index>=0) and (index<alm->count()) ) {
  150. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  151. val = aim->port();
  152. }
  153. return val;
  154. }
  155. bool MeegIMSettings::accIsManuallyHostPort(int index)
  156. {
  157. bool val = false;
  158. if( (index>=0) and (index<alm->count()) ) {
  159. AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
  160. val = aim->isManuallyHostPort();
  161. }
  162. return val;
  163. }
  164. void MeegIMSettings::saveStatusText(QString statusText)
  165. {
  166. if( statusText != this->getStatusText() )
  167. {
  168. this->setStatusText( statusText );
  169. }
  170. }
  171. void MeegIMSettings::setSoundIncomingMessage( const QString &filePath )
  172. {
  173. if( filePath != this->getSndIncomingMsg() )
  174. {
  175. this->setSndIncomingMsg( filePath );
  176. emit soundIncomingMessageChanged();
  177. }
  178. }
  179. void MeegIMSettings::setSoundOutcomingMessage( const QString &filePath )
  180. {
  181. if( filePath != this->getSndOutcomingMsg() )
  182. {
  183. this->setSndOutcomingMsg( filePath );
  184. emit soundOutcomingMessageChanged();
  185. }
  186. }
  187. void MeegIMSettings::_setNotifyConnection(bool isSet)
  188. {
  189. if( isSet != this->notifyConnection() )
  190. {
  191. this->setNotifyConnection(isSet);
  192. emit notifyConnectionChanged();
  193. }
  194. }
  195. void MeegIMSettings::_setNotifyOnline(bool isSet)
  196. {
  197. if( isSet != this->notifyOnline() )
  198. {
  199. this->setNotifyOnline(isSet);
  200. emit notifyOnlineChanged();
  201. }
  202. }
  203. void MeegIMSettings::_setNotifyOffline(bool isSet)
  204. {
  205. if( isSet != this->notifyOffline() )
  206. {
  207. this->setNotifyOffline(isSet);
  208. emit notifyOfflineChanged();
  209. }
  210. }
  211. void MeegIMSettings::_setNotifyMessage(bool isSet)
  212. {
  213. if( isSet != this->notifyMessage() )
  214. {
  215. this->setNotifyMessage(isSet);
  216. emit notifyMessageChanged();
  217. }
  218. }
  219. void MeegIMSettings::_setNotifyTyping(bool isSet)
  220. {
  221. if( isSet != this->notifyTyping() )
  222. {
  223. this->setNotifyTyping(isSet);
  224. emit notifyTypingChanged();
  225. }
  226. }
  227. void MeegIMSettings::setSoundBuddyLogsIn( const QString &filePath )
  228. {
  229. if( filePath != this->getSndBuddyLogsIn() )
  230. {
  231. this->setSndBuddyLogsIn( filePath );
  232. emit soundBuddyLogsInChanged();
  233. }
  234. }
  235. void MeegIMSettings::setSoundBuddyLogsOut( const QString &filePath )
  236. {
  237. if( filePath != this->getSndBuddyLogsOut() )
  238. {
  239. this->setSndBuddyLogsOut( filePath );
  240. emit soundBuddyLogsOutChanged();
  241. }
  242. }
  243. void MeegIMSettings::_setReconnectWhenError(bool arg)
  244. {
  245. if (this->reconnectWhenError() != arg) {
  246. this->setReconnectWhenError( arg );
  247. emit reconnectWhenErrorChanged();
  248. }
  249. }
  250. void MeegIMSettings::_setKeepAliveInterval(int arg)
  251. {
  252. if (this->keepAliveInterval() != arg) {
  253. this->setKeepAliveInterval( arg );
  254. emit keepAliveIntervalChanged();
  255. }
  256. }
  257. void MeegIMSettings::setChatSomeoneSaysMyName( const QString &filePath )
  258. {
  259. if( filePath != this->getSndChatSaysMyName() )
  260. {
  261. this->setSndChatSaysMyName( filePath );
  262. emit soundChatSomeoneSaysMyNameChanged();
  263. }
  264. }
  265. void MeegIMSettings::setChatPersonEnters( const QString &filePath )
  266. {
  267. if( filePath != this->getSndChatPersonEnters() )
  268. {
  269. this->setSndChatPersonEnters( filePath );
  270. emit soundChatPersonEntersChanged();
  271. }
  272. }
  273. void MeegIMSettings::setChatPersonLeaves( const QString &filePath )
  274. {
  275. if( filePath != this->getSndChatPersonLeaves() )
  276. {
  277. this->setSndChatPersonLeaves( filePath );
  278. emit soundChatPersonLeavesChanged();
  279. }
  280. }
  281. void MeegIMSettings::setChatITalk( const QString &filePath )
  282. {
  283. if( filePath != this->getSndChatITalk() )
  284. {
  285. this->setSndChatITalk( filePath );
  286. emit soundChatITalkChanged();
  287. }
  288. }
  289. void MeegIMSettings::setChatOthersTalk( const QString &filePath )
  290. {
  291. if( filePath != this->getSndChatOthersTalk() )
  292. {
  293. this->setSndChatOthersTalk( filePath );
  294. emit soundChatOthersTalkChanged();
  295. }
  296. }