9f17d59e
陈明泉
no message
|
1
2
3
4
5
6
7
8
9
10
11
12
|
#include "gotyemsg.h"
#include "mywidget.h"
#include <QtWebKitWidgets/QWebView>
#include <QtWebKitWidgets>
#include <QDebug>
#include "gotye/GotyeMessage.h"
#include "gotye/GotyeAPI.h"
USING_NS_GOTYEAPI;
#include "mywidgetitem.h"
#include <QtGlobal>
|
6e10e93e
陈明泉
no message
|
13
14
|
|
9f17d59e
陈明泉
no message
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
GotyeMsg *GotyeMsg::m_GotypMsg = NULL;
GotyeMsg::GotyeMsg(QWidget *parent) :
QWidget(parent)
{
isLogin = false;
apiist-> addListener(*this);
apiist-> setMessageReadIncrement(20);
apiist-> setMessageRequestIncrement(20); // < 设定单次向服务器请求消息增量为20,默认10
showMsgViwe = NULL; //显示聊天的view
useShowList = NULL; //显示聊天列表
showUserName = NULL;
myHeadImg = QString("");
otherHeadImg = QString("");
markerMsgTime = 0;
myUid = -1;
isUpdataMsg = false;
nowUser.name = "0";
|
6e10e93e
陈明泉
no message
|
35
36
37
38
39
40
|
// player = new QMediaPlayer();
// QString mpath = QCoreApplication::applicationDirPath()+"/ring/msg.mp3";
// mpath.replace("\\", "/");
// player->setMedia(QUrl::fromLocalFile(mpath));
QString mpath = QCoreApplication::applicationDirPath()+"/ring/msg.wav";
|
9f17d59e
陈明泉
no message
|
41
|
mpath.replace("\\", "/");
|
6e10e93e
陈明泉
no message
|
42
|
sound = new QSound(mpath);
|
9f17d59e
陈明泉
no message
|
43
44
45
46
|
}
void GotyeMsg::init()
{
|
6e10e93e
陈明泉
no message
|
47
48
|
apiist->init("a0044a1c-09e0-473a-8ceb-a13b445b086d", "com.gotye.api.demo");//测试环境
// apiist->init("51e493d8-879a-4c0f-8ce4-478cebdc3c8f", "com.gotye.api.demo"); //正式环境
|
9f17d59e
陈明泉
no message
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
}
void GotyeMsg::login(QString uid)
{
loginUid = uid;
apiist->login(uid.toStdString(), nullptr);///<对应回调GotyeDelegate::onLogin
}
void GotyeMsg::logout()
{
apiist->logout();///<对应回调GotyeDelegate::onLogin
apiist->exit();
isLogin = false;
}
void GotyeMsg::apiist_exit()
{
apiist->exit();
}
GotyeMsg *GotyeMsg::Instance()
{
if (!m_GotypMsg)
m_GotypMsg = new GotyeMsg();
return m_GotypMsg;
}
void GotyeMsg::onLogin(GotyeStatusCode code, const GotyeLoginUser& user)
{
switch(code)
{
case GotyeStatusCodeOK:
case GotyeStatusCodeReloginOK:
{
qDebug("CMQ 亲加云登录OK.....\n");
apiist->beginReceiveOfflineMessage();
isLogin = true;
ShowNewMsgNum();
break;
}
case GotyeStatusCodeOfflineLoginOK:
{
qDebug("CMQ 亲加云退出登录.....\n");
isLogin = false;
login(loginUid);
break;
}
case GotyeStatusCodeLoginFailed:
{
qDebug("CMQ 亲加云登录失败.....\n");
isLogin = false;
login(loginUid);
break;
}
default:
break;
}
}
void GotyeMsg::setShowMsgWebviwe(QWebView *showViwe)
{
qDebug()<<"setShowMsgWebviwe\n";
if(showViwe)
showMsgViwe = showViwe;
qDebug()<<"setShowMsgWebviwe 000\n";
connect(showMsgViwe->page(), SIGNAL(scrollRequested(int,int,const QRect&)), SLOT(scrollTop(int,int,const QRect&)));
}
void GotyeMsg::setUpdataUserList(QListWidget *useList)
{
if(useList)
useShowList = useList;
else
useShowList = NULL;
}
void GotyeMsg::setShowUserName(QLabel *showName)
{
if(showName)
showUserName = showName;
}
void GotyeMsg::setMyHeadImg(QString img)
{
if(img.length() > 1)
myHeadImg = img;
}
void GotyeMsg::setMyUid(int uid)
{
myUid = uid;
}
void GotyeMsg::setIsUpdata(bool flag)
{
isUpdataMsg = flag;
if(!isUpdataMsg)
apiist->deactiveSession (nowUser); // < 隐藏与target的会话
}
void GotyeMsg::setShowMsgNum(QLabel *label)
{
showNewMsg = label;
ShowNewMsgNum();
}
void GotyeMsg::ShowNewMsgNum()
{
int msgNum = apiist->getTotalUnreadMessageCount();
if(msgNum > 0)
{
showNewMsg->setStyleSheet("background-color:rgba(0,0,0,0);color:rgb(255,255,255);border-image: url(:Images/Home/img_msg_num.png);");
showNewMsg->setAlignment(Qt::AlignCenter);
if(msgNum > 99)
showNewMsg->setText(QString("99+"));
else
showNewMsg->setText(QString("%1").arg(msgNum));
showNewMsg->show();
}
else
showNewMsg->hide();
// qDebug("ShowNewMsgNum msgNum%d..",msgNum);
}
void GotyeMsg::sendMessage(QString targetUid,QString msg,GotyeMessageType type)
{
GotyeChatTarget receiver(targetUid.toLatin1().data());
GotyeStatusCode status;
GotyeMessage message;
qDebug("targetUid = %s\n",receiver.info.data());
if(type == GotyeMessageTypeText)
{
message = GotyeMessage::createTextMessage(receiver, msg.toUtf8().data());
}
else if(type == GotyeMessageTypeImage)
{
message = GotyeMessage::createImageMessage(receiver, msg.toStdString());
}
else if(type == GotyeMessageTypeUserData)
{
qDebug("CMQ GotyeMessageTypeUserData.....\n");
}
else if(type == GotyeMessageTypeAudio)
{
}
status = apiist-> sendMessage (message); /// < 对应回调GotyeDelegate:: onSendMessage
if(status == GotyeStatusCodeOK)
{
qDebug("CMQ 发送成功.....\n");
// qDebug() << QString::fromLocal8Bit("发送成功");
}
}
void GotyeMsg::sendMessage(QString msg,GotyeMessageType type)
{
GotyeStatusCode status;
GotyeMessage message;
if(type == GotyeMessageTypeText)
{
message = GotyeMessage::createTextMessage(nowUser, msg.toUtf8().data());
}
else if(type == GotyeMessageTypeImage)
{
message = GotyeMessage::createImageMessage(nowUser, msg.toStdString());
}
else if(type == GotyeMessageTypeUserData)
{
qDebug("CMQ GotyeMessageTypeUserData.....\n");
}
else if(type == GotyeMessageTypeAudio)
{
}
status = apiist-> sendMessage (message); /// < 对应回调GotyeDelegate:: onSendMessage
if(status == GotyeStatusCodeOK)
{
qDebug("CMQ 发送成功.....\n");
// qDebug() << QString::fromLocal8Bit("发送成功");
}
}
void GotyeMsg::onSendMessage(GotyeStatusCode code, const GotyeMessage& message)
{
// static int flagMsgTime = 1;
qDebug("CMQ GotyeMsg onSendMessage code = %d..markerMsgTime.text = %s...\n",code,message.text.data());
if(atoi(nowUser.name.data()) == 0)
return;
showMsgTime(markerMsgTime,message.date);
markerMsgTime = message.date;
if(message.type == GotyeMessageTypeText)
{
if(message.status == GotyeMessageStatusSending)
SendMsgShow(QString::fromUtf8(message.text.data()),myHeadImg,QString("Sending"));
else if(message.status == GotyeMessageStatusSendingFailed)
SendMsgShow(QString::fromUtf8(message.text.data()),myHeadImg,QString("Failed"));
else
SendMsgShow(QString::fromUtf8(message.text.data()),myHeadImg,QString(""));
}
else if(message.type == GotyeMessageTypeImage)
{
if(message.status == GotyeMessageStatusSending)
SendImageShow(QString::fromStdString(message.media.pathEx),myHeadImg,QString("Sending"));
else if(message.status == GotyeMessageStatusSendingFailed)
SendImageShow(QString::fromStdString(message.media.pathEx),myHeadImg,QString("Failed"));
else
SendImageShow(QString::fromStdString(message.media.pathEx),myHeadImg,QString(""));
}
else if(message.type == GotyeMessageTypeUserData)
{
qDebug("CMQ GotyeMessageTypeUserData.....\n");
}
else if(message.type == GotyeMessageTypeAudio)
{
}
msgChatAreaInit();//刷新聊天列表
}
void GotyeMsg::onDownloadMedia(GotyeStatusCode code, GotyeMedia& media)
{
|
6e10e93e
陈明泉
no message
|
271
|
otherHeadImg = QString(imgTitle) + QString::fromStdString(media.path);
|
9f17d59e
陈明泉
no message
|
272
273
274
275
276
277
278
279
280
281
|
otherHeadImg.replace("\\","/");
msgChatAreaInit();//刷新聊天列表
qDebug("CMQ GotyeMsg onDownloadMedia code = %d.....\n",code);
}
void GotyeMsg::onGetUserDetail(GotyeStatusCode code, const GotyeUser& user)
{
qDebug("CMQ GotyeMsg onGetUserDetail code = %d.....\n",code);
if(strlen(user.icon.path.data()) > 2)
apiist->downloadMedia(user.icon);
else
|
6e10e93e
陈明泉
no message
|
282
283
284
285
|
{
otherHeadImg = QString(defaultHeadimg);
msgChatAreaInit();//刷新聊天列表
}
|
9f17d59e
陈明泉
no message
|
286
287
288
289
290
291
292
293
294
295
296
297
|
}
void GotyeMsg::onDownloadMediaInMessage(const GotyeStatusCode code, const GotyeMessage& message)
{
qDebug("CMQ onDownloadMediaInMessage code = %d.....\n",code);
if(atoi(nowUser.name.data()) == atoi(message.sender.name.data()))
RevImageShow(QString::fromStdString(message.media.pathEx),otherHeadImg);
}
void GotyeMsg::onReceiveMessage(const GotyeMessage& message, bool* downloadMediaIfNeed)
{
GotyeUser userInfo;
userInfo = apiist->getUserDetail(message.sender);
|
6e10e93e
陈明泉
no message
|
298
|
if(atoi(message.sender.name.data()) >= 1000 && atoi(message.sender.name.data()) <= 1003)
|
9f17d59e
陈明泉
no message
|
299
300
|
{
qDebug("CMQ IShowMain onReceiveMessage ..message.text.data() = %s...message.name.data() = %s\n",message.text.data(),message.sender.name.data());
|
6e10e93e
陈明泉
no message
|
301
302
|
apiist->clearMessages(message.sender);//清除聊天
apiist->deleteSession(message.sender);
|
9f17d59e
陈明泉
no message
|
303
304
|
return;
}
|
6e10e93e
陈明泉
no message
|
305
306
307
|
// qDebug()<<player->currentMedia().canonicalUrl();
// player->play();
sound->play();
|
9f17d59e
陈明泉
no message
|
308
309
310
311
312
|
ShowNewMsgNum();
if(!isUpdataMsg)
return;
if(strlen(userInfo.icon.path.data()) > 1)
{
|
6e10e93e
陈明泉
no message
|
313
|
otherHeadImg = QString(imgTitle) + QString::fromStdString(userInfo.icon.path);
|
9f17d59e
陈明泉
no message
|
314
315
316
317
318
|
otherHeadImg.replace("\\","/");
msgChatAreaInit();//刷新聊天列表
}
else
userInfo = apiist->getUserDetail(message.sender,true);
|
6e10e93e
陈明泉
no message
|
319
320
|
qDebug()<<"CMQ otherHeadImg111="<<otherHeadImg;
|
9f17d59e
陈明泉
no message
|
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
if(atoi(nowUser.name.data()) == atoi(message.sender.name.data()))
{
showMsgTime(markerMsgTime,message.date);
markerMsgTime = message.date;
}
if(message.type == GotyeMessageTypeText)
{
qDebug("CMQ IShowMain onReceiveMessage nowUser.name.data() = %s.....message.sender.name.data() = %s...\n",nowUser.name.data(),message.sender.name.data());
if(atoi(nowUser.name.data()) == atoi(message.sender.name.data()))
RevMsgShow(QString::fromUtf8(message.text.data()),otherHeadImg);
}
else if(message.type == GotyeMessageTypeImage)
{
qDebug("CMQ message.text = %s.message.date = %d...id = %ld..path = %s...pathEx = %s.\n",message.media.url.data(),message.date,message.sender.id,message.media.path.data(),message.media.pathEx.data());
*downloadMediaIfNeed = true;
}
else if(message.type == GotyeMessageTypeUserData)
{
qDebug("CMQ GotyeMessageTypeUserData.....\n");
}
else if(message.type == GotyeMessageTypeAudio)
{
}
qDebug("CMQ message.....\n");
}
void GotyeMsg::uidGetChatLog(int uid)
{
int flagMsgTime = 1;
QString user(QString("%1").arg(uid));
GotyeChatTarget getReceiver(user.toLatin1().data());
std::deque<GotyeMessage> messageList;
GotyeMessage getMessage;
GotyeUser userInfo;
nowUser = getReceiver;
nowMessageNum = 0;
apiist-> markMessagesAsRead(nowUser,true); // < 全部标记为已读状态
apiist->activeSession (nowUser); // < 激活与target的会话
messageList = apiist->getMessageList(nowUser,false);
qDebug("CMQ messageList->size() = %d...\n",messageList.size());
userInfo = apiist->getUserDetail(nowUser,true);
if(strlen(userInfo.icon.path.data()) > 2)
{
|
6e10e93e
陈明泉
no message
|
366
|
otherHeadImg = QString(imgTitle) + QString::fromStdString(userInfo.icon.path);
|
9f17d59e
陈明泉
no message
|
367
368
369
|
otherHeadImg.replace("\\","/");
}
else
|
6e10e93e
陈明泉
no message
|
370
|
otherHeadImg = QString(defaultHeadimg);
|
9f17d59e
陈明泉
no message
|
371
372
|
QString html = QString( "document.body.innerHTML=''" );
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
|
6e10e93e
陈明泉
no message
|
373
|
// showUserName->setText(QString(userInfo.nickname.data()));
|
9f17d59e
陈明泉
no message
|
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
for(int i = 0;i < messageList.size();i++)
{
getMessage = messageList.at(i);
qDebug("CMQ getMessage.text = %s..icon = %s.\n",getMessage.sender.name.data(),getMessage.sender.icon.path.data());
showMsgTime(flagMsgTime,getMessage.date);
flagMsgTime = getMessage.date;
showUpMsg(getMessage);
}
}
QString GotyeMsg::getShowTime(int secondNum)
{
QString returnDate;
QDateTime dt = QDateTime::fromTime_t(secondNum);
QString strDate = dt.toString("yyyy-MM-dd");//日期格式自定义
QDateTime current_date_time = QDateTime::currentDateTime();
QString current_date = current_date_time.toString("yyyy-MM-dd");
// qDebug("CMQ getShowTime current_date = %s...",current_date.toLatin1().data());
if(current_date == strDate)
{
QString strtime = dt.toString("hh:mm");//日期格式自定义
// QString current_time = current_date_time.toString("hh:mm");
returnDate = strtime;
}
else
returnDate = strDate;
return returnDate;
}
//刷新聊天记录
void GotyeMsg::scrollTop(int dx, int dy, const QRect& scrollViewRect)
{
std::deque<GotyeMessage> messageList;
int scrollNum = showMsgViwe->page()->mainFrame()->scrollBarValue(Qt::Vertical);
if(dy < 0 || scrollNum > 60 )
return;
messageList = apiist->getMessageList(nowUser,true);
if(nowMessageNum != messageList.size())
{
GotyeMessage getMessage;
GotyeUser userInfo;
int flagMsgTime = 1;
int scrollMax = 0;
int scrollHigh = 0;
nowMessageNum = messageList.size();
qDebug("CMQ scrollTop messageList->size() = %d...\n",messageList.size());
userInfo = apiist->getUserDetail(nowUser,true);
scrollHigh = showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical);
QString html = QString( "document.body.innerHTML=''" );
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
|
6e10e93e
陈明泉
no message
|
431
|
// showUserName->setText(QString(userInfo.nickname.data()));
|
9f17d59e
陈明泉
no message
|
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
for(int i = 0;i < messageList.size();i++)
{
getMessage = messageList.at(i);
showMsgTime(flagMsgTime,getMessage.date);
flagMsgTime = getMessage.date;
showUpMsg(getMessage);
}
scrollMax = showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical);
showMsgViwe->page()->mainFrame()->setScrollBarValue(Qt::Vertical,scrollMax - scrollHigh);
}
}
QString GotyeMsg::getNowUserName()
{
return QString(nowUser.name.data());
}
void GotyeMsg::delItemChat(QListWidgetItem *ChangedItem)
{
GotyeChatTarget userDel;
qDebug("CMQ delItemChat.....%d......\n",useShowList->row(ChangedItem));
useShowList->removeItemWidget(ChangedItem);
userDel = pTargetList.at(useShowList->row(ChangedItem));
apiist->deleteSession(userDel);
apiist->clearMessages(userDel); // < 删除和某个聊天对象的所有消息
if(strcmp(userDel.name.data(),nowUser.name.data()) == 0)
{
QString html = QString( "document.body.innerHTML=''" );
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
nowUser.name = "0";
|
6e10e93e
陈明泉
no message
|
463
|
// showUserName->setText("");
|
9f17d59e
陈明泉
no message
|
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
}
ShowNewMsgNum();
msgChatAreaInit();
}
void GotyeMsg::showLastChatArea(GotyeChatTarget user)
{
std::deque<GotyeMessage> messageList;
GotyeMessage getMessage;
GotyeUser userInfo;
int flagMsgTime = 1;
static int lastCount = -1;
int count = 0;
count = useShowList->currentRow();
qDebug("CMQ count = %d \n",count);
apiist->deactiveSession(nowUser); // < 隐藏与target的会话
nowUser = user;
markerMsgTime = 1;
nowMessageNum = 0;
apiist-> markMessagesAsRead(nowUser,true); // < 全部标记为已读状态
apiist->activeSession(nowUser); // < 激活与target的会话
if(atoi(nowUser.name.data()) == 0)
return;
messageList = apiist->getMessageList(nowUser,false);
qDebug("CMQ messageList->size() = %d...\n",messageList.size());
userInfo = apiist->getUserDetail(nowUser,true);
if(strlen(userInfo.icon.path.data()) > 2)
{
|
6e10e93e
陈明泉
no message
|
494
|
otherHeadImg = QString(imgTitle) + QString::fromStdString(userInfo.icon.path);
|
9f17d59e
陈明泉
no message
|
495
496
497
|
otherHeadImg.replace("\\","/");
}
else
|
6e10e93e
陈明泉
no message
|
498
|
otherHeadImg = QString(defaultHeadimg);
|
9f17d59e
陈明泉
no message
|
499
500
501
502
503
|
qDebug("nowUser.name = %s useShowList cound = %d",nowUser.name.data(),useShowList->count());
if(lastCount == -1 || lastCount != count || count == useShowList->count()-1 )
{
QString html = QString( "document.body.innerHTML=''" );
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
|
6e10e93e
陈明泉
no message
|
504
|
// showUserName->setText(QString(userInfo.nickname.data()));
|
9f17d59e
陈明泉
no message
|
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
msgChatAreaInit();
for(int i = 0;i < messageList.size();i++)
{
getMessage = messageList.at(i);
showMsgTime(flagMsgTime,getMessage.date);
flagMsgTime = getMessage.date;
showUpMsg(getMessage);
}
lastCount = count;
}
ShowNewMsgNum();
}
GotyeChatTarget GotyeMsg::setChooseUser(int count)
{
apiist->deactiveSession(nowUser); // < 隐藏与target的会话
nowUser = pTargetList.at(count);
showLastChatArea(nowUser);
useShowList->setCurrentRow(count);
return nowUser;
}
void GotyeMsg::showUpMsg(GotyeMessage upMessage)
{
if(upMessage.type == GotyeMessageTypeText)
{
if(myUid == atoi(upMessage.sender.name.data()))
SendMsgShow(QString::fromUtf8(upMessage.text.data()),myHeadImg,QString(""));
else
RevMsgShow(QString::fromUtf8(upMessage.text.data()),otherHeadImg);
}
else if(upMessage.type == GotyeMessageTypeImage)
{
if(myUid == atoi(upMessage.sender.name.data()))
SendImageShow(QString::fromStdString(upMessage.media.pathEx),myHeadImg,QString(""));
else
RevImageShow(QString::fromStdString(upMessage.media.pathEx),otherHeadImg);
}
else if(upMessage.type == GotyeMessageTypeUserData)
{
qDebug("CMQ GotyeMessageTypeUserData.....\n");
}
else if(upMessage.type == GotyeMessageTypeAudio)
{
}
ShowNewMsgNum();
}
void GotyeMsg::msgChatAreaInit()
{
GotyeMessage lastMessage;
GotyeChatTarget getUser;
GotyeUser userInfo;
int count = 0;
if(useShowList == NULL)
return;
useShowList->clear();
pTargetList = apiist->getSessionList();
qDebug("CMQ pTargetList.size() = %d.....\n",pTargetList.size());
if(pTargetList.size() < 1)
return;
for(int i = 0;i < pTargetList.size();i++)
{
getUser = pTargetList.at(i);
// continue;
lastMessage = apiist->getLastMessage(getUser);
userInfo = apiist->getUserDetail(getUser);
|
6e10e93e
陈明泉
no message
|
577
|
|
9f17d59e
陈明泉
no message
|
578
579
580
581
582
583
|
QListWidgetItem* item = new QListWidgetItem();
useShowList->addItem(item);
MyWidget *userItem = new MyWidget();
// MyWidgetItem* userItem;// = new MyWidgetItem();
count = apiist-> getUnreadMessageCount(getUser);
|
6e10e93e
陈明泉
no message
|
584
|
if(atoi(getUser.name.data()) != 1000)
|
9f17d59e
陈明泉
no message
|
585
|
{
|
6e10e93e
陈明泉
no message
|
586
587
588
589
590
591
592
593
594
|
if(lastMessage.type == GotyeMessageTypeText)
{
userItem->init(QString(userInfo.icon.path.data()),QString(userInfo.nickname.data()),getShowTime(lastMessage.date),QString(lastMessage.text.data()),count);
}
else
{
userItem->init(QString(userInfo.icon.path.data()),QString(userInfo.nickname.data()),getShowTime(lastMessage.date),QString("[img]"),count);
}
useShowList->setItemWidget(item,userItem);
|
9f17d59e
陈明泉
no message
|
595
596
597
|
}
else
{
|
6e10e93e
陈明泉
no message
|
598
599
600
601
|
apiist->deleteSession(userInfo);
apiist->clearMessages(userInfo); // < 删除和某个聊天对象的所有消息
ShowNewMsgNum();
// continue;
|
9f17d59e
陈明泉
no message
|
602
|
}
|
9f17d59e
陈明泉
no message
|
603
604
605
606
607
608
|
int row = useShowList->count();
useShowList->item(row - 1)->setSizeHint(QSize(useShowList->width()-15,60));
if(strcmp(nowUser.name.data(),getUser.name.data()) == 0)
{
QListWidgetItem *item = useShowList->item(i);
item->setSelected(true);
|
6e10e93e
陈明泉
no message
|
609
610
|
useShowList->scrollToItem(item);
// qDebug("CMQ setSelected = %d.....\n",i);
|
9f17d59e
陈明泉
no message
|
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
|
}
}
}
/*
QString转换为Html的显示风格
*/
void stringToHtml(QString &str,QColor crl)
{
QByteArray array;
array.append(crl.red());
array.append(crl.green());
array.append(crl.blue());
QString strC(array.toHex());
str = QString("<span style='color:#%1;'>%2</span>").arg(strC).arg(str);
}
void imgPathToHtml(QString &path)
{
path = QString("<img src=\"%1\"/>").arg(path);
}
void stringToHtmlFilter(QString &str)
{
//注意这几行代码的顺序不能乱,否则会造成多次替换
str.replace("&","&");
str.replace(">",">");
str.replace("<","<");
str.replace("\"",""");
str.replace("\'","'");
str.replace(" "," ");
str.replace("\n","<br>");
str.replace("\r","<br>");
}
void GotyeMsg::showMsgTime(int lastTime,int nowTime)
{
QString html = QString( "" );
if(lastTime > 0 && nowTime > lastTime)
{
// qDebug("CMQ SendMsgShow..nowTime = %d..lastTime = %d...\n",nowTime,lastTime);
if(nowTime - lastTime > 60)
{
html.append(QString(
"document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;text-align:center;color:#999999;font-size:12px;'><p >%1</p></div>\");" )
.arg(getShowTime(nowTime)));
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
}
}
}
void GotyeMsg::SendMsgShow(QString msg ,QString head,QString status)
{
QString html = QString( "" );
// qDebug("CMQ IMG head = %s......\n",head.toLatin1().data());
// qDebug("CMQ SendMsgShow msg = %s...\n",msg.toLatin1().data());
stringToHtmlFilter(msg);
// imgPathToHtml(head);
html.append(QString(
|
6e10e93e
陈明泉
no message
|
668
|
"document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='divMyHead' style='float: right;'><img src=\'%1\' style='width:45px;height:45px'> </p><p class='triangle-right right'>%2</p><p class='sendType'>%3</p></div>\");document.body.scrollTop = document.documentElement.scrollHeight;" )
|
9f17d59e
陈明泉
no message
|
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
.arg( head )
.arg( msg )
.arg( status ));
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
// showMsgViwe->page()->mainFrame()->setScrollBarValue(Qt::Vertical,showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));
// qDebug("CMQ scrollBarMaximum = %d...\n",showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));
// m_timer->start( 30000 );
}
void GotyeMsg::SendImageShow(QString msg ,QString head,QString status)
{
//style='max-width:100px; padding-top:20px;margin:20px 20px 5px 0;
msg.replace("\\","/");
|
6e10e93e
陈明泉
no message
|
683
|
qDebug("CMQ msg = %s...\n",msg.toLatin1().data());
|
9f17d59e
陈明泉
no message
|
684
685
|
QString html = QString( "" );
html.append(QString(
|
6e10e93e
陈明泉
no message
|
686
|
"document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='divMyHead' style='float: right;'><img src=\'%1\' style='width:45px;height:45px'> </p><p class='triangle-right right'><img src=\'file:///%2\' width='100px' height='100px' default_width=100 default_height=100 onclick='clickimg(this)'></p><p class='sendType'>%3</p></div>\");document.body.scrollTop = document.documentElement.scrollHeight;" )
|
9f17d59e
陈明泉
no message
|
687
688
689
690
691
692
693
694
695
696
|
.arg(head)
.arg(msg)
.arg(status));
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
// m_timer->start( 30000 );
}
void GotyeMsg::RevImageShow(QString msg,QString head)
{
msg.replace("\\","/");
|
6e10e93e
陈明泉
no message
|
697
698
|
qDebug("CMQ RevMsgShow msg = %s...\n",msg.toLatin1().data());
QString html = QString("document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='divotherhead' style='float: left;'> <img src=\'%1\' style='width:45px;height:45px'> </p><p class='triangle-left left'><img src=\'file:///%2\' width='100px' height='100px' default_width=100 default_height=100 onclick='clickimg(this)'></p></div>\");document.body.scrollTop = document.documentElement.scrollHeight;")
|
9f17d59e
陈明泉
no message
|
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
|
.arg(head)
.arg(msg);
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
// showMsgViwe->page()->mainFrame()->setScrollBarValue(Qt::Vertical,showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));
}
void GotyeMsg::RevMsgShow(QString msg,QString head)
{
if(msg.indexOf("Call has no answer") > -1)
stringToHtml(msg,Qt::red);
else
stringToHtmlFilter(msg);
// qDebug("CMQ IMG head = %s......\n",head.toLatin1().data());
// qDebug("CMQ RevMsgShow msg = %s...\n",msg.toLatin1().data());
|
6e10e93e
陈明泉
no message
|
716
|
QString html = QString("document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='divotherhead' style='float: left;'> <img src=\'%1\' style='width:45px;height:45px'> </p><p class='triangle-left left'>%2</p></div>\");document.body.scrollTop = document.documentElement.scrollHeight;")
|
9f17d59e
陈明泉
no message
|
717
718
719
720
721
|
.arg(head)
.arg(msg);
showMsgViwe->page()->mainFrame()->evaluateJavaScript(html);
// showMsgViwe->page()->mainFrame()->setScrollBarValue(Qt::Vertical,showMsgViwe->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));
}
|