ishowmain.cpp 24 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 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 366 367 368 369 370 371 372 373 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 431 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 463 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 494 495 496 497 498 499 500 501 502 503 504 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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 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 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
#include "ishowmain.h"
#include "ui_main.h"
#include "ui_incomingcall.h"
#include "ui_homecenter.h"
#include "iwebrequest.h"
#include <QDebug>
#include <QApplication>
#include <QStackedWidget>
#include "isettingwidget.h"
#include <QLibrary>
#include <QFile>
#include <QTimer>
#include <QMessageBox>
#include <QDateTime>
#include <QDesktopServices>
#include <QUrl>

#include "userinfotip.h"
#include "downloadfile.h"

#include <QtWebKitWidgets>
#include "mywidget.h"

#include "GlobalSetting.h"
#include "gotyecpp/gotyemsg.h"

IShowMain::IShowMain(QWidget *parent) :
    QWidget(parent)
    ,ui(new Ui::IShowMain)
    ,uiHome(new Ui::HomeCenterWidget),
    uiIncoming(new Ui::IncomingCallWidget)
{
    userInfoTip = NULL;

    ui->setupUi(this);
    connect(ui->pushButtonMin, SIGNAL(clicked()), this, SIGNAL(hideMain()));

    connect(ui->pushButtonClose, SIGNAL(clicked()), parent, SLOT(on_pushButtonClose_clicked()));

    connect(ui->pushButtonMax, SIGNAL(clicked()), this, SIGNAL(showMainMax()));

    connect(ui->pushButtonMenuHome, SIGNAL(clicked()), SLOT(showHome()));
    connect(ui->pushButtonCourses, SIGNAL(clicked()), SLOT(showCourses()));
    connect(ui->pushButtonCourses, SIGNAL(clicked()), this, SLOT(buttonChecked()));
    ui->pushButtonCourses->setFocusPolicy(Qt::NoFocus);
//    ui->pushButtonCourses->hide();

    connect(ui->pushButtonMenuHome, SIGNAL(clicked()), this, SLOT(buttonChecked()));
    connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), this, SLOT(buttonChecked()));
   // connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), this, SLOT(showIncomingCall()));

    //界面置顶切换需要的配置
    //InitAPIVar();

    ui->pushButtonMenuHome->setChecked(true);
    currentButton =  ui->pushButtonMenuHome;
    QWidget *centerHome = new QWidget();
    uiHome->setupUi(centerHome);

    QWidget *centerCalling = new QWidget();
    uiIncoming->setupUi(centerCalling);

    ishowCourses = new IshowCourses(this);
    connect(this, SIGNAL(showMainMax()), ishowCourses, SLOT(showMainMaximized()));

    uiChatArea = new Ui::msgChatArea();
    centerChatArea = new QWidget();
    uiChatArea->setupUi(centerChatArea);
    QFile source(":Images/style/styleMsg.html");
