2 Star 0 Fork 0

cmcim/upush2-qt-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
widget.cpp 4.33 KB
一键复制 编辑 原始数据 按行查看 历史
lzk 提交于 2022-07-19 23:48 . 推送消息内容自动释放
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#define APP_ID "d21085fc"
#define APP_KEY "f8bfc7de014a41ef7e35db6c35fd0b39"
#define PACKAGE_NAME "cn.com.upush.develop.qt.test"
#define UPUSH_HOST "192.168.6.132"
#define UPUSH_PORT 5488
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QPalette pe;
pe.setColor(QPalette::WindowText, QColor("#F56C6C"));
ui->statusLabel->setPalette(pe);
ui->netComboBox->addItem("UDP");
ui->netComboBox->addItem("TCP");
ui->netComboBox->setCurrentIndex(0);
ui->hostEdit->setText(UPUSH_HOST);
ui->portEdit->setText(QString("%1").arg(UPUSH_PORT));
connect(this, &Widget::comitText, this, &Widget::onShowText);
m_client = new UPush2Client();
m_client->configUPush(PACKAGE_NAME, APP_ID, APP_KEY, this);
}
Widget::~Widget()
{
delete ui;
delete m_client;
}
void Widget::on_registerButton_clicked()
{
if(m_client->getStatus() == STATUS_LOGIN_SUCCEED){
return;
}
m_client->setNetworkType(ui->netComboBox->currentIndex());
m_client->registerUPush(ui->hostEdit->text().toStdString(), ui->portEdit->text().toInt());
}
void Widget::on_bindButton_clicked()
{
QString userId = ui->bindEdit->text();
if(!userId.isEmpty()){
m_client->bindUser(userId.toStdString());
}
}
void Widget::on_pauseButton_clicked()
{
m_client->pause();
}
void Widget::on_resumeButton_clicked()
{
m_client->resume();
}
void Widget::on_unregButton_clicked()
{
m_client->unregisterUPush();
}
void Widget::on_clearButton_clicked()
{
ui->textBrowser->clear();
}
void Widget::onShowText(const QString & msg)
{
ui->textBrowser->insertPlainText(msg);
ui->textBrowser->insertPlainText("\n");
}
void Widget::onPushToken(int code, const char* pushToken, const char* userId)
{
qDebug() << "onPushToken" << pushToken << code << userId;
if(code == 0){
if(userId != nullptr){
ui->bindEdit->setText(QString("%1").arg(userId));
}else{
ui->bindEdit->setText("");
}
emit comitText(QString("[onPushToken] %1").arg(pushToken));
}else{
emit comitText(QString("[onPushToken] %1").arg(code));
}
}
void Widget::onPush(char* data, uint64_t pushTime, bool isOfflineMsg)
{
qDebug() << "onPush" << data << pushTime << isOfflineMsg;
emit comitText(QString("[onPush] %1").arg(data));
}
void Widget::onUnregister()
{
qDebug() << "onUnregister";
emit comitText("[onUnregister]");
}
void Widget::onRegisteredOnAnotherDevice(const char* info)
{
qDebug() << "onRegisteredOnAnotherDevice" << info;
emit comitText(QString("[onRegisteredOnAnotherDevice] %1").arg(info));
}
void Widget::onRevoke(const char* data, uint64_t revokeTime)
{
qDebug() << "onRevoke" << data << revokeTime;
emit comitText(QString("[onRevoke] %1").arg(data));
}
void Widget::onBindUser(int status)
{
qDebug() << "onBindUser" << status;
emit comitText(QString("[onBindUser] %1").arg(status == 0 ? "success" : "fail"));
}
void Widget::onStatusChanged(int status)
{
qDebug() << "onStatusChanged" << status;
switch (status) {
case STATUS_INIT:
ui->statusLabel->setText("初始");
break;
case GET_CONNECT_ADDRESS:
ui->statusLabel->setText("取得连接地址");
break;
case GET_CONNECT_ADDRESS_FAIL:
ui->statusLabel->setText("取得地址失败");
break;
case STATUS_CONNECTING:
ui->statusLabel->setText("正在连接");
break;
case STATUS_CONN_FAIL:
ui->statusLabel->setText("连接失败");
break;
case STATUS_LOGINING:
ui->statusLabel->setText("正在登陆");
break;
case STATUS_LOGIN_SUCCEED:
ui->statusLabel->setText("登陆成功");
break;
case STATUS_LOGIN_FAIL:
ui->statusLabel->setText("登陆失败");
break;
case STATUS_CLOSING:
ui->statusLabel->setText("正在关闭");
break;
case STATUS_LOGOUTING:
ui->statusLabel->setText("正在注销");
break;
case STATUS_LOGOUT_FAIL:
ui->statusLabel->setText("注销失败");
break;
case STATUS_CLOSED:
ui->statusLabel->setText("已经关闭");
break;
case STATUS_LOGOUT:
ui->statusLabel->setText("已注销");
break;
default:
break;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cmcim/upush2-qt-demo.git
git@gitee.com:cmcim/upush2-qt-demo.git
cmcim
upush2-qt-demo
upush2-qt-demo
master

搜索帮助