Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
eeb2a6372b
BIN
client/img/Dalek.gif
Normal file
BIN
client/img/Dalek.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 682 B |
BIN
client/img/tardis.png
Normal file
BIN
client/img/tardis.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Form implementation generated from reading ui file 'pmFile.ui'
|
# Form implementation generated from reading ui file 'pmFile.ui'
|
||||||
#
|
#
|
||||||
# Created: Fri Apr 10 16:31:47 2015
|
# Created: Mon Apr 13 21:42:22 2015
|
||||||
# by: PyQt4 UI code generator 4.11.3
|
# by: PyQt4 UI code generator 4.11.3
|
||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
@ -71,8 +71,8 @@ class Ui_Dialog3(object):
|
|||||||
|
|
||||||
def retranslateUi(self, Dialog3):
|
def retranslateUi(self, Dialog3):
|
||||||
Dialog3.setWindowTitle(_translate("Dialog3", "Dialog", None))
|
Dialog3.setWindowTitle(_translate("Dialog3", "Dialog", None))
|
||||||
self.pushButton.setText(_translate("Dialog3", "Send message", None))
|
self.pushButton.setText(_translate("Dialog3", "Send it", None))
|
||||||
self.pushButton_2.setText(_translate("Dialog3", "send file", None))
|
self.pushButton_2.setText(_translate("Dialog3", "import file ...", None))
|
||||||
self.label.setText(_translate("Dialog3", "Sending a file to : ", None))
|
self.label.setText(_translate("Dialog3", "Sending a file to : ", None))
|
||||||
self.label_2.setText(_translate("Dialog3", "BobZorro", None))
|
self.label_2.setText(_translate("Dialog3", "BobZorro", None))
|
||||||
|
|
||||||
|
@ -35,14 +35,14 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Send message</string>
|
<string>Send it</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
<widget class="QPushButton" name="pushButton_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>send file</string>
|
<string>import file ...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
471
client/start.py
471
client/start.py
@ -7,85 +7,132 @@ from socket import *
|
|||||||
from pmWindow import Ui_Dialog2
|
from pmWindow import Ui_Dialog2
|
||||||
from pmFile import Ui_Dialog3
|
from pmFile import Ui_Dialog3
|
||||||
import configparser
|
import configparser
|
||||||
import string, sys, urllib.parse
|
|
||||||
from threading import *
|
from threading import *
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#########################################################
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# this class can receive files sent by p2p
|
||||||
|
# to run this class, we need to do :
|
||||||
|
# s = StreamHandler(portFile, fileName)
|
||||||
|
# s.start()
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
class StreamHandler (Thread):
|
class StreamHandler (Thread):
|
||||||
|
"""
|
||||||
|
this class can receive files sent by p2p
|
||||||
|
to run this class, we need to do :
|
||||||
|
s = StreamHandler(portFile, fileName)
|
||||||
|
s.start()
|
||||||
|
"""
|
||||||
|
def __init__(self, port, filename):
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__( this , port, filename):
|
:param port: the port of the new connection
|
||||||
Thread.__init__( this )
|
:param filename: the name of the file you wish to receive
|
||||||
this.port = port
|
:return:
|
||||||
this.filename = filename
|
"""
|
||||||
|
|
||||||
def run(this):
|
Thread.__init__(self)
|
||||||
this.process()
|
self.port = port
|
||||||
|
self.filename = filename
|
||||||
|
|
||||||
def bindmsock( this ):
|
def run(self):
|
||||||
this.msock = socket(AF_INET, SOCK_STREAM)
|
"""
|
||||||
this.msock.bind(('', int(this.port)))
|
Execute the process function
|
||||||
this.msock.listen(1)
|
:return:
|
||||||
print ('[Media] Listening on port'+this.port)
|
"""
|
||||||
|
self.process()
|
||||||
|
|
||||||
def acceptmsock( this ):
|
def bindmsock(self):
|
||||||
this.mconn, this.maddr = this.msock.accept()
|
"""
|
||||||
print ('[Media] Got connection from', this.maddr)
|
creation of a new socket for the p2p transfert file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
self.msock = socket(AF_INET, SOCK_STREAM)
|
||||||
|
self.msock.bind(('', int(self.port)))
|
||||||
|
self.msock.listen(1)
|
||||||
|
print('[Media] Listening on port'+self.port)
|
||||||
|
|
||||||
|
def acceptmsock(self):
|
||||||
|
"""
|
||||||
|
Get the address of the connection
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
self.mconn, self.maddr = self.msock.accept()
|
||||||
|
print('[Media] Got connection from', self.maddr)
|
||||||
|
|
||||||
|
|
||||||
def acceptcsock( this ):
|
def acceptcsock(self):
|
||||||
this.cconn, this.maddr = this.csock.accept()
|
"""
|
||||||
print ('[Control] Got connection from'+ this.maddr)
|
accept to receive the file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
self.cconn, self.maddr = self.csock.accept()
|
||||||
|
print('[Control] Got connection from'+ self.maddr)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
data = this.cconn.recv(1024)
|
data = self.cconn.recv(1024)
|
||||||
if not data: break
|
if not data: break
|
||||||
if data[0:4] == "SEND": this.filename = data[5:]
|
if data[0:4] == "SEND": self.filename = data[5:]
|
||||||
print ('[Control] Getting ready to receive ' + this.filename)
|
print ('[Control] Getting ready to receive ' + self.filename)
|
||||||
break
|
break
|
||||||
|
|
||||||
def transfer( this ):
|
def transfer( self ):
|
||||||
print ('[Media] Starting media transfer for ' + this.filename)
|
"""
|
||||||
|
Starting the transfert of the file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
print('[Media] Starting media transfer for ' + self.filename)
|
||||||
|
|
||||||
f = open(this.filename,"wb")
|
f = open(self.filename,"wb")
|
||||||
while 1:
|
while 1:
|
||||||
data = this.mconn.recv(1024)
|
data = self.mconn.recv(1024)
|
||||||
if not data: break
|
if not data: break
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
print ('[Media] Got ' + this.filename)
|
print('[Media] Got ' + self.filename)
|
||||||
print ('[Media] Closing media transfer for ' + this.filename)
|
print('[Media] Closing media transfer for ' + self.filename)
|
||||||
|
|
||||||
def close( this ):
|
def close(self):
|
||||||
#this.cconn.close()
|
"""
|
||||||
#this.csock.close()
|
We close the connection
|
||||||
this.mconn.close()
|
:return:
|
||||||
this.msock.close()
|
"""
|
||||||
|
|
||||||
def process( this ):
|
self.mconn.close()
|
||||||
#this.bindcsock()
|
self.msock.close()
|
||||||
#this.acceptcsock()
|
|
||||||
this.bindmsock()
|
|
||||||
this.acceptmsock()
|
|
||||||
this.transfer()
|
|
||||||
this.close()
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
def process(self):
|
||||||
|
"""
|
||||||
|
function who start all the function
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.bindmsock()
|
||||||
|
self.acceptmsock()
|
||||||
|
self.transfer()
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
#########################################################
|
||||||
|
|
||||||
class MySignal(QObject):
|
class MySignal(QObject):
|
||||||
sig = Signal(str)
|
sig = Signal(str)
|
||||||
|
|
||||||
class MyLongThread(QThread):
|
class MyLongThread(QThread):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
|
|
||||||
QThread.__init__(self, parent)
|
QThread.__init__(self, parent)
|
||||||
self.exiting = False
|
self.exiting = False
|
||||||
self.signal = MySignal()
|
self.signal = MySignal()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
end = time.time()+10
|
end = time.time()+10
|
||||||
while self.exiting==False:
|
while not self.exiting:
|
||||||
sys.stdout.write('*')
|
sys.stdout.write('*')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@ -111,12 +158,18 @@ class MyThread(QThread):
|
|||||||
self.gui = gui
|
self.gui = gui
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#########################################################
|
||||||
|
|
||||||
|
|
||||||
class privateFile():
|
class privateFile():
|
||||||
def __init__(self, main, s, pseudoFile):
|
def __init__(self, main, s, pseudoFile):
|
||||||
|
"""
|
||||||
|
new windows for the p2p
|
||||||
|
:param main:
|
||||||
|
:param s:
|
||||||
|
:param pseudoFile: pseudo of the people who need to send the file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.main = main
|
self.main = main
|
||||||
self.s = s
|
self.s = s
|
||||||
self.pseudoFile = pseudoFile
|
self.pseudoFile = pseudoFile
|
||||||
@ -130,6 +183,10 @@ class privateFile () :
|
|||||||
|
|
||||||
|
|
||||||
def sendFile(self):
|
def sendFile(self):
|
||||||
|
"""
|
||||||
|
Send to the sever the command : /pmfile + pseudo to send + name of the file
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.ui.lineEdit.text() != "":
|
if self.ui.lineEdit.text() != "":
|
||||||
self.ui.lineEdit.setText("")
|
self.ui.lineEdit.setText("")
|
||||||
try:
|
try:
|
||||||
@ -141,16 +198,27 @@ class privateFile () :
|
|||||||
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
||||||
|
|
||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
|
"""
|
||||||
|
buttton to open and chose the file to send and create the name of the command
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
nomFile = ' '.join(QFileDialog.getOpenFileName())
|
nomFile = ' '.join(QFileDialog.getOpenFileName())
|
||||||
self.ui.lineEdit.setText('/pmfile '+self.pseudoFile+ " "+nomFile )
|
self.ui.lineEdit.setText('/pmfile '+self.pseudoFile+ " "+nomFile )
|
||||||
self.cmd1 = self.ui.lineEdit.text()
|
self.cmd1 = self.ui.lineEdit.text()
|
||||||
self.bob = ' '.join(nomFile.split("/")[-1:])
|
self.bob = ' '.join(nomFile.split("/")[-1:])
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#########################################################
|
||||||
|
|
||||||
class privateMessage() :
|
class privateMessage() :
|
||||||
def __init__(self,main,s, pmPerson, pmPerso):
|
def __init__(self,main,s, pmPerson, pmPerso):
|
||||||
|
"""
|
||||||
|
new windows for a private conversation
|
||||||
|
:param main:
|
||||||
|
:param s:
|
||||||
|
:param pmPerson:
|
||||||
|
:param pmPerso:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.main = main
|
self.main = main
|
||||||
self.s = s
|
self.s = s
|
||||||
self.pmPerso = pmPerso
|
self.pmPerso = pmPerso
|
||||||
@ -179,8 +247,11 @@ class privateMessage () :
|
|||||||
self.ui.label_2.setText(pmPerson)
|
self.ui.label_2.setText(pmPerson)
|
||||||
|
|
||||||
def codeNb(self, txt):
|
def codeNb(self, txt):
|
||||||
#if re.compile(' ').search(str(txt)) : txt = txt.split(" ")[0]
|
"""
|
||||||
|
converted a return code (info and succes) in the message
|
||||||
|
:param txt: code from the server
|
||||||
|
:return: info, String return from server
|
||||||
|
"""
|
||||||
if txt == "300": info = "USERLIST"
|
if txt == "300": info = "USERLIST"
|
||||||
elif txt == "301": info = "USERAWAY"
|
elif txt == "301": info = "USERAWAY"
|
||||||
elif txt == "302": info = "HAS_JOIN"
|
elif txt == "302": info = "HAS_JOIN"
|
||||||
@ -189,44 +260,37 @@ class privateMessage () :
|
|||||||
elif txt == "305": info = "NAME_CHANGED"
|
elif txt == "305": info = "NAME_CHANGED"
|
||||||
elif txt == "306": info = "NEW_PM"
|
elif txt == "306": info = "NEW_PM"
|
||||||
elif txt == "307": info = "ASKING_FOR_PM"
|
elif txt == "307": info = "ASKING_FOR_PM"
|
||||||
|
elif txt == "308": info = "PRIVATE_DISCU_ACCEPTED_FROM"
|
||||||
elif txt == "308": info = "PRIVATE_DISCU_ACCEPTED_FROM" #SUCC_PRIVATE_DISCUSSION_OK SUCC_PRIVATE_DISCUSSION_ACCEPTED
|
|
||||||
elif txt == "309": info = "PRIVATE_DISCU_REFUSED_FROM"
|
elif txt == "309": info = "PRIVATE_DISCU_REFUSED_FROM"
|
||||||
|
|
||||||
elif txt == "310": info = "IS_NOW_ENABLE"
|
elif txt == "310": info = "IS_NOW_ENABLE"
|
||||||
elif txt == "311": info = "IS_NOW_DISABLE"
|
elif txt == "311": info = "IS_NOW_DISABLE"
|
||||||
elif txt == "312": info = "HAS_ASKED_FILE"
|
elif txt == "312": info = "HAS_ASKED_FILE"
|
||||||
elif txt == "313": info = "CAN_SEND_FILE"
|
elif txt == "313": info = "CAN_SEND_FILE"
|
||||||
elif txt == "314": info = "HAS_REJECT_FILE"
|
elif txt == "314": info = "HAS_REJECT_FILE"
|
||||||
|
|
||||||
|
|
||||||
elif txt == "200" or txt == "200300": info = "SUCC_CHANNEL_JOINED"
|
elif txt == "200" or txt == "200300": info = "SUCC_CHANNEL_JOINED"
|
||||||
elif txt == "200300": info = "SUCC_CHANNEL_JOINED USERLIST"
|
elif txt == "200300": info = "SUCC_CHANNEL_JOINED USERLIST"
|
||||||
|
|
||||||
elif txt == "201": info = "SUCC_CHANNEL_QUIT"
|
elif txt == "201": info = "SUCC_CHANNEL_QUIT"
|
||||||
elif txt == "202": info = "SUCC_MESSAGE_SENDED"
|
elif txt == "202": info = "SUCC_MESSAGE_SENDED"
|
||||||
|
|
||||||
elif txt == "203": info = "SUCC_NICKNAME_CHANGED"
|
elif txt == "203": info = "SUCC_NICKNAME_CHANGED"
|
||||||
elif txt == "204": info = "SUCC_VALID_NICKNAME"
|
elif txt == "204": info = "SUCC_VALID_NICKNAME"
|
||||||
elif txt == "205": info = "SUCC_PM_SENDED"
|
elif txt == "205": info = "SUCC_PM_SENDED"
|
||||||
|
|
||||||
elif txt == "206": info = "SUCCESSFUL_ASKED_CONV"
|
elif txt == "206": info = "SUCCESSFUL_ASKED_CONV"
|
||||||
elif txt == "207": info = "SUCCESSFUL_ACCEPTED_CONV"
|
elif txt == "207": info = "SUCCESSFUL_ACCEPTED_CONV"
|
||||||
elif txt == "208": info = "SUCCESSFUL_REFUSED_CONV"
|
elif txt == "208": info = "SUCCESSFUL_REFUSED_CONV"
|
||||||
|
|
||||||
elif txt == "209": info = "SUCC_ENABLED"
|
elif txt == "209": info = "SUCC_ENABLED"
|
||||||
elif txt == "210": info = "SUCC_DISABLED"
|
elif txt == "210": info = "SUCC_DISABLED"
|
||||||
|
elif txt == "211": info = "SUCC_PMFILE"
|
||||||
elif txt == "211": info = "SUCC_PMFILE" #SUCC_ASKED_FILE
|
|
||||||
|
|
||||||
elif txt == "212": info = "SUCC_ACCEPTED_FILE"
|
elif txt == "212": info = "SUCC_ACCEPTED_FILE"
|
||||||
|
|
||||||
elif txt == "213": info = "SUCC_REFUSED_FILE"
|
elif txt == "213": info = "SUCC_REFUSED_FILE"
|
||||||
else: info = txt
|
else: info = txt
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
"""
|
||||||
|
if a user reject a pm conversation
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.cmRej = "/rejectpm "+self.pmPerson
|
self.cmRej = "/rejectpm "+self.pmPerson
|
||||||
try:
|
try:
|
||||||
self.s.send(self.cmRej.encode())
|
self.s.send(self.cmRej.encode())
|
||||||
@ -238,21 +302,26 @@ class privateMessage () :
|
|||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
"""
|
||||||
|
if a user accept a pm with another user
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.cmAcc = "/acceptpm "+self.pmPerson
|
self.cmAcc = "/acceptpm "+self.pmPerson
|
||||||
try:
|
try:
|
||||||
self.s.send(self.cmAcc.encode())
|
self.s.send(self.cmAcc.encode())
|
||||||
|
|
||||||
|
|
||||||
except timeout:
|
except timeout:
|
||||||
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
||||||
self.ui.txtOutput.setText(self.message_buffer2)
|
self.ui.txtOutput.setText(self.message_buffer2)
|
||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def htmlToText( self, html ):
|
def htmlToText( self, html ):
|
||||||
|
"""
|
||||||
|
converted some characters written by the user (html tag, smiley)
|
||||||
|
:param html: message written by an user
|
||||||
|
:return: html, message converted
|
||||||
|
"""
|
||||||
html = html.replace('<', '<')
|
html = html.replace('<', '<')
|
||||||
html = html.replace('>', '>')
|
html = html.replace('>', '>')
|
||||||
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
|
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
|
||||||
@ -268,14 +337,21 @@ class privateMessage () :
|
|||||||
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
|
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
|
||||||
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
|
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
|
||||||
|
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def ShowMessageErreur(self, txt):
|
def ShowMessageErreur(self, txt):
|
||||||
|
"""
|
||||||
|
Show with color message from the server with error
|
||||||
|
:param txt:message from server
|
||||||
|
:return: message with color
|
||||||
|
"""
|
||||||
self.message_buffer2 += '<br> <span style="color : red; font-weight: bold;"> ' + self.htmlToText(txt) + ' </span>'
|
self.message_buffer2 += '<br> <span style="color : red; font-weight: bold;"> ' + self.htmlToText(txt) + ' </span>'
|
||||||
|
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
|
"""
|
||||||
|
send the message written in the pm conversation
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.cmdP = self.ui.lineEdit.text()
|
self.cmdP = self.ui.lineEdit.text()
|
||||||
if self.cmdP != "":
|
if self.cmdP != "":
|
||||||
self.ui.lineEdit.setText('')
|
self.ui.lineEdit.setText('')
|
||||||
@ -291,18 +367,29 @@ class privateMessage () :
|
|||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
def UpdateChatP(self):
|
def UpdateChatP(self):
|
||||||
|
"""
|
||||||
|
update the chat box
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.queueMsg2 :
|
if self.queueMsg2 :
|
||||||
m = self.queueMsg2.pop(0)
|
m = self.queueMsg2.pop(0)
|
||||||
if m :
|
if m :
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
self.ShowMessageAsTextPm(m)
|
self.ShowMessageAsTextPm(m)
|
||||||
|
|
||||||
|
|
||||||
def getTimeStamp(self):
|
def getTimeStamp(self):
|
||||||
|
"""
|
||||||
|
the time format: H:M
|
||||||
|
:return: time
|
||||||
|
"""
|
||||||
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
||||||
|
|
||||||
def ShowMessageAsTextPm(self, txt):
|
def ShowMessageAsTextPm(self, txt):
|
||||||
|
"""
|
||||||
|
add txt to the buffer with the time and color
|
||||||
|
:param txt: message from sever
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer2 += '<br><span style="color : grey">'+self.codeNb(txt)+'</span>'
|
self.message_buffer2 += '<br><span style="color : grey">'+self.codeNb(txt)+'</span>'
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_PRIVATE_DISCUSSION_REFUSED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_PRIVATE_DISCUSSION_REFUSED":
|
||||||
@ -313,7 +400,7 @@ class privateMessage () :
|
|||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_PM_SENDED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_PM_SENDED":
|
||||||
self.message_buffer2 += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+self.pmPerso +' > </span> ' + self.htmlToText(self.cmdP) + ''
|
self.message_buffer2 += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+self.pmPerso +' > </span> <span style="color : black">' + self.htmlToText(self.cmdP) + '</span>'
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_PRIVATE_DISCUSSION_ACCEPTED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_PRIVATE_DISCUSSION_ACCEPTED":
|
||||||
@ -336,29 +423,46 @@ class privateMessage () :
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
######################################################################################################################
|
||||||
|
|
||||||
|
|
||||||
class start(QtGui.QMainWindow):
|
class start(QtGui.QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Main Windows with the main conversation
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
super(start, self).__init__()
|
super(start, self).__init__()
|
||||||
self.queueMsg= []
|
self.queueMsg= []
|
||||||
self.thread = MyThread()
|
self.thread = MyThread()
|
||||||
self.thread.finished.connect(self.UpdateChat)
|
self.thread.finished.connect(self.UpdateChat)
|
||||||
|
|
||||||
|
|
||||||
self.createWidgets()
|
self.createWidgets()
|
||||||
|
|
||||||
def setNewMsg (self,msg) :
|
def setNewMsg (self,msg) :
|
||||||
|
"""
|
||||||
|
add msg to the queueMsg
|
||||||
|
:param msg:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.queueMsg.append(msg)
|
self.queueMsg.append(msg)
|
||||||
|
|
||||||
def getTimeStamp(self):
|
def getTimeStamp(self):
|
||||||
|
"""
|
||||||
|
the time format: H:M
|
||||||
|
:return: time
|
||||||
|
"""
|
||||||
return('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
return('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
||||||
|
|
||||||
def htmlToText( self, html):
|
def htmlToText( self, html):
|
||||||
|
"""
|
||||||
|
converted some characters written by the user (html tag, smiley)
|
||||||
|
:param html: message written by an user
|
||||||
|
:return: html, message converted
|
||||||
|
"""
|
||||||
|
|
||||||
html = html.replace('<', '<')
|
|
||||||
|
html = html.replace('&', '&')
|
||||||
html = html.replace('>', '>')
|
html = html.replace('>', '>')
|
||||||
|
html = html.replace('<', '"')
|
||||||
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
|
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
|
||||||
html = html.replace(':-(', '<img src="img/sad.png" alt="sad face">')
|
html = html.replace(':-(', '<img src="img/sad.png" alt="sad face">')
|
||||||
html = html.replace(':-p', '<img src="img/langue.png" alt="langue face">')
|
html = html.replace(':-p', '<img src="img/langue.png" alt="langue face">')
|
||||||
@ -371,25 +475,42 @@ class start(QtGui.QMainWindow):
|
|||||||
html = html.replace('3:)', '<img src="img/hell.png" alt="hell face">')
|
html = html.replace('3:)', '<img src="img/hell.png" alt="hell face">')
|
||||||
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
|
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
|
||||||
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
|
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
|
||||||
|
html = html.replace(':dalek', '<img src="img/Dalek.gif" alt="homer face">')
|
||||||
|
html = html.replace(':tardis', '<img src="img/tardis.png" alt="homer face">')
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def ShowMessageErreur(self, txt):
|
def ShowMessageErreur(self, txt):
|
||||||
|
"""
|
||||||
|
add to the buffer an erreur message with color
|
||||||
|
:param txt:message from the server
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : red; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
self.message_buffer += '<br> <span style="color : red; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
||||||
|
|
||||||
def ShowMessageOK(self, txt):
|
def ShowMessageOK(self, txt):
|
||||||
|
"""
|
||||||
|
add to the buffer a good message with style
|
||||||
|
:param txt:message from the server
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : green; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
self.message_buffer += '<br> <span style="color : green; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
||||||
|
|
||||||
def ShowMessageInfo (self, txt):
|
def ShowMessageInfo (self, txt):
|
||||||
|
"""
|
||||||
|
add to the buffer an info message with style
|
||||||
|
:param txt:message from the server
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
||||||
|
|
||||||
|
|
||||||
def ShowMessageAsText(self, txt):
|
def ShowMessageAsText(self, txt):
|
||||||
|
"""
|
||||||
|
add to the buffer message from the server with style and run some function
|
||||||
#self.message_buffer += '<br> <span style="color : #E6E6E6"> '+ txt +' </span>'
|
:param txt:message from the server
|
||||||
self.message_buffer += '<br> <span style="color : #E6E6E6"> '+ self.codeNb(str(txt)) +' </span>'
|
:return:
|
||||||
|
"""
|
||||||
|
#self.message_buffer += '<br> <span style="color : #E6E6E6"> '+ self.codeNb(str(txt)) +' </span>'
|
||||||
|
|
||||||
if re.match("^4", txt):
|
if re.match("^4", txt):
|
||||||
self.ShowMessageErreur("Erreur ! : " + self.errNb(txt))
|
self.ShowMessageErreur("Erreur ! : " + self.errNb(txt))
|
||||||
@ -401,7 +522,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
self.s.send("/userlistaway".encode())
|
self.s.send("/userlistaway".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "IS_NOW_ENABLE":
|
if self.codeNb(txt.split(" ")[0]) == "IS_NOW_ENABLE":
|
||||||
self.ShowMessageInfo(txt.split(" ")[1]+" is Back !!")
|
self.ShowMessageInfo(txt.split(" ")[1]+" is Back !!")
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
@ -409,7 +529,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
self.s.send("/userlistaway".encode())
|
self.s.send("/userlistaway".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "HAS_ASKED_FILE":
|
if self.codeNb(txt.split(" ")[0]) == "HAS_ASKED_FILE":
|
||||||
self.ShowMessageOK(txt.split(" ")[1]+" share a file with you, do you want download "+' '.join(txt.split(" ")[2].split("/")[-1:])+" ?")
|
self.ShowMessageOK(txt.split(" ")[1]+" share a file with you, do you want download "+' '.join(txt.split(" ")[2].split("/")[-1:])+" ?")
|
||||||
self.questionMessage(txt.split(" ")[1],txt.split(" ")[2])
|
self.questionMessage(txt.split(" ")[1],txt.split(" ")[2])
|
||||||
@ -423,24 +542,17 @@ class start(QtGui.QMainWindow):
|
|||||||
s = StreamHandler(self.portFile, self.fileNom)
|
s = StreamHandler(self.portFile, self.fileNom)
|
||||||
s.start()
|
s.start()
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "CAN_SEND_FILE":
|
if self.codeNb(txt.split(" ")[0]) == "CAN_SEND_FILE":
|
||||||
self.ShowMessageOK("file can be send ")
|
self.ShowMessageOK("file can be send ")
|
||||||
|
|
||||||
ms = socket(AF_INET, SOCK_STREAM)
|
ms = socket(AF_INET, SOCK_STREAM)
|
||||||
|
|
||||||
print(txt.split(" ")[2]+" "+txt.split(" ")[3])
|
print(txt.split(" ")[2]+" "+txt.split(" ")[3])
|
||||||
|
|
||||||
ms.connect((str(txt.split(" ")[2]), int(txt.split(" ")[3])))
|
ms.connect((str(txt.split(" ")[2]), int(txt.split(" ")[3])))
|
||||||
|
|
||||||
f = open(txt.split(" ")[4], "rb")
|
f = open(txt.split(" ")[4], "rb")
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
ms.send(data)
|
ms.send(data)
|
||||||
ms.close()
|
ms.close()
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCCESSFUL_ACCEPTED_CONV":
|
if self.codeNb(txt.split(" ")[0]) == "SUCCESSFUL_ACCEPTED_CONV":
|
||||||
self.message_buffer += '<br> <span style="color : green"> PRIVATE DISCUSSION ? challenge accepted ! '
|
self.message_buffer += '<br> <span style="color : green"> PRIVATE DISCUSSION ? challenge accepted ! '
|
||||||
self.private2.ShowMessageAsTextPm("SUCC_PRIVATE_DISCUSSION_ACCEPTED")
|
self.private2.ShowMessageAsTextPm("SUCC_PRIVATE_DISCUSSION_ACCEPTED")
|
||||||
@ -449,8 +561,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.message_buffer += '<br> <span style="color : green"> PRIVATE DISCUSSION WITH '+txt.split(" ")[1] + ' ? challenge accepted ! '
|
self.message_buffer += '<br> <span style="color : green"> PRIVATE DISCUSSION WITH '+txt.split(" ")[1] + ' ? challenge accepted ! '
|
||||||
self.private2.ShowMessageAsTextPm(txt)
|
self.private2.ShowMessageAsTextPm(txt)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCCESSFUL_ASKED_CONV":
|
if self.codeNb(txt.split(" ")[0]) == "SUCCESSFUL_ASKED_CONV":
|
||||||
self.ShowMessageOK("invitation requested")
|
self.ShowMessageOK("invitation requested")
|
||||||
self.private2 = privateMessage(self, self.s, self.demande, self.pseudo)
|
self.private2 = privateMessage(self, self.s, self.demande, self.pseudo)
|
||||||
@ -459,8 +569,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.ShowMessageOK("private discution from "+ txt.split(" ")[1])
|
self.ShowMessageOK("private discution from "+ txt.split(" ")[1])
|
||||||
self.private2 = privateMessage(self,self.s,txt.split(" ")[1], self.pseudo)
|
self.private2 = privateMessage(self,self.s,txt.split(" ")[1], self.pseudo)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_PM_SENDED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_PM_SENDED":
|
||||||
self.private2.ShowMessageAsTextPm(txt.split(" ")[0])
|
self.private2.ShowMessageAsTextPm(txt.split(" ")[0])
|
||||||
|
|
||||||
@ -475,8 +583,7 @@ class start(QtGui.QMainWindow):
|
|||||||
self.private2.ShowMessageAsTextPm(txt)
|
self.private2.ShowMessageAsTextPm(txt)
|
||||||
self.ShowMessageOK(txt.split(" ")[1]+" Rejected your Private discussion !!")
|
self.ShowMessageOK(txt.split(" ")[1]+" Rejected your Private discussion !!")
|
||||||
|
|
||||||
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_CHANNEL_QUIT":
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCCESSFUL_LOGOUT" :
|
|
||||||
self.ShowMessageOK("You have logged out of the DNC !")
|
self.ShowMessageOK("You have logged out of the DNC !")
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
self.ui.listNames_2.clear()
|
self.ui.listNames_2.clear()
|
||||||
@ -488,7 +595,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
self.s.send("/userlistaway".encode())
|
self.s.send("/userlistaway".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_ENABLED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_ENABLED":
|
||||||
self.ShowMessageOK("You are back !")
|
self.ShowMessageOK("You are back !")
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
@ -496,14 +602,12 @@ class start(QtGui.QMainWindow):
|
|||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
self.s.send("/userlistaway".encode())
|
self.s.send("/userlistaway".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_NICKNAME_CHANGED":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_NICKNAME_CHANGED":
|
||||||
self.ShowMessageOK("Sucessful nickname change !")
|
self.ShowMessageOK("Sucessful nickname change !")
|
||||||
|
|
||||||
if self.errNb(txt.split(" ")[0]) == "ERR_INVALID_NICKNAME":
|
if self.errNb(txt.split(" ")[0]) == "ERR_INVALID_NICKNAME":
|
||||||
self.pseudo = "INVALID_NICKNAME"
|
self.pseudo = "INVALID_NICKNAME"
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "NAME_CHANGED":
|
if self.codeNb(txt.split(" ")[0]) == "NAME_CHANGED":
|
||||||
self.ShowMessageNameChange(txt.split(" ")[1], txt.split(" ")[2])
|
self.ShowMessageNameChange(txt.split(" ")[1], txt.split(" ")[2])
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
@ -518,35 +622,29 @@ class start(QtGui.QMainWindow):
|
|||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "SUCC_CHANNEL_JOINED" or txt.split(" ")[0] == "200":
|
if self.codeNb(txt.split(" ")[0]) == "SUCC_CHANNEL_JOINED" or txt.split(" ")[0] == "200":
|
||||||
self.ShowMessageHasJoin(self.pseudo)
|
self.ShowMessageHasJoin(self.pseudo)
|
||||||
#self.s.send("/userlist".encode())
|
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
self.ui.listNames_2.clear()
|
self.ui.listNames_2.clear()
|
||||||
self.s.send("/userlist".encode())
|
self.s.send("/userlist".encode())
|
||||||
self.s.send("/userlistaway".encode())
|
self.s.send("/userlistaway".encode())
|
||||||
|
|
||||||
|
|
||||||
if self.errNb(txt.split(" ")[0]) == "ERR_NICKNAME_ALREADY_USED":
|
if self.errNb(txt.split(" ")[0]) == "ERR_NICKNAME_ALREADY_USED":
|
||||||
self.deco()
|
self.deco()
|
||||||
|
|
||||||
|
|
||||||
if re.compile('USERLIST').search(self.codeNb(txt.split(" ")[0])):
|
if re.compile('USERLIST').search(self.codeNb(txt.split(" ")[0])):
|
||||||
self.ui.listNames.clear()
|
self.ui.listNames.clear()
|
||||||
n = len(txt.split(" ")[1:]) + 1
|
n = len(txt.split(" ")[1:]) + 1
|
||||||
for i in range(1, n):
|
for i in range(1, n):
|
||||||
self.ui.listNames.addItem(str(txt.split(" ")[i]).replace("301", ""))
|
self.ui.listNames.addItem(str(txt.split(" ")[i]).replace("301", ""))
|
||||||
print(str(txt.split(" ")[1:]))
|
#print(str(txt.split(" ")[1:]))
|
||||||
|
|
||||||
if re.compile('USERAWAY').search(self.codeNb(txt.split(" ")[0])):
|
if re.compile('USERAWAY').search(self.codeNb(txt.split(" ")[0])):
|
||||||
self.ui.listNames_2.clear()
|
self.ui.listNames_2.clear()
|
||||||
n = len(txt.split(" ")[1:]) + 1
|
n = len(txt.split(" ")[1:]) + 1
|
||||||
for i in range(1, n):
|
for i in range(1, n):
|
||||||
self.ui.listNames_2.addItem(str(txt.split(" ")[i]))
|
self.ui.listNames_2.addItem(str(txt.split(" ")[i]))
|
||||||
print(str(txt.split(" ")[1:]))
|
#print(str(txt.split(" ")[1:]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.codeNb(txt.split(" ")[0]) == "NEW_MSG" :
|
if self.codeNb(txt.split(" ")[0]) == "NEW_MSG" :
|
||||||
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+txt.split(" ")[1] +' > </span> <span style="color : black">' + self.htmlToText(' '.join(txt.split(" ")[2:])) + '</span>'
|
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+txt.split(" ")[1] +' > </span> <span style="color : black">' + self.htmlToText(' '.join(txt.split(" ")[2:])) + '</span>'
|
||||||
@ -554,9 +652,12 @@ class start(QtGui.QMainWindow):
|
|||||||
if self.codeNb(txt) == "SUCC_MESSAGE_SENDED" :
|
if self.codeNb(txt) == "SUCC_MESSAGE_SENDED" :
|
||||||
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+ self.pseudo +' > </span><span style="color : black"> ' + self.htmlToText(self.cmd) + '</span>'
|
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> < '+ self.pseudo +' > </span><span style="color : black"> ' + self.htmlToText(self.cmd) + '</span>'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def errNb (self, txt):
|
def errNb (self, txt):
|
||||||
|
"""
|
||||||
|
converted a return error code in the message
|
||||||
|
:param txt: code from the server
|
||||||
|
:return: String message
|
||||||
|
"""
|
||||||
if txt == "400":
|
if txt == "400":
|
||||||
info = "ERR_NICKNAME_ALREADY_USED"
|
info = "ERR_NICKNAME_ALREADY_USED"
|
||||||
|
|
||||||
@ -590,8 +691,11 @@ class start(QtGui.QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
def codeNb (self, txt):
|
def codeNb (self, txt):
|
||||||
#if re.compile(' ').search(str(txt)) : txt = txt.split(" ")[0]
|
"""
|
||||||
|
converted a return code in the message
|
||||||
|
:param txt: code from the server
|
||||||
|
:return: info, String return from server
|
||||||
|
"""
|
||||||
if txt == "300": info = "USERLIST"
|
if txt == "300": info = "USERLIST"
|
||||||
elif txt == "301": info = "USERAWAY"
|
elif txt == "301": info = "USERAWAY"
|
||||||
elif txt == "302": info = "HAS_JOIN"
|
elif txt == "302": info = "HAS_JOIN"
|
||||||
@ -600,53 +704,62 @@ class start(QtGui.QMainWindow):
|
|||||||
elif txt == "305": info = "NAME_CHANGED"
|
elif txt == "305": info = "NAME_CHANGED"
|
||||||
elif txt == "306": info = "NEW_PM"
|
elif txt == "306": info = "NEW_PM"
|
||||||
elif txt == "307": info = "ASKING_FOR_PM"
|
elif txt == "307": info = "ASKING_FOR_PM"
|
||||||
|
elif txt == "308": info = "PRIVATE_DISCU_ACCEPTED_FROM"
|
||||||
elif txt == "308": info = "PRIVATE_DISCU_ACCEPTED_FROM" #SUCC_PRIVATE_DISCUSSION_OK SUCC_PRIVATE_DISCUSSION_ACCEPTED
|
|
||||||
elif txt == "309": info = "PRIVATE_DISCU_REFUSED_FROM"
|
elif txt == "309": info = "PRIVATE_DISCU_REFUSED_FROM"
|
||||||
|
|
||||||
elif txt == "310": info = "IS_NOW_ENABLE"
|
elif txt == "310": info = "IS_NOW_ENABLE"
|
||||||
elif txt == "311": info = "IS_NOW_DISABLE"
|
elif txt == "311": info = "IS_NOW_DISABLE"
|
||||||
elif txt == "312": info = "HAS_ASKED_FILE"
|
elif txt == "312": info = "HAS_ASKED_FILE"
|
||||||
elif txt == "313": info = "CAN_SEND_FILE"
|
elif txt == "313": info = "CAN_SEND_FILE"
|
||||||
elif txt == "314": info = "HAS_REJECT_FILE"
|
elif txt == "314": info = "HAS_REJECT_FILE"
|
||||||
|
|
||||||
|
|
||||||
elif txt == "200" or txt=="200300": info = "SUCC_CHANNEL_JOINED"
|
elif txt == "200" or txt=="200300": info = "SUCC_CHANNEL_JOINED"
|
||||||
elif txt == "200300" : info = "SUCC_CHANNEL_JOINED USERLIST"
|
elif txt == "200300" : info = "SUCC_CHANNEL_JOINED USERLIST"
|
||||||
|
|
||||||
elif txt == "201": info = "SUCC_CHANNEL_QUIT"
|
elif txt == "201": info = "SUCC_CHANNEL_QUIT"
|
||||||
elif txt == "202": info = "SUCC_MESSAGE_SENDED"
|
elif txt == "202": info = "SUCC_MESSAGE_SENDED"
|
||||||
|
|
||||||
elif txt == "203": info = "SUCC_NICKNAME_CHANGED"
|
elif txt == "203": info = "SUCC_NICKNAME_CHANGED"
|
||||||
elif txt == "204": info = "SUCC_VALID_NICKNAME"
|
elif txt == "204": info = "SUCC_VALID_NICKNAME"
|
||||||
elif txt == "205": info = "SUCC_PM_SENDED"
|
elif txt == "205": info = "SUCC_PM_SENDED"
|
||||||
|
|
||||||
elif txt == "206": info = "SUCCESSFUL_ASKED_CONV"
|
elif txt == "206": info = "SUCCESSFUL_ASKED_CONV"
|
||||||
elif txt == "207": info = "SUCCESSFUL_ACCEPTED_CONV"
|
elif txt == "207": info = "SUCCESSFUL_ACCEPTED_CONV"
|
||||||
elif txt == "208": info = "SUCCESSFUL_REFUSED_CONV"
|
elif txt == "208": info = "SUCCESSFUL_REFUSED_CONV"
|
||||||
|
|
||||||
elif txt == "209": info = "SUCC_ENABLED"
|
elif txt == "209": info = "SUCC_ENABLED"
|
||||||
elif txt == "210": info = "SUCC_DISABLED"
|
elif txt == "210": info = "SUCC_DISABLED"
|
||||||
|
elif txt == "211": info = "SUCC_PMFILE"
|
||||||
elif txt == "211": info = "SUCC_PMFILE" #SUCC_ASKED_FILE
|
|
||||||
|
|
||||||
elif txt == "212": info = "SUCC_ACCEPTED_FILE"
|
elif txt == "212": info = "SUCC_ACCEPTED_FILE"
|
||||||
|
|
||||||
elif txt == "213": info = "SUCC_REFUSED_FILE"
|
elif txt == "213": info = "SUCC_REFUSED_FILE"
|
||||||
else: info = txt
|
else: info = txt
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def ShowMessageHasJoin(self, txt):
|
def ShowMessageHasJoin(self, txt):
|
||||||
|
"""
|
||||||
|
adds a message to the buffer to alert users that a person has joined the dnc
|
||||||
|
:param txt: user name
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has joined DNC </span>'
|
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has joined DNC </span>'
|
||||||
|
|
||||||
def ShowMessageHasLeft(self, txt):
|
def ShowMessageHasLeft(self, txt):
|
||||||
|
"""
|
||||||
|
adds a message to the buffer to alert users that a person has left the dnc
|
||||||
|
:param txt: user name
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has left DNC </span>'
|
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has left DNC </span>'
|
||||||
|
|
||||||
def ShowMessageNameChange(self, txt, txt2):
|
def ShowMessageNameChange(self, txt, txt2):
|
||||||
|
"""
|
||||||
|
adds a message to the buffer to alert users that a person change his name
|
||||||
|
:param txt: old name
|
||||||
|
:param txt2:new name
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' is now : '+self.htmlToText(txt2)+' </span>'
|
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' is now : '+self.htmlToText(txt2)+' </span>'
|
||||||
|
|
||||||
def UpdateChat(self):
|
def UpdateChat(self):
|
||||||
|
"""
|
||||||
|
update the chat with the buffer
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.queueMsg :
|
if self.queueMsg :
|
||||||
m = self.queueMsg.pop(0)
|
m = self.queueMsg.pop(0)
|
||||||
if m:
|
if m:
|
||||||
@ -656,8 +769,13 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def questionMessage(self, name,fileN):
|
def questionMessage(self, name,fileN):
|
||||||
|
"""
|
||||||
|
open un QMessageBox to ask the user whether to download a file from another user
|
||||||
|
:param name: user name who send file
|
||||||
|
:param fileN: file name
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
reply = QtGui.QMessageBox.question(self, "send file", "do you want to download the file : " + ' '.join(fileN.split("/")[-1:])+" from "+name+" ?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
reply = QtGui.QMessageBox.question(self, "send file", "do you want to download the file : " + ' '.join(fileN.split("/")[-1:])+" from "+name+" ?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
||||||
|
|
||||||
if reply == QtGui.QMessageBox.Yes:
|
if reply == QtGui.QMessageBox.Yes:
|
||||||
@ -678,43 +796,23 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
elif reply == QtGui.QMessageBox.No:
|
elif reply == QtGui.QMessageBox.No:
|
||||||
try:
|
try:
|
||||||
cmdRej = "/rejectfile "+name+" "+fileN
|
cmdRej = "/rejectfile "+name+" "+fileN
|
||||||
print(cmdRej)
|
print(cmdRej)
|
||||||
self.s.send(cmdRej.encode())
|
self.s.send(cmdRej.encode())
|
||||||
|
|
||||||
|
|
||||||
except timeout:
|
except timeout:
|
||||||
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
||||||
self.ui.txtOutput.setText(self.message_buffer)
|
self.ui.txtOutput.setText(self.message_buffer)
|
||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def openInputDialog(self, name, fileN):
|
|
||||||
|
|
||||||
text, result = QtGui.QInputDialog.getText(self, "Port",
|
|
||||||
"What is the port of the transfert ?")
|
|
||||||
if result and text != "":
|
|
||||||
print ("le port d'envoi est : " + text)
|
|
||||||
|
|
||||||
cmdAccF = "/acceptfile "+name+" "+text+" "+fileN
|
|
||||||
try:
|
|
||||||
self.s.send(cmdAccF.encode())
|
|
||||||
print(cmdAccF)
|
|
||||||
self.portFile = text
|
|
||||||
|
|
||||||
except timeout:
|
|
||||||
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
|
|
||||||
self.ui.txtOutput.setText(self.message_buffer)
|
|
||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
|
||||||
sb.setValue(sb.maximum())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def connectActions(self):
|
def connectActions(self):
|
||||||
|
"""
|
||||||
|
add an action to buttons
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.ui.pushButton_2.clicked.connect(self.connecter)
|
self.ui.pushButton_2.clicked.connect(self.connecter)
|
||||||
self.ui.pushButton_3.clicked.connect(self.deco)
|
self.ui.pushButton_3.clicked.connect(self.deco)
|
||||||
self.ui.pushButton.clicked.connect(self.client)
|
self.ui.pushButton.clicked.connect(self.client)
|
||||||
@ -722,7 +820,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.ui.pushButton_5.clicked.connect(self.away)
|
self.ui.pushButton_5.clicked.connect(self.away)
|
||||||
self.ui.lineEdit.returnPressed.connect(self.client)
|
self.ui.lineEdit.returnPressed.connect(self.client)
|
||||||
|
|
||||||
|
|
||||||
self.ui.listNames.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
self.ui.listNames.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||||
self.ui.listNames.customContextMenuRequested.connect(self.buttonAMenu)
|
self.ui.listNames.customContextMenuRequested.connect(self.buttonAMenu)
|
||||||
|
|
||||||
@ -732,24 +829,42 @@ class start(QtGui.QMainWindow):
|
|||||||
print ('Doing Stuff when clicking on Button A')
|
print ('Doing Stuff when clicking on Button A')
|
||||||
|
|
||||||
def buttonAMenu(self, pos):
|
def buttonAMenu(self, pos):
|
||||||
|
"""
|
||||||
|
menu with the right click on the user list
|
||||||
|
:param pos:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
menu = QtGui.QMenu()
|
menu = QtGui.QMenu()
|
||||||
menu.addAction('Private discussion', lambda:self.FirstActionButtonA())
|
menu.addAction('Private discussion', lambda:self.FirstActionButtonA())
|
||||||
menu.addAction('Send file', lambda:self.SecondActionButtonA())
|
menu.addAction('Send file', lambda:self.SecondActionButtonA())
|
||||||
menu.exec_(QtGui.QCursor.pos())
|
menu.exec_(QtGui.QCursor.pos())
|
||||||
|
|
||||||
def FirstActionButtonA(self):
|
def FirstActionButtonA(self):
|
||||||
|
"""
|
||||||
|
first action (ask a pm) on the menu of the right click
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
test1 = self.ui.listNames.currentItem().text()
|
test1 = self.ui.listNames.currentItem().text()
|
||||||
print("1e fonction : "+str(test1))
|
print("1e fonction : "+str(test1))
|
||||||
self.someMethod(str(test1))
|
self.someMethod(str(test1))
|
||||||
|
|
||||||
|
|
||||||
def SecondActionButtonA(self):
|
def SecondActionButtonA(self):
|
||||||
|
"""
|
||||||
|
second action (send file) on the menu of the right click
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
test1 = self.ui.listNames.currentItem().text()
|
test1 = self.ui.listNames.currentItem().text()
|
||||||
print("2sd fonction : "+str(test1))
|
print("2sd fonction : "+str(test1))
|
||||||
self.privateFile = privateFile(self, self.s, str(test1))
|
self.privateFile = privateFile(self, self.s, str(test1))
|
||||||
|
|
||||||
|
|
||||||
def someMethod(self,item):
|
def someMethod(self,item):
|
||||||
|
"""
|
||||||
|
ask a pm to another user of the list
|
||||||
|
:param item: user name from the list
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
nom = item.replace("SUCCESSFUL_ASKED_CONV","")
|
nom = item.replace("SUCCESSFUL_ASKED_CONV","")
|
||||||
cmdPM = "/askpm "+nom
|
cmdPM = "/askpm "+nom
|
||||||
try:
|
try:
|
||||||
@ -762,9 +877,11 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def away(self):
|
def away(self):
|
||||||
|
"""
|
||||||
|
action on the button afk and back
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.bouton == "disable" :
|
if self.bouton == "disable" :
|
||||||
cmdAway = "/disable "
|
cmdAway = "/disable "
|
||||||
try:
|
try:
|
||||||
@ -791,8 +908,11 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def changeN(self):
|
def changeN(self):
|
||||||
|
"""
|
||||||
|
action to change name
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
changePseudo = self.ui.lineEdit_2.text()
|
changePseudo = self.ui.lineEdit_2.text()
|
||||||
cmdChange = "/name "+changePseudo
|
cmdChange = "/name "+changePseudo
|
||||||
try:
|
try:
|
||||||
@ -808,16 +928,15 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def connecter(self):
|
def connecter(self):
|
||||||
|
"""
|
||||||
|
create a connection, chose name and start thread to update the chat
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
ip = self.ui.lineEdit_4.text()
|
ip = self.ui.lineEdit_4.text()
|
||||||
port = int(self.ui.lineEdit_3.text())
|
port = int(self.ui.lineEdit_3.text())
|
||||||
self.portCo = port
|
self.portCo = port
|
||||||
Addr = (ip,port)
|
Addr = (ip,port)
|
||||||
|
|
||||||
|
|
||||||
self.s = socket(AF_INET, SOCK_STREAM)
|
self.s = socket(AF_INET, SOCK_STREAM)
|
||||||
self.s.connect(Addr)
|
self.s.connect(Addr)
|
||||||
self.thread.setConfig(self.s, self)
|
self.thread.setConfig(self.s, self)
|
||||||
@ -829,7 +948,6 @@ class start(QtGui.QMainWindow):
|
|||||||
self.ui.lineEdit_3.setDisabled(True)
|
self.ui.lineEdit_3.setDisabled(True)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
|
|
||||||
cmd2 = self.ui.lineEdit_2.text()
|
cmd2 = self.ui.lineEdit_2.text()
|
||||||
if cmd2 != "":
|
if cmd2 != "":
|
||||||
self.s.settimeout(5.0)
|
self.s.settimeout(5.0)
|
||||||
@ -846,8 +964,11 @@ class start(QtGui.QMainWindow):
|
|||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def deco(self):
|
def deco(self):
|
||||||
|
"""
|
||||||
|
action on the button to disconnect from dnc
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
quitter = "/quit"
|
quitter = "/quit"
|
||||||
self.s.send(quitter.encode())
|
self.s.send(quitter.encode())
|
||||||
#self.s.close()
|
#self.s.close()
|
||||||
@ -860,29 +981,17 @@ class start(QtGui.QMainWindow):
|
|||||||
self.ui.lineEdit_4.setDisabled(False)
|
self.ui.lineEdit_4.setDisabled(False)
|
||||||
self.ui.lineEdit_3.setDisabled(False)
|
self.ui.lineEdit_3.setDisabled(False)
|
||||||
|
|
||||||
def ecoute(self):
|
|
||||||
while 1 :
|
|
||||||
data = self.s.recv(4096)
|
|
||||||
if not data :
|
|
||||||
break
|
|
||||||
messgServeur = (data.decode())
|
|
||||||
|
|
||||||
|
|
||||||
if messgServeur == "ERR_INVALID_NICKNAME" :
|
|
||||||
self.pseudo = "INVALID_NICKNAME"
|
|
||||||
|
|
||||||
|
|
||||||
self.UpdateChat(messgServeur)
|
|
||||||
|
|
||||||
|
|
||||||
def createWidgets(self):
|
def createWidgets(self):
|
||||||
|
"""
|
||||||
|
run the main windows, with config
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
ano = "anonymous" + ''.join(str(random.randint(1,9)) for _ in range(2))
|
ano = "anonymous" + ''.join(str(random.randint(1,9)) for _ in range(2))
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
config.read("dncClient.conf")
|
config.read("dncClient.conf")
|
||||||
|
|
||||||
port = config.get("NETWORK", "port")
|
port = config.get("NETWORK", "port")
|
||||||
@ -897,22 +1006,22 @@ class start(QtGui.QMainWindow):
|
|||||||
if ip is not None:
|
if ip is not None:
|
||||||
self.ui.lineEdit_4.setText(ip)
|
self.ui.lineEdit_4.setText(ip)
|
||||||
|
|
||||||
|
|
||||||
if port is not None:
|
if port is not None:
|
||||||
self.ui.lineEdit_3.setText(port)
|
self.ui.lineEdit_3.setText(port)
|
||||||
|
|
||||||
|
|
||||||
self.ui.lineEdit.setDisabled(True)
|
self.ui.lineEdit.setDisabled(True)
|
||||||
self.ui.pushButton.setDisabled(True)
|
self.ui.pushButton.setDisabled(True)
|
||||||
self.ui.pushButton_3.setDisabled(True)
|
self.ui.pushButton_3.setDisabled(True)
|
||||||
self.ui.pushButton_6.setDisabled(True)
|
self.ui.pushButton_6.setDisabled(True)
|
||||||
self.message_buffer = ""
|
self.message_buffer = ""
|
||||||
self.bouton = "disable"
|
self.bouton = "disable"
|
||||||
|
|
||||||
self.connectActions()
|
self.connectActions()
|
||||||
|
|
||||||
def client(self):
|
def client(self):
|
||||||
|
"""
|
||||||
|
send a message to the sever
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.cmd = self.ui.lineEdit.text()
|
self.cmd = self.ui.lineEdit.text()
|
||||||
if self.cmd != "":
|
if self.cmd != "":
|
||||||
self.ui.lineEdit.setText('')
|
self.ui.lineEdit.setText('')
|
||||||
@ -942,6 +1051,6 @@ if __name__ == "__main__":
|
|||||||
myapp = start()
|
myapp = start()
|
||||||
myapp.show()
|
myapp.show()
|
||||||
myapp.focusWidget()
|
myapp.focusWidget()
|
||||||
sys.exit(app.exec_())
|
|
||||||
for t in threading.enumerate():
|
for t in threading.enumerate():
|
||||||
if t != threading.main_thread(): t.join()
|
if t != threading.main_thread(): t.join()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
Reference in New Issue
Block a user