//    QFile source("D:/QTest/jquery-lightbox-0.5/styletest.html");
    source.open(QIODevice::ReadOnly);
    uiChatArea->webView->setHtml(QString::fromUtf8(source.readAll().constData()));
    source.close();
    uiChatArea->textEdit->installEventFilter(this);
    uiChatArea->pushButton->setFocusPolicy(Qt::NoFocus);
    uiChatArea->webView->setFocusPolicy(Qt::NoFocus);
    uiChatArea->listWidget->setFocusPolicy(Qt::NoFocus);
    uiChatArea->pushButton_expression->hide();
    GotyeMsg::Instance()->setUpdataUserList(uiChatArea->listWidget);

    centerChatArea->setStyleSheet("background-color:rgba(255,255,255);");

    connect(uiChatArea->listWidget,SIGNAL(itemCliLeftChanged()),this,SLOT(showNowChat()));
    //msgChatAreaInit();
    nowUser.name = "0";

    connect(uiChatArea->pushButton_picture, SIGNAL(clicked()), SLOT(on_pushButton_picture_clicked()));
    connect(uiChatArea->pushButton, SIGNAL(clicked()), SLOT(on_pushButton_clicked()));
    connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), SLOT(showChatArea()));
    connect(uiChatArea->listWidget, SIGNAL(deleteItem(QListWidgetItem *)), SLOT(delItemChat(QListWidgetItem *)));

    stack = new QStackedWidget(this);

    stack->insertWidget(ISTACK_HOME, centerHome);
    stack->insertWidget(ISTACK_INCOMING, centerCalling);
    stack->insertWidget(ISTACK_MESSAGE, centerChatArea);
    stack->insertWidget(ISTACK_COURSE, ishowCourses);
    stack->setCurrentIndex(ISTACK_HOME);
    StackItemNum = ISTACK_HOME;
    connect(uiIncoming->pushButtonAccept, SIGNAL(clicked()), this, SIGNAL(acceptCalling()));
    connect(uiIncoming->pushButtonDecline, SIGNAL(clicked()), this, SIGNAL(repulseCalling()));

    setting = new ISettingWidget();
    connect(ui->pushButtonSetting, SIGNAL(clicked()), this, SLOT(showSetting()));

    //上线
    connect(uiHome->pushButtonOnline2, SIGNAL(clicked()), SLOT(on_pushButtonOnline_clicked()));
    ui->verticalLayoutCenter->addWidget(stack);

    IWebRequest *webrequest = IWebRequest::Instance();
    connect(webrequest, SIGNAL(response(int,int,QString,QString)), this, SLOT(doResponse(int,int,QString,QString)));


    onlineButton = new QPushButton(ui->widgetLeft);
    onlineButton->setGeometry(58, 68, 12, 12);
    onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;");


    hideTipTimer = new QTimer(this);
    userInfoTip = new UserInfoTip();
    connect(ui->label_header_img, SIGNAL(mouseIn()), this, SLOT(showUserTip()));
    connect(ui->label_header_img, SIGNAL(mousePress()), this, SLOT(showUserTip()));
    connect(ui->label_header_img, SIGNAL(mouseOut()), this, SLOT(hideUserTip()));

    connect(hideTipTimer, SIGNAL(timeout()), userInfoTip, SLOT(hide()));
    hideTipTimer->setInterval(500);

    connect(userInfoTip, SIGNAL(mouseIn()), this, SLOT(showUserTip()));
    connect(userInfoTip, SIGNAL(mouseOut()), this, SLOT(hideUserTip()));

    //未读信息
    newMsg = new QLabel(ui->widgetLeft);
    newMsg->setGeometry(50,155,20,20);
    newMsg->hide();
    GotyeMsg::Instance()->setShowMsgNum(newMsg);

    //loading
    loadTimer = new QTimer(this);
    loadTimer->setSingleShot(true);
    loadTimer->setInterval(30*1000);
    connect(loadTimer, SIGNAL(timeout()), this, SLOT(loginLoading()));

    //login Status Timer
    loginStatusTimer = new QTimer(this);
    loginStatusTimer->setInterval(60*1000*5);
    connect(loginStatusTimer, SIGNAL(timeout()), this, SLOT(initUserInfo()));
    loginStatusTimer->start();

}

static void ChMessageOnlyOk_Error(QString info)
{
    QMessageBox msg;
    msg.setWindowTitle("Warning");
    msg.setText(info);
    msg.setStyleSheet("font: 10pt;background-color:rgb(255, 255, 255)");
    msg.setIcon(QMessageBox::Critical);
    msg.addButton("I SEE",QMessageBox::ActionRole);
    msg.exec();
}

#include "GlobalSetting.h"
void IShowMain::initUserInfo()
{
    QStringList params;
    IWebRequest::Instance()->sendRequestToServer(REQ_USER_TEACHER_GET, params);
}

void IShowMain::showUserTip()
{
    hideTipTimer->stop();
    if(!userInfoTip)
    {
        userInfoTip = new UserInfoTip();
    }
    userInfoTip->setVisible(true);

//    QString headerImg = QCoreApplication::applicationDirPath()+"/img/"+_GlobalSetting.userHeadImg.file_name +_GlobalSetting.userHeadImg.ext;
//    userInfoTip->setHeaderImg(headerImg);

    QPoint point = mapToGlobal(ui->label_header_img->pos()+QPoint(ui->label_header_img->size().width()/2, ui->label_header_img->size().height()/2));
    userInfoTip->move(point);

//    WId id = userInfoTip->winId();
//    showWindowFront(id);

}

void IShowMain::hideUserTip()
{
    hideTipTimer->start();
}

void IShowMain::loginLoading()
{
    QMessageBox::warning( this , "Failed","Please check if the network is normal!" );
    uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);");
    uiHome->pushButtonOnline2->setEnabled(true);
    uiHome->pushButtonOnline2->setText("Go Online");
    onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;");
}

