forked from harry159821/XiamiForLinuxProject
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.py
121 lines (100 loc) · 4.22 KB
/
Main.py
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
#!/usr/bin/python
# -*- coding:utf-8 -*-
from PyQt4 import QtGui,QtCore,Qt
import sys,os
import mainWindows
import loginWindows
import xiamiApi
'''
Xiami For Linux Project
'''
class XiamiPlayer(QtCore.QObject):
def __init__(self):
super(XiamiPlayer, self).__init__()
self.app = QtGui.QApplication(sys.argv)
self.settings = QtCore.QSettings("setting.ini", QtCore.QSettings.IniFormat)
if self.settings.value('XiamiPlayer/cachePath',"") != "":
self.cachePath = self.settings.value('XiamiPlayer/cachePath',"").toString()
else:
self.settings.setValue('XiamiPlayer/cachePath',"./cache/")
self.cachePath = "./cache/"
self.loginWindow = loginWindows.LoginWindows()
self.loginWindow.inputEnd.connect(self.loginInputEnd)
self.loginWindow.validateInputEnd.connect(self.loginValidateInputEnd)
self.loginThread = LoginThread()
self.loginThread.loginOver.connect(self.checkLogin)
self.loginWindow.show()
self.loginWindow.setMailPwd(self.settings.value('XiamiPlayer/usermail',""),
self.settings.value('XiamiPlayer/pwd',""))
headfilename = (self.session.cachePath + self.session.usermail + '.png').toUtf8().data()
print headfilename
if os.path.exists(headfilename) and os.path.getsize(headfilename) > 0:
self.loginWindow.headLabel.setPixmap(QtGui.QPixmap(headfilename))
else:
self.loginWindow.headLabel.setPixmap(QtGui.QPixmap("default_user.ico"))
# self.mainWinow = mainWindows.MainWindow()
# self.mainWinow.show()
# Run
sys.exit(self.app.exec_())
def loginValidateInputEnd(self,validate):
self.loginThread.loginValidate(self.session,validate)
def loginInputEnd(self,mail,pwd):
print "self.cachePath:",self.cachePath
self.session = xiamiApi.loginSession(mail,pwd,self.cachePath)
self.loginThread.login(self.session)
def checkLogin(self,result):
self.result = result
if self.result == "needValidate":
self.loginWindow.inputValidate()
elif self.result == "emailPwdError":
self.loginWindow.emailPwdError()
elif self.result == "loginSuccess":
self.loginSuccess()
elif self.result == "noMailPwd":
self.loginWindow.emailPwdError()
def loginSuccess(self):
self.settings.setValue('XiamiPlayer/usermail',self.session.usermail)
self.settings.setValue('XiamiPlayer/pwd',self.session.password)
headfilename = (self.session.cachePath + self.session.usermail + '.png').toUtf8().data()
print headfilename
if os.path.exists(headfilename) and os.path.getsize(headfilename) > 0:
pass
else:
headfilename = self.session.downloadUserHead(usermail=self.session.usermail)
self.loginWindow.headLabel.setPixmap(QtGui.QPixmap(headfilename))
self.mainWinow = mainWindows.MainWindow()
self.loginWindow.close()
self.mainWinow.show()
class LoginThread(QtCore.QThread):
loginOver = QtCore.pyqtSignal(str)
def __init__(self):
super(LoginThread, self).__init__()
self.mutex = QtCore.QMutex()
self.loginFlag = False
self.loginValidateFlag = False
def login(self,session):
self.mutex.lock()
self.session = session
self.mutex.unlock()
self.loginFlag = True
if not self.isRunning():
self.start(QtCore.QThread.LowPriority)
def loginValidate(self,session,validate):
self.mutex.lock()
self.session = session
self.validate = validate
self.mutex.unlock()
self.loginValidateFlag = True
if not self.isRunning():
self.start(QtCore.QThread.LowPriority)
def run(self):
if self.loginFlag:
self.loginFlag = False
self.result = self.session.tryLogin()
self.loginOver.emit(self.result)
if self.loginValidateFlag:
self.loginValidateFlag = False
self.result = self.session.loginValidate(self.validate)
self.loginOver.emit(self.result)
if __name__ == '__main__':
xiamiPlayer = XiamiPlayer()