@ -30,7 +30,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
config ( ) ,
presence ( ) ,
state ( Shared : : ConnectionState : : disconnected ) ,
groups ( ) ,
cm ( new QXmppCarbonManager ( ) ) ,
am ( new QXmppMamManager ( ) ) ,
mm ( new QXmppMucManager ( ) ) ,
@ -40,20 +39,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
um ( new QXmppUploadRequestManager ( ) ) ,
dm ( client . findExtension < QXmppDiscoveryManager > ( ) ) ,
rcpm ( new QXmppMessageReceiptManager ( ) ) ,
contacts ( ) ,
conferences ( ) ,
reconnectScheduled ( false ) ,
reconnectTimer ( new QTimer ) ,
queuedContacts ( ) ,
outOfRosterContacts ( ) ,
pendingMessages ( ) ,
uploadingSlotsQueue ( ) ,
avatarHash ( ) ,
avatarType ( ) ,
ownVCardRequestInProgress ( false ) ,
network ( p_net ) ,
passwordType ( Shared : : AccountPassword : : plain ) ,
mh ( new MessageHandler ( this ) )
mh ( new MessageHandler ( this ) ) ,
rh ( new RosterHandler ( this ) )
{
config . setUser ( p_login ) ;
config . setDomain ( p_server ) ;
@ -66,12 +60,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
QObject : : connect ( & client , & QXmppClient : : messageReceived , mh , & MessageHandler : : onMessageReceived ) ;
QObject : : connect ( & client , & QXmppClient : : error , this , & Account : : onClientError ) ;
QObject : : connect ( rm , & QXmppRosterManager : : rosterReceived , this , & Account : : onRosterReceived ) ;
QObject : : connect ( rm , & QXmppRosterManager : : itemAdded , this , & Account : : onRosterItemAdded ) ;
QObject : : connect ( rm , & QXmppRosterManager : : itemRemoved , this , & Account : : onRosterItemRemoved ) ;
QObject : : connect ( rm , & QXmppRosterManager : : itemChanged , this , & Account : : onRosterItemChanged ) ;
//QObject::connect(&rm, &QXmppRosterManager::presenceChanged, this, &Account::onRosterPresenceChanged);
client . addExtension ( cm ) ;
QObject : : connect ( cm , & QXmppCarbonManager : : messageReceived , mh , & MessageHandler : : onCarbonMessageReceived ) ;
@ -84,10 +72,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
QObject : : connect ( am , & QXmppMamManager : : resultsRecieved , this , & Account : : onMamResultsReceived ) ;
client . addExtension ( mm ) ;
QObject : : connect ( mm , & QXmppMucManager : : roomAdded , this , & Account : : onMucRoomAdded ) ;
client . addExtension ( bm ) ;
QObject : : connect ( bm , & QXmppBookmarkManager : : bookmarksReceived , this , & Account : : bookmarksReceived ) ;
QObject : : connect ( vm , & QXmppVCardManager : : vCardReceived , this , & Account : : onVCardReceived ) ;
//QObject::connect(&vm, &QXmppVCardManager::clientVCardReceived, this, &Account::onOwnVCardReceived); //for some reason it doesn't work, launching from common handler
@ -173,13 +158,8 @@ Account::~Account()
QObject : : disconnect ( network , & NetworkAccess : : uploadFileComplete , mh , & MessageHandler : : onFileUploaded ) ;
QObject : : disconnect ( network , & NetworkAccess : : uploadFileError , mh , & MessageHandler : : onFileUploadError ) ;
for ( std : : map < QString , Contact * > : : const_iterator itr = contacts . begin ( ) , end = contacts . end ( ) ; itr ! = end ; + + itr ) {
delete itr - > second ;
}
for ( std : : map < QString , Conference * > : : const_iterator itr = conferences . begin ( ) , end = conferences . end ( ) ; itr ! = end ; + + itr ) {
delete itr - > second ;
}
delete mh ;
delete rh ;
delete reconnectTimer ;
delete rcpm ;
@ -213,7 +193,7 @@ void Core::Account::disconnect()
reconnectTimer - > stop ( ) ;
}
if ( state ! = Shared : : ConnectionState : : disconnected ) {
clearConferences ( ) ;
rh - > clearConferences ( ) ;
client . disconnectFromServer ( ) ;
}
}
@ -271,178 +251,60 @@ void Core::Account::reconnect()
}
}
QString Core : : Account : : getName ( ) const
{
return name ;
}
QString Core : : Account : : getName ( ) const {
return name ; }
QString Core : : Account : : getLogin ( ) const
{
return config . user ( ) ;
}
QString Core : : Account : : getLogin ( ) const {
return config . user ( ) ; }
QString Core : : Account : : getPassword ( ) const
{
return config . password ( ) ;
}
QString Core : : Account : : getPassword ( ) const {
return config . password ( ) ; }
QString Core : : Account : : getServer ( ) const
{
return config . domain ( ) ;
}
QString Core : : Account : : getServer ( ) const {
return config . domain ( ) ; }
Shared : : AccountPassword Core : : Account : : getPasswordType ( ) const
{
return passwordType ;
}
Shared : : AccountPassword Core : : Account : : getPasswordType ( ) const {
return passwordType ; }
void Core : : Account : : onRosterReceived ( )
{
vm - > requestClientVCard ( ) ; //TODO need to make sure server actually supports vCards
ownVCardRequestInProgress = true ;
QStringList bj = rm - > getRosterBareJids ( ) ;
for ( int i = 0 ; i < bj . size ( ) ; + + i ) {
const QString & jid = bj [ i ] ;
addedAccount ( jid ) ;
}
}
void Core : : Account : : setPasswordType ( Shared : : AccountPassword pt ) {
passwordType = pt ; }
void Core : : Account : : onRosterItemAdded ( const QString & bareJid )
{
addedAccount ( bareJid ) ;
std : : map < QString , QString > : : const_iterator itr = queuedContacts . find ( bareJid ) ;
if ( itr ! = queuedContacts . end ( ) ) {
rm - > subscribe ( bareJid , itr - > second ) ;
queuedContacts . erase ( itr ) ;
}
}
void Core : : Account : : setLogin ( const QString & p_login ) {
config . setUser ( p_login ) ; }
void Core : : Account : : setPasswordType ( Shared : : AccountPassword pt )
{
passwordType = pt ;
}
void Core : : Account : : setName ( const QString & p_name ) {
name = p_name ; }
void Core : : Account : : onRosterItemChanged ( const QString & bareJid )
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( bareJid ) ;
if ( itr = = contacts . end ( ) ) {
qDebug ( ) < < " An attempt to change non existing contact " < < bareJid < < " from account " < < name < < " , skipping " ;
return ;
}
Contact * contact = itr - > second ;
QXmppRosterIq : : Item re = rm - > getRosterEntry ( bareJid ) ;
Shared : : SubscriptionState state = castSubscriptionState ( re . subscriptionType ( ) ) ;
void Core : : Account : : setPassword ( const QString & p_password ) {
config . setPassword ( p_password ) ; }
contact - > setGroups ( re . groups ( ) ) ;
contact - > setSubscriptionState ( state ) ;
contact - > setName ( re . name ( ) ) ;
}
void Core : : Account : : setServer ( const QString & p_server ) {
config . setDomain ( p_server ) ; }
void Core : : Account : : onRosterItemRemoved ( const QString & bareJid )
Shared : : Availability Core : : Account : : getAvailability ( ) const
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( bareJid ) ;
if ( itr = = contacts . end ( ) ) {
qDebug ( ) < < " An attempt to remove non existing contact " < < bareJid < < " from account " < < name < < " , skipping " ;
return ;
}
Contact * contact = itr - > second ;
contacts . erase ( itr ) ;
QSet < QString > cGroups = contact - > getGroups ( ) ;
for ( QSet < QString > : : const_iterator itr = cGroups . begin ( ) , end = cGroups . end ( ) ; itr ! = end ; + + itr ) {
removeFromGroup ( bareJid , * itr ) ;
if ( state = = Shared : : ConnectionState : : connected ) {
QXmppPresence : : AvailableStatusType pres = presence . availableStatusType ( ) ;
return static_cast < Shared : : Availability > ( pres ) ; //they are compatible;
} else {
return Shared : : Availability : : offline ;
}
emit removeContact ( bareJid ) ;
contact - > deleteLater ( ) ;
}
void Core : : Account : : addedAccount ( const QString & jid )
void Core : : Account : : setAvailability ( Shared : : Availability avail )
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( jid ) ;
QXmppRosterIq : : Item re = rm - > getRosterEntry ( jid ) ;
Contact * contact ;
bool newContact = false ;
if ( itr = = contacts . end ( ) ) {
newContact = true ;
contact = new Contact ( jid , name ) ;
contacts . insert ( std : : make_pair ( jid , contact ) ) ;
if ( avail = = Shared : : Availability : : offline ) {
disconnect ( ) ; //TODO not sure how to do here - changing state may cause connection or disconnection
} else {
contact = itr - > second ;
}
QSet < QString > gr = re . groups ( ) ;
Shared : : SubscriptionState state = castSubscriptionState ( re . subscriptionType ( ) ) ;
contact - > setGroups ( gr ) ;
contact - > setSubscriptionState ( state ) ;
contact - > setName ( re . name ( ) ) ;
if ( newContact ) {
QMap < QString , QVariant > cData ( {
{ " name " , re . name ( ) } ,
{ " state " , QVariant : : fromValue ( state ) }
} ) ;
Archive : : AvatarInfo info ;
bool hasAvatar = contact - > readAvatarInfo ( info ) ;
if ( hasAvatar ) {
if ( info . autogenerated ) {
cData . insert ( " avatarState " , static_cast < uint > ( Shared : : Avatar : : valid ) ) ;
} else {
cData . insert ( " avatarState " , static_cast < uint > ( Shared : : Avatar : : autocreated ) ) ;
}
cData . insert ( " avatarPath " , contact - > avatarPath ( ) + " . " + info . type ) ;
} else {
cData . insert ( " avatarState " , static_cast < uint > ( Shared : : Avatar : : empty ) ) ;
cData . insert ( " avatarPath " , " " ) ;
requestVCard ( jid ) ;
}
int grCount = 0 ;
for ( QSet < QString > : : const_iterator itr = gr . begin ( ) , end = gr . end ( ) ; itr ! = end ; + + itr ) {
const QString & groupName = * itr ;
addToGroup ( jid , groupName ) ;
emit addContact ( jid , groupName , cData ) ;
grCount + + ;
}
QXmppPresence : : AvailableStatusType pres = static_cast < QXmppPresence : : AvailableStatusType > ( avail ) ;
if ( grCount = = 0 ) {
emit addContact ( jid , " " , cData ) ;
presence . setAvailableStatusType ( pres ) ;
if ( state ! = Shared : : ConnectionState : : disconnected ) {
client . setClientPresence ( presence ) ;
}
handleNewContact ( contact ) ;
}
}
void Core : : Account : : handleNewRosterItem ( Core : : RosterItem * contact )
{
QObject : : connect ( contact , & RosterItem : : needHistory , this , & Account : : onContactNeedHistory ) ;
QObject : : connect ( contact , & RosterItem : : historyResponse , this , & Account : : onContactHistoryResponse ) ;
QObject : : connect ( contact , & RosterItem : : nameChanged , this , & Account : : onContactNameChanged ) ;
QObject : : connect ( contact , & RosterItem : : avatarChanged , this , & Account : : onContactAvatarChanged ) ;
QObject : : connect ( contact , & RosterItem : : requestVCard , this , & Account : : requestVCard ) ;
}
void Core : : Account : : handleNewContact ( Core : : Contact * contact )
{
handleNewRosterItem ( contact ) ;
QObject : : connect ( contact , & Contact : : groupAdded , this , & Account : : onContactGroupAdded ) ;
QObject : : connect ( contact , & Contact : : groupRemoved , this , & Account : : onContactGroupRemoved ) ;
QObject : : connect ( contact , & Contact : : subscriptionStateChanged , this , & Account : : onContactSubscriptionStateChanged ) ;
}
void Core : : Account : : handleNewConference ( Core : : Conference * contact )
{
handleNewRosterItem ( contact ) ;
QObject : : connect ( contact , & Conference : : nickChanged , this , & Account : : onMucNickNameChanged ) ;
QObject : : connect ( contact , & Conference : : subjectChanged , this , & Account : : onMucSubjectChanged ) ;
QObject : : connect ( contact , & Conference : : joinedChanged , this , & Account : : onMucJoinedChanged ) ;
QObject : : connect ( contact , & Conference : : autoJoinChanged , this , & Account : : onMucAutoJoinChanged ) ;
QObject : : connect ( contact , & Conference : : addParticipant , this , & Account : : onMucAddParticipant ) ;
QObject : : connect ( contact , & Conference : : changeParticipant , this , & Account : : onMucChangeParticipant ) ;
QObject : : connect ( contact , & Conference : : removeParticipant , this , & Account : : onMucRemoveParticipant ) ;
}
void Core : : Account : : onPresenceReceived ( const QXmppPresence & p_presence )
{
QString id = p_presence . from ( ) ;
@ -478,11 +340,9 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
}
}
} else {
if ( pendingVCardRequests . find ( jid ) = = pendingVCardRequests . end ( ) ) {
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( jid ) ;
if ( itr ! = contacts . end ( ) ) {
itr - > second - > handlePresence ( p_presence ) ;
}
RosterItem * item = rh - > getRosterItem ( jid ) ;
if ( item ! = 0 ) {
item - > handlePresence ( p_presence ) ;
}
}
@ -501,7 +361,7 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
{ " status " , p_presence . statusText ( ) }
} ) ;
}
break ;
break ;
case QXmppPresence : : Unavailable :
emit removePresence ( jid , resource ) ;
break ;
@ -519,81 +379,20 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
}
}
void Core : : Account : : onRosterPresenceChanged ( const QString & bareJid , const QString & resource )
{
//not used for now;
qDebug ( ) < < " presence changed for " < < bareJid < < " resource " < < resource ;
const QXmppPresence & presence = rm - > getPresence ( bareJid , resource ) ;
}
QString Core : : Account : : getResource ( ) const {
return config . resource ( ) ; }
void Core : : Account : : setLogin ( const QString & p_login )
{
config . setUser ( p_login ) ;
}
void Core : : Account : : setResource ( const QString & p_resource ) {
config . setResource ( p_resource ) ; }
void Core : : Account : : setName ( const QString & p_name )
{
name = p_name ;
}
QString Core : : Account : : getFullJid ( ) const {
return getLogin ( ) + " @ " + getServer ( ) + " / " + getResource ( ) ; }
void Core : : Account : : setPassword ( const QString & p_password )
{
config . setPassword ( p_password ) ;
}
void Core : : Account : : sendMessage ( const Shared : : Message & data ) {
mh - > sendMessage ( data ) ; }
void Core : : Account : : setServer ( const QString & p_server )
{
config . setDomain ( p_server ) ;
}
Shared : : Availability Core : : Account : : getAvailability ( ) const
{
if ( state = = Shared : : ConnectionState : : connected ) {
QXmppPresence : : AvailableStatusType pres = presence . availableStatusType ( ) ;
return static_cast < Shared : : Availability > ( pres ) ; //they are compatible;
} else {
return Shared : : Availability : : offline ;
}
}
void Core : : Account : : setAvailability ( Shared : : Availability avail )
{
if ( avail = = Shared : : Availability : : offline ) {
disconnect ( ) ; //TODO not sure how to do here - changing state may cause connection or disconnection
} else {
QXmppPresence : : AvailableStatusType pres = static_cast < QXmppPresence : : AvailableStatusType > ( avail ) ;
presence . setAvailableStatusType ( pres ) ;
if ( state ! = Shared : : ConnectionState : : disconnected ) {
client . setClientPresence ( presence ) ;
}
}
}
QString Core : : Account : : getResource ( ) const
{
return config . resource ( ) ;
}
void Core : : Account : : setResource ( const QString & p_resource )
{
config . setResource ( p_resource ) ;
}
QString Core : : Account : : getFullJid ( ) const
{
return getLogin ( ) + " @ " + getServer ( ) + " / " + getResource ( ) ;
}
void Core : : Account : : sendMessage ( const Shared : : Message & data )
{
mh - > sendMessage ( data ) ;
}
void Core : : Account : : sendMessage ( const Shared : : Message & data , const QString & path )
{
mh - > sendMessage ( data , path ) ;
}
void Core : : Account : : sendMessage ( const Shared : : Message & data , const QString & path ) {
mh - > sendMessage ( data , path ) ; }
void Core : : Account : : onMamMessageReceived ( const QString & queryId , const QXmppMessage & msg )
{
@ -601,7 +400,7 @@ void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMess
std : : map < QString , QString > : : const_iterator itr = achiveQueries . find ( queryId ) ;
if ( itr ! = achiveQueries . end ( ) ) {
QString jid = itr - > second ;
RosterItem * item = getRosterItem ( jid ) ;
RosterItem * item = rh - > getRosterItem ( jid ) ;
Shared : : Message sMsg ( static_cast < Shared : : Message : : Type > ( msg . type ( ) ) ) ;
mh - > initializeMessage ( sMsg , msg , false , true , true ) ;
@ -614,31 +413,13 @@ void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMess
item - > addMessageToArchive ( sMsg ) ;
}
}
}
//handleChatMessage(msg, false, true, true);
}
Core : : RosterItem * Core : : Account : : getRosterItem ( const QString & jid )
{
RosterItem * item = 0 ;
std : : map < QString , Contact * > : : const_iterator citr = contacts . find ( jid ) ;
if ( citr ! = contacts . end ( ) ) {
item = citr - > second ;
} else {
std : : map < QString , Conference * > : : const_iterator coitr = conferences . find ( jid ) ;
if ( coitr ! = conferences . end ( ) ) {
item = coitr - > second ;
}
}
return item ;
}
void Core : : Account : : requestArchive ( const QString & jid , int count , const QString & before )
{
qDebug ( ) < < " An archive request for " < < jid < < " , before " < < before ;
RosterItem * contact = getRosterItem ( jid ) ;
RosterItem * contact = rh - > getRosterItem ( jid ) ;
if ( contact = = 0 ) {
qDebug ( ) < < " An attempt to request archive for " < < jid < < " in account " < < name < < " , but the contact with such id wasn't found, skipping " ;
@ -687,12 +468,10 @@ void Core::Account::onContactNeedHistory(const QString& before, const QString& a
with = contact - > jid ;
}
QString q = am - > retrieveArchivedMessages ( to , " " , with , start , QDateTime ( ) , query ) ;
achiveQueries . insert ( std : : make_pair ( q , contact - > jid ) ) ;
}
void Core : : Account : : onMamResultsReceived ( const QString & queryId , const QXmppResultSetReply & resultSetReply , bool complete )
{
std : : map < QString , QString > : : const_iterator itr = achiveQueries . find ( queryId ) ;
@ -700,7 +479,7 @@ void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResu
QString jid = itr - > second ;
achiveQueries . erase ( itr ) ;
RosterItem * ri = getRosterItem ( jid ) ;
RosterItem * ri = rh - > getRosterItem ( jid ) ;
if ( ri ! = 0 ) {
qDebug ( ) < < " Flushing messages for " < < jid < < " , complete: " < < complete ;
@ -715,98 +494,6 @@ void Core::Account::onMamLog(QXmppLogger::MessageType type, const QString& msg)
qDebug ( ) < < msg ;
}
void Core : : Account : : onContactGroupAdded ( const QString & group )
{
Contact * contact = static_cast < Contact * > ( sender ( ) ) ;
if ( contact - > groupsCount ( ) = = 1 ) {
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
}
QMap < QString , QVariant > cData ( {
{ " name " , contact - > getName ( ) } ,
{ " state " , QVariant : : fromValue ( contact - > getSubscriptionState ( ) ) }
} ) ;
addToGroup ( contact - > jid , group ) ;
emit addContact ( contact - > jid , group , cData ) ;
}
void Core : : Account : : onContactGroupRemoved ( const QString & group )
{
Contact * contact = static_cast < Contact * > ( sender ( ) ) ;
if ( contact - > groupsCount ( ) = = 0 ) {
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
}
emit removeContact ( contact - > jid , group ) ;
removeFromGroup ( contact - > jid , group ) ;
}
void Core : : Account : : onContactNameChanged ( const QString & cname )
{
Contact * contact = static_cast < Contact * > ( sender ( ) ) ;
QMap < QString , QVariant > cData ( {
{ " name " , cname } ,
} ) ;
emit changeContact ( contact - > jid , cData ) ;
}
void Core : : Account : : onContactSubscriptionStateChanged ( Shared : : SubscriptionState cstate )
{
Contact * contact = static_cast < Contact * > ( sender ( ) ) ;
QMap < QString , QVariant > cData ( {
{ " state " , QVariant : : fromValue ( cstate ) } ,
} ) ;
emit changeContact ( contact - > jid , cData ) ;
}
void Core : : Account : : addToGroup ( const QString & jid , const QString & group )
{
std : : map < QString , std : : set < QString > > : : iterator gItr = groups . find ( group ) ;
if ( gItr = = groups . end ( ) ) {
gItr = groups . insert ( std : : make_pair ( group , std : : set < QString > ( ) ) ) . first ;
emit addGroup ( group ) ;
}
gItr - > second . insert ( jid ) ;
}
void Core : : Account : : removeFromGroup ( const QString & jid , const QString & group )
{
QSet < QString > toRemove ;
std : : map < QString , std : : set < QString > > : : iterator itr = groups . find ( group ) ;
if ( itr = = groups . end ( ) ) {
qDebug ( ) < < " An attempt to remove contact " < < jid < < " of account " < < name < < " from non existing group " < < group < < " , skipping " ;
return ;
}
std : : set < QString > contacts = itr - > second ;
std : : set < QString > : : const_iterator cItr = contacts . find ( jid ) ;
if ( cItr ! = contacts . end ( ) ) {
contacts . erase ( cItr ) ;
if ( contacts . size ( ) = = 0 ) {
emit removeGroup ( group ) ;
groups . erase ( group ) ;
}
}
}
Shared : : SubscriptionState Core : : Account : : castSubscriptionState ( QXmppRosterIq : : Item : : SubscriptionType qs ) const
{
Shared : : SubscriptionState state ;
if ( qs = = QXmppRosterIq : : Item : : NotSet ) {
state = Shared : : SubscriptionState : : unknown ;
} else {
state = static_cast < Shared : : SubscriptionState > ( qs ) ;
}
return state ;
}
void Core : : Account : : onContactHistoryResponse ( const std : : list < Shared : : Message > & list )
{
RosterItem * contact = static_cast < RosterItem * > ( sender ( ) ) ;
qDebug ( ) < < " Collected history for contact " < < contact - > jid < < list . size ( ) < < " elements " ;
emit responseArchive ( contact - > jid , list ) ;
}
void Core : : Account : : onClientError ( QXmppClient : : Error err )
{
qDebug ( ) < < " Error " ;
@ -909,7 +596,6 @@ void Core::Account::onClientError(QXmppClient::Error err)
emit error ( errorText ) ;
}
void Core : : Account : : subscribeToContact ( const QString & jid , const QString & reason )
{
if ( state = = Shared : : ConnectionState : : connected ) {
@ -928,269 +614,50 @@ void Core::Account::unsubscribeFromContact(const QString& jid, const QString& re
}
}
void Core : : Account : : removeContactRequest ( const QString & jid )
{
if ( state = = Shared : : ConnectionState : : connected ) {
std : : set < QString > : : const_iterator itr = outOfRosterContacts . find ( jid ) ;
if ( itr ! = outOfRosterContacts . end ( ) ) {
outOfRosterContacts . erase ( itr ) ;
onRosterItemRemoved ( jid ) ;
} else {
rm - > removeItem ( jid ) ;
}
} else {
qDebug ( ) < < " An attempt to remove contact " < < jid < < " from account " < < name < < " but the account is not in the connected state, skipping " ;
}
}
void Core : : Account : : addContactRequest ( const QString & jid , const QString & name , const QSet < QString > & groups )
{
if ( state = = Shared : : ConnectionState : : connected ) {
std : : map < QString , QString > : : const_iterator itr = queuedContacts . find ( jid ) ;
if ( itr ! = queuedContacts . end ( ) ) {
qDebug ( ) < < " An attempt to add contact " < < jid < < " to account " < < name < < " but the account is already queued for adding, skipping " ;
} else {
queuedContacts . insert ( std : : make_pair ( jid , " " ) ) ; //TODO need to add reason here;
rm - > addItem ( jid , name , groups ) ;
}
} else {
qDebug ( ) < < " An attempt to add contact " < < jid < < " to account " < < name < < " but the account is not in the connected state, skipping " ;
}
}
void Core : : Account : : onMucRoomAdded ( QXmppMucRoom * room )
{
qDebug ( ) < < " room " < < room - > jid ( ) < < " added with name " < < room - > name ( ) < < " , account " < < getName ( ) < < " joined: " < < room - > isJoined ( ) ;
}
void Core : : Account : : bookmarksReceived ( const QXmppBookmarkSet & bookmarks )
{
QList < QXmppBookmarkConference > confs = bookmarks . conferences ( ) ;
for ( QList < QXmppBookmarkConference > : : const_iterator itr = confs . begin ( ) , end = confs . end ( ) ; itr ! = end ; + + itr ) {
const QXmppBookmarkConference & c = * itr ;
QString jid = c . jid ( ) ;
std : : map < QString , Conference * > : : const_iterator cItr = conferences . find ( jid ) ;
if ( cItr = = conferences . end ( ) ) {
addNewRoom ( jid , c . nickName ( ) , c . name ( ) , c . autoJoin ( ) ) ;
} else {
qDebug ( ) < < " Received a bookmark to a MUC " < < jid < < " which is already booked by another bookmark, skipping " ;
}
}
}
void Core : : Account : : onMucJoinedChanged ( bool joined )
{
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit changeRoom ( room - > jid , {
{ " joined " , joined }
} ) ;
}
void Core : : Account : : onMucAutoJoinChanged ( bool autoJoin )
{
storeConferences ( ) ;
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit changeRoom ( room - > jid , {
{ " autoJoin " , autoJoin }
} ) ;
}
void Core : : Account : : removeContactRequest ( const QString & jid ) {
rh - > removeContactRequest ( jid ) ; }
void Core : : Account : : onMucNickNameChanged ( const QString & nickName )
{
storeConferences ( ) ;
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit changeRoom ( room - > jid , {
{ " nick " , nickName }
} ) ;
}
void Core : : Account : : addContactRequest ( const QString & jid , const QString & name , const QSet < QString > & groups ) {
rh - > addContactRequest ( jid , name , groups ) ; }
void Core : : Account : : setRoomAutoJoin ( const QString & jid , bool joined )
{
std : : map < QString , Conference * > : : const_iterator cItr = conferences . find ( jid ) ;
if ( cItr = = conferences . end ( ) ) {
Conference * conf = rh - > getConference ( jid ) ;
if ( conf = = 0 ) {
qDebug ( ) < < " An attempt to set auto join to the non existing room " < < jid < < " of the account " < < getName ( ) < < " , skipping " ;
return ;
}
cItr - > second - > setAutoJoin ( joined ) ;
conf - > setAutoJoin ( joined ) ;
}
void Core : : Account : : setRoomJoined ( const QString & jid , bool joined )
{
std : : map < QString , Conference * > : : const_iterator cItr = conferences . find ( jid ) ;
if ( cItr = = conferences . end ( ) ) {
Conference * conf = rh - > getConference ( jid ) ;
if ( conf = = 0 ) {
qDebug ( ) < < " An attempt to set joined to the non existing room " < < jid < < " of the account " < < getName ( ) < < " , skipping " ;
return ;
}
cItr - > second - > setJoined ( joined ) ;
conf - > setJoined ( joined ) ;
}
void Core : : Account : : onMucAddParticipant ( const QString & nickName , const QMap < QString , QVariant > & data )
{
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit addRoomParticipant ( room - > jid , nickName , data ) ;
}
void Core : : Account : : removeRoomRequest ( const QString & jid ) {
rh - > removeRoomRequest ( jid ) ; }
void Core : : Account : : onMucChangeParticipant ( const QString & nickName , const QMap < QString , QVariant > & data )
{
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit changeRoomParticipant ( room - > jid , nickName , data ) ;
}
void Core : : Account : : addRoomRequest ( const QString & jid , const QString & nick , const QString & password , bool autoJoin ) {
rh - > addRoomRequest ( jid , nick , password , autoJoin ) ; }
void Core : : Account : : onMucRemoveParticipant ( const QString & nickName )
{
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit removeRoomParticipant ( room - > jid , nickName ) ;
}
void Core : : Account : : onMucSubjectChanged ( const QString & subject )
{
Conference * room = static_cast < Conference * > ( sender ( ) ) ;
emit changeRoom ( room - > jid , {
{ " subject " , subject }
} ) ;
}
void Core : : Account : : addContactToGroupRequest ( const QString & jid , const QString & groupName ) {
rh - > addContactToGroupRequest ( jid , groupName ) ; }
void Core : : Account : : storeConferences ( )
{
QXmppBookmarkSet bms = bm - > bookmarks ( ) ;
QList < QXmppBookmarkConference > confs ;
for ( std : : map < QString , Conference * > : : const_iterator itr = conferences . begin ( ) , end = conferences . end ( ) ; itr ! = end ; + + itr ) {
Conference * conference = itr - > second ;
QXmppBookmarkConference conf ;
conf . setJid ( conference - > jid ) ;
conf . setName ( conference - > getName ( ) ) ;
conf . setNickName ( conference - > getNick ( ) ) ;
conf . setAutoJoin ( conference - > getAutoJoin ( ) ) ;
confs . push_back ( conf ) ;
}
bms . setConferences ( confs ) ;
bm - > setBookmarks ( bms ) ;
}
void Core : : Account : : clearConferences ( )
{
for ( std : : map < QString , Conference * > : : const_iterator itr = conferences . begin ( ) , end = conferences . end ( ) ; itr ! = end ; itr + + ) {
itr - > second - > deleteLater ( ) ;
emit removeRoom ( itr - > first ) ;
}
conferences . clear ( ) ;
}
void Core : : Account : : removeRoomRequest ( const QString & jid )
{
std : : map < QString , Conference * > : : const_iterator itr = conferences . find ( jid ) ;
if ( itr = = conferences . end ( ) ) {
qDebug ( ) < < " An attempt to remove non existing room " < < jid < < " from account " < < name < < " , skipping " ;
}
itr - > second - > deleteLater ( ) ;
conferences . erase ( itr ) ;
emit removeRoom ( jid ) ;
storeConferences ( ) ;
}
void Core : : Account : : addRoomRequest ( const QString & jid , const QString & nick , const QString & password , bool autoJoin )
{
std : : map < QString , Conference * > : : const_iterator cItr = conferences . find ( jid ) ;
if ( cItr = = conferences . end ( ) ) {
addNewRoom ( jid , nick , " " , autoJoin ) ;
storeConferences ( ) ;
} else {
qDebug ( ) < < " An attempt to add a MUC " < < jid < < " which is already present in the rester, skipping " ;
}
}
void Core : : Account : : addNewRoom ( const QString & jid , const QString & nick , const QString & roomName , bool autoJoin )
{
QXmppMucRoom * room = mm - > addRoom ( jid ) ;
QString lNick = nick ;
if ( lNick . size ( ) = = 0 ) {
lNick = getName ( ) ;
}
Conference * conf = new Conference ( jid , getName ( ) , autoJoin , roomName , lNick , room ) ;
conferences . insert ( std : : make_pair ( jid , conf ) ) ;
handleNewConference ( conf ) ;
QMap < QString , QVariant > cData = {
{ " autoJoin " , conf - > getAutoJoin ( ) } ,
{ " joined " , conf - > getJoined ( ) } ,
{ " nick " , conf - > getNick ( ) } ,
{ " name " , conf - > getName ( ) } ,
{ " avatars " , conf - > getAllAvatars ( ) }
} ;
Archive : : AvatarInfo info ;
bool hasAvatar = conf - > readAvatarInfo ( info ) ;
if ( hasAvatar ) {
if ( info . autogenerated ) {
cData . insert ( " avatarState " , QVariant : : fromValue ( Shared : : Avatar : : autocreated ) ) ;
} else {
cData . insert ( " avatarState " , QVariant : : fromValue ( Shared : : Avatar : : valid ) ) ;
}
cData . insert ( " avatarPath " , conf - > avatarPath ( ) + " . " + info . type ) ;
} else {
cData . insert ( " avatarState " , QVariant : : fromValue ( Shared : : Avatar : : empty ) ) ;
cData . insert ( " avatarPath " , " " ) ;
requestVCard ( jid ) ;
}
emit addRoom ( jid , cData ) ;
}
void Core : : Account : : addContactToGroupRequest ( const QString & jid , const QString & groupName )
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( jid ) ;
if ( itr = = contacts . end ( ) ) {
qDebug ( ) < < " An attempt to add non existing contact " < < jid < < " of account " < < name < < " to the group " < < groupName < < " , skipping " ;
} else {
QXmppRosterIq : : Item item = rm - > getRosterEntry ( jid ) ;
QSet < QString > groups = item . groups ( ) ;
if ( groups . find ( groupName ) = = groups . end ( ) ) { //TODO need to change it, I guess that sort of code is better in qxmpp lib
groups . insert ( groupName ) ;
item . setGroups ( groups ) ;
QXmppRosterIq iq ;
iq . setType ( QXmppIq : : Set ) ;
iq . addItem ( item ) ;
client . sendPacket ( iq ) ;
} else {
qDebug ( ) < < " An attempt to add contact " < < jid < < " of account " < < name < < " to the group " < < groupName < < " but it's already in that group, skipping " ;
}
}
}
void Core : : Account : : removeContactFromGroupRequest ( const QString & jid , const QString & groupName )
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( jid ) ;
if ( itr = = contacts . end ( ) ) {
qDebug ( ) < < " An attempt to remove non existing contact " < < jid < < " of account " < < name < < " from the group " < < groupName < < " , skipping " ;
} else {
QXmppRosterIq : : Item item = rm - > getRosterEntry ( jid ) ;
QSet < QString > groups = item . groups ( ) ;
QSet < QString > : : const_iterator gItr = groups . find ( groupName ) ;
if ( gItr ! = groups . end ( ) ) {
groups . erase ( gItr ) ;
item . setGroups ( groups ) ;
QXmppRosterIq iq ;
iq . setType ( QXmppIq : : Set ) ;
iq . addItem ( item ) ;
client . sendPacket ( iq ) ;
} else {
qDebug ( ) < < " An attempt to remove contact " < < jid < < " of account " < < name < < " from the group " < < groupName < < " but it's not in that group, skipping " ;
}
}
}
void Core : : Account : : removeContactFromGroupRequest ( const QString & jid , const QString & groupName ) {
rh - > removeContactFromGroupRequest ( jid , groupName ) ; }
void Core : : Account : : renameContactRequest ( const QString & jid , const QString & newName )
{
std : : map < QString , Contact * > : : const_iterator itr = contacts . find ( jid ) ;
if ( itr = = contacts . end ( ) ) {
Contact * cnt = rh - > getContact ( jid ) ;
if ( cnt = = 0 ) {
qDebug ( ) < < " An attempt to rename non existing contact " < < jid < < " of account " < < name < < " , skipping " ;
} else {
rm - > renameItem ( jid , newName ) ;
@ -1207,7 +674,7 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card)
resource = comps . back ( ) ;
}
pendingVCardRequests . erase ( id ) ;
RosterItem * item = getRosterItem ( jid ) ;
RosterItem * item = rh - > getRosterItem ( jid ) ;
if ( item = = 0 ) {
if ( jid = = getLogin ( ) + " @ " + getServer ( ) ) {
@ -1327,17 +794,6 @@ QString Core::Account::getAvatarPath() const
}
}
void Core : : Account : : onContactAvatarChanged ( Shared : : Avatar type , const QString & path )
{
RosterItem * item = static_cast < RosterItem * > ( sender ( ) ) ;
QMap < QString , QVariant > cData ( {
{ " avatarState " , static_cast < uint > ( type ) } ,
{ " avatarPath " , path }
} ) ;
emit changeContact ( item - > jid , cData ) ;
}
void Core : : Account : : requestVCard ( const QString & jid )
{
if ( pendingVCardRequests . find ( jid ) = = pendingVCardRequests . end ( ) ) {
@ -1426,12 +882,7 @@ void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
void Core : : Account : : cancelHistoryRequests ( )
{
for ( const std : : pair < const QString , Conference * > & pair : conferences ) {
pair . second - > clearArchiveRequests ( ) ;
}
for ( const std : : pair < const QString , Contact * > & pair : contacts ) {
pair . second - > clearArchiveRequests ( ) ;
}
rh - > cancelHistoryRequests ( ) ;
achiveQueries . clear ( ) ;
}