void IShowMain::doResponse(int cmd,int code,QString ,QString result)
{
    switch(cmd)
    {
    case REQ_USER_ONLINE:
    {
        if(loadTimer->isActive())
            loadTimer->stop();
        uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_online.png);");
        uiHome->pushButtonOnline2->setEnabled(true);
        uiHome->pushButtonOnline2->setText("Go Offline");
        onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_online.png); background: transparent;");
        break;
    }
    case REQ_USER_OFFLINE:
    {
        if(loadTimer->isActive())
            loadTimer->stop();
        uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);");
        uiHome->pushButtonOnline2->setEnabled(true);
        uiHome->pushButtonOnline2->setText("Go Online");
        onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;");
        break;
    }
    case REQ_LOGOUT:
    {
        uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);");
        uiHome->pushButtonOnline2->setEnabled(true);
        uiHome->pushButtonOnline2->setText("Go Online");
        onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;");
        break;
    }
    case REQ_USER_GET:
    {
        qDebug() << "void IShowMain::doResponse(int cmd,int code,QString ,QString)";
        if(!GotyeMsg::Instance()->isLogin)
            GotyeMsg::Instance()->login(QString("%1").arg(_GlobalSetting.userInfo.uid));

        headerImg = QCoreApplication::applicationDirPath()+"/img/"+_GlobalSetting.userHeadImg.file_name +_GlobalSetting.userHeadImg.ext;

        GotyeMsg::Instance()->setMyUid(_GlobalSetting.userInfo.uid);
        qDebug() << "CMQ:show headerImg = "<<headerImg;
        if(_GlobalSetting.teacher.crown)
        {
            onlineButton->setGeometry(58, 93, 12, 12);
            newMsg->setGeometry(50,180,20,20);
            ui->label_crown->show();
        }
        else
        {
            onlineButton->setGeometry(58, 68, 12, 12);
            newMsg->setGeometry(50,155,20,20);
            ui->label_crown->hide();
        }


        QFile file(headerImg);
        if(_GlobalSetting.userHeadImg.size > 1 && file.exists() && file.size() > 1024)
        {
            ui->label_header_img->setPixmap(QPixmap(headerImg).scaled(54,54));

            if(userInfoTip)
                userInfoTip->setHeaderImg(headerImg);
            GotyeMsg::Instance()->setMyHeadImg(QString(imgTitle) + headerImg);

        }
        else
        {
            qDebug() << "CMQ:not found headerImg...";
            if(file.exists())
                file.remove();
            GotyeMsg::Instance()->setMyHeadImg(QString(defaultHeadimg));
            IDownloadFile *downfile = IDownloadFile::Instance();
            downfile->downloadFile(_GlobalSetting.userHeadImg.s_url, headerImg, _GlobalSetting.userHeadImg.file_id);
        }
        QTimer::singleShot(3*1000,this,SLOT(setHeadImg()));

        if(userInfoTip)
        {
            float evaluation_total = _GlobalSetting.teacher.evaluation_total/1.0;
            QString balance;
            balance.sprintf("%.2f", _GlobalSetting.credits.credits);
            uiHome->labelBalanceValue->setText(balance);
            userInfoTip->setName(_GlobalSetting.userInfo.user_name.section(' ', 0, 0));
            if(evaluation_total > 0.001)
                userInfoTip->setEvaluation(evaluation_total/_GlobalSetting.teacher.evaluation_times);
            userInfoTip->setCallTime( _GlobalSetting.userInfo.call_time);
//            qDebug("_GlobalSetting.userInfo.call_time %d...evaluation_total = %f\n",_GlobalSetting.userInfo.call_time,evaluation_total);
        }
        break;
    }
    case REQ_USER_TEACHER_GET:
    {
        if(userInfoTip)
        {
            float evaluation_total = _GlobalSetting.teacher.evaluation_total/1.0;
            QString balance;
            balance.sprintf("%.2f", _GlobalSetting.credits.credits);
            uiHome->labelBalanceValue->setText(balance);
            if(evaluation_total > 0.001 && _GlobalSetting.teacher.evaluation_times > 0)
                userInfoTip->setEvaluation(evaluation_total/_GlobalSetting.teacher.evaluation_times);
            userInfoTip->setCallTime( _GlobalSetting.userInfo.call_time);
            qDebug("_GlobalSetting.userInfo.call_time %d...evaluation_total = %f\n",_GlobalSetting.userInfo.call_time,evaluation_total);
        }

        if(_GlobalSetting.teacher.online == 3)
        {
            if(!uiHome->pushButtonOnline2->text().contains("Online"))
            {
                on_pushButtonOnline_clicked();
                ChMessageOnlyOk_Error("You have been moved offline for not answering. Please click 'go online' to get online.");
            }
        }

        break;
    }
    //通话课程
    case REQ_USER_COURSE_CALL_GET:
    {
        QJsonParseError jsonErr;
        QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr);
        QJsonArray pptarray = myjsonDoc1.object().find("result").value().toObject().find("ppt").value().toArray();
        QJsonObject courseInfo = myjsonDoc1.object().find("result").value().toObject().find("courseInfo").value().toObject();
        uiIncoming->course->show();
        uiIncoming->course->setText(courseInfo.find("content").value().toString());
        qDebug()<<"course: "<<courseInfo.find("course").value().toString()<<courseInfo.find("content").value().toString();
