123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #include "meegimsettings.h"
- #include "MyXmppClient.h"
- MeegIMSettings::MeegIMSettings() : MySettings(0)
- {
- jid_indx0 = "";
- pass_indx0 = "";
- dflt_indx0 = "";
- alm = new AccountsListModel( this );
- this->initListOfAccounts();
- }
- QXmppConfiguration MeegIMSettings::getDefaultAccount()
- {
- QXmppConfiguration xmppConfig;
- //QString passwd("");
- QStringList listAcc = getListAccounts();
- QStringList::const_iterator itr = listAcc.begin();
- while ( itr != listAcc.end() )
- {
- QString jid = *itr;
- itr++;
- QString passwd = getPasswd( jid );
- QString host = getHost( jid );
- int port = getPort( jid );
- QString resource = getResource( jid );
- bool isDefault = isAccDefault( jid );
- if( isDefault ) {
- //MyXmppClient::myPass = passwd;
- //MyXmppClient::myJid = jid;
- xmppConfig.setJid( jid );
- xmppConfig.setPassword( passwd );
- if( !resource.isEmpty() ) {
- xmppConfig.setResource( resource );
- }
- if( !host.isEmpty() ) {
- xmppConfig.setHost( host );
- }
- if( port > 0 ) {
- xmppConfig.setPort( port );
- }
- return xmppConfig;
- }
- }
- return xmppConfig;
- }
- void MeegIMSettings::initListOfAccounts() //Q_INVOKABLE
- {
- QStringList listAcc = getListAccounts();
- alm->removeRows( 0, alm->count() );
- QStringList::const_iterator itr = listAcc.begin();
- int i = 0;
- while ( itr != listAcc.end() )
- {
- QString jid = *itr;
- itr++;
- QString passwd = getPasswd( jid );
- QString icon = "qrc:/qml/images/accXMPP.png";
- bool isDefault = isAccDefault( jid );
- QString type = "xmpp";
- QString host = getHost( jid );
- int port = getPort( jid );
- QString resource = getResource( jid );
- bool isManuallyHostPort = isHostPortManually( jid );
- AccountsItemModel *aim = new AccountsItemModel( jid, passwd, icon, type, resource, host, port, isDefault, isManuallyHostPort, this );
- alm->append(aim);
- if(i==0) {
- jid_indx0 = jid;
- pass_indx0 = passwd;
- dflt_indx0 = isDefault;
- }
- i++;
- }
- emit accountsListChanged();
- }
- void MeegIMSettings::setAccount(
- QString _jid,
- QString _pass,
- bool _isDflt,
- QString _resource,
- QString _host,
- QString _port,
- bool manuallyHostPort) //Q_INVOKABLE
- {
- this->addAccount( _jid );
- this->setPasswd( _jid, _pass );
- this->setAccDefault( _jid, _isDflt );
- this->setResource( _jid, _resource );
- this->setHost( _jid, _host );
- this->setHostPortManually( _jid, manuallyHostPort );
- bool ok = false;
- int p = _port.toInt(&ok);
- if( ok ) {
- this->setPort( _jid, p );
- }
- this->getDefaultAccount();
- }
- void MeegIMSettings::removeAccount( QString _jid ) //Q_INVOKABLE
- {
- this->remAccount( _jid );
- this->remove( _jid );
- }
- bool MeegIMSettings::accIsDefault(int index)
- {
- bool val = false;
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->isDefault();
- }
- return val;
- }
- QString MeegIMSettings::accGetJid(int index)
- {
- QString val = "";
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->jid();
- }
- return val;
- }
- QString MeegIMSettings::accGetPassword(int index)
- {
- QString val = "";
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->passwd();
- }
- return val;
- }
- QString MeegIMSettings::accGetResource(int index)
- {
- QString val = "";
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->resource();
- }
- return val;
- }
- QString MeegIMSettings::accGetHost(int index)
- {
- QString val = "";
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->host();
- }
- return val;
- }
- int MeegIMSettings::accGetPort(int index)
- {
- int val = 0;
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->port();
- }
- return val;
- }
- bool MeegIMSettings::accIsManuallyHostPort(int index)
- {
- bool val = false;
- if( (index>=0) and (index<alm->count()) ) {
- AccountsItemModel *aim = reinterpret_cast<AccountsItemModel*>( alm->value( index ) );
- val = aim->isManuallyHostPort();
- }
- return val;
- }
- void MeegIMSettings::saveStatusText(QString statusText)
- {
- if( statusText != this->getStatusText() )
- {
- this->setStatusText( statusText );
- }
- }
- void MeegIMSettings::setSoundIncomingMessage( const QString &filePath )
- {
- if( filePath != this->getSndIncomingMsg() )
- {
- this->setSndIncomingMsg( filePath );
- emit soundIncomingMessageChanged();
- }
- }
- void MeegIMSettings::setSoundOutcomingMessage( const QString &filePath )
- {
- if( filePath != this->getSndOutcomingMsg() )
- {
- this->setSndOutcomingMsg( filePath );
- emit soundOutcomingMessageChanged();
- }
- }
- void MeegIMSettings::_setNotifyConnection(bool isSet)
- {
- if( isSet != this->notifyConnection() )
- {
- this->setNotifyConnection(isSet);
- emit notifyConnectionChanged();
- }
- }
- void MeegIMSettings::_setNotifyOnline(bool isSet)
- {
- if( isSet != this->notifyOnline() )
- {
- this->setNotifyOnline(isSet);
- emit notifyOnlineChanged();
- }
- }
- void MeegIMSettings::_setNotifyOffline(bool isSet)
- {
- if( isSet != this->notifyOffline() )
- {
- this->setNotifyOffline(isSet);
- emit notifyOfflineChanged();
- }
- }
- void MeegIMSettings::_setNotifyMessage(bool isSet)
- {
- if( isSet != this->notifyMessage() )
- {
- this->setNotifyMessage(isSet);
- emit notifyMessageChanged();
- }
- }
- void MeegIMSettings::_setNotifyTyping(bool isSet)
- {
- if( isSet != this->notifyTyping() )
- {
- this->setNotifyTyping(isSet);
- emit notifyTypingChanged();
- }
- }
- void MeegIMSettings::setSoundBuddyLogsIn( const QString &filePath )
- {
- if( filePath != this->getSndBuddyLogsIn() )
- {
- this->setSndBuddyLogsIn( filePath );
- emit soundBuddyLogsInChanged();
- }
- }
- void MeegIMSettings::setSoundBuddyLogsOut( const QString &filePath )
- {
- if( filePath != this->getSndBuddyLogsOut() )
- {
- this->setSndBuddyLogsOut( filePath );
- emit soundBuddyLogsOutChanged();
- }
- }
- void MeegIMSettings::_setReconnectWhenError(bool arg)
- {
- if (this->reconnectWhenError() != arg) {
- this->setReconnectWhenError( arg );
- emit reconnectWhenErrorChanged();
- }
- }
- void MeegIMSettings::_setKeepAliveInterval(int arg)
- {
- if (this->keepAliveInterval() != arg) {
- this->setKeepAliveInterval( arg );
- emit keepAliveIntervalChanged();
- }
- }
- void MeegIMSettings::setChatSomeoneSaysMyName( const QString &filePath )
- {
- if( filePath != this->getSndChatSaysMyName() )
- {
- this->setSndChatSaysMyName( filePath );
- emit soundChatSomeoneSaysMyNameChanged();
- }
- }
- void MeegIMSettings::setChatPersonEnters( const QString &filePath )
- {
- if( filePath != this->getSndChatPersonEnters() )
- {
- this->setSndChatPersonEnters( filePath );
- emit soundChatPersonEntersChanged();
- }
- }
- void MeegIMSettings::setChatPersonLeaves( const QString &filePath )
- {
- if( filePath != this->getSndChatPersonLeaves() )
- {
- this->setSndChatPersonLeaves( filePath );
- emit soundChatPersonLeavesChanged();
- }
- }
- void MeegIMSettings::setChatITalk( const QString &filePath )
- {
- if( filePath != this->getSndChatITalk() )
- {
- this->setSndChatITalk( filePath );
- emit soundChatITalkChanged();
- }
- }
- void MeegIMSettings::setChatOthersTalk( const QString &filePath )
- {
- if( filePath != this->getSndChatOthersTalk() )
- {
- this->setSndChatOthersTalk( filePath );
- emit soundChatOthersTalkChanged();
- }
- }
|