Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
arjide committed Oct 29, 2014
1 parent bd5aa9a commit 079de3d
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 30 deletions.
2 changes: 1 addition & 1 deletion images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<file>images/inputBox-password-hover.svg</file>
<file>images/inputBox-qq-clicked.svg</file>
<file>images/inputBox-qq-hover.svg</file>
<file>images/invisible.png</file>
<file>images/imhidden.png</file>
<file>images/list_arrow_down.png</file>
<file>images/list_arrow_up.png</file>
<file>images/list_item.png</file>
Expand Down
File renamed without changes
16 changes: 11 additions & 5 deletions qml/Api/QQApi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ QQ{
property string list_hash//获取好友列表时需要的hash
property string ptwebqq//登录后返回的cookie

signal closeMainPanel//如果需要从头重新登录就关闭主面板

windowScale: {
var dosktopWidth = Screen.desktopAvailableWidth
if(dosktopWidth<=1366)
Expand Down Expand Up @@ -130,6 +132,12 @@ QQ{
loginReData = data.result//将数据记录下来
var poll2data = 'r={"clientid":"'+clientid+'","psessionid":"'+loginReData.psessionid+'","key":0,"ids":[]}&clientid='+clientid+'&psessionid='+loginReData.psessionid
myqq.startPoll2(encodeURI(poll2data))//启动心跳包的post
}else{
console.debug("重新登录失败")
showWarningInfo("QQ已掉线,请重新登录")
root.closeChatWindow();//关闭聊天窗口
root.closeMainPanel();//关闭主面板
utility.loadQml("qml/Login/main.qml")//打开登录面板
}
}

Expand Down Expand Up @@ -265,11 +273,9 @@ QQ{
return
}

if( loginStatus == QQ.LoginFinished ) {
data = JSON.parse(data)
if( data.retcode==0&&data.result=="ok" ){
console.log("状态改变成功")
}
data = JSON.parse(data)
if( data.retcode==0&&data.result=="ok" ){
console.log("状态改变成功")
}
}

Expand Down
10 changes: 5 additions & 5 deletions qml/Login/LoginPanel/LoginPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,35 @@ Item{
}
MyMenuItem{
text: "Q我吧"
icon: "qrc:/images/Qme.png"
icon: "qrc:/images/imcallme.png"
onTriggered: {
myqq.state = QQ.Callme
}
}
MyMenuItem{
text: "离开"
icon: "qrc:/images/away.png"
icon: "qrc:/images/imaway.png"
onTriggered: {
myqq.state = QQ.Away
}
}
MyMenuItem{
text: "忙碌"
icon: "qrc:/images/busy.png"
icon: "qrc:/images/imbusy.png"
onTriggered: {
myqq.state = QQ.Busy
}
}
MyMenuItem{
text: "请勿打扰"
icon: "qrc:/images/mute.png"
icon: "qrc:/images/imsilent.png"
onTriggered: {
myqq.state = QQ.Silent
}
}
MyMenuItem{
text: "隐身"
icon: "qrc:/images/invisible.png"
icon: "qrc:/images/imhidden.png"
onTriggered: {
myqq.state = QQ.Hidden
}
Expand Down
1 change: 1 addition & 0 deletions qml/Login/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ MyWindow{
onLoginStatusChanged:{
if(myqq.loginStatus == QQ.LoginFinished){
main.close()
main.deleteWindow();//销毁自己
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion qml/MainPanel/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ MyWindow{
}
}

Connections{
target: myqq
onCloseMainPanel:{//如果需要重新登录
main.close()
main.deleteWindow();//销毁自己
}
}

Text{
anchors.centerIn: parent
text: "已离线"
Expand All @@ -75,7 +83,10 @@ MyWindow{
anchors.margins: 10
MouseArea{
anchors.fill: parent
onClicked: Qt.quit()
onClicked: {
myqq.state = QQ.Offlineing//将状态改为离线
Qt.quit()
}
}
}
SvgView{
Expand Down
63 changes: 54 additions & 9 deletions qml/Utility/MyWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -285,27 +285,72 @@ MyQuickWindow{
anchors.centerIn: parent
width: root.actualWidth
height: root.actualHeight
//running: true
Age{
system: particles
anchors.left: parent.left
height: parent.height
width: 80
once: true
lifeLeft: 3000
advancePosition: false

}
Age{
system: particles
anchors.right: parent.right
height: parent.height
width: 80
once: true
lifeLeft: 3000
advancePosition: false

}

Age{
system: particles
anchors.bottom: parent.bottom
height: 80
width: parent.width
once: true
lifeLeft: 3000
advancePosition: false

}

ImageParticle {
source: "qrc:/images/blueStar.png"
source: "qrc:/images/star.png"
groups: ['star']
alpha: 0.2
alphaVariation: 0.1
colorVariation: 2
autoRotation: true
rotationVariation: 360
rotationVelocity: 30
rotationVelocity: 40
}
Emitter {
id: pulseEmitter
anchors.centerIn: parent
emitRate: 20
lifeSpan: 4000
anchors.top: parent.top
width: parent.width
group: 'star'
emitRate: 8
lifeSpan: parent.height*1000/40
velocityFromMovement: 20
velocity: PointDirection { xVariation: 50; yVariation: 50;}
acceleration: PointDirection { xVariation:50; yVariation: 50;}
velocity: AngleDirection{
angle: 90
angleVariation: 50
magnitude: 90
magnitudeVariation: 10
}
acceleration: AngleDirection{
angle: -90
magnitude: 5
magnitudeVariation: 2
}
size: 20
sizeVariation: 10
sizeVariation: 5
endSize: 0
}

}
MouseArea{
id: mouse_main
Expand Down
10 changes: 5 additions & 5 deletions qml/Utility/SystemTray.qml
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,35 @@ MySystemTrayIcon{
}
MyMenuItem{
text: "Q我吧"
icon: "qrc:/images/Qme.png"
icon: "qrc:/images/imcallme.png"
onTriggered: {
myqq.state = QQ.Callme
}
}
MyMenuItem{
text: "离开"
icon: "qrc:/images/away.png"
icon: "qrc:/images/imaway.png"
onTriggered: {
myqq.state = QQ.Away
}
}
MyMenuItem{
text: "忙碌"
icon: "qrc:/images/busy.png"
icon: "qrc:/images/imbusy.png"
onTriggered: {
myqq.state = QQ.Busy
}
}
MyMenuItem{
text: "请勿打扰"
icon: "qrc:/images/mute.png"
icon: "qrc:/images/imsilent.png"
onTriggered: {
myqq.state = QQ.Silent
}
}
MyMenuItem{
text: "隐身"
icon: "qrc:/images/invisible.png"
icon: "qrc:/images/imhidden.png"
onTriggered: {
myqq.state = QQ.Hidden
}
Expand Down
5 changes: 5 additions & 0 deletions src/mywidgets/mywindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,8 @@ void MyWindow::close()
QQuickWindow::close ();
}

void MyWindow::deleteWindow()
{
deleteLater ();//销毁自己
}

1 change: 1 addition & 0 deletions src/mywidgets/mywindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public slots:
void setMousePenetrate(bool arg);

void close();
void deleteWindow();
};

#endif // MYWINDOW_H
68 changes: 64 additions & 4 deletions src/qqstars/qqstars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ QQCommand::QQCommand(QQuickItem *parent) :

jsEngine = new QJSEngine();//此对象用来加载js文件(为qq提供api)
loadApi ();//加载api的js文件

reply = NULL;
poll2Timerout_count=0;//记录网络请求的连续超时次数
poll2Error_count=0;//记录网络请求连续出错的次数
connect (utility, &Utility::networkOnlineStateChanged, this, &QQCommand::onNetworkOnlineStateChanged);
poll2_timer = new QTimer(this);
poll2_timer->setSingleShot (true);//设置为单发射器
connect (poll2_timer, &QTimer::timeout, this, &QQCommand::onPoll2Timeout);
abortPoll_timer = new QTimer(this);
abortPoll_timer->setSingleShot (true);//设置为单发射器
}

QQCommand::LoginStatus QQCommand::loginStatus() const
Expand Down Expand Up @@ -89,11 +99,18 @@ QString QQCommand::codeText() const

void QQCommand::beginPoll2()
{
manager->post (*request, poll2_data);
disconnect (abortPoll_timer, &QTimer::timeout, reply, &QNetworkReply::abort);
//qDebug()<<"reply1:"<<reply;
reply=manager->post (*request, poll2_data);
//qDebug()<<"reply2:"<<reply;
connect (abortPoll_timer, &QTimer::timeout, reply, &QNetworkReply::abort);
poll2_timer->start (100000);//网络请求超时定时器
}

void QQCommand::poll2Finished(QNetworkReply *replys)
{
poll2_timer->stop ();//停止计算请求是否超时的计时器
//qDebug()<<"网络请求完成"<<replys->error ()<<replys->errorString ();
if(replys->error ()==QNetworkReply::NoError) {
QByteArray array = replys->readAll ();
emit poll2ReData (array);
Expand Down Expand Up @@ -154,11 +171,17 @@ void QQCommand::poll2Finished(QNetworkReply *replys)
}
}else if(document.isArray ()){
QJsonArray arr = document.array ();
qDebug()<<arr.count ();
qDebug()<<"心跳包收到的是一个数组"<<arr.count ();
}
}
}else{
beginPoll2();//重新post
}else if(replys->error ()!=QNetworkReply::OperationCanceledError){//如果不是手动取消的
++poll2Error_count;
if(poll2Error_count>1){
qDebug()<<"网络请求连续出错"<<poll2Error_count<<"次,将重新登录";
poll2Error_count=0;
QMetaObject::invokeMethod (this, "reLogin");//调用槽reLogin重新登录(在qml中定义)
}else
beginPoll2();//重新post
}
}

Expand Down Expand Up @@ -206,6 +229,37 @@ void QQCommand::onStateChanged()
mysettings->setValue ("myState", (int)state());
}

void QQCommand::onPoll2Timeout()
{
++poll2Timerout_count;//记录网络请求的连续超时次数
qDebug()<<"网络请求超时:"<<poll2Timerout_count;
if(reply){
reply->abort ();//取消网络请求
}
beginPoll2 ();//再次开始网络请求
/*if(poll2Timerout_count>1){
poll2Timerout_count=0;
qDebug()<<"网络请求连续超时"<<poll2Error_count<<"次";
beginPoll2 ();//再次开始网络请求
//QMetaObject::invokeMethod (this, "reLogin");//调用槽reLogin重新登录(在qml中定义)
}else
beginPoll2 ();//再次开始网络请求*/
}

void QQCommand::onNetworkOnlineStateChanged(bool isOnline)
{
qDebug()<<"网络在线状态改变为:"<<isOnline;
if(isOnline){
abortPoll_timer->stop ();//停止计时器
if(!reply||!reply->isRunning ()){//如果心跳包没有在进行
qDebug()<<"由于断网影响,将重新登录qq";
QMetaObject::invokeMethod (this, "reLogin");//调用槽reLogin重新登录(在qml中定义)
}
}else{
abortPoll_timer->start (60000);//启动取消心跳包的定时器
}
}

void QQCommand::loadApi()
{
QString fileName = "qml/Api/api.js";
Expand Down Expand Up @@ -768,6 +822,12 @@ void QQCommand::openSqlDatabase()
FriendInfo::openSqlDatabase (userQQ());//打开数据库
}

void QQCommand::closeChatWindow()
{
if(!mainChatWindowCommand.isNull ())
mainChatWindowCommand->close ();
}

/*void QQCommand::saveAlias(int type, QString uin, QString alias)
{
QString name = QQItemInfo::typeToString ((QQItemInfo::QQItemType)type)+uin;
Expand Down
Loading

0 comments on commit 079de3d

Please sign in to comment.