//        ui->widgetLeft->hide();
        stack->setCurrentIndex(ISTACK_INCOMING);
        break;
    }
    case REQ_USER_REMARK_GET:
    {
        QJsonParseError jsonErr;
        QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr);
        QJsonObject remark = myjsonDoc1.object().find("result").value().toObject().find("remark").value().toObject();
        QString name = QString("");
        if(remark.size())
            name = myjsonDoc1.object().find("result").value().toObject().find("remark").value().\
                    toObject().find("remark_name").value().toString();
        else
            name = myjsonDoc1.object().find("result").value().toObject().find("userInfo").value().\
                    toObject().find("user_name").value().toString();
//        qDebug()<<"result: "<<result<<"\n";
        uiIncoming->label_name->setText(name);
        break;
    }
    case REQ_USER_MSG_REMARK_GET:
    {
        QJsonParseError jsonErr;
        QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr);
        QJsonObject remark = myjsonDoc1.object().find("result").value().toObject().find("remark").value().toObject();
        QString name = QString("");
        if(remark.size())
            name = myjsonDoc1.object().find("result").value().toObject().find("remark").value().\
                    toObject().find("remark_name").value().toString();
        else
            name = myjsonDoc1.object().find("result").value().toObject().find("userInfo").value().\
                    toObject().find("user_name").value().toString();
        qDebug()<<"result: "<<result<<"\n";
        uiChatArea->label->setText(name);
        break;
    }
    case REQ_USER_ORDER_GET:
    {
        QJsonParseError jsonErr;
        QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr);
        QJsonObject order = myjsonDoc1.object().find("result").value().toObject().find("orderInfo").value().toObject();
        theOrderRank.setOrder(order.find("peso").value().toDouble());
        theOrderRank.setHeaderImg(headerImg);

        QStringList paramsRank;
        IWebRequest::Instance()->sendRequestToServer(REQ_USER_ORDER_EARNING_RANK, paramsRank);
    }
    case REQ_USER_ORDER_EARNING_RANK:
    {
        QJsonParseError jsonErr;
        QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr);
        QJsonArray order = myjsonDoc1.object().find("result").value().toObject().find("lists").value().toArray();
        theOrderRank.setEarningsRank(order);

        initUserInfo();
//        QStringList params;
//        IWebRequest::Instance()->sendRequestToServer(REQ_USER_GET, params);
    }
    default:
        break;
    }
}

void IShowMain::setHeadImg()
{
    QFile HeadImg(headerImg);
    if(_GlobalSetting.userHeadImg.size > 1 && HeadImg.exists() && HeadImg.size() > 1024)
    {
        ui->label_header_img->setPixmap(QPixmap(headerImg).scaled(54,54));

        if(userInfoTip)
            userInfoTip->setHeaderImg(headerImg);
        GotyeMsg::Instance()->setMyHeadImg(QString(imgTitle) + headerImg);
    }
    qDebug()<<"setHeadImg....";
}

void IShowMain::on_pushButtonOnline_clicked()
{
    QStringList params;
    if(uiHome->pushButtonOnline2->text().contains("Online"))
    {
        //1:在线 2:忙碌 3:离线
        params << "1";
        IWebRequest::Instance()->sendRequestToServer(REQ_USER_ONLINE, params);
    }
    else
    {
        //1:在线 2:忙碌 3:离线
        params << "3";
        IWebRequest::Instance()->sendRequestToServer(REQ_USER_OFFLINE, params);
    }
    loadTimer->start();
    uiHome->pushButtonOnline2->setText("Loading...");
    uiHome->pushButtonOnline2->setEnabled(false);
    qDebug()<< "void IShowMain::on_pushButtonOnline_clicked()";
}

