75 bool retVal=false; |
75 bool retVal=false; |
76 QMessage::Type type=message.type(); |
76 QMessage::Type type=message.type(); |
77 QMessageAccountId account=message.parentAccountId(); |
77 QMessageAccountId account=message.parentAccountId(); |
78 QString cm=type == QMessage::Sms ? "ring" : type == QMessage::InstantMessage ? account.toString() : ""; |
78 QString cm=type == QMessage::Sms ? "ring" : type == QMessage::InstantMessage ? account.toString() : ""; |
79 QMessageAddressList toList=message.to(); |
79 QMessageAddressList toList=message.to(); |
|
80 TpSessionAccount *tpsa=tpSession->getAccount(account.toString()); |
|
81 // qDebug() << "sendMessage account:" << account.toString() << tpsa; |
|
82 if(!tpsa) return false; |
80 if(!cm.isEmpty()) { |
83 if(!cm.isEmpty()) { |
81 foreach(QMessageAddress to,toList) { |
84 foreach(QMessageAddress to,toList) { |
82 tpSession->sendMessageToAddress(cm,to.addressee(),message.textContent()); |
85 connect(tpsa,SIGNAL(messageQueued(TpSessionAccount *,bool)),SLOT(onMessageQueued(TpSessionAccount *,bool))); |
|
86 opBusy=true; |
|
87 tpsa->sendMessageToAddress(to.addressee(),message.textContent()); |
|
88 if(opBusy) loop.exec(); // Wait untill this message has been queued to sent next one |
|
89 // qDebug() << "sendMessage loop exit"; |
83 retVal=true; |
90 retVal=true; |
84 }; |
91 }; |
85 } |
92 } |
86 else |
93 else |
87 qDebug() << "TelepathyEngine::sendMessage unsupported message type" << type; |
94 qDebug() << "TelepathyEngine::sendMessage unsupported message type" << type; |
88 return retVal; |
95 return retVal; |
89 } |
96 } |
90 |
97 |
|
98 |
|
99 void TelepathyEngine::onMessageSent(const Tp::Message &,TpSessionAccount *) |
|
100 { |
|
101 qDebug() << "onMessageSent:" ; |
|
102 // loop.quit(); |
|
103 }; |
|
104 |
|
105 void TelepathyEngine::onMessageQueued(TpSessionAccount *,bool status) |
|
106 { |
|
107 //qDebug() << "onMessageQueued:" << status; |
|
108 opBusy=false; |
|
109 loop.quit(); // If queuinf failed, exit loop |
|
110 }; |
91 |
111 |
92 |
112 |
93 |
113 |
94 void TelepathyEngine::updateImAccounts() const |
114 void TelepathyEngine::updateImAccounts() const |
95 { |
115 { |
107 QString accountAddress = ""; |
127 QString accountAddress = ""; |
108 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
128 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
109 accountName, |
129 accountName, |
110 QMessageAddress(QMessageAddress::Phone, accountAddress), |
130 QMessageAddress(QMessageAddress::Phone, accountAddress), |
111 QMessage::Sms); |
131 QMessage::Sms); |
|
132 // qDebug() << "updateImAccounts Sms id:" << accountId << " accountName:" << accountName << "accountAddress" << accountAddress; |
112 iAccounts.insert(accountId, account); |
133 iAccounts.insert(accountId, account); |
113 defaultSmsAccountId=accountId; |
134 defaultSmsAccountId=accountId; |
114 } else |
135 } else { |
115 if(cm=="gabble") { // Gabble for googletalk |
|
116 QString accountId = tpacc->acc->uniqueIdentifier(); |
136 QString accountId = tpacc->acc->uniqueIdentifier(); |
117 QString accountName = tpacc->acc->normalizedName(); |
137 QString accountName = tpacc->acc->normalizedName(); |
118 QString accountAddress = tpacc->acc->normalizedName(); |
138 QString accountAddress = tpacc->acc->normalizedName(); |
|
139 // Some ugly hardcoded hacks |
|
140 if(tpacc->acc->protocol()=="skype") accountName+=QString("@skype"); |
|
141 if(!accountName.contains("@")) accountName+=QString("@")+tpacc->acc->parameters()["server"].toString(); |
|
142 // qDebug() << "updateImAccounts InstantMessage id:" << accountId << " accountName:" << accountName << "accountAddress" << accountAddress; |
119 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
143 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
120 accountName, |
144 accountName, |
121 QMessageAddress(QMessageAddress::InstantMessage, accountAddress), |
145 QMessageAddress(QMessageAddress::InstantMessage, accountAddress), |
122 QMessage::InstantMessage); |
146 QMessage::InstantMessage); |
123 iAccounts.insert(accountId, account); |
147 iAccounts.insert(accountId, account); |
124 } else qDebug() << "Protocol " << tpacc->acc->protocol() << "with connectionmanager " << cm << "Is not yet supported"; |
148 } |
|
149 // else qDebug() << "Protocol " << tpacc->acc->protocol() << "with connectionmanager " << cm << "Is not yet supported"; |
125 // if (strncmp(account_name_key, default_account, strlen(default_account))) iDefaultEmailAccountId = accountId; |
150 // if (strncmp(account_name_key, default_account, strlen(default_account))) iDefaultEmailAccountId = accountId; |
126 |
151 } |
127 } |
|
128 } |
152 } |
129 } |
153 } |
130 |
154 |
131 QMessageAccountIdList TelepathyEngine::queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, |
155 QMessageAccountIdList TelepathyEngine::queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, |
132 uint limit, uint offset, bool &isFiltered, bool &isSorted) const |
156 uint limit, uint offset, bool &isFiltered, bool &isSorted) const |
133 { |
157 { |
|
158 Q_UNUSED(sortOrder); |
|
159 Q_UNUSED(limit); |
|
160 Q_UNUSED(offset); |
134 // qDebug() << "TelepathyEngine::queryAccounts"; |
161 // qDebug() << "TelepathyEngine::queryAccounts"; |
135 QMessageAccountIdList accountIds; |
162 QMessageAccountIdList accountIds; |
136 |
163 |
137 updateImAccounts(); |
164 updateImAccounts(); |
138 foreach (QMessageAccount value, iAccounts) { |
165 foreach (QMessageAccount value, iAccounts) { |