|
1 #include "qmessageglobal.h" |
|
2 #include "qmessagemanager.h" |
|
3 #include "qmessageaccount.h" |
|
4 #include "qmessageaccountid.h" |
|
5 #include "qmessageaccount_p.h" |
|
6 #include "qmessageaccountfilter.h" |
|
7 #include "qmessageaccountfilter_p.h" |
|
8 #include "qmessageservice.h" |
|
9 #include "qmessage.h" |
|
10 #include "telepathyengine_maemo_p.h" |
|
11 #include "maemohelpers_p.h" |
|
12 |
|
13 |
|
14 QTM_BEGIN_NAMESPACE |
|
15 |
|
16 Q_GLOBAL_STATIC(TelepathyEngine,telepathyEngine); |
|
17 |
|
18 TelepathyEngine::TelepathyEngine() |
|
19 { |
|
20 tpSession=new TpSession("ring",TRUE); // Create as sync, telephony "ring" as default |
|
21 |
|
22 } |
|
23 |
|
24 TelepathyEngine::~TelepathyEngine() |
|
25 { |
|
26 |
|
27 } |
|
28 |
|
29 TelepathyEngine* TelepathyEngine::instance() |
|
30 { |
|
31 return telepathyEngine(); |
|
32 } |
|
33 |
|
34 bool TelepathyEngine::sendMessage(QMessage &message) |
|
35 { |
|
36 QMessage::Type type=message.type(); |
|
37 QString cm=type == QMessage::Sms ? "ring" : type == QMessage::Xmpp ? "gabble" : ""; |
|
38 QMessageAddressList toList=message.to(); |
|
39 QMessageAccountId account=message.parentAccountId(); |
|
40 if(!cm.isEmpty()) { |
|
41 foreach(QMessageAddress to,toList) { |
|
42 tpSession->sendMessageToAddress(cm,to.recipient(),message.textContent()); |
|
43 }; |
|
44 } |
|
45 else |
|
46 qDebug() << "TelepathyEngine::sendMessage unsupported message type" << type; |
|
47 } |
|
48 |
|
49 |
|
50 |
|
51 bool TelepathyEngine::queryMessages(QMessageService& messageService, const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
|
52 { |
|
53 return true; |
|
54 } |
|
55 |
|
56 bool TelepathyEngine::queryMessages(QMessageService& messageService, const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const |
|
57 { |
|
58 return true; |
|
59 } |
|
60 |
|
61 bool TelepathyEngine::countMessages(QMessageService& messageService, const QMessageFilter &filter) |
|
62 { |
|
63 return true; |
|
64 }; |
|
65 |
|
66 void TelepathyEngine::updateImAccounts() const |
|
67 { |
|
68 // iDefaultImAccountId = QMessageAccountId(); |
|
69 iAccounts.clear(); |
|
70 foreach (TpSessionAccount *tpacc, tpSession->accounts) { |
|
71 qDebug() << "TelepathyEngine::updateImAccounts" << tpacc->acc->cmName() << " " << tpacc->acc->protocol() << " " << tpacc->acc->displayName(); |
|
72 bool account_ok = tpacc->acc->isEnabled() && tpacc->acc->isValidAccount(); |
|
73 QString cm=tpacc->acc->cmName(); |
|
74 if (account_ok) { |
|
75 if(cm=="ring") { // Ring connection manager for cellular telephony |
|
76 QString accountId = tpacc->acc->uniqueIdentifier(); |
|
77 QString accountName = "SMS"; |
|
78 QString accountAddress = ""; |
|
79 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
|
80 accountName, |
|
81 QMessageAddress(QMessageAddress::Phone, accountAddress), |
|
82 QMessage::Sms); |
|
83 iAccounts.insert(accountId, account); |
|
84 defaultSmsAccountId=accountId; |
|
85 } else |
|
86 if(cm=="gabble") { // Gabble for googletalk |
|
87 QString accountId = tpacc->acc->uniqueIdentifier(); |
|
88 QString accountName = tpacc->acc->normalizedName(); |
|
89 QString accountAddress = tpacc->acc->normalizedName(); |
|
90 QMessageAccount account = QMessageAccountPrivate::from(QMessageAccountId(accountId), |
|
91 accountName, |
|
92 QMessageAddress(QMessageAddress::Xmpp, accountAddress), |
|
93 QMessage::Xmpp); |
|
94 iAccounts.insert(accountId, account); |
|
95 } else qDebug() << "Protocol " << tpacc->acc->protocol() << "with connectionmanager " << cm << "Is not yet supported"; |
|
96 // if (strncmp(account_name_key, default_account, strlen(default_account))) iDefaultEmailAccountId = accountId; |
|
97 |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 QMessageAccountIdList TelepathyEngine::queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, |
|
103 uint limit, uint offset, bool &isFiltered, bool &isSorted) const |
|
104 { |
|
105 QMessageAccountIdList accountIds; |
|
106 |
|
107 updateImAccounts(); |
|
108 foreach (QMessageAccount value, iAccounts) { |
|
109 accountIds.append(value.id()); |
|
110 } |
|
111 |
|
112 MessagingHelper::filterAccounts(accountIds, filter); |
|
113 isFiltered = true; |
|
114 |
|
115 isSorted = false; |
|
116 |
|
117 return accountIds; |
|
118 } |
|
119 |
|
120 int TelepathyEngine::countAccounts(const QMessageAccountFilter &filter) const |
|
121 { |
|
122 bool isFiltered, isSorted; |
|
123 return queryAccounts(filter, QMessageAccountSortOrder(), 0, 0, isFiltered, isSorted).count(); |
|
124 } |
|
125 |
|
126 QMessageAccount TelepathyEngine::account(const QMessageAccountId &id) const |
|
127 { |
|
128 updateImAccounts(); |
|
129 return iAccounts[id.toString()]; |
|
130 } |
|
131 |
|
132 QMessageAccountId TelepathyEngine ::defaultAccount(QMessage::Type type) const |
|
133 { |
|
134 updateImAccounts(); |
|
135 return defaultSmsAccountId; |
|
136 } |
|
137 |
|
138 QTM_END_NAMESPACE |