void IShowMain::buttonChecked()
{
    changeCurrentButton((QPushButton*)sender());
}

void IShowMain::showSetting()
{
    if(setting->isVisible())
    {
        setting->hide();
        setting->show();
    }
    else
        setting->show();
    //WId id = setting->winId();
    //showWindowFront(id);
}

void IShowMain::showWindowFront(WId id)
{
//    bool ret = InitAPIVar() ;
//    if(ret)
//    {
//        AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), true) ;
//        SetForegroundWindow(id);
//        SetFocus(id) ;
//        AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), false) ;
//    }
}

void IShowMain::changeCurrentButton(QPushButton* button)
{
    if(currentButton != NULL && button != NULL)
    {
        if(button != currentButton)
        {
            currentButton->setChecked(false);
            currentButton = button;
        }
    }
    currentButton->setChecked(true);
}

void IShowMain::setPushButtonEnabled(bool flag)
{
    if(flag)
    {
        ui->pushButtonMenuHome->setEnabled(true);
        ui->pushButtonMenuMessage->setEnabled(true);
        ui->pushButtonCourses->setEnabled(true);
    }
    else
    {
        ui->pushButtonMenuHome->setEnabled(false);
        ui->pushButtonMenuMessage->setEnabled(false);
        ui->pushButtonCourses->setEnabled(false);
    }
}

/**
 * 显示来电信息
 * @brief IShowMain::showIncomingCall
 * @param uid
 * @param img
 * @param course_id
 */
void IShowMain::showIncomingCall(const QString uid,const QString img,int course_id)
{

    if(uiHome->pushButtonOnline2->text().contains("Online"))
        return;
    setPushButtonEnabled(false);
    ui->widgetLeft->hide();

    if(img.size() > 5)
    {
        uiIncoming->webView->load(QUrl(img));
        uiIncoming->webView->show();
        uiIncoming->label_header->hide();
    }
    else
    {
        uiIncoming->label_header->show();
        uiIncoming->webView->hide();
    }

    m_callUid = uid;
//    uiIncoming->label_name->setText(name);
    QStringList getRemark;
    getRemark.append(uid);
    IWebRequest::Instance()->sendRequestToServer(REQ_USER_REMARK_GET, getRemark);

    if(course_id > 0)
    {
        QStringList params;
        params.append(QString("%1").arg(course_id));
        IWebRequest::Instance()->sendRequestToServer(REQ_USER_COURSE_CALL_GET, params);
//        qDebug()<<"CoursesId = "<<params.at(0);
    }
    else
    {
//        ui->widgetLeft->hide();
        stack->setCurrentIndex(ISTACK_INCOMING);
        uiIncoming->course->hide();
    }

    qDebug("CMQ fileName = %s filePath = %s course_id = %d",uid.toLatin1().data(),img.toLatin1().data(),course_id);
}

void IShowMain::overCallEnd(QString callId)
{
    if(callId.size() > 0)
    {
        m_callId = callId;
        QTimer::singleShot(3*1000,this,SLOT(getOrderEarningRank()));
    }
    qDebug()<<"overCallEnd callId = "<<callId;
}
void IShowMain::getOrderEarningRank()
{
    QStringList params;
    params.append(m_callId);
    IWebRequest::Instance()->sendRequestToServer(REQ_USER_ORDER_GET, params);

    if(m_callTimeSec >= 590)
    {
        QStringList params;
        params.append(m_callUid);
        params.append(m_callId);
        IWebRequest::Instance()->sendRequestToServer(REQ_USER_REVIWE_CREATE, params);
        theOrderRank.setMemeoPrompts(true);
    }
    else
    {
        theOrderRank.setMemeoPrompts(false);
    }
    qDebug()<<"m_callTimeSec = "<<m_callTimeSec;
}

//创建评语
void IShowMain::review_create(int callTimeSec)
{
    m_callTimeSec = callTimeSec;
    qDebug()<<"review_create = "<<m_callTimeSec;
}

void IShowMain::showHome()
{
    stack->setCurrentIndex(ISTACK_HOME);
    StackItemNum = ISTACK_HOME;
    GotyeMsg::Instance()->setIsUpdata(false);
}

void IShowMain::showCourses()
{
    stack->setCurrentIndex(ISTACK_COURSE);
    StackItemNum = ISTACK_COURSE;
    GotyeMsg::Instance()->setIsUpdata(false);
    ishowCourses->go_now_courses();
}


void IShowMain::showStackItem()
{
    ui->widgetLeft->show();
    if(StackItemNum == ISTACK_HOME)
        showHome();
    else if(StackItemNum == ISTACK_MESSAGE)
        showChatArea();
    else if(StackItemNum == ISTACK_COURSE)
        showCourses();
}

void IShowMain::delItemChat(QListWidgetItem *item)
{
    GotyeMsg::Instance()->delItemChat(item);
}

void IShowMain::showChatArea()
{
    stack->setCurrentIndex(ISTACK_MESSAGE);
    StackItemNum = ISTACK_MESSAGE;

    uiChatArea->textEdit->clear();
    uiChatArea->textEdit->activateWindow();
    uiChatArea->textEdit->setFocus();

    GotyeMsg::Instance()->setShowMsgWebviwe(uiChatArea->webView);
    GotyeMsg::Instance()->setUpdataUserList(uiChatArea->listWidget);
    GotyeMsg::Instance()->setShowUserName(uiChatArea->label);
    GotyeMsg::Instance()->setIsUpdata(true);

//    if(atoi(nowUser.name.data()) > 0)
    GotyeMsg::Instance()->showLastChatArea(nowUser);
    GotyeMsg::Instance()->msgChatAreaInit();

    qDebug("CMQ showChatArea...\n");
}


void IShowMain::on_pushButtonDecline_clicked()
{

    showStackItem();
    emit repulseCalling();//拒绝来电
    qDebug("CMQ repulseCalling...\n");
}

void IShowMain::showNowChat()
{
    nowUser = GotyeMsg::Instance()->setChooseUser(uiChatArea->listWidget->currentRow());
    QStringList getRemark;
    qDebug()<<"nowUser.name.data():"<<nowUser.name.data();
    getRemark.append(nowUser.name.data());
    IWebRequest::Instance()->sendRequestToServer(REQ_USER_MSG_REMARK_GET, getRemark);
}

void IShowMain::delgoty()
{
    GotyeMsg::Instance()->apiist_exit();
}


void IShowMain::on_pushButton_clicked()
{
//    QDesktopServices::openUrl(QUrl("http://www.baidu.com"));   //打开默认浏览器 跳转到

    if(GotyeMsg::Instance()->getNowUserName().toInt() == 0)
        return;
    if( uiChatArea->textEdit->toPlainText() == NULL )
    {
        QMessageBox::warning( this , "warning","Message to be sent cannot be empty!" );
        return;
    }
    //自己发送的消息

    GotyeMsg::Instance()->sendMessage(QString(nowUser.name.data()),uiChatArea->textEdit->toPlainText(),GotyeMessageTypeText);
//    msgChatAreaInit();//刷新聊天列表

    uiChatArea->textEdit->clear();
    uiChatArea->textEdit->activateWindow();
    uiChatArea->textEdit->setFocus();
}
void IShowMain::on_pushButton_picture_clicked()
{

    if(GotyeMsg::Instance()->getNowUserName().toInt() == 0)
        return;

    QFileDialog::Options options;
    //if (!native->isChecked())
        options |= QFileDialog::DontUseNativeDialog;
    QString selectedFilter,openFilesPath;
    QStringList files = QFileDialog::getOpenFileNames(
                                this, tr("QFileDialog::getOpenFileNames()"),
                                openFilesPath,
                                tr("Images (*.png *.bmp *.jpg)"),
                                &selectedFilter,
                                options);
    if (files.count())
    {
        for(int i = 0;i < files.count();i++)
        {
            GotyeMsg::Instance()->sendMessage(QString("%1").arg(nowUser.name.data()), files[i],GotyeMessageTypeImage);
            qDebug("CMQ openFile = %s...\n",files[i].toLatin1().data());
//            SendImageShow(files[i],Myhead);
        }
    }
}

bool IShowMain::eventFilter(QObject *obj, QEvent *e)
{
//    Q_ASSERT(obj == inputTextEdit);
    if (e->type() == QEvent::KeyPress)
    {
        QKeyEvent *event = static_cast<QKeyEvent*>(e);
        if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && (event->modifiers() & Qt::ControlModifier))
        {
            uiChatArea->textEdit->append("");
//            on_pushButton_clicked(); //发送消息的槽
            return true;
        }
        else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
        {
            on_pushButton_clicked(); //发送消息的槽
            return true;
        }
    }
    return false;
}